Make the Faction Permissions more dynamic as well.
This commit is contained in:
@ -1,10 +1,10 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.entity.BoardColl;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
|
||||
@ -41,8 +41,8 @@ public class CmdFactionsAccessFaction extends CmdFactionsAccessAbstract
|
||||
Boolean newValue = this.arg(1, ARBoolean.get(), !ta.isFactionIdGranted(faction.getId()));
|
||||
if (newValue == null) return;
|
||||
|
||||
// FPerm
|
||||
if (!FPerm.ACCESS.has(msender, hostFaction, true)) return;
|
||||
// MPerm
|
||||
if (!MPerm.getAccess().has(msender, hostFaction, true)) return;
|
||||
|
||||
// Apply
|
||||
ta = ta.withFactionId(faction.getId(), newValue);
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARMPlayer;
|
||||
import com.massivecraft.factions.entity.BoardColl;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
@ -41,8 +41,8 @@ public class CmdFactionsAccessPlayer extends CmdFactionsAccessAbstract
|
||||
Boolean newValue = this.arg(1, ARBoolean.get(), !ta.isPlayerIdGranted(mplayer.getId()));
|
||||
if (newValue == null) return;
|
||||
|
||||
// FPerm
|
||||
if (!FPerm.ACCESS.has(msender, hostFaction, true)) return;
|
||||
// MPerm
|
||||
if (!MPerm.getAccess().has(msender, hostFaction, true)) return;
|
||||
|
||||
// Apply
|
||||
ta = ta.withPlayerId(mplayer.getId(), newValue);
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
@ -44,8 +44,8 @@ public class CmdFactionsAutoClaim extends FactionsCommand
|
||||
return;
|
||||
}
|
||||
|
||||
// FPerm
|
||||
if (forFaction.isNormal() && !FPerm.TERRITORY.has(msender, forFaction, true)) return;
|
||||
// MPerm
|
||||
if (forFaction.isNormal() && !MPerm.getTerritory().has(msender, forFaction, true)) return;
|
||||
|
||||
msender.setAutoClaimFaction(forFaction);
|
||||
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.task.SpiralTask;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARInteger;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
@ -46,8 +46,8 @@ public class CmdFactionsClaim extends FactionsCommand
|
||||
final Faction forFaction = this.arg(1, ARFaction.get(), msenderFaction);
|
||||
if (forFaction == null) return;
|
||||
|
||||
// FPerm
|
||||
if (forFaction.isNormal() && !FPerm.TERRITORY.has(msender, forFaction, true)) return;
|
||||
// MPerm
|
||||
if (forFaction.isNormal() && !MPerm.getTerritory().has(msender, forFaction, true)) return;
|
||||
|
||||
// Validate
|
||||
if (radius < 1)
|
||||
|
@ -3,13 +3,13 @@ package com.massivecraft.factions.cmd;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.MFlag;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.event.EventFactionsDisband;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange;
|
||||
import com.massivecraft.factions.event.EventFactionsMembershipChange.MembershipChangeReason;
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
@ -45,8 +45,8 @@ public class CmdFactionsDisband extends FactionsCommand
|
||||
Faction faction = this.arg(0, ARFaction.get(), msenderFaction);
|
||||
if (faction == null) return;
|
||||
|
||||
// FPerm
|
||||
if ( ! FPerm.DISBAND.has(msender, faction, true)) return;
|
||||
// MPerm
|
||||
if ( ! MPerm.getDisband().has(msender, faction, true)) return;
|
||||
|
||||
// Verify
|
||||
if (faction.getFlag(MFlag.getPermanent()))
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARMFlag;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MFlag;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.event.EventFactionsFlagChange;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
@ -67,7 +67,7 @@ public class CmdFactionsFlag extends FactionsCommand
|
||||
}
|
||||
|
||||
// Do the sender have the right to change flags for this faction?
|
||||
if ( ! FPerm.PERMS.has(msender, faction, true)) return;
|
||||
if ( ! MPerm.getFlags().has(msender, faction, true)) return;
|
||||
|
||||
// Is this flag editable?
|
||||
if (!msender.isUsingAdminMode() && !mflag.isEditable())
|
||||
|
@ -4,7 +4,6 @@ import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
@ -12,6 +11,7 @@ import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.entity.BoardColl;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.MFlag;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.event.EventFactionsHomeTeleport;
|
||||
@ -68,7 +68,7 @@ public class CmdFactionsHome extends FactionsCommandHome
|
||||
{
|
||||
msender.msg("<b>%s <b>does not have a home.", faction.describeTo(msender, true));
|
||||
|
||||
if (FPerm.SETHOME.has(msender, faction, false))
|
||||
if (MPerm.getSethome().has(msender, faction, false))
|
||||
{
|
||||
msender.msg("<i>You should:");
|
||||
msender.sendMessage(Factions.get().getOuterCmdFactions().cmdFactionsSethome.getUseageTemplate());
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARMPlayer;
|
||||
import com.massivecraft.factions.cmd.req.ReqHasFaction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.event.EventFactionsInvitedChange;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
|
||||
@ -54,8 +54,8 @@ public class CmdFactionsInvite extends FactionsCommand
|
||||
return;
|
||||
}
|
||||
|
||||
// FPerm
|
||||
if ( ! FPerm.INVITE.has(msender, msenderFaction, true)) return;
|
||||
// MPerm
|
||||
if ( ! MPerm.getInvite().has(msender, msenderFaction, true)) return;
|
||||
|
||||
// Event
|
||||
EventFactionsInvitedChange event = new EventFactionsInvitedChange(sender, mplayer, msenderFaction, newInvited);
|
||||
|
@ -1,11 +1,11 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.arg.ARMPlayer;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.entity.MPlayer;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
@ -63,9 +63,9 @@ public class CmdFactionsKick extends FactionsCommand
|
||||
return;
|
||||
}
|
||||
|
||||
// FPerm
|
||||
// MPerm
|
||||
Faction mplayerFaction = mplayer.getFaction();
|
||||
if (!FPerm.KICK.has(msender, mplayerFaction, true)) return;
|
||||
if ( ! MPerm.getKick().has(msender, mplayerFaction, true)) return;
|
||||
|
||||
// Event
|
||||
EventFactionsMembershipChange event = new EventFactionsMembershipChange(sender, mplayer, FactionColl.get().getNone(), MembershipChangeReason.KICK);
|
||||
|
@ -1,12 +1,12 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
import com.massivecraft.factions.cmd.arg.ARFPerm;
|
||||
import com.massivecraft.factions.cmd.arg.ARMPerm;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.cmd.arg.ARRel;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARBoolean;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
@ -40,60 +40,72 @@ public class CmdFactionsPerm extends FactionsCommand
|
||||
@Override
|
||||
public void perform()
|
||||
{
|
||||
// Arg: Faction
|
||||
Faction faction = this.arg(0, ARFaction.get(), msenderFaction);
|
||||
if (faction == null) return;
|
||||
|
||||
// Case: Show All
|
||||
if ( ! this.argIsSet(1))
|
||||
{
|
||||
msg(Txt.titleize("Perms for " + faction.describeTo(msender, true)));
|
||||
msg(FPerm.getStateHeaders());
|
||||
for (FPerm perm : FPerm.values())
|
||||
msg(MPerm.getStateHeaders());
|
||||
for (MPerm perm : MPerm.getAll())
|
||||
{
|
||||
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
FPerm perm = this.arg(1, ARFPerm.get());
|
||||
if (perm == null) return;
|
||||
//System.out.println("perm = "+perm);
|
||||
// Arg: MPerm
|
||||
MPerm mperm = this.arg(1, ARMPerm.get());
|
||||
if (mperm == null) return;
|
||||
|
||||
// Case: Show One
|
||||
if ( ! this.argIsSet(2))
|
||||
{
|
||||
msg(Txt.titleize("Perm for " + faction.describeTo(msender, true)));
|
||||
msg(FPerm.getStateHeaders());
|
||||
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
|
||||
msg(MPerm.getStateHeaders());
|
||||
msg(mperm.getStateInfo(faction.getPermittedRelations(mperm), true));
|
||||
return;
|
||||
}
|
||||
|
||||
// Do the sender have the right to change perms for this faction?
|
||||
if ( ! FPerm.PERMS.has(msender, faction, true)) return;
|
||||
if ( ! MPerm.getPerms().has(msender, faction, true)) return;
|
||||
|
||||
// Is this perm editable?
|
||||
if (!msender.isUsingAdminMode() && !mperm.isEditable())
|
||||
{
|
||||
msg("<b>The perm <h>%s <b>is not editable.", mperm.getName());
|
||||
return;
|
||||
}
|
||||
|
||||
// Arg: Rel
|
||||
Rel rel = this.arg(2, ARRel.get());
|
||||
if (rel == null) return;
|
||||
|
||||
if (!this.argIsSet(3))
|
||||
if ( ! this.argIsSet(3))
|
||||
{
|
||||
msg("<b>Should <h>%s <b>have the <h>%s <b>permission or not?\nYou must <h>add \"yes\" or \"no\" <b>at the end.", Txt.getNicedEnum(rel), Txt.getNicedEnum(perm));
|
||||
msg("<b>Should <h>%s <b>have the <h>%s <b>permission or not?\nYou must <h>add \"yes\" or \"no\" <b>at the end.", Txt.getNicedEnum(rel), Txt.upperCaseFirst(mperm.getName()));
|
||||
return;
|
||||
}
|
||||
|
||||
Boolean val = this.arg(3, ARBoolean.get(), null);
|
||||
if (val == null) return;
|
||||
// Arg: Target Value
|
||||
Boolean targetValue = this.arg(3, ARBoolean.get(), null);
|
||||
if (targetValue == null) return;
|
||||
|
||||
// Do the change
|
||||
//System.out.println("setRelationPermitted perm "+perm+", rel "+rel+", val "+val);
|
||||
faction.setRelationPermitted(perm, rel, val);
|
||||
// Apply
|
||||
faction.setRelationPermitted(mperm, rel, targetValue);
|
||||
|
||||
// The following is to make sure the leader always has the right to change perms if that is our goal.
|
||||
if (perm == FPerm.PERMS && FPerm.PERMS.getDefault().contains(Rel.LEADER))
|
||||
if (mperm == MPerm.getPerms() && MPerm.getPerms().getStandard().contains(Rel.LEADER))
|
||||
{
|
||||
faction.setRelationPermitted(FPerm.PERMS, Rel.LEADER, true);
|
||||
faction.setRelationPermitted(MPerm.getPerms(), Rel.LEADER, true);
|
||||
}
|
||||
|
||||
// Inform
|
||||
msg(Txt.titleize("Perm for " + faction.describeTo(msender, true)));
|
||||
msg(FPerm.getStateHeaders());
|
||||
msg(perm.getStateInfo(faction.getPermittedRelations(perm), true));
|
||||
msg(MPerm.getStateHeaders());
|
||||
msg(mperm.getStateInfo(faction.getPermittedRelations(mperm), true));
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,10 +1,10 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.event.EventFactionsHomeChange;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqIsPlayer;
|
||||
@ -42,8 +42,8 @@ public class CmdFactionsSethome extends FactionsCommandHome
|
||||
|
||||
PS newHome = PS.valueOf(me.getLocation());
|
||||
|
||||
// FPerm
|
||||
if ( ! FPerm.SETHOME.has(msender, faction, true)) return;
|
||||
// MPerm
|
||||
if ( ! MPerm.getSethome().has(msender, faction, true)) return;
|
||||
|
||||
// Verify
|
||||
if (!msender.isUsingAdminMode() && !faction.isValidHome(newHome))
|
||||
|
@ -2,7 +2,6 @@ package com.massivecraft.factions.cmd;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Factions;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.Rel;
|
||||
@ -12,6 +11,7 @@ import com.massivecraft.factions.entity.BoardColl;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.FactionColl;
|
||||
import com.massivecraft.factions.entity.MConf;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.event.EventFactionsChunkChange;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
import com.massivecraft.massivecore.ps.PS;
|
||||
@ -44,8 +44,8 @@ public class CmdFactionsUnclaimall extends FactionsCommand
|
||||
Faction faction = msenderFaction;
|
||||
Faction newFaction = FactionColl.get().getNone();
|
||||
|
||||
// FPerm
|
||||
if (!FPerm.TERRITORY.has(msender, faction, true)) return;
|
||||
// MPerm
|
||||
if ( ! MPerm.getTerritory().has(msender, faction, true)) return;
|
||||
|
||||
// Apply
|
||||
Set<PS> chunks = BoardColl.get().getChunks(faction);
|
||||
|
@ -1,9 +1,9 @@
|
||||
package com.massivecraft.factions.cmd;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.factions.Perm;
|
||||
import com.massivecraft.factions.cmd.arg.ARFaction;
|
||||
import com.massivecraft.factions.entity.Faction;
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.factions.event.EventFactionsHomeChange;
|
||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||
|
||||
@ -39,8 +39,8 @@ public class CmdFactionsUnsethome extends FactionsCommandHome
|
||||
// Other Perm
|
||||
if (faction != msenderFaction && !Perm.HOME_OTHER.has(sender, true)) return;
|
||||
|
||||
// FPerm
|
||||
if ( ! FPerm.SETHOME.has(msender, faction, true)) return;
|
||||
// MPerm
|
||||
if ( ! MPerm.getSethome().has(msender, faction, true)) return;
|
||||
|
||||
// NoChange
|
||||
if ( ! faction.hasHome())
|
||||
|
@ -1,51 +0,0 @@
|
||||
package com.massivecraft.factions.cmd.arg;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.FPerm;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARAbstractSelect;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class ARFPerm extends ARAbstractSelect<FPerm>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ARFPerm i = new ARFPerm();
|
||||
public static ARFPerm get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String typename()
|
||||
{
|
||||
return "faction permission";
|
||||
}
|
||||
|
||||
@Override
|
||||
public FPerm select(String str, CommandSender sender)
|
||||
{
|
||||
return FPerm.parse(str);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> altNames(CommandSender sender)
|
||||
{
|
||||
List<String> ret = new ArrayList<String>();
|
||||
|
||||
for (FPerm fperm : FPerm.values())
|
||||
{
|
||||
ret.add(Txt.getNicedEnum(fperm));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
88
src/main/java/com/massivecraft/factions/cmd/arg/ARMPerm.java
Normal file
88
src/main/java/com/massivecraft/factions/cmd/arg/ARMPerm.java
Normal file
@ -0,0 +1,88 @@
|
||||
package com.massivecraft.factions.cmd.arg;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
import com.massivecraft.factions.entity.MPerm;
|
||||
import com.massivecraft.massivecore.cmd.arg.ARAbstractSelect;
|
||||
import com.massivecraft.massivecore.util.Txt;
|
||||
|
||||
public class ARMPerm extends ARAbstractSelect<MPerm>
|
||||
{
|
||||
// -------------------------------------------- //
|
||||
// INSTANCE & CONSTRUCT
|
||||
// -------------------------------------------- //
|
||||
|
||||
private static ARMPerm i = new ARMPerm();
|
||||
public static ARMPerm get() { return i; }
|
||||
|
||||
// -------------------------------------------- //
|
||||
// OVERRIDE
|
||||
// -------------------------------------------- //
|
||||
|
||||
@Override
|
||||
public String typename()
|
||||
{
|
||||
return "faction permission";
|
||||
}
|
||||
|
||||
@Override
|
||||
public MPerm select(String arg, CommandSender sender)
|
||||
{
|
||||
if (arg == null) return null;
|
||||
arg = getComparable(arg);
|
||||
|
||||
// Algorithmic General Detection
|
||||
int startswithCount = 0;
|
||||
MPerm startswith = null;
|
||||
for (MPerm mperm : MPerm.getAll())
|
||||
{
|
||||
String comparable = getComparable(mperm);
|
||||
if (comparable.equals(arg)) return mperm;
|
||||
if (comparable.startsWith(arg))
|
||||
{
|
||||
startswith = mperm;
|
||||
startswithCount++;
|
||||
}
|
||||
}
|
||||
|
||||
if (startswithCount == 1)
|
||||
{
|
||||
return startswith;
|
||||
}
|
||||
|
||||
// Nothing found
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Collection<String> altNames(CommandSender sender)
|
||||
{
|
||||
List<String> ret = new ArrayList<String>();
|
||||
|
||||
for (MPerm mperm : MPerm.getAll())
|
||||
{
|
||||
ret.add(Txt.upperCaseFirst(mperm.getName()));
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
// -------------------------------------------- //
|
||||
// UTIL
|
||||
// -------------------------------------------- //
|
||||
|
||||
public static String getComparable(String string)
|
||||
{
|
||||
return string.toLowerCase();
|
||||
}
|
||||
|
||||
public static String getComparable(MPerm mperm)
|
||||
{
|
||||
return getComparable(mperm.getName());
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user