How to disable dismounting a mob (slime)?

Discussion in 'Spigot Plugin Development' started by Simo389, Jun 1, 2015.

  1. So I mount players on slimes using this:
    Code (Text):
    slime.setPassenger(player);

    But when a player dismounts it, the VehicleExitEvent isn't fired - I assume because this isn't a typical vehicle.

    What's the correct way to prevent a player SHIFT-clicking to dismount? I've tried the PlayerToggleSneakEvent, but the player is still dismounted. Is there a better way to prevent this/disable it completely? Or am I going to have to just re-mount them if they get off it?
     
  2. Have you tried EntityDismountEvent? ^^
     
    • Agree Agree x 1
  3. Just looking at it, it is not a cancellable event
     
  4. True, you could set the player to be riding the entity every time he tries to dismount, I don't know any other way really, sorry :(
     
  5. Hrm, seems like you're right.. oddly the event has a "private boolean cancelled;" but doesn't seem to use it.

    The VehicleDismountEvent is cancellable.. but probably won't fire for a Slime mount.

    Well.. now I'm curious if this is possible, too.

    EDIT: re-mounting is probably going to be crazy-glitchy, unfortunately.
     
  6. A packet filter which blocks the dismount packet (and remount packet?) could help you with that.
     
  7. Nvm, ill test it and tell you if it works
     
  8. It is possible. Hypixel's developers made that in one of their plugin (i think its was in an party game )
     
  9. Not to be going on a complete tangent, but can anyone fire EntityDismountEvent at all? I'm having trouble as EntityMountEvent works but no reaction for dismount.
     
  10. We know it's possible .. at least with some internal Spigot hacks or protocol trickery or whatever. Who knows what Hypixel is running, they probably have their own patched Spigot or something.

    I think mainly what we're all saying is "it would be nice if the EntityDismountEvent was cancelable" :)
     
    • Agree Agree x 1
  11. It is strange how you said that it does contain a cancellable boolean that is never used. It's counterpart EntityMountEvent can be cancelled, however. But either way I'm still having trouble calling the event in the first place never mind getting it to do anything. Potentially stopping the PacketPlayOutAttachEntity could work, will have a look at the way the packet is caught with protocollib.
     
  12. It seems to be a bug in the code. They fire the event in Entity, but EntityLiving never calls super.mount(Entity) and returns instead, when the mounting entity is null (which is the case if you unmount).
    Code (Java):

    public void mount(Entity entity)
    {
        // This is our case, we are dismounting!
        if ((this.vehicle != null) && (entity == null))
        {
            Entity originalVehicle = this.vehicle;
            // We aren't a vehicle, thus no event
            if (((this.bukkitEntity instanceof LivingEntity)) && ((this.vehicle.getBukkitEntity() instanceof Vehicle)))
            {
                VehicleExitEvent event = new VehicleExitEvent((Vehicle)this.vehicle.getBukkitEntity(), (LivingEntity)this.bukkitEntity);
                getBukkitEntity().getServer().getPluginManager().callEvent(event);
                if ((event.isCancelled()) || (this.vehicle != originalVehicle)) {
                    return;
                }
            }
            if (!this.world.isClientSide) {
                q(this.vehicle);
            }
            // Here the unmount occurs
            if (this.vehicle != null) {
                this.vehicle.passenger = null;
            }
            this.vehicle = null;
        }
        // But super.mount - which fires the EntityDismountEvent - is never called
        else
        {
            super.mount(entity);
        }
    }

    EDIT: I have no clue which specific version this was on, it was v1_8_3.
    EDIT #2: It does seem to be in the later versions, and the patches seem to only cover net.minecraft.server.Entity#mount(Entity)
     
    #13 DarkSeraphim, Jun 2, 2015
    Last edited: Jun 2, 2015
  13. I managed to gain some progress by saving the entity ID and using the protocollib packet listener cancel the Entity_Attach if the value equalled to -1 (dismount) corresponding with the entity ID. The issue arises I think in metadata as even though the player remains sitting they do not acknowledge the entity underneath.

    But thanks for the insight in that, I looked at the entity mounting method and was under the pretence that LivingEntity called the super method.
     
    • Like Like x 1
  14. Maybe just a runnable mounting the entity ontop of the other entity.