spenk

Dive - old

Feb 16th, 2012
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.81 KB | None | 0 0
  1. import java.util.logging.Logger;
  2.  
  3. public class Dive extends Plugin
  4.   implements Runnable
  5. {
  6.   private static Logger a = Logger.getLogger("Minecraft");
  7.  
  8.   private Dive.Listener l = new Dive.Listener(this);
  9.  
  10.   public boolean run = true;
  11.   public int time = 5000;
  12.  
  13.   public void enable()
  14.   {
  15.     new Thread(this).start();
  16.     etc.getInstance().addCommand("/dive", " - breathe underwater!");
  17.   }
  18.  
  19.   public void disable()
  20.   {
  21.     etc.getInstance().removeCommand("/dive");
  22.   }
  23.  
  24.   public void run()
  25.   {
  26.     while (this.run)
  27.       try {
  28.         Thread.sleep(this.time);
  29.         diverCheck();
  30.       } catch (InterruptedException e1) {
  31.         e1.printStackTrace();
  32.         a.info(e1.getMessage());
  33.       }
  34.   }
  35.  
  36.   public void initialize()
  37.   {
  38.     String pluginName = "Dive";
  39.     String version = "1.0";
  40.  
  41.     PluginLoader loader = etc.getLoader();
  42.     loader.addListener(PluginLoader.Hook.COMMAND, this.l, this, PluginListener.Priority.MEDIUM);
  43.     loader.addListener(PluginLoader.Hook.PLAYER_MOVE, this.l, this, PluginListener.Priority.MEDIUM);
  44.     loader.addListener(PluginLoader.Hook.DISCONNECT, this.l, this, PluginListener.Priority.MEDIUM);
  45.     a.info(pluginName + " " + version + " initialized");
  46.   }
  47.  
  48.   public void diverCheck()
  49.   {
  50.     for (Player player : etc.getServer().getPlayerList())
  51.     {
  52.       Item hat = player.getInventory().getItemFromSlot(39);
  53.       if ((player.getAirTicks() >= 200) || (hat.getItemId() != 20))
  54.         continue;
  55.       player.setAirTicks(600);
  56.     }
  57.   }
  58.  
  59.   public class Listener extends PluginListener
  60.   {
  61.     Listener(Dive dive)
  62.     {
  63.       plugin = dive;
  64.     }
  65.     public void broadcast(String paramString) {
  66.       for (Player localPlayer : etc.getServer().getPlayerList())
  67.         localPlayer.sendMessage(paramString);
  68.       Dive.a.info("[broadcast] " + paramString);
  69.     }
  70.  
  71.     public boolean onCommand(Player player, String[] split) {
  72.       if ((split[0].equalsIgnoreCase("/dive")) || (split[0].equalsIgnoreCase("/bell")))
  73.       {
  74.         if (player.getItemInHand() == 20)
  75.         {
  76.           Item glass = player.getInventory().getItemFromId(20);
  77.           int slot = glass.getSlot();
  78.           int amt = glass.getAmount() - 1;
  79.           player.getInventory().setSlot(20, 1, 39);
  80.           if (amt < 1)
  81.             player.getInventory().removeItem(slot);
  82.           else {
  83.             player.getInventory().setSlot(20, amt, slot);
  84.           }
  85.           player.getInventory().update();
  86.           player.sendMessage("You can now breathe underwater!");
  87.           Dive.a.info("[Dive] " + player.getName() + " enabled a diving bell.");
  88.           return true;
  89.         }
  90.  
  91.         player.sendMessage("Hold a block of glass and try again...");
  92.  
  93.         return true;
  94.       }
  95.       return false;
  96.     }
  97.  
  98.     public void onDisconnect(Player player)
  99.     {
  100.     }
  101.   }
  102. }
Advertisement
Add Comment
Please, Sign In to add comment