From bd4fa1f2d421b9e5f8809b77a7030360c586d845 Mon Sep 17 00:00:00 2001 From: AlexTheCoder Date: Wed, 14 Dec 2016 23:28:26 -0500 Subject: [PATCH] Convert to MCS system for community servers and add a command to open them --- .../core/communities/CommunityManager.java | 9 ++++ .../commands/CommunityCommand.java | 2 + .../commands/CommunityMCSCommand.java | 49 ++++++++++++++++++ .../core/communities/mcs/MCSTheme.java | 50 +++++++++++++++++++ .../mps/{MPSTheme.java => MCSTheme.java} | 0 5 files changed, 110 insertions(+) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/communities/commands/CommunityMCSCommand.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/communities/mcs/MCSTheme.java rename Plugins/Mineplex.Core/src/mineplex/core/communities/mps/{MPSTheme.java => MCSTheme.java} (100%) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java index fc845eb61..b0fd5c4db 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java @@ -49,6 +49,7 @@ import mineplex.serverdata.data.DataRepository; import mineplex.serverdata.data.PlayerStatus; import mineplex.serverdata.redis.RedisDataRepository; import mineplex.serverdata.servers.ServerManager; +import mineplex.serverdata.servers.ServerRepository; public class CommunityManager extends MiniDbClientPlugin { @@ -59,6 +60,9 @@ public class CommunityManager extends MiniDbClientPlugin public final DataRepository StatusRepository; + private ServerRepository _serverRepo; + private boolean _us; + private boolean _cycling = false; @SuppressWarnings("deprecation") @@ -69,6 +73,11 @@ public class CommunityManager extends MiniDbClientPlugin StatusRepository = new RedisDataRepository(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(), Region.currentRegion(), PlayerStatus.class, "playerStatus"); + _us = plugin.getConfig().getBoolean("serverstatus.us"); + + Region region = _us ? Region.US : Region.EU; + _serverRepo = ServerManager.getServerRepository(region); + _repo = new CommunityRepository(plugin, StatusRepository); _loadedCommunities = new HashMap<>(); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/commands/CommunityCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/commands/CommunityCommand.java index 4929f8d6a..1f75b3d2d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/commands/CommunityCommand.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/commands/CommunityCommand.java @@ -21,6 +21,7 @@ public class CommunityCommand extends MultiCommandBase AddCommand(new CommunityDescriptionCommand(plugin)); AddCommand(new CommunityDisbandCommand(plugin)); AddCommand(new CommunityInviteCommand(plugin)); + AddCommand(new CommunityMCSCommand(plugin)); AddCommand(new CommunityMenuCommand(plugin)); AddCommand(new CommunityRenameCommand(plugin)); AddCommand(new CommunityUnInviteCommand(plugin)); @@ -50,6 +51,7 @@ public class CommunityCommand extends MultiCommandBase UtilPlayer.message(caller, F.help("/com chat ", "Selects which community you chat to", Rank.ALL)); UtilPlayer.message(caller, F.help("/com create ", "Creates a new community", Rank.ETERNAL)); UtilPlayer.message(caller, F.help("/com rename ", "Changes the name of a community you own", Rank.ETERNAL)); + UtilPlayer.message(caller, F.help("/com mcs ", "Opens the Mineplex Community Server of a community you manage", Rank.ALL)); UtilPlayer.message(caller, F.help("/com description ", "Sets the description of a community you manage", Rank.ALL)); UtilPlayer.message(caller, F.help("/com disband ", "Disbands a community you own", Rank.ETERNAL)); } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/commands/CommunityMCSCommand.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/commands/CommunityMCSCommand.java new file mode 100644 index 000000000..715078187 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/commands/CommunityMCSCommand.java @@ -0,0 +1,49 @@ +package mineplex.core.communities.commands; + +import org.bukkit.entity.Player; + +import mineplex.core.Managers; +import mineplex.core.account.CoreClientManager; +import mineplex.core.command.CommandBase; +import mineplex.core.common.Rank; +import mineplex.core.common.util.F; +import mineplex.core.common.util.UtilPlayer; +import mineplex.core.communities.Community; +import mineplex.core.communities.CommunityManager; +import mineplex.core.communities.CommunityMemberInfo; +import mineplex.core.communities.CommunityRole; +import mineplex.core.personalServer.PersonalServerManager; + +public class CommunityMCSCommand extends CommandBase +{ + public CommunityMCSCommand(CommunityManager plugin) + { + super(plugin, Rank.ALL, "mcs"); + } + + @Override + public void Execute(Player caller, String[] args) + { + if (args.length < 1) + { + UtilPlayer.message(caller, F.help("/com mcs ", "Opens the Mineplex Community Server of a community you manage", Rank.ALL)); + return; + } + Community c = Plugin.getLoadedCommunity(args[0]); + if (c == null) + { + UtilPlayer.message(caller, F.main(Plugin.getName(), "That community was not found!")); + return; + } + if (c.getMembers().getOrDefault(caller, new CommunityMemberInfo(caller.getName(), caller.getUniqueId(), -1, CommunityRole.MEMBER, -1L)).Role.ordinal() <= CommunityRole.COLEADER.ordinal()) + { + if (!Managers.get(CoreClientManager.class).Get(caller).GetRank().has(Rank.ADMIN)) + { + UtilPlayer.message(caller, F.main(Plugin.getName(), "You are not a co-leader of " + F.name(c.getName()) + "!")); + return; + } + } + + Managers.get(PersonalServerManager.class).hostCommunityServer(caller, c); + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/mcs/MCSTheme.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/mcs/MCSTheme.java new file mode 100644 index 000000000..d841c5cc5 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/mcs/MCSTheme.java @@ -0,0 +1,50 @@ +package mineplex.core.communities.mps; + +import org.bukkit.Material; + +import mineplex.core.common.util.C; + +public enum MCSTheme +{ + CANDYLAND(1, C.cPurple + "Candyland", Material.COOKIE, 1000, "Lobby_MPS_Candyland.zip") + ; + + private final int _id; + private final String _displayName, _file; + private final Material _displayType; + private final int _cost; + + private MCSTheme(int id, String displayName, Material displayType, int cost, String file) + { + _id = id; + _displayName = displayName; + _displayType = displayType; + _cost = cost; + _file = file; + } + + public int getId() + { + return _id; + } + + public String getDisplayName() + { + return _displayName; + } + + public Material getDisplayType() + { + return _displayType; + } + + public int getCost() + { + return _cost; + } + + public String getFile() + { + return _file; + } +} \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/mps/MPSTheme.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/mps/MCSTheme.java similarity index 100% rename from Plugins/Mineplex.Core/src/mineplex/core/communities/mps/MPSTheme.java rename to Plugins/Mineplex.Core/src/mineplex/core/communities/mps/MCSTheme.java