Improve HookImplementation.disable
This commit is contained in:
parent
bfb03f1286
commit
e041ef890e
|
@ -1,5 +1,5 @@
|
|||
package io.gitlab.jfronny.libjf.interfaces;
|
||||
|
||||
public interface ThrowingRunnable {
|
||||
void run() throws Throwable;
|
||||
public interface ThrowingRunnable<TEx extends Throwable> {
|
||||
void run() throws TEx;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
package io.gitlab.jfronny.libjf.interfaces;
|
||||
|
||||
public interface ThrowingSupplier<T> {
|
||||
T get() throws Throwable;
|
||||
public interface ThrowingSupplier<T, TEx extends Throwable> {
|
||||
T get() throws TEx;
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
package io.gitlab.jfronny.libjf.data.manipulation;
|
||||
|
||||
import io.gitlab.jfronny.libjf.LibJf;
|
||||
import io.gitlab.jfronny.libjf.ResourcePath;
|
||||
import io.gitlab.jfronny.libjf.interfaces.ThrowingRunnable;
|
||||
import io.gitlab.jfronny.libjf.interfaces.ThrowingSupplier;
|
||||
import net.minecraft.resource.ResourcePack;
|
||||
import net.minecraft.resource.ResourceType;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
@ -15,7 +16,7 @@ import java.util.function.Supplier;
|
|||
|
||||
public class HookImplementation {
|
||||
private static boolean disabled = false;
|
||||
public static <T> T disable(Supplier<T> then) {
|
||||
public static <TVal, TEx extends Throwable> TVal disable(ThrowingSupplier<TVal, TEx> then) throws TEx {
|
||||
try {
|
||||
disabled = true;
|
||||
return then.get();
|
||||
|
@ -25,6 +26,23 @@ public class HookImplementation {
|
|||
}
|
||||
}
|
||||
|
||||
public static <TEx extends Throwable> void disable(ThrowingRunnable<TEx> then) throws TEx {
|
||||
try {
|
||||
disabled = true;
|
||||
then.run();
|
||||
} finally {
|
||||
disabled = false;
|
||||
}
|
||||
}
|
||||
public static <T> T disable(Supplier<T> then) {
|
||||
try {
|
||||
disabled = true;
|
||||
return then.get();
|
||||
}
|
||||
finally {
|
||||
disabled = false;
|
||||
}
|
||||
}
|
||||
public static void disable(Runnable then) {
|
||||
try {
|
||||
disabled = true;
|
||||
|
|
Loading…
Reference in New Issue