3
0

Support to restart server after update

This commit is contained in:
Prototik 2015-06-14 19:50:18 +07:00
parent 55d1d750ec
commit 44020ecc25
7 changed files with 56 additions and 30 deletions

View File

@ -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));

View File

@ -6,13 +6,16 @@ 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 {
Enumeration<URL> resources = KCauldron.class.getClassLoader()
.getResources("META-INF/MANIFEST.MF");
@ -23,10 +26,11 @@ 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("!"));
jarFilePath = URLDecoder.decode(jarFilePath, "UTF-8");
sServerLocation = new File(jarFilePath);
String jarFilePath = path.substring(path.indexOf(":") + 1,
path.indexOf("!"));
jarFilePath = URLDecoder.decode(jarFilePath, "UTF-8");
sServerLocation = new File(jarFilePath);
sCurrentVersion = version;
sBranch = manifest.getProperty("KCauldron-Branch");
sChannel = manifest.getProperty("KCauldron-Channel");
@ -38,7 +42,7 @@ public class KCauldron {
}
}
private static String sCurrentVersion;
public static String getCurrentVersion() {
@ -52,22 +56,26 @@ public class KCauldron {
parseManifest();
return sServerLocation;
}
private static String sBranch;
public static String getBranch() {
parseManifest();
return sBranch;
}
private static String sChannel;
public static String getChannel() {
parseManifest();
return sChannel;
}
public static File sNewServerLocation;
public static String sNewServerVersion;
public static boolean sUpdateInProgress;
public static void restart() {
RestartCommand.restart(true);
}
}

View File

@ -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 {

View File

@ -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");
}

View File

@ -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);

View File

@ -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();

View File

@ -26,8 +26,12 @@ public class RestartCommand extends Command
}
return true;
}
public static void restart() {
restart(false);
}
public static void restart()
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();