1
mirror of https://github.com/StarWishsama/Slimefun4.git synced 2024-09-20 03:35:51 +00:00

Small improvements to logging

This commit is contained in:
TheBusyBiscuit 2021-03-01 13:55:57 +01:00
parent 5b86755e99
commit 15f4e838a8
2 changed files with 40 additions and 2 deletions

View File

@ -4,7 +4,9 @@ import java.util.function.Consumer;
import java.util.logging.Level; import java.util.logging.Level;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import org.bukkit.Bukkit;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Server; import org.bukkit.Server;
import org.bukkit.block.Block; 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. * 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. * If that {@link Plugin} is installed and enabled, the provided callback will be run.
@ -220,7 +246,15 @@ public class IntegrationsManager {
*/ */
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
public boolean isCustomBlock(@Nonnull Block block) { 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() { public boolean isPlaceholderAPIInstalled() {

View File

@ -36,7 +36,11 @@ class McMMOIntegration implements Listener {
@EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true)
public void onBlockPlacerPlace(BlockPlacerPlaceEvent e) { public void onBlockPlacerPlace(BlockPlacerPlaceEvent e) {
// This registers blocks placed by the BlockPlacer as "player-placed" // 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) @EventHandler(ignoreCancelled = true)