3 |
|
|
4 |
import java.util.HashMap; |
import java.util.HashMap; |
5 |
import java.util.List; |
import java.util.List; |
6 |
|
import java.util.Set; |
7 |
|
import java.util.TreeMap; |
8 |
|
import java.util.TreeSet; |
9 |
|
|
10 |
import org.bukkit.ChatColor; |
import org.bukkit.ChatColor; |
11 |
import org.bukkit.Location; |
import org.bukkit.Location; |
12 |
import org.bukkit.Material; |
import org.bukkit.Material; |
13 |
|
import org.bukkit.OfflinePlayer; |
14 |
import org.bukkit.Server; |
import org.bukkit.Server; |
15 |
import org.bukkit.World; |
import org.bukkit.World; |
16 |
import org.bukkit.block.Block; |
import org.bukkit.block.Block; |
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; |
31 |
|
import org.bukkit.event.inventory.InventoryOpenEvent; |
32 |
import org.bukkit.event.player.PlayerInteractEvent; |
import org.bukkit.event.player.PlayerInteractEvent; |
33 |
import org.bukkit.inventory.InventoryHolder; |
import org.bukkit.inventory.InventoryHolder; |
34 |
|
import org.bukkit.inventory.ItemStack; |
35 |
|
|
36 |
import dk.thoerup.bukkit.hoeruputils.HoerupUtilsPlugin; |
import dk.thoerup.bukkit.hoeruputils.HoerupUtilsPlugin; |
37 |
|
import dk.thoerup.bukkit.hoeruputils.Util; |
38 |
|
|
39 |
|
|
40 |
public class LockedChest implements Listener, CommandExecutor{ |
|
41 |
|
public class AdvancedChest implements Listener, CommandExecutor{ |
42 |
|
|
43 |
|
class ItemCount extends TreeMap<Integer,Integer> { |
44 |
|
private static final long serialVersionUID = 1L; |
45 |
|
}; |
46 |
|
|
47 |
|
HashMap<String, ItemCount> contentMap = new HashMap<String, ItemCount>(); |
48 |
|
|
49 |
|
|
50 |
HashMap<Location,LockedChestBean> chestMap = new HashMap<Location, LockedChestBean>(); |
HashMap<Location,ChestBean> chestMap = new HashMap<Location, ChestBean>(); |
51 |
|
|
52 |
|
|
53 |
HoerupUtilsPlugin plugin; |
HoerupUtilsPlugin plugin; |
54 |
Server server; |
Server server; |
55 |
|
|
56 |
public LockedChest(HoerupUtilsPlugin plugin, Runnable r) { |
public AdvancedChest(HoerupUtilsPlugin plugin, Runnable r) { |
57 |
this.plugin = plugin; |
this.plugin = plugin; |
58 |
server = plugin.getServer(); |
server = plugin.getServer(); |
59 |
try { |
try { |
75 |
|
|
76 |
Player player = (Player) sender; |
Player player = (Player) sender; |
77 |
|
|
78 |
|
if (args.length == 0) { |
79 |
|
player.sendMessage("Usage:"); |
80 |
|
player.sendMessage("/chest (status|lock|snitch|remove|addplayer|removeplayer|setowner) [player]"); |
81 |
|
return true; |
82 |
|
} |
83 |
|
|
84 |
Block b = player.getTargetBlock(null, 30); |
|
85 |
Location loc = b.getLocation(); |
Block b = player.getTargetBlock(null, 30); |
86 |
|
|
87 |
if (b.getTypeId() != 54) { |
if (b.getTypeId() != 54) { |
88 |
player.sendMessage("[LockedChest] Please look at the chest you want to lock"); |
player.sendMessage("[Chest] Please look at the chest you want to protect"); |
89 |
return true; |
return true; |
90 |
} |
} |
91 |
|
|
92 |
|
Location loc = b.getLocation(); |
93 |
Location loc2 = getNeighborChest(loc); |
Location loc2 = getNeighborChest(loc); |
94 |
|
|
95 |
LockedChestBean chest = chestMap.get(loc); |
ChestBean chest = chestMap.get(loc); |
96 |
|
String cmd = args[0].toLowerCase(); |
97 |
|
|
98 |
|
if (cmd.equals("status")) { |
99 |
|
if (chest != null) { |
100 |
|
String mode = ""; |
101 |
|
switch (chest.getChestType()) { |
102 |
|
case ChestBean.LOCKED: |
103 |
|
mode = "locked"; |
104 |
|
break; |
105 |
|
case ChestBean.SNITCHING: |
106 |
|
mode = "snitching"; |
107 |
|
break; |
108 |
|
default: |
109 |
|
mode = "unknown ??"; |
110 |
|
} |
111 |
|
|
112 |
|
player.sendMessage(ChatColor.GREEN + "Chest is a " + mode + " chest owned by " + chest.getOwner()); |
113 |
|
player.sendMessage(ChatColor.GREEN + "Allowed players: " + chest.getModifyPlayers() ); |
114 |
|
} else { |
115 |
|
player.sendMessage(ChatColor.GREEN + "The chest is not protected"); |
116 |
|
} |
117 |
|
return true; |
118 |
|
} |
119 |
|
|
120 |
|
if (cmd.equals("lock") || cmd.equals("snitch")) { |
121 |
|
if (chest == null) { |
122 |
|
chest = createChest(player.getName(), "", loc); |
123 |
|
if (loc2 != null) { |
124 |
|
chest.setDoublechest(true); |
125 |
|
} |
126 |
|
String modeStr = ""; |
127 |
|
if (cmd.equals("lock")) { |
128 |
|
chest.setChestType( ChestBean.LOCKED); |
129 |
|
modeStr = "locked"; |
130 |
|
} else { |
131 |
|
chest.setChestType( ChestBean.SNITCHING); |
132 |
|
modeStr = "snitching"; |
133 |
|
} |
134 |
|
chest.setModifyPlayers(""); |
135 |
|
addChest(loc, chest); |
136 |
|
player.sendMessage("Chest is now " + modeStr); |
137 |
|
} else { |
138 |
|
player.sendMessage("This chest is already protected"); |
139 |
|
} |
140 |
|
return true; |
141 |
|
} |
142 |
|
|
143 |
|
if (cmd.equals("remove")) { |
144 |
|
if (chest == null) { |
145 |
|
player.sendMessage("This chest is not protected"); |
146 |
|
return true; |
147 |
|
} |
148 |
|
if (! chest.getOwner().equals( player.getName() ) ) { |
149 |
|
player.sendMessage("You can not remove lock from a chest you don't own"); |
150 |
|
return true; |
151 |
|
} |
152 |
|
|
153 |
|
player.sendMessage("[LockedChest] Removing protection from chest"); |
154 |
|
removeChest(loc); |
155 |
|
|
156 |
|
return true; |
157 |
|
} |
158 |
|
|
159 |
|
if (cmd.equals("setowner")) { |
160 |
|
if (chest == null) { |
161 |
|
player.sendMessage("This chest is not protected"); |
162 |
|
return true; |
163 |
|
} |
164 |
|
if (! chest.getOwner().equals( player.getName() ) ) { |
165 |
|
player.sendMessage("You can not set new owner of a chest you dont own"); |
166 |
|
return true; |
167 |
|
} |
168 |
|
if (args.length != 2) { |
169 |
|
player.sendMessage("You need to specify which player should own this chest"); |
170 |
|
return true; |
171 |
|
} |
172 |
|
OfflinePlayer p2 = server.getOfflinePlayer(args[1]); |
173 |
|
if ( p2.hasPlayedBefore() == false && p2.isOnline() == false) { |
174 |
|
player.sendMessage("Unknown user: " + args[1] ); |
175 |
|
return true; |
176 |
|
} |
177 |
|
chest.setOwner( p2.getName() ); |
178 |
|
plugin.getDatabase().save( chest ); |
179 |
|
player.sendMessage("ok"); |
180 |
|
return true; |
181 |
|
} |
182 |
|
|
183 |
|
if (cmd.equals("addplayer") || cmd.equals("removeplayer")) { |
184 |
|
if (chest == null) { |
185 |
|
player.sendMessage("This chest is not protected"); |
186 |
|
return true; |
187 |
|
} |
188 |
|
if (! chest.getOwner().equals( player.getName() ) ) { |
189 |
|
player.sendMessage("You can not add/remove players from a chest you don't own"); |
190 |
|
return true; |
191 |
|
} |
192 |
|
if (args.length != 2) { |
193 |
|
player.sendMessage("You need to specify which player to add or remove"); |
194 |
|
return true; |
195 |
|
} |
196 |
|
OfflinePlayer p2 = server.getOfflinePlayer(args[1]); |
197 |
|
if ( p2.hasPlayedBefore() == false && p2.isOnline() == false) { |
198 |
|
player.sendMessage("Unknown user: " + args[1] ); |
199 |
|
return true; |
200 |
|
} |
201 |
|
|
202 |
|
Set<String> players = Util.stringToSet( chest.getModifyPlayers() ); |
203 |
|
if (cmd.equals("addplayer")) { |
204 |
|
players.add(p2.getName()); |
205 |
|
} else { |
206 |
|
players.remove(p2.getName()); |
207 |
|
} |
208 |
|
|
209 |
|
chest.setModifyPlayers( Util.setToString(players) ); |
210 |
|
plugin.getDatabase().save( chest ); |
211 |
|
player.sendMessage("ok"); |
212 |
|
return true; |
213 |
|
} |
214 |
|
|
215 |
|
/* |
216 |
if (chest != null) { |
if (chest != null) { |
217 |
if (chest.getOwner().equals(player.getName())) { |
if (chest.getOwner().equals(player.getName())) { |
218 |
player.sendMessage("[LockedChest] Removing lock from chest"); |
player.sendMessage("[LockedChest] Removing lock from chest"); |
219 |
removeChest(loc); |
removeChest(loc); |
220 |
} else { |
} else { |
221 |
player.sendMessage("[LockedChest] Chest is already locked"); |
player.sendMessage("[LockedChest] Chest is already protected"); |
222 |
} |
} |
223 |
|
|
224 |
return true; |
return true; |
233 |
|
|
234 |
|
|
235 |
player.sendMessage("[LockedChest] Chest is now locked"); |
player.sendMessage("[LockedChest] Chest is now locked"); |
236 |
|
*/ |
237 |
|
|
238 |
|
player.sendMessage("Unknown argument, " + cmd); |
239 |
|
|
240 |
return true; |
return true; |
241 |
} |
} |
243 |
@EventHandler |
@EventHandler |
244 |
public void onBlockBreak(BlockBreakEvent event) { |
public void onBlockBreak(BlockBreakEvent event) { |
245 |
Location loc = event.getBlock().getLocation(); |
Location loc = event.getBlock().getLocation(); |
246 |
LockedChestBean chest = chestMap.get(loc); |
ChestBean chest = chestMap.get(loc); |
247 |
if (chest != null) { |
if (chest != null) { |
248 |
if (chest.getOwner().equals(event.getPlayer().getName())) { |
if (chest.getOwner().equals(event.getPlayer().getName())) { |
249 |
removeChest(loc); |
removeChest(loc); |
250 |
event.getPlayer().sendMessage("[LockedChest] The destroyed chest was locked"); |
event.getPlayer().sendMessage("[AdvancedChest] The destroyed chest was locked or snitching"); |
251 |
} else { |
} else { |
252 |
event.setCancelled(true); |
event.setCancelled(true); |
253 |
event.getPlayer().sendMessage("You can't destroy that chest"); |
event.getPlayer().sendMessage("You can't destroy that chest"); |
254 |
|
server.getLogger().info( "[AdvancedChest] " + event.getPlayer().getName() + " tried breaking a chest owned by " + chest.getOwner() ); |
255 |
} |
} |
256 |
} |
} |
257 |
} |
} |
258 |
public void addChest(Location loc, LockedChestBean chest) { |
public void addChest(Location loc, ChestBean chest) { |
259 |
chestMap.put(loc, chest); |
chestMap.put(loc, chest); |
260 |
if (chest.isDoublechest()) { |
if (chest.isDoublechest()) { |
261 |
Location loc2 = getNeighborChest(loc); |
Location loc2 = getNeighborChest(loc); |
268 |
} |
} |
269 |
|
|
270 |
void removeChest(Location loc) { |
void removeChest(Location loc) { |
271 |
LockedChestBean chest = chestMap.remove(loc); |
ChestBean chest = chestMap.remove(loc); |
272 |
if (chest != null) { |
if (chest != null) { |
273 |
if (chest.isDoublechest()){ |
if (chest.isDoublechest()){ |
274 |
Location loc2 = getNeighborChest(loc); |
Location loc2 = getNeighborChest(loc); |
279 |
} |
} |
280 |
|
|
281 |
int loadChestsWorker() { |
int loadChestsWorker() { |
282 |
List<LockedChestBean> chestlist = plugin.getDatabase().find( LockedChestBean.class).findList(); |
List<ChestBean> chestlist = plugin.getDatabase().find( ChestBean.class).findList(); |
283 |
for (LockedChestBean chest : chestlist) { |
for (ChestBean chest : chestlist) { |
284 |
Location loc = getChestLocation(server, chest); |
Location loc = getChestLocation(server, chest); |
285 |
chestMap.put(loc, chest); |
chestMap.put(loc, chest); |
286 |
|
|
300 |
|
|
301 |
void loadChests() { |
void loadChests() { |
302 |
int count = loadChestsWorker(); |
int count = loadChestsWorker(); |
303 |
plugin.getLogger().info("[LockedChest] loaded " + count + " chests"); |
server.getLogger().info("[AdvancedChest] loaded " + count + " chests"); |
304 |
} |
} |
305 |
|
|
306 |
|
|
307 |
public LockedChestBean createChest(String owner, String description, Location loc) { |
public ChestBean createChest(String owner, String description, Location loc) { |
308 |
|
|
309 |
LockedChestBean chest = new LockedChestBean(); |
ChestBean chest = new ChestBean(); |
310 |
chest.setOwner(owner); |
chest.setOwner(owner); |
311 |
chest.setDescription(description); |
chest.setDescription(description); |
312 |
setChestLocation(chest, loc); |
setChestLocation(chest, loc); |
315 |
} |
} |
316 |
|
|
317 |
|
|
318 |
public void setChestLocation(LockedChestBean chest, Location loc) { |
public void setChestLocation(ChestBean chest, Location loc) { |
319 |
chest.setWorld( loc.getWorld().getName() ); |
chest.setWorld( loc.getWorld().getName() ); |
320 |
chest.setX( loc.getBlockX() ); |
chest.setX( loc.getBlockX() ); |
321 |
chest.setY( loc.getBlockY() ); |
chest.setY( loc.getBlockY() ); |
322 |
chest.setZ( loc.getBlockZ() ); |
chest.setZ( loc.getBlockZ() ); |
323 |
} |
} |
324 |
|
|
325 |
public Location getChestLocation(Server server, LockedChestBean chest) { |
public Location getChestLocation(Server server, ChestBean chest) { |
326 |
World wrld = server.getWorld(chest.getWorld()); |
World wrld = server.getWorld(chest.getWorld()); |
327 |
return new Location(wrld,chest.getX(),chest.getY(),chest.getZ()); |
return new Location(wrld,chest.getX(),chest.getY(),chest.getZ()); |
328 |
} |
} |
380 |
|
|
381 |
Location chestloc = getNeighborChest( block.getLocation() ); |
Location chestloc = getNeighborChest( block.getLocation() ); |
382 |
if (chestloc != null) { |
if (chestloc != null) { |
383 |
LockedChestBean chest = chestMap.get(chestloc); |
ChestBean chest = chestMap.get(chestloc); |
384 |
|
|
385 |
if (chest != null) { //the neighbor is a locked chest |
if (chest != null) { //the neighbor is a locked chest |
386 |
|
|
389 |
addChest(chestloc, chest); |
addChest(chestloc, chest); |
390 |
|
|
391 |
|
|
392 |
event.getPlayer().sendMessage( "[LockedChest] Chest has been expanded" ); |
event.getPlayer().sendMessage( "[AdvancedChest] Chest has been expanded" ); |
393 |
} |
} |
394 |
|
|
395 |
} |
} |
399 |
@EventHandler |
@EventHandler |
400 |
public void onChestExplode(EntityExplodeEvent event) { |
public void onChestExplode(EntityExplodeEvent event) { |
401 |
for (Block b : event.blockList() ) { |
for (Block b : event.blockList() ) { |
402 |
LockedChestBean chest = chestMap.get( b.getLocation() ); |
ChestBean chest = chestMap.get( b.getLocation() ); |
403 |
if (chest != null) { |
if (chest != null) { |
404 |
|
server.getLogger().info( "[AdvancedChest] Prevented an explosion from destroying chest owned by " + chest.getOwner() ); |
405 |
event.setCancelled( true ); |
event.setCancelled( true ); |
406 |
return; |
return; |
407 |
} |
} |
408 |
} |
} |
409 |
} |
} |
410 |
|
|
411 |
|
@EventHandler |
412 |
|
public void onChestBurn(BlockBurnEvent event) { |
413 |
|
ChestBean chest = chestMap.get( event.getBlock().getLocation() ); |
414 |
|
if (chest != null) { |
415 |
|
server.getLogger().info( "[AdvancedChest] prevented a fire from destrying chest owned by " + chest.getOwner() ); |
416 |
|
event.setCancelled( true); |
417 |
|
} |
418 |
|
} |
419 |
|
|
420 |
// prevent a user from opening a chest |
// prevent a user from opening a chest |
421 |
@EventHandler |
@EventHandler |
427 |
|
|
428 |
Location loc = b.getLocation(); |
Location loc = b.getLocation(); |
429 |
|
|
430 |
LockedChestBean chest = chestMap.get( loc ); |
ChestBean chest = chestMap.get( loc ); |
431 |
if (chest == null) { |
if (chest == null) { |
432 |
return; //chest not surveyed by this plugin |
return; //chest not surveyed by this plugin |
433 |
} |
} |
434 |
|
|
435 |
|
if (chest.getChestType() != ChestBean.LOCKED ) { |
436 |
|
return; //this is not a locked chests |
437 |
|
} |
438 |
|
|
439 |
Player player = (Player) event.getPlayer(); |
Player player = (Player) event.getPlayer(); |
440 |
if (player.getName().equals(chest.getOwner() )) { |
if (player.getName().equals(chest.getOwner() )) { |
441 |
return; //chest is opened by it's owner |
return; //chest is opened by it's owner |
442 |
} |
} |
443 |
|
|
444 |
if (chest.getModifyPlayers() != null && chest.getModifyPlayers().length()>0) { |
Set<String> players = Util.stringToSet( chest.getModifyPlayers() ); |
445 |
String modplayers[] = chest.getModifyPlayers().split(","); |
if ( players.contains(player.getName()) ) { |
446 |
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 |
|
|
} |
|
|
} |
|
447 |
} |
} |
448 |
|
|
449 |
|
|
450 |
|
server.getLogger().info( "[AdvancedChest] " + event.getPlayer().getName() + " tried opening a chest owned by " + chest.getOwner() ); |
451 |
player.sendMessage( ChatColor.BLUE + "Sorry but this chest is locked !"); |
player.sendMessage( ChatColor.BLUE + "Sorry but this chest is locked !"); |
452 |
event.setCancelled(true); |
event.setCancelled(true); |
453 |
} |
} |
454 |
} |
} |
455 |
} |
} |
456 |
|
|
457 |
|
@EventHandler |
458 |
|
public void onChestOpen(InventoryOpenEvent event) { |
459 |
|
|
460 |
|
if (! (event.getPlayer() instanceof Player)) { |
461 |
|
return; |
462 |
|
} |
463 |
|
|
464 |
|
|
465 |
|
|
466 |
|
InventoryHolder holder = event.getInventory().getHolder(); |
467 |
|
if (holder instanceof Chest || holder instanceof DoubleChest) { |
468 |
|
Location loc = getChestLocation(holder); |
469 |
|
|
470 |
|
ChestBean chest = chestMap.get( loc ); |
471 |
|
if (chest == null) { |
472 |
|
return; //chest not surveyed by this plugin |
473 |
|
} |
474 |
|
|
475 |
|
if (chest.getChestType() != ChestBean.SNITCHING) { |
476 |
|
return; // not a snitching chest |
477 |
|
} |
478 |
|
|
479 |
|
|
480 |
|
Player player = (Player) event.getPlayer(); |
481 |
|
if (player.getName().equals(chest.getOwner() )) { |
482 |
|
return; //chest is owned by it's own player |
483 |
|
} |
484 |
|
|
485 |
|
Set<String> players = Util.stringToSet( chest.getModifyPlayers() ); |
486 |
|
if ( players.contains(player.getName()) ) { |
487 |
|
return; //this player is on the whitelist so he may open |
488 |
|
} |
489 |
|
|
490 |
|
|
491 |
|
ItemCount contents = countItems( event.getInventory().getContents() ); |
492 |
|
|
493 |
|
contentMap.put(player.getName(), contents ); |
494 |
|
} |
495 |
|
} |
496 |
|
|
497 |
|
@EventHandler |
498 |
|
public void onChestClose(InventoryCloseEvent event) { |
499 |
|
if (! (event.getPlayer() instanceof Player)) { |
500 |
|
return; |
501 |
|
} |
502 |
|
|
503 |
|
|
504 |
|
InventoryHolder holder = event.getInventory().getHolder(); |
505 |
|
if (holder instanceof Chest || holder instanceof DoubleChest) { |
506 |
|
Location loc = getChestLocation(holder); |
507 |
|
ChestBean chest = chestMap.get(loc); |
508 |
|
|
509 |
|
if (chest == null) { //chest was not a snitching chest |
510 |
|
return; |
511 |
|
} |
512 |
|
|
513 |
|
if (chest.getChestType() != ChestBean.SNITCHING) { |
514 |
|
return; // not a snitching chest |
515 |
|
} |
516 |
|
|
517 |
|
|
518 |
|
OfflinePlayer owner = server.getOfflinePlayer( chest.getOwner() ); |
519 |
|
|
520 |
|
|
521 |
|
Player player = (Player) event.getPlayer(); |
522 |
|
|
523 |
|
ItemCount savedContent = contentMap.get( player.getName() ); |
524 |
|
|
525 |
|
if (savedContent == null) { |
526 |
|
return; |
527 |
|
} |
528 |
|
|
529 |
|
contentMap.remove( player.getName() ); |
530 |
|
|
531 |
|
ItemCount content = countItems( event.getInventory().getContents() ); |
532 |
|
|
533 |
|
Set<Integer> combinedKeyset = new TreeSet<Integer>(); |
534 |
|
combinedKeyset.addAll( savedContent.keySet() ); |
535 |
|
combinedKeyset.addAll( content.keySet() ); |
536 |
|
|
537 |
|
for (Integer item : combinedKeyset ) { |
538 |
|
Integer savedcount = savedContent.get(item); |
539 |
|
Integer count = content.get(item); |
540 |
|
|
541 |
|
if (savedcount == null) |
542 |
|
savedcount = 0; |
543 |
|
if (count == null) |
544 |
|
count = 0; |
545 |
|
|
546 |
|
|
547 |
|
int diff = Math.abs( savedcount - count); |
548 |
|
|
549 |
|
if (diff > 0) { |
550 |
|
String material = Material.getMaterial(item).name(); |
551 |
|
String msg = null; |
552 |
|
|
553 |
|
if (count > savedcount) { |
554 |
|
msg = player.getName() + " added " + diff + " units of " + material + "(" +item + ") to " + owner.getName() + "'s chest at " + loc.getWorld().getName() + "," + loc.getBlockX() + "," +loc.getBlockY() + "," + loc.getBlockZ(); |
555 |
|
} else { //(count < savedcount) |
556 |
|
msg = player.getName() + " removed " + diff + " units of " + material + "(" +item + ") from " + owner.getName() + "'s chest at " + loc.getWorld().getName() + "," + loc.getBlockX() + "," +loc.getBlockY() + "," + loc.getBlockZ(); |
557 |
|
} |
558 |
|
|
559 |
|
|
560 |
|
server.getLogger().info( "[AdvancedChest]" + msg); |
561 |
|
plugin.getMessageWrapper().sendMessage("system", owner, msg); |
562 |
|
} |
563 |
|
|
564 |
|
} |
565 |
|
|
566 |
|
|
567 |
|
} |
568 |
|
} |
569 |
|
|
570 |
|
ItemCount countItems(ItemStack[] input) { |
571 |
|
ItemCount output = new ItemCount(); |
572 |
|
for (int i=0; i<input.length; i++) { |
573 |
|
ItemStack current = input[i]; |
574 |
|
if (current == null) |
575 |
|
continue; |
576 |
|
|
577 |
|
int type = current.getTypeId(); |
578 |
|
|
579 |
|
Integer amount = output.get(type); |
580 |
|
if (amount == null) |
581 |
|
amount = 0; |
582 |
|
|
583 |
|
output.put(type, amount + current.getAmount() ); |
584 |
|
} |
585 |
|
return output; |
586 |
|
} |
587 |
|
/* |
588 |
|
ItemStack[] cloneItemStacks(ItemStack[] input) { |
589 |
|
ItemStack[] output = new ItemStack[ input.length ]; |
590 |
|
for (int i=0; i<input.length; i++) { |
591 |
|
if (input[i] != null) { |
592 |
|
output[i] = input[i].clone(); |
593 |
|
} else { |
594 |
|
output[i] = new ItemStack(0, 0); |
595 |
|
} |
596 |
|
} |
597 |
|
return output; |
598 |
|
}*/ |
599 |
|
|
600 |
|
|
601 |
} |
} |