Entity Hider Class cancels Knockback

Discussion in 'Plugin Development' started by Dolphindalt, Aug 2, 2016.

Thread Status:
Not open for further replies.
  1. Offline

    Dolphindalt

    I have a problem with this protocol lib code I use to make an entity toggle visibility.
    Code:
        /**
         * Allow the observer to see an entity that was previously hidden.
         * @param observer - the observer.
         * @param entity - the entity to show.
         * @return TRUE if the entity was hidden before, FALSE otherwise.
         */
        public final boolean showEntity(Player observer, Entity entity) {
            validate(observer, entity);
            boolean hiddenBefore = !setVisibility(observer, entity.getEntityId(), true);
    
            // Resend packets
            if (manager != null && hiddenBefore) {
                manager.updateEntity(entity, Arrays.asList(observer));
            }
            return hiddenBefore;
        }
    
        /**
         * Prevent the observer from seeing a given entity.
         * @param observer - the player observer.
         * @param entity - the entity to hide.
         * @return TRUE if the entity was previously visible, FALSE otherwise.
         */
        public final boolean hideEntity(Player observer, Entity entity) {
            validate(observer, entity);
            boolean visibleBefore = setVisibility(observer, entity.getEntityId(), false);
    
            if (visibleBefore) {
                PacketContainer destroyEntity = new PacketContainer(ENTITY_DESTROY);
                destroyEntity.getIntegerArrays().write(0, new int[] { entity.getEntityId() });
    
                // Make the entity disappear
                try {
                    manager.sendServerPacket(observer, destroyEntity);
                } catch (InvocationTargetException e) {
                    throw new RuntimeException("Cannot send server packet.", e);
                }
            }
            return visibleBefore;
        }
    The issue is when a player is made visible they sometimes sink into the floor and they do not take any knock back. I am running this code on a 1.7.10 server, I think that maybe the bug is Minecraft related.
     
    Last edited: Aug 2, 2016
  2. Offline

    mine-care

    Hmm, all you want to do here is make a player vanish? Why not using the API?
    Also there is a method in the NMS class Entity (I belive, unless it's a subclass) called "setVisible(Boolean param)" which acts like adding invisibility potion to the player without particles. That may work.

    I don't really know why this code makes the player glitch in such a way though, can't help on that :(
     
Thread Status:
Not open for further replies.

Share This Page