mirror of
https://github.com/HibiscusMC/HMCCosmetics.git
synced 2025-12-19 15:09:19 +00:00
fix: multiple schedulers when player has multiple loaded cosmetics
This commit is contained in:
@@ -10,6 +10,7 @@ import org.bukkit.Color;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@@ -28,15 +29,21 @@ public abstract class SQLData extends Data {
|
||||
if (rs.next()) {
|
||||
String rawData = rs.getString("COSMETICS");
|
||||
Map<CosmeticSlot, Map<Cosmetic, Color>> cosmetics = deserializeData(user, rawData);
|
||||
// Load cosmetics, put them into the addedCosmetic hashmap
|
||||
HashMap<Cosmetic, Color> addedCosmetics = new HashMap<>();
|
||||
for (Map<Cosmetic, Color> cosmeticColors : cosmetics.values()) {
|
||||
for (Cosmetic cosmetic : cosmeticColors.keySet()) {
|
||||
addedCosmetics.put(cosmetic, cosmeticColors.get(cosmetic));
|
||||
}
|
||||
}
|
||||
// Run a task on the main thread, adding the cosmetics to the player
|
||||
Bukkit.getScheduler().runTask(HMCCosmeticsPlugin.getInstance(), () -> {
|
||||
// This can not be async.
|
||||
user.addPlayerCosmetic(cosmetic, cosmeticColors.get(cosmetic));
|
||||
for (Cosmetic cosmetic : addedCosmetics.keySet()) {
|
||||
user.addPlayerCosmetic(cosmetic, addedCosmetics.get(cosmetic));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
e.printStackTrace();
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user