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.entity.MPerm;
 | 
			
		||||
import com.massivecraft.factions.entity.MPlayer;
 | 
			
		||||
import com.massivecraft.massivecore.MassiveCore;
 | 
			
		||||
import com.massivecraft.massivecore.cmd.req.ReqHasPerm;
 | 
			
		||||
import com.massivecraft.massivecore.mixin.Mixin;
 | 
			
		||||
import com.massivecraft.massivecore.util.MUtil;
 | 
			
		||||
@ -50,7 +51,7 @@ public class CmdFactionsMotd extends FactionsCommand
 | 
			
		||||
		target = Txt.parse(target);
 | 
			
		||||
		
 | 
			
		||||
		// 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;
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
@ -5,6 +5,7 @@ import org.bukkit.command.CommandSender;
 | 
			
		||||
import com.massivecraft.factions.entity.MPlayer;
 | 
			
		||||
import com.massivecraft.factions.entity.Faction;
 | 
			
		||||
import com.massivecraft.factions.entity.FactionColl;
 | 
			
		||||
import com.massivecraft.massivecore.MassiveCore;
 | 
			
		||||
import com.massivecraft.massivecore.cmd.arg.ArgReaderAbstract;
 | 
			
		||||
import com.massivecraft.massivecore.cmd.arg.ArgResult;
 | 
			
		||||
import com.massivecraft.massivecore.util.IdUtil;
 | 
			
		||||
@ -28,12 +29,22 @@ public class ARFaction extends ArgReaderAbstract<Faction>
 | 
			
		||||
	{
 | 
			
		||||
		ArgResult<Faction> result = new ArgResult<Faction>();
 | 
			
		||||
		
 | 
			
		||||
		// Faction Name Exact 
 | 
			
		||||
		result.setResult(FactionColl.get().getByName(str));
 | 
			
		||||
		if (result.hasResult()) return result;
 | 
			
		||||
		// Nothing/Remove targets Wilderness
 | 
			
		||||
		if (MassiveCore.NOTHING_REMOVE.contains(str))
 | 
			
		||||
		{
 | 
			
		||||
			result.setResult(FactionColl.get().getNone());
 | 
			
		||||
			return result;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		// Faction Name Match
 | 
			
		||||
		result.setResult(FactionColl.get().getBestNameMatch(str));
 | 
			
		||||
		// Faction Id Exact
 | 
			
		||||
		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;
 | 
			
		||||
		
 | 
			
		||||
		// MPlayer Name Exact
 | 
			
		||||
 | 
			
		||||
@ -238,9 +238,9 @@ public class FactionColl extends Coll<Faction>
 | 
			
		||||
		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())
 | 
			
		||||
		{
 | 
			
		||||
			if (faction.getComparisonName().equals(compStr))
 | 
			
		||||
@ -251,21 +251,6 @@ public class FactionColl extends Coll<Faction>
 | 
			
		||||
		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)
 | 
			
		||||
	{
 | 
			
		||||
		return this.getByName(str) != null;
 | 
			
		||||
 | 
			
		||||
@ -811,13 +811,13 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
 | 
			
		||||
		{
 | 
			
		||||
			if (newFaction.isNormal())
 | 
			
		||||
			{
 | 
			
		||||
				if (!mconf.worldsClaimingEnabled.contains(ps.getWorld()))
 | 
			
		||||
				if ( ! mconf.worldsClaimingEnabled.contains(ps.getWorld()))
 | 
			
		||||
				{
 | 
			
		||||
					msg("<b>Sorry, this world has land claiming disabled.");
 | 
			
		||||
					return false;
 | 
			
		||||
				}
 | 
			
		||||
				
 | 
			
		||||
				if (!MPerm.getPermTerritory().has(this, newFaction, true))
 | 
			
		||||
				if ( ! MPerm.getPermTerritory().has(this, newFaction, true))
 | 
			
		||||
				{
 | 
			
		||||
					return false;
 | 
			
		||||
				}
 | 
			
		||||
@ -863,9 +863,9 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
 | 
			
		||||
					&&
 | 
			
		||||
					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)
 | 
			
		||||
@ -882,7 +882,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
 | 
			
		||||
			
 | 
			
		||||
			if (oldFaction.isNormal())
 | 
			
		||||
			{
 | 
			
		||||
				if (!MPerm.getPermTerritory().has(this, oldFaction, false))
 | 
			
		||||
				if ( ! MPerm.getPermTerritory().has(this, oldFaction, false))
 | 
			
		||||
				{
 | 
			
		||||
					if (this.hasFaction() && this.getFaction() == oldFaction)
 | 
			
		||||
					{
 | 
			
		||||
@ -890,7 +890,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
 | 
			
		||||
						return false;
 | 
			
		||||
					}
 | 
			
		||||
					
 | 
			
		||||
					if (!mconf.claimingFromOthersAllowed)
 | 
			
		||||
					if ( ! mconf.claimingFromOthersAllowed)
 | 
			
		||||
					{
 | 
			
		||||
						msg("<b>You may not claim land from others.");
 | 
			
		||||
						return false;
 | 
			
		||||
@ -902,7 +902,7 @@ public class MPlayer extends SenderEntity<MPlayer> implements EconomyParticipato
 | 
			
		||||
						return false;
 | 
			
		||||
					}
 | 
			
		||||
					
 | 
			
		||||
					if (!oldFaction.hasLandInflation())
 | 
			
		||||
					if ( ! oldFaction.hasLandInflation())
 | 
			
		||||
					{
 | 
			
		||||
						msg("%s<i> owns this land and is strong enough to keep it.", oldFaction.getName(this));
 | 
			
		||||
						return false;
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user