Added silent/loud option to primerestart

Also using Tabs for formatting
This commit is contained in:
Norbi Peti 2018-08-12 12:28:36 +02:00
parent 9bb8713714
commit 806550a625
No known key found for this signature in database
GPG key ID: DBA4C4549A927E56
3 changed files with 35 additions and 15 deletions

View file

@ -0,0 +1,11 @@
<component name="InspectionProjectProfileManager">
<profile version="1.0">
<option name="myName" value="Project Default" />
<inspection_tool class="WeakerAccess" enabled="true" level="WARNING" enabled_by_default="true">
<option name="SUGGEST_PACKAGE_LOCAL_FOR_MEMBERS" value="false" />
<option name="SUGGEST_PACKAGE_LOCAL_FOR_TOP_CLASSES" value="false" />
<option name="SUGGEST_PRIVATE_FOR_INNERS" value="false" />
<disabledExtension id="moduleInfo" />
</inspection_tool>
</profile>
</component>

View file

@ -40,11 +40,13 @@ public class PlayerListener implements Listener {
&& !event.getQuitMessage().equalsIgnoreCase("Server closed") && !event.getQuitMessage().equalsIgnoreCase("Server closed")
&& !event.getQuitMessage().equalsIgnoreCase("Server is restarting")) { && !event.getQuitMessage().equalsIgnoreCase("Server is restarting")) {
if (Bukkit.getOnlinePlayers().size() <= 1) { 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(); Bukkit.spigot().restart();
} else if (!(event.getPlayer() instanceof IDiscordSender) && System.nanoTime() - 10 * 1000000000L - lasttime > 0) { //Ten seconds passed since last reminder } else if (!(event.getPlayer() instanceof IDiscordSender) && System.nanoTime() - 10 * 1000000000L - lasttime > 0) { //Ten seconds passed since last reminder
lasttime = System.nanoTime(); 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.");
} }
} }
} }

View file

@ -11,26 +11,33 @@ import org.bukkit.command.CommandSender;
public class PrimeRestartCommand extends TBMCCommandBase { public class PrimeRestartCommand extends TBMCCommandBase {
@Override @Override
public boolean OnCommand(CommandSender sender, String alias, String[] args) { public boolean OnCommand(CommandSender sender, String alias, String[] args) {
if (Bukkit.getOnlinePlayers().size() > 0) { loud = args.length > 0;
sender.sendMessage("§bPlayers online, restart delayed."); if (Bukkit.getOnlinePlayers().size() > 0) {
Bukkit.broadcastMessage(ChatColor.DARK_RED + "The server will restart as soon as nobody is online."); sender.sendMessage("§bPlayers online, restart delayed.");
plsrestart = true; if (loud)
} else { Bukkit.broadcastMessage(ChatColor.DARK_RED + "The server will restart as soon as nobody is online.");
sender.sendMessage("§bNobody is online. Restarting now."); plsrestart = true;
Bukkit.broadcastMessage("§cNobody is online. Restarting server."); } else {
Bukkit.spigot().restart(); sender.sendMessage("§bNobody is online. Restarting now.");
} if (loud)
return true; Bukkit.broadcastMessage("§cNobody is online. Restarting server.");
Bukkit.spigot().restart();
}
return true;
} }
@Getter @Getter
private static boolean plsrestart = false; private static boolean plsrestart = false;
@Getter
private static boolean loud = false;
@Override @Override
public String[] GetHelpText(String alias) { public String[] GetHelpText(String alias) {
return new String[]{ // return new String[]{ //
"§6---- Prime restart ----", // "§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" //
}; };
} }
} }