22 |
import org.bukkit.event.EventHandler; |
import org.bukkit.event.EventHandler; |
23 |
import org.bukkit.event.Listener; |
import org.bukkit.event.Listener; |
24 |
import org.bukkit.event.block.BlockBreakEvent; |
import org.bukkit.event.block.BlockBreakEvent; |
25 |
|
import org.bukkit.event.block.BlockPlaceEvent; |
26 |
import org.bukkit.event.inventory.InventoryCloseEvent; |
import org.bukkit.event.inventory.InventoryCloseEvent; |
27 |
import org.bukkit.event.inventory.InventoryOpenEvent; |
import org.bukkit.event.inventory.InventoryOpenEvent; |
28 |
import org.bukkit.inventory.InventoryHolder; |
import org.bukkit.inventory.InventoryHolder; |
92 |
} |
} |
93 |
|
|
94 |
SnitchingChestBean chest1 = createChest(player.getName(), "", loc); |
SnitchingChestBean chest1 = createChest(player.getName(), "", loc); |
|
//chestMap.put(loc, chest1); |
|
95 |
addChest(loc, chest1); |
addChest(loc, chest1); |
96 |
if (loc2 != null) { |
if (loc2 != null) { |
97 |
|
|
98 |
SnitchingChestBean chest2 = createChest (player.getName(), "", loc2); |
SnitchingChestBean chest2 = createChest (player.getName(), "", loc2); |
99 |
addChest(loc, chest2); |
addChest(loc, chest2); |
|
//chestMap.put(loc2, chest2 ); |
|
100 |
} |
} |
101 |
|
|
102 |
player.sendMessage("[SnitchingChest] Chest is now under surveillance"); |
player.sendMessage("[SnitchingChest] Chest is now under surveillance"); |
126 |
|
|
127 |
void removeChest(Location loc) { |
void removeChest(Location loc) { |
128 |
SnitchingChestBean chest = chestMap.remove(loc); |
SnitchingChestBean chest = chestMap.remove(loc); |
129 |
plugin.getDatabase().delete(chest); |
if (chest != null) { |
130 |
|
plugin.getDatabase().delete(chest); |
131 |
|
} |
132 |
} |
} |
133 |
|
|
134 |
void loadChests() { |
void loadChests() { |
201 |
} else { |
} else { |
202 |
loc = ( (DoubleChest)holder).getLocation(); |
loc = ( (DoubleChest)holder).getLocation(); |
203 |
} |
} |
204 |
|
|
205 |
|
loc.setX( loc.getBlockX() ); //round to integer, since double chests apparently are placed at pos + 0.5 |
206 |
|
loc.setZ( loc.getBlockZ() ); // -- // -- |
207 |
|
|
208 |
return loc; |
return loc; |
209 |
} |
} |
210 |
|
|
211 |
@EventHandler |
@EventHandler |
212 |
|
public void onChestPlaced(BlockPlaceEvent event) { |
213 |
|
Block block = event.getBlock(); |
214 |
|
|
215 |
|
if (block.getType() != Material.CHEST) { |
216 |
|
return; |
217 |
|
} |
218 |
|
|
219 |
|
Location chestloc = getNeighborChest( block.getLocation() ); |
220 |
|
if (chestloc != null) { |
221 |
|
SnitchingChestBean chest = chestMap.get(chestloc); |
222 |
|
|
223 |
|
if (chest != null) { //the neighbor is a snitching chest |
224 |
|
SnitchingChestBean newchest = createChest( chest.getOwner(), "", chestloc); |
225 |
|
addChest(chestloc, newchest); |
226 |
|
event.getPlayer().sendMessage( "[SnitchingChest] Chest has been expanded" ); |
227 |
|
} |
228 |
|
|
229 |
|
} |
230 |
|
} |
231 |
|
|
232 |
|
@EventHandler |
233 |
public void onChestOpen(InventoryOpenEvent event) { |
public void onChestOpen(InventoryOpenEvent event) { |
234 |
|
|
235 |
if (! (event.getPlayer() instanceof Player)) { |
if (! (event.getPlayer() instanceof Player)) { |
303 |
|
|
304 |
|
|
305 |
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 + "'s chest"; |
|
|
} |
|
|
if (count < savedcount) { |
|
|
msg = player.getName() + " removed " + diff + " units of " + item + " from " + owner + "'s chest"; |
|
|
} |
|
306 |
|
|
307 |
if (msg != null) { |
if (diff > 0) { |
308 |
|
String material = Material.getMaterial(item).name(); |
309 |
|
String msg = null; |
310 |
|
|
311 |
|
if (count > savedcount) { |
312 |
|
msg = player.getName() + " added " + diff + " units of " + material + "(" +item + ") to " + owner.getName() + "'s chest at " + loc.getWorld() + "," + loc.getBlockX() + "," +loc.getBlockY() + "," + loc.getBlockZ(); |
313 |
|
} else { //(count < savedcount) |
314 |
|
msg = player.getName() + " removed " + diff + " units of " + material + "(" +item + ") from " + owner.getName() + "'s chest at " + loc.getWorld() + "," + loc.getBlockX() + "," +loc.getBlockY() + "," + loc.getBlockZ(); |
315 |
|
} |
316 |
|
|
317 |
|
|
318 |
plugin.getLogger().info(msg); |
plugin.getLogger().info(msg); |
319 |
plugin.getMessageWrapper().sendMessage(owner, msg); |
plugin.getMessageWrapper().sendMessage(owner, msg); |
320 |
} |
} |