Add update TFM command & configuration entry

This commit is contained in:
business-goose 2022-03-21 20:26:29 +00:00
parent 12f07f1225
commit a14d0bc6a8
3 changed files with 39 additions and 2 deletions

View file

@ -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 = "/<command>")
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;
}
}

View file

@ -97,7 +97,8 @@ public enum ConfigurationEntry
DISCORD_FORMAT(String.class, "discord.format"), DISCORD_FORMAT(String.class, "discord.format"),
DISCORD_ADMIN_FORMAT(String.class, "discord.admin_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 Class<?> type;
private final String configName; private final String configName;

View file

@ -344,4 +344,6 @@ chat:
# {RANK} == Player's rank # {RANK} == Player's rank
# %1$s == Player's display name # %1$s == Player's display name
# %2$s == Player's message # %2$s == Player's message
format: '<{RANK} %1$s> %2$s' format: '<{RANK} %1$s> %2$s'
build_shellscript: '/home/server/tfm/update.sh'