mirror of
https://github.com/AtlasMediaGroup/TotalFreedomMod.git
synced 2024-11-27 01:05:38 +00:00
Remove updater fully and revert /tfm properly.
This commit is contained in:
parent
6e3fa2d6dd
commit
69e82b5746
@ -93,7 +93,6 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
|
||||
public EntityWiper ew;
|
||||
public FrontDoor fd;
|
||||
public ServerPing sp;
|
||||
public Updater ud;
|
||||
public ItemFun it;
|
||||
public Landminer lm;
|
||||
public MP44 mp;
|
||||
@ -206,7 +205,6 @@ public class TotalFreedomMod extends AeroPlugin<TotalFreedomMod>
|
||||
ew = services.registerService(EntityWiper.class);
|
||||
fd = services.registerService(FrontDoor.class);
|
||||
sp = services.registerService(ServerPing.class);
|
||||
ud = services.registerService(Updater.class);
|
||||
pv = services.registerService(PlayerVerification.class);
|
||||
|
||||
// Fun
|
||||
|
@ -1,103 +0,0 @@
|
||||
package me.totalfreedom.totalfreedommod;
|
||||
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.URL;
|
||||
import java.nio.channels.Channels;
|
||||
import java.nio.channels.ReadableByteChannel;
|
||||
import java.util.Scanner;
|
||||
|
||||
/*
|
||||
This class exists primarily due to the fact that it takes too long to get new builds onto the official
|
||||
TotalFreedom server. If you wish to delete this class you may do so.
|
||||
*/
|
||||
|
||||
public class Updater extends FreedomService
|
||||
{
|
||||
|
||||
private final String UPDATE_SERVER_URL = "https://tfm.zeroepoch1969.rip";
|
||||
private final TotalFreedomMod.BuildProperties build = TotalFreedomMod.build;
|
||||
public boolean updateAvailable = false;
|
||||
|
||||
public Updater(TotalFreedomMod plugin)
|
||||
{
|
||||
super(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart()
|
||||
{
|
||||
if (build.number != null)
|
||||
{
|
||||
checkForUpdates();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStop()
|
||||
{
|
||||
}
|
||||
|
||||
private void checkForUpdates()
|
||||
{
|
||||
try
|
||||
{
|
||||
URL url = new URL(UPDATE_SERVER_URL + "/build");
|
||||
String webBuild = new Scanner(url.openStream()).useDelimiter("\\Z").next();
|
||||
if (!build.number.equals(webBuild))
|
||||
{
|
||||
updateAvailable = true;
|
||||
}
|
||||
FLog.info((updateAvailable ? "A new update is a available!" : "TFM is up-to-date!"));
|
||||
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
FLog.warning("Failed to connect to the update server.");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void update()
|
||||
{
|
||||
try
|
||||
{
|
||||
URL url = new URL(UPDATE_SERVER_URL + "/TotalFreedomMod.jar");
|
||||
ReadableByteChannel input = Channels.newChannel(url.openStream());
|
||||
FileOutputStream output = new FileOutputStream(getFilePath());
|
||||
FLog.info("Downloading latest version...");
|
||||
output.getChannel().transferFrom(input, 0, Long.MAX_VALUE);
|
||||
input.close();
|
||||
output.close();
|
||||
FLog.info("The latest version has been installed! Restart the server for changes to take effect.");
|
||||
|
||||
}
|
||||
catch (IOException ex)
|
||||
{
|
||||
FLog.severe(ex);
|
||||
}
|
||||
}
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
@ -5,7 +5,6 @@ import me.totalfreedom.totalfreedommod.config.ConfigEntry;
|
||||
import me.totalfreedom.totalfreedommod.config.MainConfig;
|
||||
import me.totalfreedom.totalfreedommod.rank.Rank;
|
||||
import me.totalfreedom.totalfreedommod.util.FLog;
|
||||
import me.totalfreedom.totalfreedommod.util.FUtil;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
@ -24,8 +23,11 @@ public class Command_totalfreedommod extends FreedomCommand
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
if (args[0].equals("reload"))
|
||||
if (!args[0].equals("reload"))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!plugin.al.isAdmin(sender))
|
||||
{
|
||||
noPerms();
|
||||
|
Loading…
Reference in New Issue
Block a user