2011-04-08 15:51:07 +02:00
|
|
|
package org.mcteam.factions.listeners;
|
2011-02-06 13:36:11 +01:00
|
|
|
|
|
|
|
import org.bukkit.block.Block;
|
|
|
|
import org.bukkit.entity.Player;
|
2011-03-30 06:37:32 +02:00
|
|
|
import org.bukkit.event.block.BlockBreakEvent;
|
2011-02-06 13:36:11 +01:00
|
|
|
import org.bukkit.event.block.BlockDamageEvent;
|
|
|
|
import org.bukkit.event.block.BlockListener;
|
|
|
|
import org.bukkit.event.block.BlockPlaceEvent;
|
2011-04-08 15:51:07 +02:00
|
|
|
import org.mcteam.factions.Board;
|
|
|
|
import org.mcteam.factions.Conf;
|
|
|
|
import org.mcteam.factions.FLocation;
|
|
|
|
import org.mcteam.factions.FPlayer;
|
|
|
|
import org.mcteam.factions.Faction;
|
|
|
|
import org.mcteam.factions.Factions;
|
2011-02-06 13:36:11 +01:00
|
|
|
|
|
|
|
|
|
|
|
public class FactionsBlockListener extends BlockListener {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void onBlockPlace(BlockPlaceEvent event) {
|
|
|
|
if (event.isCancelled()) {
|
2011-03-22 17:20:21 +01:00
|
|
|
return;
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
2011-03-30 06:37:32 +02:00
|
|
|
if (!event.canBuild()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
if ( ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "build")) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
2011-03-08 13:42:48 +01:00
|
|
|
|
2011-03-30 06:37:32 +02:00
|
|
|
@Override
|
|
|
|
public void onBlockBreak(BlockBreakEvent event) {
|
|
|
|
if (event.isCancelled()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "destroy")) {
|
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
@Override
|
|
|
|
public void onBlockDamage(BlockDamageEvent event) {
|
|
|
|
if (event.isCancelled()) {
|
2011-03-23 12:00:38 +01:00
|
|
|
return;
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
2011-03-18 00:04:45 +01:00
|
|
|
|
2011-03-30 06:37:32 +02:00
|
|
|
if (event.getInstaBreak() && ! this.playerCanBuildDestroyBlock(event.getPlayer(), event.getBlock(), "destroy")) {
|
2011-02-06 13:36:11 +01:00
|
|
|
event.setCancelled(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean playerCanBuildDestroyBlock(Player player, Block block, String action) {
|
2011-04-04 14:16:53 +02:00
|
|
|
|
2011-04-06 12:04:57 +02:00
|
|
|
if (Conf.adminBypassPlayers.contains(player.getName())) {
|
2011-04-04 14:16:53 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2011-03-22 17:20:21 +01:00
|
|
|
Faction otherFaction = Board.getFactionAt(new FLocation(block));
|
2011-02-06 13:36:11 +01:00
|
|
|
|
2011-03-23 17:39:56 +01:00
|
|
|
if (otherFaction.isNone()) {
|
|
|
|
return true;
|
2011-02-06 13:36:11 +01:00
|
|
|
}
|
|
|
|
|
2011-03-18 17:33:23 +01:00
|
|
|
FPlayer me = FPlayer.get(player);
|
2011-03-23 17:39:56 +01:00
|
|
|
|
|
|
|
if (otherFaction.isSafeZone()) {
|
New boolean config options territoryBlockTNT (default false), safeZoneDenyBuild (default true), safeZoneDenyUseage (default true), safeZoneBlockTNT (default true). territoryBlockTNT prevents TNT explosions inside faction territory, which defaults to false (same as before). It prevents TNT cannons from being a viable tactic, and I think for most people it would be an undesirable option. safeZoneBlockTNT prevents TNT explosions inside safe zone areas, which defaults to true (new behavior). I think most server operators would prefer safe zones to be safe from TNT, from TNT cannons or otherwise. safeZoneDenyBuild prevents players from building inside safe zone areas, which defaults to true (same as before). This option is added for server admins who, for whatever reason, want to let their players build and break inside safe zone areas. safeZoneDenyUseage prevents players from using items in the territoryDenyUseageMaterials list, which defaults to true (new behavior). This will (with the default list) prevent players from dumping/using buckets inside safe zone areas.
2011-04-04 13:31:48 +02:00
|
|
|
if (Factions.hasPermManageSafeZone(player) || !Conf.safeZoneDenyBuild) {
|
2011-03-23 17:39:56 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
me.sendMessage("You can't "+action+" in a safe zone.");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2011-02-06 13:36:11 +01:00
|
|
|
Faction myFaction = me.getFaction();
|
|
|
|
|
|
|
|
// Cancel if we are not in our own territory
|
|
|
|
if (myFaction != otherFaction) {
|
2011-03-22 17:20:21 +01:00
|
|
|
me.sendMessage("You can't "+action+" in the territory of "+otherFaction.getTag(myFaction));
|
2011-02-06 13:36:11 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|