Skip to content
This repository was archived by the owner on Oct 12, 2025. It is now read-only.

Commit 57adf6b

Browse files
authored
Merge branch 'ServerOpenMC:main' into main
2 parents a3ebd92 + c0f5297 commit 57adf6b

File tree

6 files changed

+142
-104
lines changed

6 files changed

+142
-104
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ repositories {
1010
mavenCentral()
1111
maven { url = "https://nexus.frengor.com/repository/public/" }
1212
maven { url = "https://repo.purpurmc.org/snapshots" }
13-
maven { url = "https://mvn.coolcraft.ovh/releases" }
13+
maven { url = "https://mvn.mathiasd.fr/releases" }
1414
maven { url = "https://repo.extendedclip.com/content/repositories/placeholderapi/" }
1515
maven { url = "https://maven.enginehub.org/repo/" }
1616
maven { url = "https://repo.onarandombox.com/content/groups/public/" }

src/main/java/fr/communaywen/core/contest/cache/ContestCache.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,17 @@ public ContestCache(AywenCraftPlugin plug) {
2626

2727
// CONTEST DATA
2828
private ContestDataCache contestCache;
29+
private boolean isContestCacheLoading = false;
2930

3031
public void initContestDataCache() {
32+
33+
if (isContestCacheLoading) {
34+
return;
35+
}
36+
isContestCacheLoading = true;
37+
3138
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
32-
String sql = "SELECT * FROM contest WHERE 1";
33-
try (PreparedStatement states = connection.prepareStatement(sql)) {
39+
try (PreparedStatement states = connection.prepareStatement("SELECT * FROM contest WHERE 1")) {
3440
ResultSet result = states.executeQuery();
3541
if (result.next()) {
3642
String camp1 = result.getString("camp1");
@@ -42,10 +48,11 @@ public void initContestDataCache() {
4248

4349
Bukkit.getScheduler().runTask(plugin, () -> {
4450
contestCache = new ContestDataCache(camp1, camp2, color1, color2, phase, startdate);
51+
isContestCacheLoading = false;
4552
});
4653
}
47-
states.closeOnCompletion();
4854
} catch (SQLException e) {
55+
isContestCacheLoading = false;
4956
throw new RuntimeException(e);
5057
}
5158
});
@@ -137,9 +144,16 @@ public String getStartDateCache() {
137144

138145
// CONTEST PLAYER DATA
139146
private Map<UUID, ContestPlayerCache> playerCache = new HashMap<>();
147+
private Map<UUID, Boolean> isPlayerCacheLoading = new HashMap<>();
140148

141149
public void initPlayerDataCache(Player player) {
142150
UUID playerUUID = player.getUniqueId();
151+
if (isPlayerCacheLoading.getOrDefault(playerUUID, false)) {
152+
return;
153+
}
154+
155+
isPlayerCacheLoading.put(playerUUID, true);
156+
143157
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
144158
String sql = "SELECT * FROM camps WHERE minecraft_uuid = ?";
145159
try (PreparedStatement states = connection.prepareStatement(sql)) {
@@ -153,10 +167,11 @@ public void initPlayerDataCache(Player player) {
153167

154168
Bukkit.getScheduler().runTask(plugin, () -> {
155169
playerCache.put(playerUUID, new ContestPlayerCache(points, camp, campColor));
170+
isPlayerCacheLoading.put(playerUUID, false);
156171
});
157172
}
158-
states.closeOnCompletion();
159173
} catch (SQLException e) {
174+
isPlayerCacheLoading.put(playerUUID, false);
160175
throw new RuntimeException(e);
161176
}
162177
});

src/main/java/fr/communaywen/core/economy/EconomyManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public void addBalance(UUID player, double amount) {
4141
balances.put(player, getBalance(player) + amount);
4242

4343
saveBalances(player);
44-
if (Bukkit.getPlayer(player).isOnline()) {
44+
if (Bukkit.getOfflinePlayer(player).isOnline()) {
4545
for (QUESTS quests : QUESTS.values()) {
4646
PlayerQuests pq = QuestsManager.getPlayerQuests(player);
4747
if (quests.getType() == TYPE.MONEY) {

src/main/java/fr/communaywen/core/managers/LeaderboardManager.java

Lines changed: 70 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import java.sql.SQLException;
2626
import java.text.MessageFormat;
2727
import java.util.*;
28+
import java.util.function.Consumer;
2829

2930
import static fr.communaywen.core.commands.economy.BaltopCommand.getColor;
3031

@@ -131,27 +132,28 @@ public static void createLeaderboardTeamTop() {
131132
public static void updateLeaderboardTeamTop() {
132133
if (textDisplayTeamTop == null) return;
133134

134-
List<Map.Entry<String, Long>> topTeam = getTopTeam(10);
135+
getTopTeam(10, topTeam -> {
135136

136-
List<String> lines = new ArrayList<>();
137-
lines.add("§dLes §f10 §dTeams les plus riches sur le serveur");
137+
List<String> lines = new ArrayList<>();
138+
lines.add("§dLes §f10 §dTeams les plus riches sur le serveur");
138139

139-
int index = 1;
140-
for (Map.Entry<String, Long> entry : topTeam) {
141-
String teamName = entry.getKey();
142-
long balance = entry.getValue();
140+
int index = 1;
141+
for (Map.Entry<String, Long> entry : topTeam) {
142+
String teamName = entry.getKey();
143+
long balance = entry.getValue();
143144

144-
lines.add(MessageFormat.format("{0}# {1}: {2}",
145-
getColor(index) + index,
146-
ChatColor.GRAY + teamName,
147-
"§5" + balance));
145+
lines.add(MessageFormat.format("{0}# {1}: {2}",
146+
getColor(index) + index,
147+
ChatColor.GRAY + teamName,
148+
"§5" + balance));
148149

149-
index++;
150-
}
150+
index++;
151+
}
151152

152-
String leaderboardText = String.join("\n", lines);
153+
String leaderboardText = String.join("\n", lines);
153154

154-
textDisplayTeamTop.setText(Component.text(leaderboardText).content());
155+
textDisplayTeamTop.setText(Component.text(leaderboardText).content());
156+
});
155157
}
156158

157159
public static void removeLeaderboardTeamTop() {
@@ -235,29 +237,29 @@ public static void createLeaderboardPlayTime() {
235237
public static void updateLeaderboardPlayTime() {
236238
if (textDisplayPlayTime == null) return;
237239

238-
List<Map.Entry<UUID, Long>> topPlayTime = getTopPlayTime(10);
239-
240-
List<String> lines = new ArrayList<>();
241-
lines.add("§dLes §f10 §dMeilleurs Temps de Jeu des Joueurs");
240+
getTopPlayTime(10, topPlayTime -> {
241+
List<String> lines = new ArrayList<>();
242+
lines.add("§dLes §f10 §dMeilleurs Temps de Jeu des Joueurs");
242243

243-
int index = 1;
244-
for (Map.Entry<UUID, Long> entry : topPlayTime) {
245-
UUID playerUUID = entry.getKey();
246-
long time = entry.getValue();
244+
int index = 1;
245+
for (Map.Entry<UUID, Long> entry : topPlayTime) {
246+
UUID playerUUID = entry.getKey();
247+
long time = entry.getValue();
247248

248-
String playerName = Bukkit.getOfflinePlayer(playerUUID).getName();
249+
String playerName = Bukkit.getOfflinePlayer(playerUUID).getName();
249250

250-
lines.add(MessageFormat.format("{0}# {1}: {2}",
251-
getColor(index) + index,
252-
ChatColor.GRAY + playerName,
253-
ChatColor.DARK_PURPLE + convertTime(time)));
251+
lines.add(MessageFormat.format("{0}# {1}: {2}",
252+
getColor(index) + index,
253+
ChatColor.GRAY + playerName,
254+
ChatColor.DARK_PURPLE + convertTime(time)));
254255

255-
index++;
256-
}
256+
index++;
257+
}
257258

258-
String leaderboardText = String.join("\n", lines);
259+
String leaderboardText = String.join("\n", lines);
259260

260-
textDisplayPlayTime.setText(Component.text(leaderboardText).content());
261+
textDisplayPlayTime.setText(Component.text(leaderboardText).content());
262+
});
261263
}
262264

263265
public static void removeLeaderboardPlayTime() {
@@ -295,44 +297,52 @@ private static void insertTimePlayed(Player player, long time) {
295297
}
296298
}
297299

298-
private static List<Map.Entry<UUID, Long>> getTopPlayTime(int limit) {
299-
List<Map.Entry<UUID, Long>> playTime = new ArrayList<>();
300-
String sql = "SELECT uuid, time FROM playtime ORDER BY time DESC LIMIT ?";
300+
private static void getTopPlayTime(int limit, Consumer<List<Map.Entry<UUID, Long>>> callback) {
301+
Bukkit.getScheduler().runTaskAsynchronously(plugins, () -> {
302+
List<Map.Entry<UUID, Long>> playTime = new ArrayList<>();
303+
String sql = "SELECT uuid, time FROM playtime ORDER BY time DESC LIMIT ?";
301304

302-
try (PreparedStatement statement = connection.prepareStatement(sql)) {
303-
statement.setInt(1, limit);
304-
ResultSet rs = statement.executeQuery();
305+
try (PreparedStatement statement = connection.prepareStatement(sql)) {
306+
statement.setInt(1, limit);
307+
ResultSet rs = statement.executeQuery();
305308

306-
while (rs.next()) {
307-
UUID playerUUID = UUID.fromString(rs.getString("uuid"));
308-
long time = rs.getLong("time");
309+
while (rs.next()) {
310+
UUID playerUUID = UUID.fromString(rs.getString("uuid"));
311+
long time = rs.getLong("time");
309312

310-
playTime.add(new AbstractMap.SimpleEntry<>(playerUUID, time));
313+
playTime.add(new AbstractMap.SimpleEntry<>(playerUUID, time));
314+
}
315+
} catch (SQLException e) {
316+
e.printStackTrace();
311317
}
312-
} catch (SQLException e) {
313-
e.printStackTrace();
314-
}
315-
return playTime;
318+
319+
List<Map.Entry<UUID, Long>> finalResult = playTime;
320+
Bukkit.getScheduler().runTask(plugins, () -> callback.accept(finalResult));
321+
});
316322
}
317323

318-
private static List<Map.Entry<String, Long>> getTopTeam(int limit) {
319-
List<Map.Entry<String, Long>> teams = new ArrayList<>();
320-
String sql = "SELECT teamName, balance FROM teams ORDER BY balance DESC LIMIT ?";
324+
private static void getTopTeam(int limit, Consumer<List<Map.Entry<String, Long>>> callback) {
325+
Bukkit.getScheduler().runTaskAsynchronously(plugins, () -> {
326+
List<Map.Entry<String, Long>> teams = new ArrayList<>();
327+
328+
String sql = "SELECT teamName, balance FROM teams ORDER BY balance DESC LIMIT ?";
321329

322-
try (PreparedStatement statement = connection.prepareStatement(sql)) {
323-
statement.setInt(1, limit);
324-
ResultSet rs = statement.executeQuery();
330+
try (PreparedStatement statement = connection.prepareStatement(sql)) {
331+
statement.setInt(1, limit);
332+
ResultSet rs = statement.executeQuery();
325333

326-
while (rs.next()) {
327-
String teamName = rs.getString("teamName");
328-
long money = rs.getLong("balance");
334+
while (rs.next()) {
335+
String teamName = rs.getString("teamName");
336+
long money = rs.getLong("balance");
329337

330-
teams.add(new AbstractMap.SimpleEntry<>(teamName, money));
338+
teams.add(new AbstractMap.SimpleEntry<>(teamName, money));
339+
}
340+
} catch (SQLException e) {
341+
e.printStackTrace();
331342
}
332-
} catch (SQLException e) {
333-
e.printStackTrace();
334-
}
335-
return teams;
343+
List<Map.Entry<String, Long>> finalResult = teams;
344+
Bukkit.getScheduler().runTask(plugins, () -> callback.accept(finalResult));
345+
});
336346
}
337347

338348
public static String convertTime(long ticks) {

src/main/java/fr/communaywen/core/spawn/jump/JumpListener.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,11 @@ public void run() {
119119

120120
GuidelineManager.getAPI().getAdvancement("openmc:spawn/jump/firstjump").grant(event.getPlayer());
121121

122-
if (jumpManager.isPlayerInTop10(player)) {
122+
jumpManager.isPlayerInTop10(player, bool -> {
123+
if (bool) {
123124
GuidelineManager.getAPI().getAdvancement("openmc:spawn/jump/top10jump").grant(event.getPlayer());
124125
}
126+
});
125127

126128
jumpRewardsCooldown.put(player.getUniqueId(), System.currentTimeMillis());
127129

src/main/java/fr/communaywen/core/spawn/jump/JumpManager.java

Lines changed: 48 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.sql.ResultSet;
2121
import java.text.MessageFormat;
2222
import java.util.*;
23+
import java.util.function.Consumer;
2324

2425
import static fr.communaywen.core.commands.economy.BaltopCommand.getColor;
2526

@@ -106,35 +107,44 @@ private void insertNewBestTime(Player player, double bestTime) {
106107
}
107108
}
108109

109-
public List<Map.Entry<UUID, Double>> getTopJumpTimes(int limit) {
110-
List<Map.Entry<UUID, Double>> jumpRecords = new ArrayList<>();
111-
String sql = "SELECT uuid, best_time FROM spawn_jump ORDER BY best_time ASC LIMIT ?";
110+
public void getTopJumpTimes(int limit, Consumer<List<Map.Entry<UUID, Double>>> callback) {
111+
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
112+
List<Map.Entry<UUID, Double>> jumpRecords = new ArrayList<>();
113+
String sql = "SELECT uuid, best_time FROM spawn_jump ORDER BY best_time ASC LIMIT ?";
112114

113-
try (PreparedStatement statement = connection.prepareStatement(sql)) {
114-
statement.setInt(1, limit);
115-
ResultSet rs = statement.executeQuery();
115+
try (PreparedStatement statement = connection.prepareStatement(sql)) {
116+
statement.setInt(1, limit);
117+
ResultSet rs = statement.executeQuery();
116118

117-
while (rs.next()) {
118-
UUID playerUUID = UUID.fromString(rs.getString("uuid"));
119-
double bestTime = rs.getDouble("best_time");
119+
while (rs.next()) {
120+
UUID playerUUID = UUID.fromString(rs.getString("uuid"));
121+
double bestTime = rs.getDouble("best_time");
120122

121-
jumpRecords.add(new AbstractMap.SimpleEntry<>(playerUUID, bestTime));
123+
jumpRecords.add(new AbstractMap.SimpleEntry<>(playerUUID, bestTime));
124+
}
125+
} catch (SQLException e) {
126+
e.printStackTrace();
122127
}
123-
} catch (SQLException e) {
124-
e.printStackTrace();
125-
}
126-
return jumpRecords;
128+
129+
List<Map.Entry<UUID, Double>> finalResult = jumpRecords;
130+
Bukkit.getScheduler().runTask(plugin, () -> callback.accept(finalResult));
131+
132+
});
127133
}
128134

129-
public boolean isPlayerInTop10(Player player) {
130-
List<Map.Entry<UUID, Double>> topJumpTimes = getTopJumpTimes(10);
135+
public void isPlayerInTop10(Player player, Consumer<Boolean> callback) {
131136

132-
for (Map.Entry<UUID, Double> entry : topJumpTimes) {
133-
if (entry.getKey().equals(player.getUniqueId())) {
134-
return true;
137+
getTopJumpTimes(10, topJumpTimes -> {
138+
139+
for (Map.Entry<UUID, Double> entry : topJumpTimes) {
140+
if (entry.getKey().equals(player.getUniqueId())) {
141+
Boolean finalResult = true;
142+
callback.accept(finalResult);
143+
}
135144
}
136-
}
137-
return false;
145+
Boolean finalResult = false;
146+
callback.accept(finalResult);
147+
});
138148
}
139149

140150

@@ -223,29 +233,30 @@ public void createLeaderboardLeaderboardRecord() {
223233
public void updateLeaderboardLeaderboardRecord() {
224234
if (textDisplayLeaderboardRecord == null) return;
225235

226-
List<Map.Entry<UUID, Double>> topJumpTimes = getTopJumpTimes(10);
236+
getTopJumpTimes(10, topJumpTimes -> {
227237

228-
List<String> lines = new ArrayList<>();
229-
lines.add("§dLes §f10 §dMeilleurs Temps sur le Jump");
238+
List<String> lines = new ArrayList<>();
239+
lines.add("§dLes §f10 §dMeilleurs Temps sur le Jump");
230240

231-
int index = 1;
232-
for (Map.Entry<UUID, Double> entry : topJumpTimes) {
233-
UUID playerUUID = entry.getKey();
234-
double bestTime = entry.getValue();
241+
int index = 1;
242+
for (Map.Entry<UUID, Double> entry : topJumpTimes) {
243+
UUID playerUUID = entry.getKey();
244+
double bestTime = entry.getValue();
235245

236-
String playerName = Bukkit.getOfflinePlayer(playerUUID).getName();
246+
String playerName = Bukkit.getOfflinePlayer(playerUUID).getName();
237247

238-
lines.add(MessageFormat.format("{0}# {1}: {2} secondes",
239-
getColor(index) + index,
240-
ChatColor.GRAY + playerName,
241-
ChatColor.DARK_PURPLE + String.format("%.2f", bestTime)));
248+
lines.add(MessageFormat.format("{0}# {1}: {2} secondes",
249+
getColor(index) + index,
250+
ChatColor.GRAY + playerName,
251+
ChatColor.DARK_PURPLE + String.format("%.2f", bestTime)));
242252

243-
index++;
244-
}
253+
index++;
254+
}
245255

246-
String leaderboardText = String.join("\n", lines);
256+
String leaderboardText = String.join("\n", lines);
247257

248-
textDisplayLeaderboardRecord.setText(Component.text(leaderboardText).content());
258+
textDisplayLeaderboardRecord.setText(Component.text(leaderboardText).content());
259+
});
249260
}
250261

251262
public void removeLeaderboardLeaderboardRecord() {

0 commit comments

Comments
 (0)