Solved Removing Effects

Discussion in 'Plugin Development' started by ImaTimelord7, Mar 13, 2015.

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

    ImaTimelord7

    This code won't work?
    Code:
    package me.ImaTimelord7.plugin;
    
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.block.Action;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffectType;
    
    public class Rennervate extends JavaPlugin implements Listener {
    
        @EventHandler
        public void XRennervate(PlayerInteractEvent e) {
            Player player = e.getPlayer();
            if (e.getAction() == Action.LEFT_CLICK_AIR && player.getItemInHand().getType() == Material.STICK) {
                if (player.getItemInHand().getItemMeta().getLore() != null) {
                    if (player.getItemInHand().getItemMeta().getLore().contains(ChatColor.DARK_PURPLE + "Rennervate")) {
                        player.sendMessage("Test");
                        player.removePotionEffect(PotionEffectType.ABSORPTION);
                        player.removePotionEffect(PotionEffectType.BLINDNESS);
                        player.removePotionEffect(PotionEffectType.CONFUSION);
                        player.removePotionEffect(PotionEffectType.DAMAGE_RESISTANCE);
                        player.removePotionEffect(PotionEffectType.FAST_DIGGING);
                        player.removePotionEffect(PotionEffectType.FIRE_RESISTANCE);
                        player.removePotionEffect(PotionEffectType.INCREASE_DAMAGE);
                        player.removePotionEffect(PotionEffectType.INVISIBILITY);
                        player.removePotionEffect(PotionEffectType.JUMP);
                        player.removePotionEffect(PotionEffectType.NIGHT_VISION);
                        player.removePotionEffect(PotionEffectType.POISON);
                        player.removePotionEffect(PotionEffectType.REGENERATION);
                        player.removePotionEffect(PotionEffectType.SLOW);
                        player.removePotionEffect(PotionEffectType.SLOW_DIGGING);
                        player.removePotionEffect(PotionEffectType.SPEED);
                        player.removePotionEffect(PotionEffectType.WATER_BREATHING);
                        player.removePotionEffect(PotionEffectType.WEAKNESS);
                        player.removePotionEffect(PotionEffectType.WITHER);
                    }
                }
            }
        }
    }   
    
    And my main class holds this (Under the onEnable())
    Code:
    getServer().getPluginManager().registerEvents(new Rennervate(), this);
    I'm sure that this should work, but it doesn't I have tried removing all of the removePotionEffects but even then it doesn't say "Test". What have I done wrong? Thanks in advance.
     
  2. Offline

    Konato_K

  3. Offline

    ImaTimelord7

    Je ne sais pas.
    @Konato_K Thanks for helping me, now that its been removed:
    Code:
    public class Rennervate implements Listener {
    It works fine, and when I looked it wasn't in any other class, other than my main class, which makes sense lol. Thanks again.
     
  4. Offline

    ElliottOlson

    It is better to use:

    for (PotionEffect effect : player.getActivePotionEffects()){
    player.removePotionEffect(effect.getType());
    }
     
    Konato_K likes this.
  5. Offline

    ImaTimelord7

    I hear you, however the code I have works how I need it to, so what changes with the code you showed me?
     
  6. Offline

    ElliottOlson

    It is a lot easier to use, and it is more efficient as it only tries to remove the potion effects that you actually have.
     
Thread Status:
Not open for further replies.

Share This Page