Closes gh-46. Added long missing /deleteteamflag command. Requested since forever (February 12th, actually).

This commit is contained in:
taoneill 2011-09-19 23:05:29 -04:00
parent 23893c60da
commit f947f204b9
5 changed files with 97 additions and 1 deletions

View File

@ -87,6 +87,8 @@ public class WarCommandHandler {
commandObj = new DeleteTeamCommand(this, sender, arguments);
} else if (command.equals("setteamflag")) {
commandObj = new SetTeamFlagCommand(this, sender, arguments);
} else if (command.equals("deleteteamflag")) {
commandObj = new DeleteTeamFlagCommand(this, sender, arguments);
} else if (command.equals("setmonument")) {
commandObj = new SetMonumentCommand(this, sender, arguments);
} else if (command.equals("deletemonument")) {

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.WarzoneMapper;
import bukkit.tommytony.war.WarCommandHandler;
/**
* Deletes a monument.
*
* @author Tim Düsterhus
*/
public class DeleteTeamFlagCommand extends AbstractZoneMakerCommand {
public DeleteTeamFlagCommand(WarCommandHandler handler, CommandSender sender, String[] args) throws NotZoneMakerException {
super(handler, sender, args);
}
@Override
public boolean handle() {
Warzone zone;
if (this.args.length == 0) {
return false;
} else 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 true;
}
Team teamFlagTeam = null;
for (Team team : zone.getTeams()) {
if (team.getName().startsWith(this.args[0].toLowerCase())) {
teamFlagTeam = team;
}
}
if (teamFlagTeam != null) {
teamFlagTeam.deleteTeamFlag();
WarzoneMapper.save(zone, false);
this.msg(teamFlagTeam.getName() + " flag removed.");
} else {
this.badMsg("No such team flag.");
}
return true;
}
}

View File

@ -1,7 +1,9 @@
package com.tommytony.war;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import java.util.logging.Level;
import org.bukkit.Location;
import org.bukkit.Material;
@ -508,7 +510,7 @@ public class Team {
this.initializeTeamFlag();
}
public boolean isTeamFlagBlock(Block block) {
if (this.teamFlag != null) {
int flagX = this.teamFlag.getBlockX();
@ -524,4 +526,16 @@ public class Team {
public Location getTeamFlag() {
return this.teamFlag;
}
public void deleteTeamFlag() {
this.getFlagVolume().resetBlocks();
this.setFlagVolume(null);
this.teamFlag = null;
// remove volume file
String filePath = War.war.getDataFolder().getPath() + "/dat/warzone-" + this.warzone.getName() + "/volume-" + this.getName() + "flag.dat";
if (!new File(filePath).delete()) {
War.war.log("Failed to delete file " + filePath, Level.WARNING);
}
}
}

View File

@ -139,6 +139,11 @@ commands:
usage: Deletes the team. Team must exist. Provide a zone name if not standing in warzone or lobby.
Ex -
/deleteteam [zone-name] <team-color>
deleteteamflag:
description: War> Deletes the specified team's flag. Team and flag must exist.
usage: Deletes the specified team's flag. Team and flag must exist. Provide a zone name if not standing in warzone or lobby.
Ex -
/deleteteamflag [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.

View File

@ -139,6 +139,11 @@ commands:
usage: Deletes the team. Team must exist. Provide a zone name if not standing in warzone or lobby.
Ex -
/deleteteam [zone-name] <team-color>
deleteteamflag:
description: War> Deletes the specified team's flag. Team and flag must exist.
usage: Deletes the specified team's flag. Team and flag must exist. Provide a zone name if not standing in warzone or lobby.
Ex -
/deleteteamflag [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.