Implement auto restart system for clans servers in off-peak times
This commit is contained in:
parent
ee1f2a7ef9
commit
e01b57ceac
@ -9,6 +9,35 @@ import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import mineplex.core.MiniClientPlugin;
|
||||
import mineplex.core.account.CoreClientManager;
|
||||
import mineplex.core.achievement.AchievementManager;
|
||||
@ -97,6 +126,7 @@ import mineplex.game.clans.gameplay.HiddenChestManager;
|
||||
import mineplex.game.clans.gameplay.safelog.SafeLog;
|
||||
import mineplex.game.clans.gameplay.safelog.npc.NPCManager;
|
||||
import mineplex.game.clans.items.GearManager;
|
||||
import mineplex.game.clans.restart.RestartManager;
|
||||
import mineplex.game.clans.spawn.Spawn;
|
||||
import mineplex.game.clans.tutorial.TutorialManager;
|
||||
import mineplex.minecraft.game.classcombat.Class.ClassManager;
|
||||
@ -119,35 +149,6 @@ import mineplex.minecraft.game.core.fire.Fire;
|
||||
import mineplex.minecraft.game.core.mechanics.Weapon;
|
||||
import mineplex.serverdata.commands.ServerCommandManager;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Horse;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason;
|
||||
import org.bukkit.event.entity.EntityDamageEvent;
|
||||
import org.bukkit.event.entity.EntityShootBowEvent;
|
||||
import org.bukkit.event.entity.FoodLevelChangeEvent;
|
||||
import org.bukkit.event.entity.PlayerDeathEvent;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.bukkit.event.player.PlayerLoginEvent;
|
||||
import org.bukkit.event.player.PlayerQuitEvent;
|
||||
import org.bukkit.event.vehicle.VehicleEnterEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelation
|
||||
{
|
||||
public static final int CLAIMABLE_RADIUS = 800;
|
||||
@ -455,6 +456,8 @@ public class ClansManager extends MiniClientPlugin<ClientClan>implements IRelati
|
||||
_siegeManager = new SiegeManager(this);
|
||||
_netherManager = new NetherManager(this);
|
||||
_amplifierManager = new AmplifierManager(plugin);
|
||||
|
||||
new RestartManager(plugin);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -0,0 +1,23 @@
|
||||
package mineplex.game.clans.restart;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import mineplex.core.command.CommandBase;
|
||||
import mineplex.core.common.Rank;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilPlayer;
|
||||
|
||||
public class RestartCommand extends CommandBase<RestartManager>
|
||||
{
|
||||
public RestartCommand(RestartManager plugin)
|
||||
{
|
||||
super(plugin, Rank.ADMIN, "forceRestart");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void Execute(Player caller, String[] args)
|
||||
{
|
||||
UtilPlayer.message(caller, F.main("Clans", "Initiating server restart!"));
|
||||
Plugin.restart();
|
||||
}
|
||||
}
|
@ -0,0 +1,121 @@
|
||||
package mineplex.game.clans.restart;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import mineplex.core.MiniPlugin;
|
||||
import mineplex.core.common.util.C;
|
||||
import mineplex.core.common.util.F;
|
||||
import mineplex.core.common.util.UtilTextMiddle;
|
||||
import mineplex.core.common.util.UtilTime;
|
||||
import mineplex.core.common.util.UtilTime.TimeUnit;
|
||||
import mineplex.core.portal.Portal;
|
||||
import mineplex.core.updater.UpdateType;
|
||||
import mineplex.core.updater.event.UpdateEvent;
|
||||
import mineplex.game.clans.clans.ClansManager;
|
||||
|
||||
public class RestartManager extends MiniPlugin
|
||||
{
|
||||
private static final int MAX_RESTART_TIME = 2; //Server won't auto restart after 2am
|
||||
private final LinkedList<Long> _warnings = new LinkedList<>();
|
||||
private Long _restartUnlock;
|
||||
private Long _restartTime = -1L;
|
||||
private boolean _restarting;
|
||||
|
||||
public RestartManager(JavaPlugin plugin)
|
||||
{
|
||||
super("Restart Manager", plugin);
|
||||
|
||||
if (inRestartZone(Calendar.HOUR_OF_DAY))
|
||||
{
|
||||
_restartUnlock = System.currentTimeMillis() + 1000 + UtilTime.convert(MAX_RESTART_TIME - Calendar.HOUR_OF_DAY, TimeUnit.HOURS, TimeUnit.MILLISECONDS);
|
||||
}
|
||||
else
|
||||
{
|
||||
_restartUnlock = System.currentTimeMillis();
|
||||
}
|
||||
|
||||
_warnings.add(60000L);
|
||||
_warnings.add(30000L);
|
||||
_warnings.add(10000L);
|
||||
_warnings.add(5000L);
|
||||
addCommand(new RestartCommand(this));
|
||||
}
|
||||
|
||||
private boolean inRestartZone(int hour)
|
||||
{
|
||||
return hour >= 0 && hour < MAX_RESTART_TIME; //12 am = 0
|
||||
}
|
||||
|
||||
private boolean tryRestart()
|
||||
{
|
||||
if (!inRestartZone(Calendar.HOUR_OF_DAY) || System.currentTimeMillis() < _restartUnlock)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ClansManager.getInstance().getAmplifierManager().hasActiveAmplifier())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ClansManager.getInstance().getNetherManager().InNether.size() > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (ClansManager.getInstance().getWorldEvent().getEvents().size() > 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public void restart()
|
||||
{
|
||||
Bukkit.broadcastMessage(F.main("Clans", "This Clans server will be restarting in " + F.elem(UtilTime.MakeStr(120000)) + "!"));
|
||||
UtilTextMiddle.display(C.cRed + "Server Restart", C.cGray + "This server will restart in " + F.elem(UtilTime.MakeStr(120000)) + "!");
|
||||
_restartTime = System.currentTimeMillis() + 120000;
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void checkRestart(UpdateEvent event)
|
||||
{
|
||||
if (event.getType() != UpdateType.FAST)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_restarting)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_restartTime != -1)
|
||||
{
|
||||
if (!_warnings.isEmpty())
|
||||
{
|
||||
if (_restartTime - System.currentTimeMillis() <= _warnings.getFirst())
|
||||
{
|
||||
Long time = _warnings.removeFirst();
|
||||
Bukkit.broadcastMessage(F.main("Clans", "This Clans server will be restarting in " + F.elem(UtilTime.MakeStr(time)) + "!"));
|
||||
}
|
||||
}
|
||||
if (System.currentTimeMillis() >= _restartTime)
|
||||
{
|
||||
_restarting = true;
|
||||
Portal.getInstance().sendAllPlayers("ClansHub");
|
||||
runSyncLater(() -> {Bukkit.shutdown();}, 120L);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tryRestart())
|
||||
{
|
||||
restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user