SteamWar/SpigotCore
Archiviert
13
0

Merge pull request 'Reduce checkpoint exceptions, use "new" Reflection utils in CommandRemover' (#256) from reduceCheckpointExceptions into master
Alle Prüfungen waren erfolgreich
SteamWarCI Build successful

Reviewed-on: #256
Reviewed-by: YoyoNow <jwsteam@nidido.de>
Dieser Commit ist enthalten in:
Lixfel 2024-01-24 11:57:24 +01:00
Commit b4ba508cec
2 geänderte Dateien mit 19 neuen und 31 gelöschten Zeilen

Datei anzeigen

@ -69,8 +69,17 @@ public class CheckpointUtils {
try {
freezeInternal(path);
} catch (Exception e) {
String message = e.getMessage() != null ? e.getMessage() : "";
if(message.contains("Connected TCP socket")) {
Core.getInstance().getLogger().log(Level.INFO, "Connected TCP socket, waiting for checkpointing");
Bukkit.getScheduler().runTaskLater(Core.getInstance(), CheckpointUtils::freeze, 1);
return;
}
Bukkit.shutdown();
throw new SecurityException(e);
if(message.contains("Can't dump ghost file")) // File/Jar has been updated
throw new SecurityException(e);
} finally {
// Delete checkpoint
try (Stream<Path> stream = Files.walk(path)) {
@ -109,8 +118,6 @@ public class CheckpointUtils {
try {
criu.checkpointJVM();
} catch (JVMCRIUException e) {
Bukkit.shutdown();
Path logfile = path.resolve("criu.log");
if(logfile.toFile().exists())
throw new IllegalStateException("Could not create checkpoint, criu log:\n" + new String(Files.readAllBytes(logfile)), e);

Datei anzeigen

@ -19,41 +19,22 @@
package de.steamwar.core;
import com.comphenix.tinyprotocol.Reflection;
import lombok.experimental.UtilityClass;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.SimpleCommandMap;
import java.lang.reflect.Field;
import java.util.Map;
import java.util.logging.Level;
@UtilityClass
public class CommandRemover {
private CommandRemover(){}
private static String packageName = Bukkit.getServer().getClass().getPackage().getName();
private static String version = packageName.substring(packageName.lastIndexOf('.') + 1);
public static void removeAll(String... cmds){
for (String cmd : cmds) removeCommand(cmd);
}
private static void removeCommand(String command) {
try {
Class<?> serverClass = Class.forName("org.bukkit.craftbukkit." + version + ".CraftServer");
Field f1 = serverClass.getDeclaredField("commandMap");
f1.setAccessible(true);
SimpleCommandMap commandMap = (SimpleCommandMap) f1.get(Bukkit.getServer());
Field f2 = SimpleCommandMap.class.getDeclaredField("knownCommands");
f2.setAccessible(true);
Map<String, Command> knownCommands = (Map<String, Command>) f2.get(commandMap);
knownCommands.remove(command.toLowerCase());
} catch (Exception e) {
Bukkit.getLogger().log(Level.SEVERE, "Could not remove command", e);
private static final Reflection.FieldAccessor<SimpleCommandMap> commandMap = Reflection.getField("{obc}.CraftServer", "commandMap", SimpleCommandMap.class);
private static final Reflection.FieldAccessor<Map> knownCommands = Reflection.getField(SimpleCommandMap.class, "knownCommands", Map.class);
public static void removeAll(String... cmds) {
Map<String, Command> knownCmds = knownCommands.get(commandMap.get(Bukkit.getServer()));
for (String cmd : cmds) {
knownCmds.remove(cmd.toLowerCase());
}
}
}