2011-10-09 21:57:43 +02:00
|
|
|
package com.massivecraft.factions.cmd;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
2012-03-13 13:58:51 +01:00
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
|
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-05 12:13:54 +02:00
|
|
|
import com.massivecraft.factions.integration.SpoutFeatures;
|
2011-10-09 18:35:39 +02:00
|
|
|
import com.massivecraft.factions.struct.Permission;
|
|
|
|
import com.massivecraft.factions.util.MiscUtil;
|
2011-04-08 15:51:07 +02:00
|
|
|
|
2011-10-09 20:10:19 +02:00
|
|
|
public class CmdTag extends FCommand
|
2011-10-09 18:35:39 +02:00
|
|
|
{
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2011-10-09 20:10:19 +02:00
|
|
|
public CmdTag()
|
2011-10-09 18:35:39 +02:00
|
|
|
{
|
|
|
|
this.aliases.add("tag");
|
|
|
|
|
|
|
|
this.requiredArgs.add("faction tag");
|
|
|
|
//this.optionalArgs.put("", "");
|
2011-03-22 18:48:09 +01:00
|
|
|
|
2011-10-09 21:57:43 +02:00
|
|
|
this.permission = Permission.TAG.node;
|
|
|
|
this.disableOnLock = true;
|
2011-03-22 15:45:41 +01:00
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
senderMustBePlayer = true;
|
|
|
|
senderMustBeMember = false;
|
|
|
|
senderMustBeModerator = true;
|
|
|
|
senderMustBeAdmin = false;
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|
|
|
|
|
2011-06-21 07:38:31 +02:00
|
|
|
@Override
|
2011-10-09 18:35:39 +02:00
|
|
|
public void perform()
|
|
|
|
{
|
|
|
|
String tag = this.argAsString(0);
|
2011-03-22 15:45:41 +01:00
|
|
|
|
|
|
|
// TODO does not first test cover selfcase?
|
2011-10-09 18:35:39 +02:00
|
|
|
if (Factions.i.isTagTaken(tag) && ! MiscUtil.getComparisonString(tag).equals(myFaction.getComparisonTag()))
|
|
|
|
{
|
2011-10-10 13:40:24 +02:00
|
|
|
msg("<b>That tag is already taken");
|
2011-03-22 15:45:41 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
ArrayList<String> errors = new ArrayList<String>();
|
2011-10-09 18:35:39 +02:00
|
|
|
errors.addAll(Factions.validateTag(tag));
|
|
|
|
if (errors.size() > 0)
|
|
|
|
{
|
2011-03-22 15:45:41 +01:00
|
|
|
sendMessage(errors);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-03-13 15:48:31 +01: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, "to change the faction tag")) return;
|
2012-03-13 13:58:51 +01:00
|
|
|
|
|
|
|
// trigger the faction rename event (cancellable)
|
|
|
|
FactionRenameEvent renameEvent = new FactionRenameEvent(fme, tag);
|
|
|
|
Bukkit.getServer().getPluginManager().callEvent(renameEvent);
|
|
|
|
if(renameEvent.isCancelled()) return;
|
|
|
|
|
2012-03-13 15:48:31 +01:00
|
|
|
// then make 'em pay (if applicable)
|
|
|
|
if ( ! payForCommand(Conf.econCostTag, "to change the faction tag", "for changing the faction tag")) return;
|
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
String oldtag = myFaction.getTag();
|
|
|
|
myFaction.setTag(tag);
|
|
|
|
|
|
|
|
// Inform
|
2011-10-21 19:20:33 +02:00
|
|
|
myFaction.msg("%s<i> changed your faction tag to %s", fme.describeTo(myFaction, true), myFaction.getTag(myFaction));
|
2011-10-09 18:35:39 +02:00
|
|
|
for (Faction faction : Factions.i.get())
|
|
|
|
{
|
|
|
|
if (faction == myFaction)
|
|
|
|
{
|
2011-03-22 15:45:41 +01:00
|
|
|
continue;
|
|
|
|
}
|
2011-10-21 20:08:54 +02:00
|
|
|
faction.msg("<i>The faction %s<i> changed their name to %s.", fme.getColorTo(faction)+oldtag, myFaction.getTag(faction));
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|
2011-08-20 03:36:23 +02:00
|
|
|
|
2011-10-09 18:35:39 +02:00
|
|
|
if (Conf.spoutFactionTagsOverNames)
|
|
|
|
{
|
2011-08-20 03:36:23 +02:00
|
|
|
SpoutFeatures.updateAppearances(myFaction);
|
|
|
|
}
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|