mirror of
https://github.com/taoneill/war.git
synced 2024-11-24 03:05:54 +01:00
Merging /renameZone. Maybe I would've liked this better under /zonecfg to keep the command count as low as possible, but this will do. There's too many settings already anyway. I'm keeping plugin.yml in classes because it lets me build in a snap in eclipse instead of through mvn. I know: it's lame.
This commit is contained in:
commit
23893c60da
@ -79,6 +79,8 @@ public class WarCommandHandler {
|
|||||||
commandObj = new ResetZoneCommand(this, sender, arguments);
|
commandObj = new ResetZoneCommand(this, sender, arguments);
|
||||||
} else if (command.equals("nextbattle")) {
|
} else if (command.equals("nextbattle")) {
|
||||||
commandObj = new NextBattleCommand(this, sender, arguments);
|
commandObj = new NextBattleCommand(this, sender, arguments);
|
||||||
|
} else if (command.equals("renamezone")) {
|
||||||
|
commandObj = new RenameZoneCommand(this, sender, arguments);
|
||||||
} else if (command.equals("setteam")) {
|
} else if (command.equals("setteam")) {
|
||||||
commandObj = new SetTeamCommand(this, sender, arguments);
|
commandObj = new SetTeamCommand(this, sender, arguments);
|
||||||
} else if (command.equals("deleteteam")) {
|
} else if (command.equals("deleteteam")) {
|
||||||
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
@ -546,5 +546,4 @@ public class WarzoneMapper {
|
|||||||
War.war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING);
|
War.war.log("Failed to delete file " + zoneFile.getName(), Level.WARNING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -501,11 +501,11 @@ public class ZoneVolumeMapper {
|
|||||||
* war Instance of war
|
* war Instance of war
|
||||||
*/
|
*/
|
||||||
public static void delete(Volume volume) {
|
public static void delete(Volume volume) {
|
||||||
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".dat");
|
ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".dat");
|
||||||
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".corners");
|
ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".corners");
|
||||||
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".blocks");
|
ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".blocks");
|
||||||
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".signs");
|
ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".signs");
|
||||||
ZoneVolumeMapper.deleteFile("War/dat/volume-" + volume.getName() + ".invs");
|
ZoneVolumeMapper.deleteFile(War.war.getDataFolder().getPath() + "/dat/volume-" + volume.getName() + ".invs");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -129,6 +129,11 @@ commands:
|
|||||||
usage: Deletes the zone after resetting all blocks. Provide a zone name if not standing in warzone or lobby.
|
usage: Deletes the zone after resetting all blocks. Provide a zone name if not standing in warzone or lobby.
|
||||||
Ex -
|
Ex -
|
||||||
/deletezone [zone-name]
|
/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:
|
deleteteam:
|
||||||
description: War> Deletes the team. Team must exist.
|
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.
|
usage: Deletes the team. Team must exist. Provide a zone name if not standing in warzone or lobby.
|
||||||
|
@ -129,6 +129,11 @@ commands:
|
|||||||
usage: Deletes the zone after resetting all blocks. Provide a zone name if not standing in warzone or lobby.
|
usage: Deletes the zone after resetting all blocks. Provide a zone name if not standing in warzone or lobby.
|
||||||
Ex -
|
Ex -
|
||||||
/deletezone [zone-name]
|
/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:
|
deleteteam:
|
||||||
description: War> Deletes the team. Team must exist.
|
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.
|
usage: Deletes the team. Team must exist. Provide a zone name if not standing in warzone or lobby.
|
||||||
|
Loading…
Reference in New Issue
Block a user