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"); |
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)) { |
305 |
int diff = Math.abs( savedcount - count); |
int diff = Math.abs( savedcount - count); |
306 |
String msg = null; |
String msg = null; |
307 |
if (count > savedcount) { |
if (count > savedcount) { |
308 |
msg = player.getName() + " added " + diff + " units of " + item + " to " + owner + "'s chest"; |
msg = player.getName() + " added " + diff + " units of " + item + " to " + owner.getName() + "'s chest"; |
309 |
} |
} |
310 |
if (count < savedcount) { |
if (count < savedcount) { |
311 |
msg = player.getName() + " removed " + diff + " units of " + item + " from " + owner + "'s chest"; |
msg = player.getName() + " removed " + diff + " units of " + item + " from " + owner.getName() + "'s chest"; |
312 |
} |
} |
313 |
|
|
314 |
if (msg != null) { |
if (msg != null) { |