From 3ff0b4c556746b143a7b3eaf3d3b877dd5ab7caa Mon Sep 17 00:00:00 2001 From: Eric Date: Fri, 3 Jun 2016 14:42:48 +0200 Subject: [PATCH] Changed the way LWC is loaded (if available) --- src/de/epiceric/shopchest/ShopChest.java | 43 +++---------------- .../shopchest/event/InteractShop.java | 7 +-- .../shopchest/event/LWCMagnetListener.java | 32 ++++++++++++++ 3 files changed, 41 insertions(+), 41 deletions(-) create mode 100644 src/de/epiceric/shopchest/event/LWCMagnetListener.java diff --git a/src/de/epiceric/shopchest/ShopChest.java b/src/de/epiceric/shopchest/ShopChest.java index 31869b7..7b42aed 100644 --- a/src/de/epiceric/shopchest/ShopChest.java +++ b/src/de/epiceric/shopchest/ShopChest.java @@ -1,9 +1,5 @@ package de.epiceric.shopchest; -import com.griefcraft.lwc.LWC; -import com.griefcraft.lwc.LWCPlugin; -import com.griefcraft.scripting.JavaModule; -import com.griefcraft.scripting.event.LWCMagnetPullEvent; import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.event.*; import de.epiceric.shopchest.interfaces.JsonBuilder; @@ -26,7 +22,6 @@ import net.milkbowl.vault.permission.Permission; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.entity.Player; -import org.bukkit.plugin.Plugin; import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.java.JavaPlugin; @@ -39,8 +34,8 @@ public class ShopChest extends JavaPlugin { public static Logger logger; public static Economy econ = null; public static Permission perm = null; - public static LWC lwc = null; public static boolean lockette = false; + public static boolean lwc = false; public static Database database; public static boolean isUpdateNeeded = false; public static String latestVersion = ""; @@ -158,18 +153,8 @@ public class ShopChest extends JavaPlugin { return; } - if (getServer().getPluginManager().getPlugin("LWC") != null) { - Plugin lwcp = getServer().getPluginManager().getPlugin("LWC"); - lwc = ((LWCPlugin) lwcp).getLWC(); - } else { - lwc = null; - } - - if (getServer().getPluginManager().getPlugin("Lockette") != null) { - lockette = true; - } else { - lockette = false; - } + lockette = getServer().getPluginManager().getPlugin("Lockette") != null; + lwc = getServer().getPluginManager().getPlugin("LWC") != null; setupPermissions(); @@ -257,26 +242,8 @@ public class ShopChest extends JavaPlugin { if (getServer().getPluginManager().getPlugin("ClearLag") != null) getServer().getPluginManager().registerEvents(new RegenerateShopItemAfterRemove(), this); - if (getServer().getPluginManager().getPlugin("LWC") != null){ - try { - Class.forName("com.griefcraft.scripting.event.LWCMagnetPullEvent"); - - LWC.getInstance().getModuleLoader().registerModule(this, new JavaModule() { - - @Override - public void onMagnetPull(LWCMagnetPullEvent event) { - if (event.getItem().hasMetadata("shopItem")) { - event.setCancelled(true); - } - } - - }); - - } catch (ClassNotFoundException ex) { - getLogger().warning("Shop items can be sucked up by the magnet flag of a protected chest of LWC."); - getLogger().warning("Use 'LWC Unofficial - Entity locking' v1.7.3 or later by 'Me_Goes_RAWR' to prevent this."); - }; - } + if (getServer().getPluginManager().getPlugin("LWC") != null) + new LWCMagnetListener().initializeListener(); } @Override diff --git a/src/de/epiceric/shopchest/event/InteractShop.java b/src/de/epiceric/shopchest/event/InteractShop.java index 382f6ad..a774602 100644 --- a/src/de/epiceric/shopchest/event/InteractShop.java +++ b/src/de/epiceric/shopchest/event/InteractShop.java @@ -1,5 +1,6 @@ package de.epiceric.shopchest.event; +import com.griefcraft.lwc.LWC; import com.griefcraft.model.Protection; import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.config.Config; @@ -72,9 +73,9 @@ public class InteractShop implements Listener { } } - if (ShopChest.lwc != null) { - if (ShopChest.lwc.getPhysicalDatabase().loadProtection(b.getLocation().getWorld().getName(), b.getX(), b.getY(), b.getZ()) != null) { - Protection protection = ShopChest.lwc.getPhysicalDatabase().loadProtection(b.getLocation().getWorld().getName(), b.getX(), b.getY(), b.getZ()); + if (ShopChest.lwc) { + if (LWC.getInstance().getPhysicalDatabase().loadProtection(b.getLocation().getWorld().getName(), b.getX(), b.getY(), b.getZ()) != null) { + Protection protection = LWC.getInstance().getPhysicalDatabase().loadProtection(b.getLocation().getWorld().getName(), b.getX(), b.getY(), b.getZ()); if (!protection.isOwner(p) || !protection.isRealOwner(p)) { ClickType.removePlayerClickType(p); break; diff --git a/src/de/epiceric/shopchest/event/LWCMagnetListener.java b/src/de/epiceric/shopchest/event/LWCMagnetListener.java new file mode 100644 index 0000000..886026b --- /dev/null +++ b/src/de/epiceric/shopchest/event/LWCMagnetListener.java @@ -0,0 +1,32 @@ +package de.epiceric.shopchest.event; + +import com.griefcraft.lwc.LWC; +import com.griefcraft.scripting.JavaModule; +import com.griefcraft.scripting.event.LWCMagnetPullEvent; +import de.epiceric.shopchest.ShopChest; + +public class LWCMagnetListener { + + public void initializeListener() { + try { + Class.forName("com.griefcraft.scripting.event.LWCMagnetPullEvent"); + + LWC.getInstance().getModuleLoader().registerModule(ShopChest.getInstance(), new JavaModule() { + + @Override + public void onMagnetPull(LWCMagnetPullEvent event) { + if (event.getItem().hasMetadata("shopItem")) { + event.setCancelled(true); + } + } + + }); + + } catch (ClassNotFoundException ex) { + ShopChest.logger.warning("Shop items can be sucked up by the magnet flag of a protected chest of LWC."); + ShopChest.logger.warning("Use 'LWC Unofficial - Entity locking' v1.7.3 or later by 'Me_Goes_RAWR' to prevent this."); + }; + } + + +}