Improvements

This commit is contained in:
Lemon 2018-03-26 16:26:21 +05:00 committed by Lemon
parent affe77c203
commit a63681d4a3
2 changed files with 25 additions and 5 deletions

View File

@ -248,7 +248,7 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
plugin.pa.autoAddSpawnpoints(); plugin.pa.autoAddSpawnpoints();
} }
}.runTaskLater(plugin, 60L); }.runTaskLater(plugin, 60L);
//little workaround to stop spigot from autorestarting - causing AMP to detach from process. // little workaround to stop spigot from autorestarting - causing AMP to detach from process.
SpigotConfig.config.set("settings.restart-on-crash", false); SpigotConfig.config.set("settings.restart-on-crash", false);
} }

View File

@ -2,9 +2,13 @@ package me.totalfreedom.totalfreedommod;
import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FLog;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.plugin.java.JavaPlugin;
import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.net.URL;
import java.io.IOException; import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URL;
import java.nio.channels.Channels; import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel; import java.nio.channels.ReadableByteChannel;
import java.util.Scanner; import java.util.Scanner;
@ -66,7 +70,7 @@ public class Updater extends FreedomService
{ {
URL url = new URL(UPDATE_SERVER_URL + "/TotalFreedomMod.jar"); URL url = new URL(UPDATE_SERVER_URL + "/TotalFreedomMod.jar");
ReadableByteChannel input = Channels.newChannel(url.openStream()); ReadableByteChannel input = Channels.newChannel(url.openStream());
FileOutputStream output = new FileOutputStream("plugins/TotalFreedomMod.jar"); FileOutputStream output = new FileOutputStream(getFilePath());
FLog.info("Downloading latest version..."); FLog.info("Downloading latest version...");
output.getChannel().transferFrom(input, 0, Long.MAX_VALUE); output.getChannel().transferFrom(input, 0, Long.MAX_VALUE);
input.close(); input.close();
@ -76,12 +80,12 @@ public class Updater extends FreedomService
} }
catch (IOException ex) catch (IOException ex)
{ {
ex.printStackTrace(); FLog.severe(ex);
} }
for (Player player : server.getOnlinePlayers()) for (Player player : server.getOnlinePlayers())
{ {
player.kickPlayer("The server has restarted as TotalFreedomMod was just updated."); player.kickPlayer("The server is restarting for a TFM update.");
} }
if (!plugin.amp.enabled) if (!plugin.amp.enabled)
@ -93,5 +97,21 @@ public class Updater extends FreedomService
plugin.amp.restartServer(); plugin.amp.restartServer();
} }
} }
public String getFilePath()
{
try
{
Method method = JavaPlugin.class.getDeclaredMethod("getFile");
boolean wasAccessible = method.isAccessible();
method.setAccessible(true);
File file = (File) method.invoke(plugin);
method.setAccessible(wasAccessible);
return file.getPath();
}
catch (Exception e)
{
return "plugins" + File.separator + plugin.getName();
}
}
} }