diff --git a/config.yml b/config.yml index 615ca2d..c17dca3 100644 --- a/config.yml +++ b/config.yml @@ -194,6 +194,19 @@ cooked: + +# -- Plugin Compatibility -- + +# Enable checking of other Plugins (if installed) for Barrel Permissions [true] +useWorldGuard: true +useLWC: true +useGriefPrevention: true + +# Enable the Logging of Barrel Inventories to LogBlock +useLogBlock: true + + + # -- Chat Distortion Settings -- # Log to the Serverlog what the player actually wrote, before his words were altered [false] diff --git a/plugin.yml b/plugin.yml index f948fab..f6c8ac8 100644 --- a/plugin.yml +++ b/plugin.yml @@ -2,7 +2,7 @@ name: Brewery version: 1.2 main: com.dre.brewery.P authors: [Milan Albrecht, Frank Baumann] -softdepend: [LWC, LogBlock] +softdepend: [LWC, LogBlock, WorldGuard, GriefPrevention] commands: brewery: description: Command for Administration diff --git a/src/com/dre/brewery/Barrel.java b/src/com/dre/brewery/Barrel.java index 749876e..151a2db 100644 --- a/src/com/dre/brewery/Barrel.java +++ b/src/com/dre/brewery/Barrel.java @@ -108,21 +108,41 @@ public class Barrel { } public boolean hasPermsOpen(Player player, PlayerInteractEvent event) { - Plugin plugin = P.p.getServer().getPluginManager().getPlugin("WorldGuard"); - if (plugin != null) { - if (!WGBarrel.checkAccess(player, spigot, plugin)) { - return false; + if (P.p.useWG) { + Plugin plugin = P.p.getServer().getPluginManager().getPlugin("WorldGuard"); + if (plugin != null) { + try { + if (!WGBarrel.checkAccess(player, spigot, plugin)) { + return false; + } + } catch (Exception e) { + P.p.errorLog("Failed to Check WorldGuard for Barrel Open Permissions!"); + P.p.errorLog("Brewery was tested with version 5.8 of WorldGuard!"); + e.printStackTrace(); + P.p.msg(player, "&cError opening Barrel, please report to an Admin!"); + return false; + } } } - if (P.p.getServer().getPluginManager().isPluginEnabled("GriefPrevention")) { - if (!GriefPreventionBarrel.checkAccess(player, spigot)) { - return false; + if (P.p.useGP) { + if (P.p.getServer().getPluginManager().isPluginEnabled("GriefPrevention")) { + try { + if (!GriefPreventionBarrel.checkAccess(player, spigot)) { + return false; + } + } catch (Exception e) { + P.p.errorLog("Failed to Check GriefPrevention for Barrel Open Permissions!"); + P.p.errorLog("Brewery only works with the latest release of GriefPrevention (7.8)"); + e.printStackTrace(); + P.p.msg(player, "&cError opening Barrel, please report to an Admin!"); + return false; + } } } - if (event != null) { - plugin = P.p.getServer().getPluginManager().getPlugin("LWC"); + if (event != null && P.p.useLWC) { + Plugin plugin = P.p.getServer().getPluginManager().getPlugin("LWC"); if (plugin != null) { // If the Clicked Block was the Sign, LWC already knows and we dont need to do anything here @@ -130,7 +150,15 @@ public class Barrel { Block sign = getSignOfSpigot(); // If the Barrel does not have a Sign, it cannot be locked if (!sign.equals(event.getClickedBlock())) { - return LWCBarrel.checkAccess(player, sign, event, plugin); + try { + return LWCBarrel.checkAccess(player, sign, event, plugin); + } catch (Exception e) { + P.p.errorLog("Failed to Check LWC for Barrel Open Permissions!"); + P.p.errorLog("Brewery was tested with version 4.3.1 of LWC!"); + e.printStackTrace(); + P.p.msg(player, "&cError opening Barrel, please report to an Admin!"); + return false; + } } } } @@ -145,8 +173,15 @@ public class Barrel { willDestroy(); return true; } - if (P.p.hasLWC) { - return LWCBarrel.checkDestroy(player, this); + if (P.p.useLWC) { + try { + return LWCBarrel.checkDestroy(player, this); + } catch (Exception e) { + P.p.errorLog("Failed to Check LWC for Barrel Break Permissions!"); + e.printStackTrace(); + P.p.msg(player, "&cError breaking Barrel, please report to an Admin!"); + return false; + } } return true; @@ -154,8 +189,13 @@ public class Barrel { // If something other than the Player is destroying the barrel, inform protection plugins public void willDestroy() { - if (P.p.hasLWC) { - LWCBarrel.remove(this); + if (P.p.useLWC) { + try { + LWCBarrel.remove(this); + } catch (Exception e) { + P.p.errorLog("Failed to Remove LWC Lock from Barrel!"); + e.printStackTrace(); + } } } @@ -194,8 +234,14 @@ public class Barrel { // reset barreltime, potions have new age time = 0; - if (P.p.hasLB) { - LogBlockBarrel.openBarrel(player, inventory, spigot.getLocation()); + if (P.p.useLB) { + try { + LogBlockBarrel.openBarrel(player, inventory, spigot.getLocation()); + } catch (Exception e) { + P.p.errorLog("Failed to Log Barrel to LogBlock!"); + P.p.errorLog("Brewery was tested with version 1.80 of LogBlock!"); + e.printStackTrace(); + } } player.openInventory(inventory); } @@ -369,8 +415,14 @@ public class Barrel { human.closeInventory(); } ItemStack[] items = inventory.getContents(); - if (P.p.hasLB && breaker != null) { - LogBlockBarrel.breakBarrel(breaker.getName(), items, spigot.getLocation()); + if (P.p.useLB && breaker != null) { + try { + LogBlockBarrel.breakBarrel(breaker.getName(), items, spigot.getLocation()); + } catch (Exception e) { + P.p.errorLog("Failed to Log Barrel-break to LogBlock!"); + P.p.errorLog("Brewery was tested with version 1.80 of LogBlock!"); + e.printStackTrace(); + } } for (ItemStack item : items) { if (item != null) { diff --git a/src/com/dre/brewery/ConfigUpdater.java b/src/com/dre/brewery/ConfigUpdater.java index c2eaa8b..6790513 100644 --- a/src/com/dre/brewery/ConfigUpdater.java +++ b/src/com/dre/brewery/ConfigUpdater.java @@ -279,6 +279,39 @@ public class ConfigUpdater { } else { addLines(index, lines); } + + // Add Plugin Support Settings + lines = new String[] { + "", + "", + "# -- Plugin Kompatiblität --", + "", + "# Andere Plugins (wenn installiert) nach Rechten zum öffnen von Fässern checken [true]", + "useWorldGuard: true", + "useLWC: true", + "useGriefPrevention: true", + "", + "# Änderungen an Fassinventaren mit LogBlock aufzeichen", + "useLogBlock: true", + "", + "", + "" + }; + index = indexOfStart("# -- Chat Veränderungs Einstellungen"); + if (index == -1) { + index = indexOfStart("# words"); + } + if (index == -1) { + index = indexOfStart("distortCommands"); + if (index > 4) { + index -= 4; + } + } + if (index != -1) { + addLines(index, lines); + } else { + appendLines(lines); + } } // Updates en from 1.1 to 1.2 @@ -311,6 +344,39 @@ public class ConfigUpdater { } else { addLines(index, lines); } + + // Add Plugin Support Settings + lines = new String[] { + "", + "", + "# -- Plugin Compatibility --", + "", + "# Enable checking of other Plugins (if installed) for Barrel Permissions [true]", + "useWorldGuard: true", + "useLWC: true", + "useGriefPrevention: true", + "", + "# Enable the Logging of Barrel Inventories to LogBlock", + "useLogBlock: true", + "", + "", + "" + }; + index = indexOfStart("# -- Chat Distortion Settings"); + if (index == -1) { + index = indexOfStart("# words"); + } + if (index == -1) { + index = indexOfStart("distortCommands"); + if (index > 4) { + index -= 4; + } + } + if (index != -1) { + addLines(index, lines); + } else { + appendLines(lines); + } } } diff --git a/src/com/dre/brewery/P.java b/src/com/dre/brewery/P.java index 8a19938..431e9f7 100644 --- a/src/com/dre/brewery/P.java +++ b/src/com/dre/brewery/P.java @@ -7,6 +7,7 @@ import java.util.ListIterator; import java.util.HashMap; import java.io.IOException; import java.io.File; +import java.util.logging.Level; import org.bukkit.entity.Player; import org.bukkit.plugin.java.JavaPlugin; @@ -36,8 +37,10 @@ public class P extends JavaPlugin { public static int autosave = 3; // Third Party Enabled - public boolean hasLWC; - public boolean hasLB; + public boolean useWG; //WorldGuard + public boolean useLWC; //LWC + public boolean useLB; //LogBlock + public boolean useGP; //GriefPrevention // Listeners public BlockListener blockListener; @@ -125,8 +128,12 @@ public class P extends JavaPlugin { BIngredients.cookedNames.clear(); Words.words.clear(); BPlayer.drainItems.clear(); - if (hasLB) { - LogBlockBarrel.clear(); + if (useLB) { + try { + LogBlockBarrel.clear(); + } catch (Exception e) { + e.printStackTrace(); + } } // load the Config @@ -163,14 +170,10 @@ public class P extends JavaPlugin { } public void errorLog(String msg) { - Bukkit.getConsoleSender().sendMessage(ChatColor.DARK_GREEN + "[Brewery] " + ChatColor.DARK_RED + "ERROR: " + ChatColor.RED + msg); + Bukkit.getLogger().log(Level.SEVERE, ChatColor.DARK_GREEN + "[Brewery] " + ChatColor.DARK_RED + "ERROR: " + ChatColor.RED + msg); } public void readConfig() { - // Check Third Party - hasLWC = getServer().getPluginManager().isPluginEnabled("LWC"); - hasLB = getServer().getPluginManager().isPluginEnabled("LogBlock"); - File file = new File(p.getDataFolder(), "config.yml"); if (!file.exists()) { saveDefaultConfig(); @@ -194,6 +197,12 @@ public class P extends JavaPlugin { } } + // Third-Party + useWG = config.getBoolean("useWorldGuard", true) && getServer().getPluginManager().isPluginEnabled("WorldGuard"); + useLWC = config.getBoolean("useLWC", true) && getServer().getPluginManager().isPluginEnabled("LWC"); + useGP = config.getBoolean("useGriefPrevention", true) && getServer().getPluginManager().isPluginEnabled("GriefPrevention"); + useLB = config.getBoolean("useLogBlock", false) && getServer().getPluginManager().isPluginEnabled("LogBlock"); + // various Settings autosave = config.getInt("autosave", 3); debug = config.getBoolean("debug", false); diff --git a/src/com/dre/brewery/listeners/EntityListener.java b/src/com/dre/brewery/listeners/EntityListener.java index c834eb4..8099994 100644 --- a/src/com/dre/brewery/listeners/EntityListener.java +++ b/src/com/dre/brewery/listeners/EntityListener.java @@ -58,10 +58,16 @@ public class EntityListener implements Listener { } if (!removedBarrel) { if (barrel != null) { - if (P.p.hasLWC) { - if (LWCBarrel.blockExplosion(barrel, block)) { - iter.remove(); - } else { + if (P.p.useLWC) { + try { + if (LWCBarrel.blockExplosion(barrel, block)) { + iter.remove(); + } else { + removedBarrel = true; + } + } catch (Exception e) { + P.p.errorLog("Failed to Check LWC on Barrel Explosion!"); + e.printStackTrace(); removedBarrel = true; } } diff --git a/src/com/dre/brewery/listeners/InventoryListener.java b/src/com/dre/brewery/listeners/InventoryListener.java index 9a63e5f..ea4cb11 100644 --- a/src/com/dre/brewery/listeners/InventoryListener.java +++ b/src/com/dre/brewery/listeners/InventoryListener.java @@ -95,10 +95,16 @@ public class InventoryListener implements Listener { @EventHandler public void onInventoryClose(InventoryCloseEvent event) { - if (P.p.hasLB) { + if (P.p.useLB) { if (event.getInventory().getType() == InventoryType.CHEST) { if (event.getInventory().getTitle().equals(P.p.languageReader.get("Etc_Barrel"))) { - LogBlockBarrel.closeBarrel(event.getPlayer(), event.getInventory()); + try { + LogBlockBarrel.closeBarrel(event.getPlayer(), event.getInventory()); + } catch (Exception e) { + P.p.errorLog("Failed to Log Barrel to LogBlock!"); + P.p.errorLog("Brewery was tested with version 1.80 of LogBlock!"); + e.printStackTrace(); + } } } }