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

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

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

revision 1809 by torben, Sun Jun 3 20:34:42 2012 UTC revision 1915 by torben, Fri Jan 18 09:41:46 2013 UTC
# Line 24  import org.bukkit.event.EventHandler; Line 24  import org.bukkit.event.EventHandler;
24  import org.bukkit.event.Listener;  import org.bukkit.event.Listener;
25  import org.bukkit.event.block.Action;  import org.bukkit.event.block.Action;
26  import org.bukkit.event.block.BlockBreakEvent;  import org.bukkit.event.block.BlockBreakEvent;
27    import org.bukkit.event.block.BlockBurnEvent;
28  import org.bukkit.event.block.BlockPlaceEvent;  import org.bukkit.event.block.BlockPlaceEvent;
29  import org.bukkit.event.entity.EntityExplodeEvent;  import org.bukkit.event.entity.EntityExplodeEvent;
30  import org.bukkit.event.inventory.InventoryCloseEvent;  import org.bukkit.event.inventory.InventoryCloseEvent;
# Line 76  public class AdvancedChest  implements L Line 77  public class AdvancedChest  implements L
77                                    
78                  if (args.length == 0) {                  if (args.length == 0) {
79                          player.sendMessage("Usage:");                          player.sendMessage("Usage:");
80                          player.sendMessage("/chest (status|lock|snitch|remove|addplayer|removeplayer) [player]");                          player.sendMessage("/chest (status|lock|snitch|remove|addplayer|removeplayer|setowner|comment) [player]");
81                          return true;                          return true;
82                  }                  }
83                                    
# Line 110  public class AdvancedChest  implements L Line 111  public class AdvancedChest  implements L
111                                                                    
112                                  player.sendMessage(ChatColor.GREEN + "Chest is  a " + mode + " chest owned by " + chest.getOwner());                                  player.sendMessage(ChatColor.GREEN + "Chest is  a " + mode + " chest owned by " + chest.getOwner());
113                                  player.sendMessage(ChatColor.GREEN + "Allowed players: " + chest.getModifyPlayers() );                                  player.sendMessage(ChatColor.GREEN + "Allowed players: " + chest.getModifyPlayers() );
114                                    player.sendMessage(ChatColor.GREEN + "Comment: " + chest.getComment() );
115                          } else {                          } else {
116                                  player.sendMessage(ChatColor.GREEN + "The chest is not protected");                                  player.sendMessage(ChatColor.GREEN + "The chest is not protected");
117                          }                          }
# Line 131  public class AdvancedChest  implements L Line 133  public class AdvancedChest  implements L
133                                          modeStr = "snitching";                                          modeStr = "snitching";
134                                  }                                  }
135                                  chest.setModifyPlayers("");                                  chest.setModifyPlayers("");
136                                    chest.setComment("");
137                                  addChest(loc, chest);                                  addChest(loc, chest);
138                                  player.sendMessage("Chest is now " + modeStr);                                  player.sendMessage("Chest is now " + modeStr);
139                          } else {                          } else {
140                                    server.getLogger().info( player.getName() + " tried to protect a chest owned by " + chest.getOwner() );
141                                  player.sendMessage("This chest is already protected");                                  player.sendMessage("This chest is already protected");
142                          }                          }
143                          return true;                          return true;
144                  }                  }
145                                    
146                  if (cmd.equals("remove")) {                  if (cmd.equals("remove")) {
147                          if (chest != null) {                          if (chest == null) {
148                                  player.sendMessage("[LockedChest] Removing protection from chest");                                  player.sendMessage("This chest is not protected");
149                                  removeChest(loc);                                                                return true;
150                            }
151                            if ( chest.getOwner().equals( player.getName() ) || player.isOp() ) {
152                                    //do nothing
153                            } else {
154                                    player.sendMessage("You can not remove lock from a chest you don't own");
155                                    server.getLogger().info( player.getName() + " tried to remove protection froma chest owned by " + chest.getOwner() );
156                                    return true;
157                            }
158    
159                            player.sendMessage("[LockedChest] Removing protection from chest");
160                            removeChest(loc);                              
161    
162                            return true;
163                    }
164    
165                    if (cmd.equals("setowner")) {
166                            if (chest == null) {
167                                    player.sendMessage("This chest is not protected");
168                                    return true;
169                            }
170                            if ( chest.getOwner().equals( player.getName() ) || player.isOp() ) {
171                                    //do nothing
172                          } else {                          } else {
173                                  player.sendMessage("This chest is not protected");                                        player.sendMessage("You can not set new owner of a chest you dont own");
174                                    server.getLogger().info( player.getName() + " tried to set owner on a chest owned by " + chest.getOwner() );
175                                    return true;
176                            }
177                            if (args.length != 2) {
178                                    player.sendMessage("You need to specify which player should own this chest");
179                                    return true;
180                            }
181                            OfflinePlayer p2 = server.getOfflinePlayer(args[1]);
182                            if ( p2.hasPlayedBefore() == false && p2.isOnline() == false) {
183                                    player.sendMessage("Unknown user: " + args[1] );
184                                    return true;
185                          }                          }
186                            chest.setOwner( p2.getName() );
187                            plugin.getDatabase().save( chest );
188                            player.sendMessage("ok");
189                          return true;                          return true;
190                  }                  }
191                                    
# Line 154  public class AdvancedChest  implements L Line 194  public class AdvancedChest  implements L
194                                  player.sendMessage("This chest is not protected");                                  player.sendMessage("This chest is not protected");
195                                  return true;                                  return true;
196                          }                          }
197                            if (! chest.getOwner().equals( player.getName() ) ) {
198                                    player.sendMessage("You can not add/remove players from a chest you don't own");
199                                    server.getLogger().info( player.getName() + " tried to add/remove player on a chest owned by " + chest.getOwner() );
200                                    return true;
201                            }
202                          if (args.length != 2) {                          if (args.length != 2) {
203                                  player.sendMessage("You need to specify which player to add or remove");                                  player.sendMessage("You need to specify which player to add or remove");
204                                  return true;                                  return true;
# Line 176  public class AdvancedChest  implements L Line 221  public class AdvancedChest  implements L
221                          player.sendMessage("ok");                          player.sendMessage("ok");
222                          return true;                          return true;
223                  }                  }
224                    if (cmd.equals("comment")) {    
225                            if (chest == null) {
226                                    player.sendMessage("This chest is not protected");
227                                    return true;
228                            }
229                            if (! chest.getOwner().equals( player.getName() ) ) {                          
230                                    player.sendMessage("You can not comment a chest you don't own");
231                                    server.getLogger().info( player.getName() + " tried to comment on a chest owned by " + chest.getOwner() );
232                                    return true;
233                            }
234    
235                            StringBuilder sb = new StringBuilder();
236                            for (int i=1; i<args.length; i++) {
237                                    sb.append(args[i]).append(" ");
238                            }
239                            String comment = sb.toString().trim();
240    
241                            chest.setComment( comment );
242                            plugin.getDatabase().save( chest );
243                            player.sendMessage("Comment set");
244    
245                            return true;
246                    }
247                                    
248                  /*                  /*
249                  if (chest != null) {                  if (chest != null) {
# Line 216  public class AdvancedChest  implements L Line 284  public class AdvancedChest  implements L
284                          } else {                          } else {
285                                  event.setCancelled(true);                                  event.setCancelled(true);
286                                  event.getPlayer().sendMessage("You can't destroy that chest");                                  event.getPlayer().sendMessage("You can't destroy that chest");
287                                    server.getLogger().info( "[AdvancedChest] " + event.getPlayer().getName() + " tried breaking a chest owned by " + chest.getOwner() + chest.getCommentString() );
288                          }                          }
289                  }                  }
290          }          }
# Line 264  public class AdvancedChest  implements L Line 333  public class AdvancedChest  implements L
333                    
334          void loadChests() {                      void loadChests() {            
335                  int count = loadChestsWorker();                  int count = loadChestsWorker();
336                  plugin.getLogger().info("[AdvancedChest] loaded " + count + " chests");                  server.getLogger().info("[AdvancedChest] loaded " + count + " chests");
337          }          }
338                    
339                    
# Line 365  public class AdvancedChest  implements L Line 434  public class AdvancedChest  implements L
434                  for (Block b : event.blockList() ) {                  for (Block b : event.blockList() ) {
435                          ChestBean chest = chestMap.get( b.getLocation() );                          ChestBean chest = chestMap.get( b.getLocation() );
436                          if (chest != null) {                          if (chest != null) {
437                                    server.getLogger().info( "[AdvancedChest] Prevented an explosion from destroying chest owned by " + chest.getOwner() +  chest.getCommentString() );
438                                  event.setCancelled( true );                                  event.setCancelled( true );
439                                  return;                                  return;
440                          }                          }
441                  }                  }
442          }                }
443    
444            @EventHandler
445            public void onChestBurn(BlockBurnEvent event) {
446                    ChestBean chest = chestMap.get( event.getBlock().getLocation() );
447                    if (chest != null) {
448                            server.getLogger().info( "[AdvancedChest] prevented a fire from destrying chest owned by " + chest.getOwner() + chest.getCommentString()  );
449                            event.setCancelled( true);
450                    }
451            }
452                    
453          // prevent a user from opening a chest          // prevent a user from opening a chest
454          @EventHandler          @EventHandler
# Line 395  public class AdvancedChest  implements L Line 474  public class AdvancedChest  implements L
474                                          return; //chest is opened by it's owner                                          return; //chest is opened by it's owner
475                                  }                                  }
476                                                                    
477                                  Set<String> players = Util.stringToSet( chest.getModifyPlayers() );                                  Set<String> players = chest.getModifyPlayersSet() ;
478                                  if ( players.contains(player.getName()) ) {                                  if ( players.contains(player.getName()) ) {
479                                          return; //this player is on the whitelist so he may open                                          return; //this player is on the whitelist so he may open
480                                  }                                  }
481    
482    
483                                                            server.getLogger().info( "[AdvancedChest] " + event.getPlayer().getName() + " tried opening a chest owned by " + chest.getOwner()  + chest.getCommentString() );
484                                  player.sendMessage( ChatColor.BLUE +  "Sorry but this chest is locked !");                                  player.sendMessage( ChatColor.BLUE +  "Sorry but this chest is locked !");
485                                  event.setCancelled(true);                                  event.setCancelled(true);
486                          }                          }
# Line 436  public class AdvancedChest  implements L Line 515  public class AdvancedChest  implements L
515                                  return; //chest is owned by it's own player                                  return; //chest is owned by it's own player
516                          }                          }
517                                                    
518                          Set<String> players = Util.stringToSet( chest.getModifyPlayers() );                          Set<String> players = chest.getModifyPlayersSet();
519                          if ( players.contains(player.getName()) ) {                          if ( players.contains(player.getName()) ) {
520                                  return; //this player is on the whitelist so he may open                                  return; //this player is on the whitelist so he may open
521                          }                          }
522                                                    
523                                                    
524                            server.getLogger().info( "[AdvancedChest] " + event.getPlayer().getName() + " opened a snitching chest owned by " + chest.getOwner()  + chest.getCommentString()  );
525    
526                          ItemCount contents = countItems( event.getInventory().getContents() );                                            ItemCount contents = countItems( event.getInventory().getContents() );                  
527                                                    
528                          contentMap.put(player.getName(), contents );                          contentMap.put(player.getName(), contents );
# Line 511  public class AdvancedChest  implements L Line 592  public class AdvancedChest  implements L
592                                          }                                          }
593                                                                    
594                                                                    
595                                          plugin.getLogger().info(msg);                                          server.getLogger().info( "[AdvancedChest]" + msg);
596                                          plugin.getMessageWrapper().sendMessage("system", owner, msg);                                          plugin.getMessageWrapper().sendMessage("system", owner, msg);
597                                  }                                  }
598                                                                    

Legend:
Removed from v.1809  
changed lines
  Added in v.1915

  ViewVC Help
Powered by ViewVC 1.1.20