diff --git a/src/main/java/me/StevenLawson/TotalFreedomMod/commands/Command_updatetfm.java b/src/main/java/me/StevenLawson/TotalFreedomMod/commands/Command_updatetfm.java new file mode 100644 index 0000000..520eaba --- /dev/null +++ b/src/main/java/me/StevenLawson/TotalFreedomMod/commands/Command_updatetfm.java @@ -0,0 +1,34 @@ +package me.StevenLawson.TotalFreedomMod.commands; + +import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry; +import me.StevenLawson.TotalFreedomMod.config.MainConfig; +import me.StevenLawson.TotalFreedomMod.util.Utilities; +import org.bukkit.Bukkit; +import org.bukkit.ChatColor; +import org.bukkit.command.Command; +import org.bukkit.command.CommandSender; + +@CommandPermissions(level = AdminLevel.SENIOR, source = SourceType.ONLY_CONSOLE) +@CommandParameters(description = "For developers only - update TFM.", usage = "/") +public class Command_updatetfm extends FreedomCommand { + @Override + public boolean run(CommandSender sender, org.bukkit.entity.Player sender_p, Command cmd, String commandLabel, String[] args, boolean senderIsConsole) { + playerMsg("Updating TFM, please wait...", ChatColor.RED); + Utilities.adminAction(sender.getName(), "Updating TFM", true); + String path = MainConfig.getString(ConfigurationEntry.TFM_BUILD_SHELLSCRIPT); + try { + Process uptimeProc = Runtime.getRuntime().exec(String.format("bash -c \"./%s\"", path)); + uptimeProc.waitFor(); + playerMsg("Updated TFM! Reloading..."); + Utilities.adminAction(sender.getName(), "Update successful, reloading TFM...", false); + Bukkit.dispatchCommand(sender, "plugman reload TotalFreedomMod"); + } catch (Exception e) { + playerMsg("Failed to update TFM! Check the logs for more details."); + Utilities.adminAction(sender.getName(), "Could not update TFM", true); + e.printStackTrace(); + } + + + return true; + } +} \ No newline at end of file diff --git a/src/main/java/me/StevenLawson/TotalFreedomMod/config/ConfigurationEntry.java b/src/main/java/me/StevenLawson/TotalFreedomMod/config/ConfigurationEntry.java index 79683b5..e887402 100644 --- a/src/main/java/me/StevenLawson/TotalFreedomMod/config/ConfigurationEntry.java +++ b/src/main/java/me/StevenLawson/TotalFreedomMod/config/ConfigurationEntry.java @@ -97,7 +97,8 @@ public enum ConfigurationEntry DISCORD_FORMAT(String.class, "discord.format"), DISCORD_ADMIN_FORMAT(String.class, "discord.admin_format"), // - CHAT_FORMAT(String.class, "chat.format"); + CHAT_FORMAT(String.class, "chat.format"), + TFM_BUILD_SHELLSCRIPT(String.class, "build_shellscript"); private final Class type; private final String configName; diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 2b8fe1c..41faafe 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -344,4 +344,6 @@ chat: # {RANK} == Player's rank # %1$s == Player's display name # %2$s == Player's message - format: '<{RANK} %1$s> %2$s' \ No newline at end of file + format: '<{RANK} %1$s> %2$s' + +build_shellscript: '/home/server/tfm/update.sh' \ No newline at end of file