diff --git a/SpigotCore_Main/src/de/steamwar/core/CheckpointUtils.java b/SpigotCore_Main/src/de/steamwar/core/CheckpointUtils.java index 15d063a..6f0af7f 100644 --- a/SpigotCore_Main/src/de/steamwar/core/CheckpointUtils.java +++ b/SpigotCore_Main/src/de/steamwar/core/CheckpointUtils.java @@ -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 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); diff --git a/SpigotCore_Main/src/de/steamwar/core/CommandRemover.java b/SpigotCore_Main/src/de/steamwar/core/CommandRemover.java index 6543e64..bbce137 100644 --- a/SpigotCore_Main/src/de/steamwar/core/CommandRemover.java +++ b/SpigotCore_Main/src/de/steamwar/core/CommandRemover.java @@ -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 knownCommands = (Map) 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 commandMap = Reflection.getField("{obc}.CraftServer", "commandMap", SimpleCommandMap.class); + private static final Reflection.FieldAccessor knownCommands = Reflection.getField(SimpleCommandMap.class, "knownCommands", Map.class); + public static void removeAll(String... cmds) { + Map knownCmds = knownCommands.get(commandMap.get(Bukkit.getServer())); + for (String cmd : cmds) { + knownCmds.remove(cmd.toLowerCase()); } } }