From 45716af6b8bcc619147607ef8a87d4e7e1bf6c24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim=20D=C3=BCsterhus?= Date: Wed, 27 Jul 2011 22:01:27 +0200 Subject: [PATCH] More commands :) --- .../main/java/bukkit/tommytony/war/War.java | 173 +----------------- .../tommytony/war/WarCommandHandler.java | 60 ++++-- .../tommytony/war/WarEntityListener.java | 48 ++--- .../war/command/AbstractZoneMakerCommand.java | 25 +++ .../war/command/DeletewarhubCommand.java | 41 +++++ .../war/command/DeletezoneCommand.java | 70 +++++++ .../tommytony/war/command/JoinCommand.java | 1 + .../tommytony/war/command/LoadwarCommand.java | 19 ++ .../war/command/ResetzoneCommand.java | 58 ++++++ .../war/command/UnloadwarCommand.java | 19 ++ war/src/main/java/com/tommytony/war/Team.java | 3 - .../tommytony/war/mappers/VolumeMapper.java | 4 +- 12 files changed, 312 insertions(+), 209 deletions(-) create mode 100644 war/src/main/java/bukkit/tommytony/war/command/AbstractZoneMakerCommand.java create mode 100644 war/src/main/java/bukkit/tommytony/war/command/DeletewarhubCommand.java create mode 100644 war/src/main/java/bukkit/tommytony/war/command/DeletezoneCommand.java create mode 100644 war/src/main/java/bukkit/tommytony/war/command/LoadwarCommand.java create mode 100644 war/src/main/java/bukkit/tommytony/war/command/ResetzoneCommand.java create mode 100644 war/src/main/java/bukkit/tommytony/war/command/UnloadwarCommand.java diff --git a/war/src/main/java/bukkit/tommytony/war/War.java b/war/src/main/java/bukkit/tommytony/war/War.java index 54cbbe4..ff182d3 100644 --- a/war/src/main/java/bukkit/tommytony/war/War.java +++ b/war/src/main/java/bukkit/tommytony/war/War.java @@ -151,8 +151,8 @@ public class War extends JavaPlugin { this.warHub.getVolume().resetBlocks(); } - this.setLoaded(false); this.log("War v" + this.desc.getVersion() + " is off.", Level.INFO); + this.setLoaded(false); } /** @@ -190,10 +190,6 @@ public class War extends JavaPlugin { this.performSaveZone(player, arguments); } else if (command.equals("setzoneconfig") || command.equals("zonecfg")) { this.performSetZoneConfig(player, arguments); - } else if (command.equals("resetzone")) { - this.performResetZone(player, arguments); - } else if (command.equals("deletezone")) { - this.performDeleteZone(player, arguments); } else if (command.equals("setteam")) { this.performSetTeam(player, arguments); } else if (command.equals("setteamflag")) { @@ -206,20 +202,11 @@ public class War extends JavaPlugin { this.performDeleteMonument(player, arguments); } else if (command.equals("setwarhub")) { this.performSetWarhub(player); - } else if (command.equals("deletewarhub")) { - this.performDeleteWarhub(player); } else if (command.equals("setwarconfig") || command.equals("warcfg")) { this.performSetWarConfig(player, arguments); } else if (command.equals("zonemaker") || command.equals("zm")) { this.performZonemakerAsZonemaker(player, arguments); - } else if (command.equals("unloadwar")) { - this.unloadWar(); - } else if (command.equals("loadwar")) { - this.loadWar(); } - } else if (command.equals("setzone") // Not a zone maker but War command. - || command.equals("nextbattle") || command.equals("setzonelobby") || command.equals("savezone") || command.equals("setzoneconfig") || command.equals("resetzone") || command.equals("deletezone") || command.equals("setteam") || command.equals("deleteteam") || command.equals("setmonument") || command.equals("deletemonument") || command.equals("setwarhub") || command.equals("deletewarhub") || command.equals("setwarconfig") || command.equals("unloadwar")) { - this.badMsg(player, "You can't do this if you are not a warzone maker."); } else if (command.equals("zonemaker") || command.equals("zm")) { this.performZonemakerAsPlayer(player); } @@ -230,8 +217,8 @@ public class War extends JavaPlugin { /** * Converts the player-inventory to a loadout hashmap * - * @param PlayerInventory inv inventory to get the items from - * @param HashMap loadout the hashmap to save to + * @param inv inventory to get the items from + * @param loadout the hashmap to save to */ private void inventoryToLoadout(PlayerInventory inv, HashMap loadout) { loadout.clear(); @@ -257,8 +244,8 @@ public class War extends JavaPlugin { /** * Converts the player-inventory to a loadout hashmap * - * @param Player player player to get the inventory to get the items from - * @param HashMap loadout the hashmap to save to + * @param player player to get the inventory to get the items from + * @param loadout the hashmap to save to */ private void inventoryToLoadout(Player player, HashMap loadout) { this.inventoryToLoadout(player.getInventory(), loadout); @@ -326,26 +313,6 @@ public class War extends JavaPlugin { } } - public void performDeleteWarhub(Player player) { - if (this.warHub != null) { - // reset existing hub - this.warHub.getVolume().resetBlocks(); - VolumeMapper.delete(this.warHub.getVolume(), this); - this.warHub = null; - for (Warzone zone : this.warzones) { - if (zone.getLobby() != null) { - zone.getLobby().getVolume().resetBlocks(); - zone.getLobby().initialize(); - } - } - - this.msg(player, "War hub removed."); - } else { - this.badMsg(player, "No War hub to delete."); - } - WarMapper.save(); - } - public void performSetWarhub(Player player) { if (this.warzones.size() > 0) { if (this.warHub != null) { @@ -509,95 +476,6 @@ public class War extends JavaPlugin { } } - public void performDeleteZone(Player player, String[] arguments) { - if (arguments.length == 0 && !this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) { - this.badMsg(player, "Usage: /deletezone [warzone-name]. " + "Deletes the warzone. " + "Must be in the warzone or name must be provided (try /zones and /zone). "); - } else { - ZoneLobby lobby = null; - Warzone warzone = null; - if (arguments.length == 1) { // get zone by name - for (Warzone tmp : this.getWarzones()) { - if (tmp.getName().toLowerCase().startsWith(arguments[0].toLowerCase())) { - warzone = tmp; - break; - } - } - if (warzone == null) { - this.badMsg(player, "No such warzone."); - return; - } - } else { // get zone by position - warzone = Warzone.getZoneByLocation(player); - lobby = ZoneLobby.getLobbyByLocation(player); - } - - if (warzone == null && lobby != null) { - warzone = lobby.getZone(); - } else { - lobby = warzone.getLobby(); - } - - for (Team t : warzone.getTeams()) { - if (t.getTeamFlag() != null) { - t.getFlagVolume().resetBlocks(); - } - t.getSpawnVolume().resetBlocks(); - - // reset inventory - for (Player p : t.getPlayers()) { - warzone.restorePlayerInventory(p); - } - } - for (Monument m : warzone.getMonuments()) { - m.getVolume().resetBlocks(); - } - if (warzone.getLobby() != null) { - warzone.getLobby().getVolume().resetBlocks(); - } - warzone.getVolume().resetBlocks(); - this.getWarzones().remove(warzone); - WarMapper.save(); - WarzoneMapper.delete(warzone.getName()); - if (this.warHub != null) { // warhub has to change - this.warHub.getVolume().resetBlocks(); - this.warHub.initialize(); - } - this.msg(player, "Warzone " + warzone.getName() + " removed."); - } - } - - public void performResetZone(Player player, String[] arguments) { - if (!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) { - this.badMsg(player, "Usage: /resetzone. Reloads the zone. Must be in warzone or lobby."); - } else { - Warzone warzone = Warzone.getZoneByLocation(player); - ZoneLobby lobby = ZoneLobby.getLobbyByLocation(player); - if (warzone == null && lobby != null) { - warzone = lobby.getZone(); - } else { - lobby = warzone.getLobby(); - } - warzone.clearFlagThieves(); - for (Team team : warzone.getTeams()) { - team.teamcast("The war has ended. " + warzone.getTeamInformation() + " Resetting warzone " + warzone.getName() + " and teams..."); - for (Player p : team.getPlayers()) { - warzone.restorePlayerInventory(p); - p.teleport(warzone.getTeleport()); - this.msg(player, "You have left the warzone. Your inventory has been restored."); - } - team.resetPoints(); - team.getPlayers().clear(); - } - - this.msg(player, "Reloading warzone " + warzone.getName() + "."); - warzone.getVolume().resetBlocksAsJob(); - if (lobby != null) { - lobby.getVolume().resetBlocksAsJob(); - } - warzone.initializeZoneAsJob(); - } - } - public void performSetZoneConfig(Player player, String[] arguments) { if ((!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) || arguments.length == 0) { this.badMsg(player, "Usage: /setzoneconfig lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on " + "Please give at leaset one named parameter. Does not save the blocks of the warzone. Resets the zone with the new config. Must be in warzone."); @@ -838,11 +716,9 @@ public class War extends JavaPlugin { warzone.setNoCreatures(onOff.equals("on") || onOff.equals("true")); } if (namedParams.containsKey("loadout")) { - // String loadoutType = namedParams.get("loadout"); this.inventoryToLoadout(player, warzone.getLoadout()); } if (namedParams.containsKey("reward")) { - // String rewardType = namedParams.get("reward"); this.inventoryToLoadout(player, warzone.getReward()); } if (namedParams.containsKey("resetonempty")) { @@ -887,7 +763,7 @@ public class War extends JavaPlugin { } if (namedParams.containsKey("ff")) { String onOff = namedParams.get("ff"); - this.setDefaultFriendlyFire(onOff.equals("on")); + this.setDefaultFriendlyFire(onOff.equals("on") || onOff.equals("true")); } if (namedParams.containsKey("autoassign")) { String onOff = namedParams.get("autoassign"); @@ -928,11 +804,9 @@ public class War extends JavaPlugin { this.setDefaultNoCreatures(onOff.equals("on") || onOff.equals("true")); } if (namedParams.containsKey("loadout")) { - // String loadoutType = namedParams.get("loadout"); this.inventoryToLoadout(player, this.getDefaultLoadout()); } if (namedParams.containsKey("reward")) { - // String rewardType = namedParams.get("reward"); this.inventoryToLoadout(player, this.getDefaultReward()); } if (namedParams.containsKey("resetonempty")) { @@ -948,7 +822,6 @@ public class War extends JavaPlugin { this.setDefaultResetOnUnload(onOff.equals("on") || onOff.equals("true")); } if (namedParams.containsKey("rallypoint")) { - // String rewardType = namedParams.get("reward"); this.setZoneRallyPoint(namedParams.get("rallypoint"), player); } @@ -968,10 +841,6 @@ public class War extends JavaPlugin { } } - public Logger getLogger() { - return this.log; - } - public boolean inAnyWarzone(Location location) { Block locBlock = location.getWorld().getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ()); Warzone currentZone = Warzone.getZoneByLocation(location); @@ -1025,28 +894,6 @@ public class War extends JavaPlugin { return str; } - /** - * Sends a message of Level Info to the logger - * - * @param String str message to send - * @deprecated Use War.log() now - */ - @Deprecated - public void logInfo(String str) { - this.log(str, Level.INFO); - } - - /** - * Sends a message of Level Warning to the logger - * - * @param String str message to send - * @deprecated Use War.log() now - */ - @Deprecated - public void logWarn(String str) { - this.log(str, Level.WARNING); - } - /** * Logs a specified message with a specified level * @@ -1125,6 +972,10 @@ public class War extends JavaPlugin { return this.defaultLoadout; } + public Logger getLogger() { + return this.log; + } + public void setDefaultLifepool(int defaultLifepool) { this.defaultLifepool = defaultLifepool; } @@ -1149,10 +1000,6 @@ public class War extends JavaPlugin { return this.defaultFriendlyFire; } - public String getName() { - return this.desc.getName(); - } - public Warzone zoneOfZoneWallAtProximity(Location location) { for (Warzone zone : this.warzones) { if (zone.getWorld() == location.getWorld() && zone.isNearWall(location)) { diff --git a/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java b/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java index 5e1571e..541097b 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java +++ b/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java @@ -33,26 +33,50 @@ public class WarCommandHandler { } AbstractWarCommand commandObj = null; - if (command.equals("zones") || command.equals("warzones")) { - commandObj = new WarzonesCommand(this, sender, arguments); + try { + if (command.equals("zones") || command.equals("warzones")) { + commandObj = new WarzonesCommand(this, sender, arguments); + } + else if (command.equals("zone") || command.equals("warzone")) { + commandObj = new WarzoneCommand(this, sender, arguments); + } + else if (command.equals("teams")) { + commandObj = new TeamsCommand(this, sender, arguments); + } + else if (command.equals("join")) { + commandObj = new JoinCommand(this, sender, arguments); + } + else if (command.equals("leave")) { + commandObj = new LeaveCommand(this, sender, arguments); + } + else if (command.equals("team")) { + commandObj = new TeamCommand(this, sender, arguments); + } + else if (command.equals("deletezone")) { + commandObj = new DeletezoneCommand(this, sender, arguments); + } + else if (command.equals("resetzone")) { + commandObj = new ResetzoneCommand(this, sender, arguments); + } + else if (command.equals("deletewarhub")) { + commandObj = new DeletewarhubCommand(this, sender, arguments); + } + else if (command.equals("loadwar")) { + commandObj = new LoadwarCommand(this, sender, arguments); + } + else if (command.equals("unloadwar")) { + commandObj = new UnloadwarCommand(this, sender, arguments); + } + else { + // we are not responsible for this command + return true; + } } - else if (command.equals("zone") || command.equals("warzone")) { - commandObj = new WarzoneCommand(this, sender, arguments); + catch (AbstractZoneMakerCommand.NoZoneMakerException e) { + sender.sendMessage("You can't do this if you are not a warzone maker."); + return true; } - else if (command.equals("teams")) { - commandObj = new TeamsCommand(this, sender, arguments); - } - else if (command.equals("join")) { - commandObj = new JoinCommand(this, sender, arguments); - } - else if (command.equals("leave")) { - commandObj = new LeaveCommand(this, sender, arguments); - } - else if (command.equals("team")) { - commandObj = new TeamCommand(this, sender, arguments); - } - else { - // we are not responsible for this command + catch (Exception e) { return true; } diff --git a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java index 8bb5c29..0ac6538 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java +++ b/war/src/main/java/bukkit/tommytony/war/WarEntityListener.java @@ -34,13 +34,13 @@ public class WarEntityListener extends EntityListener { /** * Handles PVP-Damage * - * @param EntityDamageByEntityEvent event fired event + * @param event fired event */ private void handlerAttackDefend(EntityDamageByEntityEvent event) { Entity attacker = event.getDamager(); Entity defender = event.getEntity(); - if (attacker != null && defender != null && attacker instanceof Player && defender instanceof Player) { + if (attacker == null && defender != null && attacker instanceof Player && defender instanceof Player) { // only let adversaries (same warzone, different team) attack each other Player a = (Player) attacker; Player d = (Player) defender; @@ -48,16 +48,17 @@ public class WarEntityListener extends EntityListener { Team attackerTeam = Team.getTeamByPlayerName(a.getName()); Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName()); Team defenderTeam = Team.getTeamByPlayerName(d.getName()); + if (attackerTeam != null && defenderTeam != null && attackerTeam != defenderTeam && attackerWarzone == defenderWarzone) { // Make sure one of the players isn't in the spawn if (defenderTeam.getSpawnVolume().contains(d.getLocation())) { // attacking person in spawn - if (!defenderWarzone.isFlagThief(d.getName())) { // thiefs can always be attacked + if (!defenderWarzone.isFlagThief(d.getName())) { // thieves can always be attacked War.war.badMsg(a, "Can't attack a player that's inside his team's spawn."); event.setCancelled(true); } } else if (attackerTeam.getSpawnVolume().contains(a.getLocation()) && !attackerTeam.getSpawnVolume().contains(d.getLocation())) { // only let a player inside spawn attack an enemy player if that player enters the spawn - if (!attackerWarzone.isFlagThief(a.getName())) { // thiefs can always attack + if (!attackerWarzone.isFlagThief(a.getName())) { // thieves can always attack War.war.badMsg(a, "Can't attack a player from inside your spawn."); event.setCancelled(true); } @@ -66,8 +67,9 @@ public class WarEntityListener extends EntityListener { // Detect death, prevent it and respawn the player if (event.getDamage() >= d.getHealth()) { String killMessage = ""; - killMessage = attackerTeam.getKind().getColor() + a.getDisplayName() + ChatColor.WHITE + - " killed " + defenderTeam.getKind().getColor() + d.getDisplayName(); + String attackerString = attackerTeam.getKind().getColor() + a.getDisplayName(); + String defenderString = defenderTeam.getKind().getColor() + d.getDisplayName(); + killMessage = attackerString + ChatColor.WHITE + " killed " + defenderString; for (Team team : defenderWarzone.getTeams()) { team.teamcast(killMessage); } @@ -92,7 +94,7 @@ public class WarEntityListener extends EntityListener { } else { War.war.badMsg(a, "Your attack missed!"); if (attackerTeam == null) { - War.war.badMsg(a, "You must join a team " + ", then you'll be able to damage people " + "in the other teams in that warzone."); + War.war.badMsg(a, "You must join a team, then you'll be able to damage people " + "in the other teams in that warzone."); } else if (defenderTeam == null) { War.war.badMsg(a, "Your target is not in a team."); } else if (attacker != null && defender != null && attacker.getEntityId() == defender.getEntityId()) { @@ -104,7 +106,6 @@ public class WarEntityListener extends EntityListener { } event.setCancelled(true); // can't attack someone inside a warzone if you're not in a team } - } else if (defender instanceof Player) { // attacked by dispenser arrow most probably // Detect death, prevent it and respawn the player @@ -112,12 +113,13 @@ public class WarEntityListener extends EntityListener { Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName()); if (d != null && defenderWarzone != null && event.getDamage() >= d.getHealth()) { String deathMessage = ""; + String defenderString = Team.getTeamByPlayerName(d.getName()).getKind().getColor() + d.getDisplayName(); if (event instanceof EntityDamageByProjectileEvent) - deathMessage = "A dispenser killed " + Team.getTeamByPlayerName(d.getName()).getKind().getColor() + d.getDisplayName(); + deathMessage = "A dispenser killed " + defenderString; else if (event.getDamager() instanceof CraftTNTPrimed) - deathMessage = Team.getTeamByPlayerName(d.getName()).getKind().getColor() + d.getDisplayName() + ChatColor.WHITE + " exploded"; + deathMessage = defenderString + ChatColor.WHITE + " exploded"; else - deathMessage = Team.getTeamByPlayerName(d.getName()).getKind().getColor() + d.getDisplayName() + ChatColor.WHITE + " died"; + deathMessage = defenderString + ChatColor.WHITE + " died"; for (Team team : defenderWarzone.getTeams()) { team.teamcast(deathMessage); } @@ -163,8 +165,11 @@ public class WarEntityListener extends EntityListener { public void onEntityDamage(EntityDamageEvent event) { if (War.war.isLoaded()) { Entity entity = event.getEntity(); + if (!(entity instanceof Player)) return; + Player player = (Player) entity; + // prevent godmode - if (entity instanceof Player && Warzone.getZoneByPlayerName(((Player) entity).getName()) != null) { + if (Warzone.getZoneByPlayerName(player.getName()) != null) { event.setCancelled(false); } @@ -173,18 +178,15 @@ public class WarEntityListener extends EntityListener { this.handlerAttackDefend((EntityDamageByEntityEvent) event); } else { // Detect death, prevent it and respawn the player - if (entity instanceof Player) { - Player player = (Player) entity; - 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); + 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); } } } diff --git a/war/src/main/java/bukkit/tommytony/war/command/AbstractZoneMakerCommand.java b/war/src/main/java/bukkit/tommytony/war/command/AbstractZoneMakerCommand.java new file mode 100644 index 0000000..d1acfdf --- /dev/null +++ b/war/src/main/java/bukkit/tommytony/war/command/AbstractZoneMakerCommand.java @@ -0,0 +1,25 @@ +package bukkit.tommytony.war.command; + +import org.bukkit.command.CommandSender; +import org.bukkit.command.ConsoleCommandSender; +import org.bukkit.entity.Player; + +import bukkit.tommytony.war.War; +import bukkit.tommytony.war.WarCommandHandler; + +public abstract class AbstractZoneMakerCommand extends AbstractWarCommand { + + public AbstractZoneMakerCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NoZoneMakerException { + super(handler, sender, args); + if (sender instanceof Player) { + if (War.war.isZoneMaker((Player) sender)) throw new NoZoneMakerException(); + } + else if (!(sender instanceof ConsoleCommandSender)) { + throw new NoZoneMakerException(); + } + } + + public class NoZoneMakerException extends Exception { + private static final long serialVersionUID = -70491862705766496L; + } +} diff --git a/war/src/main/java/bukkit/tommytony/war/command/DeletewarhubCommand.java b/war/src/main/java/bukkit/tommytony/war/command/DeletewarhubCommand.java new file mode 100644 index 0000000..9b988a1 --- /dev/null +++ b/war/src/main/java/bukkit/tommytony/war/command/DeletewarhubCommand.java @@ -0,0 +1,41 @@ +package bukkit.tommytony.war.command; + +import org.bukkit.command.CommandSender; + +import com.tommytony.war.Warzone; +import com.tommytony.war.WarHub; + +import com.tommytony.war.mappers.VolumeMapper; +import com.tommytony.war.mappers.WarMapper; + +import bukkit.tommytony.war.War; +import bukkit.tommytony.war.WarCommandHandler; + +public class DeletewarhubCommand extends AbstractZoneMakerCommand { + public DeletewarhubCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NoZoneMakerException { + super(handler, sender, args); + } + + @Override + public boolean handle() { + if (War.war.getWarHub() != null) { + // reset existing hub + War.war.getWarHub().getVolume().resetBlocks(); + VolumeMapper.delete(War.war.getWarHub().getVolume()); + War.war.setWarHub((WarHub) null); + for (Warzone zone : War.war.getWarzones()) { + if (zone.getLobby() != null) { + zone.getLobby().getVolume().resetBlocks(); + zone.getLobby().initialize(); + } + } + + this.msg("War hub removed."); + } else { + this.msg("No War hub to delete."); + } + WarMapper.save(); + + return true; + } +} diff --git a/war/src/main/java/bukkit/tommytony/war/command/DeletezoneCommand.java b/war/src/main/java/bukkit/tommytony/war/command/DeletezoneCommand.java new file mode 100644 index 0000000..43d6f99 --- /dev/null +++ b/war/src/main/java/bukkit/tommytony/war/command/DeletezoneCommand.java @@ -0,0 +1,70 @@ +package bukkit.tommytony.war.command; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.tommytony.war.Monument; +import com.tommytony.war.Team; +import com.tommytony.war.Warzone; +import com.tommytony.war.ZoneLobby; +import com.tommytony.war.mappers.WarMapper; +import com.tommytony.war.mappers.WarzoneMapper; + +import bukkit.tommytony.war.War; +import bukkit.tommytony.war.WarCommandHandler; + +public class DeletezoneCommand extends AbstractZoneMakerCommand { + public DeletezoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NoZoneMakerException { + super(handler, sender, args); + } + + @Override + public boolean handle() { + Warzone zone; + if (this.args.length == 1) { + zone = Warzone.getZoneByName(this.args[0]); + } else { + if (!(this.sender instanceof Player)) { + return false; + } + zone = Warzone.getZoneByLocation((Player) this.sender); + if (zone == null) { + ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.sender); + if (lobby == null) return false; + zone = lobby.getZone(); + } + } + if (zone == null) { + return false; + } + + for (Team t : zone.getTeams()) { + if (t.getTeamFlag() != null) { + t.getFlagVolume().resetBlocks(); + } + t.getSpawnVolume().resetBlocks(); + + // reset inventory + for (Player p : t.getPlayers()) { + zone.restorePlayerInventory(p); + } + } + for (Monument m : zone.getMonuments()) { + m.getVolume().resetBlocks(); + } + if (zone.getLobby() != null) { + zone.getLobby().getVolume().resetBlocks(); + } + zone.getVolume().resetBlocks(); + War.war.getWarzones().remove(zone); + WarMapper.save(); + WarzoneMapper.delete(zone.getName()); + if (War.war.getWarHub() != null) { // warhub has to change + War.war.getWarHub().getVolume().resetBlocks(); + War.war.getWarHub().initialize(); + } + this.msg("Warzone " + zone.getName() + " removed."); + + return true; + } +} diff --git a/war/src/main/java/bukkit/tommytony/war/command/JoinCommand.java b/war/src/main/java/bukkit/tommytony/war/command/JoinCommand.java index 58cdc8f..42e3c7c 100644 --- a/war/src/main/java/bukkit/tommytony/war/command/JoinCommand.java +++ b/war/src/main/java/bukkit/tommytony/war/command/JoinCommand.java @@ -19,6 +19,7 @@ public class JoinCommand extends AbstractWarCommand { super(handler, sender, args); } + @Override public boolean handle() { if (!(this.sender instanceof Player)) return true; diff --git a/war/src/main/java/bukkit/tommytony/war/command/LoadwarCommand.java b/war/src/main/java/bukkit/tommytony/war/command/LoadwarCommand.java new file mode 100644 index 0000000..efb8854 --- /dev/null +++ b/war/src/main/java/bukkit/tommytony/war/command/LoadwarCommand.java @@ -0,0 +1,19 @@ +package bukkit.tommytony.war.command; + +import org.bukkit.command.CommandSender; + +import bukkit.tommytony.war.War; +import bukkit.tommytony.war.WarCommandHandler; + +public class LoadwarCommand extends AbstractZoneMakerCommand { + public LoadwarCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NoZoneMakerException { + super(handler, sender, args); + } + + @Override + public boolean handle() { + War.war.loadWar(); + + return true; + } +} diff --git a/war/src/main/java/bukkit/tommytony/war/command/ResetzoneCommand.java b/war/src/main/java/bukkit/tommytony/war/command/ResetzoneCommand.java new file mode 100644 index 0000000..af5d02f --- /dev/null +++ b/war/src/main/java/bukkit/tommytony/war/command/ResetzoneCommand.java @@ -0,0 +1,58 @@ +package bukkit.tommytony.war.command; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.tommytony.war.Team; +import com.tommytony.war.Warzone; +import com.tommytony.war.ZoneLobby; +import bukkit.tommytony.war.War; +import bukkit.tommytony.war.WarCommandHandler; + +public class ResetzoneCommand extends AbstractZoneMakerCommand { + public ResetzoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NoZoneMakerException { + super(handler, sender, args); + } + + @Override + public boolean handle() { + Warzone zone; + if (this.args.length == 1) { + zone = Warzone.getZoneByName(this.args[0]); + } else { + if (!(this.sender instanceof Player)) { + return false; + } + zone = Warzone.getZoneByLocation((Player) this.sender); + if (zone == null) { + ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.sender); + if (lobby == null) return false; + zone = lobby.getZone(); + } + } + if (zone == null) { + return false; + } + + zone.clearFlagThieves(); + for (Team team : zone.getTeams()) { + team.teamcast("The war has ended. " + zone.getTeamInformation() + " Resetting warzone " + zone.getName() + " and teams..."); + for (Player p : team.getPlayers()) { + zone.restorePlayerInventory(p); + p.teleport(zone.getTeleport()); + War.war.msg(p, "You have left the warzone. Your inventory has been restored."); + } + team.resetPoints(); + team.getPlayers().clear(); + } + + this.msg("Reloading warzone " + zone.getName() + "."); + zone.getVolume().resetBlocksAsJob(); + if (zone.getLobby() != null) { + zone.getLobby().getVolume().resetBlocksAsJob(); + } + zone.initializeZoneAsJob(); + + return true; + } +} diff --git a/war/src/main/java/bukkit/tommytony/war/command/UnloadwarCommand.java b/war/src/main/java/bukkit/tommytony/war/command/UnloadwarCommand.java new file mode 100644 index 0000000..dda4dd6 --- /dev/null +++ b/war/src/main/java/bukkit/tommytony/war/command/UnloadwarCommand.java @@ -0,0 +1,19 @@ +package bukkit.tommytony.war.command; + +import org.bukkit.command.CommandSender; + +import bukkit.tommytony.war.War; +import bukkit.tommytony.war.WarCommandHandler; + +public class UnloadwarCommand extends AbstractZoneMakerCommand { + public UnloadwarCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NoZoneMakerException { + super(handler, sender, args); + } + + @Override + public boolean handle() { + War.war.unloadWar(); + + return true; + } +} diff --git a/war/src/main/java/com/tommytony/war/Team.java b/war/src/main/java/com/tommytony/war/Team.java index 19a6147..349bd7d 100644 --- a/war/src/main/java/com/tommytony/war/Team.java +++ b/war/src/main/java/com/tommytony/war/Team.java @@ -317,7 +317,6 @@ public class Team { } public void setTeamSpawn(Location teamSpawn) { - this.teamSpawn = teamSpawn; // this resets the block to old state @@ -501,7 +500,6 @@ public class Team { } public void setTeamFlag(Location teamFlag) { - this.teamFlag = teamFlag; // this resets the block to old state @@ -524,7 +522,6 @@ public class Team { } public Location getTeamFlag() { - return this.teamFlag; } } diff --git a/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java b/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java index 5a3d099..1f8f497 100644 --- a/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/VolumeMapper.java @@ -285,11 +285,11 @@ public class VolumeMapper { } } - public static void delete(Volume volume, War war) { + public static void delete(Volume volume) { File volFile = new File("War/dat/volume-" + volume.getName()); boolean deletedData = volFile.delete(); if (!deletedData) { - war.log("Failed to delete file " + volFile.getName(), Level.WARNING); + War.war.log("Failed to delete file " + volFile.getName(), Level.WARNING); } }