/[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 2432 by torben, Mon Mar 9 13:55:54 2015 UTC revision 2433 by torben, Mon Mar 9 14:00:35 2015 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 575  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 592  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 619  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.2432  
changed lines
  Added in v.2433

  ViewVC Help
Powered by ViewVC 1.1.20