9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2025-12-20 07:29:15 +00:00

Compare commits

...

4 Commits

Author SHA1 Message Date
LoJoSho
bebee807bc fix: fix possible database memory leak (as well as improvements in code) 2025-05-29 14:59:57 -05:00
LoJoSho
26c579b69f chore: add cosmetic passengers to dump command 2025-05-25 14:02:04 -05:00
LoJoSho
ef665e7e83 fix: improper call to getEntity when not needed 2025-05-23 13:22:29 -05:00
LoJoSho
7a6475c467 chore: update LuckPerms 2025-05-22 21:07:12 -05:00
6 changed files with 21 additions and 39 deletions

View File

@@ -139,7 +139,7 @@ tasks {
downloadPlugins { downloadPlugins {
hangar("PlaceholderAPI", "2.11.6") hangar("PlaceholderAPI", "2.11.6")
url("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/build/libs/ProtocolLib.jar") url("https://ci.dmulloy2.net/job/ProtocolLib/lastSuccessfulBuild/artifact/build/libs/ProtocolLib.jar")
url("https://download.luckperms.net/1567/bukkit/loader/LuckPerms-Bukkit-5.4.150.jar") url("https://download.luckperms.net/1582/bukkit/loader/LuckPerms-Bukkit-5.4.165.jar")
} }
} }

View File

@@ -400,6 +400,7 @@ public class CosmeticCommand implements CommandExecutor {
if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) { if (user.hasCosmeticInSlot(CosmeticSlot.BACKPACK)) {
player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getEntityManager().getLocation()); player.sendMessage("Backpack Location -> " + user.getUserBackpackManager().getEntityManager().getLocation());
} }
player.sendMessage("Cosmetic Passengers -> " + user.getUserBackpackManager().getAreaEffectEntityId());
player.sendMessage("Cosmetics -> " + user.getCosmetics()); player.sendMessage("Cosmetics -> " + user.getCosmetics());
player.sendMessage("EntityId -> " + player.getEntityId()); player.sendMessage("EntityId -> " + player.getEntityId());
return true; return true;

View File

@@ -39,10 +39,12 @@ public class MySQLData extends SQLData {
try { try {
openConnection(); openConnection();
if (connection == null) throw new NullPointerException("Connection is null"); if (connection == null) throw new NullPointerException("Connection is null");
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " + try (PreparedStatement preparedStatement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
"(UUID varchar(36) PRIMARY KEY, " + "(UUID varchar(36) PRIMARY KEY, " +
"COSMETICS MEDIUMTEXT " + "COSMETICS MEDIUMTEXT " +
");").execute(); ");")) {
preparedStatement.execute();
}
} catch (SQLException | NullPointerException e) { } catch (SQLException | NullPointerException e) {
plugin.getLogger().severe(""); plugin.getLogger().severe("");
plugin.getLogger().severe(""); plugin.getLogger().severe("");
@@ -60,17 +62,11 @@ public class MySQLData extends SQLData {
@Override @Override
public void clear(UUID uniqueId) { public void clear(UUID uniqueId) {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> { Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
PreparedStatement preparedSt = null; try (PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;")) {
try {
preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
preparedSt.setString(1, uniqueId.toString()); preparedSt.setString(1, uniqueId.toString());
preparedSt.executeUpdate(); preparedSt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally {
try {
if (preparedSt != null) preparedSt.close();
} catch (SQLException e) {}
} }
}); });
} }

View File

@@ -23,22 +23,17 @@ public abstract class SQLData extends Data {
return CompletableFuture.supplyAsync(() -> { return CompletableFuture.supplyAsync(() -> {
UserData data = new UserData(uniqueId); UserData data = new UserData(uniqueId);
PreparedStatement preparedStatement = null; try (PreparedStatement preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;")){
try {
preparedStatement = preparedStatement("SELECT * FROM COSMETICDATABASE WHERE UUID = ?;");
preparedStatement.setString(1, uniqueId.toString()); preparedStatement.setString(1, uniqueId.toString());
ResultSet rs = preparedStatement.executeQuery(); try (ResultSet rs = preparedStatement.executeQuery()) {
if (rs.next()) { if (rs.next()) {
String rawData = rs.getString("COSMETICS"); String rawData = rs.getString("COSMETICS");
HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> cosmetics = deserializeData(rawData); HashMap<CosmeticSlot, Map.Entry<Cosmetic, Integer>> cosmetics = deserializeData(rawData);
data.setCosmetics(cosmetics); data.setCosmetics(cosmetics);
}
} }
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally {
try {
if (preparedStatement != null) preparedStatement.close();
} catch (SQLException e) {}
} }
return data; return data;
}); });
@@ -48,18 +43,12 @@ public abstract class SQLData extends Data {
@SuppressWarnings("resource") @SuppressWarnings("resource")
public void save(CosmeticUser user) { public void save(CosmeticUser user) {
Runnable run = () -> { Runnable run = () -> {
PreparedStatement preparedSt = null; try (PreparedStatement preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);")) {
try {
preparedSt = preparedStatement("REPLACE INTO COSMETICDATABASE(UUID,COSMETICS) VALUES(?,?);");
preparedSt.setString(1, user.getUniqueId().toString()); preparedSt.setString(1, user.getUniqueId().toString());
preparedSt.setString(2, serializeData(user)); preparedSt.setString(2, serializeData(user));
preparedSt.executeUpdate(); preparedSt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} finally {
try {
if (preparedSt != null) preparedSt.close();
} catch (SQLException e) {}
} }
}; };
if (!HMCCosmeticsPlugin.getInstance().isDisabled()) { if (!HMCCosmeticsPlugin.getInstance().isDisabled()) {

View File

@@ -35,10 +35,12 @@ public class SQLiteData extends SQLData {
connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder); connection = DriverManager.getConnection("jdbc:sqlite:" + dataFolder);
openConnection(); openConnection();
connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " + try (PreparedStatement preparedStatement = connection.prepareStatement("CREATE TABLE IF NOT EXISTS `COSMETICDATABASE` " +
"(UUID varchar(36) PRIMARY KEY, " + "(UUID varchar(36) PRIMARY KEY, " +
"COSMETICS MEDIUMTEXT " + "COSMETICS MEDIUMTEXT " +
");").execute(); ");")) {
preparedStatement.execute();
}
} catch (SQLException e) { } catch (SQLException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
@@ -48,17 +50,11 @@ public class SQLiteData extends SQLData {
@SuppressWarnings("resource") @SuppressWarnings("resource")
public void clear(UUID uniqueId) { public void clear(UUID uniqueId) {
Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> { Bukkit.getScheduler().runTaskAsynchronously(HMCCosmeticsPlugin.getInstance(), () -> {
PreparedStatement preparedSt = null; try (PreparedStatement preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;")){
try {
preparedSt = preparedStatement("DELETE FROM COSMETICDATABASE WHERE UUID=?;");
preparedSt.setString(1, uniqueId.toString()); preparedSt.setString(1, uniqueId.toString());
preparedSt.executeUpdate(); preparedSt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} finally {
try {
if (preparedSt != null) preparedSt.close();
} catch (SQLException e) {}
} }
}); });
} }

View File

@@ -144,7 +144,7 @@ public class CosmeticUser implements CosmeticHolder {
showCosmetics(HiddenReason.GAMEMODE); showCosmetics(HiddenReason.GAMEMODE);
} }
if (bukkitPlayer != null && Settings.getDisabledWorlds().contains(getEntity().getLocation().getWorld().getName())) { if (bukkitPlayer != null && Settings.getDisabledWorlds().contains(bukkitPlayer.getLocation().getWorld().getName())) {
MessagesUtil.sendDebugMessages("Hiding Cosmetics due to world"); MessagesUtil.sendDebugMessages("Hiding Cosmetics due to world");
hideCosmetics(CosmeticUser.HiddenReason.WORLD); hideCosmetics(CosmeticUser.HiddenReason.WORLD);
} else if (this.isHidden(HiddenReason.WORLD)) { } else if (this.isHidden(HiddenReason.WORLD)) {