81 |
if (chest.getOwner().equals(player.getName())) { |
if (chest.getOwner().equals(player.getName())) { |
82 |
player.sendMessage("[SnitchingChest] Removing surveillance from chest"); |
player.sendMessage("[SnitchingChest] Removing surveillance from chest"); |
83 |
removeChest(loc); |
removeChest(loc); |
|
if (loc2 != null) { |
|
|
removeChest(loc2); |
|
|
} |
|
84 |
} else { |
} else { |
85 |
player.sendMessage("[SnitchingChest] Chest is already under surveillance"); |
player.sendMessage("[SnitchingChest] Chest is already under surveillance"); |
86 |
} |
} |
88 |
return true; |
return true; |
89 |
} |
} |
90 |
|
|
91 |
SnitchingChestBean chest1 = createChest(player.getName(), "", loc); |
chest = createChest(player.getName(), "", loc); |
|
addChest(loc, chest1); |
|
92 |
if (loc2 != null) { |
if (loc2 != null) { |
93 |
|
chest.setDoublechest(true); |
|
SnitchingChestBean chest2 = createChest (player.getName(), "", loc2); |
|
|
addChest(loc, chest2); |
|
94 |
} |
} |
95 |
|
addChest(loc, chest); |
96 |
|
|
97 |
|
|
98 |
player.sendMessage("[SnitchingChest] Chest is now under surveillance"); |
player.sendMessage("[SnitchingChest] Chest is now under surveillance"); |
99 |
|
|
117 |
} |
} |
118 |
public void addChest(Location loc, SnitchingChestBean chest) { |
public void addChest(Location loc, SnitchingChestBean chest) { |
119 |
chestMap.put(loc, chest); |
chestMap.put(loc, chest); |
120 |
|
if (chest.isDoublechest()) { |
121 |
|
Location loc2 = getNeighborChest(loc); |
122 |
|
chestMap.put(loc2, chest); |
123 |
|
} |
124 |
plugin.getDatabase().save(chest); |
plugin.getDatabase().save(chest); |
125 |
|
|
126 |
|
reloadChests(); |
127 |
|
|
128 |
} |
} |
129 |
|
|
130 |
void removeChest(Location loc) { |
void removeChest(Location loc) { |
131 |
SnitchingChestBean chest = chestMap.remove(loc); |
SnitchingChestBean chest = chestMap.remove(loc); |
132 |
if (chest != null) { |
if (chest != null) { |
133 |
|
if (chest.isDoublechest()){ |
134 |
|
Location loc2 = getNeighborChest(loc); |
135 |
|
chestMap.remove(loc2); |
136 |
|
} |
137 |
plugin.getDatabase().delete(chest); |
plugin.getDatabase().delete(chest); |
138 |
} |
} |
139 |
} |
} |
140 |
|
|
141 |
void loadChests() { |
int loadChestsWorker() { |
142 |
List<SnitchingChestBean> chestlist = plugin.getDatabase().find( SnitchingChestBean.class).findList(); |
List<SnitchingChestBean> chestlist = plugin.getDatabase().find( SnitchingChestBean.class).findList(); |
143 |
for (SnitchingChestBean chest : chestlist) { |
for (SnitchingChestBean chest : chestlist) { |
144 |
Location loc = getChestLocation(server, chest); |
Location loc = getChestLocation(server, chest); |
145 |
chestMap.put(loc, chest); |
chestMap.put(loc, chest); |
146 |
|
|
147 |
|
if (chest.isDoublechest()) { |
148 |
|
Location loc2 = getNeighborChest(loc); |
149 |
|
chestMap.put(loc2, chest); |
150 |
|
} |
151 |
} |
} |
152 |
|
|
153 |
plugin.getLogger().info("[SnitchingChest] loaded " + chestMap.size() + " chests"); |
return chestlist.size(); |
154 |
|
} |
155 |
|
|
156 |
|
void reloadChests() { |
157 |
|
chestMap.clear(); |
158 |
|
loadChestsWorker(); |
159 |
|
} |
160 |
|
|
161 |
|
void loadChests() { |
162 |
|
int count = loadChestsWorker(); |
163 |
|
plugin.getLogger().info("[SnitchingChest] loaded " + count + " chests"); |
164 |
} |
} |
165 |
|
|
166 |
|
|
243 |
SnitchingChestBean chest = chestMap.get(chestloc); |
SnitchingChestBean chest = chestMap.get(chestloc); |
244 |
|
|
245 |
if (chest != null) { //the neighbor is a snitching chest |
if (chest != null) { //the neighbor is a snitching chest |
246 |
SnitchingChestBean newchest = createChest( chest.getOwner(), "", chestloc); |
//SnitchingChestBean newchest = createChest( chest.getOwner(), "", chestloc); |
247 |
addChest(chestloc, newchest); |
//plugin.getDatabase().save(chest); |
248 |
|
|
249 |
|
chest.setDoublechest(true); |
250 |
|
addChest(chestloc, chest); |
251 |
|
|
252 |
|
|
253 |
event.getPlayer().sendMessage( "[SnitchingChest] Chest has been expanded" ); |
event.getPlayer().sendMessage( "[SnitchingChest] Chest has been expanded" ); |
254 |
} |
} |
255 |
|
|
330 |
|
|
331 |
|
|
332 |
int diff = Math.abs( savedcount - count); |
int diff = Math.abs( savedcount - count); |
|
String msg = null; |
|
|
if (count > savedcount) { |
|
|
msg = player.getName() + " added " + diff + " units of " + item + " to " + owner.getName() + "'s chest"; |
|
|
} |
|
|
if (count < savedcount) { |
|
|
msg = player.getName() + " removed " + diff + " units of " + item + " from " + owner.getName() + "'s chest"; |
|
|
} |
|
333 |
|
|
334 |
if (msg != null) { |
if (diff > 0) { |
335 |
|
String material = Material.getMaterial(item).name(); |
336 |
|
String msg = null; |
337 |
|
|
338 |
|
if (count > savedcount) { |
339 |
|
msg = player.getName() + " added " + diff + " units of " + material + "(" +item + ") to " + owner.getName() + "'s chest at " + loc.getWorld().getName() + "," + loc.getBlockX() + "," +loc.getBlockY() + "," + loc.getBlockZ(); |
340 |
|
} else { //(count < savedcount) |
341 |
|
msg = player.getName() + " removed " + diff + " units of " + material + "(" +item + ") from " + owner.getName() + "'s chest at " + loc.getWorld().getName() + "," + loc.getBlockX() + "," +loc.getBlockY() + "," + loc.getBlockZ(); |
342 |
|
} |
343 |
|
|
344 |
|
|
345 |
plugin.getLogger().info(msg); |
plugin.getLogger().info(msg); |
346 |
plugin.getMessageWrapper().sendMessage(owner, msg); |
plugin.getMessageWrapper().sendMessage(owner, msg); |
347 |
} |
} |