How can i show a player again that is removed by packets ?

Discussion in 'Spigot Plugin Development' started by Bombastickj, May 30, 2015.

?

How can i show a player again that is removed by packets ?

Poll closed May 30, 2015.
  1. Player Spawn Packet?

    1 vote(s)
    100.0%
  2. EntitySpawn Packet?

    0 vote(s)
    0.0%
  1. Hello everyone!
    I'm making a plugin with short commands and i need help for the vanish command trying to do this with packets. I need help by the showPlayer metod (to show the player agagin).

    My code is this:

    Code (Text):
    public class Vanish implements Listener {
       
        public static ArrayList<Player> vanishPlayerMove = new ArrayList<>();
       
        public static PacketPlayOutEntityDestroy destroyEntity(Entity entity) {
            return new PacketPlayOutEntityDestroy(entity.getId());
        }
       
        public static PacketPlayOutSpawnEntity showEntity(Entity entity) {
            return new PacketPlayOutSpawnEntity(entity, entity.getId());
        }
       
        public static void vanishPlayer(Player player) {
            for(Player p : Bukkit.getOnlinePlayers()) {
                ((CraftPlayer) p).getHandle().playerConnection.sendPacket(destroyEntity(((CraftPlayer) player).getHandle()));
            }
            vanishPlayerMove.add(player);
        }
       
        public static void showPlayer(Player player) {
            for(Player p : Bukkit.getOnlinePlayers()) {
                ((CraftPlayer) p).getHandle().playerConnection.sendPacket(showEntity(((CraftPlayer) player).getHandle()));
            }
            vanishPlayerMove.remove(player);
        }
       
        @EventHandler
        public void onMove(PlayerMoveEvent e) {
            Player p = e.getPlayer();
            if(vanishPlayerMove.contains(p)) {
                for(Player player : Bukkit.getOnlinePlayers()) {
                    ((CraftPlayer) player).getHandle().playerConnection.sendPacket(destroyEntity(((CraftPlayer) p).getHandle()));
                }
            }
        }
    }
     
    thx for helping :)

    Bombastickj
     
  2. Vanish and showing players is already part of the bukkit api. Use that.
    How you are doing such things can lead to errors in the client where he gets for example movement packets about players which are despawned already.
     
  3. konsolas

    Supporter

    Send a PacketPlayOutPlayerInfo and then a PacketPlayOutNamedEntitySpawn.
     
  4. And how can i do that ? (Sorry i'm not the best in programming).
     
  5. konsolas

    Supporter

    Player#hidePlayer
     
  6. If you try using the spigot API before getting familiar with Java, you'll get nowhere. I'd recommend going over a bunch of comprehensive tutorials to make sure you really understand the language you're working with.
     
  7. This is not working .. the player isn't invisible :(
     
  8. this is not a answer of my question .. sorry but i can program with java but not with packets in minecraft .. :D
     
  9. Are you familiar with the spigot javadocs? They'd answer your "how do I do that" question.
     
  10. So i did it now thanks to all! Here is the code :D it was much easyer than i thought !

    Code (Text):
        public static void hidePlayer(Player p) {
            for(Player player : Bukkit.getOnlinePlayers()) {
                player.hidePlayer(p);
            }
        }

        public static void showPlayer(Player p) {
            for(Player player : Bukkit.getOnlinePlayers()) {
                player.showPlayer(p);
            }
        }
     
    • Agree Agree x 2
    • Like Like x 1