Documentation

This commit is contained in:
Tim Düsterhus 2011-07-28 18:48:59 +02:00
parent 9dae88a5fc
commit 8891b97a9d
5 changed files with 370 additions and 328 deletions

View File

@ -83,11 +83,19 @@ public class War extends JavaPlugin {
War.war = this; War.war = this;
} }
/**
* @see JavaPlugin.onEnable()
* @see War.loadWar()
*/
public void onEnable() { public void onEnable() {
War.war = this; War.war = this;
this.loadWar(); this.loadWar();
} }
/**
* @see JavaPlugin.onDisable()
* @see War.unloadWar()
*/
public void onDisable() { public void onDisable() {
this.unloadWar(); this.unloadWar();
} }
@ -169,7 +177,7 @@ public class War extends JavaPlugin {
* Handles war commands * Handles war commands
*/ */
public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) { public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
return this.commandHandler.handle(sender, cmd, commandLabel, args); return this.commandHandler.handle(sender, cmd, args);
/* /*
if (this.isZoneMaker(player)) { if (this.isZoneMaker(player)) {

View File

@ -24,91 +24,101 @@ import com.tommytony.war.Warzone;
*/ */
public class WarBlockListener extends BlockListener { public class WarBlockListener extends BlockListener {
/**
* @see BlockListener.onBlockPlace()
*/
@Override @Override
public void onBlockPlace(BlockPlaceEvent event) { public void onBlockPlace(BlockPlaceEvent event) {
if (War.war.isLoaded()) { if (!War.war.isLoaded()) return;
Player player = event.getPlayer();
Block block = event.getBlock();
if (player != null && block != null) {
Team team = Team.getTeamByPlayerName(player.getName());
Warzone zone = Warzone.getZoneByLocation(player);
if (team != null && block != null && zone != null && zone.isMonumentCenterBlock(block) && block.getType() == team.getKind().getMaterial() && block.getData() == team.getKind().getData()) {
Monument monument = zone.getMonumentFromCenterBlock(block);
if (monument != null && !monument.hasOwner()) {
monument.capture(team);
List<Team> teams = zone.getTeams();
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.war.badMsg(player, "You can't capture a monument without a block of your team's material. Get one from your team spawn.");
event.setCancelled(true);
return;
}
}
boolean isZoneMaker = War.war.isZoneMaker(player);
if (zone != null && zone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) {
War.war.badMsg(player, "Can't build here.");
event.setCancelled(true);
return;
}
// protect warzone lobbies
for (Warzone wz : War.war.getWarzones()) {
if (wz.getLobby() != null && wz.getLobby().getVolume() != null && wz.getLobby().getVolume().contains(block)) {
War.war.badMsg(player, "Can't build here.");
event.setCancelled(true);
return;
}
}
// protect the hub
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
War.war.badMsg(player, "Can't build here.");
event.setCancelled(true);
return;
}
// buildInZonesOnly Player player = event.getPlayer();
if (zone == null && War.war.isBuildInZonesOnly() && !War.war.canBuildOutsideZone(player)) { Block block = event.getBlock();
War.war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside."); if (player == null || block == null) return;
event.setCancelled(true);
return;
}
// can't place a block of your team's color Team team = Team.getTeamByPlayerName(player.getName());
if (team != null && block.getType() == team.getKind().getMaterial() && block.getData() == team.getKind().getData()) { Warzone zone = Warzone.getZoneByLocation(player);
War.war.badMsg(player, "You can only use your team's blocks to capture monuments."); // Monument capturing
event.setCancelled(true); if (team != null && block != null && zone != null && zone.isMonumentCenterBlock(block) && block.getType() == team.getKind().getMaterial() && block.getData() == team.getKind().getData()) {
return; Monument monument = zone.getMonumentFromCenterBlock(block);
} if (monument != null && !monument.hasOwner()) {
monument.capture(team);
if (team != null && zone != null && zone.isFlagThief(player.getName())) { List<Team> teams = zone.getTeams();
// a flag thief can't drop his flag for (Team t : teams) {
War.war.badMsg(player, "Can't drop the flag. What are you doing? Run!"); t.teamcast("Monument " + monument.getName() + " has been captured by team " + team.getName() + ".");
event.setCancelled(true);
}
// unbreakableZoneBlocks
if (zone != null && zone.isUnbreakableZoneBlocks() && (!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, "The blocks in this zone are unbreakable - this also means you can't build!");
event.setCancelled(true);
return;
} }
event.setCancelled(false);
return; // important otherwise cancelled down a few line by isImportantblock
} else {
War.war.badMsg(player, "You can't capture a monument without a block of your team's material. Get one from your team spawn.");
event.setCancelled(true);
return;
} }
} }
boolean isZoneMaker = War.war.isZoneMaker(player);
// prevent build in important parts
if (zone != null && zone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) {
War.war.badMsg(player, "Can't build here.");
event.setCancelled(true);
return;
}
// protect warzone lobbies
for (Warzone wz : War.war.getWarzones()) {
if (wz.getLobby() != null && wz.getLobby().getVolume() != null && wz.getLobby().getVolume().contains(block)) {
War.war.badMsg(player, "Can't build here.");
event.setCancelled(true);
return;
}
}
// protect the hub
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
War.war.badMsg(player, "Can't build here.");
event.setCancelled(true);
return;
}
// buildInZonesOnly
if (zone == null && War.war.isBuildInZonesOnly() && !War.war.canBuildOutsideZone(player)) {
War.war.badMsg(player, "You can only build inside warzones. Ask for the 'war.build' permission to build outside.");
event.setCancelled(true);
return;
}
// can't place a block of your team's color
if (team != null && block.getType() == team.getKind().getMaterial() && block.getData() == team.getKind().getData()) {
War.war.badMsg(player, "You can only use your team's blocks to capture monuments.");
event.setCancelled(true);
return;
}
// a flag thief can't drop his flag
if (team != null && zone != null && zone.isFlagThief(player.getName())) {
War.war.badMsg(player, "Can't drop the flag. What are you doing? Run!");
event.setCancelled(true);
}
// unbreakableZoneBlocks
if (zone != null && zone.isUnbreakableZoneBlocks() && (!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, "The blocks in this zone are unbreakable - this also means you can't build!");
event.setCancelled(true);
return;
}
} }
/**
* @see BlockListener.onBlockBreak()
*/
@Override @Override
public void onBlockBreak(BlockBreakEvent event) { public void onBlockBreak(BlockBreakEvent event) {
if (War.war.isLoaded()) { if (!War.war.isLoaded()) return;
Player player = event.getPlayer(); Player player = event.getPlayer();
Block block = event.getBlock(); Block block = event.getBlock();
if (player != null && block != null) { if (player != null && block != null) {
this.handleBreakOrDamage(player, block, event); this.handleBreakOrDamage(player, block, event);
}
} }
} }
@ -122,10 +132,11 @@ public class WarBlockListener extends BlockListener {
War.war.badMsg(player, "Can't destroy part of a warzone if you're not in a team."); War.war.badMsg(player, "Can't destroy part of a warzone if you're not in a team.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} else if (team != null && block != null && warzone != null && warzone.isMonumentCenterBlock(block)) { }
// monument's center is destroyed
if (team != null && block != null && warzone != null && warzone.isMonumentCenterBlock(block)) {
Monument monument = warzone.getMonumentFromCenterBlock(block); Monument monument = warzone.getMonumentFromCenterBlock(block);
if (monument.hasOwner()) { if (monument.hasOwner()) {
List<Team> teams = warzone.getTeams(); List<Team> teams = warzone.getTeams();
for (Team t : teams) { for (Team t : teams) {
t.teamcast("Team " + monument.getOwnerTeam().getName() + " loses control of monument " + monument.getName()); t.teamcast("Team " + monument.getOwnerTeam().getName() + " loses control of monument " + monument.getName());
@ -134,10 +145,13 @@ public class WarBlockListener extends BlockListener {
} }
event.setCancelled(false); event.setCancelled(false);
return; return;
} else if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) { }
// changes in parts of important areas
if (warzone != null && warzone.isImportantBlock(block) && (!isZoneMaker || (isZoneMaker && team != null))) {
// breakage of spawn
if (team != null && team.getSpawnVolume().contains(block)) { if (team != null && team.getSpawnVolume().contains(block)) {
ItemStack teamKindBlock = new ItemStack(team.getKind().getMaterial(), team.getKind().getData()); ItemStack teamKindBlock = new ItemStack(team.getKind().getMaterial(), team.getKind().getData());
// let team members loot one block the spawn for monument captures
if (player.getInventory().contains(teamKindBlock)) { if (player.getInventory().contains(teamKindBlock)) {
War.war.badMsg(player, "You already have a " + team.getName() + " block."); War.war.badMsg(player, "You already have a " + team.getName() + " block.");
event.setCancelled(true); event.setCancelled(true);
@ -146,8 +160,9 @@ public class WarBlockListener extends BlockListener {
event.setCancelled(false); // very important, otherwise could get cancelled but unbreakableZoneBlocks further down event.setCancelled(false); // very important, otherwise could get cancelled but unbreakableZoneBlocks further down
return; return;
} }
// let team members loot one block the spawn for monument captures }
} else if (team != null && warzone.isEnemyTeamFlagBlock(team, block)) { // stealing of flag
if (team != null && warzone.isEnemyTeamFlagBlock(team, block)) {
if (warzone.isFlagThief(player.getName())) { if (warzone.isFlagThief(player.getName())) {
// detect audacious thieves // detect audacious thieves
War.war.badMsg(player, "You can only steal one flag at a time!"); War.war.badMsg(player, "You can only steal one flag at a time!");

View File

@ -6,12 +6,22 @@ import org.bukkit.command.CommandSender;
import bukkit.tommytony.war.command.*; import bukkit.tommytony.war.command.*;
/** /**
* Handles commands received by War
*
* @author Tim Düsterhus * @author Tim Düsterhus
* @package bukkit.tommytony.war * @package bukkit.tommytony.war
*/ */
public class WarCommandHandler { public class WarCommandHandler {
public boolean handle(CommandSender sender, Command cmd, String commandLabel, String[] args) { /**
* Handles a command
*
* @param sender The sender of the command
* @param cmd The command
* @param args The arguments
* @return Success
*/
public boolean handle(CommandSender sender, Command cmd, String[] args) {
String command = cmd.getName(); String command = cmd.getName();
String[] arguments = null; String[] arguments = null;

View File

@ -34,7 +34,7 @@ public class WarEntityListener extends EntityListener {
/** /**
* Handles PVP-Damage * Handles PVP-Damage
* *
* @param event fired event * @param event fired event
*/ */
private void handlerAttackDefend(EntityDamageByEntityEvent event) { private void handlerAttackDefend(EntityDamageByEntityEvent event) {
Entity attacker = event.getDamager(); Entity attacker = event.getDamager();
@ -132,28 +132,30 @@ public class WarEntityListener extends EntityListener {
/** /**
* Protects important structures from explosions * Protects important structures from explosions
*
* @see EntityListener.onEntityExplode()
*/ */
@Override @Override
public void onEntityExplode(EntityExplodeEvent event) { public void onEntityExplode(EntityExplodeEvent event) {
if (War.war.isLoaded()) { if (!War.war.isLoaded()) return;
// protect zones elements, lobbies and warhub from creepers // protect zones elements, lobbies and warhub from creepers
List<Block> explodedBlocks = event.blockList(); List<Block> explodedBlocks = event.blockList();
for (Block block : explodedBlocks) { for (Block block : explodedBlocks) {
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) { if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
event.setCancelled(true);
War.war.log("Explosion prevented at warhub.", Level.INFO);
return;
}
for (Warzone zone : War.war.getWarzones()) {
if (zone.isImportantBlock(block)) {
event.setCancelled(true); event.setCancelled(true);
War.war.log("Explosion prevented at warhub.", Level.INFO); War.war.log("Explosion prevented in zone " + zone.getName() + ".", Level.INFO);
return;
} else if (zone.getLobby() != null && zone.getLobby().getVolume().contains(block)) {
event.setCancelled(true);
War.war.log("Explosion prevented at zone " + zone.getName() + " lobby.", Level.INFO);
return; return;
}
for (Warzone zone : War.war.getWarzones()) {
if (zone.isImportantBlock(block)) {
event.setCancelled(true);
War.war.log("Explosion prevented in zone " + zone.getName() + ".", Level.INFO);
return;
} else if (zone.getLobby() != null && zone.getLobby().getVolume().contains(block)) {
event.setCancelled(true);
War.war.log("Explosion prevented at zone " + zone.getName() + " lobby.", Level.INFO);
return;
}
} }
} }
} }
@ -161,89 +163,93 @@ public class WarEntityListener extends EntityListener {
/** /**
* Handles damage on Players * Handles damage on Players
*
* @see EntityListener.onEntityDamage()
*/ */
@Override @Override
public void onEntityDamage(EntityDamageEvent event) { public void onEntityDamage(EntityDamageEvent event) {
if (War.war.isLoaded()) { if (!War.war.isLoaded()) return;
Entity entity = event.getEntity();
if (!(entity instanceof Player)) {
return;
}
Player player = (Player) entity;
// prevent godmode Entity entity = event.getEntity();
if (Warzone.getZoneByPlayerName(player.getName()) != null) { if (!(entity instanceof Player)) {
event.setCancelled(false); return;
} }
Player player = (Player) entity;
// pass pvp-damage // prevent godmode
if (event instanceof EntityDamageByEntityEvent || event instanceof EntityDamageByProjectileEvent) { if (Warzone.getZoneByPlayerName(player.getName()) != null) {
this.handlerAttackDefend((EntityDamageByEntityEvent) event); event.setCancelled(false);
} else { }
// Detect death, prevent it and respawn the player
Warzone zone = Warzone.getZoneByPlayerName(player.getName()); // pass pvp-damage
if (zone != null && event.getDamage() >= player.getHealth()) { if (event instanceof EntityDamageByEntityEvent || event instanceof EntityDamageByProjectileEvent) {
String deathMessage = ""; this.handlerAttackDefend((EntityDamageByEntityEvent) event);
deathMessage = Team.getTeamByPlayerName(player.getName()).getKind().getColor() + player.getDisplayName() + ChatColor.WHITE + " died"; } else {
for (Team team : zone.getTeams()) { // Detect death, prevent it and respawn the player
team.teamcast(deathMessage); Warzone zone = Warzone.getZoneByPlayerName(player.getName());
} if (zone != null && event.getDamage() >= player.getHealth()) {
zone.handleDeath(player); String deathMessage = "";
event.setCancelled(true); deathMessage = Team.getTeamByPlayerName(player.getName()).getKind().getColor() + player.getDisplayName() + ChatColor.WHITE + " died";
for (Team team : zone.getTeams()) {
team.teamcast(deathMessage);
} }
zone.handleDeath(player);
event.setCancelled(true);
} }
} }
} }
@Override @Override
public void onEntityCombust(EntityCombustEvent event) { public void onEntityCombust(EntityCombustEvent event) {
if (War.war.isLoaded()) { if (!War.war.isLoaded()) return;
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (entity instanceof Player) { if (entity instanceof Player) {
Player player = (Player) entity; Player player = (Player) entity;
Team team = Team.getTeamByPlayerName(player.getName()); Team team = Team.getTeamByPlayerName(player.getName());
if (team != null && team.getSpawnVolume().contains(player.getLocation())) { if (team != null && team.getSpawnVolume().contains(player.getLocation())) {
// smother out the fire that didn't burn out when you respawned // smother out the fire that didn't burn out when you respawned
// Stop fire (upcast, watch out!) // Stop fire (upcast, watch out!)
if (player instanceof CraftPlayer) { if (player instanceof CraftPlayer) {
net.minecraft.server.Entity playerEntity = ((CraftPlayer) player).getHandle(); net.minecraft.server.Entity playerEntity = ((CraftPlayer) player).getHandle();
playerEntity.fireTicks = 0; playerEntity.fireTicks = 0;
}
event.setCancelled(true);
} }
event.setCancelled(true);
} }
} }
} }
/** /**
* Prevents creatures from spawning in warzones if no creatures is active * Prevents creatures from spawning in warzones if no creatures is active
*
* @see EntityListener.onCreatureSpawn()
*/ */
@Override @Override
public void onCreatureSpawn(CreatureSpawnEvent event) { public void onCreatureSpawn(CreatureSpawnEvent event) {
if (War.war.isLoaded()) { if (!War.war.isLoaded()) return;
Location location = event.getLocation();
Warzone zone = Warzone.getZoneByLocation(location); Location location = event.getLocation();
if (zone != null && zone.isNoCreatures()) { Warzone zone = Warzone.getZoneByLocation(location);
event.setCancelled(true); if (zone != null && zone.isNoCreatures()) {
// war.logInfo("Prevented " + event.getMobType().getName() + " from spawning in zone " + zone.getName()); event.setCancelled(true);
} // war.logInfo("Prevented " + event.getMobType().getName() + " from spawning in zone " + zone.getName());
} }
} }
/** /**
* Prevents health regaining caused by peaceful mode * Prevents health regaining caused by peaceful mode
*
* @see EntityListener.onEntityRegainHealth()
*/ */
@Override @Override
public void onEntityRegainHealth(EntityRegainHealthEvent event) { public void onEntityRegainHealth(EntityRegainHealthEvent event) {
if (War.war.isLoaded() && event.getRegainReason() == RegainReason.REGEN) { if (!War.war.isLoaded() || event.getRegainReason() != RegainReason.REGEN) return;
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (entity instanceof Player) { if (!(entity instanceof Player)) return;
Player player = (Player) entity;
Warzone zone = Warzone.getZoneByLocation(player); Player player = (Player) entity;
if (zone != null) { Warzone zone = Warzone.getZoneByLocation(player);
event.setCancelled(true); if (zone != null) {
} event.setCancelled(true);
}
} }
} }
} }

View File

@ -32,9 +32,13 @@ import com.tommytony.war.ZoneSetter;
* @package bukkit.tommytony.war * @package bukkit.tommytony.war
*/ */
public class WarPlayerListener extends PlayerListener { public class WarPlayerListener extends PlayerListener {
private java.util.Random random = new java.util.Random(); private java.util.Random random = new java.util.Random();
/**
* Correctly removes quitting players from warzones
*
* @see PlayerListener.onPlayerQuit()
*/
@Override @Override
public void onPlayerQuit(PlayerQuitEvent event) { public void onPlayerQuit(PlayerQuitEvent event) {
if (War.war.isLoaded()) { if (War.war.isLoaded()) {
@ -82,6 +86,7 @@ public class WarPlayerListener extends PlayerListener {
} }
} }
} }
if (War.war.isWandBearer(player)) { if (War.war.isWandBearer(player)) {
Item item = event.getItemDrop(); Item item = event.getItemDrop();
if (item.getItemStack().getType() == Material.WOOD_SWORD) { if (item.getItemStack().getType() == Material.WOOD_SWORD) {
@ -112,7 +117,6 @@ public class WarPlayerListener extends PlayerListener {
ItemStack itemStack = cItem.getItemStack(); ItemStack itemStack = cItem.getItemStack();
if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() && player.getInventory().contains(new ItemStack(team.getKind().getMaterial(), team.getKind().getData()))) { if (itemStack != null && itemStack.getType() == team.getKind().getMaterial() && player.getInventory().contains(new ItemStack(team.getKind().getMaterial(), team.getKind().getData()))) {
// Can't pick up a second precious block // Can't pick up a second precious block
// war.badMsg(player, "You already have a " + team.getName() + " block.");
event.setCancelled(true); event.setCancelled(true);
return; return;
} }
@ -154,11 +158,13 @@ public class WarPlayerListener extends PlayerListener {
if (!War.war.isZoneMaker(player) && split.length > 0 && split[0].startsWith("/")) { if (!War.war.isZoneMaker(player) && split.length > 0 && split[0].startsWith("/")) {
String command = split[0].substring(1); String command = split[0].substring(1);
if (!command.equals("war") && !command.equals("zones") && !command.equals("warzones") && !command.equals("zone") && !command.equals("warzone") && !command.equals("teams") && !command.equals("join") && !command.equals("leave") && !command.equals("team") && !command.equals("warhub") && !command.equals("zonemaker")) { if (!command.equals("war") && !command.equals("zones") && !command.equals("warzones") && !command.equals("zone") && !command.equals("warzone") && !command.equals("teams") && !command.equals("join") && !command.equals("leave") && !command.equals("team") && !command.equals("warhub") && !command.equals("zonemaker")) {
// allow white commands
for (String whiteCommand : War.war.getCommandWhitelist()) { for (String whiteCommand : War.war.getCommandWhitelist()) {
if (whiteCommand.equals(command)) { if (whiteCommand.equals(command)) {
return; return;
} }
} }
War.war.badMsg(player, "Can't use anything but War commands (e.g. /leave, /warhub) while you're playing in a warzone."); War.war.badMsg(player, "Can't use anything but War commands (e.g. /leave, /warhub) while you're playing in a warzone.");
event.setCancelled(true); event.setCancelled(true);
} }
@ -209,203 +215,200 @@ public class WarPlayerListener extends PlayerListener {
@Override @Override
public void onPlayerMove(PlayerMoveEvent event) { public void onPlayerMove(PlayerMoveEvent event) {
if (War.war.isLoaded()) { if (!War.war.isLoaded()) return;
Player player = event.getPlayer(); Player player = event.getPlayer();
Location playerLoc = event.getFrom(); // same as player.getLoc. Don't call again we need same result. Location playerLoc = event.getFrom(); // same as player.getLoc. Don't call again we need same result.
Warzone locZone = null; Warzone locZone = Warzone.getZoneByLocation(playerLoc);
ZoneLobby locLobby = null; ZoneLobby locLobby = ZoneLobby.getLobbyByLocation(playerLoc);
locZone = Warzone.getZoneByLocation(playerLoc);
locLobby = ZoneLobby.getLobbyByLocation(playerLoc);
boolean canPlay = War.war.canPlayWar(player);
boolean isMaker = War.war.isZoneMaker(player);
// Zone walls boolean canPlay = War.war.canPlayWar(player);
Team currentTeam = Team.getTeamByPlayerName(player.getName()); boolean isMaker = War.war.isZoneMaker(player);
Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName()); // this uses the teams, so it asks: get the player's team's warzone
boolean protecting = false; // Zone walls
if (currentTeam != null) { Team currentTeam = Team.getTeamByPlayerName(player.getName());
// Warzone nearbyZone = war.zoneOfZoneWallAtProximity(playerLoc); Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName()); // this uses the teams, so it asks: get the player's team's warzone
protecting = playerWarzone.protectZoneWallAgainstPlayer(player); boolean protecting = false;
} else { if (currentTeam != null) {
Warzone nearbyZone = War.war.zoneOfZoneWallAtProximity(playerLoc); // Warzone nearbyZone = war.zoneOfZoneWallAtProximity(playerLoc);
if (nearbyZone != null && !isMaker) { protecting = playerWarzone.protectZoneWallAgainstPlayer(player);
protecting = nearbyZone.protectZoneWallAgainstPlayer(player); } else {
} Warzone nearbyZone = War.war.zoneOfZoneWallAtProximity(playerLoc);
if (nearbyZone != null && !isMaker) {
protecting = nearbyZone.protectZoneWallAgainstPlayer(player);
} }
}
if (!protecting) { if (!protecting) {
// zone makers still need to delete their walls // zone makers still need to delete their walls
// make sure to delete any wall guards as you leave // make sure to delete any wall guards as you leave
for (Warzone zone : War.war.getWarzones()) { for (Warzone zone : War.war.getWarzones()) {
zone.dropZoneWallGuardIfAny(player); zone.dropZoneWallGuardIfAny(player);
}
} }
}
// Warzone lobby gates // Warzone lobby gates
if (locLobby != null) { if (locLobby != null) {
Warzone zone = locLobby.getZone(); Warzone zone = locLobby.getZone();
Team oldTeam = Team.getTeamByPlayerName(player.getName()); Team oldTeam = Team.getTeamByPlayerName(player.getName());
boolean isAutoAssignGate = false; boolean isAutoAssignGate = false;
if (oldTeam == null && canPlay) { // trying to counter spammy player move if (oldTeam == null && canPlay) { // trying to counter spammy player move
isAutoAssignGate = zone.getLobby().isAutoAssignGate(playerLoc); isAutoAssignGate = zone.getLobby().isAutoAssignGate(playerLoc);
if (isAutoAssignGate) { if (isAutoAssignGate) {
if (zone.isDisabled()) {
this.handleDisabledZone(event, player, zone);
} else {
this.dropFromOldTeamIfAny(player);
int noOfPlayers = 0;
for (Team t : zone.getTeams()) {
noOfPlayers += t.getPlayers().size();
}
if (noOfPlayers < zone.getTeams().size() * zone.getTeamCap()) {
zone.autoAssign(player);
if (War.war.getWarHub() != null) {
War.war.getWarHub().resetZoneSign(zone);
}
} else {
event.setTo(zone.getTeleport());
// player.teleport(zone.getTeleport());
War.war.badMsg(player, "All teams are full.");
}
}
return;
}
// go through all the team gates
for (Team team : zone.getTeams()) {
if (zone.getLobby().isInTeamGate(team, playerLoc)) {
this.dropFromOldTeamIfAny(player);
if (zone.isDisabled()) { if (zone.isDisabled()) {
this.handleDisabledZone(event, player, zone); this.handleDisabledZone(event, player, zone);
} else { } else if (team.getPlayers().size() < zone.getTeamCap()) {
this.dropFromOldTeamIfAny(player); team.addPlayer(player);
int noOfPlayers = 0; team.resetSign();
if (War.war.getWarHub() != null) {
War.war.getWarHub().resetZoneSign(zone);
}
zone.keepPlayerInventory(player);
War.war.msg(player, "Your inventory is in storage until you /leave.");
zone.respawnPlayer(event, team, player);
for (Team t : zone.getTeams()) { for (Team t : zone.getTeams()) {
noOfPlayers += t.getPlayers().size(); t.teamcast("" + player.getName() + " joined team " + team.getName() + ".");
}
if (noOfPlayers < zone.getTeams().size() * zone.getTeamCap()) {
zone.autoAssign(player);
if (War.war.getWarHub() != null) {
War.war.getWarHub().resetZoneSign(zone);
}
} else {
event.setTo(zone.getTeleport());
// player.teleport(zone.getTeleport());
War.war.badMsg(player, "All teams are full.");
} }
} else {
event.setTo(zone.getTeleport());
War.war.badMsg(player, "Team " + team.getName() + " is full.");
} }
return; return;
} }
// go through all the team gates
for (Team team : zone.getTeams()) {
if (zone.getLobby().isInTeamGate(team, playerLoc)) {
this.dropFromOldTeamIfAny(player);
if (zone.isDisabled()) {
this.handleDisabledZone(event, player, zone);
} else if (team.getPlayers().size() < zone.getTeamCap()) {
team.addPlayer(player);
team.resetSign();
if (War.war.getWarHub() != null) {
War.war.getWarHub().resetZoneSign(zone);
}
zone.keepPlayerInventory(player);
War.war.msg(player, "Your inventory is in storage until you /leave.");
zone.respawnPlayer(event, team, player);
for (Team t : zone.getTeams()) {
t.teamcast("" + player.getName() + " joined team " + team.getName() + ".");
}
} else {
event.setTo(zone.getTeleport());
War.war.badMsg(player, "Team " + team.getName() + " is full.");
}
return;
}
}
if (War.war.getWarHub() != null && zone.getLobby().isInWarHubLinkGate(playerLoc) && !War.war.getWarHub().getVolume().contains(player.getLocation())) {
this.dropFromOldTeamIfAny(player);
event.setTo(War.war.getWarHub().getLocation());
// player.teleport(war.getWarHub().getLocation());
War.war.msg(player, "Welcome to the War hub.");
return;
}
} }
} if (War.war.getWarHub() != null && zone.getLobby().isInWarHubLinkGate(playerLoc) && !War.war.getWarHub().getVolume().contains(player.getLocation())) {
this.dropFromOldTeamIfAny(player);
// Warhub zone gates event.setTo(War.war.getWarHub().getLocation());
WarHub hub = War.war.getWarHub(); // player.teleport(war.getWarHub().getLocation());
if (hub != null && hub.getVolume().contains(player.getLocation())) { War.war.msg(player, "Welcome to the War hub.");
Warzone zone = hub.getDestinationWarzoneForLocation(playerLoc);
if (zone != null && zone.getTeleport() != null) {
event.setTo(zone.getTeleport());
// player.teleport(zone.getTeleport());
War.war.msg(player, "Welcome to warzone " + zone.getName() + ".");
return; return;
} }
} }
boolean isLeaving = playerWarzone != null && playerWarzone.getLobby().isLeavingZone(playerLoc); }
Team playerTeam = Team.getTeamByPlayerName(player.getName());
if (isLeaving) { // already in a team and in warzone, leaving
// same as leave
if (playerTeam != null) {
boolean atSpawnAlready = playerTeam.getTeamSpawn().getBlockX() == player.getLocation().getBlockX() && playerTeam.getTeamSpawn().getBlockY() == player.getLocation().getBlockY() && playerTeam.getTeamSpawn().getBlockZ() == player.getLocation().getBlockZ();
if (!atSpawnAlready) {
playerWarzone.handlePlayerLeave(player, playerWarzone.getTeleport(), event, true);
return;
}
}
}
if (playerWarzone != null) { // Warhub zone gates
// Player belongs to a warzone team but is outside: he snuck out or is at spawn and died WarHub hub = War.war.getWarHub();
if (locZone == null && playerTeam != null && playerWarzone.getLobby() != null && !playerWarzone.getLobby().getVolume().contains(playerLoc) && !isLeaving) { if (hub != null && hub.getVolume().contains(player.getLocation())) {
War.war.badMsg(player, "Use /leave to exit the zone."); Warzone zone = hub.getDestinationWarzoneForLocation(playerLoc);
event.setTo(playerTeam.getTeamSpawn()); if (zone != null && zone.getTeleport() != null) {
return;
}
// Monuments
if (playerTeam != null && playerWarzone.nearAnyOwnedMonument(playerLoc, playerTeam) && player.getHealth() < 20 && player.getHealth() > 0 // don't heal the dead
&& this.random.nextInt(77) == 3) { // one chance out of many of getting healed
int currentHp = player.getHealth();
int newHp = Math.max(20, currentHp + locZone.getMonumentHeal());
player.setHealth(newHp);
String isS = "s";
String heartNum = ""; // since (newHp-currentHp)/2 won't give the right amount
if (newHp - currentHp == 2) { // no 's' in 'hearts' when it's just one heart
isS = "";
heartNum = "one ";
}
else if (newHp - currentHp % 2 == 0) {
heartNum = ((newHp - currentHp) / 2) + " ";
} else {
heartNum = ((newHp - currentHp - 1) / 2) + ".5 ";
}
War.war.msg(player, "Your dance pleases the monument's voodoo. You gain " + heartNum + "heart" + isS + "!");
return;
}
// Flag capture
if (playerWarzone.isFlagThief(player.getName()) && (playerTeam.getSpawnVolume().contains(player.getLocation()) || (playerTeam.getFlagVolume() != null && playerTeam.getFlagVolume().contains(player.getLocation())))) {
if (playerWarzone.isTeamFlagStolen(playerTeam)) {
War.war.badMsg(player, "You can't capture the enemy flag until your team's flag is returned.");
} else {
synchronized (playerWarzone) {
// flags can be captured at own spawn or own flag pole
playerTeam.addPoint();
if (playerTeam.getPoints() >= playerWarzone.getScoreCap()) {
if (playerWarzone.hasPlayerInventory(player.getName())) {
playerWarzone.restorePlayerInventory(player);
}
playerWarzone.handleScoreCapReached(player, playerTeam.getName());
event.setTo(playerWarzone.getTeleport());
// player.teleport(playerWarzone.getTeleport());
} else {
// added a point
Team victim = playerWarzone.getVictimTeamForThief(player.getName());
victim.getFlagVolume().resetBlocks(); // bring back flag to team that lost it
victim.initializeTeamFlag();
for (Team t : playerWarzone.getTeams()) {
t.teamcast(playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE
+ " captured team " + victim.getName() + "'s flag. Team " + playerTeam.getName() + " scores one point.");
}
playerWarzone.respawnPlayer(event, playerTeam, player);
playerTeam.resetSign();
playerWarzone.getLobby().resetTeamGateSign(playerTeam);
}
playerWarzone.removeThief(player.getName());
}
}
return;
}
} else if (locZone != null && locZone.getLobby() != null && !locZone.getLobby().isLeavingZone(playerLoc) && !isMaker) {
// player is not in any team, but inside warzone boundaries, get him out
Warzone zone = Warzone.getZoneByLocation(playerLoc);
event.setTo(zone.getTeleport()); event.setTo(zone.getTeleport());
// player.teleport(zone.getTeleport()); // player.teleport(zone.getTeleport());
War.war.badMsg(player, "You can't be inside a warzone without a team."); War.war.msg(player, "Welcome to warzone " + zone.getName() + ".");
return; return;
} }
} }
boolean isLeaving = playerWarzone != null && playerWarzone.getLobby().isLeavingZone(playerLoc);
Team playerTeam = Team.getTeamByPlayerName(player.getName());
if (isLeaving) { // already in a team and in warzone, leaving
// same as leave
if (playerTeam != null) {
boolean atSpawnAlready = playerTeam.getTeamSpawn().getBlockX() == player.getLocation().getBlockX() && playerTeam.getTeamSpawn().getBlockY() == player.getLocation().getBlockY() && playerTeam.getTeamSpawn().getBlockZ() == player.getLocation().getBlockZ();
if (!atSpawnAlready) {
playerWarzone.handlePlayerLeave(player, playerWarzone.getTeleport(), event, true);
return;
}
}
}
if (playerWarzone != null) {
// Player belongs to a warzone team but is outside: he snuck out or is at spawn and died
if (locZone == null && playerTeam != null && playerWarzone.getLobby() != null && !playerWarzone.getLobby().getVolume().contains(playerLoc) && !isLeaving) {
War.war.badMsg(player, "Use /leave to exit the zone.");
event.setTo(playerTeam.getTeamSpawn());
return;
}
// Monuments
if (playerTeam != null && playerWarzone.nearAnyOwnedMonument(playerLoc, playerTeam) && player.getHealth() < 20 && player.getHealth() > 0 // don't heal the dead
&& this.random.nextInt(77) == 3) { // one chance out of many of getting healed
int currentHp = player.getHealth();
int newHp = Math.max(20, currentHp + locZone.getMonumentHeal());
player.setHealth(newHp);
String isS = "s";
String heartNum = ""; // since (newHp-currentHp)/2 won't give the right amount
if (newHp - currentHp == 2) { // no 's' in 'hearts' when it's just one heart
isS = "";
heartNum = "one ";
} else if (newHp - currentHp % 2 == 0) {
heartNum = ((newHp - currentHp) / 2) + " ";
} else {
heartNum = ((newHp - currentHp - 1) / 2) + ".5 ";
}
War.war.msg(player, "Your dance pleases the monument's voodoo. You gain " + heartNum + "heart" + isS + "!");
return;
}
// Flag capture
if (playerWarzone.isFlagThief(player.getName()) && (playerTeam.getSpawnVolume().contains(player.getLocation()) || (playerTeam.getFlagVolume() != null && playerTeam.getFlagVolume().contains(player.getLocation())))) {
if (playerWarzone.isTeamFlagStolen(playerTeam)) {
War.war.badMsg(player, "You can't capture the enemy flag until your team's flag is returned.");
} else {
synchronized (playerWarzone) {
// flags can be captured at own spawn or own flag pole
playerTeam.addPoint();
if (playerTeam.getPoints() >= playerWarzone.getScoreCap()) {
if (playerWarzone.hasPlayerInventory(player.getName())) {
playerWarzone.restorePlayerInventory(player);
}
playerWarzone.handleScoreCapReached(player, playerTeam.getName());
event.setTo(playerWarzone.getTeleport());
// player.teleport(playerWarzone.getTeleport());
} else {
// added a point
Team victim = playerWarzone.getVictimTeamForThief(player.getName());
victim.getFlagVolume().resetBlocks(); // bring back flag to team that lost it
victim.initializeTeamFlag();
for (Team t : playerWarzone.getTeams()) {
t.teamcast(playerTeam.getKind().getColor() + player.getName() + ChatColor.WHITE
+ " captured team " + victim.getName() + "'s flag. Team " + playerTeam.getName() + " scores one point.");
}
playerWarzone.respawnPlayer(event, playerTeam, player);
playerTeam.resetSign();
playerWarzone.getLobby().resetTeamGateSign(playerTeam);
}
playerWarzone.removeThief(player.getName());
}
}
return;
}
} else if (locZone != null && locZone.getLobby() != null && !locZone.getLobby().isLeavingZone(playerLoc) && !isMaker) {
// player is not in any team, but inside warzone boundaries, get him out
Warzone zone = Warzone.getZoneByLocation(playerLoc);
event.setTo(zone.getTeleport());
// player.teleport(zone.getTeleport());
War.war.badMsg(player, "You can't be inside a warzone without a team.");
return;
}
} }
private void handleDisabledZone(PlayerMoveEvent event, Player player, Warzone zone) { private void handleDisabledZone(PlayerMoveEvent event, Player player, Warzone zone) {