SteamWar/SpigotCore
Archiviert
13
0

Add versionDependantCall, See #144 BauSystem

Dieser Commit ist enthalten in:
jojo 2020-12-24 12:04:50 +01:00
Ursprung dc92ce6fda
Commit 8468d9a13e
2 geänderte Dateien mit 75 neuen und 0 gelöschten Zeilen

Datei anzeigen

@ -28,6 +28,10 @@ import de.steamwar.sql.SQL;
import org.bukkit.Bukkit;
import org.bukkit.plugin.java.JavaPlugin;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.logging.Logger;
public class Core extends JavaPlugin{
private static Core instance;
@ -82,4 +86,69 @@ public class Core extends JavaPlugin{
private static void setInstance(Core instance) {
Core.instance = instance;
}
public static void versionDependantCall(Runnable v12, Runnable v15) {
switch (getVersion()) {
case 12:
v12.run();
break;
case 15:
default:
v15.run();
break;
}
}
public static <T> T versionDependantCall(ExceptionlessCallable<T> v12, ExceptionlessCallable<T> v15) {
switch (getVersion()) {
case 12:
return v12.call();
case 15:
default:
return v15.call();
}
}
public static void versionDependantCall(Runnable v8, Runnable v9, Runnable v10, Runnable v12, Runnable v14, Runnable v15) {
switch (Core.getVersion()) {
case 8:
v8.run();
break;
case 9:
v9.run();
break;
case 10:
v10.run();
break;
case 12:
v12.run();
break;
case 14:
v14.run();
break;
case 15:
default:
v15.run();
break;
}
}
public static <T> T versionDependantCall(ExceptionlessCallable<T> v8, ExceptionlessCallable<T> v9, ExceptionlessCallable<T> v10, ExceptionlessCallable<T> v12, ExceptionlessCallable<T> v14, ExceptionlessCallable<T> v15) {
switch (Core.getVersion()) {
case 8:
return v8.call();
case 9:
return v9.call();
case 10:
return v10.call();
case 12:
return v12.call();
case 14:
return v14.call();
case 15:
default:
return v15.call();
}
}
}

Datei anzeigen

@ -0,0 +1,6 @@
package de.steamwar.core;
@FunctionalInterface
public interface ExceptionlessCallable<T> {
T call();
}