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;
|
|
|
|
|
2013-04-09 12:56:29 +02:00
|
|
|
import com.massivecraft.factions.Perm;
|
2013-04-16 12:04:12 +02:00
|
|
|
import com.massivecraft.factions.Rel;
|
2013-04-25 13:25:15 +02:00
|
|
|
import com.massivecraft.factions.cmd.req.ReqFactionsEnabled;
|
2013-04-25 13:53:22 +02:00
|
|
|
import com.massivecraft.factions.cmd.req.ReqHasFaction;
|
2013-04-16 12:04:12 +02:00
|
|
|
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;
|
2013-04-24 19:01:17 +02:00
|
|
|
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
|
|
|
|
2013-04-24 19:01:17 +02:00
|
|
|
public class CmdFactionsName extends FCommand
|
2011-10-09 18:35:39 +02:00
|
|
|
{
|
2013-11-11 09:31:04 +01:00
|
|
|
// -------------------------------------------- //
|
|
|
|
// CONSTRUCT
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
2013-04-24 19:01:17 +02:00
|
|
|
public CmdFactionsName()
|
2011-10-09 18:35:39 +02:00
|
|
|
{
|
2013-11-11 09:31:04 +01:00
|
|
|
// Aliases
|
2013-04-24 19:01:17 +02:00
|
|
|
this.addAliases("name");
|
2013-11-11 09:31:04 +01:00
|
|
|
|
|
|
|
// Args
|
2013-04-24 19:01:17 +02:00
|
|
|
this.addRequiredArg("new name");
|
2013-11-11 09:31:04 +01:00
|
|
|
|
|
|
|
// Requirements
|
2013-04-25 13:25:15 +02:00
|
|
|
this.addRequirements(ReqFactionsEnabled.get());
|
2013-04-24 19:01:17 +02:00
|
|
|
this.addRequirements(ReqHasPerm.get(Perm.NAME.node));
|
2013-04-25 13:53:22 +02:00
|
|
|
this.addRequirements(ReqHasFaction.get());
|
2013-04-16 12:04:12 +02:00
|
|
|
this.addRequirements(ReqRoleIsAtLeast.get(Rel.OFFICER));
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|
2013-11-11 09:31:04 +01:00
|
|
|
|
|
|
|
// -------------------------------------------- //
|
|
|
|
// OVERRIDE
|
|
|
|
// -------------------------------------------- //
|
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()
|
|
|
|
{
|
2013-04-19 12:27:39 +02:00
|
|
|
// Arg
|
2013-04-24 19:01:17 +02:00
|
|
|
String newName = this.arg(0);
|
2011-03-22 15:45:41 +01:00
|
|
|
|
|
|
|
// TODO does not first test cover selfcase?
|
2013-04-22 16:58:22 +02:00
|
|
|
|
2013-04-25 07:29:19 +02:00
|
|
|
FactionColl factionColl = FactionColls.get().get(usenderFaction);
|
|
|
|
if (factionColl.isNameTaken(newName) && ! MiscUtil.getComparisonString(newName).equals(usenderFaction.getComparisonName()))
|
2011-10-09 18:35:39 +02:00
|
|
|
{
|
2013-04-24 19:01:17 +02:00
|
|
|
msg("<b>That name is already taken");
|
2011-03-22 15:45:41 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-03-09 23:09:33 +01:00
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
ArrayList<String> errors = new ArrayList<String>();
|
2013-04-24 19:01:17 +02:00
|
|
|
errors.addAll(factionColl.validateName(newName));
|
2011-10-09 18:35:39 +02:00
|
|
|
if (errors.size() > 0)
|
|
|
|
{
|
2011-03-22 15:45:41 +01:00
|
|
|
sendMessage(errors);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-04-19 12:27:39 +02:00
|
|
|
// Event
|
2013-04-25 07:29:19 +02:00
|
|
|
FactionsEventNameChange event = new FactionsEventNameChange(sender, usenderFaction, newName);
|
2013-04-19 12:44:28 +02:00
|
|
|
event.run();
|
|
|
|
if (event.isCancelled()) return;
|
2013-04-24 19:01:17 +02:00
|
|
|
newName = event.getNewName();
|
2012-03-09 23:09:33 +01:00
|
|
|
|
2013-04-19 12:27:39 +02:00
|
|
|
// Apply
|
2013-04-25 07:29:19 +02:00
|
|
|
String oldName = usenderFaction.getName();
|
|
|
|
usenderFaction.setName(newName);
|
2012-03-09 23:09:33 +01:00
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
// Inform
|
2013-04-25 07:29:19 +02:00
|
|
|
usenderFaction.msg("%s<i> changed your faction name to %s", usender.describeTo(usenderFaction, true), usenderFaction.getName(usenderFaction));
|
|
|
|
for (Faction faction : FactionColls.get().get(usenderFaction).getAll())
|
2011-10-09 18:35:39 +02:00
|
|
|
{
|
2013-04-25 07:29:19 +02:00
|
|
|
if (faction == usenderFaction)
|
2011-10-09 18:35:39 +02:00
|
|
|
{
|
2011-03-22 15:45:41 +01:00
|
|
|
continue;
|
|
|
|
}
|
2013-04-25 07:29:19 +02:00
|
|
|
faction.msg("<i>The faction %s<i> changed their name to %s.", usender.getColorTo(faction)+oldName, usenderFaction.getName(faction));
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|