From b54293577da119d592493ffd4cb4af3b60d7e223 Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Mon, 13 Oct 2014 08:11:00 +0200 Subject: [PATCH] Rework the ARFaction. No best match. Matching is slow and dangerous. --- .../factions/cmd/CmdFactionsMotd.java | 3 ++- .../factions/cmd/arg/ARFaction.java | 21 ++++++++++++++----- .../factions/entity/FactionColl.java | 19 ++--------------- .../massivecraft/factions/entity/MPlayer.java | 14 ++++++------- 4 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMotd.java b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMotd.java index 34e493ea..551b9cb9 100644 --- a/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMotd.java +++ b/src/main/java/com/massivecraft/factions/cmd/CmdFactionsMotd.java @@ -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; } diff --git a/src/main/java/com/massivecraft/factions/cmd/arg/ARFaction.java b/src/main/java/com/massivecraft/factions/cmd/arg/ARFaction.java index cbfe2818..24155758 100644 --- a/src/main/java/com/massivecraft/factions/cmd/arg/ARFaction.java +++ b/src/main/java/com/massivecraft/factions/cmd/arg/ARFaction.java @@ -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 { ArgResult result = new ArgResult(); - // 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 diff --git a/src/main/java/com/massivecraft/factions/entity/FactionColl.java b/src/main/java/com/massivecraft/factions/entity/FactionColl.java index 4f7e45d4..382cbea3 100644 --- a/src/main/java/com/massivecraft/factions/entity/FactionColl.java +++ b/src/main/java/com/massivecraft/factions/entity/FactionColl.java @@ -238,9 +238,9 @@ public class FactionColl extends Coll 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 return null; } - public Faction getBestNameMatch(String searchFor) - { - Map name2faction = new HashMap(); - - // 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; diff --git a/src/main/java/com/massivecraft/factions/entity/MPlayer.java b/src/main/java/com/massivecraft/factions/entity/MPlayer.java index 27b75fdf..10f473cb 100644 --- a/src/main/java/com/massivecraft/factions/entity/MPlayer.java +++ b/src/main/java/com/massivecraft/factions/entity/MPlayer.java @@ -811,13 +811,13 @@ public class MPlayer extends SenderEntity implements EconomyParticipato { if (newFaction.isNormal()) { - if (!mconf.worldsClaimingEnabled.contains(ps.getWorld())) + if ( ! mconf.worldsClaimingEnabled.contains(ps.getWorld())) { msg("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 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 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 implements EconomyParticipato return false; } - if (!mconf.claimingFromOthersAllowed) + if ( ! mconf.claimingFromOthersAllowed) { msg("You may not claim land from others."); return false; @@ -902,7 +902,7 @@ public class MPlayer extends SenderEntity implements EconomyParticipato return false; } - if (!oldFaction.hasLandInflation()) + if ( ! oldFaction.hasLandInflation()) { msg("%s owns this land and is strong enough to keep it.", oldFaction.getName(this)); return false;