mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 05:06:45 +01:00
Fixed a memory leak in MySQL that would cause errors if users were
removed from the DB
This commit is contained in:
parent
54eca5b8ba
commit
4795143fca
@ -1,3 +1,7 @@
|
||||
Version 2.1.66
|
||||
Fixed a bug that could happen if a player was removed from the DB when using MySQL/MariaDB when the user was offline
|
||||
Fixed a minor memory leak for MySQL
|
||||
|
||||
Version 2.1.65
|
||||
Corrected a bug that would cause RetroMode to use Linear formula regardless of setting
|
||||
|
||||
|
2
pom.xml
2
pom.xml
@ -2,7 +2,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.gmail.nossr50.mcMMO</groupId>
|
||||
<artifactId>mcMMO</artifactId>
|
||||
<version>2.1.65</version>
|
||||
<version>2.1.66-SNAPSHOT</version>
|
||||
<name>mcMMO</name>
|
||||
<url>https://github.com/mcMMO-Dev/mcMMO</url>
|
||||
<scm>
|
||||
|
@ -5,6 +5,7 @@ import com.gmail.nossr50.mcMMO;
|
||||
import com.gmail.nossr50.util.commands.CommandUtils;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.command.TabExecutor;
|
||||
@ -12,6 +13,7 @@ import org.bukkit.util.StringUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
public class McremoveCommand implements TabExecutor {
|
||||
@Override
|
||||
@ -24,7 +26,13 @@ public class McremoveCommand implements TabExecutor {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (mcMMO.getDatabaseManager().removeUser(playerName)) {
|
||||
UUID uuid = null;
|
||||
|
||||
if(Bukkit.getPlayer(playerName) != null) {
|
||||
uuid = Bukkit.getPlayer(playerName).getUniqueId();
|
||||
}
|
||||
|
||||
if (mcMMO.getDatabaseManager().removeUser(playerName, uuid)) {
|
||||
sender.sendMessage(LocaleLoader.getString("Commands.mcremove.Success", playerName));
|
||||
}
|
||||
else {
|
||||
|
@ -30,9 +30,17 @@ public interface DatabaseManager {
|
||||
* Remove a user from the database.
|
||||
*
|
||||
* @param playerName The name of the user to remove
|
||||
* @param uuid player UUID, can be null
|
||||
* @return true if the user was successfully removed, false otherwise
|
||||
*/
|
||||
public boolean removeUser(String playerName);
|
||||
public boolean removeUser(String playerName, UUID uuid);
|
||||
|
||||
/**
|
||||
* Removes any cache used for faster lookups
|
||||
* Currently only used for SQL
|
||||
* @param uuid target UUID to cleanup
|
||||
*/
|
||||
public void cleanupUser(UUID uuid);
|
||||
|
||||
/**
|
||||
* Save a user to the database.
|
||||
|
@ -185,7 +185,8 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
mcMMO.p.getLogger().info("Purged " + removedPlayers + " users from the database.");
|
||||
}
|
||||
|
||||
public boolean removeUser(String playerName) {
|
||||
public boolean removeUser(String playerName, UUID uuid) {
|
||||
//NOTE: UUID is unused for FlatFile for this interface implementation
|
||||
boolean worked = false;
|
||||
|
||||
BufferedReader in = null;
|
||||
@ -240,6 +241,11 @@ public final class FlatfileDatabaseManager implements DatabaseManager {
|
||||
return worked;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cleanupUser(UUID uuid) {
|
||||
//Not used in FlatFile
|
||||
}
|
||||
|
||||
public boolean saveUser(PlayerProfile profile) {
|
||||
String playerName = profile.getPlayerName();
|
||||
UUID uuid = profile.getUniqueId();
|
||||
|
@ -15,6 +15,7 @@ import com.gmail.nossr50.runnables.database.UUIDUpdateAsyncTask;
|
||||
import com.gmail.nossr50.util.Misc;
|
||||
import org.apache.tomcat.jdbc.pool.DataSource;
|
||||
import org.apache.tomcat.jdbc.pool.PoolProperties;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.sql.*;
|
||||
@ -172,7 +173,7 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
mcMMO.p.getLogger().info("Purged " + purged + " users from the database.");
|
||||
}
|
||||
|
||||
public boolean removeUser(String playerName) {
|
||||
public boolean removeUser(String playerName, UUID uuid) {
|
||||
boolean success = false;
|
||||
Connection connection = null;
|
||||
PreparedStatement statement = null;
|
||||
@ -200,12 +201,20 @@ public final class SQLDatabaseManager implements DatabaseManager {
|
||||
}
|
||||
|
||||
if (success) {
|
||||
if(uuid != null)
|
||||
cleanupUser(uuid);
|
||||
|
||||
Misc.profileCleanup(playerName);
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public void cleanupUser(UUID uuid) {
|
||||
if(cachedUserIDs.containsKey(uuid))
|
||||
cachedUserIDs.remove(uuid);
|
||||
}
|
||||
|
||||
public boolean saveUser(PlayerProfile profile) {
|
||||
boolean success = true;
|
||||
PreparedStatement statement = null;
|
||||
|
@ -1008,5 +1008,8 @@ public class McMMOPlayer {
|
||||
if (inParty()) {
|
||||
party.removeOnlineMember(thisPlayer);
|
||||
}
|
||||
|
||||
//Remove user from cache
|
||||
mcMMO.getDatabaseManager().cleanupUser(thisPlayer.getUniqueId());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user