/[projects]/miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/chests/AdvancedChest.java
ViewVC logotype

Annotation of /miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/chests/AdvancedChest.java

Parent Directory Parent Directory | Revision Log Revision Log


Revision 2432 - (hide annotations) (download)
Mon Mar 9 13:55:54 2015 UTC (9 years, 2 months ago) by torben
File size: 18133 byte(s)
Remove/silence warnings
1 torben 1805 package dk.thoerup.bukkit.hoeruputils.chests;
2    
3    
4     import java.util.HashMap;
5 torben 2426 import java.util.HashSet;
6 torben 1805 import java.util.List;
7 torben 1807 import java.util.Set;
8     import java.util.TreeMap;
9     import java.util.TreeSet;
10 torben 1805
11     import org.bukkit.ChatColor;
12     import org.bukkit.Location;
13     import org.bukkit.Material;
14 torben 1807 import org.bukkit.OfflinePlayer;
15 torben 1805 import org.bukkit.Server;
16     import org.bukkit.World;
17     import org.bukkit.block.Block;
18     import org.bukkit.block.Chest;
19     import org.bukkit.block.DoubleChest;
20     import org.bukkit.command.Command;
21     import org.bukkit.command.CommandExecutor;
22     import org.bukkit.command.CommandSender;
23     import org.bukkit.entity.Player;
24     import org.bukkit.event.EventHandler;
25     import org.bukkit.event.Listener;
26     import org.bukkit.event.block.Action;
27     import org.bukkit.event.block.BlockBreakEvent;
28 torben 1868 import org.bukkit.event.block.BlockBurnEvent;
29 torben 1805 import org.bukkit.event.block.BlockPlaceEvent;
30 torben 1806 import org.bukkit.event.entity.EntityExplodeEvent;
31 torben 1807 import org.bukkit.event.inventory.InventoryCloseEvent;
32     import org.bukkit.event.inventory.InventoryOpenEvent;
33 torben 1805 import org.bukkit.event.player.PlayerInteractEvent;
34     import org.bukkit.inventory.InventoryHolder;
35 torben 1807 import org.bukkit.inventory.ItemStack;
36 torben 1805
37     import dk.thoerup.bukkit.hoeruputils.HoerupUtilsPlugin;
38 torben 1807 import dk.thoerup.bukkit.hoeruputils.Util;
39 torben 1805
40    
41 torben 1807
42     public class AdvancedChest implements Listener, CommandExecutor{
43    
44     class ItemCount extends TreeMap<Integer,Integer> {
45     private static final long serialVersionUID = 1L;
46     };
47 torben 1949
48 torben 1807 HashMap<String, ItemCount> contentMap = new HashMap<String, ItemCount>();
49 torben 1949
50    
51 torben 1807 HashMap<Location,ChestBean> chestMap = new HashMap<Location, ChestBean>();
52 torben 1805
53 torben 1949
54 torben 1805 HoerupUtilsPlugin plugin;
55     Server server;
56 torben 1949
57 torben 1807 public AdvancedChest(HoerupUtilsPlugin plugin, Runnable r) {
58 torben 1805 this.plugin = plugin;
59     server = plugin.getServer();
60     try {
61     loadChests();
62     } catch (Exception e) {
63     e.printStackTrace();
64     //r.run();
65     loadChests();
66     }
67     }
68    
69 torben 1949
70 torben 1805 @Override
71     public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
72     if (! (sender instanceof Player) ) {
73     sender.sendMessage("this is not a console command!");
74     return true;
75     }
76 torben 1949
77 torben 1805 Player player = (Player) sender;
78 torben 1949
79 torben 1807 if (args.length == 0) {
80     player.sendMessage("Usage:");
81 torben 1869 player.sendMessage("/chest (status|lock|snitch|remove|addplayer|removeplayer|setowner|comment) [player]");
82 torben 1807 return true;
83     }
84 torben 1949
85    
86 torben 2429 Block b = player.getTargetBlock( (Set<Material>)null, 30);
87 torben 2432 Material mat = b.getType();
88    
89     if (mat != Material.CHEST && mat != Material.HOPPER) {
90 torben 1949 player.sendMessage("[Chest] Please look at the chest/hopper you want to protect");
91 torben 1805 return true;
92     }
93 torben 1949
94 torben 1807 Location loc = b.getLocation();
95 torben 1949 Location loc2 = null;
96 torben 2432 if ( mat == Material.HOPPER) { //dont find neighbours for Hoppers
97 torben 1949 loc2 = getNeighborChest(loc);
98     }
99    
100 torben 1807 ChestBean chest = chestMap.get(loc);
101     String cmd = args[0].toLowerCase();
102 torben 1949
103 torben 1807 if (cmd.equals("status")) {
104     if (chest != null) {
105     String mode = "";
106     switch (chest.getChestType()) {
107     case ChestBean.LOCKED:
108     mode = "locked";
109     break;
110     case ChestBean.SNITCHING:
111     mode = "snitching";
112     break;
113     default:
114     mode = "unknown ??";
115     }
116 torben 1949
117 torben 1807 player.sendMessage(ChatColor.GREEN + "Chest is a " + mode + " chest owned by " + chest.getOwner());
118     player.sendMessage(ChatColor.GREEN + "Allowed players: " + chest.getModifyPlayers() );
119 torben 1869 player.sendMessage(ChatColor.GREEN + "Comment: " + chest.getComment() );
120 torben 1807 } else {
121     player.sendMessage(ChatColor.GREEN + "The chest is not protected");
122     }
123     return true;
124     }
125 torben 1949
126 torben 1807 if (cmd.equals("lock") || cmd.equals("snitch")) {
127     if (chest == null) {
128     chest = createChest(player.getName(), "", loc);
129     if (loc2 != null) {
130     chest.setDoublechest(true);
131     }
132     String modeStr = "";
133     if (cmd.equals("lock")) {
134     chest.setChestType( ChestBean.LOCKED);
135     modeStr = "locked";
136     } else {
137     chest.setChestType( ChestBean.SNITCHING);
138     modeStr = "snitching";
139     }
140     chest.setModifyPlayers("");
141 torben 1869 chest.setComment("");
142 torben 1807 addChest(loc, chest);
143     player.sendMessage("Chest is now " + modeStr);
144     } else {
145 torben 1874 server.getLogger().info( player.getName() + " tried to protect a chest owned by " + chest.getOwner() );
146 torben 1807 player.sendMessage("This chest is already protected");
147     }
148     return true;
149     }
150 torben 1949
151 torben 1807 if (cmd.equals("remove")) {
152 torben 1853 if (chest == null) {
153     player.sendMessage("This chest is not protected");
154     return true;
155     }
156 torben 1915 if ( chest.getOwner().equals( player.getName() ) || player.isOp() ) {
157     //do nothing
158     } else {
159 torben 1852 player.sendMessage("You can not remove lock from a chest you don't own");
160 torben 1874 server.getLogger().info( player.getName() + " tried to remove protection froma chest owned by " + chest.getOwner() );
161 torben 1852 return true;
162     }
163 torben 1853
164     player.sendMessage("[LockedChest] Removing protection from chest");
165     removeChest(loc);
166    
167 torben 1807 return true;
168     }
169 torben 1854
170     if (cmd.equals("setowner")) {
171     if (chest == null) {
172     player.sendMessage("This chest is not protected");
173     return true;
174     }
175 torben 1915 if ( chest.getOwner().equals( player.getName() ) || player.isOp() ) {
176     //do nothing
177     } else {
178 torben 1854 player.sendMessage("You can not set new owner of a chest you dont own");
179 torben 1874 server.getLogger().info( player.getName() + " tried to set owner on a chest owned by " + chest.getOwner() );
180 torben 1854 return true;
181     }
182     if (args.length != 2) {
183     player.sendMessage("You need to specify which player should own this chest");
184     return true;
185     }
186 torben 2432
187     @SuppressWarnings("deprecation")//user by name is our only option here
188 torben 1854 OfflinePlayer p2 = server.getOfflinePlayer(args[1]);
189 torben 2432
190 torben 1854 if ( p2.hasPlayedBefore() == false && p2.isOnline() == false) {
191     player.sendMessage("Unknown user: " + args[1] );
192     return true;
193     }
194     chest.setOwner( p2.getName() );
195     plugin.getDatabase().save( chest );
196     player.sendMessage("ok");
197     return true;
198     }
199 torben 1949
200 torben 1807 if (cmd.equals("addplayer") || cmd.equals("removeplayer")) {
201     if (chest == null) {
202     player.sendMessage("This chest is not protected");
203     return true;
204     }
205 torben 1852 if (! chest.getOwner().equals( player.getName() ) ) {
206     player.sendMessage("You can not add/remove players from a chest you don't own");
207 torben 1874 server.getLogger().info( player.getName() + " tried to add/remove player on a chest owned by " + chest.getOwner() );
208 torben 1852 return true;
209     }
210 torben 1807 if (args.length != 2) {
211     player.sendMessage("You need to specify which player to add or remove");
212     return true;
213     }
214 torben 2432
215     @SuppressWarnings("deprecation")//user by name is our only option here
216 torben 1807 OfflinePlayer p2 = server.getOfflinePlayer(args[1]);
217     if ( p2.hasPlayedBefore() == false && p2.isOnline() == false) {
218     player.sendMessage("Unknown user: " + args[1] );
219     return true;
220     }
221 torben 1949
222 torben 1807 Set<String> players = Util.stringToSet( chest.getModifyPlayers() );
223     if (cmd.equals("addplayer")) {
224 torben 1808 players.add(p2.getName());
225 torben 1807 } else {
226 torben 1808 players.remove(p2.getName());
227 torben 1807 }
228 torben 1949
229 torben 1807 chest.setModifyPlayers( Util.setToString(players) );
230     plugin.getDatabase().save( chest );
231     player.sendMessage("ok");
232     return true;
233     }
234 torben 1869 if (cmd.equals("comment")) {
235     if (chest == null) {
236     player.sendMessage("This chest is not protected");
237     return true;
238     }
239 torben 1874 if (! chest.getOwner().equals( player.getName() ) ) {
240 torben 1869 player.sendMessage("You can not comment a chest you don't own");
241 torben 1874 server.getLogger().info( player.getName() + " tried to comment on a chest owned by " + chest.getOwner() );
242 torben 1869 return true;
243     }
244    
245     StringBuilder sb = new StringBuilder();
246     for (int i=1; i<args.length; i++) {
247     sb.append(args[i]).append(" ");
248     }
249     String comment = sb.toString().trim();
250    
251     chest.setComment( comment );
252     plugin.getDatabase().save( chest );
253     player.sendMessage("Comment set");
254    
255     return true;
256     }
257 torben 1949
258 torben 1807 /*
259 torben 1805 if (chest != null) {
260     if (chest.getOwner().equals(player.getName())) {
261     player.sendMessage("[LockedChest] Removing lock from chest");
262     removeChest(loc);
263     } else {
264 torben 1807 player.sendMessage("[LockedChest] Chest is already protected");
265 torben 1805 }
266 torben 1949
267 torben 1805 return true;
268     }
269 torben 1949
270 torben 1805 chest = createChest(player.getName(), "", loc);
271     if (loc2 != null) {
272     chest.setDoublechest(true);
273     }
274 torben 1949
275 torben 1805 addChest(loc, chest);
276 torben 1949
277    
278 torben 1805 player.sendMessage("[LockedChest] Chest is now locked");
279 torben 1949 */
280    
281 torben 1807 player.sendMessage("Unknown argument, " + cmd);
282 torben 1949
283 torben 1805 return true;
284     }
285 torben 1949
286 torben 1805 @EventHandler
287     public void onBlockBreak(BlockBreakEvent event) {
288     Location loc = event.getBlock().getLocation();
289 torben 1807 ChestBean chest = chestMap.get(loc);
290 torben 1805 if (chest != null) {
291     if (chest.getOwner().equals(event.getPlayer().getName())) {
292     removeChest(loc);
293 torben 1807 event.getPlayer().sendMessage("[AdvancedChest] The destroyed chest was locked or snitching");
294 torben 1805 } else {
295     event.setCancelled(true);
296     event.getPlayer().sendMessage("You can't destroy that chest");
297 torben 1871 server.getLogger().info( "[AdvancedChest] " + event.getPlayer().getName() + " tried breaking a chest owned by " + chest.getOwner() + chest.getCommentString() );
298 torben 1805 }
299     }
300     }
301 torben 1807 public void addChest(Location loc, ChestBean chest) {
302 torben 1805 chestMap.put(loc, chest);
303     if (chest.isDoublechest()) {
304     Location loc2 = getNeighborChest(loc);
305     chestMap.put(loc2, chest);
306     }
307     plugin.getDatabase().save(chest);
308 torben 1949
309 torben 1805 reloadChests();
310 torben 1949
311 torben 1805 }
312 torben 1949
313 torben 1805 void removeChest(Location loc) {
314 torben 1807 ChestBean chest = chestMap.remove(loc);
315 torben 1805 if (chest != null) {
316     if (chest.isDoublechest()){
317     Location loc2 = getNeighborChest(loc);
318     chestMap.remove(loc2);
319     }
320     plugin.getDatabase().delete(chest);
321     }
322     }
323 torben 1949
324 torben 1805 int loadChestsWorker() {
325 torben 1807 List<ChestBean> chestlist = plugin.getDatabase().find( ChestBean.class).findList();
326     for (ChestBean chest : chestlist) {
327 torben 1805 Location loc = getChestLocation(server, chest);
328     chestMap.put(loc, chest);
329 torben 1949
330 torben 1805 if (chest.isDoublechest()) {
331     Location loc2 = getNeighborChest(loc);
332     chestMap.put(loc2, chest);
333     }
334     }
335    
336     return chestlist.size();
337     }
338 torben 1949
339 torben 1805 void reloadChests() {
340     chestMap.clear();
341     loadChestsWorker();
342     }
343 torben 1949
344 torben 1805 void loadChests() {
345     int count = loadChestsWorker();
346 torben 1813 server.getLogger().info("[AdvancedChest] loaded " + count + " chests");
347 torben 1805 }
348 torben 1949
349    
350 torben 1807 public ChestBean createChest(String owner, String description, Location loc) {
351 torben 1949
352 torben 1807 ChestBean chest = new ChestBean();
353 torben 1805 chest.setOwner(owner);
354     chest.setDescription(description);
355     setChestLocation(chest, loc);
356    
357     return chest;
358     }
359 torben 1949
360    
361 torben 1807 public void setChestLocation(ChestBean chest, Location loc) {
362 torben 1805 chest.setWorld( loc.getWorld().getName() );
363     chest.setX( loc.getBlockX() );
364     chest.setY( loc.getBlockY() );
365     chest.setZ( loc.getBlockZ() );
366     }
367 torben 1949
368 torben 1807 public Location getChestLocation(Server server, ChestBean chest) {
369 torben 1805 World wrld = server.getWorld(chest.getWorld());
370     return new Location(wrld,chest.getX(),chest.getY(),chest.getZ());
371     }
372    
373 torben 1949
374 torben 1805 /*
375     void saveChests() {
376 torben 1949
377 torben 1805 }*/
378 torben 1949
379 torben 1805 Location getNeighborChest(Location loc) {
380     World world = loc.getWorld();
381 torben 1949
382 torben 1805 Location target = new Location(world, loc.getX()+1, loc.getY(), loc.getZ() );
383     if (world.getBlockAt(target).getType() == Material.CHEST )
384     return target;
385 torben 1949
386 torben 1805 target = new Location(world, loc.getX()-1, loc.getY(), loc.getZ() );
387     if (world.getBlockAt(target).getType() == Material.CHEST )
388     return target;
389    
390     target = new Location(world, loc.getX(), loc.getY(), loc.getZ() +1);
391     if (world.getBlockAt(target).getType() == Material.CHEST )
392     return target;
393    
394     target = new Location(world, loc.getX(), loc.getY(), loc.getZ() -1);
395     if (world.getBlockAt(target).getType() == Material.CHEST )
396     return target;
397 torben 1949
398 torben 1805 return null;
399     }
400 torben 1949
401    
402 torben 1805 Location getChestLocation(InventoryHolder holder) {
403     Location loc;
404     if ( holder instanceof Chest) {
405     loc = ( (Chest)holder).getLocation();
406     } else {
407     loc = ( (DoubleChest)holder).getLocation();
408     }
409 torben 1949
410 torben 1805 loc.setX( loc.getBlockX() ); //round to integer, since double chests apparently are placed at pos + 0.5
411     loc.setZ( loc.getBlockZ() ); // -- // --
412 torben 1949
413 torben 1805 return loc;
414     }
415 torben 1949
416 torben 1805 @EventHandler
417     public void onChestPlaced(BlockPlaceEvent event) {
418     Block block = event.getBlock();
419 torben 1949
420 torben 1805 if (block.getType() != Material.CHEST) {
421     return;
422     }
423 torben 1949
424 torben 1805 Location chestloc = getNeighborChest( block.getLocation() );
425 torben 1949 if (chestloc == null)
426     return;
427 torben 1805
428 torben 1949 ChestBean chest = chestMap.get(chestloc);
429    
430     if (chest == null)//the neighbor is not a locked chest
431     return;
432    
433    
434     chest.setDoublechest(true);
435     addChest(chestloc, chest);
436    
437    
438     event.getPlayer().sendMessage( "[AdvancedChest] Chest has been expanded" );
439 torben 1805 }
440 torben 1806
441    
442     @EventHandler
443     public void onChestExplode(EntityExplodeEvent event) {
444     for (Block b : event.blockList() ) {
445 torben 1807 ChestBean chest = chestMap.get( b.getLocation() );
446 torben 1806 if (chest != null) {
447 torben 1871 server.getLogger().info( "[AdvancedChest] Prevented an explosion from destroying chest owned by " + chest.getOwner() + chest.getCommentString() );
448 torben 1806 event.setCancelled( true );
449     return;
450     }
451     }
452 torben 1868 }
453    
454     @EventHandler
455     public void onChestBurn(BlockBurnEvent event) {
456     ChestBean chest = chestMap.get( event.getBlock().getLocation() );
457     if (chest != null) {
458 torben 1871 server.getLogger().info( "[AdvancedChest] prevented a fire from destrying chest owned by " + chest.getOwner() + chest.getCommentString() );
459 torben 1868 event.setCancelled( true);
460     }
461     }
462 torben 1949
463 torben 1805 // prevent a user from opening a chest
464     @EventHandler
465     public void onChestInteract(PlayerInteractEvent event) {
466     if (event.getAction() == Action.RIGHT_CLICK_BLOCK) {
467     Block b = event.getClickedBlock();
468 torben 1949
469 torben 1805 if (b.getType() == Material.CHEST) {
470 torben 1949
471 torben 1805 Location loc = b.getLocation();
472 torben 1949
473 torben 1807 ChestBean chest = chestMap.get( loc );
474 torben 1805 if (chest == null) {
475     return; //chest not surveyed by this plugin
476     }
477 torben 1949
478 torben 1807 if (chest.getChestType() != ChestBean.LOCKED ) {
479     return; //this is not a locked chests
480     }
481 torben 1949
482 torben 1805 Player player = (Player) event.getPlayer();
483     if (player.getName().equals(chest.getOwner() )) {
484     return; //chest is opened by it's owner
485     }
486 torben 1949
487 torben 1904 Set<String> players = chest.getModifyPlayersSet() ;
488 torben 1809 if ( players.contains(player.getName()) ) {
489     return; //this player is on the whitelist so he may open
490 torben 1805 }
491    
492 torben 1809
493 torben 1871 server.getLogger().info( "[AdvancedChest] " + event.getPlayer().getName() + " tried opening a chest owned by " + chest.getOwner() + chest.getCommentString() );
494 torben 1805 player.sendMessage( ChatColor.BLUE + "Sorry but this chest is locked !");
495     event.setCancelled(true);
496     }
497     }
498     }
499 torben 1807
500     @EventHandler
501     public void onChestOpen(InventoryOpenEvent event) {
502 torben 1949
503 torben 1807 if (! (event.getPlayer() instanceof Player)) {
504     return;
505     }
506    
507    
508 torben 1949
509 torben 1807 InventoryHolder holder = event.getInventory().getHolder();
510     if (holder instanceof Chest || holder instanceof DoubleChest) {
511     Location loc = getChestLocation(holder);
512 torben 1949
513 torben 1807 ChestBean chest = chestMap.get( loc );
514     if (chest == null) {
515     return; //chest not surveyed by this plugin
516     }
517 torben 1949
518 torben 1807 if (chest.getChestType() != ChestBean.SNITCHING) {
519     return; // not a snitching chest
520     }
521 torben 1949
522    
523 torben 1807 Player player = (Player) event.getPlayer();
524     if (player.getName().equals(chest.getOwner() )) {
525     return; //chest is owned by it's own player
526 torben 1809 }
527 torben 1949
528 torben 1904 Set<String> players = chest.getModifyPlayersSet();
529 torben 1809 if ( players.contains(player.getName()) ) {
530     return; //this player is on the whitelist so he may open
531     }
532 torben 1949
533    
534 torben 1871 server.getLogger().info( "[AdvancedChest] " + event.getPlayer().getName() + " opened a snitching chest owned by " + chest.getOwner() + chest.getCommentString() );
535 torben 1869
536 torben 1807 ItemCount contents = countItems( event.getInventory().getContents() );
537 torben 1949
538 torben 1807 contentMap.put(player.getName(), contents );
539     }
540     }
541 torben 1949
542 torben 1807 @EventHandler
543     public void onChestClose(InventoryCloseEvent event) {
544     if (! (event.getPlayer() instanceof Player)) {
545     return;
546     }
547 torben 1949
548    
549 torben 1807 InventoryHolder holder = event.getInventory().getHolder();
550     if (holder instanceof Chest || holder instanceof DoubleChest) {
551     Location loc = getChestLocation(holder);
552     ChestBean chest = chestMap.get(loc);
553 torben 1949
554 torben 1807 if (chest == null) { //chest was not a snitching chest
555     return;
556     }
557 torben 1949
558 torben 1807 if (chest.getChestType() != ChestBean.SNITCHING) {
559     return; // not a snitching chest
560     }
561 torben 1949
562    
563 torben 1807 OfflinePlayer owner = server.getOfflinePlayer( chest.getOwner() );
564 torben 1949
565    
566 torben 1807 Player player = (Player) event.getPlayer();
567 torben 1949
568 torben 1807 ItemCount savedContent = contentMap.get( player.getName() );
569 torben 1949
570 torben 1807 if (savedContent == null) {
571     return;
572     }
573 torben 1949
574 torben 1807 contentMap.remove( player.getName() );
575 torben 1949
576 torben 1807 ItemCount content = countItems( event.getInventory().getContents() );
577 torben 1949
578 torben 1807 Set<Integer> combinedKeyset = new TreeSet<Integer>();
579     combinedKeyset.addAll( savedContent.keySet() );
580     combinedKeyset.addAll( content.keySet() );
581 torben 1949
582 torben 1807 for (Integer item : combinedKeyset ) {
583     Integer savedcount = savedContent.get(item);
584     Integer count = content.get(item);
585 torben 1949
586 torben 1807 if (savedcount == null)
587     savedcount = 0;
588     if (count == null)
589     count = 0;
590 torben 1949
591    
592 torben 1807 int diff = Math.abs( savedcount - count);
593 torben 1949
594 torben 1807 if (diff > 0) {
595     String material = Material.getMaterial(item).name();
596     String msg = null;
597 torben 1949
598 torben 1807 if (count > savedcount) {
599 torben 1916 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();
600 torben 1807 } else { //(count < savedcount)
601 torben 1916 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();
602 torben 1807 }
603 torben 1949
604    
605 torben 1813 server.getLogger().info( "[AdvancedChest]" + msg);
606 torben 1807 plugin.getMessageWrapper().sendMessage("system", owner, msg);
607     }
608 torben 1949
609 torben 1807 }
610 torben 1949
611    
612 torben 1807 }
613     }
614 torben 1949
615 torben 1807 ItemCount countItems(ItemStack[] input) {
616     ItemCount output = new ItemCount();
617     for (int i=0; i<input.length; i++) {
618     ItemStack current = input[i];
619     if (current == null)
620     continue;
621 torben 1949
622 torben 1807 int type = current.getTypeId();
623 torben 1949
624 torben 1807 Integer amount = output.get(type);
625     if (amount == null)
626     amount = 0;
627 torben 1949
628 torben 1807 output.put(type, amount + current.getAmount() );
629     }
630     return output;
631     }
632     /*
633     ItemStack[] cloneItemStacks(ItemStack[] input) {
634     ItemStack[] output = new ItemStack[ input.length ];
635     for (int i=0; i<input.length; i++) {
636     if (input[i] != null) {
637     output[i] = input[i].clone();
638     } else {
639     output[i] = new ItemStack(0, 0);
640     }
641     }
642     return output;
643     }*/
644 torben 1949
645    
646 torben 1805 }

  ViewVC Help
Powered by ViewVC 1.1.20