How to set a players tag to invisible when they consume an invisibility potion

Discussion in 'Plugin Development' started by OfficialSammy, May 6, 2018.

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

    OfficialSammy

    So basically what I want this plugin to do when a player consumes a certain potion effect, in this case "Invisibility", their nametag while disappear. I'm making this for one problem and I'm sure by now we all know why.. You can see nametags of players who have invisibility in Minecraft 1.8.x.

    So I just have some small questions.
    • How would I set an event to trigger only when a player drinks an "Invisibility" potion.
    • How would I set the players nametag to be invisible when they have the effect applied.
    This is the class that I attempted to write this..
    But I stopped once I had no clue how to have it trigger when a certain potion effect is applied to the player.

    Code:
    package me.OfficialSammy.HideInvis;
    
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerItemConsumeEvent;
    import org.bukkit.potion.PotionEffect;
    import org.bukkit.potion.PotionEffectType;
    
    
    public class HidingPlayerName implements Listener {
        public Main main;
    
        public HidingPlayerName(Main main) {
            this.main = main;
        }
        public void onConsume(PlayerItemConsumeEvent e) {
            Player p = e.getPlayer();
           
            if(e.getItem().getType().equals(Material.POTION)) {
                p.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 2480 * 20, 1));
            }
        }
    }
     
  2. Offline

    MightyOne

    I think for the first thingy you can just cast the ItemStack to Potion and then test if INVISIBILITY is inside the Potion#getEffects().
    Idk much about the display name thing. I guess it has something to do with packets. Even if it seems to be not so suiting anymore for 1.8+ you could maybe go with the TagAPI.
     
  3. Offline

    Sploon

    You can remove a player's nametag with scoreboards (it's a team option).
     
  4. Offline

    DutchJellyV2

Thread Status:
Not open for further replies.

Share This Page