/[projects]/miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/chests/SnitchingChest.java
ViewVC logotype

Diff of /miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/chests/SnitchingChest.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1773 by torben, Thu Apr 5 12:37:13 2012 UTC revision 1780 by torben, Thu Apr 5 18:51:57 2012 UTC
# Line 22  import org.bukkit.entity.Player; Line 22  import org.bukkit.entity.Player;
22  import org.bukkit.event.EventHandler;  import org.bukkit.event.EventHandler;
23  import org.bukkit.event.Listener;  import org.bukkit.event.Listener;
24  import org.bukkit.event.block.BlockBreakEvent;  import org.bukkit.event.block.BlockBreakEvent;
25    import org.bukkit.event.block.BlockPlaceEvent;
26  import org.bukkit.event.inventory.InventoryCloseEvent;  import org.bukkit.event.inventory.InventoryCloseEvent;
27  import org.bukkit.event.inventory.InventoryOpenEvent;  import org.bukkit.event.inventory.InventoryOpenEvent;
28  import org.bukkit.inventory.InventoryHolder;  import org.bukkit.inventory.InventoryHolder;
# Line 91  public class SnitchingChest  implements Line 92  public class SnitchingChest  implements
92                  }                  }
93                                    
94                  SnitchingChestBean chest1 = createChest(player.getName(), "", loc);                  SnitchingChestBean chest1 = createChest(player.getName(), "", loc);
                 //chestMap.put(loc, chest1);  
95                  addChest(loc, chest1);                  addChest(loc, chest1);
96                  if (loc2 != null) {                  if (loc2 != null) {
97                                                    
98                          SnitchingChestBean chest2 = createChest (player.getName(), "", loc2);                          SnitchingChestBean chest2 = createChest (player.getName(), "", loc2);
99                          addChest(loc, chest2);                          addChest(loc, chest2);
                         //chestMap.put(loc2, chest2 );  
100                  }                  }
101                    
102                  player.sendMessage("[SnitchingChest] Chest is now under surveillance");                  player.sendMessage("[SnitchingChest] Chest is now under surveillance");
# Line 127  public class SnitchingChest  implements Line 126  public class SnitchingChest  implements
126                    
127          void removeChest(Location loc) {          void removeChest(Location loc) {
128                  SnitchingChestBean chest = chestMap.remove(loc);                  SnitchingChestBean chest = chestMap.remove(loc);
129                  plugin.getDatabase().delete(chest);                  if (chest != null) {
130                            plugin.getDatabase().delete(chest);
131                    }
132          }          }
133                    
134          void loadChests() {                      void loadChests() {            
# Line 136  public class SnitchingChest  implements Line 137  public class SnitchingChest  implements
137                          Location loc = getChestLocation(server, chest);                          Location loc = getChestLocation(server, chest);
138                          chestMap.put(loc, chest);                                chestMap.put(loc, chest);      
139                  }                  }
140                    
141                    plugin.getLogger().info("[SnitchingChest] loaded " + chestMap.size() + " chests");
142          }          }
143                    
144                    
# Line 198  public class SnitchingChest  implements Line 201  public class SnitchingChest  implements
201                  } else {                  } else {
202                          loc =  ( (DoubleChest)holder).getLocation();                          loc =  ( (DoubleChest)holder).getLocation();
203                  }                  }
204                    
205                    loc.setX( loc.getBlockX() ); //round to integer, since double chests apparently are placed at pos + 0.5
206                    loc.setZ( loc.getBlockZ() ); // -- // --
207                    
208                  return loc;                  return loc;
209          }          }
210                    
211          @EventHandler          @EventHandler
212            public void onChestPlaced(BlockPlaceEvent event) {
213                    Block block = event.getBlock();
214                    
215                    if (block.getType() != Material.CHEST) {
216                            return;
217                    }
218                    
219                    Location chestloc = getNeighborChest( block.getLocation() );
220                    if (chestloc != null) {
221                            SnitchingChestBean chest = chestMap.get(chestloc);
222                            
223                            if (chest != null) { //the neighbor is a snitching chest
224                                    SnitchingChestBean newchest = createChest( chest.getOwner(), "", chestloc);
225                                    addChest(chestloc, newchest);
226                                    event.getPlayer().sendMessage( "[SnitchingChest] Chest has been expanded" );
227                            }                      
228                            
229                    }
230            }
231            
232            @EventHandler
233          public void onChestOpen(InventoryOpenEvent event) {          public void onChestOpen(InventoryOpenEvent event) {
234                                    
235                  if (! (event.getPlayer() instanceof Player)) {                  if (! (event.getPlayer() instanceof Player)) {
# Line 241  public class SnitchingChest  implements Line 269  public class SnitchingChest  implements
269                  if (holder instanceof Chest || holder instanceof DoubleChest) {                  if (holder instanceof Chest || holder instanceof DoubleChest) {
270                          Location loc = getChestLocation(holder);                          Location loc = getChestLocation(holder);
271                          SnitchingChestBean chest = chestMap.get(loc);                          SnitchingChestBean chest = chestMap.get(loc);
272                            
273                            if (chest == null) { //chest was not a snitching chest
274                                    return;
275                            }
276                            
277                          OfflinePlayer owner = server.getOfflinePlayer( chest.getOwner() );                          OfflinePlayer owner = server.getOfflinePlayer( chest.getOwner() );
278                                                    
279                                                    

Legend:
Removed from v.1773  
changed lines
  Added in v.1780

  ViewVC Help
Powered by ViewVC 1.1.20