1.8.8 Perfect Vanish Code - Help

Discussion in 'Spigot Plugin Development' started by toshi2131, Apr 8, 2020.

  1. hello, I've been trying to code vanish for a bit while and it was never perfect or at least working correctly.
    the closest was working, but it had a problem that if you toggle vanish on, leave the server and join again
    the vanish isn't kept, i think its because i used an array list or something wrong
    So, if anybody got a good vanish code, or anything that could help me with vanish source so I can base on it and then improve mine It would really help me
  2. SteelPhoenix


    soo, listen to when a player joins, and if the player should be vanished, vanish him?
    • Agree Agree x 1
  3. how do I check it, my plugin does that if he vanishes he join a list, but when he logs he leaves the list so he's not vanished and then the problem accrues
  4. Store it in a database. When the player joins, check in the database whether the player should be vanished.
  5. I stored it in a file, but now i have another problem xd,
    okay so since I'm using 1.8.8 and i wanna send an actionBar when you vanished, i had to use packets
    this is the code
    Code (Java):
    public void sendActionText(Player player, String message){
                PacketPlayOutChat packet = new PacketPlayOutChat(new ChatComponentText(message), (byte)2);
                ((CraftPlayer) player).getHandle().playerConnection.sendPacket(packet);
    and then i created a runnable, but the thing is it removes when i relog, i tried adding it to the playerJoinEvent,
    but it didn't work (it does work on the command though)
    Code (Java):
    new BukkitRunnable() {
                    public void run() {
                        if (plugin.getVanish().vanished.contains(event.getPlayer())) {
                            sendActionText(event.getPlayer(), toColor("&2&kI&a You are currently vanished &2&kI"));

                }.runTaskTimer(plugin, 0, 20);
  6. So what exactly are you trying to do?
    Why is the action bar and runnable a problem?
  7. The problem is, since actionbar is not really added in 1.8.8 I had to use Packets,
    but the big problem is ok take this example
    i did /vanish, it worked but when i leave the server and rejoin
    the actionbar is gone, and yes i am still vanished so no one can see me but, if i do /vanish again it says i wasn't vanished so it toggles vanish again. i just want it to be fixed by that if i join the actiobar will stay and if i type /v again it will toggle off instead of on again (and with that if i join it will send vanished kept on or something, i know its somewhere in my playerjoinevent but i couldn't find the error or how to fix it
  8. I don't know if this is correct, but maybe if you have a hashmap with the players UUID and a boolean. Put it in your onEnable, then check to see if the UUID is true then do the runnable.

    When executing the command you would have to add the players UUID to the hashmap, and set the boolean to true.

    Im not sure if that will work, but it sounds like it would.
  9. You don't need a HashMap. You can have a List with the UUIDs of players who have vanish enabled.
    You also don't need to create a runnable for each player.
    You can have on runnable that iterates through the players in that list. If the player is online you show them the actionbar, if the player isn't online, you do nothing.

    This is more or less what you would have inside your runnable.
    Code (Java):
    for (UUID uuid : vanishedPlayers) {
        // If the player is online
            // show actionbar
    The command would then be used to remove or add players to the list.
    When they join you just need to check if they are in the list. If they are in that list you vanish them.