2016-03-02 19:28:01 +00:00
|
|
|
package me.totalfreedom.totalfreedommod.command;
|
2012-12-22 03:22:08 +00:00
|
|
|
|
|
|
|
import java.io.File;
|
2016-03-06 15:56:15 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.rank.Rank;
|
2015-10-19 17:43:46 +00:00
|
|
|
import me.totalfreedom.totalfreedommod.util.FLog;
|
|
|
|
import me.totalfreedom.totalfreedommod.util.FUtil;
|
2012-12-22 03:22:08 +00:00
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
|
|
|
import org.bukkit.entity.Player;
|
2013-07-27 21:49:25 +00:00
|
|
|
import org.bukkit.scheduler.BukkitRunnable;
|
2012-12-22 03:22:08 +00:00
|
|
|
|
2016-03-06 15:56:15 +00:00
|
|
|
@CommandPermissions(level = Rank.SENIOR_ADMIN, source = SourceType.ONLY_CONSOLE, blockHostConsole = true)
|
2013-04-10 02:05:24 +00:00
|
|
|
@CommandParameters(description = "Update server files.", usage = "/<command>")
|
2015-10-19 17:43:46 +00:00
|
|
|
public class Command_tfupdate extends FreedomCommand
|
2012-12-22 03:22:08 +00:00
|
|
|
{
|
2015-11-15 23:32:04 +00:00
|
|
|
|
|
|
|
public static final String[] FILES
|
|
|
|
=
|
|
|
|
{
|
|
|
|
};
|
2012-12-22 03:22:08 +00:00
|
|
|
|
|
|
|
@Override
|
2015-11-22 18:26:47 +00:00
|
|
|
public boolean run(CommandSender sender, Player playerSender, Command cmd, String commandLabel, String[] args, boolean senderIsConsole)
|
2012-12-22 03:22:08 +00:00
|
|
|
{
|
2014-07-20 21:25:45 +00:00
|
|
|
if (FILES.length == 0)
|
|
|
|
{
|
2016-03-02 19:28:01 +00:00
|
|
|
msg("This command is disabled.");
|
2014-07-20 21:25:45 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2012-12-22 03:22:08 +00:00
|
|
|
if (!sender.getName().equalsIgnoreCase("madgeek1450"))
|
|
|
|
{
|
2015-11-15 23:32:04 +00:00
|
|
|
noPerms();
|
2012-12-22 03:22:08 +00:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (final String url : FILES)
|
|
|
|
{
|
2013-07-27 21:49:25 +00:00
|
|
|
new BukkitRunnable()
|
2012-12-22 03:22:08 +00:00
|
|
|
{
|
|
|
|
@Override
|
|
|
|
public void run()
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.info("Downloading: " + url);
|
2012-12-22 03:22:08 +00:00
|
|
|
|
|
|
|
File file = new File("./updates/" + url.substring(url.lastIndexOf("/") + 1));
|
|
|
|
if (file.exists())
|
|
|
|
{
|
|
|
|
file.delete();
|
|
|
|
}
|
|
|
|
if (!file.getParentFile().exists())
|
|
|
|
{
|
|
|
|
file.getParentFile().mkdirs();
|
|
|
|
}
|
|
|
|
|
2015-10-19 17:43:46 +00:00
|
|
|
FUtil.downloadFile(url, file, true);
|
2012-12-22 03:22:08 +00:00
|
|
|
}
|
2013-08-14 13:28:19 +00:00
|
|
|
catch (Exception ex)
|
2012-12-22 03:22:08 +00:00
|
|
|
{
|
2015-10-19 17:43:46 +00:00
|
|
|
FLog.severe(ex);
|
2012-12-22 03:22:08 +00:00
|
|
|
}
|
|
|
|
}
|
2013-07-27 21:49:25 +00:00
|
|
|
}.runTaskAsynchronously(plugin);
|
2012-12-22 03:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|