Closes gh-57. New buildInZonesOnly setting for griefer control on almost-only-War servers. Can be overridden by the war.build permission node.

This commit is contained in:
taoneill 2011-02-15 09:19:06 -05:00
parent 03b987ee37
commit bb66feab2d
3 changed files with 141 additions and 70 deletions

View File

@ -79,6 +79,7 @@ public class War extends JavaPlugin {
private final HashMap<Integer, ItemStack> defaultReward = new HashMap<Integer, ItemStack>();
private boolean pvpInZonesOnly = false;
private boolean buildInZonesOnly = false;
private WarHub warHub;
@ -121,6 +122,7 @@ public class War extends JavaPlugin {
pm.registerEvent(Event.Type.ENTITY_COMBUST, entityListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_PLACED, blockListener, Priority.Normal, this);
//pm.registerEvent(Event.Type.BLOCK_BREAK, blockListener, Priority.Normal, this);
pm.registerEvent(Event.Type.BLOCK_DAMAGED, blockListener, Priority.Normal, this);
// Load files from disk or create them (using these defaults)
@ -1112,6 +1114,10 @@ public class War extends JavaPlugin {
setDefaultSpawnStyle(TeamSpawnStyles.BIG);
}
}
if(namedParams.containsKey("buildinzonesonly")) {
String onOff = namedParams.get("buildinzonesonly");
setBuildInZonesOnly(onOff.equals("on") || onOff.equals("true"));
}
// if(namedParams.containsKey("dropLootOnDeath")){
// String onOff = namedParams.get("dropLootOnDeath");
// setDefaultDropLootOnDeath(onOff.equals("on") || onOff.equals("true"));
@ -1281,6 +1287,20 @@ public class War extends JavaPlugin {
return false;
}
public boolean canBuildOutsideZone(Player player) {
if(isBuildInZonesOnly()) {
if(Permissions != null
&& (Permissions.Security.permission(player, "war.build")
|| Permissions.Security.permission(player, "War.build"))) {
return true;
}
// w/o Permissions, if buildInZonesOnly, no one can build outside the zone
return false;
} else {
return true;
}
}
public boolean isZoneMaker(Player player) {
boolean isPlayerImpersonator = false;
for(String disguised : zoneMakersImpersonatingPlayers) {
@ -1431,5 +1451,13 @@ public class War extends JavaPlugin {
public List<Warzone> getIncompleteZones() {
return incompleteZones;
}
public void setBuildInZonesOnly(boolean buildInZonesOnly) {
this.buildInZonesOnly = buildInZonesOnly;
}
public boolean isBuildInZonesOnly() {
return buildInZonesOnly;
}
}

View File

@ -2,10 +2,14 @@ package bukkit.tommytony.war;
import java.util.List;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.block.BlockDamageLevel;
import org.bukkit.entity.Player;
import org.bukkit.event.Cancellable;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockCanBuildEvent;
import org.bukkit.event.block.BlockDamageEvent;
import org.bukkit.event.block.BlockListener;
import org.bukkit.event.block.BlockPlaceEvent;
@ -45,7 +49,7 @@ public class WarBlockListener extends BlockListener {
for(Team t : teams) {
t.teamcast("Monument " + monument.getName() + " has been captured by team " + team.getName() + ".");
}
event.setCancelled(false);
return; // important otherwise cancelled down a few line by isImportantblock
} else {
war.badMsg(player, "You can't capture a monument without a block of your team's material. Get one from your team spawn.");
@ -73,89 +77,122 @@ public class WarBlockListener extends BlockListener {
event.setCancelled(true);
return;
}
// buildInZonesOnly
if(zone == null && war.isBuildInZonesOnly() && !war.canBuildOutsideZone(player)) {
war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside.");
event.setCancelled(true);
return;
}
}
}
// public void onBlockBreak(BlockBreakEvent event) {
// Player player = event.getPlayer();
// Block block = event.getBlock();
// if(player != null && block != null) {
// handleBreakOrDamage(player, block, event);
// }
// }
public void onBlockDamage(BlockDamageEvent event) {
Player player = event.getPlayer();
Block block = event.getBlock();
if(player != null && block != null && event.getDamageLevel() == BlockDamageLevel.BROKEN) {
Warzone warzone = war.warzone(player.getLocation());
Team team = war.getPlayerTeam(player.getName());
boolean isZoneMaker = war.isZoneMaker(player);
handleBreakOrDamage(player,block, event);
if(warzone != null && war.getPlayerTeam(player.getName()) == null && !isZoneMaker) {
// can't actually destroy blocks in a warzone if not part of a team
war.badMsg(player, "Can't destroy part of a warzone if you're not in a team.");
event.setCancelled(true);
return;
} else if(team != null && block != null && warzone != null
&& warzone.isMonumentCenterBlock(block)){
Monument monument = warzone.getMonumentFromCenterBlock(block);
if(monument.hasOwner()) {
}
}
List<Team> teams = warzone.getTeams();
for(Team t : teams) {
t.teamcast("Team " + monument.getOwnerTeam().getName() + " loses control of monument " + monument.getName());
}
monument.uncapture();
private void handleBreakOrDamage(Player player, Block block, Cancellable event) {
Warzone warzone = war.warzone(player.getLocation());
Team team = war.getPlayerTeam(player.getName());
boolean isZoneMaker = war.isZoneMaker(player);
if(warzone != null && war.getPlayerTeam(player.getName()) == null && !isZoneMaker) {
// can't actually destroy blocks in a warzone if not part of a team
war.badMsg(player, "Can't destroy part of a warzone if you're not in a team.");
event.setCancelled(true);
return;
} else if(team != null && block != null && warzone != null
&& warzone.isMonumentCenterBlock(block)){
Monument monument = warzone.getMonumentFromCenterBlock(block);
if(monument.hasOwner()) {
List<Team> teams = warzone.getTeams();
for(Team t : teams) {
t.teamcast("Team " + monument.getOwnerTeam().getName() + " loses control of monument " + monument.getName());
}
return;
}else if(warzone != null && warzone.isImportantBlock(block)) {
if(team != null && team.getSpawnVolume().contains(block)) {
if(player.getInventory().contains(team.getMaterial())) {
war.badMsg(player, "You already have a " + team.getName() + " block.");
event.setCancelled(true);
return;
}
// let team members loot one block the spawn for monument captures
} else if (team != null && warzone.isEnemyTeamFlagBlock(team, block)) {
if(warzone.isFlagThief(player.getName())) {
// detect audacious thieves
war.badMsg(player, "You can only steal one flag at a time!");
} else {
// player just broke the flag block of other team: cancel to avoid drop, give player the block, set block to air
Team lostFlagTeam = warzone.getTeamForFlagBlock(block);
player.getInventory().clear();
player.getInventory().addItem(new ItemStack(lostFlagTeam.getMaterial(), 1));
warzone.addFlagThief(lostFlagTeam, player.getName());
block.setType(Material.AIR);
for(Team t : warzone.getTeams()) {
t.teamcast(player.getName() + " stole team " + lostFlagTeam.getName() + "'s flag.");
if(t.getName().equals(lostFlagTeam.getName())){
t.teamcast("Prevent " + player.getName() + " from reaching team " + team.getName() + "'s spawn or flag.");
}
monument.uncapture();
}
event.setCancelled(false);
return;
}else if(warzone != null && warzone.isImportantBlock(block)) {
if(team != null && team.getSpawnVolume().contains(block)) {
if(player.getInventory().contains(team.getMaterial())) {
war.badMsg(player, "You already have a " + team.getName() + " block.");
event.setCancelled(true);
return;
} else {
event.setCancelled(false);
return;
}
// let team members loot one block the spawn for monument captures
} else if (team != null && warzone.isEnemyTeamFlagBlock(team, block)) {
if(warzone.isFlagThief(player.getName())) {
// detect audacious thieves
war.badMsg(player, "You can only steal one flag at a time!");
} else {
// player just broke the flag block of other team: cancel to avoid drop, give player the block, set block to air
Team lostFlagTeam = warzone.getTeamForFlagBlock(block);
player.getInventory().clear();
player.getInventory().addItem(new ItemStack(lostFlagTeam.getMaterial(), 1));
warzone.addFlagThief(lostFlagTeam, player.getName());
block.setType(Material.AIR);
for(Team t : warzone.getTeams()) {
t.teamcast(player.getName() + " stole team " + lostFlagTeam.getName() + "'s flag.");
if(t.getName().equals(lostFlagTeam.getName())){
t.teamcast("Prevent " + player.getName() + " from reaching team " + team.getName() + "'s spawn or flag.");
}
war.msg(player, "You have team " + lostFlagTeam.getName() + "'s flag. Reach your team spawn or flag to capture it!");
}
event.setCancelled(true);
return;
} else if (!warzone.isMonumentCenterBlock(block)){
war.badMsg(player, "Can't destroy this.");
event.setCancelled(true);
return;
}
}
// protect warzone lobbies
if(block != null) {
for(Warzone zone: war.getWarzones()) {
if(zone.getLobby() != null &&
zone.getLobby().getVolume().contains(block)) {
war.badMsg(player, "Can't destroy this.");
event.setCancelled(true);
return;
}
}
}
// protect the hub
if(war.getWarHub() != null && war.getWarHub().getVolume().contains(block)) {
}
war.msg(player, "You have team " + lostFlagTeam.getName() + "'s flag. Reach your team spawn or flag to capture it!");
}
event.setCancelled(true);
return;
} else if (!warzone.isMonumentCenterBlock(block)){
war.badMsg(player, "Can't destroy this.");
event.setCancelled(true);
return;
}
}
// protect warzone lobbies
if(block != null) {
for(Warzone zone: war.getWarzones()) {
if(zone.getLobby() != null &&
zone.getLobby().getVolume().contains(block)) {
war.badMsg(player, "Can't destroy this.");
event.setCancelled(true);
return;
}
}
}
}
// protect the hub
if(war.getWarHub() != null && war.getWarHub().getVolume().contains(block)) {
war.badMsg(player, "Can't destroy this.");
event.setCancelled(true);
return;
}
// buildInZonesOnly
if(war.warzone(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ())) == null
&& war.isBuildInZonesOnly()
&& !war.canBuildOutsideZone(player)) {
war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside.");
event.setCancelled(true);
return;
}
}
}

View File

@ -111,6 +111,9 @@ public class WarMapper {
// defaultBlockHeads
war.setDefaultBlockHeads(warConfig.getBoolean("defaultBlockHeads"));
// buildInZonesOnly
war.setBuildInZonesOnly(warConfig.getBoolean("buildInZonesOnly"));
// defaultSpawnStyle
String spawnStyle = warConfig.getString("defaultspawnStyle");
if(spawnStyle != null && !spawnStyle.equals("")){
@ -228,6 +231,9 @@ public class WarMapper {
// defaultBlockHeads
warConfig.setBoolean("defaultBlockHeads", war.isDefaultBlockHeads());
// buildInZonesOnly
warConfig.setBoolean("buildInZonesOnly", war.isBuildInZonesOnly());
// spawnStyle
warConfig.setString("spawnStyle", war.getDefaultSpawnStyle());