From cf859f2e61a105b5c1fbbc570134a4846e06281a Mon Sep 17 00:00:00 2001 From: Olof Larsson Date: Wed, 17 Sep 2014 21:31:41 +0200 Subject: [PATCH] Upgraded to EngineAbstract for LWC and made use of the LWC module system. --- .../factions/integration/lwc/EngineLwc.java | 29 ++++--------- .../integration/lwc/FactionsLwcModule.java | 42 +++++++++++++++++++ .../integration/lwc/IntegrationLwc.java | 6 +++ 3 files changed, 56 insertions(+), 21 deletions(-) create mode 100644 src/main/java/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java diff --git a/src/main/java/com/massivecraft/factions/integration/lwc/EngineLwc.java b/src/main/java/com/massivecraft/factions/integration/lwc/EngineLwc.java index e080450b..f8ca9799 100644 --- a/src/main/java/com/massivecraft/factions/integration/lwc/EngineLwc.java +++ b/src/main/java/com/massivecraft/factions/integration/lwc/EngineLwc.java @@ -3,30 +3,27 @@ package com.massivecraft.factions.integration.lwc; import java.util.ArrayList; import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.Chunk; import org.bukkit.Material; import org.bukkit.block.Block; import org.bukkit.block.BlockState; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; -import org.bukkit.event.HandlerList; -import org.bukkit.event.Listener; +import org.bukkit.plugin.Plugin; import com.griefcraft.lwc.LWC; import com.griefcraft.model.Protection; -import com.griefcraft.scripting.event.LWCProtectionRegisterEvent; import com.massivecraft.factions.Factions; import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.event.EventFactionsChunkChange; import com.massivecraft.factions.event.EventFactionsChunkChangeType; -import com.massivecraft.factions.listeners.FactionsListenerMain; +import com.massivecraft.massivecore.EngineAbstract; import com.massivecraft.massivecore.ps.PS; -public class EngineLwc implements Listener +public class EngineLwc extends EngineAbstract { // -------------------------------------------- // // INSTANCE & CONSTRUCT @@ -37,17 +34,13 @@ public class EngineLwc implements Listener private EngineLwc() {} // -------------------------------------------- // - // ACTIVATE & DEACTIVATE + // OVERRIDE // -------------------------------------------- // - public void activate() + @Override + public Plugin getPlugin() { - Bukkit.getPluginManager().registerEvents(this, Factions.get()); - } - - public void deactivate() - { - HandlerList.unregisterAll(this); + return Factions.get(); } // -------------------------------------------- // @@ -68,13 +61,6 @@ public class EngineLwc implements Listener removeAlienProtections(event.getChunk(), newFaction); } - @EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true) - public void onCreateProtection(LWCProtectionRegisterEvent event) - { - if (FactionsListenerMain.canPlayerBuildAt(event.getPlayer(), PS.valueOf(event.getBlock()), false)) return; - event.setCancelled(true); - } - // -------------------------------------------- // // UTIL // -------------------------------------------- // @@ -121,4 +107,5 @@ public class EngineLwc implements Listener return ret; } + } diff --git a/src/main/java/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java b/src/main/java/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java new file mode 100644 index 00000000..51f270fb --- /dev/null +++ b/src/main/java/com/massivecraft/factions/integration/lwc/FactionsLwcModule.java @@ -0,0 +1,42 @@ +package com.massivecraft.factions.integration.lwc; + +import com.griefcraft.lwc.LWC; +import com.griefcraft.scripting.JavaModule; +import com.griefcraft.scripting.event.LWCProtectionRegisterEvent; +import com.massivecraft.factions.Factions; +import com.massivecraft.factions.listeners.FactionsListenerMain; +import com.massivecraft.massivecore.ps.PS; + +@SuppressWarnings("unused") +public class FactionsLwcModule extends JavaModule +{ + // -------------------------------------------- // + // FIELDS + // -------------------------------------------- // + + // These plugin variables must be present. + // They are set by LWC using reflection somehow. + private Factions plugin; + private LWC lwc; + + // -------------------------------------------- // + // CONSTRUCT + // -------------------------------------------- // + + public FactionsLwcModule(Factions plugin) + { + this.plugin = plugin; + } + + // -------------------------------------------- // + // OVERRIDE + // -------------------------------------------- // + + @Override + public void onRegisterProtection(LWCProtectionRegisterEvent event) + { + if (FactionsListenerMain.canPlayerBuildAt(event.getPlayer(), PS.valueOf(event.getBlock()), false)) return; + event.setCancelled(true); + } + +} diff --git a/src/main/java/com/massivecraft/factions/integration/lwc/IntegrationLwc.java b/src/main/java/com/massivecraft/factions/integration/lwc/IntegrationLwc.java index ac5764c5..a1723874 100644 --- a/src/main/java/com/massivecraft/factions/integration/lwc/IntegrationLwc.java +++ b/src/main/java/com/massivecraft/factions/integration/lwc/IntegrationLwc.java @@ -1,5 +1,7 @@ package com.massivecraft.factions.integration.lwc; +import com.griefcraft.lwc.LWC; +import com.massivecraft.factions.Factions; import com.massivecraft.massivecore.integration.IntegrationAbstract; public class IntegrationLwc extends IntegrationAbstract @@ -20,12 +22,16 @@ public class IntegrationLwc extends IntegrationAbstract public void activate() { EngineLwc.get().activate(); + + LWC.getInstance().getModuleLoader().registerModule(Factions.get(), new FactionsLwcModule(Factions.get())); } @Override public void deactivate() { EngineLwc.get().deactivate(); + + LWC.getInstance().getModuleLoader().removeModules(Factions.get()); } }