/[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 2429 by torben, Mon Mar 9 12:29:22 2015 UTC revision 3207 by torben, Sat Aug 19 14:06:42 2017 UTC
# Line 1  Line 1 
1  package dk.thoerup.bukkit.hoeruputils.chests;  package dk.thoerup.bukkit.hoeruputils.chests;
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 36  import org.bukkit.inventory.ItemStack; Line 35  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;  import dk.thoerup.bukkit.hoeruputils.Util;
38    import io.ebean.Ebean;
39    
40    
41    
42  public class AdvancedChest  implements Listener, CommandExecutor{  public class AdvancedChest  implements Listener, CommandExecutor{
43    
44          class ItemCount extends TreeMap<Integer,Integer> {          class ItemCount extends TreeMap<Material,Integer> {
45                  private static final long serialVersionUID = 1L;                  private static final long serialVersionUID = 1L;
46          };          };
47    
# Line 54  public class AdvancedChest  implements L Line 54  public class AdvancedChest  implements L
54          HoerupUtilsPlugin plugin;          HoerupUtilsPlugin plugin;
55          Server server;          Server server;
56    
57          public AdvancedChest(HoerupUtilsPlugin plugin, Runnable r) {          public AdvancedChest(HoerupUtilsPlugin plugin) {
58                  this.plugin = plugin;                  this.plugin = plugin;
59                  server = plugin.getServer();                  server = plugin.getServer();
60                  try {                  try {
# Line 84  public class AdvancedChest  implements L Line 84  public class AdvancedChest  implements L
84    
85    
86                  Block b = player.getTargetBlock( (Set<Material>)null, 30);                                        Block b = player.getTargetBlock( (Set<Material>)null, 30);                      
87                    Material mat = b.getType();
88                  if (b.getTypeId() != 54 && b.getTypeId() != 154) {                  
89                    if (mat != Material.CHEST && mat != Material.HOPPER) {
90                          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");
91                          return true;                          return true;
92                  }                  }
93    
94                  Location loc = b.getLocation();                  Location loc = b.getLocation();
95                  Location loc2 = null;                  Location loc2 = null;
96                  if ( b.getTypeId() == 54) { //dont find neighbours for Hoppers                  if ( mat == Material.HOPPER) { //dont find neighbours for Hoppers
97                          loc2 = getNeighborChest(loc);                          loc2 = getNeighborChest(loc);
98                  }                  }
99    
# Line 182  public class AdvancedChest  implements L Line 183  public class AdvancedChest  implements L
183                                  player.sendMessage("You need to specify which player should own this chest");                                  player.sendMessage("You need to specify which player should own this chest");
184                                  return true;                                  return true;
185                          }                          }
186                            
187                            //@SuppressWarnings("deprecation")//user by name is our only option here
188                          OfflinePlayer p2 = server.getOfflinePlayer(args[1]);                          OfflinePlayer p2 = server.getOfflinePlayer(args[1]);
189                            
190                          if ( p2.hasPlayedBefore() == false && p2.isOnline() == false) {                          if ( p2.hasPlayedBefore() == false && p2.isOnline() == false) {
191                                  player.sendMessage("Unknown user: " + args[1] );                                  player.sendMessage("Unknown user: " + args[1] );
192                                  return true;                                  return true;
193                          }                          }
194                          chest.setOwner( p2.getName() );                          chest.setOwner( p2.getName() );
195                          plugin.getDatabase().save( chest );                          Ebean.getDefaultServer().save( chest );
196                          player.sendMessage("ok");                          player.sendMessage("ok");
197                          return true;                          return true;
198                  }                  }
# Line 207  public class AdvancedChest  implements L Line 211  public class AdvancedChest  implements L
211                                  player.sendMessage("You need to specify which player to add or remove");                                  player.sendMessage("You need to specify which player to add or remove");
212                                  return true;                                  return true;
213                          }                          }
214                            
215                            //@SuppressWarnings("deprecation")//user by name is our only option here
216                          OfflinePlayer p2 = server.getOfflinePlayer(args[1]);                          OfflinePlayer p2 = server.getOfflinePlayer(args[1]);
217                          if ( p2.hasPlayedBefore() == false && p2.isOnline() == false) {                          if ( p2.hasPlayedBefore() == false && p2.isOnline() == false) {
218                                  player.sendMessage("Unknown user: " + args[1] );                                  player.sendMessage("Unknown user: " + args[1] );
# Line 221  public class AdvancedChest  implements L Line 227  public class AdvancedChest  implements L
227                          }                          }
228    
229                          chest.setModifyPlayers( Util.setToString(players) );                          chest.setModifyPlayers( Util.setToString(players) );
230                          plugin.getDatabase().save( chest );                          Ebean.getDefaultServer().save( chest );
231                          player.sendMessage("ok");                          player.sendMessage("ok");
232                          return true;                          return true;
233                  }                  }
# Line 243  public class AdvancedChest  implements L Line 249  public class AdvancedChest  implements L
249                          String comment = sb.toString().trim();                          String comment = sb.toString().trim();
250    
251                          chest.setComment( comment );                          chest.setComment( comment );
252                          plugin.getDatabase().save( chest );                          Ebean.getDefaultServer().save( chest );
253                          player.sendMessage("Comment set");                          player.sendMessage("Comment set");
254    
255                          return true;                          return true;
# Line 270  public class AdvancedChest  implements L Line 276  public class AdvancedChest  implements L
276    
277    
278                  player.sendMessage("[LockedChest] Chest is now locked");                  player.sendMessage("[LockedChest] Chest is now locked");
279                   */                   * /
280    
281                  player.sendMessage("Unknown argument, " + cmd);                  player.sendMessage("Unknown argument, " + cmd);
282    
# Line 298  public class AdvancedChest  implements L Line 304  public class AdvancedChest  implements L
304                          Location loc2 = getNeighborChest(loc);                          Location loc2 = getNeighborChest(loc);
305                          chestMap.put(loc2, chest);                          chestMap.put(loc2, chest);
306                  }                                }              
307                  plugin.getDatabase().save(chest);                  Ebean.getDefaultServer().save(chest);
308    
309                  reloadChests();                  reloadChests();
310    
# Line 311  public class AdvancedChest  implements L Line 317  public class AdvancedChest  implements L
317                                  Location loc2 = getNeighborChest(loc);                                  Location loc2 = getNeighborChest(loc);
318                                  chestMap.remove(loc2);                                  chestMap.remove(loc2);
319                          }                          }
320                          plugin.getDatabase().delete(chest);                          Ebean.getDefaultServer().delete(chest);
321                  }                  }
322          }          }
323    
324          int loadChestsWorker() {          int loadChestsWorker() {
325                  List<ChestBean> chestlist = plugin.getDatabase().find( ChestBean.class).findList();                  List<ChestBean> chestlist = Ebean.getDefaultServer().find( ChestBean.class).findList();
326                  for (ChestBean chest : chestlist) {                  for (ChestBean chest : chestlist) {
327                          Location loc = getChestLocation(server, chest);                          Location loc = getChestLocation(server, chest);
328                          chestMap.put(loc, chest);                                chestMap.put(loc, chest);      
# Line 368  public class AdvancedChest  implements L Line 374  public class AdvancedChest  implements L
374          /*          /*
375          void saveChests() {          void saveChests() {
376    
377          }*/          }* /
378    
379          Location getNeighborChest(Location loc) {          Location getNeighborChest(Location loc) {
380                  World world = loc.getWorld();                  World world = loc.getWorld();
# Line 569  public class AdvancedChest  implements L Line 575  public class AdvancedChest  implements L
575    
576                          ItemCount content = countItems( event.getInventory().getContents() );                          ItemCount content = countItems( event.getInventory().getContents() );
577    
578                          Set<Integer> combinedKeyset = new TreeSet<Integer>();                                            Set<Material> combinedKeyset = new TreeSet<Material>();                
579                          combinedKeyset.addAll( savedContent.keySet() );                          combinedKeyset.addAll( savedContent.keySet() );
580                          combinedKeyset.addAll( content.keySet() );                          combinedKeyset.addAll( content.keySet() );
581    
582                          for (Integer item : combinedKeyset ) {                          for (Material material : combinedKeyset ) {
583                                  Integer savedcount = savedContent.get(item);                                                              Integer savedcount = savedContent.get(material);                                
584                                  Integer count = content.get(item);                                  Integer count = content.get(material);
585    
586                                  if (savedcount == null)                                  if (savedcount == null)
587                                          savedcount = 0;                                          savedcount = 0;
# Line 586  public class AdvancedChest  implements L Line 592  public class AdvancedChest  implements L
592                                  int diff = Math.abs( savedcount - count);                                  int diff = Math.abs( savedcount - count);
593    
594                                  if (diff > 0) {                                  if (diff > 0) {
                                         String material = Material.getMaterial(item).name();  
595                                          String msg = null;                                          String msg = null;
596    
597                                          if (count > savedcount) {                                          if (count > savedcount) {
598                                                  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();
599                                          } else { //(count < savedcount)                                          } else { //(count < savedcount)
600                                                  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();
601                                          }                                          }
602    
603    
# Line 613  public class AdvancedChest  implements L Line 618  public class AdvancedChest  implements L
618                          if (current == null)                          if (current == null)
619                                  continue;                                  continue;
620    
621                          int type = current.getTypeId();                          Material type = current.getType();
622    
623                          Integer amount = output.get(type);                          Integer amount = output.get(type);
624                          if (amount == null)                          if (amount == null)
# Line 634  public class AdvancedChest  implements L Line 639  public class AdvancedChest  implements L
639                          }                          }
640                  }                  }
641                  return output;                  return output;
642          }*/          }* /
643    
644    
645  }  }
646    */

Legend:
Removed from v.2429  
changed lines
  Added in v.3207

  ViewVC Help
Powered by ViewVC 1.1.20