Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 1st, 2012  |  syntax: None  |  size: 3.44 KB  |  hits: 16  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. public class BlockLogLite extends org.bukkit.plugin.java.JavaPlugin {
  2.  
  3. ...
  4.  
  5.     public boolean onChestOpen(Player player, Integer[] xyz) {
  6.         String player_name = player.getName();
  7.         if (chestInteractions.containsKey(player_name)) {
  8.             onChestClose(player, chestInteractions.get(player_name));
  9.             chestInteractions.remove(player_name);
  10.         }
  11.         log("onChestOpen(" + player_name + ", {" + xyz[0] + ", " + xyz[1] + ", " + xyz[2] + "});");
  12.         chestInteractions.put(player_name, xyz);
  13.         return false;
  14.     }
  15.    
  16.     public boolean onChestClose(Player player, Integer[] xyz) {
  17.         log("onChestClose(" + player.getName() + ", {" + xyz[0] + ", " + xyz[1] + ", " + xyz[2] + "});");
  18.         Block chest_block = player.getWorld().getBlockAt(xyz[0], xyz[1], xyz[2]);
  19.         Block block = chest_block;
  20.         BlockFace[] faces = {BlockFace.NORTH, BlockFace.EAST, BlockFace.SOUTH, BlockFace.WEST};
  21.         for (int i = 0; i < 5; i++) {
  22.             if (i > 0) {
  23.                 block = chest_block.getFace(faces[i - 1]);
  24.             }
  25.             if (block.getTypeId() != 54) {
  26.                 continue;
  27.             }
  28.             Chest chest = (Chest) block.getState();
  29.             ItemStack[] items = chest.getInventory().getContents();
  30.             for (int i2 = 0; i2 < 27; i2++) {
  31.                 if (items[i2].getAmount() > 0) {
  32.                     log("[" + i2 + "," + items[i2].getTypeId() + "," + items[i2].getDurability() + "," + items[i2].getAmount() + "]");
  33.                 }
  34.             }
  35.         }
  36.         return false;
  37.     }
  38.  
  39. ...
  40.  
  41. }
  42.  
  43.  
  44. public class BlockListener extends org.bukkit.event.block.BlockListener {
  45.  
  46. ...
  47.  
  48.     @Override
  49.     public void onBlockInteract(BlockInteractEvent event) {
  50.         if (event.isCancelled()) {
  51.             return;
  52.         }
  53.         if (event.isPlayer()) {
  54.             Block block = event.getBlock();
  55.             switch (block.getTypeId()) {
  56.                 case 54:
  57.                         plugin.onChestOpen((Player) event.getEntity(), new Integer[] {block.getX(), block.getY(), block.getZ()});
  58.                     break;
  59.             }
  60.         }
  61.     }
  62.  
  63. ...
  64.  
  65. }
  66.  
  67. public class PlayerListener extends org.bukkit.event.player.PlayerListener {
  68.  
  69. ...
  70.  
  71.     @Override
  72.     public void onPlayerQuit(PlayerEvent event) {
  73.         Player player = event.getPlayer();
  74.         String player_name = player.getName();
  75.         plugin.onPlayerEvent(player_name, 2);
  76.         if (plugin.chestInteractions.containsKey(player_name)) {
  77.             plugin.onChestClose(player, plugin.chestInteractions.get(player_name));
  78.             plugin.chestInteractions.remove(player_name);
  79.         }
  80.     }
  81.  
  82.     @Override
  83.     public void onPlayerMove(PlayerMoveEvent event) {
  84.         if (event.isCancelled()) {
  85.             return;
  86.         }
  87.         Player player = event.getPlayer();
  88.         String player_name = player.getName();
  89.         if (plugin.chestInteractions.containsKey(player_name)) {
  90.             Integer[] xyz = plugin.chestInteractions.get(player_name);
  91.             int x = player.getLocation().getBlockX() - xyz[0];
  92.             int y = player.getLocation().getBlockY() - xyz[1];
  93.             int z = player.getLocation().getBlockZ() - xyz[2];
  94.             if (x > 5 || x < -5 || y > 5 || y < -5 || z > 5 || z < -5) {
  95.                 plugin.onChestClose(player, xyz);
  96.                 plugin.chestInteractions.remove(player_name);
  97.             }
  98.         }
  99.     }
  100.  
  101. ...
  102.  
  103. }