From f1375ea6994b59459dfd6d34c7f1aa2395ae921b Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 8 Oct 2014 06:38:26 +0200 Subject: [PATCH] Rename and repackage the Engines/Listeners. --- .../com/massivecraft/factions/Factions.java | 26 ++++----- .../EngineChat.java} | 8 +-- .../EngineEcon.java} | 21 +++---- .../EngineExploit.java} | 8 +-- .../EngineMain.java} | 10 ++-- .../factions/engine/EngineSeeChunk.java | 58 +++++++++++++++++++ .../massivecraft/factions/entity/MConf.java | 6 +- .../massivecraft/factions/entity/MPlayer.java | 8 ++- .../integration/lwc/FactionsLwcModule.java | 6 +- 9 files changed, 107 insertions(+), 44 deletions(-) rename src/main/java/com/massivecraft/factions/{listeners/FactionsListenerChat.java => engine/EngineChat.java} (94%) rename src/main/java/com/massivecraft/factions/{listeners/FactionsListenerEcon.java => engine/EngineEcon.java} (92%) rename src/main/java/com/massivecraft/factions/{listeners/FactionsListenerExploit.java => engine/EngineExploit.java} (95%) rename src/main/java/com/massivecraft/factions/{listeners/FactionsListenerMain.java => engine/EngineMain.java} (96%) create mode 100644 src/main/java/com/massivecraft/factions/engine/EngineSeeChunk.java diff --git a/src/main/java/com/massivecraft/factions/Factions.java b/src/main/java/com/massivecraft/factions/Factions.java index 8dd5f8ac..bec03fee 100644 --- a/src/main/java/com/massivecraft/factions/Factions.java +++ b/src/main/java/com/massivecraft/factions/Factions.java @@ -19,6 +19,11 @@ import com.massivecraft.factions.chat.tag.ChatTagNameforce; import com.massivecraft.factions.chat.tag.ChatTagRoleprefixforce; import com.massivecraft.factions.chat.tag.ChatTagTitle; 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.EngineMain; +import com.massivecraft.factions.engine.EngineSeeChunk; import com.massivecraft.factions.entity.Board; import com.massivecraft.factions.entity.BoardColl; import com.massivecraft.factions.entity.Faction; @@ -31,10 +36,6 @@ import com.massivecraft.factions.integration.dynmap.IntegrationDynmap; import com.massivecraft.factions.integration.dynmap.IntegrationDynmapFactions; import com.massivecraft.factions.integration.herochat.IntegrationHerochat; import com.massivecraft.factions.integration.lwc.IntegrationLwc; -import com.massivecraft.factions.listeners.FactionsListenerChat; -import com.massivecraft.factions.listeners.FactionsListenerEcon; -import com.massivecraft.factions.listeners.FactionsListenerExploit; -import com.massivecraft.factions.listeners.FactionsListenerMain; import com.massivecraft.factions.mixin.PowerMixin; import com.massivecraft.factions.mixin.PowerMixinDefault; import com.massivecraft.factions.task.TaskPlayerDataRemove; @@ -134,16 +135,13 @@ public class Factions extends MassivePlugin this.outerCmdFactions = new CmdFactions(); this.outerCmdFactions.register(); - // Setup Listeners - FactionsListenerMain.get().activate(); - FactionsListenerChat.get().activate(); - FactionsListenerExploit.get().activate(); + // Engines + EngineMain.get().activate(); + EngineChat.get().activate(); + EngineExploit.get().activate(); EngineIdUpdate.get().activate(); - - // TODO: This listener is a work in progress. - // The goal is that the Econ integration should be completely based on listening to our own events. - // Right now only a few situations are handled through this listener. - FactionsListenerEcon.get().setup(); + EngineSeeChunk.get().activate(); + EngineEcon.get().activate(); // TODO: Take an extra look and make sure all economy stuff is handled using events. // Integrate this.integrate( @@ -153,7 +151,7 @@ public class Factions extends MassivePlugin IntegrationDynmapFactions.get() ); - // Schedule recurring non-tps-dependent tasks + // Modulo Repeat Tasks TaskPlayerPowerUpdate.get().activate(this); TaskPlayerDataRemove.get().activate(this); TaskEconLandReward.get().activate(this); diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsListenerChat.java b/src/main/java/com/massivecraft/factions/engine/EngineChat.java similarity index 94% rename from src/main/java/com/massivecraft/factions/listeners/FactionsListenerChat.java rename to src/main/java/com/massivecraft/factions/engine/EngineChat.java index 81b6750b..1a507278 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsListenerChat.java +++ b/src/main/java/com/massivecraft/factions/engine/EngineChat.java @@ -1,4 +1,4 @@ -package com.massivecraft.factions.listeners; +package com.massivecraft.factions.engine; import org.bukkit.Bukkit; import org.bukkit.event.Event; @@ -15,14 +15,14 @@ import com.massivecraft.factions.entity.MConf; import com.massivecraft.massivecore.EngineAbstract; import com.massivecraft.massivecore.event.EventMassiveCorePlayerToRecipientChat; -public class FactionsListenerChat extends EngineAbstract +public class EngineChat extends EngineAbstract { // -------------------------------------------- // // INSTANCE & CONSTRUCT // -------------------------------------------- // - private static FactionsListenerChat i = new FactionsListenerChat(); - public static FactionsListenerChat get() { return i; } + private static EngineChat i = new EngineChat(); + public static EngineChat get() { return i; } // -------------------------------------------- // // OVERRIDE diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsListenerEcon.java b/src/main/java/com/massivecraft/factions/engine/EngineEcon.java similarity index 92% rename from src/main/java/com/massivecraft/factions/listeners/FactionsListenerEcon.java rename to src/main/java/com/massivecraft/factions/engine/EngineEcon.java index a2b3f049..f8f082d5 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsListenerEcon.java +++ b/src/main/java/com/massivecraft/factions/engine/EngineEcon.java @@ -1,9 +1,8 @@ -package com.massivecraft.factions.listeners; +package com.massivecraft.factions.engine; -import org.bukkit.Bukkit; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; import com.massivecraft.factions.Factions; import com.massivecraft.factions.entity.Faction; @@ -25,25 +24,27 @@ import com.massivecraft.factions.event.EventFactionsFlagChange; import com.massivecraft.factions.event.EventFactionsRelationChange; import com.massivecraft.factions.event.EventFactionsTitleChange; import com.massivecraft.factions.integration.Econ; +import com.massivecraft.massivecore.EngineAbstract; import com.massivecraft.massivecore.money.Money; -public class FactionsListenerEcon implements Listener +public class EngineEcon extends EngineAbstract { // -------------------------------------------- // // INSTANCE & CONSTRUCT // -------------------------------------------- // - private static FactionsListenerEcon i = new FactionsListenerEcon(); - public static FactionsListenerEcon get() { return i; } - public FactionsListenerEcon() {} + private static EngineEcon i = new EngineEcon(); + public static EngineEcon get() { return i; } + public EngineEcon() {} // -------------------------------------------- // - // SETUP + // OVERRIDE // -------------------------------------------- // - public void setup() + @Override + public Plugin getPlugin() { - Bukkit.getPluginManager().registerEvents(this, Factions.get()); + return Factions.get(); } // -------------------------------------------- // diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsListenerExploit.java b/src/main/java/com/massivecraft/factions/engine/EngineExploit.java similarity index 95% rename from src/main/java/com/massivecraft/factions/listeners/FactionsListenerExploit.java rename to src/main/java/com/massivecraft/factions/engine/EngineExploit.java index 962f3175..740986ca 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsListenerExploit.java +++ b/src/main/java/com/massivecraft/factions/engine/EngineExploit.java @@ -1,4 +1,4 @@ -package com.massivecraft.factions.listeners; +package com.massivecraft.factions.engine; import java.util.ArrayList; import java.util.List; @@ -19,14 +19,14 @@ import com.massivecraft.factions.entity.MConf; import com.massivecraft.massivecore.EngineAbstract; -public class FactionsListenerExploit extends EngineAbstract +public class EngineExploit extends EngineAbstract { // -------------------------------------------- // // INSTANCE & CONSTRUCT // -------------------------------------------- // - private static FactionsListenerExploit i = new FactionsListenerExploit(); - public static FactionsListenerExploit get() { return i; } + private static EngineExploit i = new EngineExploit(); + public static EngineExploit get() { return i; } // -------------------------------------------- // // OVERRIDE diff --git a/src/main/java/com/massivecraft/factions/listeners/FactionsListenerMain.java b/src/main/java/com/massivecraft/factions/engine/EngineMain.java similarity index 96% rename from src/main/java/com/massivecraft/factions/listeners/FactionsListenerMain.java rename to src/main/java/com/massivecraft/factions/engine/EngineMain.java index b4c3d3b5..fc909a8d 100644 --- a/src/main/java/com/massivecraft/factions/listeners/FactionsListenerMain.java +++ b/src/main/java/com/massivecraft/factions/engine/EngineMain.java @@ -1,4 +1,4 @@ -package com.massivecraft.factions.listeners; +package com.massivecraft.factions.engine; import java.text.MessageFormat; import java.util.Collection; @@ -80,15 +80,15 @@ import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.PlayerUtil; import com.massivecraft.massivecore.util.Txt; -public class FactionsListenerMain extends EngineAbstract +public class EngineMain extends EngineAbstract { // -------------------------------------------- // // INSTANCE & CONSTRUCT // -------------------------------------------- // - private static FactionsListenerMain i = new FactionsListenerMain(); - public static FactionsListenerMain get() { return i; } - public FactionsListenerMain() {} + private static EngineMain i = new EngineMain(); + public static EngineMain get() { return i; } + public EngineMain() {} // -------------------------------------------- // // OVERRIDE diff --git a/src/main/java/com/massivecraft/factions/engine/EngineSeeChunk.java b/src/main/java/com/massivecraft/factions/engine/EngineSeeChunk.java new file mode 100644 index 00000000..144ef7c6 --- /dev/null +++ b/src/main/java/com/massivecraft/factions/engine/EngineSeeChunk.java @@ -0,0 +1,58 @@ +package com.massivecraft.factions.engine; + +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.EventPriority; +import org.bukkit.event.player.PlayerChangedWorldEvent; +import org.bukkit.plugin.Plugin; + +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.entity.MPlayer; +import com.massivecraft.massivecore.EngineAbstract; +import com.massivecraft.massivecore.event.EventMassiveCorePlayerLeave; + +public class EngineSeeChunk extends EngineAbstract +{ + // -------------------------------------------- // + // INSTANCE & CONSTRUCT + // -------------------------------------------- // + + private static EngineSeeChunk i = new EngineSeeChunk(); + public static EngineSeeChunk get() { return i; } + public EngineSeeChunk() {} + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public Plugin getPlugin() + { + return Factions.get(); + } + + // -------------------------------------------- // + // LEAVE AND WORLD CHANGE REMOVAL + // -------------------------------------------- // + + public static void leaveAndWorldChangeRemoval(Player player) + { + final MPlayer mplayer = MPlayer.get(player); + mplayer.setSeeingChunk(false); + } + + // Can't be cancelled + @EventHandler(priority = EventPriority.NORMAL) + public void leaveAndWorldChangeRemoval(EventMassiveCorePlayerLeave event) + { + leaveAndWorldChangeRemoval(event.getPlayer()); + } + + // Can't be cancelled + @EventHandler(priority = EventPriority.NORMAL) + public void leaveAndWorldChangeRemoval(PlayerChangedWorldEvent event) + { + leaveAndWorldChangeRemoval(event.getPlayer()); + } + +} diff --git a/src/main/java/com/massivecraft/factions/entity/MConf.java b/src/main/java/com/massivecraft/factions/entity/MConf.java index de31b71d..b19a9ee3 100644 --- a/src/main/java/com/massivecraft/factions/entity/MConf.java +++ b/src/main/java/com/massivecraft/factions/entity/MConf.java @@ -15,9 +15,9 @@ import org.bukkit.event.EventPriority; import com.massivecraft.factions.Factions; import com.massivecraft.factions.Rel; import com.massivecraft.factions.WorldExceptionSet; +import com.massivecraft.factions.engine.EngineChat; import com.massivecraft.factions.event.EventFactionsChunkChangeType; import com.massivecraft.factions.integration.dynmap.DynmapStyle; -import com.massivecraft.factions.listeners.FactionsListenerChat; import com.massivecraft.massivecore.store.Entity; import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.TimeUnit; @@ -42,8 +42,8 @@ public class MConf extends Entity if (!Factions.get().isDatabaseInitialized()) return this; - FactionsListenerChat.get().deactivate(); - FactionsListenerChat.get().activate(); + EngineChat.get().deactivate(); + EngineChat.get().activate(); return this; } diff --git a/src/main/java/com/massivecraft/factions/entity/MPlayer.java b/src/main/java/com/massivecraft/factions/entity/MPlayer.java index 38d3aa28..27b75fdf 100644 --- a/src/main/java/com/massivecraft/factions/entity/MPlayer.java +++ b/src/main/java/com/massivecraft/factions/entity/MPlayer.java @@ -149,12 +149,18 @@ public class MPlayer extends SenderEntity implements EconomyParticipato private Boolean usingAdminMode = null; // The id for the faction this player is currently autoclaiming for. - // NOTE: This field will not be saved to the database ever. // Null means the player isn't auto claiming. + // NOTE: This field will not be saved to the database ever. private transient Faction autoClaimFaction = null; public Faction getAutoClaimFaction() { return this.autoClaimFaction; } public void setAutoClaimFaction(Faction autoClaimFaction) { this.autoClaimFaction = autoClaimFaction; } + // Does the player have /f seechunk activated? + // NOTE: This field will not be saved to the database ever. + private transient boolean seeingChunk = false; + public boolean isSeeingChunk() { return this.seeingChunk; } + public void setSeeingChunk(boolean seeingChunk) { this.seeingChunk = seeingChunk; } + // -------------------------------------------- // // CORE UTILITIES // -------------------------------------------- // diff --git a/src/main/java/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java b/src/main/java/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java index 425ba5fc..2e2036e9 100644 --- a/src/main/java/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java +++ b/src/main/java/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java @@ -11,9 +11,9 @@ import com.griefcraft.scripting.JavaModule; import com.griefcraft.scripting.event.LWCProtectionInteractEvent; import com.griefcraft.scripting.event.LWCProtectionRegisterEvent; import com.massivecraft.factions.Factions; +import com.massivecraft.factions.engine.EngineMain; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MPlayer; -import com.massivecraft.factions.listeners.FactionsListenerMain; import com.massivecraft.massivecore.mixin.Mixin; import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.util.IdUtil; @@ -54,7 +54,7 @@ public class FactionsLwcModule extends JavaModule // ... and the player don't have build rights here ... // NOTE: We verbosely check the build rights so that a proper info message is sent - if (FactionsListenerMain.canPlayerBuildAt(event.getPlayer(), PS.valueOf(event.getBlock()), true)) return; + if (EngineMain.canPlayerBuildAt(event.getPlayer(), PS.valueOf(event.getBlock()), true)) return; // ... then cancel the event. event.setCancelled(true); @@ -79,7 +79,7 @@ public class FactionsLwcModule extends JavaModule // ... and if the protection owner no longer has build rights for the area ... // NOTE: We silently check the build rights for the protection owner. // NOTE: The protection owner may even be offline at the moment. - if (FactionsListenerMain.canPlayerBuildAt(mowner, ps, false)) return; + if (EngineMain.canPlayerBuildAt(mowner, ps, false)) return; // ... remove the protection ... protection.remove();