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,41 +23,44 @@ public class Command_totalfreedommod extends FreedomCommand
|
||||
{
|
||||
if (args.length == 1)
|
||||
{
|
||||
if (args[0].equals("reload"))
|
||||
if (!args[0].equals("reload"))
|
||||
{
|
||||
if (!plugin.al.isAdmin(sender))
|
||||
{
|
||||
noPerms();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
plugin.config.load();
|
||||
plugin.services.stop();
|
||||
plugin.services.start();
|
||||
|
||||
final String message = String.format("%s v%s reloaded.",
|
||||
TotalFreedomMod.pluginName,
|
||||
TotalFreedomMod.pluginVersion);
|
||||
|
||||
msg(message);
|
||||
FLog.info(message);
|
||||
if (!plugin.al.isAdmin(sender))
|
||||
{
|
||||
noPerms();
|
||||
return true;
|
||||
}
|
||||
|
||||
plugin.config.load();
|
||||
plugin.services.stop();
|
||||
plugin.services.start();
|
||||
|
||||
final String message = String.format("%s v%s reloaded.",
|
||||
TotalFreedomMod.pluginName,
|
||||
TotalFreedomMod.pluginVersion);
|
||||
|
||||
msg(message);
|
||||
FLog.info(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
TotalFreedomMod.BuildProperties build = TotalFreedomMod.build;
|
||||
msg("TotalFreedomMod for 'Total Freedom', the original all-op server.", ChatColor.GOLD);
|
||||
msg("Running on " + ConfigEntry.SERVER_NAME.getString() + ".", ChatColor.GOLD);
|
||||
msg("Created by Madgeek1450 and Prozza.", ChatColor.GOLD);
|
||||
msg(String.format("Version "
|
||||
+ ChatColor.BLUE + "%s %s.%s " + ChatColor.GOLD + "("
|
||||
+ ChatColor.BLUE + "%s" + ChatColor.GOLD + ")",
|
||||
+ ChatColor.BLUE + "%s %s.%s " + ChatColor.GOLD + "("
|
||||
+ ChatColor.BLUE + "%s" + ChatColor.GOLD + ")",
|
||||
build.codename,
|
||||
build.version,
|
||||
build.number,
|
||||
build.head), ChatColor.GOLD);
|
||||
msg(String.format("Compiled "
|
||||
+ ChatColor.BLUE + "%s" + ChatColor.GOLD + " by "
|
||||
+ ChatColor.BLUE + "%s",
|
||||
+ ChatColor.BLUE + "%s" + ChatColor.GOLD + " by "
|
||||
+ ChatColor.BLUE + "%s",
|
||||
build.date,
|
||||
build.author), ChatColor.GOLD);
|
||||
msg("Visit " + ChatColor.AQUA + "http://github.com/TotalFreedom/TotalFreedomMod"
|
||||
|
Loading…
Reference in New Issue
Block a user