My own way to control block-breaking/-placing

This version controls blockbreaking and -placing when noone is playing
(no game is running) using the whitelist/blacklist feature to prevent
people from breaking the spawn-/lobby-area !  This behaviour is
switchable (config) and controllable (permission) !
This commit is contained in:
Jeppa 2013-03-30 16:33:08 +01:00
parent 2ae5363b4b
commit 1a5b18ebe1

View File

@ -32,20 +32,18 @@ public class BlockStorage implements Listener {
String pname = p.getName(); String pname = p.getName();
boolean protall = false; boolean protall = false;
if (plugin.config.getString("Protected_Arena_Always").equalsIgnoreCase("True")) { /* Jeppa Fix/Add */ if (plugin.config.getString("Protected_Arena_Always").equalsIgnoreCase("True")) { /* Jeppa Fix/Add */
if(!p.hasPermission("HungerArena.arena")){ // Admins frei...
protall = true; protall = true;
if(!p.hasPermission("HungerArena.arena")){
event.setCancelled(true);
p.sendMessage("You can't break blocks, at all, if you feel this should change, talk to the server owner.");
} }
} }
if (plugin.getArena(p) != null || !protall) { if ((plugin.getArena(p) != null) || (protall)) { /* Bug1a */
//int a = this.plugin.getArena(p).intValue(); //int a = this.plugin.getArena(p).intValue();
int a = 1; //Jeppa: define a default (may be needed if protall is true) int a = 1; //Jeppa: define a default (may be needed if protall is true)
if (plugin.getArena(p) != null){ if (plugin.getArena(p) != null) a = plugin.getArena(p);
a = plugin.getArena(p); if ((!event.isCancelled()) && (((plugin.Playing.get(a)).contains(pname)) || (protall))) /* Bug1a */
if (!event.isCancelled() && plugin.Playing.get(a).contains(pname)){ {
if (plugin.config.getString("Protected_Arena").equalsIgnoreCase("True")) { if (plugin.config.getString("Protected_Arena").equalsIgnoreCase("True")) {
event.setCancelled(true); event.setCancelled(true); /* Jeppa fix Bug1 */
p.sendMessage(ChatColor.RED + "You can't break blocks while playing!"); p.sendMessage(ChatColor.RED + "You can't break blocks while playing!");
} else if ((((plugin.canjoin.get(a))) || (protall)) && ((plugin.config.getStringList("worlds").isEmpty()) || ((!plugin.config.getStringList("worlds").isEmpty()) && (plugin.config.getStringList("worlds").contains(p.getWorld().getName()))))) { } else if ((((plugin.canjoin.get(a))) || (protall)) && ((plugin.config.getStringList("worlds").isEmpty()) || ((!plugin.config.getStringList("worlds").isEmpty()) && (plugin.config.getStringList("worlds").contains(p.getWorld().getName()))))) {
if (((plugin.management.getIntegerList("blocks.whitelist").isEmpty()) || ((!plugin.management.getIntegerList("blocks.whitelist").isEmpty()) && (!plugin.management.getIntegerList("blocks.whitelist").contains(Integer.valueOf(b.getTypeId()))))) ^ (plugin.management.getBoolean("blocks.useWhitelistAsBlacklist"))) { if (((plugin.management.getIntegerList("blocks.whitelist").isEmpty()) || ((!plugin.management.getIntegerList("blocks.whitelist").isEmpty()) && (!plugin.management.getIntegerList("blocks.whitelist").contains(Integer.valueOf(b.getTypeId()))))) ^ (plugin.management.getBoolean("blocks.useWhitelistAsBlacklist"))) {
@ -70,7 +68,6 @@ public class BlockStorage implements Listener {
} }
} }
} }
}
@EventHandler(priority = EventPriority.MONITOR) @EventHandler(priority = EventPriority.MONITOR)
public void Explosion(EntityExplodeEvent event){ public void Explosion(EntityExplodeEvent event){
List<Block> blocksd = event.blockList(); List<Block> blocksd = event.blockList();
@ -140,11 +137,18 @@ public class BlockStorage implements Listener {
public void blockPlace(BlockPlaceEvent event){ public void blockPlace(BlockPlaceEvent event){
Block b = event.getBlock(); Block b = event.getBlock();
Player p = event.getPlayer(); Player p = event.getPlayer();
if(plugin.getArena(p)!= null){ boolean protall = false;
int a = plugin.getArena(p); if (plugin.config.getString("Protected_Arena_Always").equalsIgnoreCase("True")) { /* Jeppa Fix/Add */
if(!p.hasPermission("HungerArena.arena")){ // Admins or with permission : free...
protall = true;
}
}
if ((plugin.getArena(p) != null) || (protall)) { /* Bug1a */
int a = 1; //Jeppa: define a default (may be needed if protall is true)
if (plugin.getArena(p) != null) a = plugin.getArena(p);
if(!event.isCancelled()){ if(!event.isCancelled()){
if(plugin.Playing.get(a).contains(p.getName())){ if (((plugin.Playing.get(a)).contains(p.getName())) || (protall)) {
if(plugin.canjoin.get(a)){ if((plugin.canjoin.get(a)) || (protall)){
if(plugin.config.getStringList("worlds").isEmpty() || (!plugin.config.getStringList("worlds").isEmpty() && plugin.config.getStringList("worlds").contains(b.getWorld().getName()))){ if(plugin.config.getStringList("worlds").isEmpty() || (!plugin.config.getStringList("worlds").isEmpty() && plugin.config.getStringList("worlds").contains(b.getWorld().getName()))){
if((b.getType()== Material.SAND || b.getType()== Material.GRAVEL) && (b.getRelative(BlockFace.DOWN).getType()== Material.AIR || b.getRelative(BlockFace.DOWN).getType()== Material.WATER || b.getRelative(BlockFace.DOWN).getType()== Material.LAVA)){ if((b.getType()== Material.SAND || b.getType()== Material.GRAVEL) && (b.getRelative(BlockFace.DOWN).getType()== Material.AIR || b.getRelative(BlockFace.DOWN).getType()== Material.WATER || b.getRelative(BlockFace.DOWN).getType()== Material.LAVA)){
int n = b.getY() -1; int n = b.getY() -1;
@ -159,6 +163,7 @@ public class BlockStorage implements Listener {
int y = br.getY(); int y = br.getY();
int z = br.getZ(); int z = br.getZ();
String coords = w + "," + x + "," + y + "," + z + "," + a; String coords = w + "," + x + "," + y + "," + z + "," + a;
p.sendMessage(ChatColor.GREEN + "Sand/Gravel will land at " + coords);
List<String> blocks = plugin.data.getStringList("Blocks_Placed"); List<String> blocks = plugin.data.getStringList("Blocks_Placed");
blocks.add(coords); blocks.add(coords);
plugin.data.set("Blocks_Placed", blocks); plugin.data.set("Blocks_Placed", blocks);