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 |
|
|
82 |
} |
} |
83 |
|
|
84 |
|
|
85 |
Block b = player.getTargetBlock(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 |
|
|
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; |
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] ); |
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) |