From e0245b562c6d220d7c7f130130b79cb5febc5564 Mon Sep 17 00:00:00 2001 From: Dan Mulloy Date: Fri, 15 Jun 2018 12:28:52 -0400 Subject: [PATCH] Load communities in the login process, fix a few bugs --- .../core/communities/CommunityManager.java | 135 ++++++++++-------- .../core/communities/CommunityRepository.java | 16 ++- .../mineplex/core/communities/MCSTheme.java | 50 ------- .../communities/data/BrowserCommunity.java | 24 +++- .../core/communities/data/Community.java | 39 ++++- .../core/communities/data/ICommunity.java | 5 + .../buttons/CommunityVisualizationButton.java | 26 +++- .../gui/pages/CommunityInvitesPage.java | 58 +++++--- 8 files changed, 201 insertions(+), 152 deletions(-) delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/communities/MCSTheme.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java index 19e809f08..f8c9e849c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java @@ -16,7 +16,6 @@ import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; import java.util.function.Consumer; import java.util.regex.Pattern; -import java.util.stream.Collectors; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -42,7 +41,6 @@ import mineplex.core.common.util.UtilServer; import mineplex.core.communities.commands.CommunityCommand; import mineplex.core.communities.data.BrowserCommunity; import mineplex.core.communities.data.Community; -import mineplex.core.communities.data.Community.PrivacySetting; import mineplex.core.communities.data.CommunityJoinRequestInfo; import mineplex.core.communities.data.CommunityMemberData; import mineplex.core.communities.data.CommunityMemberInfo; @@ -87,7 +85,6 @@ import mineplex.core.recharge.Recharge; import mineplex.core.serverConfig.ServerConfiguration; import mineplex.serverdata.Region; import mineplex.serverdata.commands.ServerCommandManager; -import mineplex.serverdata.data.DataRepository; import mineplex.serverdata.data.PlayerStatus; import mineplex.serverdata.data.ServerGroup; import mineplex.serverdata.redis.RedisDataRepository; @@ -119,25 +116,25 @@ public class CommunityManager extends MiniDbClientPlugin public final static String CHAT_PREFIX = "!"; public final static String COMMUNITY_CHAT_KEY = "core.communities.chat.selected"; - public final static int MAX_NAME_LENGTH = 15; + private final static int MAX_NAME_LENGTH = 15; - private final int UPDATE_CYCLE_SECONDS = 10; // The number of seconds between dirty communities refreshes - private final int CACHE_INVALIDATION_SECONDS = 300; // The number of seconds between full communities refreshes - public final Pattern VALID_NAME_PATTERN = Pattern.compile("^[A-Za-z0-9]{1," + MAX_NAME_LENGTH + "}$"); + private static final int UPDATE_CYCLE_SECONDS = 10; // The number of seconds between dirty communities refreshes + private static final int CACHE_INVALIDATION_SECONDS = 300; // The number of seconds between full communities refreshes + private final Pattern VALID_NAME_PATTERN = Pattern.compile("^[A-Za-z0-9]{1," + MAX_NAME_LENGTH + "}$"); public final Pattern NON_ALPHANUMERIC_PATTERN = Pattern.compile("[^A-Za-z0-9]"); public final List BLOCKED_NAMES = Arrays.asList("help", "chat", "create", "description", "disband", "invite", "join", "mcs", "rename", "uninvite", "trainee", "mod", "moderator", "srmod", "seniormod", "seniormoderator", "builder", "maplead", "twitch", "youtube", "support", "admin", "administrator", "leader", "dev", "developer", "owner", "party", "mineplex", "mineplexofficial", "staff", "mineplexstaff", "qualityassurance", "traineemanagement", "modcoordination", "forumninja", "communitymanagement", "event", "socialmedia"); private final CommunityRepository _repo; - private final Map _loadedCommunities; - private final Map _browserCommunities; + private final Map _loadedCommunities = new ConcurrentHashMap<>(); + private final Map _browserCommunities = new ConcurrentHashMap<>(); private final Random _rand = new Random(); private final List _browserIds = new LinkedList<>(); private final List _creating = new ArrayList<>(); - private Integer mcsCommunity = null; - private boolean _us; + private Integer _mcsCommunity = null; + private Region _region; private final Set _dirty = Collections.newSetFromMap(new ConcurrentHashMap<>()); // Communities with redis updates @@ -149,20 +146,16 @@ public class CommunityManager extends MiniDbClientPlugin private final CoreClientManager _clientManager; private final CustomDataManager _customDataManager; - @SuppressWarnings("deprecation") + @SuppressWarnings({"deprecation", "unchecked"}) private CommunityManager() { super("Communities"); - DataRepository statusRepo = new RedisDataRepository<>(ServerManager.getMasterConnection(), + RedisDataRepository statusRepo = new RedisDataRepository<>(ServerManager.getMasterConnection(), ServerManager.getSlaveConnection(), Region.currentRegion(), PlayerStatus.class, "playerStatus"); - _us = _plugin.getConfig().getBoolean("serverstatus.us"); - - _repo = new CommunityRepository(_plugin, statusRepo, _us); - - _loadedCommunities = new ConcurrentHashMap<>(); - _browserCommunities = new ConcurrentHashMap<>(); + _region = Region.currentRegion(); + _repo = new CommunityRepository(statusRepo, _region); runAsync(() -> { @@ -189,7 +182,7 @@ public class CommunityManager extends MiniDbClientPlugin while (resultSet.next()) { String region = resultSet.getString("region"); - if ((_us && region.equalsIgnoreCase("US")) || (!_us && region.equalsIgnoreCase("EU"))) + if (region.equalsIgnoreCase(_region.name())) { CommunityManager.this.Get(uuid).Invites.add(resultSet.getInt("communityId")); } @@ -225,12 +218,12 @@ public class CommunityManager extends MiniDbClientPlugin ServerGroup group = require(ServerConfiguration.class).getServerGroup(); if (group.getName().startsWith("COM-")) { - mcsCommunity = Integer.valueOf(group.getName().split("-")[1]); + _mcsCommunity = Integer.valueOf(group.getName().split("-")[1]); - Community community = getLoadedCommunity(mcsCommunity); + Community community = getLoadedCommunity(_mcsCommunity); if (community == null) { - _repo.loadCommunity(_loadedCommunities, mcsCommunity); + _repo.loadCommunity(_loadedCommunities, _mcsCommunity); } } @@ -343,20 +336,30 @@ public class CommunityManager extends MiniDbClientPlugin public void loadBrowserCommunities(final List displaying, final Runnable onComplete) { - runAsync(() -> + final List load = new ArrayList<>(displaying.size()); + for (Integer id : displaying) { - List load = new ArrayList<>(displaying.size()); - for (Integer id : displaying) + if (!_loadedCommunities.containsKey(id) && !_browserCommunities.containsKey(id)) { - if (!_loadedCommunities.containsKey(id) && !_browserCommunities.containsKey(id)) - { - load.add(id); - } + load.add(id); } + } - _repo.loadBrowserCommunities(_browserCommunities, load); + if (!load.isEmpty()) + { + runAsync(() -> + { + _repo.loadBrowserCommunities(_browserCommunities, load); + + if (onComplete != null) + { + runSync(onComplete); + } + }); + } else if (onComplete != null) + { runSync(onComplete); - }); + } } public void tempLoadCommunity(final int id, final Consumer consumer) @@ -377,10 +380,9 @@ public class CommunityManager extends MiniDbClientPlugin return community != null ? community : _browserCommunities.get(id); } - public void updateBrowserStatus(Community community) + private void updateBrowserStatus(ICommunity community) { - _repo.updateBrowserStatus(community, community.getPrivacySetting() != PrivacySetting.PRIVATE - && community.getMembers().size() >= 5); + _repo.updateBrowserStatus(community, community.isBrowserEligible()); } public int getCount() @@ -676,7 +678,7 @@ public class CommunityManager extends MiniDbClientPlugin public void handleInvite(Player sender, Community community, String target) { - CommunityJoinRequestInfo[] jr = community.getJoinRequests().values().stream().filter(data -> data.Name.equalsIgnoreCase(target)).toArray(size -> new CommunityJoinRequestInfo[size]); + CommunityJoinRequestInfo[] jr = community.getJoinRequests().values().stream().filter(data -> data.Name.equalsIgnoreCase(target)).toArray(CommunityJoinRequestInfo[]::new); if (jr.length == 1) { UtilPlayer.message(sender, F.main(getName(), "You have accepted " + F.name(target) + "'s join request to " + F.name(community.getName()) + "!")); @@ -725,15 +727,15 @@ public class CommunityManager extends MiniDbClientPlugin }); } - public void handleRejectInvite(Player sender, Community community) + public void handleRejectInvite(Player sender, int id) { final String playerName = _clientManager.Get(sender).getName(); runAsync(() -> { - _repo.deleteInviteToCommunity(community.getId(), playerName); + _repo.deleteInviteToCommunity(id, playerName); }); - new CommunityUnInvite(community.getId(), sender.getName(), sender.getName(), sender.getUniqueId().toString(), false).publish(); + new CommunityUnInvite(id, sender.getName(), sender.getName(), sender.getUniqueId().toString(), false).publish(); } public void handleJoinRequest(Player sender, Community community) @@ -768,7 +770,7 @@ public class CommunityManager extends MiniDbClientPlugin new CommunityCloseJoinRequest(community.getId(), sender.getName(), info.Name, info.UUID.toString(), info.AccountId, announce).publish(); } - public void handleJoin(Player sender, Community community, boolean fromInvite) + public void handleJoin(Player sender, ICommunity community, boolean fromInvite) { final int accountId = _clientManager.getAccountId(sender); final String playerName = _clientManager.Get(sender).getName(); @@ -780,6 +782,8 @@ public class CommunityManager extends MiniDbClientPlugin _repo.deleteInviteToCommunity(community.getId(), playerName); } updateBrowserStatus(community); + _repo.handlePlayerJoin(_loadedCommunities, Collections.singletonList(community.getId()), accountId); + _browserCommunities.remove(community.getId()); }); new CommunityUpdateMembership(community.getId(), sender.getName(), sender.getName(), sender.getUniqueId().toString(), accountId, false, false).publish(); if (fromInvite) @@ -901,18 +905,36 @@ public class CommunityManager extends MiniDbClientPlugin @Override public void processLoginResultSet(String playerName, UUID uuid, int accountId, ResultSet resultSet) throws SQLException { + List load = new ArrayList<>(); CommunityMemberData data = new CommunityMemberData(); while (resultSet.next()) { Integer communityId = resultSet.getInt("communityId"); CommunityRole role = CommunityRole.parseRole(resultSet.getString("communityRole")); String region = resultSet.getString("region"); - if ((_us && region.equalsIgnoreCase("US")) || (!_us && region.equalsIgnoreCase("EU"))) + if (region.equalsIgnoreCase(_region.name())) { data.joinCommunity(communityId, role); + if (getLoadedCommunity(communityId) == null) + { + load.add(communityId); + } } } Set(uuid, data); + + if (!load.isEmpty()) + { + _browserCommunities.keySet().removeAll(load); + _repo.handlePlayerJoin(_loadedCommunities, load, accountId); + System.out.println("Loaded communities: " + load + "; Total: " + _loadedCommunities.size()); + } + + System.out.println("invites = " + data.Invites); // TODO debug + if (!data.Invites.isEmpty()) + { + loadBrowserCommunities(data.Invites, null); + } } @EventHandler(priority = EventPriority.LOW, ignoreCancelled = true) @@ -992,44 +1014,25 @@ public class CommunityManager extends MiniDbClientPlugin { UtilPlayer.message(event.getPlayer(), F.main(getName(), "You have been invited to join " + F.elem(data.Invites.size()) + " communities!")); } - - Set communityIds = data.getCommunityIds(); - - final List load = communityIds.stream().filter(id -> getLoadedCommunity(id) == null).collect(Collectors.toList()); - if (load.isEmpty()) - { - return; - } - - final int accountId = _clientManager.getAccountId(player); - - _browserCommunities.keySet().removeAll(load); - - runAsync(() -> - { - _repo.handlePlayerJoin(_loadedCommunities, load, accountId); - System.out.println("Loaded communities: " + load + "; Total: " + _loadedCommunities.size()); - }); } @EventHandler(priority = EventPriority.LOW) public void onPlayerQuit(PlayerQuitEvent event) { // Remove their communities from memory if they're the last player + List unloaded = new ArrayList<>(); Player player = event.getPlayer(); List communities = Get(player).getCommunities(); for (Community community : communities) { - if (community.getId().equals(mcsCommunity) + if (community.getId().equals(_mcsCommunity) || community.getMembers().keySet().stream().anyMatch(uuid -> !player.getUniqueId().equals(uuid) && Bukkit.getPlayer(uuid) != null)) { continue; } - System.out.println("Unloading community: " + community.getId()); - // If it's a browser community, keep some of the data - if (community.isBrowserEilgible()) + if (community.isBrowserEligible()) { _browserCommunities.put(community.getId(), community.toBrowser()); } @@ -1037,6 +1040,12 @@ public class CommunityManager extends MiniDbClientPlugin // Unload this community from memory _dirty.remove(community); _loadedCommunities.remove(community.getId()); + unloaded.add(community.getId()); + } + + if (!unloaded.isEmpty()) + { + System.out.println("Unloaded communities: " + unloaded + "; Total: " + _loadedCommunities.size()); } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityRepository.java index 77ff0c236..40019631c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityRepository.java @@ -22,7 +22,9 @@ import mineplex.core.communities.data.CommunityJoinRequestInfo; import mineplex.core.communities.data.CommunityMemberInfo; import mineplex.core.communities.data.CommunityRole; import mineplex.core.communities.data.CommunitySetting; +import mineplex.core.communities.data.ICommunity; import mineplex.core.game.GameDisplay; +import mineplex.serverdata.Region; import mineplex.serverdata.data.DataRepository; import mineplex.serverdata.data.PlayerStatus; import mineplex.serverdata.database.DBPool; @@ -30,6 +32,7 @@ import mineplex.serverdata.database.RepositoryBase; import mineplex.serverdata.database.column.ColumnBoolean; import mineplex.serverdata.database.column.ColumnInt; import mineplex.serverdata.database.column.ColumnVarChar; +import mineplex.serverdata.redis.RedisDataRepository; public class CommunityRepository extends RepositoryBase { @@ -55,14 +58,14 @@ public class CommunityRepository extends RepositoryBase private static final String SET_READING_CHAT_IN = "UPDATE communityMembers SET readingChat=? WHERE accountId=? AND communityId=?;"; private DataRepository _repo; - private boolean _us; + private Region _region; - public CommunityRepository(JavaPlugin plugin, DataRepository statusRepo, boolean us) + public CommunityRepository(RedisDataRepository statusRepo, Region region) { super(DBPool.getAccount()); _repo = statusRepo; - _us = us; + _region = region; } public void communityExists(String name, Consumer result) @@ -188,7 +191,7 @@ public class CommunityRepository extends RepositoryBase updateMembersAndJoinRequests(communities); } - public void updateBrowserStatus(Community community, boolean flag) + public void updateBrowserStatus(ICommunity community, boolean flag) { updateCommunitySetting(CommunitySetting.SHOW_IN_BROWSER, community.getId(), String.valueOf(flag)); } @@ -285,7 +288,8 @@ public class CommunityRepository extends RepositoryBase { if (!com.isBrowserFlagSet()) { - updateBrowserStatus(com, com.isBrowserEilgible()); + updateBrowserStatus(com, com.isBrowserEligible()); + com.setBrowserFlag(); } } } @@ -444,7 +448,7 @@ public class CommunityRepository extends RepositoryBase { idCallback.run(-1); } - }, () -> idCallback.run(-1), new ColumnVarChar("name", 15, name), new ColumnVarChar("region", 5, _us ? "US" : "EU")); + }, () -> idCallback.run(-1), new ColumnVarChar("name", 15, name), new ColumnVarChar("region", 5, _region.name())); } catch (SQLException e) { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/MCSTheme.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/MCSTheme.java deleted file mode 100644 index c62056dd7..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/MCSTheme.java +++ /dev/null @@ -1,50 +0,0 @@ -package mineplex.core.communities; - -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/data/BrowserCommunity.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/data/BrowserCommunity.java index 018f838fc..c071c4b60 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/data/BrowserCommunity.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/data/BrowserCommunity.java @@ -1,5 +1,7 @@ package mineplex.core.communities.data; +import com.google.common.base.Preconditions; + import mineplex.core.game.GameDisplay; public class BrowserCommunity implements ICommunity @@ -15,6 +17,9 @@ public class BrowserCommunity implements ICommunity { _id = id; _name = name; + _description = "No Description Set"; + _favoriteGame = GameDisplay.ChampionsCTF; + _privacySetting = Community.PrivacySetting.RECRUITING; } @Override @@ -61,19 +66,19 @@ public class BrowserCommunity implements ICommunity public BrowserCommunity setDescription(String description) { - _description = description; + _description = Preconditions.checkNotNull(description); return this; } public BrowserCommunity setFavoriteGame(GameDisplay favoriteGame) { - _favoriteGame = favoriteGame; + _favoriteGame = Preconditions.checkNotNull(favoriteGame); return this; } public BrowserCommunity setPrivacySetting(Community.PrivacySetting privacySetting) { - _privacySetting = privacySetting; + _privacySetting = Preconditions.checkNotNull(privacySetting); return this; } @@ -88,4 +93,17 @@ public class BrowserCommunity implements ICommunity { return o == this || (o instanceof BrowserCommunity && ((BrowserCommunity) o)._id == _id); } + + @Override + public String toString() + { + return "BrowserCommunity{" + + "_id=" + _id + + ", _members=" + _members + + ", _name='" + _name + '\'' + + ", _description='" + _description + '\'' + + ", _favoriteGame=" + _favoriteGame + + ", _privacySetting=" + _privacySetting + + '}'; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/data/Community.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/data/Community.java index 9eb2c183d..0db3e0183 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/data/Community.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/data/Community.java @@ -1,6 +1,7 @@ package mineplex.core.communities.data; import java.util.Map; +import java.util.Objects; import java.util.UUID; import java.util.concurrent.ConcurrentHashMap; @@ -152,11 +153,6 @@ public class Community implements ICommunity .setMembers(getMemberCount()); } - public boolean isBrowserEilgible() - { - return getMemberCount() >= 5 && getPrivacySetting() != PrivacySetting.PRIVATE; - } - public enum PrivacySetting { OPEN("Open to Join"), @@ -188,5 +184,38 @@ public class Community implements ICommunity return PrivacySetting.RECRUITING; } + + @Override + public String toString() + { + return _display; + } + } + + @Override + public boolean equals(Object o) + { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Community community = (Community) o; + return _id == community._id; + } + + @Override + public int hashCode() + { + return Objects.hash(_id); + } + + @Override + public String toString() + { + return "Community{" + + "_id=" + _id + + ", _name='" + _name + '\'' + + ", _description='" + _description + '\'' + + ", _favoriteGame=" + _favoriteGame + + ", _privacy=" + _privacy + + '}'; } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/data/ICommunity.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/data/ICommunity.java index dc06eb1d0..d40c7912b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/data/ICommunity.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/data/ICommunity.java @@ -15,4 +15,9 @@ public interface ICommunity GameDisplay getFavoriteGame(); Community.PrivacySetting getPrivacySetting(); + + default boolean isBrowserEligible() + { + return getPrivacySetting() != Community.PrivacySetting.PRIVATE && getMemberCount() >= 5; + } } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/gui/buttons/CommunityVisualizationButton.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/gui/buttons/CommunityVisualizationButton.java index 3f96aa60d..269d2ce9d 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/gui/buttons/CommunityVisualizationButton.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/gui/buttons/CommunityVisualizationButton.java @@ -9,16 +9,17 @@ import mineplex.core.common.util.C; import mineplex.core.common.util.LineFormat; import mineplex.core.common.util.UtilText; import mineplex.core.communities.data.Community; +import mineplex.core.communities.data.ICommunity; import mineplex.core.communities.gui.pages.CommunityMembersPage; import mineplex.core.itemstack.ItemBuilder; public class CommunityVisualizationButton extends CommunitiesGUIButton { private Player _viewer; - private Community _community; + private ICommunity _community; private boolean _invite; - public CommunityVisualizationButton(Player viewer, Community community, boolean invite) + public CommunityVisualizationButton(Player viewer, ICommunity community, boolean invite) { super(new ItemBuilder(Material.BARRIER).build()); @@ -28,15 +29,25 @@ public class CommunityVisualizationButton extends CommunitiesGUIButton update(); } - @SuppressWarnings("deprecation") @Override public void update() { - ItemBuilder builder = new ItemBuilder(new ItemStack(_community.getFavoriteGame().getMaterial(), 1, _community.getFavoriteGame().getMaterialData(), null)).setTitle(C.cGreenB + _community.getName()).addLore(UtilText.splitLinesToArray(new String[] {C.cRed, C.cYellow + "Members " + C.cWhite + _community.getMembers().size(), C.cYellow + "Favorite Game " + C.cWhite + _community.getFavoriteGame().getName(), C.cYellow + "Description " + C.cWhite + _community.getDescription()}, LineFormat.LORE)); + ItemBuilder builder = new ItemBuilder(new ItemStack(_community.getFavoriteGame().getMaterial(), 1, _community.getFavoriteGame().getMaterialData())) + .setTitle(C.cGreenB + _community.getName()) + .addLore(UtilText.splitLinesToArray(new String[] { + C.cRed, + C.cYellow + "Members " + C.cWhite + _community.getMemberCount(), + C.cYellow + "Favorite Game " + C.cWhite + _community.getFavoriteGame().getName(), + C.cYellow + "Description " + C.cWhite + _community.getDescription()}, LineFormat.LORE)); + if (_invite) { - builder.addLore(UtilText.splitLinesToArray(new String[] {C.cGold, C.cYellow + "Shift-Left Click " + C.cWhite + "Join", C.cYellow + "Shift-Right Click " + C.cWhite + "Decline"}, LineFormat.LORE)); + builder.addLore(UtilText.splitLinesToArray(new String[] { + C.cGold, + C.cYellow + "Shift-Left Click " + C.cWhite + "Join", + C.cYellow + "Shift-Right Click " + C.cWhite + "Decline"}, LineFormat.LORE)); } + builder.addLore(C.cBlue, C.cGreen + "Click to view community"); Button = builder.build(); } @@ -46,7 +57,7 @@ public class CommunityVisualizationButton extends CommunitiesGUIButton { if (_invite && type == ClickType.SHIFT_RIGHT) { - getCommunityManager().handleRejectInvite(_viewer, _community); + getCommunityManager().handleRejectInvite(_viewer, _community.getId()); } else if (_invite && type == ClickType.SHIFT_LEFT) { @@ -54,7 +65,8 @@ public class CommunityVisualizationButton extends CommunitiesGUIButton } else { - new CommunityMembersPage(_viewer, _community).open(); + getCommunityManager().tempLoadCommunity(_community.getId(), community -> + new CommunityMembersPage(_viewer, community)); } } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/gui/pages/CommunityInvitesPage.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/gui/pages/CommunityInvitesPage.java index 3122547d9..4d0239f54 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/gui/pages/CommunityInvitesPage.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/gui/pages/CommunityInvitesPage.java @@ -1,10 +1,17 @@ package mineplex.core.communities.gui.pages; +import java.util.List; + +import org.bukkit.DyeColor; import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; +import org.bukkit.inventory.ItemStack; import mineplex.core.common.util.C; +import mineplex.core.communities.CommunityManager; +import mineplex.core.communities.data.CommunityMemberData; +import mineplex.core.communities.data.ICommunity; import mineplex.core.communities.events.CommunityDisbandEvent; import mineplex.core.communities.events.CommunityMemberDataUpdateEvent; import mineplex.core.communities.gui.buttons.ActionButton; @@ -70,29 +77,44 @@ public class CommunityInvitesPage extends CommunitiesGUIPage Buttons.put(53, next); Inv.setItem(53, next.Button); } - - int slot = 18; - boolean cleared = false; - for (int i = (page - 1) * COMMUNITIES_PER_PAGE; i < (page - 1) * COMMUNITIES_PER_PAGE + COMMUNITIES_PER_PAGE && i < getCommunityManager().Get(Viewer).Invites.size(); i++) + + final CommunityManager manager = getCommunityManager(); + final List invites = manager.Get(Viewer).Invites; + + manager.loadBrowserCommunities(invites, () -> { - if (!cleared && !initial) + int slot = 18; + boolean cleared = false; + for (int i = (page - 1) * COMMUNITIES_PER_PAGE; i < (page - 1) * COMMUNITIES_PER_PAGE + COMMUNITIES_PER_PAGE && i < invites.size(); i++) { - cleared = true; - _page = page; - for (int clear = 18; clear < 45; clear++) + if (!cleared && !initial) { - Buttons.remove(clear); - Inv.setItem(clear, null); + cleared = true; + _page = page; + for (int clear = 18; clear < 45; clear++) + { + Buttons.remove(clear); + Inv.setItem(clear, null); + } } + + int communityId = invites.get(i); + ICommunity community = manager.getBrowserCommunity(communityId); + if (community == null) + { + Inv.setItem(slot, new ItemStack(Material.INK_SACK, 1, DyeColor.GRAY.getDyeData())); + } else + { + CommunityVisualizationButton button = new CommunityVisualizationButton(Viewer, community, true); + Buttons.put(slot, button); + Inv.setItem(slot, button.Button); + } + + slot++; } - CommunityVisualizationButton button = new CommunityVisualizationButton(Viewer, getCommunityManager().getLoadedCommunity(getCommunityManager().Get(Viewer).Invites.get(i)), true); - Buttons.put(slot, button); - Inv.setItem(slot, button.Button); - - slot++; - } - - Viewer.updateInventory(); + + Viewer.updateInventory(); + }); } @EventHandler