mirror of
https://github.com/taoneill/war.git
synced 2024-11-24 03:05:54 +01:00
Documentation
This commit is contained in:
parent
9dae88a5fc
commit
8891b97a9d
@ -83,11 +83,19 @@ public class War extends JavaPlugin {
|
||||
War.war = this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see JavaPlugin.onEnable()
|
||||
* @see War.loadWar()
|
||||
*/
|
||||
public void onEnable() {
|
||||
War.war = this;
|
||||
this.loadWar();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see JavaPlugin.onDisable()
|
||||
* @see War.unloadWar()
|
||||
*/
|
||||
public void onDisable() {
|
||||
this.unloadWar();
|
||||
}
|
||||
@ -169,7 +177,7 @@ public class War extends JavaPlugin {
|
||||
* Handles war commands
|
||||
*/
|
||||
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)) {
|
||||
|
@ -24,91 +24,101 @@ import com.tommytony.war.Warzone;
|
||||
*/
|
||||
public class WarBlockListener extends BlockListener {
|
||||
|
||||
/**
|
||||
* @see BlockListener.onBlockPlace()
|
||||
*/
|
||||
@Override
|
||||
public void onBlockPlace(BlockPlaceEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
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;
|
||||
}
|
||||
if (!War.war.isLoaded()) 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;
|
||||
}
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
if (player == null || block == null) 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;
|
||||
}
|
||||
|
||||
if (team != null && zone != null && zone.isFlagThief(player.getName())) {
|
||||
// a flag thief can't drop his flag
|
||||
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;
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
// Monument capturing
|
||||
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);
|
||||
// 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
|
||||
public void onBlockBreak(BlockBreakEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
if (player != null && block != null) {
|
||||
this.handleBreakOrDamage(player, block, event);
|
||||
}
|
||||
if (!War.war.isLoaded()) return;
|
||||
Player player = event.getPlayer();
|
||||
Block block = event.getBlock();
|
||||
if (player != null && block != null) {
|
||||
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.");
|
||||
event.setCancelled(true);
|
||||
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);
|
||||
if (monument.hasOwner()) {
|
||||
|
||||
List<Team> teams = warzone.getTeams();
|
||||
for (Team t : teams) {
|
||||
t.teamcast("Team " + monument.getOwnerTeam().getName() + " loses control of monument " + monument.getName());
|
||||
@ -134,10 +145,13 @@ public class WarBlockListener extends BlockListener {
|
||||
}
|
||||
event.setCancelled(false);
|
||||
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)) {
|
||||
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)) {
|
||||
War.war.badMsg(player, "You already have a " + team.getName() + " block.");
|
||||
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
|
||||
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())) {
|
||||
// detect audacious thieves
|
||||
War.war.badMsg(player, "You can only steal one flag at a time!");
|
||||
|
@ -6,12 +6,22 @@ import org.bukkit.command.CommandSender;
|
||||
import bukkit.tommytony.war.command.*;
|
||||
|
||||
/**
|
||||
* Handles commands received by War
|
||||
*
|
||||
* @author Tim Düsterhus
|
||||
* @package bukkit.tommytony.war
|
||||
*/
|
||||
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[] arguments = null;
|
||||
|
||||
|
@ -34,7 +34,7 @@ public class WarEntityListener extends EntityListener {
|
||||
/**
|
||||
* Handles PVP-Damage
|
||||
*
|
||||
* @param event fired event
|
||||
* @param event fired event
|
||||
*/
|
||||
private void handlerAttackDefend(EntityDamageByEntityEvent event) {
|
||||
Entity attacker = event.getDamager();
|
||||
@ -132,28 +132,30 @@ public class WarEntityListener extends EntityListener {
|
||||
|
||||
/**
|
||||
* Protects important structures from explosions
|
||||
*
|
||||
* @see EntityListener.onEntityExplode()
|
||||
*/
|
||||
@Override
|
||||
public void onEntityExplode(EntityExplodeEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
// protect zones elements, lobbies and warhub from creepers
|
||||
List<Block> explodedBlocks = event.blockList();
|
||||
for (Block block : explodedBlocks) {
|
||||
if (War.war.getWarHub() != null && War.war.getWarHub().getVolume().contains(block)) {
|
||||
if (!War.war.isLoaded()) return;
|
||||
// protect zones elements, lobbies and warhub from creepers
|
||||
List<Block> explodedBlocks = event.blockList();
|
||||
for (Block block : explodedBlocks) {
|
||||
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);
|
||||
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;
|
||||
}
|
||||
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
|
||||
*
|
||||
* @see EntityListener.onEntityDamage()
|
||||
*/
|
||||
@Override
|
||||
public void onEntityDamage(EntityDamageEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Entity entity = event.getEntity();
|
||||
if (!(entity instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) entity;
|
||||
if (!War.war.isLoaded()) return;
|
||||
|
||||
// prevent godmode
|
||||
if (Warzone.getZoneByPlayerName(player.getName()) != null) {
|
||||
event.setCancelled(false);
|
||||
}
|
||||
Entity entity = event.getEntity();
|
||||
if (!(entity instanceof Player)) {
|
||||
return;
|
||||
}
|
||||
Player player = (Player) entity;
|
||||
|
||||
// pass pvp-damage
|
||||
if (event instanceof EntityDamageByEntityEvent || event instanceof EntityDamageByProjectileEvent) {
|
||||
this.handlerAttackDefend((EntityDamageByEntityEvent) event);
|
||||
} else {
|
||||
// Detect death, prevent it and respawn the player
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null && event.getDamage() >= player.getHealth()) {
|
||||
String deathMessage = "";
|
||||
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);
|
||||
// prevent godmode
|
||||
if (Warzone.getZoneByPlayerName(player.getName()) != null) {
|
||||
event.setCancelled(false);
|
||||
}
|
||||
|
||||
// pass pvp-damage
|
||||
if (event instanceof EntityDamageByEntityEvent || event instanceof EntityDamageByProjectileEvent) {
|
||||
this.handlerAttackDefend((EntityDamageByEntityEvent) event);
|
||||
} else {
|
||||
// Detect death, prevent it and respawn the player
|
||||
Warzone zone = Warzone.getZoneByPlayerName(player.getName());
|
||||
if (zone != null && event.getDamage() >= player.getHealth()) {
|
||||
String deathMessage = "";
|
||||
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
|
||||
public void onEntityCombust(EntityCombustEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (team != null && team.getSpawnVolume().contains(player.getLocation())) {
|
||||
// smother out the fire that didn't burn out when you respawned
|
||||
// Stop fire (upcast, watch out!)
|
||||
if (player instanceof CraftPlayer) {
|
||||
net.minecraft.server.Entity playerEntity = ((CraftPlayer) player).getHandle();
|
||||
playerEntity.fireTicks = 0;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
if (!War.war.isLoaded()) return;
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
Team team = Team.getTeamByPlayerName(player.getName());
|
||||
if (team != null && team.getSpawnVolume().contains(player.getLocation())) {
|
||||
// smother out the fire that didn't burn out when you respawned
|
||||
// Stop fire (upcast, watch out!)
|
||||
if (player instanceof CraftPlayer) {
|
||||
net.minecraft.server.Entity playerEntity = ((CraftPlayer) player).getHandle();
|
||||
playerEntity.fireTicks = 0;
|
||||
}
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents creatures from spawning in warzones if no creatures is active
|
||||
*
|
||||
* @see EntityListener.onCreatureSpawn()
|
||||
*/
|
||||
@Override
|
||||
public void onCreatureSpawn(CreatureSpawnEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Location location = event.getLocation();
|
||||
Warzone zone = Warzone.getZoneByLocation(location);
|
||||
if (zone != null && zone.isNoCreatures()) {
|
||||
event.setCancelled(true);
|
||||
// war.logInfo("Prevented " + event.getMobType().getName() + " from spawning in zone " + zone.getName());
|
||||
}
|
||||
if (!War.war.isLoaded()) return;
|
||||
|
||||
Location location = event.getLocation();
|
||||
Warzone zone = Warzone.getZoneByLocation(location);
|
||||
if (zone != null && zone.isNoCreatures()) {
|
||||
event.setCancelled(true);
|
||||
// war.logInfo("Prevented " + event.getMobType().getName() + " from spawning in zone " + zone.getName());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevents health regaining caused by peaceful mode
|
||||
*
|
||||
* @see EntityListener.onEntityRegainHealth()
|
||||
*/
|
||||
@Override
|
||||
public void onEntityRegainHealth(EntityRegainHealthEvent event) {
|
||||
if (War.war.isLoaded() && event.getRegainReason() == RegainReason.REGEN) {
|
||||
Entity entity = event.getEntity();
|
||||
if (entity instanceof Player) {
|
||||
Player player = (Player) entity;
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
if (zone != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
if (!War.war.isLoaded() || event.getRegainReason() != RegainReason.REGEN) return;
|
||||
Entity entity = event.getEntity();
|
||||
if (!(entity instanceof Player)) return;
|
||||
|
||||
Player player = (Player) entity;
|
||||
Warzone zone = Warzone.getZoneByLocation(player);
|
||||
if (zone != null) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -32,9 +32,13 @@ import com.tommytony.war.ZoneSetter;
|
||||
* @package bukkit.tommytony.war
|
||||
*/
|
||||
public class WarPlayerListener extends PlayerListener {
|
||||
|
||||
private java.util.Random random = new java.util.Random();
|
||||
|
||||
/**
|
||||
* Correctly removes quitting players from warzones
|
||||
*
|
||||
* @see PlayerListener.onPlayerQuit()
|
||||
*/
|
||||
@Override
|
||||
public void onPlayerQuit(PlayerQuitEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
@ -82,6 +86,7 @@ public class WarPlayerListener extends PlayerListener {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (War.war.isWandBearer(player)) {
|
||||
Item item = event.getItemDrop();
|
||||
if (item.getItemStack().getType() == Material.WOOD_SWORD) {
|
||||
@ -112,7 +117,6 @@ public class WarPlayerListener extends PlayerListener {
|
||||
ItemStack itemStack = cItem.getItemStack();
|
||||
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
|
||||
// war.badMsg(player, "You already have a " + team.getName() + " block.");
|
||||
event.setCancelled(true);
|
||||
return;
|
||||
}
|
||||
@ -154,11 +158,13 @@ public class WarPlayerListener extends PlayerListener {
|
||||
if (!War.war.isZoneMaker(player) && split.length > 0 && split[0].startsWith("/")) {
|
||||
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")) {
|
||||
// allow white commands
|
||||
for (String whiteCommand : War.war.getCommandWhitelist()) {
|
||||
if (whiteCommand.equals(command)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
@ -209,203 +215,200 @@ public class WarPlayerListener extends PlayerListener {
|
||||
|
||||
@Override
|
||||
public void onPlayerMove(PlayerMoveEvent event) {
|
||||
if (War.war.isLoaded()) {
|
||||
Player player = event.getPlayer();
|
||||
Location playerLoc = event.getFrom(); // same as player.getLoc. Don't call again we need same result.
|
||||
Warzone locZone = null;
|
||||
ZoneLobby locLobby = null;
|
||||
locZone = Warzone.getZoneByLocation(playerLoc);
|
||||
locLobby = ZoneLobby.getLobbyByLocation(playerLoc);
|
||||
boolean canPlay = War.war.canPlayWar(player);
|
||||
boolean isMaker = War.war.isZoneMaker(player);
|
||||
if (!War.war.isLoaded()) return;
|
||||
Player player = event.getPlayer();
|
||||
Location playerLoc = event.getFrom(); // same as player.getLoc. Don't call again we need same result.
|
||||
Warzone locZone = Warzone.getZoneByLocation(playerLoc);
|
||||
ZoneLobby locLobby = ZoneLobby.getLobbyByLocation(playerLoc);
|
||||
|
||||
// Zone walls
|
||||
Team currentTeam = Team.getTeamByPlayerName(player.getName());
|
||||
Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName()); // this uses the teams, so it asks: get the player's team's warzone
|
||||
boolean protecting = false;
|
||||
if (currentTeam != null) {
|
||||
// Warzone nearbyZone = war.zoneOfZoneWallAtProximity(playerLoc);
|
||||
protecting = playerWarzone.protectZoneWallAgainstPlayer(player);
|
||||
} else {
|
||||
Warzone nearbyZone = War.war.zoneOfZoneWallAtProximity(playerLoc);
|
||||
if (nearbyZone != null && !isMaker) {
|
||||
protecting = nearbyZone.protectZoneWallAgainstPlayer(player);
|
||||
}
|
||||
boolean canPlay = War.war.canPlayWar(player);
|
||||
boolean isMaker = War.war.isZoneMaker(player);
|
||||
|
||||
// Zone walls
|
||||
Team currentTeam = Team.getTeamByPlayerName(player.getName());
|
||||
Warzone playerWarzone = Warzone.getZoneByPlayerName(player.getName()); // this uses the teams, so it asks: get the player's team's warzone
|
||||
boolean protecting = false;
|
||||
if (currentTeam != null) {
|
||||
// Warzone nearbyZone = war.zoneOfZoneWallAtProximity(playerLoc);
|
||||
protecting = playerWarzone.protectZoneWallAgainstPlayer(player);
|
||||
} else {
|
||||
Warzone nearbyZone = War.war.zoneOfZoneWallAtProximity(playerLoc);
|
||||
if (nearbyZone != null && !isMaker) {
|
||||
protecting = nearbyZone.protectZoneWallAgainstPlayer(player);
|
||||
}
|
||||
}
|
||||
|
||||
if (!protecting) {
|
||||
// zone makers still need to delete their walls
|
||||
// make sure to delete any wall guards as you leave
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
zone.dropZoneWallGuardIfAny(player);
|
||||
}
|
||||
if (!protecting) {
|
||||
// zone makers still need to delete their walls
|
||||
// make sure to delete any wall guards as you leave
|
||||
for (Warzone zone : War.war.getWarzones()) {
|
||||
zone.dropZoneWallGuardIfAny(player);
|
||||
}
|
||||
}
|
||||
|
||||
// Warzone lobby gates
|
||||
if (locLobby != null) {
|
||||
Warzone zone = locLobby.getZone();
|
||||
Team oldTeam = Team.getTeamByPlayerName(player.getName());
|
||||
boolean isAutoAssignGate = false;
|
||||
if (oldTeam == null && canPlay) { // trying to counter spammy player move
|
||||
isAutoAssignGate = zone.getLobby().isAutoAssignGate(playerLoc);
|
||||
if (isAutoAssignGate) {
|
||||
// Warzone lobby gates
|
||||
if (locLobby != null) {
|
||||
Warzone zone = locLobby.getZone();
|
||||
Team oldTeam = Team.getTeamByPlayerName(player.getName());
|
||||
boolean isAutoAssignGate = false;
|
||||
if (oldTeam == null && canPlay) { // trying to counter spammy player move
|
||||
isAutoAssignGate = zone.getLobby().isAutoAssignGate(playerLoc);
|
||||
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()) {
|
||||
this.handleDisabledZone(event, player, zone);
|
||||
} else {
|
||||
this.dropFromOldTeamIfAny(player);
|
||||
int noOfPlayers = 0;
|
||||
} 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()) {
|
||||
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.");
|
||||
t.teamcast("" + player.getName() + " joined team " + team.getName() + ".");
|
||||
}
|
||||
} else {
|
||||
event.setTo(zone.getTeleport());
|
||||
War.war.badMsg(player, "Team " + team.getName() + " is 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()) {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// Warhub zone gates
|
||||
WarHub hub = War.war.getWarHub();
|
||||
if (hub != null && hub.getVolume().contains(player.getLocation())) {
|
||||
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() + ".");
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
// Warhub zone gates
|
||||
WarHub hub = War.war.getWarHub();
|
||||
if (hub != null && hub.getVolume().contains(player.getLocation())) {
|
||||
Warzone zone = hub.getDestinationWarzoneForLocation(playerLoc);
|
||||
if (zone != null && zone.getTeleport() != null) {
|
||||
event.setTo(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;
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
Loading…
Reference in New Issue
Block a user