Fixed bad implementation of IncognitoManager that was locking up threads.

Temporarily disabled MessageManager's handling of Incognito.
This commit is contained in:
Jonathan Williams 2016-04-04 13:48:26 -05:00
parent 60010f90b4
commit 02459c6a10
4 changed files with 37 additions and 62 deletions

View File

@ -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<IncognitoClient>
public class IncognitoManager extends MiniDbClientPlugin<IncognitoClient>
{
private CoreClientManager _clientManager;
private IncognitoRepository _repository;
@ -32,9 +36,9 @@ public class IncognitoManager extends MiniClientPlugin<IncognitoClient>
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<IncognitoClient>
}
}
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<IncognitoClient>
{
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<IncognitoClient>
}
}
@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<IncognitoClient>
{
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;
}
}
}

View File

@ -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<Boolean> 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<Integer> 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()
{
}
}

View File

@ -553,11 +553,14 @@ public class MessageManager extends MiniClientPlugin<ClientMessage>
@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()
{

View File

@ -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() { }
}