EssentialsX

EssentialsX

2M Downloads

Add vanished metadata value

xtomyserrax opened this issue ยท 8 comments

commented

Feature request

Feature description

When a player vanishes, add to its metadata the "vanished" state, many plugins check that in order to know if a player is vanished so they can hide them from their commands. This is a function many plugin are using, which makes them free of adding each vanish plugin to hook with theirs:

public static boolean isVanished(Player player) {
    if (player != null && player.hasMetadata("vanished") && !player.getMetadata("vanished").isEmpty()) {
        return player.getMetadata("vanished").get(0).asBoolean();
    }
    return false;
}

How the feature is useful

As I said before, no more plugins should hook with Essentials to know if a player is vanished, they can just check the player metadata. If all plugins start asking for this behaviour, vanish secrecy will improve in all servers as it is really easy to implement and it doesnt depend on any plugin, one server could be using Essentials, other another vanish plugin, and the plugin will support vanished players for all of them using this metadata values.

I didnt want to make a pull request as I dont really want to do anything wrong, but this is the code I use:

When a player vanishes:
player.setMetadata("vanished", new FixedMetadataValue(Main.plugin, true));

When a player unvanishes:
player.removeMetadata("vanished", Main.plugin); (or you can set it to false)

Thank you for considering this, it will completely change the vanish experience for servers and for developers. Sorry if I had any typo and if you need more information, please let me know.

commented

So, it may be helpful if you can name a few popular plugins that use this method and link to the code that handles it as a reference.

VanishNoPacket (which started it) and SuperVanish (and presumably PremiumVanish) both use it, along with some other plugins I can't recall at this moment.

My strategy is my favorite, since it involves the least effort:

.setMetadata("vanished", new LazyMetadataValue(this.plugin, CacheStrategy.NEVER_CACHE, /* Callable here that queries status */ ));
commented

Thanks mbax. Again, im not really a pro with this github and maven world, I just wanted to give the idea but made the pull so maybe it helped, guess I couldnt.

If anyone is able to do it, then thank you so much, as I cant understand how to compile the fork I made and that means I cant test it. Noob4Ever

commented

Ah, the person who knows how vanish plugins work has arrived! Fair enough. You probably want to use the method he mentioned.

commented

But I wont be able to test it pop. I actually know the FixedMetadataValue works fine, idk what difference it has with LazyMetadataValue.

If you want I can change it to what he said or leave it as it is right now, but again, I wont be able to test it :/

Also mbax, if you are allowed to edit the pull, then feel free to do it please

commented

Fixed is fine, Lazy is fine (as long as it's not expensive to call). All is fine!

commented

Please do make a PR. If anything appears to be wrong, someone will point it out for you. As you can see, there are a lot of open issues and not enough people to go through them all.

I don't personally know much about how vanish typically works (and I wouldn't assume everyone does). So, it may be helpful if you can name a few popular plugins that use this method and link to the code that handles it as a reference.

commented

Okay I just made the pull request, the only thing to check is if Im calling the plugin correctly, as the function requires Plugin and Boolean variables

commented

@xtomyserrax Recently the requirement for running buildtools in order to build the plugin has been lifted. So maybe give it a try again if you want, because it should be significantly easier. Just make sure you fork the latest version of Essentials.