Add functionality constants

This commit is contained in:
Mariell Hoversholm committed 2020-09-05 16:22:38 +02:00
1 parent 73d75a5fe7
commit 52a42a1a2b
2 files changed
+51 -24

No files matched your search

@@ -0,0 +1,25 @@
package net.draycia.carbon.util;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.ItemStack;
import org.checkerframework.checker.nullness.qual.NonNull;
@SuppressWarnings("ResultOfMethodCallIgnored") // This is a common pattern in this class.
public final class FunctionalityConstants {
public static final boolean HAS_HOVER_EVENT_METHOD = noThrow(() -> ItemFactory.class.getMethod("hoverContentOf", ItemStack.class));
private static boolean noThrow(@NonNull ThrowingRunnable runnable) {
try {
runnable.run();
return true;
} catch (Exception ex) {
return false;
}
}
@FunctionalInterface
private interface ThrowingRunnable {
void run() throws Exception;
}
}