event.setCancelled(true);
}
}
private void handleBreakOrDamage(Player player, Block block, Cancellable event) {
Warzone warzone = Warzone.getZoneByLocation(player);
Team team = Team.getTeamByPlayerName(player.getName());
boolean isZoneMaker = War.war.isZoneMaker(player);
if (warzone != null && team == null && !isZoneMaker) {
// can't actually destroy blocks in a warzone if not part of a team
War.war.badMsg(player, "build.denied.zone.outside");
event.setCancelled(true);
return;
}
// monument's center is destroyed
if (team != null && block != null && warzone != null && warzone.isMonumentCenterBlock(block)) {
Monument monument = warzone.getMonumentFromCenterBlock(block);
if (monument.hasOwner()) {
Team ownerTeam = monument.getOwnerTeam();
if (War.war.isSpoutServer()) {
for (Player p : team.getPlayers()) {
SpoutPlayer sp = SpoutManager.getPlayer(p);
if (sp.isSpoutCraftEnabled()) {
sp.sendNotification(
SpoutDisplayer.cleanForNotification("Monument " + ChatColor.WHITE + monument.getName()),
SpoutDisplayer.cleanForNotification(ChatColor.YELLOW + "freed by " + team.getKind().getColor() + player.getName() + ChatColor.YELLOW + "!"),
ownerTeam.getKind().getMaterial(),
ownerTeam.getKind().getData(),
10000);
}
}
}
warzone.broadcast("zone.monument.lose", ownerTeam.getName(), monument.getName());
monument.uncapture();
}
event.setCancelled(false);
return;
}
// changes in parts of important areas
if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) {
// breakage of spawn
if (team != null && team.isSpawnLocation(block.getLocation())) {
// let team members loot one block the spawn for monument captures
if (player.getInventory().containsAtLeast(team.getKind().getBlockHead(), 1)) {
War.war.badMsg(player, "build.denied.zone.multteam", team.getName());
event.setCancelled(true);
return;
} else {
event.setCancelled(false); // very important, otherwise could get cancelled but unbreakableZoneBlocks further down
return;
}
}
// stealing of flag
if (team != null && warzone.isEnemyTeamFlagBlock(team, block)) {
if (warzone.isFlagThief(player.getName())) {
// detect audacious thieves
War.war.badMsg(player, "zone.stealextra.flag");
} else if (warzone.isBombThief(player.getName()) || warzone.isCakeThief(player.getName())) {
War.war.badMsg(player, "zone.stealextra.other");
} else {
Team lostFlagTeam = warzone.getTeamForFlagBlock(block);
if (lostFlagTeam.getPlayers().size() != 0) {
// player just broke the flag block of other team: cancel to avoid drop, give player the block, set block to air
ItemStack teamKindBlock = lostFlagTeam.getKind().getBlockHead();
player.getInventory().clear();
player.getInventory().addItem(teamKindBlock);
warzone.addFlagThief(lostFlagTeam, player.getName());
block.setType(Material.AIR);
for (Team t : warzone.getTeams()) {
t.teamcast("zone.steal.flag.broadcast", team.getKind().getColor() + player.getName() + ChatColor.WHITE, lostFlagTeam.getName());
if (t.getName().equals(lostFlagTeam.getName())) {
if (War.war.isSpoutServer()) {
for (Player p : t.getPlayers()) {
SpoutPlayer sp = SpoutManager.getPlayer(p);
if (sp.isSpoutCraftEnabled()) {
sp.sendNotification(
SpoutDisplayer.cleanForNotification(team.getKind().getColor() + player.getName() + ChatColor.YELLOW + " stole"),
SpoutDisplayer.cleanForNotification(ChatColor.YELLOW + "your flag!"),
lostFlagTeam.getKind().getMaterial(),
lostFlagTeam.getKind().getData(),
5000);
}
}
}
t.teamcast("zone.steal.flag.prevent", team.getKind().getColor() + player.getName() + ChatColor.WHITE, team.getName());
}
}
War.war.msg(player, "zone.steal.flag.notice", lostFlagTeam.getName());
} else {
War.war.msg(player, "zone.steal.flag.empty", lostFlagTeam.getName());
}
}
event.setCancelled(true);
return;
} else if (team != null && warzone.isBombBlock(block)) {
if (warzone.isBombThief(player.getName())) {
// detect audacious thieves
War.war.badMsg(player, "zone.stealextra.bomb");
} else if (warzone.isFlagThief(player.getName()) || warzone.isCakeThief(player.getName())) {
War.war.badMsg(player, "zone.stealextra.other");
} else {
Bomb bomb = warzone.getBombForBlock(block);
// player just broke the bomb block: cancel to avoid drop, give player the block, set block to air
ItemStack tntBlock = new ItemStack(Material.TNT);
tntBlock.setDurability((short)8);
player.getInventory().clear();
player.getInventory().addItem(tntBlock);
warzone.addBombThief(bomb, player.getName());
block.setType(Material.AIR);
for (Team t : warzone.getTeams()) {
t.teamcast("zone.steal.bomb.broadcast", team.getKind().getColor() + player.getName() + ChatColor.WHITE, ChatColor.GREEN + bomb.getName() + ChatColor.WHITE);
if (War.war.isSpoutServer()) {
for (Player p : t.getPlayers()) {
SpoutPlayer sp = SpoutManager.getPlayer(p);
if (sp.isSpoutCraftEnabled()) {
sp.sendNotification(
SpoutDisplayer.cleanForNotification(team.getKind().getColor() + player.getName() + ChatColor.YELLOW + " has "),
SpoutDisplayer.cleanForNotification(ChatColor.YELLOW + "bomb " + ChatColor.GREEN + bomb.getName() + ChatColor.YELLOW + "!"),
Material.TNT,
(short)0,
5000);
}
}
}
t.teamcast("zone.steal.bomb.prevent", team.getKind().getColor() + player.getName() + ChatColor.WHITE);
}
War.war.msg(player, "zone.steal.bomb.notice", bomb.getName());
}
event.setCancelled(true);
return;
} else if (team != null && warzone.isCakeBlock(block)) {
if (warzone.isCakeThief(player.getName())) {
// detect audacious thieves
War.war.badMsg(player, "zone.stealextra.cake");
} else if (warzone.isFlagThief(player.getName()) || warzone.isBombThief(player.getName())) {
War.war.badMsg(player, "zone.stealextra.other");
} else {
Cake cake = warzone.getCakeForBlock(block);
// player just broke the cake block: cancel to avoid drop, give player the block, set block to air
ItemStack cakeBlock = new ItemStack(Material.CAKE);
cakeBlock.setDurability((short)8);
player.getInventory().clear();
player.getInventory().addItem(cakeBlock);
warzone.addCakeThief(cake, player.getName());
block.setType(Material.AIR);
for (Team t : warzone.getTeams()) {
t.teamcast("zone.steal.cake.broadcast", team.getKind().getColor() + player.getName() + ChatColor.WHITE, ChatColor.GREEN + cake.getName() + ChatColor.WHITE);
if (War.war.isSpoutServer()) {
for (Player p : t.getPlayers()) {
SpoutPlayer sp = SpoutManager.getPlayer(p);
if (sp.isSpoutCraftEnabled()) {
sp.sendNotification(
SpoutDisplayer.cleanForNotification(team.getKind().getColor() + player.getName() + ChatColor.YELLOW + " has "),
SpoutDisplayer.cleanForNotification(ChatColor.YELLOW + "cake " + ChatColor.GREEN + cake.getName() + ChatColor.YELLOW + "!"),
Material.CAKE,
(short)0,
5000);
}
}
}
t.teamcast("zone.steal.cake.prevent", team.getKind().getColor() + player.getName() + ChatColor.WHITE);
}
War.war.msg(player, "zone.steal.cake.notice", cake.getName());
}
event.setCancelled(true);
return;
} else if (!warzone.isMonumentCenterBlock(block)) {
War.war.badMsg(player, "build.denied.location");
event.setCancelled(true);
return;
}
}
// protect warzone lobbies
if (block != null) {
for (Warzone zone : War.war.getWarzones()) {
if (zone.getLobby() != null && zone.getLobby().getVolume() != null && zone.getLobby().getVolume().contains(block)) {
War.war.badMsg(player, "build.denied.location");
event.setCancelled(true);
return;
}
}
}
// protect the hub
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
War.war.badMsg(player, "build.denied.location");
event.setCancelled(true);
return;
}
// buildInZonesOnly
Warzone blockZone = Warzone.getZoneByLocation(new Location(block.getWorld(), block.getX(), block.getY(), block.getZ()));
if (blockZone == null && War.war.getWarConfig().getBoolean(WarConfig.BUILDINZONESONLY) && !War.war.canBuildOutsideZone(player)) {
if (!War.war.getWarConfig().getBoolean(WarConfig.DISABLEBUILDMESSAGE)) {
War.war.badMsg(player, "build.denied.outside");
}
event.setCancelled(true);
return;
}
// unbreakableZoneBlocks
if (blockZone != null && blockZone.getWarzoneConfig().getBoolean(WarzoneConfig.UNBREAKABLE) && (!isZoneMaker || (isZoneMaker && team != null))) {
// if the zone is unbreakable, no one but zone makers can break blocks (even then, zone makers in a team can't break blocks
War.war.badMsg(player, "build.denied.zone.break");
event.setCancelled(true);
return;
}