2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2011-07-18 22:06:02 +02:00
|
|
|
import com.massivecraft.factions.Conf;
|
|
|
|
import com.massivecraft.factions.Faction;
|
2011-10-09 18:35:39 +02:00
|
|
|
import com.massivecraft.factions.Factions;
|
2012-03-13 13:58:51 +01:00
|
|
|
import com.massivecraft.factions.event.FactionRenameEvent;
|
2011-10-09 18:35:39 +02:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
|
|
|
import com.massivecraft.factions.util.MiscUtil;
|
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 21:52:40 +02:00
|
|
|
this.permission = Permission.TAG.node; this.disableOnLock = true;
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2014-07-01 21:52:40 +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.i.isTagTaken(tag) && !MiscUtil.getComparisonString(tag).equals(myFaction.getComparisonTag())) {
|
2014-07-01 21:52:40 +02:00
|
|
|
msg("<b>That tag is already taken"); return;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
2014-07-01 21:52:40 +02:00
|
|
|
ArrayList<String> errors = new ArrayList<String>(); errors.addAll(Factions.validateTag(tag));
|
2014-04-04 20:55:21 +02:00
|
|
|
if (errors.size() > 0) {
|
2014-07-01 21:52:40 +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
|
2014-07-01 21:49:42 +02:00
|
|
|
if (!canAffordCommand(Conf.econCostTag, "to change the faction tag")) { return; }
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
// trigger the faction rename event (cancellable)
|
|
|
|
FactionRenameEvent renameEvent = new FactionRenameEvent(fme, tag);
|
2014-07-01 21:52:40 +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-07-01 21:49:42 +02:00
|
|
|
if (!payForCommand(Conf.econCostTag, "to change the faction tag", "for changing the faction tag")) { return; }
|
2014-04-04 20:55:21 +02:00
|
|
|
|
2014-07-01 21:52:40 +02:00
|
|
|
String oldtag = myFaction.getTag(); myFaction.setTag(tag);
|
2014-04-04 20:55:21 +02:00
|
|
|
|
|
|
|
// Inform
|
|
|
|
myFaction.msg("%s<i> changed your faction tag to %s", fme.describeTo(myFaction, true), myFaction.getTag(myFaction));
|
|
|
|
for (Faction faction : Factions.i.get()) {
|
|
|
|
if (faction == myFaction) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
faction.msg("<i>The faction %s<i> changed their name to %s.", fme.getColorTo(faction) + oldtag, myFaction.getTag(faction));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2011-04-08 15:51:07 +02:00
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|