Adding Renamezone command

Closes gh-43
This commit is contained in:
Tim Düsterhus 2011-08-13 18:55:28 +02:00
parent 7fef7c9649
commit 44df6a3f62
6 changed files with 144 additions and 234 deletions

View File

@ -35,12 +35,12 @@ public class WarCommandHandler {
}
if (arguments.length == 1 && (arguments[0].equals("help") || arguments[0].equals("h"))) {
// show /war help
War.war.badMsg(sender, cmd.getUsage());
War.war.badMsg(sender, cmd.getUsage());
return true;
}
} else if (command.equals("war") || command.equals("War")) {
// show /war help
War.war.msg(sender, cmd.getUsage());
War.war.msg(sender, cmd.getUsage());
return true;
} else {
arguments = args;
@ -74,6 +74,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")) {
@ -98,7 +100,7 @@ public class WarCommandHandler {
commandObj = new SetWarConfigCommand(this, sender, arguments);
} else if (command.equals("zonemaker") || command.equals("zm")) {
commandObj = new ZoneMakerCommand(this, sender, arguments);
}
}
// we are not responsible for any other command
}
catch (NotZoneMakerException e) {
@ -108,14 +110,14 @@ public class WarCommandHandler {
War.war.log("An error occured while handling command " + cmd.getName() + ". Exception:" + e.getClass().toString() + " " + e.getMessage(), Level.WARNING);
e.printStackTrace();
}
if(commandObj != null) {
boolean handled = commandObj.handle();
if(!handled) {
War.war.badMsg(sender, cmd.getUsage());
War.war.badMsg(sender, cmd.getUsage());
}
}
return true;
}
}

View File

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

View File

@ -487,5 +487,4 @@ public class WarzoneMapper {
War.war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING);
}
}
}

View File

@ -490,11 +490,11 @@ public class ZoneVolumeMapper {
* @param War 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");
}
/**

View File

@ -8,65 +8,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-name>
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 <zone-name>
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 <team-color>
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 <message>
# 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 <zone-name> to get wooden sword,
2) Left-click to select or move corner1,
3) Right-click to select or move corner2.
1) /setzone <zone-name> 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 <zone-name> <corner1/corner2/c1/c2/pos1/pos2>
==Wandless Cuboid mode==>
/setzone <zone-name> <corner1/corner2/c1/c2/pos1/pos2>
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:<big/flat/small> 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:<big/flat/small> 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.
@ -85,8 +85,8 @@ commands:
/setteam <diamond/iron/gold/white/orange/magenta/blue/green/pink/gray/purple/navy/brown/darkgreen/red/black>
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 <monument-name>
setteamflag:
description: War> Creates/moves a team flag post for CTF.
@ -96,13 +96,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] <new-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.
@ -143,7 +148,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.
@ -154,7 +159,7 @@ commands:
unloadwar:
description: War> Disables the War plugin.
usage: Disables the War plugin.
Ex -
Ex -
/unloadwar
loadwar:
description: War> Enables the War plugin.
@ -179,12 +184,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:<warzone-name> => 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 <zone-name>,
/war warhub,

View File

@ -1,194 +0,0 @@
name: War
version: 1.6 (de Gaulle) PREVIEW 5
description: Lets you create TDM and CTF (warzones) for a more structured PVP experience.
author: tommytony
website: war.tommytony.com
main: bukkit.tommytony.war.War
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.
Ex - /warzones
zones:
description: War> Shortcut for /warzones.
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.
Ex - /warzone <zone-name>
zone:
description: War> Shortcut for /warzone.
usage: Teleports you to the specified warzone's lobby.
Ex - /zone <zone-name>
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.
Ex - /warhub
teams:
description: War> Lists the teams in the 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.
Ex - /join <team-color>
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.
Ex - /leave
team:
description: War> Team chat.
usage: Team chat.
Ex - /team <message>
# 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.
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 -
==Wand Cuboid mode==>
1) /setzone <zone-name> 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 <zone-name> <corner1/corner2/c1/c2/pos1/pos2>
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:<big/flat/small> 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.
usage: Creates or changes the position of the warzone lobby.
Ex -
==Attached lobby==>
Must be standing in warzone or lobby.
/setzonelobby <north/east/south/west/n/e/s/w>
==Detached lobby==>
Must be standing outside warzone or lobby.
/setzonelobby <zone-name>
setteam:
description: War> Creates or moves a team spawn. The lobby is updated.
usage: Creates or moves a team spawn. The lobby is updated. Must be standing in warzone.
Ex -
/setteam <diamond/iron/gold/white/orange/magenta/blue/green/pink/gray/purple/navy/brown/darkgreen/red/black>
setmonument:
description: War> Creates or moves a monument.
usage: Creates or moves a monument. Must be standing in warzone.
Ex -
/setmonument <monument-name>
setteamflag:
description: War> Creates/moves a team flag post for CTF.
usage: Creates/moves a team flag post for CTF. Must be standing in warzone.
Ex -
/setteamflag <team-color>
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 -
/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]
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.
Ex -
/deleteteam [zone-name] <team-color>
deletemonument:
description: War> Deletes the monument.
usage: Deletes the monument. Provide a zone name if not standing in warzone or lobby.
Ex -
/deletemonument [zone-name] <monument-name>
setzoneconfig:
description: War> Use named parameters to change the configuration of the warzone. Resets blocks like /nextbattle. Does not save zone blocks like /savezone.
usage: Use named parameters to change the configuration of the warzone. Resets blocks like /nextbattle. Does not save zone blocks like /savezone. Provide a zone name if not standing in warzone or lobby.
Ex -
/setzoneconfig [zone-name] lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle:<big/flat/small/invisible> unbreakable:on nocreatures:on disabled:on,
/setzoneconfig [zone-name] loadout:default => sets the respawn inventory to your current items,
/setzoneconfig [zone-name] reward:default => sets the winner's reward to your current items
zonecfg:
description: War> Alias for /setzoneconfig
usage: Use named parameters to change the configuration of the warzone. Resets blocks like /nextbattle. Does not save zone blocks like /savezone. Provide a zone name if not standing in warzone or lobby.
Ex -
/setzoneconfig [zone-name] lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle:<big/flat/small/invisible> unbreakable:on nocreatures:on disabled:on,
/setzoneconfig [zone-name] loadout:default => sets the respawn inventory to your current items,
/setzoneconfig [zone-name] reward:default => sets the winner's reward to your current items
zonemaker:
description: War> Toggles between player mode and zone maker mode. Or gives/removes access to zonemaker commands for another player.
usage: Toggles between player mode and zone maker mode. Or gives/removes access to zonemaker commands for another player.
Ex -
/zonemaker
/zonemaker <new-or-kicked-zone-maker-name>
zm:
description: War> Alias for /zonemaker
usage: Toggles between player mode and zone maker mode. Or gives/removes access to zonemaker commands for another player.
Ex -
/zonemaker
/zonemaker <new-or-kicked-zone-maker-name>
# 3- War hub
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 -
/setwarhub
deletewarhub:
description: War> Deletes the warhub if it exists. Resets all warzone lobbies.
usage: Deletes the warhub if it exists. Resets all warzone lobbies.
Ex -
/deletewarhub
# 4- Defaults and server configuration
unloadwar:
description: War> Disables the War plugin.
usage: Disables the War plugin.
Ex -
/unloadwar
loadwar:
description: War> Enables the War plugin.
usage: Enables the War plugin.
Ex -
/loadwar
setwarconfig:
description: War> Change gobal settings and the default warzone configuration values.
usage: Change gobal settings and the default warzone configuration values.
Ex -
/setwarconfig pvpinzonesonly:on buildinzonesonly:on => Global settings,
/setwarconfig lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle:<big/flat/small/invisible> unbreakable:on nocreatures:on => Warzone defaults,
/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:<warzone-name> => 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
warcfg:
description: War> Alias for /setwarconfig
usage: Change gobal settings and the default warzone configuration values.
Ex -
/setwarconfig pvpinzonesonly:on buildinzonesonly:on => Global settings,
/setwarconfig lifepool:8 teamsize:5 maxscore:7 autoassign:on outline:off ff:on blockheads:off spawnstyle:<big/flat/small/invisible> unbreakable:on nocreatures:on => Warzone defaults,
/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:<warzone-name> => 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 -
/war,
/war setzone <zone-name>,
/war warhub,
/war zone <zone-name>
War:
description: War> Same as /war. Used as fallback.
usage: See /war.