diff --git a/src/com/massivecraft/factions/EngineIdUpdate.java b/src/com/massivecraft/factions/EngineIdUpdate.java new file mode 100644 index 00000000..390004b8 --- /dev/null +++ b/src/com/massivecraft/factions/EngineIdUpdate.java @@ -0,0 +1,125 @@ +package com.massivecraft.factions; + +import java.util.Set; + +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.plugin.Plugin; + +import com.massivecraft.factions.entity.Board; +import com.massivecraft.factions.entity.BoardColl; +import com.massivecraft.factions.entity.BoardColls; +import com.massivecraft.factions.entity.Faction; +import com.massivecraft.factions.entity.FactionColl; +import com.massivecraft.factions.entity.FactionColls; +import com.massivecraft.factions.entity.MPlayerColl; +import com.massivecraft.factions.entity.UPlayerColl; +import com.massivecraft.factions.entity.UPlayerColls; +import com.massivecraft.mcore.EngineAbstract; +import com.massivecraft.mcore.event.MCoreUuidUpdateEvent; +import com.massivecraft.mcore.util.IdUpdateUtil; +import com.massivecraft.mcore.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(MCoreUuidUpdateEvent event) + { + for (FactionColl coll : FactionColls.get().getColls()) + { + for (Faction entity : coll.getAll()) + { + update(coll, entity); + } + } + + IdUpdateUtil.update(MPlayerColl.get()); + + for (UPlayerColl coll : UPlayerColls.get().getColls()) + { + IdUpdateUtil.update(coll); + } + + for (BoardColl coll : BoardColls.get().getColls()) + { + update(coll); + } + } + + public static void update(FactionColl coll, 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/Factions.java b/src/com/massivecraft/factions/Factions.java index ce01cc1b..11f23776 100644 --- a/src/com/massivecraft/factions/Factions.java +++ b/src/com/massivecraft/factions/Factions.java @@ -128,6 +128,7 @@ public class Factions extends MPlugin this.outerCmdFactions.register(); // Setup Listeners + EngineIdUpdate.get().activate(); FactionsListenerMain.get().setup(); FactionsListenerChat.get().setup(); FactionsListenerExploit.get().setup(); diff --git a/src/com/massivecraft/factions/TerritoryAccess.java b/src/com/massivecraft/factions/TerritoryAccess.java index 2b435b47..a359466c 100644 --- a/src/com/massivecraft/factions/TerritoryAccess.java +++ b/src/com/massivecraft/factions/TerritoryAccess.java @@ -32,8 +32,9 @@ public class TerritoryAccess private final Set factionIds; public Set getFactionIds() { return this.factionIds; } + // TODO: remate private final // default is empty - private final Set playerIds; + public Set playerIds; public Set getPlayerIds() { return this.playerIds; } // -------------------------------------------- // diff --git a/src/com/massivecraft/factions/cmd/arg/ARFaction.java b/src/com/massivecraft/factions/cmd/arg/ARFaction.java index 119bbb2f..cbe9860a 100644 --- a/src/com/massivecraft/factions/cmd/arg/ARFaction.java +++ b/src/com/massivecraft/factions/cmd/arg/ARFaction.java @@ -9,6 +9,7 @@ import com.massivecraft.factions.entity.FactionColl; import com.massivecraft.factions.entity.FactionColls; import com.massivecraft.mcore.cmd.arg.ArgReaderAbstract; import com.massivecraft.mcore.cmd.arg.ArgResult; +import com.massivecraft.mcore.util.IdUtil; import com.massivecraft.mcore.util.Txt; public class ARFaction extends ArgReaderAbstract @@ -48,7 +49,8 @@ public class ARFaction extends ArgReaderAbstract if (result.hasResult()) return result; // UPlayer Name Exact - UPlayer uplayer = UPlayerColls.get().get(this.getColl()).get(str); + String id = IdUtil.getId(str); + UPlayer uplayer = UPlayerColls.get().get(this.getColl()).get(id); if (uplayer != null) { result.setResult(uplayer.getFaction()); diff --git a/src/com/massivecraft/factions/entity/Faction.java b/src/com/massivecraft/factions/entity/Faction.java index d8b36da0..62fb7436 100644 --- a/src/com/massivecraft/factions/entity/Faction.java +++ b/src/com/massivecraft/factions/entity/Faction.java @@ -21,8 +21,8 @@ import com.massivecraft.mcore.mixin.Mixin; import com.massivecraft.mcore.money.Money; import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.store.Entity; +import com.massivecraft.mcore.util.IdUtil; import com.massivecraft.mcore.util.MUtil; -import com.massivecraft.mcore.util.SenderUtil; import com.massivecraft.mcore.util.Txt; public class Faction extends Entity implements EconomyParticipator @@ -931,7 +931,7 @@ public class Faction extends Entity implements EconomyParticipator public List getOnlineCommandSenders() { List ret = new ArrayList(); - for (CommandSender player : SenderUtil.getOnlineSenders()) + for (CommandSender player : IdUtil.getOnlineSenders()) { UPlayer uplayer = UPlayer.get(player); if (!MUtil.equals(uplayer.getUniverse(), this.getUniverse())) continue; @@ -1050,34 +1050,34 @@ public class Faction extends Entity implements EconomyParticipator public boolean sendMessage(String message) { - return Mixin.message(new FactionEqualsPredictate(this), message); + return Mixin.messagePredictate(new FactionEqualsPredictate(this), message); } public boolean sendMessage(String... messages) { - return Mixin.message(new FactionEqualsPredictate(this), messages); + return Mixin.messagePredictate(new FactionEqualsPredictate(this), messages); } public boolean sendMessage(Collection messages) { - return Mixin.message(new FactionEqualsPredictate(this), messages); + return Mixin.messagePredictate(new FactionEqualsPredictate(this), messages); } // CONVENIENCE MSG public boolean msg(String msg) { - return Mixin.msg(new FactionEqualsPredictate(this), msg); + return Mixin.msgPredictate(new FactionEqualsPredictate(this), msg); } public boolean msg(String msg, Object... args) { - return Mixin.msg(new FactionEqualsPredictate(this), msg, args); + return Mixin.msgPredictate(new FactionEqualsPredictate(this), msg, args); } public boolean msg(Collection msgs) { - return Mixin.msg(new FactionEqualsPredictate(this), msgs); + return Mixin.msgPredictate(new FactionEqualsPredictate(this), msgs); } } diff --git a/src/com/massivecraft/factions/entity/UPlayer.java b/src/com/massivecraft/factions/entity/UPlayer.java index 869f6ae4..56516dde 100644 --- a/src/com/massivecraft/factions/entity/UPlayer.java +++ b/src/com/massivecraft/factions/entity/UPlayer.java @@ -21,8 +21,8 @@ import com.massivecraft.mcore.mixin.Mixin; import com.massivecraft.mcore.ps.PS; import com.massivecraft.mcore.ps.PSFormatHumanSpace; import com.massivecraft.mcore.store.SenderEntity; +import com.massivecraft.mcore.util.IdUtil; import com.massivecraft.mcore.util.MUtil; -import com.massivecraft.mcore.util.SenderUtil; import com.massivecraft.mcore.util.Txt; @@ -74,7 +74,7 @@ public class UPlayer extends SenderEntity implements EconomyParticipato Faction faction = this.getFaction(); faction.uplayers.add(this); - Factions.get().log(Txt.parse("postAttach added %s aka %s to %s aka %s.", id, Mixin.getDisplayName(id), faction.getId(), faction.getName())); + //Factions.get().log(Txt.parse("postAttach added %s aka %s to %s aka %s.", id, Mixin.getDisplayName(id), faction.getId(), faction.getName())); } @Override @@ -87,7 +87,7 @@ public class UPlayer extends SenderEntity implements EconomyParticipato Faction faction = this.getFaction(); faction.uplayers.remove(this); - Factions.get().log(Txt.parse("preDetach removed %s aka %s to %s aka %s.", id, Mixin.getDisplayName(id), faction.getId(), faction.getName())); + //Factions.get().log(Txt.parse("preDetach removed %s aka %s to %s aka %s.", id, Mixin.getDisplayName(id), faction.getId(), faction.getName())); } // -------------------------------------------- // @@ -475,11 +475,6 @@ public class UPlayer extends SenderEntity implements EconomyParticipato // TITLE, NAME, FACTION NAME AND CHAT // -------------------------------------------- // - public String getName() - { - return this.getFixedId(); - } - public String getFactionName() { Faction faction = this.getFaction(); @@ -785,7 +780,7 @@ public class UPlayer extends SenderEntity implements EconomyParticipato } if (MConf.get().logLandClaims) { - informees.add(UPlayer.get(SenderUtil.getConsole())); + informees.add(UPlayer.get(IdUtil.getConsole())); } String chunkString = chunk.toString(PSFormatHumanSpace.get()); diff --git a/src/com/massivecraft/factions/entity/XColls.java b/src/com/massivecraft/factions/entity/XColls.java index 1aaf486a..24f7dad6 100644 --- a/src/com/massivecraft/factions/entity/XColls.java +++ b/src/com/massivecraft/factions/entity/XColls.java @@ -1,12 +1,13 @@ package com.massivecraft.factions.entity; import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import com.massivecraft.mcore.store.Coll; import com.massivecraft.mcore.store.Colls; import com.massivecraft.mcore.store.Entity; import com.massivecraft.mcore.util.MUtil; -import com.massivecraft.mcore.util.SenderUtil; public abstract class XColls, E> extends Colls { @@ -29,7 +30,7 @@ public abstract class XColls, E> extends Colls return this.getForUniverse(universe); } - if (SenderUtil.isNonplayer(o)) + if ((o instanceof CommandSender) && !(o instanceof Player)) { return this.getForWorld(Bukkit.getWorlds().get(0).getName()); } diff --git a/src/com/massivecraft/factions/util/VisualizeUtil.java b/src/com/massivecraft/factions/util/VisualizeUtil.java index d4d23521..0b04287b 100644 --- a/src/com/massivecraft/factions/util/VisualizeUtil.java +++ b/src/com/massivecraft/factions/util/VisualizeUtil.java @@ -6,6 +6,7 @@ import java.util.HashSet; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.UUID; import org.bukkit.Location; import org.bukkit.block.Block; @@ -17,18 +18,18 @@ import org.bukkit.entity.Player; public class VisualizeUtil { - protected static Map> playerLocations = new HashMap>(); + protected static Map> playerLocations = new HashMap>(); public static Set getPlayerLocations(Player player) { - return getPlayerLocations(player.getName()); + return getPlayerLocations(player.getUniqueId()); } - public static Set getPlayerLocations(String playerName) + public static Set getPlayerLocations(UUID uuid) { - Set ret = playerLocations.get(playerName); + Set ret = playerLocations.get(uuid); if (ret == null) { ret = new HashSet(); - playerLocations.put(playerName, ret); + playerLocations.put(uuid, ret); } return ret; }