Disabling Invisability Potion + Remove from inventory!

Discussion in 'Plugin Development' started by Curtis3321, Oct 30, 2012.

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

    Curtis3321

    Hello, this is basically my very first Bukkit plugin for my server, all i am trying to do is stop players from brewing the potions and having already existed invis potions removed from a players inventory!

    So far my code consists off this (Thanks to a freind for the disabling of the brewing!)
    Code:
    package me.Curtis3321.AntiInvis;
     
    import org.bukkit.Material;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.EventPriority;
    import org.bukkit.event.inventory.BrewEvent;
    import org.bukkit.inventory.BrewerInventory;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.plugin.java.JavaPlugin;
     
    public class Blocking extends JavaPlugin {
     
    @Override
    public void onDisable() {
    pluginInfo("Disabled");
     
    }
     
    @Override
    public void onEnable() {
      pluginInfo("Enabled");
    }
    public static void pluginInfo(String message) {
      String v = "0.1";
      
      System.out.println("AntiInvis Plugin " + v + " " + message);
    }
     
    @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
    public void AntiInvis(BrewEvent e) {
     BrewerInventory i = e.getContents();
     if(i == null) return;
     if(i.getItem(3) != null && i.getItem(3).getType() == Material.FERMENTED_SPIDER_EYE){
      for(int k = 0; k < 3; k++){
       ItemStack item = i.getItem(k);
       if(item == null) continue;
       if(item.getType() == Material.POTION){
        if(item.getDurability() == 8198 ||
          item.getDurability() == 8262 || 
          item.getDurability() == 16390 ||
          item.getDurability() == 16454 ||
          item.getDurability() == 16310 ||
          item.getDurability() == 16374 ||
          item.getDurability() == 32694 ||
          item.getDurability() == 32758  
          ){
         e.setCancelled(true);
        }
       }
      }
     }
    }
    }
    
    All i want to do now, is get it to remove the item from there inv, and message them saying Stop trying to go invisible! or something ;D
    Remember this is my first plugin, my friend hooked me up with the disable brewing part ;D
     
  2. Offline

    Rprrr

    Code:
    public void onJoinEvent(PlayerJoinEvent event){
            Player pjoined = event.getPlayer();
            if (pjoined.getInventory().contains("potionstuffhere")){
                pjoined.getInventory().remove(blablablapotionstuffhere);
                }
    I don't know what the ID etc. for an invisibility potion is, but you should just search for that, and put it at the location of "potionstuffhere" and "blablabalbalpotionstuffhere".
     
  3. Offline

    swifteh3146

    If they already have the potions I just replace them with water bottles for now :D

    Code:
    @EventHandler(priority = EventPriority.MONITOR)
    public void onPotion(PlayerInteractEvent e)
    {
        ItemStack item = e.getPlayer().getItemInHand();
        if (item == null) return;
        if(item.getType() == Material.POTION) {
            switch (item.getDurability()) {
                case 8206:
                case 8270:
                case 16398:
                case 16462:
                e.setCancelled(true);
                e.getPlayer().sendMessage("Invisibility Disabled for now, sorry");
                item.setDurability((short)0);
                default:
                return;
            }
        }
    }
    hope it helps
     
  4. Offline

    Curtis3321

    Does not seem to take the item from there inventory! ;(
     
Thread Status:
Not open for further replies.

Share This Page