From 806550a6256ebc283355d14058f42b7d3c53f4ba Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sun, 12 Aug 2018 12:28:36 +0200 Subject: [PATCH] Added silent/loud option to primerestart Also using Tabs for formatting --- .idea/inspectionProfiles/Project_Default.xml | 11 +++++++ .../buttondevteam/core/PlayerListener.java | 6 ++-- .../core/PrimeRestartCommand.java | 33 +++++++++++-------- 3 files changed, 35 insertions(+), 15 deletions(-) create mode 100644 .idea/inspectionProfiles/Project_Default.xml diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..4f1aeda --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,11 @@ + + + + \ No newline at end of file diff --git a/ButtonCore/src/main/java/buttondevteam/core/PlayerListener.java b/ButtonCore/src/main/java/buttondevteam/core/PlayerListener.java index c85ecea..af8220e 100755 --- a/ButtonCore/src/main/java/buttondevteam/core/PlayerListener.java +++ b/ButtonCore/src/main/java/buttondevteam/core/PlayerListener.java @@ -40,11 +40,13 @@ public class PlayerListener implements Listener { && !event.getQuitMessage().equalsIgnoreCase("Server closed") && !event.getQuitMessage().equalsIgnoreCase("Server is restarting")) { if (Bukkit.getOnlinePlayers().size() <= 1) { - Bukkit.broadcastMessage("§cNobody is online anymore. Restarting."); + if (PrimeRestartCommand.isLoud()) + Bukkit.broadcastMessage("§cNobody is online anymore. Restarting."); Bukkit.spigot().restart(); } else if (!(event.getPlayer() instanceof IDiscordSender) && System.nanoTime() - 10 * 1000000000L - lasttime > 0) { //Ten seconds passed since last reminder lasttime = System.nanoTime(); - Bukkit.broadcastMessage(ChatColor.DARK_RED + "The server will restart as soon as nobody is online."); + if (PrimeRestartCommand.isLoud()) + Bukkit.broadcastMessage(ChatColor.DARK_RED + "The server will restart as soon as nobody is online."); } } } diff --git a/ButtonCore/src/main/java/buttondevteam/core/PrimeRestartCommand.java b/ButtonCore/src/main/java/buttondevteam/core/PrimeRestartCommand.java index 5ab0bcc..1f03451 100644 --- a/ButtonCore/src/main/java/buttondevteam/core/PrimeRestartCommand.java +++ b/ButtonCore/src/main/java/buttondevteam/core/PrimeRestartCommand.java @@ -11,26 +11,33 @@ import org.bukkit.command.CommandSender; public class PrimeRestartCommand extends TBMCCommandBase { @Override public boolean OnCommand(CommandSender sender, String alias, String[] args) { - if (Bukkit.getOnlinePlayers().size() > 0) { - sender.sendMessage("§bPlayers online, restart delayed."); - Bukkit.broadcastMessage(ChatColor.DARK_RED + "The server will restart as soon as nobody is online."); - plsrestart = true; - } else { - sender.sendMessage("§bNobody is online. Restarting now."); - Bukkit.broadcastMessage("§cNobody is online. Restarting server."); - Bukkit.spigot().restart(); - } - return true; + loud = args.length > 0; + if (Bukkit.getOnlinePlayers().size() > 0) { + sender.sendMessage("§bPlayers online, restart delayed."); + if (loud) + Bukkit.broadcastMessage(ChatColor.DARK_RED + "The server will restart as soon as nobody is online."); + plsrestart = true; + } else { + sender.sendMessage("§bNobody is online. Restarting now."); + if (loud) + Bukkit.broadcastMessage("§cNobody is online. Restarting server."); + Bukkit.spigot().restart(); + } + return true; } - @Getter - private static boolean plsrestart = false; + @Getter + private static boolean plsrestart = false; + @Getter + private static boolean loud = false; @Override public String[] GetHelpText(String alias) { return new String[]{ // "§6---- Prime restart ----", // - "Restarts the server as soon as nobody is online." // + "Restarts the server as soon as nobody is online.", // + "To be loud, type something after, like /primerestart lol (it doesn't matter what you write)", // + "To be silent, don't type anything" // }; } }