/[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 1807 by torben, Sun Jun 3 18:05:09 2012 UTC revision 1874 by torben, Tue Nov 27 15:38:11 2012 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                          } else {                          }
151                                  player.sendMessage("This chest is not protected");                                if (! chest.getOwner().equals( player.getName() ) ) {
152                                    player.sendMessage("You can not remove lock from a chest you don't own");
153                                    server.getLogger().info( player.getName() + " tried to remove protection froma chest owned by " + chest.getOwner() );
154                                    return true;
155                          }                          }
156    
157                            player.sendMessage("[LockedChest] Removing protection from chest");
158                            removeChest(loc);                              
159    
160                            return true;
161                    }
162    
163                    if (cmd.equals("setowner")) {
164                            if (chest == null) {
165                                    player.sendMessage("This chest is not protected");
166                                    return true;
167                            }
168                            if (! chest.getOwner().equals( player.getName() ) ) {
169                                    player.sendMessage("You can not set new owner of a chest you dont own");
170                                    server.getLogger().info( player.getName() + " tried to set owner on a chest owned by " + chest.getOwner() );
171                                    return true;
172                            }
173                            if (args.length != 2) {
174                                    player.sendMessage("You need to specify which player should own this chest");
175                                    return true;
176                            }
177                            OfflinePlayer p2 = server.getOfflinePlayer(args[1]);
178                            if ( p2.hasPlayedBefore() == false && p2.isOnline() == false) {
179                                    player.sendMessage("Unknown user: " + args[1] );
180                                    return true;
181                            }
182                            chest.setOwner( p2.getName() );
183                            plugin.getDatabase().save( chest );
184                            player.sendMessage("ok");
185                          return true;                          return true;
186                  }                  }
187                                    
# Line 154  public class AdvancedChest  implements L Line 190  public class AdvancedChest  implements L
190                                  player.sendMessage("This chest is not protected");                                  player.sendMessage("This chest is not protected");
191                                  return true;                                  return true;
192                          }                          }
193                            if (! chest.getOwner().equals( player.getName() ) ) {
194                                    player.sendMessage("You can not add/remove players from a chest you don't own");
195                                    server.getLogger().info( player.getName() + " tried to add/remove player on a chest owned by " + chest.getOwner() );
196                                    return true;
197                            }
198                          if (args.length != 2) {                          if (args.length != 2) {
199                                  player.sendMessage("You need to specify which player to add or remove");                                  player.sendMessage("You need to specify which player to add or remove");
200                                  return true;                                  return true;
# Line 166  public class AdvancedChest  implements L Line 207  public class AdvancedChest  implements L
207                                                    
208                          Set<String> players = Util.stringToSet( chest.getModifyPlayers() );                          Set<String> players = Util.stringToSet( chest.getModifyPlayers() );
209                          if (cmd.equals("addplayer")) {                          if (cmd.equals("addplayer")) {
210                                  players.add(args[1]);                                  players.add(p2.getName());
211                          } else {                          } else {
212                                  players.remove(args[1]);                                  players.remove(p2.getName());
213                          }                          }
214                                                    
215                          chest.setModifyPlayers( Util.setToString(players) );                          chest.setModifyPlayers( Util.setToString(players) );
# Line 176  public class AdvancedChest  implements L Line 217  public class AdvancedChest  implements L
217                          player.sendMessage("ok");                          player.sendMessage("ok");
218                          return true;                          return true;
219                  }                  }
220                    if (cmd.equals("comment")) {    
221                            if (chest == null) {
222                                    player.sendMessage("This chest is not protected");
223                                    return true;
224                            }
225                            if (! chest.getOwner().equals( player.getName() ) ) {                          
226                                    player.sendMessage("You can not comment a chest you don't own");
227                                    server.getLogger().info( player.getName() + " tried to comment on a chest owned by " + chest.getOwner() );
228                                    return true;
229                            }
230    
231                            StringBuilder sb = new StringBuilder();
232                            for (int i=1; i<args.length; i++) {
233                                    sb.append(args[i]).append(" ");
234                            }
235                            String comment = sb.toString().trim();
236    
237                            chest.setComment( comment );
238                            plugin.getDatabase().save( chest );
239                            player.sendMessage("Comment set");
240    
241                            return true;
242                    }
243                                    
244                  /*                  /*
245                  if (chest != null) {                  if (chest != null) {
# Line 216  public class AdvancedChest  implements L Line 280  public class AdvancedChest  implements L
280                          } else {                          } else {
281                                  event.setCancelled(true);                                  event.setCancelled(true);
282                                  event.getPlayer().sendMessage("You can't destroy that chest");                                  event.getPlayer().sendMessage("You can't destroy that chest");
283                                    server.getLogger().info( "[AdvancedChest] " + event.getPlayer().getName() + " tried breaking a chest owned by " + chest.getOwner() + chest.getCommentString() );
284                          }                          }
285                  }                  }
286          }          }
# Line 264  public class AdvancedChest  implements L Line 329  public class AdvancedChest  implements L
329                    
330          void loadChests() {                      void loadChests() {            
331                  int count = loadChestsWorker();                  int count = loadChestsWorker();
332                  plugin.getLogger().info("[AdvancedChest] loaded " + count + " chests");                  server.getLogger().info("[AdvancedChest] loaded " + count + " chests");
333          }          }
334                    
335                    
# Line 365  public class AdvancedChest  implements L Line 430  public class AdvancedChest  implements L
430                  for (Block b : event.blockList() ) {                  for (Block b : event.blockList() ) {
431                          ChestBean chest = chestMap.get( b.getLocation() );                          ChestBean chest = chestMap.get( b.getLocation() );
432                          if (chest != null) {                          if (chest != null) {
433                                    server.getLogger().info( "[AdvancedChest] Prevented an explosion from destroying chest owned by " + chest.getOwner() +  chest.getCommentString() );
434                                  event.setCancelled( true );                                  event.setCancelled( true );
435                                  return;                                  return;
436                          }                          }
437                  }                  }
438          }                }
439    
440            @EventHandler
441            public void onChestBurn(BlockBurnEvent event) {
442                    ChestBean chest = chestMap.get( event.getBlock().getLocation() );
443                    if (chest != null) {
444                            server.getLogger().info( "[AdvancedChest] prevented a fire from destrying chest owned by " + chest.getOwner() + chest.getCommentString()  );
445                            event.setCancelled( true);
446                    }
447            }
448                    
449          // prevent a user from opening a chest          // prevent a user from opening a chest
450          @EventHandler          @EventHandler
# Line 395  public class AdvancedChest  implements L Line 470  public class AdvancedChest  implements L
470                                          return; //chest is opened by it's owner                                          return; //chest is opened by it's owner
471                                  }                                  }
472                                                                    
473                                  if (chest.getModifyPlayers() != null && chest.getModifyPlayers().length()>0) {                                  Set<String> players = Util.stringToSet( chest.getModifyPlayers() );
474                                          String modplayers[] = chest.getModifyPlayers().split(",");                                  if ( players.contains(player.getName()) ) {
475                                          for (String p : modplayers) {                                          return; //this player is on the whitelist so he may open
                                                 if ( player.getName().equals(p) ) {  
                                                         return; //this player is on the whitelist so he may open  
                                                 }  
                                         }  
476                                  }                                  }
477    
478                            
479                                    server.getLogger().info( "[AdvancedChest] " + event.getPlayer().getName() + " tried opening a chest owned by " + chest.getOwner()  + chest.getCommentString() );
480                                  player.sendMessage( ChatColor.BLUE +  "Sorry but this chest is locked !");                                  player.sendMessage( ChatColor.BLUE +  "Sorry but this chest is locked !");
481                                  event.setCancelled(true);                                  event.setCancelled(true);
482                          }                          }
# Line 437  public class AdvancedChest  implements L Line 509  public class AdvancedChest  implements L
509                          Player player = (Player) event.getPlayer();                          Player player = (Player) event.getPlayer();
510                          if (player.getName().equals(chest.getOwner() )) {                          if (player.getName().equals(chest.getOwner() )) {
511                                  return; //chest is owned by it's own player                                  return; //chest is owned by it's own player
512                          }                                                }
513                            
514                            Set<String> players = Util.stringToSet( chest.getModifyPlayers() );
515                            if ( players.contains(player.getName()) ) {
516                                    return; //this player is on the whitelist so he may open
517                            }
518                                                    
519                                                    
520                            server.getLogger().info( "[AdvancedChest] " + event.getPlayer().getName() + " opened a snitching chest owned by " + chest.getOwner()  + chest.getCommentString()  );
521    
522                          ItemCount contents = countItems( event.getInventory().getContents() );                                            ItemCount contents = countItems( event.getInventory().getContents() );                  
523                                                    
524                          contentMap.put(player.getName(), contents );                          contentMap.put(player.getName(), contents );
# Line 509  public class AdvancedChest  implements L Line 588  public class AdvancedChest  implements L
588                                          }                                          }
589                                                                    
590                                                                    
591                                          plugin.getLogger().info(msg);                                          server.getLogger().info( "[AdvancedChest]" + msg);
592                                          plugin.getMessageWrapper().sendMessage("system", owner, msg);                                          plugin.getMessageWrapper().sendMessage("system", owner, msg);
593                                  }                                  }
594                                                                    

Legend:
Removed from v.1807  
changed lines
  Added in v.1874

  ViewVC Help
Powered by ViewVC 1.1.20