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;
|
2014-10-03 13:37:47 +02:00
|
|
|
import com.massivecraft.factions.cmd.arg.ARFaction;
|
|
|
|
import com.massivecraft.factions.entity.Faction;
|
2013-04-22 09:37:53 +02:00
|
|
|
import com.massivecraft.factions.entity.FactionColl;
|
2014-10-03 09:01:36 +02:00
|
|
|
import com.massivecraft.factions.entity.MPerm;
|
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;
|
2015-02-12 12:00:55 +01:00
|
|
|
import com.massivecraft.massivecore.MassiveException;
|
2015-05-06 17:04:35 +02:00
|
|
|
import com.massivecraft.massivecore.cmd.arg.ARString;
|
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
|
|
|
|
// -------------------------------------------- //
|
|
|
|
|
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
|
2015-05-06 17:04:35 +02:00
|
|
|
this.addArg(ARString.get(), "new name");
|
|
|
|
this.addArg(ARFaction.get(), "faction", "you");
|
2013-11-11 09:31:04 +01:00
|
|
|
|
|
|
|
// Requirements
|
2013-04-24 19:01:17 +02:00
|
|
|
this.addRequirements(ReqHasPerm.get(Perm.NAME.node));
|
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
|
2015-02-12 12:00:55 +01:00
|
|
|
public void perform() throws MassiveException
|
2011-10-09 18:35:39 +02:00
|
|
|
{
|
2014-10-03 13:37:47 +02:00
|
|
|
// Args
|
2015-05-06 17:04:35 +02:00
|
|
|
String newName = this.readArg();
|
|
|
|
Faction faction = this.readArg(msenderFaction);
|
2014-10-03 13:37:47 +02:00
|
|
|
|
2014-10-03 09:01:36 +02:00
|
|
|
// MPerm
|
2014-10-03 13:37:47 +02:00
|
|
|
if ( ! MPerm.getPermName().has(msender, faction, true)) return;
|
2013-04-22 16:58:22 +02:00
|
|
|
|
2014-10-03 09:01:36 +02:00
|
|
|
// TODO does not first test cover selfcase?
|
2014-10-03 13:37:47 +02:00
|
|
|
if (FactionColl.get().isNameTaken(newName) && ! MiscUtil.getComparisonString(newName).equals(faction.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>();
|
2014-09-17 13:17:33 +02:00
|
|
|
errors.addAll(FactionColl.get().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
|
2014-10-03 13:37:47 +02:00
|
|
|
EventFactionsNameChange event = new EventFactionsNameChange(sender, faction, 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
|
2014-10-03 13:37:47 +02:00
|
|
|
faction.setName(newName);
|
2012-03-09 23:09:33 +01:00
|
|
|
|
2011-03-22 15:45:41 +01:00
|
|
|
// Inform
|
2014-10-03 13:37:47 +02:00
|
|
|
faction.msg("%s<i> changed your faction name to %s", msender.describeTo(faction, true), faction.getName(faction));
|
|
|
|
if (msenderFaction != faction)
|
|
|
|
{
|
|
|
|
msg("<i>You changed the faction name to %s", faction.getName(msender));
|
|
|
|
}
|
2011-03-22 15:45:41 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|