diff --git a/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java b/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java index 9689953..7730890 100644 --- a/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java +++ b/war/src/main/java/bukkit/tommytony/war/WarCommandHandler.java @@ -79,6 +79,8 @@ public class WarCommandHandler { commandObj = new ResetZoneCommand(this, sender, arguments); } else if (command.equals("nextbattle")) { commandObj = new NextBattleCommand(this, sender, arguments); + } else if (command.equals("renamezone")) { + commandObj = new RenameZoneCommand(this, sender, arguments); } else if (command.equals("setteam")) { commandObj = new SetTeamCommand(this, sender, arguments); } else if (command.equals("deleteteam")) { @@ -112,9 +114,9 @@ public class WarCommandHandler { e.printStackTrace(); } - if (commandObj != null) { + if(commandObj != null) { boolean handled = commandObj.handle(); - if (!handled) { + if(!handled) { War.war.badMsg(sender, cmd.getUsage()); } } diff --git a/war/src/main/java/bukkit/tommytony/war/command/RenameZoneCommand.java b/war/src/main/java/bukkit/tommytony/war/command/RenameZoneCommand.java new file mode 100644 index 0000000..6232122 --- /dev/null +++ b/war/src/main/java/bukkit/tommytony/war/command/RenameZoneCommand.java @@ -0,0 +1,98 @@ +package bukkit.tommytony.war.command; + +import java.io.File; +import java.util.logging.Level; + +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; + +import com.tommytony.war.Warzone; +import com.tommytony.war.ZoneLobby; +import com.tommytony.war.mappers.PropertiesFile; +import com.tommytony.war.mappers.WarMapper; +import com.tommytony.war.mappers.WarzoneMapper; + +import bukkit.tommytony.war.War; +import bukkit.tommytony.war.WarCommandHandler; + +public class RenameZoneCommand extends AbstractZoneMakerCommand { + public RenameZoneCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException { + super(handler, sender, args); + } + + @Override + public boolean handle() { + Warzone zone; + + if (this.args.length == 2) { + zone = Warzone.getZoneByName(this.args[0]); + this.args[0] = this.args[1]; + } else if (this.args.length == 1) { + if (!(this.getSender() instanceof Player)) { + return false; + } + zone = Warzone.getZoneByLocation((Player) this.getSender()); + if (zone == null) { + ZoneLobby lobby = ZoneLobby.getLobbyByLocation((Player) this.getSender()); + if (lobby == null) { + return false; + } + zone = lobby.getZone(); + } + } else { + return false; + } + if (zone == null) { + return false; + } + + // kill old reference + zone.unload(); + War.war.getWarzones().remove(zone); + + // rename zone file + (new File(War.war.getDataFolder().getPath() + "/warzone-" + zone.getName() + ".txt")).renameTo(new File(War.war.getDataFolder().getPath() + "/warzone-" + this.args[0] + ".txt")); + // rename zone folder + (new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + zone.getName())).renameTo(new File(War.war.getDataFolder().getPath() + "/dat/warzone-" + this.args[0])); + + // TODO: Move renaming into ZoneVolumeMapper? + // rename volume files + String oldStart = War.war.getDataFolder().getPath() + "/dat/warzone-" + this.args[0] + "/volume-" + zone.getName() + "."; + String newStart = War.war.getDataFolder().getPath() + "/dat/warzone-" + this.args[0] + "/volume-" + this.args[0] + "."; + (new File(oldStart + "corners")).renameTo(new File(newStart + "corners")); + (new File(oldStart + "blocks")).renameTo(new File(newStart + "blocks")); + (new File(oldStart + "signs")).renameTo(new File(newStart + "signs")); + (new File(oldStart + "invs")).renameTo(new File(newStart + "invs")); + + // set new name + PropertiesFile warzoneConfig = new PropertiesFile(War.war.getDataFolder().getPath() + "/warzone-" + this.args[0] + ".txt"); + warzoneConfig.setString("name", this.args[0]); + warzoneConfig.save(); + warzoneConfig.close(); + + War.war.log("Loading zone " + this.args[0] + "...", Level.INFO); + Warzone newZone = WarzoneMapper.load(this.args[0], false); + War.war.getWarzones().add(newZone); + // zone.getVolume().loadCorners(); + newZone.getVolume().loadCorners(); + if (newZone.getLobby() != null) { + newZone.getLobby().getVolume().resetBlocks(); + } + if (newZone.isResetOnLoad()) { + newZone.getVolume().resetBlocks(); + } + newZone.initializeZone(); + + // save war config + WarMapper.save(); + + if (War.war.getWarHub() != null) { // warhub has to change + War.war.getWarHub().getVolume().resetBlocks(); + War.war.getWarHub().initialize(); + } + + this.msg("Warzone " + zone.getName() + " renamed to " + this.args[0] + "."); + + return true; + } +} diff --git a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java index de850f1..e2ed4a9 100644 --- a/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/WarzoneMapper.java @@ -546,5 +546,4 @@ public class WarzoneMapper { War.war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING); } } - } diff --git a/war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java b/war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java index 16e42ad..82dd566 100644 --- a/war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java +++ b/war/src/main/java/com/tommytony/war/mappers/ZoneVolumeMapper.java @@ -501,11 +501,11 @@ public class ZoneVolumeMapper { * war Instance of war */ public static void delete(Volume volume) { - ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".dat"); - ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".corners"); - ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".blocks"); - ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".signs"); - ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".invs"); + ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat"); + ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".corners"); + ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".blocks"); + ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".signs"); + ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".invs"); } /** diff --git a/war/src/main/java/plugin.yml b/war/src/main/java/plugin.yml index a52058c..8f0054c 100644 --- a/war/src/main/java/plugin.yml +++ b/war/src/main/java/plugin.yml @@ -34,65 +34,65 @@ commands: # Player commands warzones: description: War> Lists the warzones on the server. Each warzone is an independent arena. - usage: Lists the warzones on the server. Each warzone is an independent arena. + usage: Lists the warzones on the server. Each warzone is an independent arena. Ex - /warzones zones: description: War> Shortcut for /warzones. - usage: Lists the warzones on the server. Each warzone is an independent arena. + usage: Lists the warzones on the server. Each warzone is an independent arena. Ex - /zones warzone: description: War> Teleports you to the specified warzone's lobby. - usage: Teleports you to the specified warzone's lobby. + usage: Teleports you to the specified warzone's lobby. Ex - /warzone zone: description: War> Shortcut for /warzone. - usage: Teleports you to the specified warzone's lobby. + usage: Teleports you to the specified warzone's lobby. Ex - /zone warhub: description: War> Teleports you to the warhub, if it exists. The warhub offers portals to reach each warzone on the server. - usage: Teleports you to the warhub, if it exists. + usage: Teleports you to the warhub, if it exists. Ex - /warhub teams: description: War> Lists the teams in the warzone. - usage: Lists the teams in the warzone. Use zone name when outside warzone. + usage: Lists the teams in the warzone. Use zone name when outside warzone. Ex - /teams [zone-name] join: description: War> Use to change teams. Also used instead of walking in the team gate in the lobby. - usage: Use to change teams. Also used instead of walking in the team gate in the lobby. Must be standing in warzone or lobby. + usage: Use to change teams. Also used instead of walking in the team gate in the lobby. Must be standing in warzone or lobby. Ex - /join leave: description: War> Use to leave a warzone. Teleports you back to the lobby. - usage: Use to leave a warzone. Teleports you back to the lobby. Must be in team already. + usage: Use to leave a warzone. Teleports you back to the lobby. Must be in team already. Ex - /leave team: description: War> Team chat. - usage: Team chat. + usage: Team chat. Ex - /team # Warzone maker commands (must have the 'war.*' permission or be added as a zone-maker in /plugins/War/war.txt # 1- Battle-related commands nextbattle: description: War> Warzone blocks are restored, teams are respawned but score remains unaffected. - usage: Warzone blocks are restored, teams are respawned but score remains unaffected. Provide a zone name if not standing in warzone or lobby. + usage: Warzone blocks are restored, teams are respawned but score remains unaffected. Provide a zone name if not standing in warzone or lobby. Ex - /nextbattle [zone-name] # 2- Warzone creation commands setzone: description: War> Use to create a warzone. Lobby is created and blocks are saved when the second corner is set. usage: Use to create a warzone. Lobby is created and blocks are saved when the second corner is set. Warzones must be at least 10 blocks wide in all directions. - Ex - + Ex - ==Wand Cuboid mode==> - 1) /setzone to get wooden sword, - 2) Left-click to select or move corner1, - 3) Right-click to select or move corner2. + 1) /setzone to get wooden sword, + 2) Left-click to select or move corner1, + 3) Right-click to select or move corner2. Turn off wand by dropping the wooden sword. - ==Wandless Cuboid mode==> - /setzone + ==Wandless Cuboid mode==> + /setzone savezone: description: War> Persists changes made to the warzone since the last save. Config can be set with named parameters. usage: Persists changes made to the warzone since the last save. Config can be set with named parameters. Provide a zone name if not standing in warzone or lobby. - Ex - - /savezone [zone-name] => Basic save - name optional if standing inside, - /savezone [zone-name] lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle: unbreakable:on nocreatures:on disabled:on, - /savezone [zone-name] loadout:default => sets the respawn inventory to your current items, + Ex - + /savezone [zone-name] => Basic save - name optional if standing inside, + /savezone [zone-name] lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle: unbreakable:on nocreatures:on disabled:on, + /savezone [zone-name] loadout:default => sets the respawn inventory to your current items, /savezone [zone-name] reward:default => sets the winner's reward to your current items. setzonelobby: description: War> Creates or changes the position of the warzone lobby. @@ -111,8 +111,8 @@ commands: /setteam setmonument: description: War> Creates or moves a monument. - usage: Creates or moves a monument. Must be standing in warzone. - Ex - + usage: Creates or moves a monument. Must be standing in warzone. + Ex - /setmonument setteamflag: description: War> Creates/moves a team flag post for CTF. @@ -122,13 +122,18 @@ commands: resetzone: description: War> Reloads zone blocks from disk. Everyone is teleported back to the lobby. usage: Reloads zone blocks from disk. Everyone is teleported back to the lobby. Provide a zone name if not standing in warzone or lobby. - Ex - + Ex - /resetzone [zone-name] deletezone: description: War> Deletes the zone, resets all blocks. usage: Deletes the zone after resetting all blocks. Provide a zone name if not standing in warzone or lobby. Ex - /deletezone [zone-name] + renamezone: + description: War> Renames the zone + usage: Renames the zone. Provide a zone name if not standing in warzone or lobby. + Ex - + /renamezone [zone-name] deleteteam: description: War> Deletes the team. Team must exist. usage: Deletes the team. Team must exist. Provide a zone name if not standing in warzone or lobby. @@ -169,7 +174,7 @@ commands: setwarhub: description: War> Create or moves a wall of portals. One portal per warzone. Warzones get a portal back to the warhub. usage: Create or moves a wall of portals. One portal per warzone. Warzones get a portal back to the warhub. - Ex - + Ex - /setwarhub deletewarhub: description: War> Deletes the warhub if it exists. Resets all warzone lobbies. @@ -180,7 +185,7 @@ commands: unloadwar: description: War> Disables the War plugin. usage: Disables the War plugin. - Ex - + Ex - /unloadwar loadwar: description: War> Enables the War plugin. @@ -205,12 +210,12 @@ commands: /setwarconfig loadout:default => sets the respawn inventory to your current items, /setwarconfig reward:default => sets the winner's reward to your current items, /setwarconfig rallypoint: => changes when players get teleported at the end of a match for that zone, useful for chaining warzones together in a sequence, or preventing players from rejoining immediately - + # Fallback war: description: War> Short War help. Can also be used as a prefix for all War commands as a fallback if they conflict with other plugins. - usage: War is on. Please pick your battle. Try /warhub, /zones and /zone. Further instructions at war.tommytony.com/instructions. - The /war command can be used as a prefix to all other command as a fallback if they conflict with other plugins. Ex - + usage: War is on. Please pick your battle. Try /warhub, /zones and /zone. Further instructions at war.tommytony.com/instructions. + The /war command can be used as a prefix to all other command as a fallback if they conflict with other plugins. Ex - /war, /war setzone , /war warhub, diff --git a/war/target/classes/plugin.yml b/war/target/classes/plugin.yml index a52058c..8f0054c 100644 --- a/war/target/classes/plugin.yml +++ b/war/target/classes/plugin.yml @@ -34,65 +34,65 @@ commands: # Player commands warzones: description: War> Lists the warzones on the server. Each warzone is an independent arena. - usage: Lists the warzones on the server. Each warzone is an independent arena. + usage: Lists the warzones on the server. Each warzone is an independent arena. Ex - /warzones zones: description: War> Shortcut for /warzones. - usage: Lists the warzones on the server. Each warzone is an independent arena. + usage: Lists the warzones on the server. Each warzone is an independent arena. Ex - /zones warzone: description: War> Teleports you to the specified warzone's lobby. - usage: Teleports you to the specified warzone's lobby. + usage: Teleports you to the specified warzone's lobby. Ex - /warzone zone: description: War> Shortcut for /warzone. - usage: Teleports you to the specified warzone's lobby. + usage: Teleports you to the specified warzone's lobby. Ex - /zone warhub: description: War> Teleports you to the warhub, if it exists. The warhub offers portals to reach each warzone on the server. - usage: Teleports you to the warhub, if it exists. + usage: Teleports you to the warhub, if it exists. Ex - /warhub teams: description: War> Lists the teams in the warzone. - usage: Lists the teams in the warzone. Use zone name when outside warzone. + usage: Lists the teams in the warzone. Use zone name when outside warzone. Ex - /teams [zone-name] join: description: War> Use to change teams. Also used instead of walking in the team gate in the lobby. - usage: Use to change teams. Also used instead of walking in the team gate in the lobby. Must be standing in warzone or lobby. + usage: Use to change teams. Also used instead of walking in the team gate in the lobby. Must be standing in warzone or lobby. Ex - /join leave: description: War> Use to leave a warzone. Teleports you back to the lobby. - usage: Use to leave a warzone. Teleports you back to the lobby. Must be in team already. + usage: Use to leave a warzone. Teleports you back to the lobby. Must be in team already. Ex - /leave team: description: War> Team chat. - usage: Team chat. + usage: Team chat. Ex - /team # Warzone maker commands (must have the 'war.*' permission or be added as a zone-maker in /plugins/War/war.txt # 1- Battle-related commands nextbattle: description: War> Warzone blocks are restored, teams are respawned but score remains unaffected. - usage: Warzone blocks are restored, teams are respawned but score remains unaffected. Provide a zone name if not standing in warzone or lobby. + usage: Warzone blocks are restored, teams are respawned but score remains unaffected. Provide a zone name if not standing in warzone or lobby. Ex - /nextbattle [zone-name] # 2- Warzone creation commands setzone: description: War> Use to create a warzone. Lobby is created and blocks are saved when the second corner is set. usage: Use to create a warzone. Lobby is created and blocks are saved when the second corner is set. Warzones must be at least 10 blocks wide in all directions. - Ex - + Ex - ==Wand Cuboid mode==> - 1) /setzone to get wooden sword, - 2) Left-click to select or move corner1, - 3) Right-click to select or move corner2. + 1) /setzone to get wooden sword, + 2) Left-click to select or move corner1, + 3) Right-click to select or move corner2. Turn off wand by dropping the wooden sword. - ==Wandless Cuboid mode==> - /setzone + ==Wandless Cuboid mode==> + /setzone savezone: description: War> Persists changes made to the warzone since the last save. Config can be set with named parameters. usage: Persists changes made to the warzone since the last save. Config can be set with named parameters. Provide a zone name if not standing in warzone or lobby. - Ex - - /savezone [zone-name] => Basic save - name optional if standing inside, - /savezone [zone-name] lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle: unbreakable:on nocreatures:on disabled:on, - /savezone [zone-name] loadout:default => sets the respawn inventory to your current items, + Ex - + /savezone [zone-name] => Basic save - name optional if standing inside, + /savezone [zone-name] lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle: unbreakable:on nocreatures:on disabled:on, + /savezone [zone-name] loadout:default => sets the respawn inventory to your current items, /savezone [zone-name] reward:default => sets the winner's reward to your current items. setzonelobby: description: War> Creates or changes the position of the warzone lobby. @@ -111,8 +111,8 @@ commands: /setteam setmonument: description: War> Creates or moves a monument. - usage: Creates or moves a monument. Must be standing in warzone. - Ex - + usage: Creates or moves a monument. Must be standing in warzone. + Ex - /setmonument setteamflag: description: War> Creates/moves a team flag post for CTF. @@ -122,13 +122,18 @@ commands: resetzone: description: War> Reloads zone blocks from disk. Everyone is teleported back to the lobby. usage: Reloads zone blocks from disk. Everyone is teleported back to the lobby. Provide a zone name if not standing in warzone or lobby. - Ex - + Ex - /resetzone [zone-name] deletezone: description: War> Deletes the zone, resets all blocks. usage: Deletes the zone after resetting all blocks. Provide a zone name if not standing in warzone or lobby. Ex - /deletezone [zone-name] + renamezone: + description: War> Renames the zone + usage: Renames the zone. Provide a zone name if not standing in warzone or lobby. + Ex - + /renamezone [zone-name] deleteteam: description: War> Deletes the team. Team must exist. usage: Deletes the team. Team must exist. Provide a zone name if not standing in warzone or lobby. @@ -169,7 +174,7 @@ commands: setwarhub: description: War> Create or moves a wall of portals. One portal per warzone. Warzones get a portal back to the warhub. usage: Create or moves a wall of portals. One portal per warzone. Warzones get a portal back to the warhub. - Ex - + Ex - /setwarhub deletewarhub: description: War> Deletes the warhub if it exists. Resets all warzone lobbies. @@ -180,7 +185,7 @@ commands: unloadwar: description: War> Disables the War plugin. usage: Disables the War plugin. - Ex - + Ex - /unloadwar loadwar: description: War> Enables the War plugin. @@ -205,12 +210,12 @@ commands: /setwarconfig loadout:default => sets the respawn inventory to your current items, /setwarconfig reward:default => sets the winner's reward to your current items, /setwarconfig rallypoint: => changes when players get teleported at the end of a match for that zone, useful for chaining warzones together in a sequence, or preventing players from rejoining immediately - + # Fallback war: description: War> Short War help. Can also be used as a prefix for all War commands as a fallback if they conflict with other plugins. - usage: War is on. Please pick your battle. Try /warhub, /zones and /zone. Further instructions at war.tommytony.com/instructions. - The /war command can be used as a prefix to all other command as a fallback if they conflict with other plugins. Ex - + usage: War is on. Please pick your battle. Try /warhub, /zones and /zone. Further instructions at war.tommytony.com/instructions. + The /war command can be used as a prefix to all other command as a fallback if they conflict with other plugins. Ex - /war, /war setzone , /war warhub,