From 60010f90b466065596fd14b6a913f1c782ee7d08 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Mon, 4 Apr 2016 13:47:45 -0500 Subject: [PATCH] Load simple clan token on player login to reduce overhead. Increased dbpool connections to 4 --- .../mineplex/hub/server/ServerManager.java | 45 ++++++++++++++----- .../server/ui/clans/ClanMoveServerShop.java | 1 - .../hub/server/ui/clans/ClansServerPage.java | 41 ++++------------- .../hub/server/ui/clans/ClansServerShop.java | 2 +- .../mineplex/serverdata/database/DBPool.java | 4 +- .../serverdata/database/RepositoryBase.java | 2 +- 6 files changed, 47 insertions(+), 48 deletions(-) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java index d6a21481f..6e07ae2b3 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ServerManager.java @@ -1,5 +1,7 @@ package mineplex.hub.server; +import java.sql.ResultSet; +import java.sql.SQLException; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -26,7 +28,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; -import mineplex.core.MiniPlugin; +import mineplex.core.MiniDbClientPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.common.Rank; import mineplex.core.common.util.C; @@ -48,10 +50,10 @@ import mineplex.core.shop.ShopBase; import mineplex.core.status.ServerStatusManager; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; +import mineplex.game.clans.core.repository.tokens.SimpleClanToken; import mineplex.hub.HubManager; import mineplex.hub.modules.StackerManager; import mineplex.hub.queue.QueueManager; -import mineplex.hub.queue.ui.QueueShop; import mineplex.hub.server.ui.LobbyShop; import mineplex.hub.server.ui.QuickShop; import mineplex.hub.server.ui.ServerCountSorter; @@ -61,7 +63,7 @@ import mineplex.serverdata.Region; import mineplex.serverdata.data.MinecraftServer; import mineplex.serverdata.data.ServerGroup; -public class ServerManager extends MiniPlugin +public class ServerManager extends MiniDbClientPlugin { private static final Long FREE_PORTAL_TIMER = 20000L; private static final Long BETA_PORTAL_TIMER = 120000L; @@ -77,8 +79,6 @@ public class ServerManager extends MiniPlugin private PartyManager _partyManager; private ServerStatusManager _statusManager; private HubManager _hubManager; - private StackerManager _stackerManager; - private QueueManager _queueManager; private NautHashMap _queueCooldowns = new NautHashMap(); private NautHashMap> _serverKeyInfoMap = new NautHashMap>(); @@ -93,7 +93,6 @@ public class ServerManager extends MiniPlugin // Join Time for Free Players Timer private NautHashMap _joinTime = new NautHashMap(); - private QueueShop _domShop; private QuickShop _quickShop; private LobbyShop _lobbyShop; @@ -103,7 +102,7 @@ public class ServerManager extends MiniPlugin public ServerManager(JavaPlugin plugin, CoreClientManager clientManager, DonationManager donationManager, Portal portal, PartyManager partyManager, ServerStatusManager statusManager, HubManager hubManager, StackerManager stackerManager, QueueManager queueManager) { - super("Server Manager", plugin); + super("Server Manager", plugin, clientManager); _clientManager = clientManager; _donationManager = donationManager; @@ -111,8 +110,6 @@ public class ServerManager extends MiniPlugin _partyManager = partyManager; _statusManager = statusManager; _hubManager = hubManager; - _stackerManager = stackerManager; - _queueManager = queueManager; plugin.getServer().getMessenger().registerOutgoingPluginChannel(plugin, "BungeeCord"); @@ -120,7 +117,6 @@ public class ServerManager extends MiniPlugin _quickShop = new QuickShop(this, clientManager, donationManager, "Quick Menu"); _lobbyShop = new LobbyShop(this, clientManager, donationManager, "Lobby Menu"); - //_domShop = new new QueueShop(_queueManager, clientManager, donationManager, "Dominate"); // TODO: Find more appropriate place to initialize Clans server shop? _clansShop = new ClansServerShop(this, _clientManager, _donationManager); @@ -918,4 +914,33 @@ public class ServerManager extends MiniPlugin { return _serverNpcShopMap.get("Valentines Vendetta"); } + + @Override + public String getQuery(int accountId, String uuid, String name) + { + return "SELECT clans.name, accountClan.clanRole, clanServer.serverName, clans.id FROM accountClan INNER JOIN clans ON clans.id = accountClan.clanId INNER JOIN clanServer ON clans.serverId = clanServer.id WHERE accountClan.accountId = " + accountId + "?;"; + } + + @Override + public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException + { + SimpleClanToken clanToken = new SimpleClanToken(); + + while (resultSet.next()) + { + String clanName = resultSet.getString(1); + String clanRole = resultSet.getString(2); + String homeServer = resultSet.getString(3); + int clanId = resultSet.getInt(4); + clanToken = new SimpleClanToken(clanName, clanRole, homeServer, clanId); + } + + Set(playerName, clanToken); + } + + @Override + protected SimpleClanToken AddPlayer(String player) + { + return new SimpleClanToken(); + } } diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerShop.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerShop.java index d8fb30e91..e85528ee8 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerShop.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClanMoveServerShop.java @@ -4,7 +4,6 @@ import org.bukkit.Sound; import org.bukkit.entity.Player; import mineplex.core.account.CoreClientManager; -import mineplex.core.common.util.C; import mineplex.core.common.util.F; import mineplex.core.donation.DonationManager; import mineplex.core.party.Party; diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java index d597dbc82..fe5ceaeea 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerPage.java @@ -27,16 +27,10 @@ import mineplex.serverdata.data.DataRepository; public class ClansServerPage extends ShopPageBase { - private ClanRepository _repository; - private int _accountId; - public ClansServerPage(ServerManager plugin, ClansServerShop shop, CoreClientManager clientManager, - DonationManager donationManager, Player player, ClanRepository repository) + DonationManager donationManager, Player player) { super(plugin, shop, clientManager, donationManager, "Clans Beta", player, 54); - - _repository = repository; - _accountId = clientManager.getAccountId(player); buildPage(); } @@ -44,33 +38,14 @@ public class ClansServerPage extends ShopPageBase() - { - @Override - public void run(SimpleClanToken data) - { - getPlugin().runSync(new Runnable() - { - public void run() - { - if (data != null) - { - buildClanPage(data); - } - else - { - buildNoClanPage(); - } - } - }); - } - }); - } - }); + buildClanPage(getPlugin().Get(_player)); + } + else + { + buildNoClanPage(); + } } private void buildClanPage(SimpleClanToken clan) diff --git a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerShop.java b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerShop.java index b74a37acd..f5590b095 100644 --- a/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerShop.java +++ b/Plugins/Mineplex.Hub/src/mineplex/hub/server/ui/clans/ClansServerShop.java @@ -26,7 +26,7 @@ public class ClansServerShop extends ShopBase @Override protected ShopPageBase> buildPagesFor(Player player) { - return new ClansServerPage(getPlugin(), this, getClientManager(), getDonationManager(), player, _repository); + return new ClansServerPage(getPlugin(), this, getClientManager(), getDonationManager(), player); } @Override diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/DBPool.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/DBPool.java index f69fabe62..4a01218f1 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/DBPool.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/DBPool.java @@ -29,8 +29,8 @@ public final class DBPool source.setUrl(url); source.setUsername(username); source.setPassword(password); - source.setMaxTotal(3); - source.setMaxIdle(3); + source.setMaxTotal(4); + source.setMaxIdle(4); source.setTimeBetweenEvictionRunsMillis(180 * 1000); source.setSoftMinEvictableIdleTimeMillis(180 * 1000); diff --git a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/RepositoryBase.java b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/RepositoryBase.java index e4b2d688c..28650bc01 100644 --- a/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/RepositoryBase.java +++ b/Plugins/Mineplex.ServerData/src/mineplex/serverdata/database/RepositoryBase.java @@ -143,7 +143,7 @@ public abstract class RepositoryBase } protected void executeQuery(String query, ResultSetCallable callable, Column...columns) - { + { // Automatic resource management for handling/closing objects. try ( Connection connection = getConnection();