Support the MCS in Arcade

This commit is contained in:
AlexTheCoder 2016-12-14 23:29:13 -05:00 committed by cnr
parent fe62e5a683
commit cbe1a617af
2 changed files with 119 additions and 93 deletions

View File

@ -389,7 +389,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
_progressionKitManager = new ProgressingKitManager(this);
_serverUptimeManager = new ServerUptimeManager(this);
if (GetHost() != null && !GetHost().isEmpty())
if (GetHost() != null && !GetHost().isEmpty() && !GetHost().startsWith("COM-"))
{
Bukkit.getScheduler().runTaskLater(plugin, () -> Portal.transferPlayer(GetHost(), _serverStatusManager.getCurrentServerName()), 80L);
}
@ -918,7 +918,7 @@ public class ArcadeManager extends MiniPlugin implements IRelation
return;
}
if (!GetServerConfig().PublicServer || GetServerConfig().PlayerServerWhitelist)
if (!GetServerConfig().PublicServer || GetServerConfig().PlayerServerWhitelist || _gameHostManager.isCommunityServer())
{
event.setMotd(ChatColor.GRAY + "Private");
return;

View File

@ -4,25 +4,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTime;
import mineplex.core.game.GameCategory;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.punish.PunishClient;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.gui.privateServer.PrivateServerShop;
import nautilus.game.arcade.gui.privateServer.page.GameVotingPage;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.GameMode;
@ -30,7 +11,6 @@ import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.HandlerList;
import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.event.player.PlayerCommandPreprocessEvent;
@ -40,6 +20,29 @@ import org.bukkit.event.player.PlayerLoginEvent;
import org.bukkit.event.player.PlayerQuitEvent;
import org.bukkit.plugin.Plugin;
import mineplex.core.Managers;
import mineplex.core.common.Rank;
import mineplex.core.common.util.C;
import mineplex.core.common.util.F;
import mineplex.core.common.util.UtilGear;
import mineplex.core.common.util.UtilPlayer;
import mineplex.core.common.util.UtilServer;
import mineplex.core.common.util.UtilTextBottom;
import mineplex.core.common.util.UtilTime;
import mineplex.core.communities.Community;
import mineplex.core.communities.CommunityDisbandEvent;
import mineplex.core.communities.CommunityManager;
import mineplex.core.communities.CommunityRole;
import mineplex.core.game.GameCategory;
import mineplex.core.itemstack.ItemStackFactory;
import mineplex.core.updater.UpdateType;
import mineplex.core.updater.event.UpdateEvent;
import nautilus.game.arcade.ArcadeManager;
import nautilus.game.arcade.GameType;
import nautilus.game.arcade.game.Game.GameState;
import nautilus.game.arcade.gui.privateServer.PrivateServerShop;
import nautilus.game.arcade.gui.privateServer.page.GameVotingPage;
public class GameHostManager implements Listener
{
private ArrayList<GameType> ultraGames = new ArrayList<GameType>();
@ -49,7 +52,6 @@ public class GameHostManager implements Listener
ArcadeManager Manager;
private Player _host;
private String _hostName;
private Rank _hostRank;
private long _serverStartTime = System.currentTimeMillis();
private long _serverExpireTime = 21600000;
@ -174,13 +176,13 @@ public class GameHostManager implements Listener
// Admins update
for (Player player : UtilServer.getPlayers())
{
if (player.equals(_host) || _adminList.contains(player.getName()) || Manager.GetClients().Get(player).GetRank().has(Rank.ADMIN))
if (isHost(player) || isAdmin(player, true))
{
if (Manager.GetGame() == null || Manager.GetGame().GetState() == GameState.Recruit)
giveAdminItem(player);
}
if (player.equals(_host) || (isAdmin(player, false) && isEventServer()))
if (isHost(player) || (isAdmin(player, false) && (isEventServer() || isCommunityServer())))
_lastOnline = System.currentTimeMillis();
}
}
@ -218,7 +220,18 @@ public class GameHostManager implements Listener
{
return;
}
event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, "This MPS is whitelisted.");
if (isCommunityServer())
{
if (getOwner().getMembers().containsKey(p.getUniqueId()))
{
return;
}
event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, "This MCS is whitelisted.");
}
else
{
event.disallow(PlayerLoginEvent.Result.KICK_WHITELIST, "This MPS is whitelisted.");
}
}
}
if (_blacklist.contains(p.getName()))
@ -309,7 +322,16 @@ public class GameHostManager implements Listener
return;
if (UtilTime.elapsed(_lastOnline, _expireTime))
setHostExpired(true, Manager.GetServerConfig().HostName + " has abandoned the server. Thanks for playing!");
{
if (isCommunityServer())
{
setHostExpired(true, getOwner().getName() + " has abandoned the server. Thanks for playing!");
}
else
{
setHostExpired(true, Manager.GetServerConfig().HostName + " has abandoned the server. Thanks for playing!");
}
}
else if (UtilTime.elapsed(_serverStartTime, _serverExpireTime))
setHostExpired(true, "This server has expired! Thank you for playing!");
@ -501,11 +523,23 @@ public class GameHostManager implements Listener
public boolean isAdmin(Player player, boolean includeStaff)
{
if (isCommunityServer())
{
return (getOwner().getMembers().containsKey(player.getUniqueId()) && getOwner().getMembers().get(player.getUniqueId()).Role.ordinal() <= CommunityRole.COLEADER.ordinal()) || (includeStaff && Manager.GetClients().Get(_host).GetRank().has(Rank.ADMIN));
}
return player.equals(_host) || _adminList.contains(player.getName()) || (includeStaff && Manager.GetClients().Get(player).GetRank().has(Rank.ADMIN));
}
public boolean isHost(Player player)
{
if (Manager.GetHost().startsWith("COM-"))
{
CommunityManager cmanager = Managers.get(CommunityManager.class);
int communityId = Integer.parseInt(Manager.GetHost().replace("COM-", ""));
Community c = cmanager.getLoadedCommunity(communityId);
return c.getMembers().containsKey(player.getUniqueId()) && c.getMembers().get(player.getUniqueId()).Role == CommunityRole.LEADER;
}
return player.getName().equals(Manager.GetHost());
}
@ -517,7 +551,7 @@ public class GameHostManager implements Listener
@EventHandler
public void whitelistCommand(PlayerCommandPreprocessEvent event)
{
if (_host == null || !event.getPlayer().equals(_host))
if ((_host == null || !event.getPlayer().equals(_host)) || (isCommunityServer() && getOwner().getMembers().containsKey(event.getPlayer().getUniqueId()) && getOwner().getMembers().get(event.getPlayer().getUniqueId()).Role.ordinal() <= CommunityRole.COLEADER.ordinal()))
return;
if (!event.getMessage().toLowerCase().startsWith("/whitelist"))
@ -540,64 +574,6 @@ public class GameHostManager implements Listener
}
}
}
public void setGame(GameType type)
{
if (_host == null)
return;
Manager.GetGameCreationManager().SetNextGameType(type);
//End Current
if (Manager.GetGame().GetState() == GameState.Recruit)
{
Manager.GetGame().SetState(GameState.Dead);
Bukkit.broadcastMessage(C.cGreen + C.Bold + _host.getName() + " has changed game to " + type.GetName() + ".");
}
else
{
Bukkit.broadcastMessage(C.cGreen + C.Bold + _host.getName() + " set next game to " + type.GetName() + ".");
}
}
public void startGame()
{
if (_host == null)
return;
Manager.GetGameManager().StateCountdown(Manager.GetGame(), 10, true);
Manager.GetGame().Announce(C.cGreen + C.Bold + _host.getName() + " has started the game.");
}
public void stopGame()
{
if (_host == null)
return;
if (Manager.GetGame() == null)
return;
HandlerList.unregisterAll(Manager.GetGame());
if (Manager.GetGame().GetState() == GameState.End || Manager.GetGame().GetState() == GameState.End)
{
_host.sendMessage("Game is already ending...");
return;
}
else if (Manager.GetGame().GetState() == GameState.Recruit)
{
Manager.GetGame().SetState(GameState.Dead);
}
else
{
Manager.GetGame().SetState(GameState.End);
}
Manager.GetGame().Announce(C.cGreen + C.Bold + _host.getName() + " has stopped the game.");
}
public boolean hasRank(Rank rank)
{
@ -642,8 +618,15 @@ public class GameHostManager implements Listener
public void ban(Player player)
{
_blacklist.add(player.getName());
Manager.GetPortal().sendToHub(player, "You were removed from this Mineplex Private Server.");
if (isCommunityServer())
{
Manager.GetPortal().sendToHub(player, "You were removed from this Mineplex Community Server.");
}
else
{
Manager.GetPortal().sendToHub(player, "You were removed from this Mineplex Private Server.");
}
}
@EventHandler
@ -656,7 +639,26 @@ public class GameHostManager implements Listener
{
if (_blacklist.contains(player.getName()))
{
Manager.GetPortal().sendToHub(player, "You were removed from this Mineplex Private Server.");
if (isCommunityServer())
{
Manager.GetPortal().sendToHub(player, "You were removed from this Mineplex Community Server.");
}
else
{
Manager.GetPortal().sendToHub(player, "You were removed from this Mineplex Private Server.");
}
}
}
}
@EventHandler
public void onDisband(CommunityDisbandEvent event)
{
if (isCommunityServer())
{
if (getOwner().getId() == event.getCommunity().getId())
{
setHostExpired(true, getOwner().getName() + " has disbanded and abandoned the server. Thanks for playing!");
}
}
}
@ -715,6 +717,10 @@ public class GameHostManager implements Listener
public int getMaxPlayerCap()
{
if (isCommunityServer())
{
return 100;
}
if (hasRank(Rank.SNR_MODERATOR) || _hostRank == Rank.YOUTUBE || _hostRank == Rank.TWITCH)
return 100;
else if (_hostRank == Rank.YOUTUBE_SMALL || _hostRank == Rank.ETERNAL)
@ -809,10 +815,31 @@ public class GameHostManager implements Listener
return;
String serverName = Manager.getPlugin().getConfig().getString("serverstatus.name");
UtilPlayer.message(event.getPlayer(), ChatColor.BOLD + "Welcome to Mineplex Private Servers!");
if (!isCommunityServer())
{
UtilPlayer.message(event.getPlayer(), ChatColor.BOLD + "Welcome to Mineplex Private Servers!");
}
else
{
UtilPlayer.message(event.getPlayer(), ChatColor.BOLD + "Welcome to Mineplex Community Servers!");
}
UtilPlayer.message(event.getPlayer(), C.Bold + "Friends can connect with " + C.cGreen + C.Bold + "/server " + serverName);
}
public boolean isCommunityServer()
{
return Manager.GetHost() != null && Manager.GetHost().startsWith("COM-");
}
public Community getOwner()
{
if (!isCommunityServer())
{
return null;
}
return Managers.get(CommunityManager.class).getLoadedCommunity(Integer.parseInt(Manager.GetHost().replace("COM-", "")));
}
public boolean isEventServer()
{
return _isEventServer;
@ -856,6 +883,5 @@ public class GameHostManager implements Listener
public void setHost(Player player)
{
_host = player;
}
}
}
}