set arrow true invisible (not despawn or send packets)

Discussion in 'Plugin Development' started by atesin, Jul 9, 2017.

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

    atesin

    SOLVED: you can see the finished plugin >here<

    hi everyone

    i am trying to write a lightweight chat bubbles plugin ... so i spawned some arrows, set custom name with chat text and set as player passenger so they stick with him ... works perfect, but i cant make them invisible, i tried:

    - accessing nms entityArrow.setInvisible(true) --> still visible
    - spawn far away, make them invisible, then teleport near player --> arrows dont seem to come
    - reload chunk --> nothing changes
    - with nms: create entity arrow, set invisible first, then spawn --> dont appear to spawn

    i had tried with armorstands too, it works but:

    - arrows noclip blocks
    - arrows seem to have perfect size
    - armorstands are too big so each text appear one floor above player, even with setSmall(true)
    - are pixel tiny with setMarker(true) so all texts stack in player head and it is unreadable
    - i could not find any way to set a custom size, nms entityArmorStand.setSize() does nothing

    upload_2017-7-9_21-41-14.png

    - i could move stands with teleportTo(location) every PlayerMoveEvent --> awful, player appear followed by a trail of texts
    - maybe arrow invisibility and armorstand size are hardcoded client side
    - the funny thing is i could make armorstands noclip with nms, but cant make arrows invisible

    some code i tried, comments are what i tried and didnt work:

    Code:
        private Entity spawnNamePlate(Entity vehicle, String textLine)
        {
            Location loc = vehicle.getLocation();
            //loc = new Location(loc.getWorld(), 0D, 0D, 0D);
            Arrow namePlate = (Arrow) loc.getWorld().spawnEntity(loc, EntityType.ARROW);
            namePlate.setInvulnerable(true);
            //namePlate.setVisible(false);
            namePlate.setGravity(false);
            //namePlate.setSmall(true);
            //namePlate.setMarker(true);
    
            try // nms + reflection methods
            {
                Object handle = namePlate.getClass().getMethod("getHandle").invoke(namePlate);
                Class handleClass = handle.getClass();
                //handleClass.getSuperclass().getSuperclass().getMethod("setInvisible", boolean.class).invoke(handle, true);
                //Class.forName("net.minecraft.server."+version+".Entity").getMethod("setInvisible", boolean.class).invoke(handle, true);
            }
            catch (IllegalAccessException | IllegalArgumentException
                    | InvocationTargetException | NoSuchMethodException
                    | SecurityException e)
            { e.printStackTrace(); }
    
            //namePlate.teleport(vehicle);
    
            vehicle.addPassenger(namePlate);
            namePlate.setCustomName(chatFormat+textLine);
            namePlate.setCustomNameVisible(true);
            //loc.getWorld().getChunkAt(loc).load();
            return namePlate;
        }
    
     
    Last edited: Aug 1, 2017
  2. Offline

    Zombie_Striker

    @atesin
    Don't use reflection. This should be achievable just using the bukkit api.

    Have you tried changing the entity type? Does it work if you set the entity to a Horse or pig instead?
     
  3. Offline

    atesin

    i think should be achievable just with bukkit api too, but i couldnt figured how to ... why i shouldnt use reflection? .. when all things gone wrong, reflection comes to rescue

    i didnt tried with other mobs .. i like arrows because its size and because are not living entities so it wont produce sound and wont flee running... but also i like stands because are the only entity that has INVISIBILITY in bukkit api

    what other "Nameable" superclass do you recommend that could be turn invisible, noclip, invulnerable and have correct size?
     
  4. Offline

    Zombie_Striker

    @atesin
    1. Considering you are using reflections to access the API, reflection is just making this more complicated than it needs to be.
    2. If you don't want the entity to make sound, use Entity#setSilent(true);
    3. You can use armorstands. That would be better than other living mobs, but the invisibility should work for any entity.
    4. All entities are nameable, invulnerable, and invisible using one line each. The noclip just requires three, which is just creating a runnable that sets the velocity and location every couple of ticks.
    Anyway, just try changing the arrow to any other entity.
     
  5. Offline

    atesin

    @Zombie_Striker thanks for your early answers

    1. i havent find any way to do some things purely with bukkit api, i can use craftbukkit but i want my plugins wont break compatibility through updates too
    2. i will try with bats, maybe invisibility with arrows dont work because are not living entities
    3. armorstands are the only entities i had found that has setVisible(flag) method... i shearched in bukkit javadocs for "visib" and had confirmed ... if you know how to turn invisible an entity that had not implemented the method tell me please
    4. yes i know all entities are subclasses of Nameable (this confirms), but armorstand are the only one that implements setVisible(f) afaik
    anyway... i dont know how to make entity invisible without some implemented method... if you give me some hint i would gladly appreciate it

    Edit: i tried with bats but i still dont find so small, linetexts still get too separated... do you know another tiny living entity?

    Edit: i tried with silverfishes, has correct size but still no way invisible :( ... and invisibility potion effect turns nameplate invisible too ... please help me somebody if knows how, i had tried everything with no luck

    Code:
    Silverfish namePlate = ...world.spawnEntity(location, Type.SILVERFISH)... etc;
    try{
      Object handle = namePlate.getClass().getMethod("getHandle").invoke(namePlate);
      Class handleClass = handle.getClass();
      handleClass.getSuperclass().getSuperclass().getMethod("setInvisible", boolean.class).invoke(handle, true);
    }catch(...);
    world.chunk(location).load() ... etc;
     
    Last edited: Jul 9, 2017
  6. Offline

    atesin

    well thanks to @Zombie_Striker by his suggestions, i could resolve most of the problem taking the better of each alternative

    until chats now works apparently fine, the only issue remain is when i enter water, the chat baloon "dismounts" player and go away floating .... i opened another thread to asking for ideas *here*

    SOLVED

    i used area effect entities, you can see the finished plugin >here<
     
    Last edited: Aug 1, 2017
Thread Status:
Not open for further replies.

Share This Page