Restart impr.

This commit is contained in:
Norbi Peti 2019-02-27 16:39:45 +01:00
parent e4f5850ad6
commit 0cdfcb9ff4
5 changed files with 20 additions and 20 deletions

View file

@ -12,7 +12,7 @@
</profile> </profile>
</annotationProcessing> </annotationProcessing>
<bytecodeTargetLevel> <bytecodeTargetLevel>
<module name="BuildConfigUpdater" target="1.8" /> <module name="BuildConfigUpdater" target="1.5" />
<module name="ButtonCore" target="1.5" /> <module name="ButtonCore" target="1.5" />
<module name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" target="1.8" /> <module name="ButtonCore (1) (com.github.TBMCPlugins.ButtonCore)" target="1.8" />
<module name="ButtonProcessor" target="1.8" /> <module name="ButtonProcessor" target="1.8" />

View file

@ -20,12 +20,12 @@ public class PrimeRestartCommand extends TBMCCommandBase {
if (Bukkit.getOnlinePlayers().size() > 0) { if (Bukkit.getOnlinePlayers().size() > 0) {
sender.sendMessage("§bPlayers online, restart delayed."); sender.sendMessage("§bPlayers online, restart delayed.");
if (loud) if (loud)
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, ChatColor.DARK_RED + "The server will restart as soon as nobody is online.", component.restartBroadcast); TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, ChatColor.DARK_RED + "The server will restart as soon as nobody is online.", component.getRestartBroadcast());
plsrestart = true; plsrestart = true;
} else { } else {
sender.sendMessage("§bNobody is online. Restarting now."); sender.sendMessage("§bNobody is online. Restarting now.");
if (loud) if (loud)
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, "§cNobody is online. Restarting server.", component.restartBroadcast); TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, "§cNobody is online. Restarting server.", component.getRestartBroadcast());
Bukkit.spigot().restart(); Bukkit.spigot().restart();
} }
return true; return true;

View file

@ -5,6 +5,7 @@ import buttondevteam.lib.TBMCSystemChatEvent;
import buttondevteam.lib.architecture.Component; import buttondevteam.lib.architecture.Component;
import buttondevteam.lib.chat.IFakePlayer; import buttondevteam.lib.chat.IFakePlayer;
import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCChatAPI;
import lombok.Getter;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.ChatColor; import org.bukkit.ChatColor;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -15,7 +16,7 @@ public class RestartComponent extends Component implements Listener {
@Override @Override
public void enable() { public void enable() {
//TODO: Permissions for the commands //TODO: Permissions for the commands
TBMCChatAPI.AddCommand(this, new ScheduledRestartCommand(this)); registerCommand(new ScheduledRestartCommand(this));
TBMCChatAPI.AddCommand(this, new PrimeRestartCommand(this)); TBMCChatAPI.AddCommand(this, new PrimeRestartCommand(this));
registerListener(this); registerListener(this);
restartBroadcast = TBMCSystemChatEvent.BroadcastTarget.add("restartCountdown"); restartBroadcast = TBMCSystemChatEvent.BroadcastTarget.add("restartCountdown");
@ -27,7 +28,8 @@ public class RestartComponent extends Component implements Listener {
} }
private long lasttime = 0; private long lasttime = 0;
TBMCSystemChatEvent.BroadcastTarget restartBroadcast; @Getter
private TBMCSystemChatEvent.BroadcastTarget restartBroadcast;
@EventHandler @EventHandler
public void onPlayerLeave(PlayerQuitEvent event) { public void onPlayerLeave(PlayerQuitEvent event) {

View file

@ -3,9 +3,10 @@ package buttondevteam.core.component.restart;
import buttondevteam.core.MainPlugin; import buttondevteam.core.MainPlugin;
import buttondevteam.core.component.channel.Channel; import buttondevteam.core.component.channel.Channel;
import buttondevteam.lib.ScheduledServerRestartEvent; import buttondevteam.lib.ScheduledServerRestartEvent;
import buttondevteam.lib.chat.Command2;
import buttondevteam.lib.chat.CommandClass; import buttondevteam.lib.chat.CommandClass;
import buttondevteam.lib.chat.ICommand2MC;
import buttondevteam.lib.chat.TBMCChatAPI; import buttondevteam.lib.chat.TBMCChatAPI;
import buttondevteam.lib.chat.TBMCCommandBase;
import lombok.Getter; import lombok.Getter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.Setter; import lombok.Setter;
@ -17,18 +18,23 @@ import org.bukkit.boss.BossBar;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.scheduler.BukkitTask; import org.bukkit.scheduler.BukkitTask;
@CommandClass(modOnly = true, path = "schrestart") @CommandClass(modOnly = true, path = "schrestart", helpText = {
"Scheduled restart", //
"This command restarts the server 1 minute after it's executed, warning players every 10 seconds.", //
"You can optionally set the amount of seconds to wait before the restart." //
})
@RequiredArgsConstructor @RequiredArgsConstructor
public class ScheduledRestartCommand extends TBMCCommandBase { public class ScheduledRestartCommand extends ICommand2MC {
@Getter @Getter
@Setter @Setter
private int restartCounter; private int restartCounter;
private BukkitTask restarttask; private BukkitTask restarttask;
private volatile BossBar restartbar; private volatile BossBar restartbar;
@Getter
private final RestartComponent component; private final RestartComponent component;
@Override @Command2.Subcommand
public boolean OnCommand(CommandSender sender, String alias, String[] args) { public boolean def(CommandSender sender, String alias, String[] args) {
int secs = 60; int secs = 60;
try { try {
if (args.length > 0) if (args.length > 0)
@ -56,20 +62,11 @@ public class ScheduledRestartCommand extends TBMCCommandBase {
Bukkit.spigot().restart(); Bukkit.spigot().restart();
} }
if (restartCounter % 200 == 0) if (restartCounter % 200 == 0)
TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, "§c-- The server is restarting in " + restartCounter / 20 + " seconds! (/press)", component.restartBroadcast); TBMCChatAPI.SendSystemMessage(Channel.GlobalChat, Channel.RecipientTestResult.ALL, "§c-- The server is restarting in " + restartCounter / 20 + " seconds! (/press)", component.getRestartBroadcast());
restartbar.setProgress(restartCounter / (double) restarttime); restartbar.setProgress(restartCounter / (double) restarttime);
restartbar.setTitle(String.format("Server restart in %.2f", restartCounter / 20f)); restartbar.setTitle(String.format("Server restart in %.2f", restartCounter / 20f));
restartCounter--; restartCounter--;
}, 1, 1); }, 1, 1);
return true; return true;
} }
@Override
public String[] GetHelpText(String alias) {
return new String[] { //
"§6---- Scheduled restart ----", //
"This command restarts the server 1 minute after it's executed, warning players every 10 seconds.", //
"You can optionally set the amount of ticks to wait before the restart." //
};
}
} }

View file

@ -13,6 +13,7 @@
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.21" level="project" /> <orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.21" level="project" />
<orderEntry type="library" name="Maven: org.yaml:snakeyaml:1.21" level="project" />
<orderEntry type="library" name="Maven: org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT" level="project" /> <orderEntry type="library" name="Maven: org.spigotmc:spigot-api:1.12.2-R0.1-SNAPSHOT" level="project" />
<orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" /> <orderEntry type="library" name="Maven: commons-lang:commons-lang:2.6" level="project" />
<orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" /> <orderEntry type="library" name="Maven: com.googlecode.json-simple:json-simple:1.1.1" level="project" />