2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2014-11-06 01:36:47 +01:00
|
|
|
import com.massivecraft.factions.*;
|
2012-03-13 13:58:51 +01:00
|
|
|
import com.massivecraft.factions.event.FactionRenameEvent;
|
2014-10-22 18:54:00 +02:00
|
|
|
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;
|
2014-12-08 00:12:52 +01:00
|
|
|
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?
|
2014-10-19 07:37:25 +02:00
|
|
|
if (Factions.getInstance().isTagTaken(tag) && !MiscUtil.getComparisonString(tag).equals(myFaction.getComparisonTag())) {
|
2014-12-08 00:12:52 +01:00
|
|
|
msg(TL.COMMAND_TAG_TAKEN);
|
2014-07-01 22:10:18 +02:00
|
|
|
return;
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
2014-10-19 07:37:25 +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
|
2014-12-08 00:12:52 +01:00
|
|
|
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
|
2014-10-19 07:37:25 +02:00
|
|
|
for (FPlayer fplayer : FPlayers.getInstance().getOnlinePlayers()) {
|
|
|
|
if (fplayer.getFactionId() == myFaction.getId()) {
|
2014-12-08 00:12:52 +01:00
|
|
|
fplayer.msg(TL.COMMAND_TAG_FACTION, fme.describeTo(myFaction, true), myFaction.getTag(myFaction));
|
2014-04-04 20:55:21 +02:00
|
|
|
continue;
|
|
|
|
}
|
2014-10-19 07:37:25 +02:00
|
|
|
Faction faction = fplayer.getFaction();
|
2014-12-08 00:12:52 +01:00
|
|
|
fplayer.msg(TL.COMMAND_TAG_CHANGED, fme.getColorTo(faction) + oldtag, myFaction.getTag(faction));
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
|
|
|
|
2014-10-22 18:54:00 +02:00
|
|
|
FTeamWrapper.updatePrefixes(myFaction);
|
2014-04-04 20:55:21 +02:00
|
|
|
}
|
2011-04-08 15:51:07 +02:00
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|