Removing all potion effects

Discussion in 'Plugin Development' started by Nebuler, Aug 28, 2015.

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

    Nebuler

    Code:
    package me.nebuler;
    
    import org.bukkit.Bukkit;
    import org.bukkit.permissions.Permission;
    import org.bukkit.plugin.PluginManager;
    import org.bukkit.plugin.java.JavaPlugin;
    import org.bukkit.potion.PotionEffect;
    
    public class NoEffect extends JavaPlugin {
       
        public Permission bypassRemove = new Permission("noeffect.bypass");
       
        @Override
        public void onEnable() {
            PluginManager pm = getServer().getPluginManager();
            pm.addPermission(bypassRemove);
            getLogger().info("NoEffect successfully enabled! Working correctly");
            alwaysRunning();
        }
       
        @Override
        public void onDisable() {
            getLogger().info("NoEffect successfully disabled!");
        }
       
        public void alwaysRunning(){
            Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
                @Override
                public void run() {
                   
                    if (!(player.hasPermission("noeffect.bypass"))) {
                        for (PotionEffect effect : player.getActivePotionEffects())
                            player.removePotionEffect(effect.getType());
                    }
                   
                }
            }, 20, 200);
        }
    }
    I have this code and want to remove the potion effects from a player when they don't have a bypass permission. But the problem is, I can't find a way to set the player to remove the effects from as I'm not using a command to trigger it. Thankyou in advance - Nebs
     
  2. Offline

    ShadowRanger

  3. Offline

    Nebuler

    @ShadowRanger is there a way to do it my way? by checking the player or something?
     
  4. Offline

    ShadowRanger

    Uhh yeah I guess, however it might not be very performance efficient. Just iterate through all the players on the server in your task here. Right now you have player, which isn't actually defined. Use a for loop to iterate over Bukkit.getOnlinePlayers() and check each player. But like I said, this isn't really the most efficient way to do it.
     
  5. Offline

    Nebuler

  6. Offline

    mrgreen33gamer

    @Nebuler

    Code:java
    1.  
    2. for(PotionEffect effects : player.getActivePotionEffects())
    3. player.removePotionEffect(effects.getType());
    4.  
     
Thread Status:
Not open for further replies.

Share This Page