mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2024-12-27 11:37:36 +01:00
Fixes MySQL exists and delete functions.
This commit is contained in:
parent
46c1ff4761
commit
9847235df1
@ -165,7 +165,8 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(sb)) {
|
||||
Method getUniqueId = dataObject.getMethod("getUniqueId");
|
||||
String uniqueId = (String) getUniqueId.invoke(instance);
|
||||
preparedStatement.setString(1, uniqueId);
|
||||
// UniqueId needs to be placed in quotes
|
||||
preparedStatement.setString(1, "\"" + uniqueId + "\"");
|
||||
preparedStatement.execute();
|
||||
} catch (Exception e) {
|
||||
plugin.logError("Could not delete object " + instance.getClass().getName() + " " + e.getMessage());
|
||||
@ -180,10 +181,12 @@ public class MySQLDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
"` WHERE `uniqueId` = ?), 1, 0)";
|
||||
|
||||
try (PreparedStatement preparedStatement = connection.prepareStatement(query)) {
|
||||
preparedStatement.setString(1, uniqueId);
|
||||
// UniqueId needs to be placed in quotes
|
||||
preparedStatement.setString(1, "\"" + uniqueId + "\"");
|
||||
try (ResultSet resultSet = preparedStatement.executeQuery()) {
|
||||
if (resultSet.next()) {
|
||||
return resultSet.getBoolean(1);
|
||||
boolean result = resultSet.getBoolean(1);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
|
@ -58,7 +58,6 @@ public class JoinLeaveListener implements Listener {
|
||||
|
||||
@EventHandler(priority = EventPriority.NORMAL)
|
||||
public void onPlayerQuit(final PlayerQuitEvent event) {
|
||||
players.removeOnlinePlayer(event.getPlayer().getUniqueId());
|
||||
User.removePlayer(event.getPlayer());
|
||||
players.save(event.getPlayer().getUniqueId());
|
||||
}
|
||||
}
|
||||
|
@ -117,29 +117,6 @@ public class PlayersManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Stores the player's info and removes the player from the cache
|
||||
*
|
||||
* @param playerUUID - the player - UUID of player
|
||||
*
|
||||
*/
|
||||
public void removeOnlinePlayer(UUID playerUUID) {
|
||||
save(playerUUID);
|
||||
playerCache.remove(playerUUID);
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves all players on the server and clears the cache
|
||||
*/
|
||||
public void removeAllPlayers() {
|
||||
playerCache.keySet().forEach(this::save);
|
||||
playerCache.clear();
|
||||
}
|
||||
|
||||
/*
|
||||
* Player info query methods
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checks if the player is known or not. Will check not just the cache but if the object is
|
||||
* in the database too.
|
||||
|
@ -85,7 +85,7 @@ public class PlayersManagerTest {
|
||||
when(end.getName()).thenReturn("world_the_end");
|
||||
when(iwm.inWorld(any())).thenReturn(true);
|
||||
when(plugin.getIWM()).thenReturn(iwm);
|
||||
|
||||
|
||||
// Settings
|
||||
Settings s = mock(Settings.class);
|
||||
when(plugin.getSettings()).thenReturn(s);
|
||||
@ -219,42 +219,6 @@ public class PlayersManagerTest {
|
||||
pm.addPlayer(uuid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.managers.PlayersManager#removeOnlinePlayer(java.util.UUID)}.
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveOnlinePlayer() {
|
||||
PlayersManager pm = new PlayersManager(plugin);
|
||||
pm.setHandler(db);
|
||||
// Unknown UUID
|
||||
assertFalse(pm.isKnown(uuid));
|
||||
// Remove it just to check this does not fail
|
||||
pm.removeOnlinePlayer(uuid);
|
||||
// Should still be unknown
|
||||
assertFalse(pm.isKnown(uuid));
|
||||
// Add the player
|
||||
pm.addPlayer(uuid);
|
||||
// Now should be known
|
||||
assertTrue(pm.isKnown(uuid));
|
||||
// Remove the player
|
||||
pm.removeOnlinePlayer(uuid);
|
||||
// There's no check possible to confirm right now.
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.managers.PlayersManager#removeAllPlayers()}.
|
||||
*/
|
||||
@Test
|
||||
public void testRemoveAllPlayers() {
|
||||
PlayersManager pm = new PlayersManager(plugin);
|
||||
pm.setHandler(db);
|
||||
|
||||
pm.addPlayer(uuid);
|
||||
pm.addPlayer(notUUID);
|
||||
|
||||
pm.removeAllPlayers();
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link world.bentobox.bentobox.managers.PlayersManager#isKnown(java.util.UUID)}.
|
||||
*/
|
||||
@ -330,7 +294,7 @@ public class PlayersManagerTest {
|
||||
// Add a player to the cache
|
||||
pm.addPlayer(uuid);
|
||||
UUID uuidResult = pm.getUUID("tastybento");
|
||||
assertEquals(uuid, uuidResult);
|
||||
assertEquals(uuid, uuidResult);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -343,7 +307,7 @@ public class PlayersManagerTest {
|
||||
// Add a player
|
||||
pm.addPlayer(uuid);
|
||||
assertEquals("tastybento", pm.getName(user.getUniqueId()));
|
||||
pm.setPlayerName(user);
|
||||
pm.setPlayerName(user);
|
||||
assertEquals(user.getName(), pm.getName(user.getUniqueId()));
|
||||
}
|
||||
|
||||
@ -357,7 +321,7 @@ public class PlayersManagerTest {
|
||||
// Add a player to the cache
|
||||
pm.addPlayer(uuid);
|
||||
// Unknown player should return null
|
||||
assertNull(pm.getUUID("tastybento123"));
|
||||
assertNull(pm.getUUID("tastybento123"));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user