/[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 2429 by torben, Mon Mar 9 12:29:22 2015 UTC revision 3133 by torben, Fri Nov 18 13:14:07 2016 UTC
# Line 2  package dk.thoerup.bukkit.hoeruputils.ch Line 2  package dk.thoerup.bukkit.hoeruputils.ch
2    
3    
4  import java.util.HashMap;  import java.util.HashMap;
 import java.util.HashSet;  
5  import java.util.List;  import java.util.List;
6  import java.util.Set;  import java.util.Set;
7  import java.util.TreeMap;  import java.util.TreeMap;
# Line 41  import dk.thoerup.bukkit.hoeruputils.Uti Line 40  import dk.thoerup.bukkit.hoeruputils.Uti
40    
41  public class AdvancedChest  implements Listener, CommandExecutor{  public class AdvancedChest  implements Listener, CommandExecutor{
42    
43          class ItemCount extends TreeMap<Integer,Integer> {          class ItemCount extends TreeMap<Material,Integer> {
44                  private static final long serialVersionUID = 1L;                  private static final long serialVersionUID = 1L;
45          };          };
46    
# Line 84  public class AdvancedChest  implements L Line 83  public class AdvancedChest  implements L
83    
84    
85                  Block b = player.getTargetBlock( (Set<Material>)null, 30);                                        Block b = player.getTargetBlock( (Set<Material>)null, 30);                      
86                    Material mat = b.getType();
87                  if (b.getTypeId() != 54 && b.getTypeId() != 154) {                  
88                    if (mat != Material.CHEST && mat != Material.HOPPER) {
89                          player.sendMessage("[Chest] Please look at the chest/hopper you want to protect");                          player.sendMessage("[Chest] Please look at the chest/hopper you want to protect");
90                          return true;                          return true;
91                  }                  }
92    
93                  Location loc = b.getLocation();                  Location loc = b.getLocation();
94                  Location loc2 = null;                  Location loc2 = null;
95                  if ( b.getTypeId() == 54) { //dont find neighbours for Hoppers                  if ( mat == Material.HOPPER) { //dont find neighbours for Hoppers
96                          loc2 = getNeighborChest(loc);                          loc2 = getNeighborChest(loc);
97                  }                  }
98    
# Line 182  public class AdvancedChest  implements L Line 182  public class AdvancedChest  implements L
182                                  player.sendMessage("You need to specify which player should own this chest");                                  player.sendMessage("You need to specify which player should own this chest");
183                                  return true;                                  return true;
184                          }                          }
185                            
186                            //@SuppressWarnings("deprecation")//user by name is our only option here
187                          OfflinePlayer p2 = server.getOfflinePlayer(args[1]);                          OfflinePlayer p2 = server.getOfflinePlayer(args[1]);
188                            
189                          if ( p2.hasPlayedBefore() == false && p2.isOnline() == false) {                          if ( p2.hasPlayedBefore() == false && p2.isOnline() == false) {
190                                  player.sendMessage("Unknown user: " + args[1] );                                  player.sendMessage("Unknown user: " + args[1] );
191                                  return true;                                  return true;
# Line 207  public class AdvancedChest  implements L Line 210  public class AdvancedChest  implements L
210                                  player.sendMessage("You need to specify which player to add or remove");                                  player.sendMessage("You need to specify which player to add or remove");
211                                  return true;                                  return true;
212                          }                          }
213                            
214                            //@SuppressWarnings("deprecation")//user by name is our only option here
215                          OfflinePlayer p2 = server.getOfflinePlayer(args[1]);                          OfflinePlayer p2 = server.getOfflinePlayer(args[1]);
216                          if ( p2.hasPlayedBefore() == false && p2.isOnline() == false) {                          if ( p2.hasPlayedBefore() == false && p2.isOnline() == false) {
217                                  player.sendMessage("Unknown user: " + args[1] );                                  player.sendMessage("Unknown user: " + args[1] );
# Line 569  public class AdvancedChest  implements L Line 574  public class AdvancedChest  implements L
574    
575                          ItemCount content = countItems( event.getInventory().getContents() );                          ItemCount content = countItems( event.getInventory().getContents() );
576    
577                          Set<Integer> combinedKeyset = new TreeSet<Integer>();                                            Set<Material> combinedKeyset = new TreeSet<Material>();                
578                          combinedKeyset.addAll( savedContent.keySet() );                          combinedKeyset.addAll( savedContent.keySet() );
579                          combinedKeyset.addAll( content.keySet() );                          combinedKeyset.addAll( content.keySet() );
580    
581                          for (Integer item : combinedKeyset ) {                          for (Material material : combinedKeyset ) {
582                                  Integer savedcount = savedContent.get(item);                                                              Integer savedcount = savedContent.get(material);                                
583                                  Integer count = content.get(item);                                  Integer count = content.get(material);
584    
585                                  if (savedcount == null)                                  if (savedcount == null)
586                                          savedcount = 0;                                          savedcount = 0;
# Line 586  public class AdvancedChest  implements L Line 591  public class AdvancedChest  implements L
591                                  int diff = Math.abs( savedcount - count);                                  int diff = Math.abs( savedcount - count);
592    
593                                  if (diff > 0) {                                  if (diff > 0) {
                                         String material = Material.getMaterial(item).name();  
594                                          String msg = null;                                          String msg = null;
595    
596                                          if (count > savedcount) {                                          if (count > savedcount) {
597                                                  msg = player.getName() + " added "   + diff + " units of " + material + "(" +item + ") to "   + owner.getName() + "'s chest at " + loc.getWorld().getName() + "," + loc.getBlockX() + "," +loc.getBlockY() + "," + loc.getBlockZ() + chest.getCommentString();                                                  msg = player.getName() + " added "   + diff + " units of " + material + " to "   + owner.getName() + "'s chest at " + loc.getWorld().getName() + "," + loc.getBlockX() + "," +loc.getBlockY() + "," + loc.getBlockZ() + chest.getCommentString();
598                                          } else { //(count < savedcount)                                          } else { //(count < savedcount)
599                                                  msg = player.getName() + " removed " + diff + " units of " + material + "(" +item + ") from " + owner.getName() + "'s chest at " + loc.getWorld().getName() + "," + loc.getBlockX() + "," +loc.getBlockY() + "," + loc.getBlockZ() + chest.getCommentString();                                                  msg = player.getName() + " removed " + diff + " units of " + material + " from " + owner.getName() + "'s chest at " + loc.getWorld().getName() + "," + loc.getBlockX() + "," +loc.getBlockY() + "," + loc.getBlockZ() + chest.getCommentString();
600                                          }                                          }
601    
602    
# Line 613  public class AdvancedChest  implements L Line 617  public class AdvancedChest  implements L
617                          if (current == null)                          if (current == null)
618                                  continue;                                  continue;
619    
620                          int type = current.getTypeId();                          Material type = current.getType();
621    
622                          Integer amount = output.get(type);                          Integer amount = output.get(type);
623                          if (amount == null)                          if (amount == null)

Legend:
Removed from v.2429  
changed lines
  Added in v.3133

  ViewVC Help
Powered by ViewVC 1.1.20