Factions/src/com/massivecraft/factions/cmd/CmdFactionsName.java

74 lines
2.0 KiB
Java
Raw Normal View History

2011-10-09 21:57:43 +02:00
package com.massivecraft.factions.cmd;
import java.util.ArrayList;
import com.massivecraft.factions.Perm;
import com.massivecraft.factions.Rel;
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.FactionColl;
2013-04-22 13:03:21 +02:00
import com.massivecraft.factions.entity.FactionColls;
import com.massivecraft.factions.event.FactionsEventNameChange;
2011-10-09 18:35:39 +02:00
import com.massivecraft.factions.util.MiscUtil;
2013-04-16 10:11:59 +02:00
import com.massivecraft.mcore.cmd.req.ReqHasPerm;
2011-04-08 15:51:07 +02:00
public class CmdFactionsName extends FCommand
2011-10-09 18:35:39 +02:00
{
public CmdFactionsName()
2011-10-09 18:35:39 +02:00
{
this.addAliases("name");
2011-10-09 18:35:39 +02:00
this.addRequiredArg("new name");
this.addRequirements(ReqHasPerm.get(Perm.NAME.node));
this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER));
}
@Override
2011-10-09 18:35:39 +02:00
public void perform()
{
// Arg
String newName = this.arg(0);
// TODO does not first test cover selfcase?
FactionColl factionColl = FactionColls.get().get(myFaction);
if (factionColl.isNameTaken(newName) && ! MiscUtil.getComparisonString(newName).equals(myFaction.getComparisonName()))
2011-10-09 18:35:39 +02:00
{
msg("<b>That name is already taken");
return;
}
ArrayList<String> errors = new ArrayList<String>();
errors.addAll(factionColl.validateName(newName));
2011-10-09 18:35:39 +02:00
if (errors.size() > 0)
{
sendMessage(errors);
return;
}
// Event
FactionsEventNameChange event = new FactionsEventNameChange(sender, myFaction, newName);
event.run();
if (event.isCancelled()) return;
newName = event.getNewName();
// Apply
String oldName = myFaction.getName();
myFaction.setName(newName);
// Inform
myFaction.msg("%s<i> changed your faction name to %s", fme.describeTo(myFaction, true), myFaction.getName(myFaction));
2013-04-22 13:03:21 +02:00
for (Faction faction : FactionColls.get().get(myFaction).getAll())
2011-10-09 18:35:39 +02:00
{
if (faction == myFaction)
{
continue;
}
faction.msg("<i>The faction %s<i> changed their name to %s.", fme.getColorTo(faction)+oldName, myFaction.getName(faction));
}
}
}