Changed the way LWC is loaded (if available)

This commit is contained in:
Eric 2016-06-03 14:42:48 +02:00
parent 380705fe29
commit 3ff0b4c556
3 changed files with 41 additions and 41 deletions

View File

@ -1,9 +1,5 @@
package de.epiceric.shopchest; 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.config.Config;
import de.epiceric.shopchest.event.*; import de.epiceric.shopchest.event.*;
import de.epiceric.shopchest.interfaces.JsonBuilder; import de.epiceric.shopchest.interfaces.JsonBuilder;
@ -26,7 +22,6 @@ import net.milkbowl.vault.permission.Permission;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.RegisteredServiceProvider; import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.plugin.java.JavaPlugin;
@ -39,8 +34,8 @@ public class ShopChest extends JavaPlugin {
public static Logger logger; public static Logger logger;
public static Economy econ = null; public static Economy econ = null;
public static Permission perm = null; public static Permission perm = null;
public static LWC lwc = null;
public static boolean lockette = false; public static boolean lockette = false;
public static boolean lwc = false;
public static Database database; public static Database database;
public static boolean isUpdateNeeded = false; public static boolean isUpdateNeeded = false;
public static String latestVersion = ""; public static String latestVersion = "";
@ -158,18 +153,8 @@ public class ShopChest extends JavaPlugin {
return; return;
} }
if (getServer().getPluginManager().getPlugin("LWC") != null) { lockette = getServer().getPluginManager().getPlugin("Lockette") != null;
Plugin lwcp = getServer().getPluginManager().getPlugin("LWC"); lwc = getServer().getPluginManager().getPlugin("LWC") != null;
lwc = ((LWCPlugin) lwcp).getLWC();
} else {
lwc = null;
}
if (getServer().getPluginManager().getPlugin("Lockette") != null) {
lockette = true;
} else {
lockette = false;
}
setupPermissions(); setupPermissions();
@ -257,26 +242,8 @@ public class ShopChest extends JavaPlugin {
if (getServer().getPluginManager().getPlugin("ClearLag") != null) if (getServer().getPluginManager().getPlugin("ClearLag") != null)
getServer().getPluginManager().registerEvents(new RegenerateShopItemAfterRemove(), this); getServer().getPluginManager().registerEvents(new RegenerateShopItemAfterRemove(), this);
if (getServer().getPluginManager().getPlugin("LWC") != null){ if (getServer().getPluginManager().getPlugin("LWC") != null)
try { new LWCMagnetListener().initializeListener();
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.");
};
}
} }
@Override @Override

View File

@ -1,5 +1,6 @@
package de.epiceric.shopchest.event; package de.epiceric.shopchest.event;
import com.griefcraft.lwc.LWC;
import com.griefcraft.model.Protection; import com.griefcraft.model.Protection;
import de.epiceric.shopchest.ShopChest; import de.epiceric.shopchest.ShopChest;
import de.epiceric.shopchest.config.Config; import de.epiceric.shopchest.config.Config;
@ -72,9 +73,9 @@ public class InteractShop implements Listener {
} }
} }
if (ShopChest.lwc != null) { if (ShopChest.lwc) {
if (ShopChest.lwc.getPhysicalDatabase().loadProtection(b.getLocation().getWorld().getName(), b.getX(), b.getY(), b.getZ()) != null) { if (LWC.getInstance().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()); Protection protection = LWC.getInstance().getPhysicalDatabase().loadProtection(b.getLocation().getWorld().getName(), b.getX(), b.getY(), b.getZ());
if (!protection.isOwner(p) || !protection.isRealOwner(p)) { if (!protection.isOwner(p) || !protection.isRealOwner(p)) {
ClickType.removePlayerClickType(p); ClickType.removePlayerClickType(p);
break; break;

View File

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