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; |
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 |
|
|
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 { |
184 |
return true; |
return true; |
185 |
} |
} |
186 |
|
|
187 |
@SuppressWarnings("deprecation")//user by name is our only option here |
//@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) { |
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 |
} |
} |
212 |
return true; |
return true; |
213 |
} |
} |
214 |
|
|
215 |
@SuppressWarnings("deprecation")//user by name is our only option here |
//@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] ); |
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 |
} |
} |
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; |
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 |
|
|
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); |
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; |
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 |
|
|
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) |