Saber-Factions/src/main/java/com/massivecraft/factions/cmd/CmdTag.java

80 lines
2.6 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
2014-11-06 01:36:47 +01:00
import com.massivecraft.factions.*;
import com.massivecraft.factions.event.FactionRenameEvent;
import com.massivecraft.factions.scoreboards.FTeamWrapper;
2011-10-09 18:35:39 +02:00
import com.massivecraft.factions.struct.Permission;
import com.massivecraft.factions.util.MiscUtil;
import com.massivecraft.factions.zcore.util.TL;
2014-04-04 20:55:21 +02:00
import org.bukkit.Bukkit;
import java.util.ArrayList;
public class CmdTag extends FCommand {
public CmdTag() {
this.aliases.add("tag");
this.requiredArgs.add("faction tag");
//this.optionalArgs.put("", "");
2014-07-01 22:10:18 +02:00
this.permission = Permission.TAG.node;
this.disableOnLock = true;
2014-04-04 20:55:21 +02:00
2014-07-01 22:10:18 +02:00
senderMustBePlayer = true;
senderMustBeMember = false;
senderMustBeModerator = true;
senderMustBeAdmin = false;
2014-04-04 20:55:21 +02:00
}
@Override
public void perform() {
String tag = this.argAsString(0);
// TODO does not first test cover selfcase?
if (Factions.getInstance().isTagTaken(tag) && !MiscUtil.getComparisonString(tag).equals(myFaction.getComparisonTag())) {
msg(TL.COMMAND_TAG_TAKEN);
2014-07-01 22:10:18 +02:00
return;
2014-04-04 20:55:21 +02:00
}
ArrayList<String> errors = MiscUtil.validateTag(tag);
2014-04-04 20:55:21 +02:00
if (errors.size() > 0) {
2014-07-01 22:10:18 +02:00
sendMessage(errors);
return;
2014-04-04 20:55:21 +02:00
}
// if economy is enabled, they're not on the bypass list, and this command has a cost set, make sure they can pay
if (!canAffordCommand(Conf.econCostTag, TL.COMMAND_TAG_TOCHANGE.toString())) {
2014-07-01 22:10:18 +02:00
return;
}
2014-04-04 20:55:21 +02:00
// trigger the faction rename event (cancellable)
FactionRenameEvent renameEvent = new FactionRenameEvent(fme, tag);
2014-07-01 22:10:18 +02:00
Bukkit.getServer().getPluginManager().callEvent(renameEvent);
if (renameEvent.isCancelled()) {
return;
}
2014-04-04 20:55:21 +02:00
// then make 'em pay (if applicable)
2014-12-11 17:05:04 +01:00
if (!payForCommand(Conf.econCostTag, TL.COMMAND_TAG_TOCHANGE, TL.COMMAND_TAG_FORCHANGE)) {
2014-07-01 22:10:18 +02:00
return;
}
2014-04-04 20:55:21 +02:00
2014-07-01 22:10:18 +02:00
String oldtag = myFaction.getTag();
myFaction.setTag(tag);
2014-04-04 20:55:21 +02:00
// Inform
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
if (fplayer.getFactionId().equals(myFaction.getId())) {
fplayer.msg(TL.COMMAND_TAG_FACTION, fme.describeTo(myFaction, true), myFaction.getTag(myFaction));
2014-04-04 20:55:21 +02:00
continue;
}
Faction faction = fplayer.getFaction();
fplayer.msg(TL.COMMAND_TAG_CHANGED, fme.getColorTo(faction) + oldtag, myFaction.getTag(faction));
2014-04-04 20:55:21 +02:00
}
FTeamWrapper.updatePrefixes(myFaction);
2014-04-04 20:55:21 +02:00
}
2011-04-08 15:51:07 +02:00
}