Upgraded to EngineAbstract for LWC and made use of the LWC module system.

This commit is contained in:
Olof Larsson 2014-09-17 21:31:41 +02:00
parent 34b166503e
commit cf859f2e61
3 changed files with 56 additions and 21 deletions

View File

@ -3,30 +3,27 @@ package com.massivecraft.factions.integration.lwc;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import org.bukkit.Bukkit;
import org.bukkit.Chunk; import org.bukkit.Chunk;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.HandlerList; import org.bukkit.plugin.Plugin;
import org.bukkit.event.Listener;
import com.griefcraft.lwc.LWC; import com.griefcraft.lwc.LWC;
import com.griefcraft.model.Protection; import com.griefcraft.model.Protection;
import com.griefcraft.scripting.event.LWCProtectionRegisterEvent;
import com.massivecraft.factions.Factions; import com.massivecraft.factions.Factions;
import com.massivecraft.factions.entity.Faction; import com.massivecraft.factions.entity.Faction;
import com.massivecraft.factions.entity.MConf; import com.massivecraft.factions.entity.MConf;
import com.massivecraft.factions.entity.MPlayer; import com.massivecraft.factions.entity.MPlayer;
import com.massivecraft.factions.event.EventFactionsChunkChange; import com.massivecraft.factions.event.EventFactionsChunkChange;
import com.massivecraft.factions.event.EventFactionsChunkChangeType; import com.massivecraft.factions.event.EventFactionsChunkChangeType;
import com.massivecraft.factions.listeners.FactionsListenerMain; import com.massivecraft.massivecore.EngineAbstract;
import com.massivecraft.massivecore.ps.PS; import com.massivecraft.massivecore.ps.PS;
public class EngineLwc implements Listener public class EngineLwc extends EngineAbstract
{ {
// -------------------------------------------- // // -------------------------------------------- //
// INSTANCE & CONSTRUCT // INSTANCE & CONSTRUCT
@ -37,17 +34,13 @@ public class EngineLwc implements Listener
private EngineLwc() {} private EngineLwc() {}
// -------------------------------------------- // // -------------------------------------------- //
// ACTIVATE & DEACTIVATE // OVERRIDE
// -------------------------------------------- // // -------------------------------------------- //
public void activate() @Override
public Plugin getPlugin()
{ {
Bukkit.getPluginManager().registerEvents(this, Factions.get()); return Factions.get();
}
public void deactivate()
{
HandlerList.unregisterAll(this);
} }
// -------------------------------------------- // // -------------------------------------------- //
@ -68,13 +61,6 @@ public class EngineLwc implements Listener
removeAlienProtections(event.getChunk(), newFaction); 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 // UTIL
// -------------------------------------------- // // -------------------------------------------- //
@ -121,4 +107,5 @@ public class EngineLwc implements Listener
return ret; return ret;
} }
} }

View File

@ -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);
}
}

View File

@ -1,5 +1,7 @@
package com.massivecraft.factions.integration.lwc; package com.massivecraft.factions.integration.lwc;
import com.griefcraft.lwc.LWC;
import com.massivecraft.factions.Factions;
import com.massivecraft.massivecore.integration.IntegrationAbstract; import com.massivecraft.massivecore.integration.IntegrationAbstract;
public class IntegrationLwc extends IntegrationAbstract public class IntegrationLwc extends IntegrationAbstract
@ -20,12 +22,16 @@ public class IntegrationLwc extends IntegrationAbstract
public void activate() public void activate()
{ {
EngineLwc.get().activate(); EngineLwc.get().activate();
LWC.getInstance().getModuleLoader().registerModule(Factions.get(), new FactionsLwcModule(Factions.get()));
} }
@Override @Override
public void deactivate() public void deactivate()
{ {
EngineLwc.get().deactivate(); EngineLwc.get().deactivate();
LWC.getInstance().getModuleLoader().removeModules(Factions.get());
} }
} }