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; |
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 |
|
|
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; |
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 |
|
|
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) |