From 0b4d2173030df8228f667cd0ddc6fd42b5ffa5e7 Mon Sep 17 00:00:00 2001 From: cnr Date: Mon, 26 Dec 2016 22:34:09 -0700 Subject: [PATCH 1/3] Reduce number of redis requests by communities --- .../core/communities/CommunityManager.java | 13 +--- .../storage/CommunityRepository.java | 61 +++++++++++-------- .../serverdata/data/DataRepository.java | 3 +- .../serverdata/redis/RedisDataRepository.java | 13 ++-- 4 files changed, 48 insertions(+), 42 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java index c465a7ce8..509c65f57 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/CommunityManager.java @@ -84,9 +84,7 @@ public class CommunityManager extends MiniDbClientPlugin private boolean _us; private volatile boolean _cycling = false; - - private volatile boolean _updateJoinRequests = false; - + @SuppressWarnings("deprecation") public CommunityManager(JavaPlugin plugin, CoreClientManager clientManager) { @@ -141,13 +139,8 @@ public class CommunityManager extends MiniDbClientPlugin LinkedList communities = new LinkedList<>(); _loadedCommunities.values().forEach(community -> communities.add(community)); - _repo.updateMembers(communities); - if (_updateJoinRequests) - { - _repo.updateJoinRequests(communities); - } - _updateJoinRequests = !_updateJoinRequests; - }, 0L, 20 * 7); + _repo.updateMembersAndJoinRequests(communities); + }, 0L, 20 * 10); Bukkit.getScheduler().scheduleSyncRepeatingTask(plugin, () -> { diff --git a/Plugins/Mineplex.Core/src/mineplex/core/communities/storage/CommunityRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/communities/storage/CommunityRepository.java index 8c86d5b86..0e4844cf3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/communities/storage/CommunityRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/communities/storage/CommunityRepository.java @@ -2,13 +2,13 @@ package mineplex.core.communities.storage; import java.sql.Connection; import java.sql.SQLException; -import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.UUID; import java.util.stream.Collectors; +import java.util.stream.Stream; import org.bukkit.plugin.java.JavaPlugin; @@ -143,22 +143,32 @@ public class CommunityRepository extends MinecraftRepository e.printStackTrace(); } } - - public void updateMembers(LinkedList communities) + + public void updateMembersAndJoinRequests(List communities) { if (communities.isEmpty()) { return; } - TimingManager.start("member elements"); + + TimingManager.start("members + join requests"); + Map statuses = _repo.getElementsMap( + Stream.concat( + communities.stream().flatMap(community -> community.getMembers().keySet().stream()), + communities.stream().flatMap(community -> community.getJoinRequests().keySet().stream()) + ) + .distinct() + .map(UUID::toString) + .collect(Collectors.toList()) + ); + for (Community c : communities) { - List members = new ArrayList<>(c.getMembers().values()); - List statuses = _repo.getElementsSequential(members.stream().map(info -> info.UUID.toString()).collect(Collectors.toList())); - for (int i = 0; i < members.size(); i++) + // Update member player status + for (Map.Entry entry : c.getMembers().entrySet()) { - CommunityMemberInfo info = members.get(i); - PlayerStatus status = statuses.get(i); + CommunityMemberInfo info = entry.getValue(); + PlayerStatus status = statuses.get(entry.getKey().toString()); boolean online = false; String server = ""; @@ -180,25 +190,13 @@ public class CommunityRepository extends MinecraftRepository } } } - } - TimingManager.stop("member elements"); - } - - public void updateJoinRequests(LinkedList communities) - { - if (communities.isEmpty()) - { - return; - } - TimingManager.start("request elements"); - for (Community c : communities) - { - List requests = new ArrayList<>(c.getJoinRequests().values()); - List statuses = _repo.getElementsSequential(requests.stream().map(info -> info.UUID.toString()).collect(Collectors.toList())); - for (int i = 0; i < requests.size(); i++) + + // Update join request names + for (Map.Entry entry : c.getJoinRequests().entrySet()) { - CommunityJoinRequestInfo info = requests.get(i); - PlayerStatus status = statuses.get(i); + + CommunityJoinRequestInfo info = entry.getValue(); + PlayerStatus status = statuses.get(entry.getKey().toString()); if (status != null) { @@ -209,6 +207,15 @@ public class CommunityRepository extends MinecraftRepository } } } + TimingManager.stop("members + join requests"); + } + + public void updateJoinRequests(LinkedList communities) + { + if (communities.isEmpty()) + { + return; + } TimingManager.stop("request elements"); } diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/DataRepository.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/DataRepository.java index cdac8d117..03500ca2a 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/DataRepository.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/data/DataRepository.java @@ -2,6 +2,7 @@ package mineplex.serverdata.data; import java.util.Collection; import java.util.List; +import java.util.Map; /** * DataRepository is used to store {@link Data} objects in a central database @@ -19,7 +20,7 @@ public interface DataRepository public Collection getElements(Collection dataIds); - public List getElementsSequential(List dataIds); + public Map getElementsMap(List dataIds); public void addElement(T element, int timeout); diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/RedisDataRepository.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/RedisDataRepository.java index 46e74fc6b..55f3a2d58 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/RedisDataRepository.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/redis/RedisDataRepository.java @@ -2,8 +2,10 @@ package mineplex.serverdata.redis; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.HashSet; import java.util.List; +import java.util.Map; import java.util.Set; import mineplex.serverdata.Region; @@ -104,9 +106,9 @@ public class RedisDataRepository extends RedisRepository impleme } @Override - public List getElementsSequential(List dataIds) + public Map getElementsMap(List dataIds) { - List elements = new ArrayList<>(); + Map elements = new HashMap<>(); try(Jedis jedis = getResource(false)) { @@ -121,12 +123,15 @@ public class RedisDataRepository extends RedisRepository impleme // Block until all requests have received pipelined responses pipeline.sync(); - for (Response response : responses) + for (int i = 0; i < responses.size(); i++) { + String key = dataIds.get(i); + + Response response = responses.get(i); String serializedData = response.get(); T element = deserialize(serializedData); - elements.add(element); + elements.put(key, element); } } From d3bcc77e01968906fd774ca9024cc98a8d32d132 Mon Sep 17 00:00:00 2001 From: cnr Date: Mon, 26 Dec 2016 22:43:32 -0700 Subject: [PATCH 2/3] Enable double XP + gems for the holidays --- .../src/nautilus/game/arcade/game/Game.java | 2 +- .../src/nautilus/game/arcade/managers/GameRewardManager.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java index d2864e5e5..b41df5c9c 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/game/Game.java @@ -292,7 +292,7 @@ public abstract class Game implements Listener public long PrepareTime = 9000; public boolean PlaySoundGameStart = true; - public double XpMult = 1; + public double XpMult = 2; public boolean SpeedMeasurement = false; diff --git a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameRewardManager.java b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameRewardManager.java index 4c8db7903..12d448581 100644 --- a/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameRewardManager.java +++ b/Plugins/Nautilus.Game.Arcade/src/nautilus/game/arcade/managers/GameRewardManager.java @@ -44,7 +44,7 @@ public class GameRewardManager implements Listener { ArcadeManager Manager; - boolean DoubleGem = false; + boolean DoubleGem = true; boolean TimeReward = true; public GameRewardManager(ArcadeManager manager) @@ -352,7 +352,7 @@ public class GameRewardManager implements Listener //Double Gem if (DoubleGem && game.GemDoubleEnabled) { - UtilPlayer.message(player, F.elem(C.cGreen + "+" + (earnedGems) + " Gems") + " for " + F.elem(C.cDGreen + "Double Gem Weekend")); + UtilPlayer.message(player, F.elem(C.cGreen + "+" + (earnedGems) + " Gems") + " for " + F.elem(C.cDGreen + "Holiday Double Gems")); totalGems += earnedGems; } From 3a6cef32a4f49b0a7b4cad11b0b4a7f1fd39af13 Mon Sep 17 00:00:00 2001 From: Sam Date: Sun, 25 Dec 2016 22:46:20 +0000 Subject: [PATCH 3/3] Add Gem Hunters as a catagory for the build server --- .../src/mineplex/mapparser/GameType.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java index 1f4262d28..5bc34de18 100644 --- a/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java +++ b/Plugins/Mineplex.MapParser/src/mineplex/mapparser/GameType.java @@ -2,12 +2,14 @@ package mineplex.mapparser; public enum GameType { - //Mini + // Stand Alone Other("Other"), Unknown("Unknown"), Lobby("Lobby"), Event("Mineplex Event"), + GemHunters("Gem Hunters"), + // Games BaconBrawl("Bacon Brawl"), Barbarians("A Barbarians Life"), Bridge("The Bridges"), @@ -67,13 +69,13 @@ public enum GameType UHC("Ultra Hardcore"), WitherAssault("Wither Assault"), Wizards("Wizards"), - ZombieSurvival("Zombie Survival"), + ZombieSurvival("Zombie Survival"), + // Build States Upload("Upload"), Submissions("Submissions"), InProgress("In Progress"), - None("None"); String _name;