2022-03-21 20:26:29 +00:00
|
|
|
package me.StevenLawson.TotalFreedomMod.commands;
|
|
|
|
|
|
|
|
import me.StevenLawson.TotalFreedomMod.config.ConfigurationEntry;
|
|
|
|
import me.StevenLawson.TotalFreedomMod.config.MainConfig;
|
2022-03-21 21:19:39 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.util.SynchronousUtil;
|
2022-03-21 20:26:29 +00:00
|
|
|
import me.StevenLawson.TotalFreedomMod.util.Utilities;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import org.bukkit.ChatColor;
|
|
|
|
import org.bukkit.command.Command;
|
|
|
|
import org.bukkit.command.CommandSender;
|
2022-03-21 21:19:39 +00:00
|
|
|
import org.bukkit.entity.Player;
|
2022-03-21 20:26:29 +00:00
|
|
|
|
2022-03-21 20:37:24 +00:00
|
|
|
import java.io.File;
|
|
|
|
|
2022-03-21 21:13:40 +00:00
|
|
|
@CommandPermissions(level = AdminLevel.SUPER, source = SourceType.BOTH)
|
2022-03-21 20:26:29 +00:00
|
|
|
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) {
|
2022-03-23 23:48:41 +00:00
|
|
|
playerMsg(sender, "Compiling TFM, please wait...", ChatColor.RED);
|
2022-03-23 20:54:36 +00:00
|
|
|
Utilities.adminAction(sender.getName(), "Compiling TFM", true);
|
2022-03-21 20:26:29 +00:00
|
|
|
String path = MainConfig.getString(ConfigurationEntry.TFM_BUILD_SHELLSCRIPT);
|
2022-03-21 21:01:55 +00:00
|
|
|
File file = new File(path);
|
|
|
|
String directory = file.getParent();
|
2022-03-21 20:37:24 +00:00
|
|
|
|
2022-03-21 20:26:29 +00:00
|
|
|
try {
|
2022-03-21 21:10:39 +00:00
|
|
|
String command = String.format("cd %s && ./%s", directory, file.getName());
|
2022-03-21 20:49:52 +00:00
|
|
|
ProcessBuilder proc = new ProcessBuilder("/bin/bash", "-c", command);
|
2022-03-21 20:42:11 +00:00
|
|
|
Process process = proc.start();
|
|
|
|
process.waitFor();
|
2022-03-23 23:48:41 +00:00
|
|
|
playerMsg(sender, "Compiling TFM! Reloading...");
|
2022-03-21 21:28:45 +00:00
|
|
|
Utilities.adminAction(sender.getName(), "Compilation successful, reloading TFM...", false);
|
2022-03-21 21:19:39 +00:00
|
|
|
for (Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
2022-03-21 21:21:42 +00:00
|
|
|
onlinePlayer.kickPlayer(ChatColor.RED + "Reloading TFM, please rejoin.");
|
2022-03-21 21:19:39 +00:00
|
|
|
}
|
|
|
|
|
2022-03-21 20:26:29 +00:00
|
|
|
Bukkit.dispatchCommand(sender, "plugman reload TotalFreedomMod");
|
|
|
|
} catch (Exception e) {
|
2022-03-23 23:48:41 +00:00
|
|
|
playerMsg(sender, "Failed to update TFM! Check the logs for more details.");
|
2022-03-21 20:26:29 +00:00
|
|
|
Utilities.adminAction(sender.getName(), "Could not update TFM", true);
|
|
|
|
e.printStackTrace();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|