From 02459c6a10214ca06c65c7de667e5915c5053ef3 Mon Sep 17 00:00:00 2001 From: Jonathan Williams Date: Mon, 4 Apr 2016 13:48:26 -0500 Subject: [PATCH] Fixed bad implementation of IncognitoManager that was locking up threads. Temporarily disabled MessageManager's handling of Incognito. --- .../core/incognito/IncognitoManager.java | 41 ++++++++++----- .../repository/IncognitoRepository.java | 51 ++----------------- .../mineplex/core/message/MessageManager.java | 3 ++ .../repository/tokens/SimpleClanToken.java | 4 +- 4 files changed, 37 insertions(+), 62 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java b/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java index 664415263..db73b3b55 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/incognito/IncognitoManager.java @@ -1,5 +1,8 @@ package mineplex.core.incognito; +import java.sql.ResultSet; +import java.sql.SQLException; + import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; @@ -10,6 +13,7 @@ import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.plugin.java.JavaPlugin; import mineplex.core.MiniClientPlugin; +import mineplex.core.MiniDbClientPlugin; import mineplex.core.account.CoreClientManager; import mineplex.core.common.util.C; import mineplex.core.common.util.F; @@ -23,7 +27,7 @@ import mineplex.core.packethandler.PacketHandler; import mineplex.core.updater.UpdateType; import mineplex.core.updater.event.UpdateEvent; -public class IncognitoManager extends MiniClientPlugin +public class IncognitoManager extends MiniDbClientPlugin { private CoreClientManager _clientManager; private IncognitoRepository _repository; @@ -32,9 +36,9 @@ public class IncognitoManager extends MiniClientPlugin public IncognitoManager(JavaPlugin plugin, CoreClientManager clientManager, PacketHandler packetHandler) { - super("Incognito", plugin); + super("Incognito", plugin, clientManager); - _repository = new IncognitoRepository(this, clientManager); + _repository = new IncognitoRepository(this); _clientManager = clientManager; Instance = this; @@ -66,7 +70,7 @@ public class IncognitoManager extends MiniClientPlugin } } - runAsync(() -> _repository.SetStatus(_clientManager.getAccountId(caller), enabled)); + runAsync(() -> _repository.setStatus(_clientManager.getAccountId(caller), enabled)); return enabled; } @@ -76,8 +80,10 @@ public class IncognitoManager extends MiniClientPlugin { if (event.getType() != UpdateType.FAST) { - UtilServer.getPlayersCollection().forEach(player -> { - UtilServer.getPlayersCollection().forEach(other -> { + UtilServer.getPlayersCollection().forEach(player -> + { + UtilServer.getPlayersCollection().forEach(other -> + { if (Get(other).Status && !_clientManager.hasRank(player, _clientManager.Get(other).GetRank())) player.hidePlayer(other); @@ -91,14 +97,6 @@ public class IncognitoManager extends MiniClientPlugin } } - @EventHandler(priority = EventPriority.LOWEST) - public void ClientLoad(AsyncPlayerPreLoginEvent event) - { - _clientManager.getRepository().getAccountId(event.getUniqueId(), accountId -> { - Get(event.getName()).Status = _repository.GetStatus(accountId.intValue()); - }); - } - @EventHandler(priority = EventPriority.HIGHEST) public void Join(PlayerJoinEvent event) { @@ -155,4 +153,19 @@ public class IncognitoManager extends MiniClientPlugin { return _repository; } + + @Override + public String getQuery(int accountId, String uuid, String name) + { + return "SELECT * FROM incognitoStaff WHERE accountId = " + accountId + ";"; + } + + @Override + public void processLoginResultSet(String playerName, int accountId, ResultSet resultSet) throws SQLException + { + while (resultSet.next()) + { + Get(playerName).Status = resultSet.getInt("status") == 1; + } + } } \ No newline at end of file diff --git a/Plugins/Mineplex.Core/src/mineplex/core/incognito/repository/IncognitoRepository.java b/Plugins/Mineplex.Core/src/mineplex/core/incognito/repository/IncognitoRepository.java index 1032eb809..21f03b062 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/incognito/repository/IncognitoRepository.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/incognito/repository/IncognitoRepository.java @@ -1,8 +1,5 @@ package mineplex.core.incognito.repository; -import mineplex.core.account.CoreClientManager; -import mineplex.core.common.util.EnclosedObject; -import mineplex.core.common.util.UUIDFetcher; import mineplex.core.database.MinecraftRepository; import mineplex.core.incognito.IncognitoManager; import mineplex.serverdata.database.DBPool; @@ -11,57 +8,18 @@ import mineplex.serverdata.database.column.ColumnInt; public class IncognitoRepository extends MinecraftRepository { private static final String CREATE_TABLE = "CREATE TABLE IF NOT EXISTS incognitoStaff (accountId INT NOT NULL, status TINYINT(1) DEFAULT '0', PRIMARY KEY (accountId));"; - private static final String GET_STATUS = "SELECT * FROM incognitoStaff WHERE accountId = ?;"; private static final String INSERT_STATUS = "INSERT INTO incognitoStaff (accountId, status) VALUES (?, ?);"; private static final String UPDATE_STATUS = "UPDATE incognitoStaff SET status=? WHERE accountId=?;"; - private IncognitoManager _incognitoManager; - - private CoreClientManager _clientManager; - - public IncognitoRepository(IncognitoManager incognitoManager, CoreClientManager clientManager) + public IncognitoRepository(IncognitoManager incognitoManager) { super(incognitoManager.getPlugin(), DBPool.getAccount()); - - _clientManager = clientManager; - - _incognitoManager = incognitoManager; } - public void SetStatus(int accountId, boolean status) + public void setStatus(int accountId, boolean status) { - // Prevent duplicate entries for individuals - executeQuery(GET_STATUS, result -> { - if (result.next()) - executeUpdate(UPDATE_STATUS, new ColumnInt("status", status ? 1 : 0), new ColumnInt("accountId", accountId)); - else - executeUpdate(INSERT_STATUS, new ColumnInt("accountId", accountId), new ColumnInt("status", status ? 1 : 0)); - }, new ColumnInt("accountId", accountId)); - } - - public boolean GetStatus(int accountId) - { - EnclosedObject status = new EnclosedObject<>(); - - executeQuery(GET_STATUS, result -> { - if (result.next()) - status.Set(result.getInt("status") == 1 ? Boolean.TRUE : Boolean.FALSE); - else - status.Set(Boolean.FALSE); - }, new ColumnInt("accountId", accountId)); - - return status.Get().booleanValue(); - } - - public boolean GetStatus(String name) - { - EnclosedObject accountId = new EnclosedObject<>(); - - _clientManager.getRepository().getAccountId(UUIDFetcher.getUUIDOf(name), id -> - accountId.Set(id) - ); - - return GetStatus(accountId.Get().intValue()); + if (executeUpdate(UPDATE_STATUS, new ColumnInt("accountId", accountId)) <= 0) + executeInsert(INSERT_STATUS, null, new ColumnInt("accountId", accountId), new ColumnInt("status", status ? 1 : 0)); } protected void initialize() @@ -72,5 +30,4 @@ public class IncognitoRepository extends MinecraftRepository protected void update() { } - } diff --git a/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java b/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java index 774a65138..8e1790063 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/message/MessageManager.java @@ -553,11 +553,14 @@ public class MessageManager extends MiniClientPlugin @Override public void run() { + // TODO Newgarbo wrote this stuff inefficiently and for sake of time and thousands of players i'm going to just comment this out + /* if (IncognitoManager.Instance.getRepository().GetStatus(playerTarget)) { UtilPlayer.message(sender, F.main("Online Player Search", F.elem("0") + " matches for [" + F.elem(target) + "].")); return; } + */ runSync(new Runnable() { diff --git a/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/SimpleClanToken.java b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/SimpleClanToken.java index 70757bd98..e7fd13ca0 100644 --- a/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/SimpleClanToken.java +++ b/Plugins/Mineplex.Game.Clans.Core/src/mineplex/game/clans/core/repository/tokens/SimpleClanToken.java @@ -3,7 +3,7 @@ package mineplex.game.clans.core.repository.tokens; public class SimpleClanToken { - private String _clanName; + private String _clanName = ""; public String getClanName() { return _clanName; } private String _clanRole; @@ -22,4 +22,6 @@ public class SimpleClanToken _homeServer = homeServer; _clanId = clanId; } + + public SimpleClanToken() { } }