Add faction argument to /f name. Adds #680

This commit is contained in:
Olof Larsson 2014-10-03 13:37:47 +02:00
parent 1141dce696
commit 8612f0a39a

View File

@ -3,7 +3,8 @@ package com.massivecraft.factions.cmd;
import java.util.ArrayList; import java.util.ArrayList;
import com.massivecraft.factions.Perm; import com.massivecraft.factions.Perm;
import com.massivecraft.factions.cmd.req.ReqHasFaction; import com.massivecraft.factions.cmd.arg.ARFaction;
import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.FactionColl;
import com.massivecraft.factions.entity.MPerm; import com.massivecraft.factions.entity.MPerm;
import com.massivecraft.factions.event.EventFactionsNameChange; import com.massivecraft.factions.event.EventFactionsNameChange;
@ -23,10 +24,10 @@ public class CmdFactionsName extends FactionsCommand
// Args // Args
this.addRequiredArg("new name"); this.addRequiredArg("new name");
this.addOptionalArg("faction", "you");
// Requirements // Requirements
this.addRequirements(ReqHasPerm.get(Perm.NAME.node)); this.addRequirements(ReqHasPerm.get(Perm.NAME.node));
this.addRequirements(ReqHasFaction.get());
} }
// -------------------------------------------- // // -------------------------------------------- //
@ -36,14 +37,17 @@ public class CmdFactionsName extends FactionsCommand
@Override @Override
public void perform() public void perform()
{ {
// Arg // Args
String newName = this.arg(0); String newName = this.arg(0);
Faction faction = this.arg(1, ARFaction.get(), msenderFaction);
if (faction == null) return;
// MPerm // MPerm
if ( ! MPerm.getPermName().has(msender, msenderFaction, true)) return; if ( ! MPerm.getPermName().has(msender, faction, true)) return;
// TODO does not first test cover selfcase? // TODO does not first test cover selfcase?
if (FactionColl.get().isNameTaken(newName) && ! MiscUtil.getComparisonString(newName).equals(msenderFaction.getComparisonName())) if (FactionColl.get().isNameTaken(newName) && ! MiscUtil.getComparisonString(newName).equals(faction.getComparisonName()))
{ {
msg("<b>That name is already taken"); msg("<b>That name is already taken");
return; return;
@ -58,16 +62,20 @@ public class CmdFactionsName extends FactionsCommand
} }
// Event // Event
EventFactionsNameChange event = new EventFactionsNameChange(sender, msenderFaction, newName); EventFactionsNameChange event = new EventFactionsNameChange(sender, faction, newName);
event.run(); event.run();
if (event.isCancelled()) return; if (event.isCancelled()) return;
newName = event.getNewName(); newName = event.getNewName();
// Apply // Apply
msenderFaction.setName(newName); faction.setName(newName);
// Inform // Inform
msenderFaction.msg("%s<i> changed your faction name to %s", msender.describeTo(msenderFaction, true), msenderFaction.getName(msenderFaction)); 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));
}
} }
} }