More commands :)

This commit is contained in:
Tim Düsterhus 2011-07-27 22:01:27 +02:00
parent 736f270a4a
commit 45716af6b8
12 changed files with 312 additions and 209 deletions

View File

@ -151,8 +151,8 @@ public class War extends JavaPlugin {
this.warHub.getVolume().resetBlocks(); this.warHub.getVolume().resetBlocks();
} }
this.setLoaded(false);
this.log("War v" + this.desc.getVersion() + " is off.", Level.INFO); 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); this.performSaveZone(player, arguments);
} else if (command.equals("setzoneconfig") || command.equals("zonecfg")) { } else if (command.equals("setzoneconfig") || command.equals("zonecfg")) {
this.performSetZoneConfig(player, arguments); 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")) { } else if (command.equals("setteam")) {
this.performSetTeam(player, arguments); this.performSetTeam(player, arguments);
} else if (command.equals("setteamflag")) { } else if (command.equals("setteamflag")) {
@ -206,20 +202,11 @@ public class War extends JavaPlugin {
this.performDeleteMonument(player, arguments); this.performDeleteMonument(player, arguments);
} else if (command.equals("setwarhub")) { } else if (command.equals("setwarhub")) {
this.performSetWarhub(player); this.performSetWarhub(player);
} else if (command.equals("deletewarhub")) {
this.performDeleteWarhub(player);
} else if (command.equals("setwarconfig") || command.equals("warcfg")) { } else if (command.equals("setwarconfig") || command.equals("warcfg")) {
this.performSetWarConfig(player, arguments); this.performSetWarConfig(player, arguments);
} else if (command.equals("zonemaker") || command.equals("zm")) { } else if (command.equals("zonemaker") || command.equals("zm")) {
this.performZonemakerAsZonemaker(player, arguments); 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")) { } else if (command.equals("zonemaker") || command.equals("zm")) {
this.performZonemakerAsPlayer(player); this.performZonemakerAsPlayer(player);
} }
@ -230,8 +217,8 @@ public class War extends JavaPlugin {
/** /**
* Converts the player-inventory to a loadout hashmap * Converts the player-inventory to a loadout hashmap
* *
* @param PlayerInventory inv inventory to get the items from * @param inv inventory to get the items from
* @param HashMap<Integer, ItemStack> loadout the hashmap to save to * @param loadout the hashmap to save to
*/ */
private void inventoryToLoadout(PlayerInventory inv, HashMap<Integer, ItemStack> loadout) { private void inventoryToLoadout(PlayerInventory inv, HashMap<Integer, ItemStack> loadout) {
loadout.clear(); loadout.clear();
@ -257,8 +244,8 @@ public class War extends JavaPlugin {
/** /**
* Converts the player-inventory to a loadout hashmap * Converts the player-inventory to a loadout hashmap
* *
* @param Player player player to get the inventory to get the items from * @param player player to get the inventory to get the items from
* @param HashMap<Integer, ItemStack> loadout the hashmap to save to * @param loadout the hashmap to save to
*/ */
private void inventoryToLoadout(Player player, HashMap<Integer, ItemStack> loadout) { private void inventoryToLoadout(Player player, HashMap<Integer, ItemStack> loadout) {
this.inventoryToLoadout(player.getInventory(), 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) { public void performSetWarhub(Player player) {
if (this.warzones.size() > 0) { if (this.warzones.size() > 0) {
if (this.warHub != null) { 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) { public void performSetZoneConfig(Player player, String[] arguments) {
if ((!this.inAnyWarzone(player.getLocation()) && !this.inAnyWarzoneLobby(player.getLocation())) || arguments.length == 0) { 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."); 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")); warzone.setNoCreatures(onOff.equals("on") || onOff.equals("true"));
} }
if (namedParams.containsKey("loadout")) { if (namedParams.containsKey("loadout")) {
// String loadoutType = namedParams.get("loadout");
this.inventoryToLoadout(player, warzone.getLoadout()); this.inventoryToLoadout(player, warzone.getLoadout());
} }
if (namedParams.containsKey("reward")) { if (namedParams.containsKey("reward")) {
// String rewardType = namedParams.get("reward");
this.inventoryToLoadout(player, warzone.getReward()); this.inventoryToLoadout(player, warzone.getReward());
} }
if (namedParams.containsKey("resetonempty")) { if (namedParams.containsKey("resetonempty")) {
@ -887,7 +763,7 @@ public class War extends JavaPlugin {
} }
if (namedParams.containsKey("ff")) { if (namedParams.containsKey("ff")) {
String onOff = namedParams.get("ff"); String onOff = namedParams.get("ff");
this.setDefaultFriendlyFire(onOff.equals("on")); this.setDefaultFriendlyFire(onOff.equals("on") || onOff.equals("true"));
} }
if (namedParams.containsKey("autoassign")) { if (namedParams.containsKey("autoassign")) {
String onOff = namedParams.get("autoassign"); String onOff = namedParams.get("autoassign");
@ -928,11 +804,9 @@ public class War extends JavaPlugin {
this.setDefaultNoCreatures(onOff.equals("on") || onOff.equals("true")); this.setDefaultNoCreatures(onOff.equals("on") || onOff.equals("true"));
} }
if (namedParams.containsKey("loadout")) { if (namedParams.containsKey("loadout")) {
// String loadoutType = namedParams.get("loadout");
this.inventoryToLoadout(player, this.getDefaultLoadout()); this.inventoryToLoadout(player, this.getDefaultLoadout());
} }
if (namedParams.containsKey("reward")) { if (namedParams.containsKey("reward")) {
// String rewardType = namedParams.get("reward");
this.inventoryToLoadout(player, this.getDefaultReward()); this.inventoryToLoadout(player, this.getDefaultReward());
} }
if (namedParams.containsKey("resetonempty")) { if (namedParams.containsKey("resetonempty")) {
@ -948,7 +822,6 @@ public class War extends JavaPlugin {
this.setDefaultResetOnUnload(onOff.equals("on") || onOff.equals("true")); this.setDefaultResetOnUnload(onOff.equals("on") || onOff.equals("true"));
} }
if (namedParams.containsKey("rallypoint")) { if (namedParams.containsKey("rallypoint")) {
// String rewardType = namedParams.get("reward");
this.setZoneRallyPoint(namedParams.get("rallypoint"), player); 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) { public boolean inAnyWarzone(Location location) {
Block locBlock = location.getWorld().getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ()); Block locBlock = location.getWorld().getBlockAt(location.getBlockX(), location.getBlockY(), location.getBlockZ());
Warzone currentZone = Warzone.getZoneByLocation(location); Warzone currentZone = Warzone.getZoneByLocation(location);
@ -1025,28 +894,6 @@ public class War extends JavaPlugin {
return str; 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 * Logs a specified message with a specified level
* *
@ -1125,6 +972,10 @@ public class War extends JavaPlugin {
return this.defaultLoadout; return this.defaultLoadout;
} }
public Logger getLogger() {
return this.log;
}
public void setDefaultLifepool(int defaultLifepool) { public void setDefaultLifepool(int defaultLifepool) {
this.defaultLifepool = defaultLifepool; this.defaultLifepool = defaultLifepool;
} }
@ -1149,10 +1000,6 @@ public class War extends JavaPlugin {
return this.defaultFriendlyFire; return this.defaultFriendlyFire;
} }
public String getName() {
return this.desc.getName();
}
public Warzone zoneOfZoneWallAtProximity(Location location) { public Warzone zoneOfZoneWallAtProximity(Location location) {
for (Warzone zone : this.warzones) { for (Warzone zone : this.warzones) {
if (zone.getWorld() == location.getWorld() && zone.isNearWall(location)) { if (zone.getWorld() == location.getWorld() && zone.isNearWall(location)) {

View File

@ -33,6 +33,7 @@ public class WarCommandHandler {
} }
AbstractWarCommand commandObj = null; AbstractWarCommand commandObj = null;
try {
if (command.equals("zones") || command.equals("warzones")) { if (command.equals("zones") || command.equals("warzones")) {
commandObj = new WarzonesCommand(this, sender, arguments); commandObj = new WarzonesCommand(this, sender, arguments);
} }
@ -51,10 +52,33 @@ public class WarCommandHandler {
else if (command.equals("team")) { else if (command.equals("team")) {
commandObj = new TeamCommand(this, sender, arguments); 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 { else {
// we are not responsible for this command // we are not responsible for this command
return true; return true;
} }
}
catch (AbstractZoneMakerCommand.NoZoneMakerException e) {
sender.sendMessage("You can't do this if you are not a warzone maker.");
return true;
}
catch (Exception e) {
return true;
}
return commandObj.handle(); return commandObj.handle();
} }

View File

@ -34,13 +34,13 @@ public class WarEntityListener extends EntityListener {
/** /**
* Handles PVP-Damage * Handles PVP-Damage
* *
* @param EntityDamageByEntityEvent 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();
Entity defender = event.getEntity(); 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 // only let adversaries (same warzone, different team) attack each other
Player a = (Player) attacker; Player a = (Player) attacker;
Player d = (Player) defender; Player d = (Player) defender;
@ -48,16 +48,17 @@ public class WarEntityListener extends EntityListener {
Team attackerTeam = Team.getTeamByPlayerName(a.getName()); Team attackerTeam = Team.getTeamByPlayerName(a.getName());
Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName()); Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName());
Team defenderTeam = Team.getTeamByPlayerName(d.getName()); Team defenderTeam = Team.getTeamByPlayerName(d.getName());
if (attackerTeam != null && defenderTeam != null && attackerTeam != defenderTeam && attackerWarzone == defenderWarzone) { if (attackerTeam != null && defenderTeam != null && attackerTeam != defenderTeam && attackerWarzone == defenderWarzone) {
// Make sure one of the players isn't in the spawn // Make sure one of the players isn't in the spawn
if (defenderTeam.getSpawnVolume().contains(d.getLocation())) { // attacking person in 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."); War.war.badMsg(a, "Can't attack a player that's inside his team's spawn.");
event.setCancelled(true); event.setCancelled(true);
} }
} else if (attackerTeam.getSpawnVolume().contains(a.getLocation()) && !attackerTeam.getSpawnVolume().contains(d.getLocation())) { } 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 // 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."); War.war.badMsg(a, "Can't attack a player from inside your spawn.");
event.setCancelled(true); event.setCancelled(true);
} }
@ -66,8 +67,9 @@ public class WarEntityListener extends EntityListener {
// Detect death, prevent it and respawn the player // Detect death, prevent it and respawn the player
if (event.getDamage() >= d.getHealth()) { if (event.getDamage() >= d.getHealth()) {
String killMessage = ""; String killMessage = "";
killMessage = attackerTeam.getKind().getColor() + a.getDisplayName() + ChatColor.WHITE + String attackerString = attackerTeam.getKind().getColor() + a.getDisplayName();
" killed " + defenderTeam.getKind().getColor() + d.getDisplayName(); String defenderString = defenderTeam.getKind().getColor() + d.getDisplayName();
killMessage = attackerString + ChatColor.WHITE + " killed " + defenderString;
for (Team team : defenderWarzone.getTeams()) { for (Team team : defenderWarzone.getTeams()) {
team.teamcast(killMessage); team.teamcast(killMessage);
} }
@ -92,7 +94,7 @@ public class WarEntityListener extends EntityListener {
} else { } else {
War.war.badMsg(a, "Your attack missed!"); War.war.badMsg(a, "Your attack missed!");
if (attackerTeam == null) { 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) { } else if (defenderTeam == null) {
War.war.badMsg(a, "Your target is not in a team."); War.war.badMsg(a, "Your target is not in a team.");
} else if (attacker != null && defender != null && attacker.getEntityId() == defender.getEntityId()) { } 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 event.setCancelled(true); // can't attack someone inside a warzone if you're not in a team
} }
} else if (defender instanceof Player) { } else if (defender instanceof Player) {
// attacked by dispenser arrow most probably // attacked by dispenser arrow most probably
// Detect death, prevent it and respawn the player // Detect death, prevent it and respawn the player
@ -112,12 +113,13 @@ public class WarEntityListener extends EntityListener {
Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName()); Warzone defenderWarzone = Warzone.getZoneByPlayerName(d.getName());
if (d != null && defenderWarzone != null && event.getDamage() >= d.getHealth()) { if (d != null && defenderWarzone != null && event.getDamage() >= d.getHealth()) {
String deathMessage = ""; String deathMessage = "";
String defenderString = Team.getTeamByPlayerName(d.getName()).getKind().getColor() + d.getDisplayName();
if (event instanceof EntityDamageByProjectileEvent) 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) else if (event.getDamager() instanceof CraftTNTPrimed)
deathMessage = Team.getTeamByPlayerName(d.getName()).getKind().getColor() + d.getDisplayName() + ChatColor.WHITE + " exploded"; deathMessage = defenderString + ChatColor.WHITE + " exploded";
else else
deathMessage = Team.getTeamByPlayerName(d.getName()).getKind().getColor() + d.getDisplayName() + ChatColor.WHITE + " died"; deathMessage = defenderString + ChatColor.WHITE + " died";
for (Team team : defenderWarzone.getTeams()) { for (Team team : defenderWarzone.getTeams()) {
team.teamcast(deathMessage); team.teamcast(deathMessage);
} }
@ -163,8 +165,11 @@ public class WarEntityListener extends EntityListener {
public void onEntityDamage(EntityDamageEvent event) { public void onEntityDamage(EntityDamageEvent event) {
if (War.war.isLoaded()) { if (War.war.isLoaded()) {
Entity entity = event.getEntity(); Entity entity = event.getEntity();
if (!(entity instanceof Player)) return;
Player player = (Player) entity;
// prevent godmode // prevent godmode
if (entity instanceof Player && Warzone.getZoneByPlayerName(((Player) entity).getName()) != null) { if (Warzone.getZoneByPlayerName(player.getName()) != null) {
event.setCancelled(false); event.setCancelled(false);
} }
@ -173,8 +178,6 @@ public class WarEntityListener extends EntityListener {
this.handlerAttackDefend((EntityDamageByEntityEvent) event); this.handlerAttackDefend((EntityDamageByEntityEvent) event);
} else { } else {
// Detect death, prevent it and respawn the player // Detect death, prevent it and respawn the player
if (entity instanceof Player) {
Player player = (Player) entity;
Warzone zone = Warzone.getZoneByPlayerName(player.getName()); Warzone zone = Warzone.getZoneByPlayerName(player.getName());
if (zone != null && event.getDamage() >= player.getHealth()) { if (zone != null && event.getDamage() >= player.getHealth()) {
String deathMessage = ""; String deathMessage = "";
@ -188,7 +191,6 @@ public class WarEntityListener extends EntityListener {
} }
} }
} }
}
@Override @Override
public void onEntityCombust(EntityCombustEvent event) { public void onEntityCombust(EntityCombustEvent event) {

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -19,6 +19,7 @@ public class JoinCommand extends AbstractWarCommand {
super(handler, sender, args); super(handler, sender, args);
} }
@Override
public boolean handle() { public boolean handle() {
if (!(this.sender instanceof Player)) return true; if (!(this.sender instanceof Player)) return true;

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -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;
}
}

View File

@ -317,7 +317,6 @@ public class Team {
} }
public void setTeamSpawn(Location teamSpawn) { public void setTeamSpawn(Location teamSpawn) {
this.teamSpawn = teamSpawn; this.teamSpawn = teamSpawn;
// this resets the block to old state // this resets the block to old state
@ -501,7 +500,6 @@ public class Team {
} }
public void setTeamFlag(Location teamFlag) { public void setTeamFlag(Location teamFlag) {
this.teamFlag = teamFlag; this.teamFlag = teamFlag;
// this resets the block to old state // this resets the block to old state
@ -524,7 +522,6 @@ public class Team {
} }
public Location getTeamFlag() { public Location getTeamFlag() {
return this.teamFlag; return this.teamFlag;
} }
} }

View File

@ -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()); File volFile = new File("War/dat/volume-" + volume.getName());
boolean deletedData = volFile.delete(); boolean deletedData = volFile.delete();
if (!deletedData) { if (!deletedData) {
war.log("Failed to delete file " + volFile.getName(), Level.WARNING); War.war.log("Failed to delete file " + volFile.getName(), Level.WARNING);
} }
} }