44 lines
1.7 KiB
Java
44 lines
1.7 KiB
Java
package cf.sobrooms.commands;
|
|
|
|
import cf.sobrooms.Main;
|
|
import org.bukkit.Bukkit;
|
|
import org.bukkit.command.Command;
|
|
import org.bukkit.command.CommandExecutor;
|
|
import org.bukkit.command.CommandSender;
|
|
import org.bukkit.ChatColor;
|
|
|
|
import java.io.FileWriter;
|
|
import java.io.IOException;
|
|
|
|
public class SetLoggingModeCommand implements CommandExecutor {
|
|
public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
|
|
if (args[0].isBlank()) {
|
|
sender.sendMessage("Please only provide true or false in the command arguments.");
|
|
return false;
|
|
} else {
|
|
if (args[0].equals("true") || args[0].equals("false")) {
|
|
try {
|
|
|
|
FileWriter writer = new FileWriter(Main.isLoggingConfig);
|
|
writer.write(args[0]);
|
|
writer.close();
|
|
System.out.println("Wrote to config, closing writer...");
|
|
sender.sendMessage(ChatColor.RED + "" + ChatColor.ITALIC + "Changes will only apply once the server has restarted.");
|
|
String status = "";
|
|
if (args[0].equals("true"))
|
|
status = "enabled";
|
|
else if (args[0].equals("false"))
|
|
status = "disabled";
|
|
Bukkit.broadcastMessage(ChatColor.ITALIC + "%s %s server logging.".formatted(sender.getName(), status));
|
|
Bukkit.broadcastMessage(ChatColor.ITALIC + "Changes will only apply once the server has restarted.");
|
|
} catch (IOException e) {
|
|
throw new RuntimeException(e);
|
|
}
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|