Support to restart server after update
This commit is contained in:
parent
55d1d750ec
commit
44020ecc25
@ -1795,7 +1795,7 @@
|
||||
{
|
||||
packetbuffer = new PacketBuffer(Unpooled.wrappedBuffer(p_147349_1_.func_149558_e()));
|
||||
@@ -1093,16 +2398,18 @@
|
||||
{
|
||||
|
||||
if (itemstack.getItem() == Items.writable_book && itemstack.getItem() == itemstack1.getItem())
|
||||
{
|
||||
- itemstack1.setTagInfo("pages", itemstack.getTagCompound().getTagList("pages", 8));
|
||||
|
@ -6,11 +6,14 @@ import java.net.URLDecoder;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.spigotmc.RestartCommand;
|
||||
|
||||
public class KCauldron {
|
||||
private static boolean sManifestParsed = false;
|
||||
|
||||
private static void parseManifest() {
|
||||
if (sManifestParsed) return;
|
||||
if (sManifestParsed)
|
||||
return;
|
||||
sManifestParsed = true;
|
||||
|
||||
try {
|
||||
@ -23,7 +26,8 @@ public class KCauldron {
|
||||
String version = manifest.getProperty("KCauldron-Version");
|
||||
if (version != null) {
|
||||
String path = url.getPath();
|
||||
String jarFilePath = path.substring(path.indexOf(":") + 1, path.indexOf("!"));
|
||||
String jarFilePath = path.substring(path.indexOf(":") + 1,
|
||||
path.indexOf("!"));
|
||||
jarFilePath = URLDecoder.decode(jarFilePath, "UTF-8");
|
||||
sServerLocation = new File(jarFilePath);
|
||||
|
||||
@ -70,4 +74,8 @@ public class KCauldron {
|
||||
public static File sNewServerLocation;
|
||||
public static String sNewServerVersion;
|
||||
public static boolean sUpdateInProgress;
|
||||
|
||||
public static void restart() {
|
||||
RestartCommand.restart(true);
|
||||
}
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package kcauldron;
|
||||
|
||||
import static org.objectweb.asm.Opcodes.*;
|
||||
|
||||
import org.apache.logging.log4j.Level;
|
||||
import org.objectweb.asm.ClassReader;
|
||||
import org.objectweb.asm.ClassVisitor;
|
||||
@ -11,19 +13,9 @@ import org.objectweb.asm.tree.InsnList;
|
||||
import org.objectweb.asm.tree.InsnNode;
|
||||
import org.objectweb.asm.tree.IntInsnNode;
|
||||
|
||||
import pw.prok.imagine.api.Pair;
|
||||
import pw.prok.imagine.asm.ImagineASM;
|
||||
import pw.prok.imagine.asm.ImagineMethod;
|
||||
import pw.prok.imagine.asm.ImagineRemapper;
|
||||
import pw.prok.imagine.asm.Transformer;
|
||||
|
||||
import com.avaje.ebean.annotation.Transactional;
|
||||
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
import net.minecraft.launchwrapper.IClassTransformer;
|
||||
import net.minecraft.world.WorldServer;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import static org.objectweb.asm.Opcodes.*;
|
||||
|
||||
@Transformer.RegisterTransformer
|
||||
public class KCauldronClassTransformer implements Transformer {
|
||||
|
@ -9,16 +9,20 @@ import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
|
||||
public class KCauldronCommand extends Command {
|
||||
public static final String NAME = "kcauldron";
|
||||
public static final String NAME = "kc";
|
||||
public static final String CHECK = NAME + ".check";
|
||||
public static final String UPDATE = NAME + ".update";
|
||||
public static final String RESTART = NAME + ".restart";
|
||||
|
||||
public KCauldronCommand() {
|
||||
super(NAME);
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.append(String.format("/%s check\n", NAME));
|
||||
builder.append(String.format("/%s update [version]\n", NAME));
|
||||
builder.append(String.format("/%s check - Check to update\n", NAME));
|
||||
builder.append(String
|
||||
.format("/%s update [version] - Update to specified or latest version\n",
|
||||
NAME));
|
||||
builder.append(String.format("/%s restart - Restart server\n", NAME));
|
||||
setUsage(builder.toString());
|
||||
|
||||
setPermission("kcauldron");
|
||||
@ -50,6 +54,7 @@ public class KCauldronCommand extends Command {
|
||||
return true;
|
||||
if (args.length == 0) {
|
||||
sender.sendMessage(ChatColor.YELLOW + "Please specify action");
|
||||
sender.sendMessage(ChatColor.AQUA + usageMessage);
|
||||
return true;
|
||||
}
|
||||
String action = args[0];
|
||||
@ -62,6 +67,10 @@ public class KCauldronCommand extends Command {
|
||||
} else if ("update".equals(action)) {
|
||||
KCauldronUpdater.initUpdate(sender, args.length > 1 ? args[1]
|
||||
: null);
|
||||
} else if ("restart".equals(action)) {
|
||||
if (!testPermission(sender, RESTART))
|
||||
return true;
|
||||
KCauldron.restart();
|
||||
} else {
|
||||
sender.sendMessage(ChatColor.RED + "Unknown action");
|
||||
}
|
||||
|
@ -19,13 +19,15 @@ public class KCauldronConfig extends ConfigBase {
|
||||
"updatechecker.symlinks", "", "(Re)create symlinks after update");
|
||||
public BoolSetting updatecheckerAutoinstall = new BoolSetting(this,
|
||||
"updatechecker.autoinstall", false, "Install updates without confirming");
|
||||
public BoolSetting updatecheckerAutorestart = new BoolSetting(this,
|
||||
"updatechecker.autorestart", false, "Restart server after updating without confirming (set restart script in spigot.yml)");
|
||||
public BoolSetting updatecheckerQuite = new BoolSetting(this,
|
||||
"updatechecker.quite", false, "Print less info during update");
|
||||
public StringSetting updatecheckerInstallAs = new StringSetting(this,
|
||||
"updatechecker.installAs", "", "Install new version with specified name");
|
||||
|
||||
public BoolSetting loggingMaterialInjection = new BoolSetting(this,
|
||||
"loggin.materialInjection", false, "Log material injection event");
|
||||
"logging.materialInjection", false, "Log material injection event");
|
||||
|
||||
public KCauldronConfig() {
|
||||
super("kcauldron.yml", "kc");
|
||||
@ -34,6 +36,7 @@ public class KCauldronConfig extends ConfigBase {
|
||||
register(updatecheckerDeleteOld);
|
||||
register(updatecheckerSymlinks);
|
||||
register(updatecheckerAutoinstall);
|
||||
register(updatecheckerAutorestart);
|
||||
register(updatecheckerQuite);
|
||||
register(updatecheckerInstallAs);
|
||||
register(loggingMaterialInjection);
|
||||
|
@ -152,6 +152,12 @@ public class KCauldronUpdater implements Runnable {
|
||||
}
|
||||
KCauldron.sNewServerLocation = newPath;
|
||||
KCauldron.sNewServerVersion = mVersion;
|
||||
if (MinecraftServer.kcauldronConfig.updatecheckerAutorestart.getValue()) {
|
||||
if (mSender != null) {
|
||||
mSender.sendMessage(ChatColor.DARK_RED + "Initiate server restart");
|
||||
}
|
||||
KCauldron.restart();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
if (!quite) {
|
||||
e.printStackTrace();
|
||||
|
@ -27,7 +27,11 @@ public class RestartCommand extends Command
|
||||
return true;
|
||||
}
|
||||
|
||||
public static void restart()
|
||||
public static void restart() {
|
||||
restart(false);
|
||||
}
|
||||
|
||||
public static void restart(boolean forbidShutdown)
|
||||
{
|
||||
try
|
||||
{
|
||||
@ -98,9 +102,13 @@ public class RestartCommand extends Command
|
||||
Runtime.getRuntime().addShutdownHook( shutdownHook );
|
||||
} else
|
||||
{
|
||||
if (forbidShutdown) {
|
||||
System.out.println("Attempt to restart server without restart script, decline request");
|
||||
return;
|
||||
}
|
||||
System.out.println( "Startup script '" + SpigotConfig.restartScript + "' does not exist! Stopping server." );
|
||||
}
|
||||
System.exit( 0 );
|
||||
cpw.mods.fml.common.FMLCommonHandler.instance().exitJava(0, false);
|
||||
} catch ( Exception ex )
|
||||
{
|
||||
ex.printStackTrace();
|
||||
|
Loading…
Reference in New Issue
Block a user