From a9b80dacfe6de6bdc5a973d155d79b624e4c774f Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Sat, 16 May 2015 12:19:36 +0200 Subject: [PATCH] Remove ID update. Add NPC awareness. --- .../factions/FactionEqualsPredictate.java | 2 + src/com/massivecraft/factions/Factions.java | 2 - .../factions/TerritoryAccess.java | 7 +- .../factions/cmd/CmdFactionsHome.java | 3 + .../factions/cmd/arg/ARFaction.java | 3 +- .../factions/cmd/req/ReqHasFaction.java | 5 +- .../factions/cmd/req/ReqHasntFaction.java | 5 +- .../factions/cmd/req/ReqRoleIsAtLeast.java | 2 + .../factions/engine/EngineChat.java | 7 +- .../factions/engine/EngineIdUpdate.java | 112 ------------------ .../factions/engine/EngineMain.java | 14 ++- .../massivecraft/factions/entity/Faction.java | 2 + .../factions/spigot/EngineSpigot.java | 2 + .../factions/task/TaskPlayerPowerUpdate.java | 1 + 14 files changed, 44 insertions(+), 123 deletions(-) delete mode 100644 src/com/massivecraft/factions/engine/EngineIdUpdate.java diff --git a/src/com/massivecraft/factions/FactionEqualsPredictate.java b/src/com/massivecraft/factions/FactionEqualsPredictate.java index c4424541..4bc24a1e 100644 --- a/src/com/massivecraft/factions/FactionEqualsPredictate.java +++ b/src/com/massivecraft/factions/FactionEqualsPredictate.java @@ -7,6 +7,7 @@ import org.bukkit.command.CommandSender; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.Faction; import com.massivecraft.massivecore.Predictate; +import com.massivecraft.massivecore.util.MUtil; public class FactionEqualsPredictate implements Predictate, Serializable { @@ -35,6 +36,7 @@ public class FactionEqualsPredictate implements Predictate, Seria @Override public boolean apply(CommandSender sender) { + if (MUtil.isNpc(sender)) return false; MPlayer mplayer = MPlayer.get(sender); return this.factionId.equals(mplayer.getFactionId()); } diff --git a/src/com/massivecraft/factions/Factions.java b/src/com/massivecraft/factions/Factions.java index ea22eb6b..5ede3138 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -24,7 +24,6 @@ import com.massivecraft.factions.cmd.*; import com.massivecraft.factions.engine.EngineChat; import com.massivecraft.factions.engine.EngineEcon; import com.massivecraft.factions.engine.EngineExploit; -import com.massivecraft.factions.engine.EngineIdUpdate; import com.massivecraft.factions.engine.EngineMain; import com.massivecraft.factions.engine.EngineSeeChunk; import com.massivecraft.factions.entity.Board; @@ -149,7 +148,6 @@ public class Factions extends MassivePlugin EngineMain.get().activate(); EngineChat.get().activate(); EngineExploit.get().activate(); - EngineIdUpdate.get().activate(); EngineSeeChunk.get().activate(); EngineEcon.get().activate(); // TODO: Take an extra look and make sure all economy stuff is handled using events. diff --git a/src/com/massivecraft/factions/TerritoryAccess.java b/src/com/massivecraft/factions/TerritoryAccess.java index 54596826..fdb3a8a8 100644 --- a/src/com/massivecraft/factions/TerritoryAccess.java +++ b/src/com/massivecraft/factions/TerritoryAccess.java @@ -17,7 +17,7 @@ public class TerritoryAccess // FIELDS: RAW // -------------------------------------------- // - // TODO: remake private final + // TODO: Remake private final // no default value, can't be null public String hostFactionId; public String getHostFactionId() { return this.hostFactionId; } @@ -26,14 +26,13 @@ public class TerritoryAccess private final boolean hostFactionAllowed; public boolean isHostFactionAllowed() { return this.hostFactionAllowed; } - // TODO: remake private final + // TODO: Remake private final // default is empty public Set factionIds; public Set getFactionIds() { return this.factionIds; } - // TODO: remake private final // default is empty - public Set playerIds; + private final Set playerIds; public Set getPlayerIds() { return this.playerIds; } // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java b/src/com/massivecraft/factions/cmd/CmdFactionsHome.java index 448d7e1d..ef407252 100644 --- a/src/com/massivecraft/factions/cmd/CmdFactionsHome.java +++ b/src/com/massivecraft/factions/cmd/CmdFactionsHome.java @@ -23,6 +23,7 @@ import com.massivecraft.massivecore.mixin.TeleporterException; import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.teleport.Destination; import com.massivecraft.massivecore.teleport.DestinationSimple; +import com.massivecraft.massivecore.util.MUtil; public class CmdFactionsHome extends FactionsCommandHome @@ -119,6 +120,8 @@ public class CmdFactionsHome extends FactionsCommandHome for (Player p : me.getServer().getOnlinePlayers()) { + if (MUtil.isNpc(p)) continue; + if (p == null || !p.isOnline() || p.isDead() || p == me || p.getWorld() != w) continue; diff --git a/src/com/massivecraft/factions/cmd/arg/ARFaction.java b/src/com/massivecraft/factions/cmd/arg/ARFaction.java index 6b87e476..7ef55378 100644 --- a/src/com/massivecraft/factions/cmd/arg/ARFaction.java +++ b/src/com/massivecraft/factions/cmd/arg/ARFaction.java @@ -10,6 +10,7 @@ import org.bukkit.command.CommandSender; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.factions.entity.MPlayerColl; import com.massivecraft.massivecore.CaseInsensitiveComparator; import com.massivecraft.massivecore.MassiveCore; import com.massivecraft.massivecore.MassiveException; @@ -53,7 +54,7 @@ public class ARFaction extends ARAbstract // MPlayer Name Exact String id = IdUtil.getId(str); - MPlayer mplayer = MPlayer.get(id); + MPlayer mplayer = MPlayerColl.get().get(id, false); if (mplayer != null) { return mplayer.getFaction(); diff --git a/src/com/massivecraft/factions/cmd/req/ReqHasFaction.java b/src/com/massivecraft/factions/cmd/req/ReqHasFaction.java index 29587137..d7c285ff 100644 --- a/src/com/massivecraft/factions/cmd/req/ReqHasFaction.java +++ b/src/com/massivecraft/factions/cmd/req/ReqHasFaction.java @@ -5,6 +5,7 @@ import org.bukkit.command.CommandSender; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.massivecore.cmd.MassiveCommand; import com.massivecraft.massivecore.cmd.req.ReqAbstract; +import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.Txt; public class ReqHasFaction extends ReqAbstract @@ -25,7 +26,9 @@ public class ReqHasFaction extends ReqAbstract @Override public boolean apply(CommandSender sender, MassiveCommand command) { - return MPlayer.get(sender).hasFaction(); + if (MUtil.isNpc(sender)) return false; + MPlayer mplayer = MPlayer.get(sender); + return mplayer.hasFaction(); } @Override diff --git a/src/com/massivecraft/factions/cmd/req/ReqHasntFaction.java b/src/com/massivecraft/factions/cmd/req/ReqHasntFaction.java index d802234c..1924cd67 100644 --- a/src/com/massivecraft/factions/cmd/req/ReqHasntFaction.java +++ b/src/com/massivecraft/factions/cmd/req/ReqHasntFaction.java @@ -5,6 +5,7 @@ import org.bukkit.command.CommandSender; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.massivecore.cmd.MassiveCommand; import com.massivecraft.massivecore.cmd.req.ReqAbstract; +import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.Txt; public class ReqHasntFaction extends ReqAbstract @@ -25,7 +26,9 @@ public class ReqHasntFaction extends ReqAbstract @Override public boolean apply(CommandSender sender, MassiveCommand command) { - return !MPlayer.get(sender).hasFaction(); + if (MUtil.isNpc(sender)) return true; + MPlayer mplayer = MPlayer.get(sender); + return !mplayer.hasFaction(); } @Override diff --git a/src/com/massivecraft/factions/cmd/req/ReqRoleIsAtLeast.java b/src/com/massivecraft/factions/cmd/req/ReqRoleIsAtLeast.java index cf9d1e47..c04979b9 100644 --- a/src/com/massivecraft/factions/cmd/req/ReqRoleIsAtLeast.java +++ b/src/com/massivecraft/factions/cmd/req/ReqRoleIsAtLeast.java @@ -6,6 +6,7 @@ import com.massivecraft.factions.Rel; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.massivecore.cmd.MassiveCommand; import com.massivecraft.massivecore.cmd.req.ReqAbstract; +import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.Txt; public class ReqRoleIsAtLeast extends ReqAbstract @@ -33,6 +34,7 @@ public class ReqRoleIsAtLeast extends ReqAbstract @Override public boolean apply(CommandSender sender, MassiveCommand command) { + if (MUtil.isNpc(sender)) return false; MPlayer mplayer = MPlayer.get(sender); return mplayer.getRole().isAtLeast(this.rel); } diff --git a/src/com/massivecraft/factions/engine/EngineChat.java b/src/com/massivecraft/factions/engine/EngineChat.java index 1a507278..bff28e12 100644 --- a/src/com/massivecraft/factions/engine/EngineChat.java +++ b/src/com/massivecraft/factions/engine/EngineChat.java @@ -1,6 +1,7 @@ package com.massivecraft.factions.engine; import org.bukkit.Bukkit; +import org.bukkit.entity.Player; import org.bukkit.event.Event; import org.bukkit.event.EventException; import org.bukkit.event.EventPriority; @@ -14,6 +15,7 @@ import com.massivecraft.factions.chat.ChatFormatter; import com.massivecraft.factions.entity.MConf; import com.massivecraft.massivecore.EngineAbstract; import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat; +import com.massivecraft.massivecore.util.MUtil; public class EngineChat extends EngineAbstract { @@ -104,8 +106,11 @@ public class EngineChat extends EngineAbstract public static void parseTags(AsyncPlayerChatEvent event) { + Player player = event.getPlayer(); + if (MUtil.isNpc(player)) return; + String format = event.getFormat(); - format = ChatFormatter.format(format, event.getPlayer(), null); + format = ChatFormatter.format(format, player, null); event.setFormat(format); } diff --git a/src/com/massivecraft/factions/engine/EngineIdUpdate.java b/src/com/massivecraft/factions/engine/EngineIdUpdate.java deleted file mode 100644 index d20be9a8..00000000 --- a/src/com/massivecraft/factions/engine/EngineIdUpdate.java +++ /dev/null @@ -1,112 +0,0 @@ -package com.massivecraft.factions.engine; - -import java.util.Set; - -import org.bukkit.event.EventHandler; -import org.bukkit.event.EventPriority; -import org.bukkit.plugin.Plugin; - -import com.massivecraft.factions.Factions; -import com.massivecraft.factions.TerritoryAccess; -import com.massivecraft.factions.entity.Board; -import com.massivecraft.factions.entity.BoardColl; -import com.massivecraft.factions.entity.Faction; -import com.massivecraft.factions.entity.FactionColl; -import com.massivecraft.factions.entity.MPlayerColl; -import com.massivecraft.massivecore.EngineAbstract; -import com.massivecraft.massivecore.event.EventMassiveCoreUuidUpdate; -import com.massivecraft.massivecore.util.IdUpdateUtil; -import com.massivecraft.massivecore.util.MUtil; - -public class EngineIdUpdate extends EngineAbstract -{ - // -------------------------------------------- // - // INSTANCE & CONSTRUCT - // -------------------------------------------- // - - private static EngineIdUpdate i = new EngineIdUpdate(); - public static EngineIdUpdate get() { return i; } - - // -------------------------------------------- // - // OVERRIDE - // -------------------------------------------- // - - @Override - public Plugin getPlugin() - { - return Factions.get(); - } - - // -------------------------------------------- // - // LISTENER - // -------------------------------------------- // - - @EventHandler(priority = EventPriority.MONITOR) - public void update(EventMassiveCoreUuidUpdate event) - { - for (Faction entity : FactionColl.get().getAll()) - { - update(entity); - } - - IdUpdateUtil.update(MPlayerColl.get()); - - update(BoardColl.get()); - } - - public static void update(Faction entity) - { - // Before and After - Set before = entity.getInvitedPlayerIds(); - if (before == null) return; - Set after = IdUpdateUtil.update(before, true); - if (after == null) return; - - // NoChange - if (MUtil.equals(before, after)) return; - - // Apply - entity.setInvitedPlayerIds(after); - entity.sync(); - } - - public static void update(BoardColl coll) - { - for (Board board : coll.getAll()) - { - update(board); - } - } - - public static void update(Board board) - { - boolean changed = false; - for (TerritoryAccess ta : board.getMap().values()) - { - changed |= update(ta); - } - if (changed) - { - board.changed(); - board.sync(); - } - } - - public static boolean update(TerritoryAccess entity) - { - // Before and After - Set before = entity.playerIds; - if (before == null) return false; - Set after = IdUpdateUtil.update(before, true); - if (after == null) return false; - - // NoChange - if (MUtil.equals(before, after)) return false; - - // Apply - entity.playerIds = after; - //entity.sync(); - return true; - } - -} diff --git a/src/com/massivecraft/factions/engine/EngineMain.java b/src/com/massivecraft/factions/engine/EngineMain.java index b59b5a9f..f2f379eb 100644 --- a/src/com/massivecraft/factions/engine/EngineMain.java +++ b/src/com/massivecraft/factions/engine/EngineMain.java @@ -345,6 +345,7 @@ public class EngineMain extends EngineAbstract public static void updateLastActivity(CommandSender sender) { if (sender == null) throw new RuntimeException("sender"); + if (MUtil.isNpc(sender)) return; MPlayer mplayer = MPlayer.get(sender); mplayer.setLastActivityMillis(); } @@ -389,6 +390,7 @@ public class EngineMain extends EngineAbstract { // Gather info ... final Player player = event.getPlayer(); + if (MUtil.isNpc(player)) return; final MPlayer mplayer = MPlayer.get(player); final Faction faction = mplayer.getFaction(); @@ -662,6 +664,7 @@ public class EngineMain extends EngineAbstract // If the player is moving from one chunk to another ... if (MUtil.isSameChunk(event)) return; Player player = event.getPlayer(); + if (MUtil.isNpc(player)) return; // ... gather info on the player and the move ... MPlayer mplayer = MPlayer.get(player); @@ -769,6 +772,7 @@ public class EngineMain extends EngineAbstract { // If a player dies ... Player player = event.getEntity(); + if (MUtil.isNpc(player)) return; // ... and this is the first death event this tick ... // (yeah other plugins can case death event to fire twice the same tick) @@ -870,6 +874,7 @@ public class EngineMain extends EngineAbstract Entity edefender = event.getEntity(); if (!(edefender instanceof Player)) return true; Player defender = (Player)edefender; + if (MUtil.isNpc(defender)) return true; MPlayer mdefender = MPlayer.get(edefender); // ... and the attacker is someone else ... @@ -992,6 +997,7 @@ public class EngineMain extends EngineAbstract Entity entity = event.getEntity(); if (!(entity instanceof Player)) return; Player player = (Player)entity; + if (MUtil.isNpc(player)) return; MPlayer mplayer = MPlayer.get(player); // ... and that player has a faction ... @@ -1063,7 +1069,7 @@ public class EngineMain extends EngineAbstract { // If a player is trying to run a command ... Player player = event.getPlayer(); - + if (MUtil.isNpc(player)) return; MPlayer mplayer = MPlayer.get(player); // ... and the player does not have adminmode ... @@ -1488,6 +1494,8 @@ public class EngineMain extends EngineAbstract public static boolean playerCanUseItemHere(Player player, PS ps, Material material, boolean verboose) { + if (MUtil.isNpc(player)) return true; + if ( ! MConf.get().materialsEditTools.contains(material) && ! MConf.get().materialsEditToolsDupeBug.contains(material)) return true; String name = player.getName(); @@ -1501,6 +1509,8 @@ public class EngineMain extends EngineAbstract public static boolean canPlayerUseBlock(Player player, Block block, boolean verboose) { + if (MUtil.isNpc(player)) return true; + String name = player.getName(); if (MConf.get().playersWhoBypassAllProtection.contains(name)) return true; @@ -1539,6 +1549,7 @@ public class EngineMain extends EngineAbstract { // If a player ... if (player == null) return true; + if (MUtil.isNpc(player)) return true; // ... interacts with an entity ... if (entity == null) return true; @@ -1595,6 +1606,7 @@ public class EngineMain extends EngineAbstract { // If a player is respawning ... final Player player = event.getPlayer(); + if (MUtil.isNpc(player)) return; final MPlayer mplayer = MPlayer.get(player); // ... homes are enabled, active and at this priority ... diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index b0207c22..1d09947c 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -1077,6 +1077,7 @@ public class Faction extends Entity implements EconomyParticipator List ret = new ArrayList(); for (CommandSender player : IdUtil.getOnlineSenders()) { + if (MUtil.isNpc(player)) continue; MPlayer mplayer = MPlayer.get(player); if (mplayer.getFaction() != this) continue; ret.add(player); @@ -1089,6 +1090,7 @@ public class Faction extends Entity implements EconomyParticipator List ret = new ArrayList(); for (Player player : MUtil.getOnlinePlayers()) { + if (MUtil.isNpc(player)) continue; MPlayer mplayer = MPlayer.get(player); if (mplayer.getFaction() != this) continue; ret.add(player); diff --git a/src/com/massivecraft/factions/spigot/EngineSpigot.java b/src/com/massivecraft/factions/spigot/EngineSpigot.java index 0439c31d..fb925cda 100644 --- a/src/com/massivecraft/factions/spigot/EngineSpigot.java +++ b/src/com/massivecraft/factions/spigot/EngineSpigot.java @@ -21,6 +21,7 @@ import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MPerm; import com.massivecraft.massivecore.EngineAbstract; import com.massivecraft.massivecore.ps.PS; +import com.massivecraft.massivecore.util.MUtil; public class EngineSpigot extends EngineAbstract @@ -70,6 +71,7 @@ public class EngineSpigot extends EngineAbstract { // Gather Info final Player player = event.getPlayer(); + if (MUtil.isNpc(player)) return; final Entity entity = event.getRightClicked(); final boolean verboose = true; diff --git a/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java b/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java index 940fc6b0..5d628f3a 100644 --- a/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java +++ b/src/com/massivecraft/factions/task/TaskPlayerPowerUpdate.java @@ -50,6 +50,7 @@ public class TaskPlayerPowerUpdate extends ModuloRepeatTask for (Player player : MUtil.getOnlinePlayers()) { + if (MUtil.isNpc(player)) continue; if (player.isDead()) continue; MPlayer mplayer = MPlayer.get(player);