mirror of
https://github.com/plan-player-analytics/Plan.git
synced 2024-12-21 05:50:18 +08:00
parent
d05a887878
commit
f32cf95fc1
@ -22,6 +22,7 @@ import com.djrapitops.plan.storage.database.DBSystem;
|
|||||||
import com.djrapitops.plan.utilities.java.Reflection;
|
import com.djrapitops.plan.utilities.java.Reflection;
|
||||||
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
import com.djrapitops.plan.utilities.logging.ErrorLogger;
|
||||||
import net.playeranalytics.plugin.server.PluginLogger;
|
import net.playeranalytics.plugin.server.PluginLogger;
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
@ -46,19 +47,49 @@ public class BukkitServerShutdownSave extends ServerShutdownSave {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean checkServerShuttingDownStatus() {
|
protected boolean checkServerShuttingDownStatus() {
|
||||||
|
return isStoppedBefore1p17() || isStoppedV1p17() || isStoppedAfterV1p17();
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isStoppedBefore1p17() {
|
||||||
try {
|
try {
|
||||||
return performCheck();
|
// Special thanks to Fuzzlemann for figuring out the methods required for this check.
|
||||||
|
// https://github.com/plan-player-analytics/Plan/issues/769#issuecomment-433898242
|
||||||
|
Class<?> minecraftServerClass = Reflection.getMinecraftClass("MinecraftServer");
|
||||||
|
Object minecraftServer = Reflection.getField(minecraftServerClass, "SERVER", minecraftServerClass).get(null);
|
||||||
|
|
||||||
|
return Reflection.getField(minecraftServerClass, "isStopped", boolean.class).get(minecraftServer);
|
||||||
} catch (Exception | NoClassDefFoundError | NoSuchFieldError e) {
|
} catch (Exception | NoClassDefFoundError | NoSuchFieldError e) {
|
||||||
return false; // ShutdownHook handles save in case this fails upon plugin disable.
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean performCheck() {
|
private boolean isStoppedV1p17() {
|
||||||
// Special thanks to Fuzzlemann for figuring out the methods required for this check.
|
try {
|
||||||
// https://github.com/plan-player-analytics/Plan/issues/769#issuecomment-433898242
|
// Special thanks to Fuzzlemann for figuring out the methods required for this check.
|
||||||
Class<?> minecraftServerClass = Reflection.getMinecraftClass("MinecraftServer");
|
// https://github.com/plan-player-analytics/Plan/issues/769#issuecomment-433898242
|
||||||
Object minecraftServer = Reflection.getField(minecraftServerClass, "SERVER", minecraftServerClass).get(null);
|
Class<?> minecraftServerClass = Class.forName("net.minecraft.server.MinecraftServer");
|
||||||
|
Class<?> craftServerClass = Reflection.getCraftBukkitClass("CraftServer");
|
||||||
|
Object minecraftServer = Reflection.getField(craftServerClass, "console", minecraftServerClass).get(Bukkit.getServer());
|
||||||
|
|
||||||
return Reflection.getField(minecraftServerClass, "isStopped", boolean.class).get(minecraftServer);
|
return (Boolean) minecraftServerClass.getMethod("isStopped").invoke(minecraftServer);
|
||||||
|
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isStoppedAfterV1p17() {
|
||||||
|
try {
|
||||||
|
// Special thanks to Fuzzlemann for figuring out the methods required for this check.
|
||||||
|
// https://github.com/plan-player-analytics/Plan/issues/769#issuecomment-433898242
|
||||||
|
Class<?> minecraftServerClass = Reflection.getMinecraftClass("MinecraftServer");
|
||||||
|
Class<?> craftServerClass = Reflection.getCraftBukkitClass("CraftServer");
|
||||||
|
Object minecraftServer = Reflection.getField(craftServerClass, "console", minecraftServerClass).get(Bukkit.getServer());
|
||||||
|
|
||||||
|
return (Boolean) minecraftServerClass.getMethod("isStopped").invoke(minecraftServer);
|
||||||
|
} catch (Exception | NoClassDefFoundError | NoSuchFieldError | NoSuchMethodError e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user