Disabling arrows and potions

Discussion in 'Plugin Development' started by Nerdfuryz, Jan 1, 2013.

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

    Nerdfuryz

    Code:
    package me.NerdFuryz.NoPotions;
     
    import org.bukkit.GameMode;
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
     
    public class PotionListener
        implements Listener{
     
        public PotionListener(NoPotions plugin)
          {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
          }
          @EventHandler
          public void onPlayerInteractEvent(PlayerInteractEvent e) {
            if ((e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) &&
              (e.getItem().getType().equals(Material.POTION))) {
                e.getPlayer().sendMessage("You're not allowed to use potions in Creative on DranCraft!");
                e.getPlayer().getInventory().removeItem(new ItemStack[] { e.getItem() });
                e.setCancelled(true);
            if ((e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) &&
              (e.getItem().getType().equals(Material.BOW))) {
                e.getPlayer().sendMessage("You're not allowed to shoot arrows in Creative on DranCraft!");
                e.setCancelled(true);
                }
                }
            }     
    }      
    That is the listener of course main is just this

    Code:
    package me.NerdFuryz.NoPotions;
     
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class NoPotions extends JavaPlugin{
       
          public PotionListener potionListener;
     
          public void onEnable()
          {
            this.potionListener = new PotionListener(this);
          }
     
          public void onDisable()
          {
          }
     
    }
    
    Disabling of potions in creative works but the bow is not? How would I change it so the bow does not shoot arrows in creative?

    Nevermind I fixed it. I changed it too this and it worked.

    Code:
    package me.NerdFuryz.NoPotions;
     
    import org.bukkit.GameMode;
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.PlayerInteractEvent;
    import org.bukkit.inventory.ItemStack;
     
    public class PotionListener
        implements Listener{
     
        public PotionListener(NoPotions plugin)
          {
            plugin.getServer().getPluginManager().registerEvents(this, plugin);
          }
          @EventHandler
          public void onPlayerInteractEvent(PlayerInteractEvent e) {
            if ((e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) &&
              (e.getItem().getType().equals(Material.POTION))) {
                e.getPlayer().sendMessage("You're not allowed to use potions in Creative on DranCraft!");
                e.getPlayer().getInventory().removeItem(new ItemStack[] { e.getItem() });
                e.setCancelled(true);
            }
            }
            @EventHandler
            public void onPlayerEvent(PlayerInteractEvent e) {
            if ((e.getPlayer().getGameMode().equals(GameMode.CREATIVE)) &&
              (e.getItem().getType().equals(Material.BOW))) {
                e.getPlayer().sendMessage("You're not allowed to shoot arrows in Creative on DranCraft!");
                e.setCancelled(true);
                }
                }     
    }     
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jul 8, 2016
Thread Status:
Not open for further replies.

Share This Page