Rework the ARFaction. No best match. Matching is slow and dangerous.
This commit is contained in:
parent
6974c82bb6
commit
b54293577d
@ -3,6 +3,7 @@ package com.massivecraft.factions.cmd;
|
|||||||
import com.massivecraft.factions.Perm;
|
import com.massivecraft.factions.Perm;
|
||||||
import com.massivecraft.factions.entity.MPerm;
|
import com.massivecraft.factions.entity.MPerm;
|
||||||
import com.massivecraft.factions.entity.MPlayer;
|
import com.massivecraft.factions.entity.MPlayer;
|
||||||
|
import com.massivecraft.massivecore.MassiveCore;
|
||||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
|
||||||
import com.massivecraft.massivecore.mixin.Mixin;
|
import com.massivecraft.massivecore.mixin.Mixin;
|
||||||
import com.massivecraft.massivecore.util.MUtil;
|
import com.massivecraft.massivecore.util.MUtil;
|
||||||
@ -50,7 +51,7 @@ public class CmdFactionsMotd extends FactionsCommand
|
|||||||
target = Txt.parse(target);
|
target = Txt.parse(target);
|
||||||
|
|
||||||
// Removal
|
// Removal
|
||||||
if (target != null && MUtil.set("", "r", "remove", "d", "delete", "del", "e", "erase", "none", "null", "nothing").contains(target))
|
if (target != null && MassiveCore.NOTHING_REMOVE.contains(target))
|
||||||
{
|
{
|
||||||
target = null;
|
target = null;
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import com.massivecraft.factions.entity.MPlayer;
|
import com.massivecraft.factions.entity.MPlayer;
|
||||||
import com.massivecraft.factions.entity.Faction;
|
import com.massivecraft.factions.entity.Faction;
|
||||||
import com.massivecraft.factions.entity.FactionColl;
|
import com.massivecraft.factions.entity.FactionColl;
|
||||||
|
import com.massivecraft.massivecore.MassiveCore;
|
||||||
import com.massivecraft.massivecore.cmd.arg.ArgReaderAbstract;
|
import com.massivecraft.massivecore.cmd.arg.ArgReaderAbstract;
|
||||||
import com.massivecraft.massivecore.cmd.arg.ArgResult;
|
import com.massivecraft.massivecore.cmd.arg.ArgResult;
|
||||||
import com.massivecraft.massivecore.util.IdUtil;
|
import com.massivecraft.massivecore.util.IdUtil;
|
||||||
@ -28,12 +29,22 @@ public class ARFaction extends ArgReaderAbstract<Faction>
|
|||||||
{
|
{
|
||||||
ArgResult<Faction> result = new ArgResult<Faction>();
|
ArgResult<Faction> result = new ArgResult<Faction>();
|
||||||
|
|
||||||
// Faction Name Exact
|
// Nothing/Remove targets Wilderness
|
||||||
result.setResult(FactionColl.get().getByName(str));
|
if (MassiveCore.NOTHING_REMOVE.contains(str))
|
||||||
if (result.hasResult()) return result;
|
{
|
||||||
|
result.setResult(FactionColl.get().getNone());
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// Faction Name Match
|
// Faction Id Exact
|
||||||
result.setResult(FactionColl.get().getBestNameMatch(str));
|
if (FactionColl.get().containsId(str))
|
||||||
|
{
|
||||||
|
result.setResult(FactionColl.get().get(str));
|
||||||
|
if (result.hasResult()) return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Faction Name Exact
|
||||||
|
result.setResult(FactionColl.get().getByName(str));
|
||||||
if (result.hasResult()) return result;
|
if (result.hasResult()) return result;
|
||||||
|
|
||||||
// MPlayer Name Exact
|
// MPlayer Name Exact
|
||||||
|
@ -238,9 +238,9 @@ public class FactionColl extends Coll<Faction>
|
|||||||
return errors;
|
return errors;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Faction getByName(String str)
|
public Faction getByName(String name)
|
||||||
{
|
{
|
||||||
String compStr = MiscUtil.getComparisonString(str);
|
String compStr = MiscUtil.getComparisonString(name);
|
||||||
for (Faction faction : this.getAll())
|
for (Faction faction : this.getAll())
|
||||||
{
|
{
|
||||||
if (faction.getComparisonName().equals(compStr))
|
if (faction.getComparisonName().equals(compStr))
|
||||||
@ -251,21 +251,6 @@ public class FactionColl extends Coll<Faction>
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Faction getBestNameMatch(String searchFor)
|
|
||||||
{
|
|
||||||
Map<String, Faction> name2faction = new HashMap<String, Faction>();
|
|
||||||
|
|
||||||
// TODO: Slow index building
|
|
||||||
for (Faction faction : this.getAll())
|
|
||||||
{
|
|
||||||
name2faction.put(ChatColor.stripColor(faction.getName()), faction);
|
|
||||||
}
|
|
||||||
|
|
||||||
String tag = Txt.getBestCIStart(name2faction.keySet(), searchFor);
|
|
||||||
if (tag == null) return null;
|
|
||||||
return name2faction.get(tag);
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isNameTaken(String str)
|
public boolean isNameTaken(String str)
|
||||||
{
|
{
|
||||||
return this.getByName(str) != null;
|
return this.getByName(str) != null;
|
||||||
|
@ -811,13 +811,13 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
|
|||||||
{
|
{
|
||||||
if (newFaction.isNormal())
|
if (newFaction.isNormal())
|
||||||
{
|
{
|
||||||
if (!mconf.worldsClaimingEnabled.contains(ps.getWorld()))
|
if ( ! mconf.worldsClaimingEnabled.contains(ps.getWorld()))
|
||||||
{
|
{
|
||||||
msg("<b>Sorry, this world has land claiming disabled.");
|
msg("<b>Sorry, this world has land claiming disabled.");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!MPerm.getPermTerritory().has(this, newFaction, true))
|
if ( ! MPerm.getPermTerritory().has(this, newFaction, true))
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -863,9 +863,9 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
|
|||||||
&&
|
&&
|
||||||
newFaction.getLandCountInWorld(ps.getWorld()) > 0
|
newFaction.getLandCountInWorld(ps.getWorld()) > 0
|
||||||
&&
|
&&
|
||||||
!BoardColl.get().isConnectedPs(chunk, newFaction)
|
! BoardColl.get().isConnectedPs(chunk, newFaction)
|
||||||
&&
|
&&
|
||||||
(!mconf.claimsCanBeUnconnectedIfOwnedByOtherFaction || oldFaction.isNone())
|
( ! mconf.claimsCanBeUnconnectedIfOwnedByOtherFaction || oldFaction.isNone())
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
if (mconf.claimsCanBeUnconnectedIfOwnedByOtherFaction)
|
if (mconf.claimsCanBeUnconnectedIfOwnedByOtherFaction)
|
||||||
@ -882,7 +882,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
|
|||||||
|
|
||||||
if (oldFaction.isNormal())
|
if (oldFaction.isNormal())
|
||||||
{
|
{
|
||||||
if (!MPerm.getPermTerritory().has(this, oldFaction, false))
|
if ( ! MPerm.getPermTerritory().has(this, oldFaction, false))
|
||||||
{
|
{
|
||||||
if (this.hasFaction() && this.getFaction() == oldFaction)
|
if (this.hasFaction() && this.getFaction() == oldFaction)
|
||||||
{
|
{
|
||||||
@ -890,7 +890,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mconf.claimingFromOthersAllowed)
|
if ( ! mconf.claimingFromOthersAllowed)
|
||||||
{
|
{
|
||||||
msg("<b>You may not claim land from others.");
|
msg("<b>You may not claim land from others.");
|
||||||
return false;
|
return false;
|
||||||
@ -902,7 +902,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!oldFaction.hasLandInflation())
|
if ( ! oldFaction.hasLandInflation())
|
||||||
{
|
{
|
||||||
msg("%s<i> owns this land and is strong enough to keep it.", oldFaction.getName(this));
|
msg("%s<i> owns this land and is strong enough to keep it.", oldFaction.getName(this));
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user