Factions3/src/main/java/com/massivecraft/factions/cmd/CmdFactionsName.java

74 lines
1.9 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.ReqHasFaction;
import com.massivecraft.factions.cmd.req.ReqRoleIsAtLeast;
2013-04-22 09:37:53 +02:00
import com.massivecraft.factions.entity.FactionColl;
2014-06-04 16:47:01 +02:00
import com.massivecraft.factions.event.EventFactionsNameChange;
2011-10-09 18:35:39 +02:00
import com.massivecraft.factions.util.MiscUtil;
2014-06-04 14:02:23 +02:00
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
2011-04-08 15:51:07 +02:00
2014-09-18 13:41:20 +02:00
public class CmdFactionsName extends FactionsCommand
2011-10-09 18:35:39 +02:00
{
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// CONSTRUCT
// -------------------------------------------- //
public CmdFactionsName()
2011-10-09 18:35:39 +02:00
{
2013-11-11 09:31:04 +01:00
// Aliases
this.addAliases("name");
2013-11-11 09:31:04 +01:00
// Args
this.addRequiredArg("new name");
2013-11-11 09:31:04 +01:00
// Requirements
this.addRequirements(ReqHasPerm.get(Perm.NAME.node));
this.addRequirements(ReqHasFaction.get());
this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER));
}
2013-11-11 09:31:04 +01:00
// -------------------------------------------- //
// OVERRIDE
// -------------------------------------------- //
@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?
2014-09-18 13:41:20 +02:00
if (FactionColl.get().isNameTaken(newName) && ! MiscUtil.getComparisonString(newName).equals(msenderFaction.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.get().validateName(newName));
2011-10-09 18:35:39 +02:00
if (errors.size() > 0)
{
sendMessage(errors);
return;
}
// Event
2014-09-18 13:41:20 +02:00
EventFactionsNameChange event = new EventFactionsNameChange(sender, msenderFaction, newName);
event.run();
if (event.isCancelled()) return;
newName = event.getNewName();
// Apply
2014-09-18 13:41:20 +02:00
msenderFaction.setName(newName);
// Inform
2014-09-18 13:41:20 +02:00
msenderFaction.msg("%s<i> changed your faction name to %s", msender.describeTo(msenderFaction, true), msenderFaction.getName(msenderFaction));
}
}