From 15f4e838a892e9687e4faab276c827ab402abcb6 Mon Sep 17 00:00:00 2001 From: TheBusyBiscuit Date: Mon, 1 Mar 2021 13:55:57 +0100 Subject: [PATCH] Small improvements to logging --- .../integrations/IntegrationsManager.java | 36 ++++++++++++++++++- .../integrations/McMMOIntegration.java | 6 +++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java index 92ef1ec56..794751805 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/IntegrationsManager.java @@ -4,7 +4,9 @@ import java.util.function.Consumer; import java.util.logging.Level; import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Server; import org.bukkit.block.Block; @@ -158,6 +160,30 @@ public class IntegrationsManager { } } + /** + * This method logs a {@link Throwable} that was caused by a {@link Plugin} + * we integrate into. + * Calling this method will probably log the error and provide the version of this {@link Plugin} + * for error analysis. + * + * @param name + * The name of the {@link Plugin} + * @param throwable + * The {@link Throwable} to throw + */ + @ParametersAreNonnullByDefault + protected void logError(String name, Throwable throwable) { + Plugin externalPlugin = Bukkit.getPluginManager().getPlugin(name); + + if (externalPlugin != null) { + String version = externalPlugin.getDescription().getVersion(); + SlimefunPlugin.logger().log(Level.WARNING, "Is {0} v{1} up to date?", new Object[] { name, version }); + SlimefunPlugin.logger().log(Level.SEVERE, throwable, () -> "An unknown error was detected while interacting with \"" + name + " v" + version + "\""); + } else { + SlimefunPlugin.logger().log(Level.SEVERE, throwable, () -> "An unknown error was detected while interacting with the plugin \"" + name + "\""); + } + } + /** * This method loads an integration with a {@link Plugin} of the specified name. * If that {@link Plugin} is installed and enabled, the provided callback will be run. @@ -220,7 +246,15 @@ public class IntegrationsManager { */ @SuppressWarnings("deprecation") public boolean isCustomBlock(@Nonnull Block block) { - return isItemsAdderInstalled && ItemsAdder.isCustomBlock(block); + if (isItemsAdderInstalled) { + try { + return ItemsAdder.isCustomBlock(block); + } catch (Exception | LinkageError x) { + logError("ItemsAdder", x); + } + } + + return false; } public boolean isPlaceholderAPIInstalled() { diff --git a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/McMMOIntegration.java b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/McMMOIntegration.java index 722864a0f..2f82b935f 100644 --- a/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/McMMOIntegration.java +++ b/src/main/java/io/github/thebusybiscuit/slimefun4/integrations/McMMOIntegration.java @@ -36,7 +36,11 @@ class McMMOIntegration implements Listener { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onBlockPlacerPlace(BlockPlacerPlaceEvent e) { // This registers blocks placed by the BlockPlacer as "player-placed" - mcMMO.getPlaceStore().setTrue(e.getBlock()); + try { + mcMMO.getPlaceStore().setTrue(e.getBlock()); + } catch (Exception | LinkageError x) { + SlimefunPlugin.getIntegrations().logError("mcMMO", x); + } } @EventHandler(ignoreCancelled = true)