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

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

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

revision 1784 by torben, Thu Apr 5 21:15:30 2012 UTC revision 1785 by torben, Fri Apr 6 09:51:01 2012 UTC
# Line 81  public class SnitchingChest  implements Line 81  public class SnitchingChest  implements
81                          if (chest.getOwner().equals(player.getName())) {                          if (chest.getOwner().equals(player.getName())) {
82                                  player.sendMessage("[SnitchingChest] Removing surveillance from chest");                                  player.sendMessage("[SnitchingChest] Removing surveillance from chest");
83                                  removeChest(loc);                                  removeChest(loc);
                                 if (loc2 != null) {  
                                         removeChest(loc2);                                        
                                 }  
84                          } else {                          } else {
85                                  player.sendMessage("[SnitchingChest] Chest is already under surveillance");                                  player.sendMessage("[SnitchingChest] Chest is already under surveillance");
86                          }                          }
# Line 91  public class SnitchingChest  implements Line 88  public class SnitchingChest  implements
88                          return true;                          return true;
89                  }                  }
90                                    
91                  SnitchingChestBean chest1 = createChest(player.getName(), "", loc);                  chest = createChest(player.getName(), "", loc);        
                 addChest(loc, chest1);  
92                  if (loc2 != null) {                  if (loc2 != null) {
93                                                    chest.setDoublechest(true);
                         SnitchingChestBean chest2 = createChest (player.getName(), "", loc2);  
                         addChest(loc, chest2);  
94                  }                  }
95                    addChest(loc, chest);
96                    
97                    
98                  player.sendMessage("[SnitchingChest] Chest is now under surveillance");                  player.sendMessage("[SnitchingChest] Chest is now under surveillance");
99                                    
# Line 121  public class SnitchingChest  implements Line 117  public class SnitchingChest  implements
117          }          }
118          public void addChest(Location loc, SnitchingChestBean chest) {          public void addChest(Location loc, SnitchingChestBean chest) {
119                  chestMap.put(loc, chest);                  chestMap.put(loc, chest);
120                    if (chest.isDoublechest()) {
121                            Location loc2 = getNeighborChest(loc);
122                            chestMap.put(loc2, chest);
123                    }              
124                  plugin.getDatabase().save(chest);                  plugin.getDatabase().save(chest);
125                    
126                    reloadChests();
127                    
128          }          }
129                    
130          void removeChest(Location loc) {          void removeChest(Location loc) {
131                  SnitchingChestBean chest = chestMap.remove(loc);                  SnitchingChestBean chest = chestMap.remove(loc);
132                  if (chest != null) {                  if (chest != null) {                                                                    
133                            if (chest.isDoublechest()){
134                                    Location loc2 = getNeighborChest(loc);
135                                    chestMap.remove(loc2);
136                            }
137                          plugin.getDatabase().delete(chest);                          plugin.getDatabase().delete(chest);
138                  }                  }
139          }          }
140                    
141          void loadChests() {                      int loadChestsWorker() {
142                  List<SnitchingChestBean> chestlist = plugin.getDatabase().find( SnitchingChestBean.class).findList();                  List<SnitchingChestBean> chestlist = plugin.getDatabase().find( SnitchingChestBean.class).findList();
143                  for (SnitchingChestBean chest : chestlist) {                  for (SnitchingChestBean chest : chestlist) {
144                          Location loc = getChestLocation(server, chest);                          Location loc = getChestLocation(server, chest);
145                          chestMap.put(loc, chest);                                chestMap.put(loc, chest);      
146                            
147                            if (chest.isDoublechest()) {
148                                    Location loc2 = getNeighborChest(loc);
149                                    chestMap.put(loc2, chest);      
150                            }
151                  }                  }
152                    
153                  plugin.getLogger().info("[SnitchingChest] loaded " + chestMap.size() + " chests");                  return chestlist.size();
154            }
155            
156            void reloadChests() {          
157                    chestMap.clear();
158                    loadChestsWorker();            
159            }
160            
161            void loadChests() {            
162                    int count = loadChestsWorker();
163                    plugin.getLogger().info("[SnitchingChest] loaded " + count + " chests");
164          }          }
165                    
166                    
# Line 221  public class SnitchingChest  implements Line 243  public class SnitchingChest  implements
243                          SnitchingChestBean chest = chestMap.get(chestloc);                          SnitchingChestBean chest = chestMap.get(chestloc);
244                                                    
245                          if (chest != null) { //the neighbor is a snitching chest                          if (chest != null) { //the neighbor is a snitching chest
246                                  SnitchingChestBean newchest = createChest( chest.getOwner(), "", chestloc);                                  //SnitchingChestBean newchest = createChest( chest.getOwner(), "", chestloc);
247                                  addChest(chestloc, newchest);                                  //plugin.getDatabase().save(chest);
248                                    
249                                    chest.setDoublechest(true);
250                                    addChest(chestloc, chest);
251                                    
252                                    
253                                  event.getPlayer().sendMessage( "[SnitchingChest] Chest has been expanded" );                                  event.getPlayer().sendMessage( "[SnitchingChest] Chest has been expanded" );
254                          }                                                }                      
255                                                    

Legend:
Removed from v.1784  
changed lines
  Added in v.1785

  ViewVC Help
Powered by ViewVC 1.1.20