JSONify the arcade server motd
This commit is contained in:
parent
d8e58baea7
commit
bffd474322
@ -0,0 +1,100 @@
|
|||||||
|
package mineplex.core.game.status;
|
||||||
|
|
||||||
|
import mineplex.core.account.permissions.PermissionGroup;
|
||||||
|
import mineplex.core.common.Constants;
|
||||||
|
|
||||||
|
public class GameInfo
|
||||||
|
{
|
||||||
|
|
||||||
|
public static GameInfo fromString(String json)
|
||||||
|
{
|
||||||
|
return Constants.GSON.fromJson(json, GameInfo.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
private final String _game, _mode, _map, _serverType;
|
||||||
|
private final int _timer;
|
||||||
|
private final String[] _votingOn;
|
||||||
|
private final PermissionGroup _hostRank;
|
||||||
|
private final GameDisplayStatus _status;
|
||||||
|
private final GameJoinStatus _joinable;
|
||||||
|
|
||||||
|
public GameInfo(String game, String mode, String map, String serverType, int timer, String[] votingOn, PermissionGroup hostRank, GameDisplayStatus status, GameJoinStatus joinable)
|
||||||
|
{
|
||||||
|
_game = game;
|
||||||
|
_mode = mode;
|
||||||
|
_map = map;
|
||||||
|
_serverType = serverType;
|
||||||
|
_timer = timer;
|
||||||
|
_votingOn = votingOn;
|
||||||
|
_hostRank = hostRank;
|
||||||
|
_status = status;
|
||||||
|
_joinable = joinable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGame()
|
||||||
|
{
|
||||||
|
return _game;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMode()
|
||||||
|
{
|
||||||
|
return _mode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMap()
|
||||||
|
{
|
||||||
|
return _map;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerType()
|
||||||
|
{
|
||||||
|
return _serverType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTimer()
|
||||||
|
{
|
||||||
|
return _timer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getVotingOn()
|
||||||
|
{
|
||||||
|
return _votingOn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public PermissionGroup getHostRank()
|
||||||
|
{
|
||||||
|
return _hostRank;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameDisplayStatus getStatus()
|
||||||
|
{
|
||||||
|
return _status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameJoinStatus getJoinable()
|
||||||
|
{
|
||||||
|
return _joinable;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return Constants.GSON.toJson(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum GameDisplayStatus
|
||||||
|
{
|
||||||
|
WAITING,
|
||||||
|
VOTING,
|
||||||
|
STARTING,
|
||||||
|
IN_PROGRESS,
|
||||||
|
CLOSING
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum GameJoinStatus
|
||||||
|
{
|
||||||
|
OPEN,
|
||||||
|
RANKS_ONLY,
|
||||||
|
CLOSED
|
||||||
|
}
|
||||||
|
}
|
@ -30,6 +30,7 @@ import org.bukkit.event.player.PlayerCommandPreprocessEvent;
|
|||||||
import org.bukkit.event.player.PlayerInteractEvent;
|
import org.bukkit.event.player.PlayerInteractEvent;
|
||||||
import org.bukkit.event.player.PlayerJoinEvent;
|
import org.bukkit.event.player.PlayerJoinEvent;
|
||||||
import org.bukkit.event.player.PlayerLoginEvent;
|
import org.bukkit.event.player.PlayerLoginEvent;
|
||||||
|
import org.bukkit.event.player.PlayerLoginEvent.Result;
|
||||||
import org.bukkit.event.player.PlayerQuitEvent;
|
import org.bukkit.event.player.PlayerQuitEvent;
|
||||||
import org.bukkit.event.server.ServerListPingEvent;
|
import org.bukkit.event.server.ServerListPingEvent;
|
||||||
import org.bukkit.potion.PotionEffect;
|
import org.bukkit.potion.PotionEffect;
|
||||||
@ -80,6 +81,9 @@ import mineplex.core.gadget.event.ToggleMobsEvent;
|
|||||||
import mineplex.core.gadget.types.Gadget;
|
import mineplex.core.gadget.types.Gadget;
|
||||||
import mineplex.core.gadget.types.GadgetType;
|
import mineplex.core.gadget.types.GadgetType;
|
||||||
import mineplex.core.game.MineplexGameManager;
|
import mineplex.core.game.MineplexGameManager;
|
||||||
|
import mineplex.core.game.status.GameInfo;
|
||||||
|
import mineplex.core.game.status.GameInfo.GameDisplayStatus;
|
||||||
|
import mineplex.core.game.status.GameInfo.GameJoinStatus;
|
||||||
import mineplex.core.game.winstreaks.WinStreakManager;
|
import mineplex.core.game.winstreaks.WinStreakManager;
|
||||||
import mineplex.core.google.GoogleSheetsManager;
|
import mineplex.core.google.GoogleSheetsManager;
|
||||||
import mineplex.core.hologram.HologramManager;
|
import mineplex.core.hologram.HologramManager;
|
||||||
@ -170,6 +174,8 @@ import nautilus.game.arcade.managers.chat.GameChatManager;
|
|||||||
import nautilus.game.arcade.managers.lobby.LobbyManager;
|
import nautilus.game.arcade.managers.lobby.LobbyManager;
|
||||||
import nautilus.game.arcade.managers.lobby.current.NewGameLobbyManager;
|
import nautilus.game.arcade.managers.lobby.current.NewGameLobbyManager;
|
||||||
import nautilus.game.arcade.managers.lobby.legacy.LegacyGameLobbyManager;
|
import nautilus.game.arcade.managers.lobby.legacy.LegacyGameLobbyManager;
|
||||||
|
import nautilus.game.arcade.managers.voting.Vote;
|
||||||
|
import nautilus.game.arcade.managers.voting.types.GameVote;
|
||||||
|
|
||||||
public class ArcadeManager extends MiniPlugin implements IRelation
|
public class ArcadeManager extends MiniPlugin implements IRelation
|
||||||
{
|
{
|
||||||
@ -1010,13 +1016,13 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
|||||||
}
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void MessageMOTD(ServerListPingEvent event)
|
public void motdPing(ServerListPingEvent event)
|
||||||
{
|
{
|
||||||
event.setMaxPlayers(_serverConfig.MaxPlayers);
|
event.setMaxPlayers(_serverConfig.MaxPlayers);
|
||||||
|
|
||||||
if (UtilServer.isTestServer(false))
|
if (UtilServer.isTestServer(false))
|
||||||
{
|
{
|
||||||
event.setMotd(ChatColor.GOLD + "Private Mineplex Test Server");
|
event.setMotd(C.cGold + "Private Mineplex Test Server");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1025,61 +1031,95 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
|||||||
{
|
{
|
||||||
if (_gameHostManager.isHostExpired())
|
if (_gameHostManager.isHostExpired())
|
||||||
{
|
{
|
||||||
event.setMotd(ChatColor.RED + "Finished");
|
event.setMotd(C.cRed + "Finished");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!GetServerConfig().PublicServer || GetServerConfig().PlayerServerWhitelist || _gameHostManager.isCommunityServer())
|
if (!GetServerConfig().PublicServer || GetServerConfig().PlayerServerWhitelist || _gameHostManager.isCommunityServer())
|
||||||
{
|
{
|
||||||
event.setMotd(ChatColor.GRAY + "Private");
|
event.setMotd(C.cGray + "Private");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String game = "Waiting For Players";
|
boolean nullGame = _game == null;
|
||||||
String map = game;
|
String game = null, mode = null, map = null;
|
||||||
|
int timer = -1;
|
||||||
|
String[] votingOn = null;
|
||||||
|
PermissionGroup hostRank = null;
|
||||||
|
GameDisplayStatus status;
|
||||||
|
|
||||||
|
// Vote in progress
|
||||||
if (_gameCreationManager.getVotingManager().isVoteInProgress())
|
if (_gameCreationManager.getVotingManager().isVoteInProgress())
|
||||||
{
|
{
|
||||||
game = _gameCreationManager.getNextGameType() == null ? "Voting" : _gameCreationManager.getNextGameType().getName();
|
status = GameDisplayStatus.VOTING;
|
||||||
map = "Voting";
|
|
||||||
}
|
|
||||||
else if (!_serverConfig.GameVoting && !_serverConfig.GameList.isEmpty())
|
|
||||||
{
|
|
||||||
game = _serverConfig.GameList.get(0).getName();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (_game != null && _game.WorldData != null)
|
// Null game - GameVote
|
||||||
|
if (nullGame)
|
||||||
|
{
|
||||||
|
game = "Voting";
|
||||||
|
map = game;
|
||||||
|
|
||||||
|
Vote vote = _gameCreationManager.getVotingManager().getCurrentVote();
|
||||||
|
|
||||||
|
if (vote instanceof GameVote)
|
||||||
|
{
|
||||||
|
votingOn = ((GameVote) vote).getValues().stream()
|
||||||
|
.map(GameType::getName)
|
||||||
|
.toArray(String[]::new);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// MapVote
|
||||||
|
else
|
||||||
{
|
{
|
||||||
game = _game.GetName();
|
game = _game.GetName();
|
||||||
|
mode = _game.GetMode();
|
||||||
|
map = "Voting";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// No vote and game null. Staff-1 or pre game voting
|
||||||
|
else if (nullGame)
|
||||||
|
{
|
||||||
|
status = GameDisplayStatus.WAITING;
|
||||||
|
}
|
||||||
|
// Game not null
|
||||||
|
else
|
||||||
|
{
|
||||||
|
game = _game.GetName();
|
||||||
|
mode = _game.GetMode();
|
||||||
map = _game.WorldData.MapName;
|
map = _game.WorldData.MapName;
|
||||||
}
|
|
||||||
|
|
||||||
String extrainformation = "|" + _serverConfig.ServerType + "|" + game + "|" + map;
|
// Game not in progress
|
||||||
|
if (_game.inLobby())
|
||||||
|
{
|
||||||
|
timer = _game.GetCountdown();
|
||||||
|
|
||||||
if (_gameHostManager.isPrivateServer() && _gameHostManager.hasPermission(Perm.FEATURED_SERVER))
|
// Counting down
|
||||||
|
if (timer != -1)
|
||||||
{
|
{
|
||||||
extrainformation += "|HostRank." + _gameHostManager.getHostRank().name();
|
status = GameDisplayStatus.STARTING;
|
||||||
}
|
|
||||||
|
|
||||||
if (_game == null || _game.GetState() == GameState.Recruit)
|
|
||||||
{
|
|
||||||
if (_game != null && _game.GetCountdown() != -1)
|
|
||||||
{
|
|
||||||
event.setMotd(ChatColor.GREEN + "Starting in " + _game.GetCountdown() + " Seconds" + extrainformation);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
event.setMotd(ChatColor.GREEN + "Recruiting" + extrainformation);
|
status = GameDisplayStatus.WAITING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//In Progress
|
// Game in progress
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
event.setMotd(ChatColor.YELLOW + "In Progress" + extrainformation);
|
status = GameDisplayStatus.IN_PROGRESS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// MPS
|
||||||
|
if (_gameHostManager.isPrivateServer() && _gameHostManager.getHostRank().hasPermission(Perm.FEATURED_SERVER))
|
||||||
|
{
|
||||||
|
hostRank = _gameHostManager.getHostRank();
|
||||||
|
}
|
||||||
|
|
||||||
|
event.setMotd(new GameInfo(game, mode, map, _serverConfig.ServerType, timer, votingOn, hostRank, status, getJoinable()).toString());
|
||||||
|
}
|
||||||
|
|
||||||
@EventHandler
|
@EventHandler
|
||||||
public void onClickCompassPartyIcon(PartySelectServerEvent event)
|
public void onClickCompassPartyIcon(PartySelectServerEvent event)
|
||||||
{
|
{
|
||||||
@ -1193,57 +1233,63 @@ public class ArcadeManager extends MiniPlugin implements IRelation
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Reserved Slot Check
|
GameJoinStatus joinable = getJoinable();
|
||||||
if (Bukkit.getOnlinePlayers().size() >= Bukkit.getServer().getMaxPlayers())
|
|
||||||
|
if (joinable != GameJoinStatus.OPEN)
|
||||||
{
|
{
|
||||||
if (client.hasPermission(Perm.JOIN_FULL_STAFF))
|
if (client.hasPermission(Perm.JOIN_FULL_STAFF))
|
||||||
{
|
{
|
||||||
event.allow();
|
event.allow();
|
||||||
event.setResult(PlayerLoginEvent.Result.ALLOWED);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (client.hasPermission(Perm.JOIN_FULL) || _donationManager.Get(player).ownsUnknownSalesPackage(_serverConfig.ServerType + " ULTRA"))
|
|
||||||
{
|
|
||||||
String reason = C.Bold + "Server has reached max capacity for gameplay purposes.";
|
|
||||||
|
|
||||||
if (_serverConfig.HardMaxPlayerCap)
|
|
||||||
{
|
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, reason);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (Bukkit.getServer().getOnlinePlayers().size() / Bukkit.getMaxPlayers() > 1.5)
|
|
||||||
{
|
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, reason);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (_gameHostManager.isEventServer() && Bukkit.getServer().getOnlinePlayers().size() >= 128)
|
|
||||||
{
|
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, reason);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean canOverflow = client.hasPermission(Perm.JOIN_FULL) || _donationManager.Get(player).ownsUnknownSalesPackage(_serverConfig.ServerType + " ULTRA");
|
||||||
|
|
||||||
|
if (canOverflow)
|
||||||
|
{
|
||||||
|
if (joinable == GameJoinStatus.RANKS_ONLY)
|
||||||
|
{
|
||||||
event.allow();
|
event.allow();
|
||||||
event.setResult(PlayerLoginEvent.Result.ALLOWED);
|
|
||||||
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
event.disallow(PlayerLoginEvent.Result.KICK_OTHER, "Server Full > Purchase Ultra at www.mineplex.com/shop");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@EventHandler(priority = EventPriority.LOW)
|
|
||||||
public void AdminOP(PlayerJoinEvent event)
|
|
||||||
{
|
|
||||||
if (_clientManager.Get(event.getPlayer()).hasPermission(Perm.AUTO_OP))
|
|
||||||
{
|
|
||||||
event.getPlayer().setOp(true);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
event.getPlayer().setOp(false);
|
event.disallow(Result.KICK_OTHER, C.Bold + "Server has reached max capacity for gameplay purposes.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (joinable == GameJoinStatus.RANKS_ONLY)
|
||||||
|
{
|
||||||
|
event.disallow(Result.KICK_OTHER, C.Bold + "Server has reached max capacity for gameplay purposes.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
event.disallow(Result.KICK_OTHER, C.Bold + "Server Full > Purchase Ultra at www.mineplex.com/shop");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private GameJoinStatus getJoinable()
|
||||||
|
{
|
||||||
|
if (Bukkit.getOnlinePlayers().size() >= Bukkit.getServer().getMaxPlayers())
|
||||||
|
{
|
||||||
|
if (_serverConfig.HardMaxPlayerCap || (double) Bukkit.getServer().getOnlinePlayers().size() / Bukkit.getMaxPlayers() > 1.5 || (_gameHostManager.isEventServer() && Bukkit.getServer().getOnlinePlayers().size() >= 128))
|
||||||
|
{
|
||||||
|
return GameJoinStatus.CLOSED;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GameJoinStatus.RANKS_ONLY;
|
||||||
|
}
|
||||||
|
|
||||||
|
return GameJoinStatus.OPEN;
|
||||||
|
}
|
||||||
|
|
||||||
|
@EventHandler(priority = EventPriority.LOW)
|
||||||
|
public void adminOP(PlayerJoinEvent event)
|
||||||
|
{
|
||||||
|
event.getPlayer().setOp(_clientManager.Get(event.getPlayer()).hasPermission(Perm.AUTO_OP));
|
||||||
|
}
|
||||||
|
|
||||||
public boolean IsAlive(Player player)
|
public boolean IsAlive(Player player)
|
||||||
{
|
{
|
||||||
|
@ -14,7 +14,7 @@ import org.bukkit.event.player.PlayerQuitEvent;
|
|||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
|
|
||||||
import mineplex.core.common.util.UtilServer;
|
import mineplex.core.common.util.UtilServer;
|
||||||
import mineplex.core.game.region.GameRejoinManager;
|
import mineplex.core.game.rejoin.GameRejoinManager;
|
||||||
|
|
||||||
import nautilus.game.arcade.ArcadeManager;
|
import nautilus.game.arcade.ArcadeManager;
|
||||||
import nautilus.game.arcade.game.GameTeam;
|
import nautilus.game.arcade.game.GameTeam;
|
||||||
|
Loading…
Reference in New Issue
Block a user