From 5468697e19f5e371ead6dd7f287e0c46319ce4b4 Mon Sep 17 00:00:00 2001 From: iambibi Date: Tue, 22 Oct 2024 19:27:17 +0200 Subject: [PATCH 01/18] Fix Claim Reminder --- .../luckyblocks/managers/LBPlayerManager.java | 8 +++++++ .../core/luckyblocks/utils/LBReminder.java | 2 +- .../core/managers/LeaderboardManager.java | 22 ++++++++++--------- 3 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/main/java/fr/communaywen/core/luckyblocks/managers/LBPlayerManager.java b/src/main/java/fr/communaywen/core/luckyblocks/managers/LBPlayerManager.java index 27b639d2..5b9a978b 100644 --- a/src/main/java/fr/communaywen/core/luckyblocks/managers/LBPlayerManager.java +++ b/src/main/java/fr/communaywen/core/luckyblocks/managers/LBPlayerManager.java @@ -25,6 +25,14 @@ public boolean canClaimLuckyBlocks(UUID uuid) { return true; } + public boolean canCheckClaimLuckyBlocks(UUID uuid) { + if (System.currentTimeMillis() - getLuckyBlocksCooldown(uuid) < timeToWait) { + return false; + } else { + return true; + } + } + public int getRemainingHours(UUID uuid) { return (int) ((timeToWait - (System.currentTimeMillis() - getLuckyBlocksCooldown(uuid))) / 3600000); } diff --git a/src/main/java/fr/communaywen/core/luckyblocks/utils/LBReminder.java b/src/main/java/fr/communaywen/core/luckyblocks/utils/LBReminder.java index e770c121..429e3831 100644 --- a/src/main/java/fr/communaywen/core/luckyblocks/utils/LBReminder.java +++ b/src/main/java/fr/communaywen/core/luckyblocks/utils/LBReminder.java @@ -36,7 +36,7 @@ public void startReminder() { return; } - if (playerManager.canClaimLuckyBlocks(playerUUID)) { + if (playerManager.canCheckClaimLuckyBlocks(playerUUID)) { MessageManager.sendMessageType(player, "Vous pouvez réclamer vos Lucky Block Quotidien!", Prefix.LUCKYBLOCK, MessageType.INFO, true); Component message = Component.text("", NamedTextColor.GRAY) .append(Component.text("Cliquez-ici", NamedTextColor.GRAY)) diff --git a/src/main/java/fr/communaywen/core/managers/LeaderboardManager.java b/src/main/java/fr/communaywen/core/managers/LeaderboardManager.java index b942cdfa..1d85a902 100644 --- a/src/main/java/fr/communaywen/core/managers/LeaderboardManager.java +++ b/src/main/java/fr/communaywen/core/managers/LeaderboardManager.java @@ -131,21 +131,23 @@ public static void createLeaderboardTeamTop() { public static void updateLeaderboardTeamTop() { if (textDisplayTeamTop == null) return; - List teamBalances = TeamManager.getTeams(); - - teamBalances.sort((a, b) -> Double.compare(b.getBalance(), a.getBalance())); - - if (teamBalances.size() > 10) { - teamBalances = teamBalances.subList(0, 10); - } + List> topTeam = getTopTeam(10); List lines = new ArrayList<>(); lines.add("§dLes §f10 §dTeams les plus riches sur le serveur"); int index = 1; - for (Team team : teamBalances) { - String teamName = team.getName(); - lines.add(MessageFormat.format("{0}# {1}: {2}", getColor(index) + index, ChatColor.GRAY + teamName, ChatColor.DARK_PURPLE + String.format("%.1f", EconomieTeam.getTeamBalances(team.getName()).doubleValue()))); + for (Map.Entry entry : topTeam) { + UUID playerUUID = entry.getKey(); + long balance = entry.getValue(); + + String playerName = Bukkit.getOfflinePlayer(playerUUID).getName(); + + lines.add(MessageFormat.format("{0}# {1}: {2}", + getColor(index) + index, + ChatColor.GRAY + playerName, + ChatColor.DARK_PURPLE + balance)); + index++; } From 445d3e577f426d8486efe82d042017b0e3eae438 Mon Sep 17 00:00:00 2001 From: iambibi Date: Tue, 22 Oct 2024 20:24:18 +0200 Subject: [PATCH 02/18] Fix TP jump --- .../fr/communaywen/core/commands/spawn/jump/JumpCommand.java | 2 +- src/main/java/fr/communaywen/core/spawn/jump/JumpListener.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/communaywen/core/commands/spawn/jump/JumpCommand.java b/src/main/java/fr/communaywen/core/commands/spawn/jump/JumpCommand.java index a9199364..63e08bee 100644 --- a/src/main/java/fr/communaywen/core/commands/spawn/jump/JumpCommand.java +++ b/src/main/java/fr/communaywen/core/commands/spawn/jump/JumpCommand.java @@ -38,7 +38,7 @@ public void end(Player player) { if (jumpManager.isJumping(player)) { jumpManager.endJump(player); - Location spawn_jump = new Location(player.getServer().getWorld(plugin.getConfig().getString("jump.world")), plugin.getConfig().getDouble("jump.start.posX") - 2, plugin.getConfig().getDouble("jump.start.posY"), plugin.getConfig().getDouble("jump.start.posZ") - 2, 0, 0); + Location spawn_jump = new Location(player.getServer().getWorld(plugin.getConfig().getString("jump.world")), plugin.getConfig().getDouble("jump.start.posX") + 2, plugin.getConfig().getDouble("jump.start.posY"), plugin.getConfig().getDouble("jump.start.posZ") - 2, 0, 0); player.teleport(spawn_jump); MessageManager.sendMessageType(player, "§7Vous avez §carreter votre jump", Prefix.JUMP, MessageType.SUCCESS, true); diff --git a/src/main/java/fr/communaywen/core/spawn/jump/JumpListener.java b/src/main/java/fr/communaywen/core/spawn/jump/JumpListener.java index 712a2feb..acff9096 100644 --- a/src/main/java/fr/communaywen/core/spawn/jump/JumpListener.java +++ b/src/main/java/fr/communaywen/core/spawn/jump/JumpListener.java @@ -125,7 +125,7 @@ public void run() { jumpRewardsCooldown.put(player.getUniqueId(), System.currentTimeMillis()); - Location spawn_jump = new Location(player.getServer().getWorld(plugin.getConfig().getString("jump.world")), plugin.getConfig().getDouble("jump.start.posX") - 2, plugin.getConfig().getDouble("jump.start.posY"), plugin.getConfig().getDouble("jump.start.posZ") - 2, 0, 0); + Location spawn_jump = new Location(player.getServer().getWorld(plugin.getConfig().getString("jump.world")), plugin.getConfig().getDouble("jump.start.posX") + 2, plugin.getConfig().getDouble("jump.start.posY"), plugin.getConfig().getDouble("jump.start.posZ") - 2, 0, 0); player.teleport(spawn_jump); } } From 468e06a57e6a78651c5aa168e2479027b6da5075 Mon Sep 17 00:00:00 2001 From: iambibi Date: Tue, 22 Oct 2024 20:25:48 +0200 Subject: [PATCH 03/18] Fix Leaderboard Team --- .../core/managers/LeaderboardManager.java | 32 +++++++++++++++---- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/src/main/java/fr/communaywen/core/managers/LeaderboardManager.java b/src/main/java/fr/communaywen/core/managers/LeaderboardManager.java index 1d85a902..e03f381e 100644 --- a/src/main/java/fr/communaywen/core/managers/LeaderboardManager.java +++ b/src/main/java/fr/communaywen/core/managers/LeaderboardManager.java @@ -131,22 +131,20 @@ public static void createLeaderboardTeamTop() { public static void updateLeaderboardTeamTop() { if (textDisplayTeamTop == null) return; - List> topTeam = getTopTeam(10); + List> topTeam = getTopTeam(10); List lines = new ArrayList<>(); lines.add("§dLes §f10 §dTeams les plus riches sur le serveur"); int index = 1; - for (Map.Entry entry : topTeam) { - UUID playerUUID = entry.getKey(); + for (Map.Entry entry : topTeam) { + String teamName = entry.getKey(); long balance = entry.getValue(); - String playerName = Bukkit.getOfflinePlayer(playerUUID).getName(); - lines.add(MessageFormat.format("{0}# {1}: {2}", getColor(index) + index, - ChatColor.GRAY + playerName, - ChatColor.DARK_PURPLE + balance)); + ChatColor.GRAY + teamName, + "§5" + balance)); index++; } @@ -317,6 +315,26 @@ private static List> getTopPlayTime(int limit) { return playTime; } + private static List> getTopTeam(int limit) { + List> teams = new ArrayList<>(); + String sql = "SELECT teamName, balance FROM teams ORDER BY balance DESC LIMIT ?"; + + try (PreparedStatement statement = connection.prepareStatement(sql)) { + statement.setInt(1, limit); + ResultSet rs = statement.executeQuery(); + + while (rs.next()) { + String teamName = rs.getString("teamName"); + long money = rs.getLong("balance"); + + teams.add(new AbstractMap.SimpleEntry<>(teamName, money)); + } + } catch (SQLException e) { + e.printStackTrace(); + } + return teams; + } + public static String convertTime(long ticks) { long millis = ticks * 50; From 9d470c004ec0dadbd6d19774935c207ad5d5e81f Mon Sep 17 00:00:00 2001 From: iambibi Date: Tue, 22 Oct 2024 21:50:51 +0200 Subject: [PATCH 04/18] Fix Config contest_trades --- src/main/resources/config.yml | 194 +++++++++++++++++----------------- 1 file changed, 97 insertions(+), 97 deletions(-) diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index 5a6e6f3b..ba0ec228 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -79,6 +79,103 @@ contest: boost: 0 #in % # La Liste des Contest # - Couleur autorisé : BLACK, DARK_BLUE, DARK_GREEN, DARK_AQUA, DARK_RED, DARK_PURPLE, GOLD, GRAY, DARK_GRAY, BLUE, GREEN, AQUA, RED, LIGHT_PURPLE, YELLOW, WHITE + contestTrades: + - ress: PRISMARINE + amount: 2 + amount_shell: 1 + selected: false + - ress: LARGE_AMETHYST_BUD + amount: 1 + amount_shell: 2 + selected: false + - ress: RABBIT_STEW + amount: 2 + amount_shell: 3 + selected: false + - ress: SHROOMLIGHT + amount: 2 + amount_shell: 1 + selected: false + - ress: ROOTED_DIRT + amount: 2 + amount_shell: 1 + selected: false + - ress: SEA_LANTERN + amount: 2 + amount_shell: 1 + selected: false + - ress: ENCHANTED_GOLDEN_APPLE + amount: 1 + amount_shell: 8 + selected: false + - ress: MANGROVE_LOG + amount: 7 + amount_shell: 1 + selected: false + - ress: BEE_NEST + amount: 1 + amount_shell: 2 + selected: false + - ress: GOAT_HORN + amount: 1 + amount_shell: 6 + selected: false + - ress: PACKED_MUD + amount: 2 + amount_shell: 1 + selected: false + - ress: POPPED_CHORUS_FRUIT + amount: 3 + amount_shell: 1 + selected: false + - ress: HEAVY_CORE + amount: 1 + amount_shell: 18 + selected: false + - ress: END_CRYSTAL + amount: 2 + amount_shell: 5 + selected: false + - ress: TINTED_GLASS + amount: 3 + amount_shell: 1 + selected: false + - ress: CONDUIT + amount: 1 + amount_shell: 15 + selected: false + - ress: DECORATED_POT + amount: 2 + amount_shell: 1 + selected: false + - ress: CALIBRATED_SCULK_SENSOR + amount: 4 + amount_shell: 1 + selected: false + - ress: MUDDY_MANGROVE_ROOTS + amount: 2 + amount_shell: 3 + selected: false + - ress: TORCHFLOWER + amount: 2 + amount_shell: 3 + selected: false + - ress: SPONGE + amount: 1 + amount_shell: 2 + selected: false + - ress: MAGENTA_GLAZED_TERRACOTTA + amount: 3 + amount_shell: 1 + selected: false + - ress: VERDANT_FROGLIGHT + amount: 1 + amount_shell: 2 + selected: false + - ress: HONEYCOMB + amount: 2 + amount_shell: 1 + selected: falseD contestList: - camp1: "Mayonnaise" color1: "YELLOW" @@ -155,103 +252,6 @@ contest: camp2: "Campagne" color2: "DARK_GREEN" selected: 0 -contestTrades: - - ress: PRISMARINE - amount: 2 - amount_shell: 1 - selected: false - - ress: LARGE_AMETHYST_BUD - amount: 1 - amount_shell: 2 - selected: false - - ress: RABBIT_STEW - amount: 2 - amount_shell: 3 - selected: false - - ress: SHROOMLIGHT - amount: 2 - amount_shell: 1 - selected: false - - ress: ROOTED_DIRT - amount: 2 - amount_shell: 1 - selected: false - - ress: SEA_LANTERN - amount: 2 - amount_shell: 1 - selected: false - - ress: ENCHANTED_GOLDEN_APPLE - amount: 1 - amount_shell: 8 - selected: false - - ress: MANGROVE_LOG - amount: 7 - amount_shell: 1 - selected: false - - ress: BEE_NEST - amount: 1 - amount_shell: 2 - selected: false - - ress: GOAT_HORN - amount: 1 - amount_shell: 6 - selected: false - - ress: PACKED_MUD - amount: 2 - amount_shell: 1 - selected: false - - ress: POPPED_CHORUS_FRUIT - amount: 3 - amount_shell: 1 - selected: false - - ress: HEAVY_CORE - amount: 1 - amount_shell: 18 - selected: false - - ress: END_CRYSTAL - amount: 2 - amount_shell: 5 - selected: false - - ress: TINTED_GLASS - amount: 3 - amount_shell: 1 - selected: false - - ress: CONDUIT - amount: 1 - amount_shell: 15 - selected: false - - ress: DECORATED_POT - amount: 2 - amount_shell: 1 - selected: false - - ress: CALIBRATED_SCULK_SENSOR - amount: 4 - amount_shell: 1 - selected: false - - ress: MUDDY_MANGROVE_ROOTS - amount: 2 - amount_shell: 3 - selected: false - - ress: TORCHFLOWER - amount: 2 - amount_shell: 3 - selected: false - - ress: SPONGE - amount: 1 - amount_shell: 2 - selected: false - - ress: MAGENTA_GLAZED_TERRACOTTA - amount: 3 - amount_shell: 1 - selected: false - - ress: VERDANT_FROGLIGHT - amount: 1 - amount_shell: 2 - selected: false - - ress: HONEYCOMB - amount: 2 - amount_shell: 1 - selected: false rewards: peluche_aywen: #Example à laisser From eda85176f9a88d47924bb9f876ca95e8052707a0 Mon Sep 17 00:00:00 2001 From: iambibi Date: Tue, 22 Oct 2024 22:53:09 +0200 Subject: [PATCH 05/18] Fix Fly Flag on Gamemode --- .../fr/communaywen/core/listeners/CustomFlagsEvents.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/fr/communaywen/core/listeners/CustomFlagsEvents.java b/src/main/java/fr/communaywen/core/listeners/CustomFlagsEvents.java index 1b64d91d..3589567b 100644 --- a/src/main/java/fr/communaywen/core/listeners/CustomFlagsEvents.java +++ b/src/main/java/fr/communaywen/core/listeners/CustomFlagsEvents.java @@ -7,6 +7,7 @@ import com.sk89q.worldguard.protection.regions.RegionContainer; import com.sk89q.worldguard.protection.regions.RegionQuery; import fr.communaywen.core.AywenCraftPlugin; +import org.bukkit.GameMode; import org.bukkit.Material; import org.bukkit.entity.EntityType; import org.bukkit.entity.Player; @@ -31,6 +32,11 @@ public void onFlyToggle(org.bukkit.event.player.PlayerToggleFlightEvent event) { RegionQuery query = container.createQuery(); ApplicableRegionSet set = query.getApplicableRegions(BukkitAdapter.adapt(event.getPlayer().getLocation())); + if(event.getPlayer().getGameMode() == GameMode.CREATIVE) { + event.setCancelled(false); + return; + } + if(event.getPlayer().hasPermission("essentials.fly")) { event.setCancelled(false); return; From 45e7c225e7bd64fabfae0124fd7e1447bb0c5099 Mon Sep 17 00:00:00 2001 From: AxenoDev Date: Tue, 22 Oct 2024 23:05:56 +0200 Subject: [PATCH 06/18] Adding a security to check if pq is null or not --- .../communaywen/core/quests/PlayerQuests.java | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/main/java/fr/communaywen/core/quests/PlayerQuests.java b/src/main/java/fr/communaywen/core/quests/PlayerQuests.java index f3918b1a..bc830873 100644 --- a/src/main/java/fr/communaywen/core/quests/PlayerQuests.java +++ b/src/main/java/fr/communaywen/core/quests/PlayerQuests.java @@ -2,6 +2,7 @@ import fr.communaywen.core.quests.qenum.QUESTS; import lombok.Getter; +import org.jetbrains.annotations.NotNull; import java.util.HashMap; import java.util.Map; @@ -9,8 +10,8 @@ @Getter public class PlayerQuests { - private final Map questsProgress; - public final Map questsTier; + @NotNull private final Map questsProgress; + @NotNull public final Map questsTier; public PlayerQuests() { this.questsProgress = new HashMap<>(); @@ -21,19 +22,19 @@ public PlayerQuests() { } } - public int getProgress(QUESTS quest) { + public int getProgress(@NotNull QUESTS quest) { return questsProgress.getOrDefault(quest, 0); } - public int getCurrentTier(QUESTS quest) { + public int getCurrentTier(@NotNull QUESTS quest) { return questsTier.getOrDefault(quest, 0); } - public void setCurrentTier(QUESTS quests, int tier) { + public void setCurrentTier(@NotNull QUESTS quests, int tier) { questsTier.put(quests, tier); } - public void setProgress(QUESTS quest, int progress) { + public void setProgress(@NotNull QUESTS quest, int progress) { questsProgress.put(quest, progress); int tier = 0; for (int i = 0; i < quest.getQtTiers().length; i++) { @@ -46,7 +47,7 @@ public void setProgress(QUESTS quest, int progress) { } } - public void addProgress(QUESTS quest, int amount) { + public void addProgress(@NotNull QUESTS quest, int amount) { int currentTier = getCurrentTier(quest); if(currentTier < 0 || currentTier >= quest.getQtTiers().length) throw new IllegalArgumentException("Invalid tier for quest " + quest.name()); @@ -58,12 +59,12 @@ public void addProgress(QUESTS quest, int amount) { } } - public boolean isQuestCompleted(QUESTS quest) { + public boolean isQuestCompleted(@NotNull QUESTS quest) { int currentTier = getCurrentTier(quest); return currentTier >= quest.getQtTiers().length - 1 && getProgress(quest) >= quest.getQt(quest.getQtTiers().length - 1); } - public void removeProgress(QUESTS quest, int amount) { + public void removeProgress(@NotNull QUESTS quest, int amount) { int currentProgress = questsProgress.getOrDefault(quest, 0); int newProgress = Math.max(0, currentProgress - amount); questsProgress.put(quest, newProgress); @@ -79,7 +80,7 @@ public void removeProgress(QUESTS quest, int amount) { } } - public void resetProgress(QUESTS quest) { + public void resetProgress(@NotNull QUESTS quest) { questsProgress.put(quest, 0); setCurrentTier(quest, 0); } From ad6634ef591e0db42508cc73fbe4b73155e6b542 Mon Sep 17 00:00:00 2001 From: AxenoDev Date: Tue, 22 Oct 2024 23:06:57 +0200 Subject: [PATCH 07/18] Adding a security to check if pq is null or not --- .../java/fr/communaywen/core/quests/QuestsManager.java | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/main/java/fr/communaywen/core/quests/QuestsManager.java b/src/main/java/fr/communaywen/core/quests/QuestsManager.java index 4d5c95d3..181caf89 100644 --- a/src/main/java/fr/communaywen/core/quests/QuestsManager.java +++ b/src/main/java/fr/communaywen/core/quests/QuestsManager.java @@ -17,6 +17,7 @@ import org.bukkit.Sound; import org.bukkit.entity.Player; import org.bukkit.inventory.ItemStack; +import org.jetbrains.annotations.NotNull; import java.sql.*; import java.util.*; @@ -57,8 +58,6 @@ public static void loadPlayerData(Player player) throws SQLException { playerQuests.put(playerId, pq); for (QUESTS quest : QUESTS.values()) { - int progress = pq.getProgress(quest); - int tier = pq.getCurrentTier(quest); StringBuilder tierInfo = new StringBuilder(); for (int i = 0; i < quest.getQtTiers().length; i++) { tierInfo.append("Tier ").append(i).append(": ").append(quest.getQt(i)).append(", "); @@ -72,11 +71,9 @@ public static PlayerQuests getPlayerQuests(UUID player) { public static void manageQuestsPlayer(UUID uuid, QUESTS quest, int amount, String actionBar) { Player player = Bukkit.getPlayer(uuid); - if(!player.isConnected()) return; - PlayerQuests pq = getPlayerQuests(uuid); + @NotNull PlayerQuests pq = getPlayerQuests(uuid); int currentTier = pq.getCurrentTier(quest); - - if (pq.isQuestCompleted(quest)) { return; } + if (!player.isConnected() || pq == null || pq.isQuestCompleted(quest)) { return; } if (currentTier < 0 || currentTier >= quest.getQtTiers().length) { return; From f80656abaac15e0bedf6f8d6db19b75ffcc5edac Mon Sep 17 00:00:00 2001 From: MathiasDPX Date: Wed, 23 Oct 2024 11:42:09 +0200 Subject: [PATCH 08/18] Add logo --- .gitignore | 5 ++--- .idea/icon.png | Bin 0 -> 12755 bytes 2 files changed, 2 insertions(+), 3 deletions(-) create mode 100644 .idea/icon.png diff --git a/.gitignore b/.gitignore index 2727da89..293333ab 100644 --- a/.gitignore +++ b/.gitignore @@ -138,7 +138,6 @@ gradle-app.setting ### Project ### /builds/ - bin/ - -/server/ \ No newline at end of file +/server/ +!.idea/icon.png \ No newline at end of file diff --git a/.idea/icon.png b/.idea/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..d0477cfee1cd5be204263f46f959c1facdf2c4d0 GIT binary patch literal 12755 zcmeHuc|6qJ+y9v{A`+FjqZlnz3~m(>W+)+BDOtu=l65Q-+07s+vZSPL*@+Ocj4jQS zl%j0e*X&Dn!kFcE+~4QJb*}6EJ|12+)aK(6;Q;{f z>FQiC1^@{^A_4af_-EDkCmsIT>7iqO2LRrE+dl~K&&$7HBjS#+wk9b2ac~+wpd2&| zGyr%T%geaI3Bccux)(IA`6A{9c;igg5*C*151%v$M8}>>&u&E@=MSHFt?46pUTKd4 zId(7d$%W{n_Ma`Ao_67#O(ad6qwNQBm0BO3b&f|!><^!KCh4{QAPax_-bDI4yx>3D zhfnioDvC7uuJ`)KUrgV6**;17L7HQ)pYs0Jq;D_zFrt(c@P=){eli$*W9|I=pfr<|N4o?KeV)v=z}PL7I1eRJS-~G z`6>1McP{mHDi*^7CT)B}9vv5#7UmO|1o3lO6*gwfw?IcGXt7JCAbt){dBtp=?yar4 zW|%BWsxdl+DtYMh{WE)cC_9ni+OR1r4$lbu(2c%)76sBkVE4!*@0%S{J>=z` z`;ll8)S}pCWqq@-2?Zl{LFNMGcXIg&TfOeJCQSJ)Q{r?kSKw#SoTW_h_i(<83=4`J_FKkVcmmmT0ug{4po-TNtSGDr}=~jT(tgKS=yY%nsB+6-S z)zg!EPT7SeXLf4$+*^VwF(dW4%NlRAw?gZ!|P`+Kz7W<>{jQjj2 zqWL$+Gx}2tpB=%JjMcLv!^r!g+U=kXjLiE-l#ci>)*Sy=J}@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s z#mF6iImLONo@v#9rp*l9+8EoL<3`NgBn$Gu&PQP9EbMdo#PwVXP+}j`3+&7SNr<(8 z)ApaeEOZz5CV^kIny&lajsG||)hhWw4Eb)I(zkN=ugf`jNp1e%XF4AoY~C^ZN?9f# zwmzvfBa+O@ohS5;Gqf#-guM5O#%Es5F(j@|U4b=9er48Bhcxx?zpW?g@YsKm%q+^z zPR#4*X70)~iMsV3&s*C3!-S!C9X&VEl#LG}7C>IN4_P%Rnd|OuL7)7Nsj@740?n5X z(Oisa;;yAde(gd{+)P_a-JsgJvnlYqY)x& zyMjs^Z@I=ryAGcVgBMNX&eAhkpC>RSYV?EsB;0OAcJ0sn*`O_J-w#rxaqWYtmx3Ht z^}jw|$Fu$ Date: Wed, 23 Oct 2024 11:45:54 +0200 Subject: [PATCH 09/18] Fix Crash Contest --- .../core/contest/managers/ContestManager.java | 22 +++++++++---------- .../core/contest/menu/ConfirmMenu.java | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/main/java/fr/communaywen/core/contest/managers/ContestManager.java b/src/main/java/fr/communaywen/core/contest/managers/ContestManager.java index 1ed7ca3d..0fc23c29 100644 --- a/src/main/java/fr/communaywen/core/contest/managers/ContestManager.java +++ b/src/main/java/fr/communaywen/core/contest/managers/ContestManager.java @@ -564,17 +564,17 @@ public void updateColumnBooleanFromRandomTrades(Boolean bool, String ress) { } public void insertChoicePlayer(Player player, Integer camp) { - - String sql = "INSERT INTO camps (minecraft_uuid, name, camps, point_dep) VALUES (?, ?, ?, 0)"; - try (PreparedStatement states = connection.prepareStatement(sql)) { - states.setString(1, player.getUniqueId().toString()); - states.setString(2, player.getName()); - states.setInt(3, camp); - states.addBatch(); - states.executeBatch(); - } catch (SQLException e) { - throw new RuntimeException(e); - } + Bukkit.getScheduler().runTaskAsynchronously(plugins, () -> { + String sql = "INSERT INTO camps (minecraft_uuid, name, camps, point_dep) VALUES (?, ?, ?, 0)"; + try (PreparedStatement states = connection.prepareStatement(sql)) { + states.setString(1, player.getUniqueId().toString()); + states.setString(2, player.getName()); + states.setInt(3, camp); + states.executeUpdate(); + } catch (SQLException e) { + throw new RuntimeException(e); + } + }); } public DayOfWeek getCurrentDayOfWeek() { diff --git a/src/main/java/fr/communaywen/core/contest/menu/ConfirmMenu.java b/src/main/java/fr/communaywen/core/contest/menu/ConfirmMenu.java index c4976267..598625dd 100644 --- a/src/main/java/fr/communaywen/core/contest/menu/ConfirmMenu.java +++ b/src/main/java/fr/communaywen/core/contest/menu/ConfirmMenu.java @@ -50,8 +50,8 @@ public void onInventoryClick(InventoryClickEvent click) {} public @NotNull Map getContent() { Map inventory = new HashMap<>(); - String campNameFinal = contestManager.getString("contest", getCampName).join();; - String campColor = contestManager.getString("contest", getColor).join();; + String campNameFinal = ContestManager.getString("contest", getCampName).join();; + String campColor = ContestManager.getString("contest", getColor).join();; ChatColor colorFinal = ChatColor.valueOf(campColor); List lore1 = new ArrayList(); From dc7961fe719c715aae9a6c9c02e816ed9a6f5309 Mon Sep 17 00:00:00 2001 From: iambibi Date: Wed, 23 Oct 2024 13:01:30 +0200 Subject: [PATCH 10/18] Fix Crash Contest (2) --- .../java/fr/communaywen/core/QuizManager.java | 10 ++--- .../core/commands/contest/ContestCommand.java | 2 +- .../core/contest/cache/ContestCache.java | 2 +- .../core/contest/managers/ContestManager.java | 22 ++++------ .../core/contest/menu/ConfirmMenu.java | 29 ++++++++----- .../core/contest/menu/ContributionMenu.java | 42 ++++++++++--------- 6 files changed, 57 insertions(+), 50 deletions(-) diff --git a/src/main/java/fr/communaywen/core/QuizManager.java b/src/main/java/fr/communaywen/core/QuizManager.java index c34caa57..ae9ce957 100644 --- a/src/main/java/fr/communaywen/core/QuizManager.java +++ b/src/main/java/fr/communaywen/core/QuizManager.java @@ -102,11 +102,11 @@ public void onPlayerChat(AsyncPlayerChatEvent event) { "§8§m §r" ); - - contestManager.addPointPlayer(points + contestManager.getPlayerPoints(event.getPlayer()).join(), event.getPlayer()); - String playerCamp = "points" + contestCache.getPlayerCampsCache(event.getPlayer()); - contestManager.updateColumnInt("contest", playerCamp, points + contestManager.getInt("contest", playerCamp).join()); - + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + contestManager.addPointPlayer(points + contestManager.getPlayerPoints(event.getPlayer()), event.getPlayer()); + String playerCamp = "points" + contestCache.getPlayerCampsCache(event.getPlayer()); + contestManager.updateColumnInt("contest", playerCamp, points + contestManager.getInt("contest", playerCamp)); + }); } else { Bukkit.broadcastMessage( "§8§m §r\n" + diff --git a/src/main/java/fr/communaywen/core/commands/contest/ContestCommand.java b/src/main/java/fr/communaywen/core/commands/contest/ContestCommand.java index 35e0bd60..7e633aaf 100644 --- a/src/main/java/fr/communaywen/core/commands/contest/ContestCommand.java +++ b/src/main/java/fr/communaywen/core/commands/contest/ContestCommand.java @@ -99,7 +99,7 @@ public void setcontest(Player player, String camp1, @Named("colorContest") Strin @Description("Permet d'ajouter des points a un membre") @CommandPermission("ayw.command.contest.addpoints") public void addpoints(Player player, Player target, Integer points) { - contestManager.addPointPlayer(points + contestManager.getPlayerPoints(target).join(), target); + contestManager.addPointPlayer(points + contestManager.getPlayerPoints(target), target); MessageManager.sendMessageType(player, "§aVous avez ajouté " + points + " §apoint(s) à " + target.getName(), Prefix.STAFF, MessageType.SUCCESS, true); } diff --git a/src/main/java/fr/communaywen/core/contest/cache/ContestCache.java b/src/main/java/fr/communaywen/core/contest/cache/ContestCache.java index 81f4bbc4..3f264256 100644 --- a/src/main/java/fr/communaywen/core/contest/cache/ContestCache.java +++ b/src/main/java/fr/communaywen/core/contest/cache/ContestCache.java @@ -148,7 +148,7 @@ public void initPlayerDataCache(Player player) { if (result.next()) { int points = result.getInt("point_dep"); int camp = result.getInt("camps"); - String color = ContestManager.getString("contest","color" + camp).join(); + String color = ContestManager.getString("contest","color" + camp); ChatColor campColor = ChatColor.valueOf(color); Bukkit.getScheduler().runTask(plugin, () -> { diff --git a/src/main/java/fr/communaywen/core/contest/managers/ContestManager.java b/src/main/java/fr/communaywen/core/contest/managers/ContestManager.java index 0fc23c29..26d2f055 100644 --- a/src/main/java/fr/communaywen/core/contest/managers/ContestManager.java +++ b/src/main/java/fr/communaywen/core/contest/managers/ContestManager.java @@ -252,8 +252,8 @@ public void initPhase3(JavaPlugin plugin, FileConfiguration eventConfig) { int totalvote = vote1 + vote2; int vote1Taux = (int) (((double) vote1 / totalvote) * 100); int vote2Taux = (int) (((double) vote2 / totalvote) * 100); - int points1 = getInt("contest", "points1").join(); - int points2 = getInt("contest", "points2").join(); + int points1 = getInt("contest", "points1"); + int points2 = getInt("contest", "points2"); int multiplicateurPoint = Math.abs(vote1Taux - vote2Taux)/16; multiplicateurPoint=Integer.valueOf(df.format(multiplicateurPoint)); @@ -464,8 +464,7 @@ public void initPhase3(JavaPlugin plugin, FileConfiguration eventConfig) { System.out.println("[CONTEST] Fermeture du Contest"); } - public static CompletableFuture getString(String table, String column) { - return CompletableFuture.supplyAsync(() -> { + public static String getString(String table, String column) { try { PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + table); ResultSet rs = statement.executeQuery(); @@ -476,11 +475,9 @@ public static CompletableFuture getString(String table, String column) { throw new RuntimeException(e); } return null; - }); } - public static CompletableFuture getInt(String table, String column) { - return CompletableFuture.supplyAsync(() -> { + public static Integer getInt(String table, String column) { try { PreparedStatement statement = connection.prepareStatement("SELECT * FROM "+table); ResultSet rs = statement.executeQuery(); @@ -491,7 +488,6 @@ public static CompletableFuture getInt(String table, String column) { throw new RuntimeException(e); } return -1; - }); } public static String getTimeUntilNextMonday() { @@ -508,8 +504,7 @@ public static String getTimeUntilNextMonday() { return String.format("%dd %dh %dm", days, hours, minutes); } - public CompletableFuture getPlayerPoints(Player player) { - return CompletableFuture.supplyAsync(() -> { + public Integer getPlayerPoints(Player player) { UUID playerUUID = player.getUniqueId(); String sql = "SELECT * FROM camps WHERE minecraft_uuid = ?"; @@ -523,7 +518,6 @@ public CompletableFuture getPlayerPoints(Player player) { throw new RuntimeException(e); } return -1; - }); } @@ -616,7 +610,7 @@ public ResultSet getAllPlayer() { public String getPlayerCampName(Player player) { Integer campInteger = contestCache.getPlayerCampsCache(player); - String campName = getString("contest","camp" + campInteger).join(); + String campName = getString("contest","camp" + campInteger); return campName; } public Integer getOfflinePlayerCamp(OfflinePlayer player) { @@ -635,12 +629,12 @@ public Integer getOfflinePlayerCamp(OfflinePlayer player) { public String getOfflinePlayerCampName(OfflinePlayer player) { Integer campInteger = getOfflinePlayerCamp(player); - String campName = getString("contest","camp" + campInteger).join();; + String campName = getString("contest","camp" + campInteger);; return campName; } public ChatColor getOfflinePlayerCampChatColor(OfflinePlayer player) { Integer campInteger = getOfflinePlayerCamp(player); - String color = getString("contest","color" + campInteger).join();; + String color = getString("contest","color" + campInteger);; ChatColor campColor = ChatColor.valueOf(color); return campColor; } diff --git a/src/main/java/fr/communaywen/core/contest/menu/ConfirmMenu.java b/src/main/java/fr/communaywen/core/contest/menu/ConfirmMenu.java index 598625dd..c8a30a34 100644 --- a/src/main/java/fr/communaywen/core/contest/menu/ConfirmMenu.java +++ b/src/main/java/fr/communaywen/core/contest/menu/ConfirmMenu.java @@ -8,6 +8,7 @@ import fr.communaywen.core.utils.constant.MessageType; import fr.communaywen.core.utils.constant.Prefix; import me.clip.placeholderapi.PlaceholderAPI; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.Sound; @@ -18,6 +19,7 @@ import org.jetbrains.annotations.NotNull; import java.util.*; +import java.util.concurrent.CompletableFuture; public class ConfirmMenu extends Menu { private final String getCampName; @@ -50,16 +52,21 @@ public void onInventoryClick(InventoryClickEvent click) {} public @NotNull Map getContent() { Map inventory = new HashMap<>(); - String campNameFinal = ContestManager.getString("contest", getCampName).join();; - String campColor = ContestManager.getString("contest", getColor).join();; - ChatColor colorFinal = ChatColor.valueOf(campColor); + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { - List lore1 = new ArrayList(); - lore1.add("§7Vous allez rejoindre " + colorFinal + "La Team " + campNameFinal); - lore1.add("§c§lATTENTION! Vous ne pourrez changer de choix !"); + String campName = ContestManager.getString("contest", getCampName); - List lore0 = new ArrayList(); - lore0.add("§7Vous allez annuler votre choix : " + colorFinal + "La Team " + campNameFinal); + String campColor = ContestManager.getString("contest", getColor); + + ChatColor colorFinal = ChatColor.valueOf(campColor); + + Bukkit.getScheduler().runTask(plugin, () -> { + List lore1 = new ArrayList(); + lore1.add("§7Vous allez rejoindre " + colorFinal + "La Team " + campName); + lore1.add("§c§lATTENTION! Vous ne pourrez changer de choix !"); + + List lore0 = new ArrayList(); + lore0.add("§7Vous allez annuler votre choix : " + colorFinal + "La Team " + campName); inventory.put(11, new ItemBuilder(this, Material.RED_CONCRETE, itemMeta -> { itemMeta.setDisplayName("§r§cAnnuler"); @@ -76,9 +83,11 @@ public void onInventoryClick(InventoryClickEvent click) {} String substring = this.getCampName.substring(this.getCampName.length() - 1); contestManager.insertChoicePlayer(getOwner(), Integer.valueOf(substring)); getOwner().playSound(getOwner().getEyeLocation(), Sound.BLOCK_AMETHYST_BLOCK_RESONATE, 1.0F, 0.2F); - MessageManager.sendMessageType(getOwner(), "§7Vous avez bien rejoint : "+ colorFinal + "La Team " + contestManager.getString("contest", getCampName).join(), Prefix.CONTEST, MessageType.SUCCESS, false); + MessageManager.sendMessageType(getOwner(), "§7Vous avez bien rejoint : " + colorFinal + "La Team " + campName, Prefix.CONTEST, MessageType.SUCCESS, false); getOwner().closeInventory(); })); - return inventory; + }); + }); + return inventory; } } diff --git a/src/main/java/fr/communaywen/core/contest/menu/ContributionMenu.java b/src/main/java/fr/communaywen/core/contest/menu/ContributionMenu.java index c4019f1b..96fe1014 100644 --- a/src/main/java/fr/communaywen/core/contest/menu/ContributionMenu.java +++ b/src/main/java/fr/communaywen/core/contest/menu/ContributionMenu.java @@ -13,6 +13,7 @@ import fr.communaywen.core.utils.constant.MessageType; import fr.communaywen.core.utils.constant.Prefix; import me.clip.placeholderapi.PlaceholderAPI; +import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.Material; import org.bukkit.configuration.ConfigurationSection; @@ -113,32 +114,35 @@ public void onInventoryClick(InventoryClickEvent click) { itemMeta.setDisplayName("§r§7Contribuer pour la"+ campColor+ " Team " + campName); itemMeta.setLore(lore_contribute); }).setOnClick(inventoryClickEvent -> { - try { - ItemStack shell_contestItem = CustomStack.getInstance("contest:contest_shell").getItemStack(); + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + try { + ItemStack shell_contestItem = CustomStack.getInstance("contest:contest_shell").getItemStack(); - int shellCount = Arrays.stream(getOwner().getInventory().getContents()).filter(is -> is != null && is.isSimilar(shell_contestItem)).mapToInt(ItemStack::getAmount).sum(); + int shellCount = Arrays.stream(getOwner().getInventory().getContents()).filter(is -> is != null && is.isSimilar(shell_contestItem)).mapToInt(ItemStack::getAmount).sum(); - if (ItemUtils.hasEnoughItems(getOwner(), shell_contestItem.getType(), shellCount)) { - ItemUtils.removeItemsFromInventory(getOwner(), shell_contestItem.getType(), shellCount); + if (ItemUtils.hasEnoughItems(getOwner(), shell_contestItem.getType(), shellCount)) { + ItemUtils.removeItemsFromInventory(getOwner(), shell_contestItem.getType(), shellCount); - contestManager.getPlayerPoints(getOwner()).thenAccept(playerPoints -> { - int newPlayerPoints = shellCount + playerPoints; + int newPlayerPoints = shellCount + contestManager.getPlayerPoints(getOwner()); + int updatedCampPoints = shellCount + contestManager.getInt("contest", "points" + contestCache.getPlayerCampsCache(getOwner())); - contestManager.getInt("contest", "points" + contestCache.getPlayerCampsCache(getOwner())) - .thenAccept(campPoints -> { - int updatedCampPoints = shellCount + campPoints; - contestManager.updateColumnInt("contest", "points" + contestCache.getPlayerCampsCache(getOwner()), updatedCampPoints); + contestManager.addPointPlayer(newPlayerPoints, getOwner()); - MessageManager.sendMessageType(getOwner(), "§7Vous avez déposé§b " + shellCount + " Coquillage(s) de Contest§7 pour votre Team!", Prefix.CONTEST, MessageType.SUCCESS, true); - }); - }); - } else { - MessageManager.sendMessageType(getOwner(), "§cVous n'avez pas de Coquillage(s) de Contest§7", Prefix.CONTEST, MessageType.ERROR, true); + contestManager.updateColumnInt("contest", "points" + contestCache.getPlayerCampsCache(getOwner()), updatedCampPoints); + + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + MessageManager.sendMessageType(getOwner(), "§7Vous avez déposé§b " + shellCount + " Coquillage(s) de Contest§7 pour votre Team!", Prefix.CONTEST, MessageType.SUCCESS, true); + }); + } else { + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + MessageManager.sendMessageType(getOwner(), "§cVous n'avez pas de Coquillage(s) de Contest§7", Prefix.CONTEST, MessageType.ERROR, true); + }); + } + } catch (Exception e) { + throw new RuntimeException(e); } - } catch (Exception e) { - throw new RuntimeException(e); - } + }); })); inventory.put(16, new ItemBuilder(this, Material.OMINOUS_TRIAL_KEY, itemMeta -> { From 0d93d5d37a0e3004240244e04a429faec33958fa Mon Sep 17 00:00:00 2001 From: iambibi Date: Wed, 23 Oct 2024 15:38:25 +0200 Subject: [PATCH 11/18] Fix Crash Contest (3) --- .../core/contest/menu/ConfirmMenu.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/java/fr/communaywen/core/contest/menu/ConfirmMenu.java b/src/main/java/fr/communaywen/core/contest/menu/ConfirmMenu.java index c8a30a34..e6b9fc27 100644 --- a/src/main/java/fr/communaywen/core/contest/menu/ConfirmMenu.java +++ b/src/main/java/fr/communaywen/core/contest/menu/ConfirmMenu.java @@ -15,11 +15,11 @@ import org.bukkit.entity.Player; import dev.xernas.menulib.Menu; import org.bukkit.event.inventory.InventoryClickEvent; +import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; import org.jetbrains.annotations.NotNull; import java.util.*; -import java.util.concurrent.CompletableFuture; public class ConfirmMenu extends Menu { private final String getCampName; @@ -27,12 +27,15 @@ public class ConfirmMenu extends Menu { private final ContestManager contestManager; private final AywenCraftPlugin plugin; + private Map inventory; + private boolean isInventoryPrepared = false; // Flag pour vérifier si l'inventaire est prêt + public ConfirmMenu(Player owner, AywenCraftPlugin plugins, String camp, String color, ContestManager manager) { super(owner); this.contestManager = manager; this.getCampName = camp; this.getColor = color; - this.plugin= plugins; + this.plugin = plugins; } @Override @@ -48,24 +51,28 @@ public ConfirmMenu(Player owner, AywenCraftPlugin plugins, String camp, String c @Override public void onInventoryClick(InventoryClickEvent click) {} + @Override public @NotNull Map getContent() { - Map inventory = new HashMap<>(); - Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + if (isInventoryPrepared) { + return inventory; + } - String campName = ContestManager.getString("contest", getCampName); + inventory = new HashMap<>(); + isInventoryPrepared = true; + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + String campName = ContestManager.getString("contest", getCampName); String campColor = ContestManager.getString("contest", getColor); - ChatColor colorFinal = ChatColor.valueOf(campColor); - Bukkit.getScheduler().runTask(plugin, () -> { - List lore1 = new ArrayList(); + ChatColor colorFinal = ChatColor.valueOf(campColor); + List lore1 = new ArrayList<>(); lore1.add("§7Vous allez rejoindre " + colorFinal + "La Team " + campName); lore1.add("§c§lATTENTION! Vous ne pourrez changer de choix !"); - List lore0 = new ArrayList(); + List lore0 = new ArrayList<>(); lore0.add("§7Vous allez annuler votre choix : " + colorFinal + "La Team " + campName); inventory.put(11, new ItemBuilder(this, Material.RED_CONCRETE, itemMeta -> { @@ -86,8 +93,11 @@ public void onInventoryClick(InventoryClickEvent click) {} MessageManager.sendMessageType(getOwner(), "§7Vous avez bien rejoint : " + colorFinal + "La Team " + campName, Prefix.CONTEST, MessageType.SUCCESS, false); getOwner().closeInventory(); })); + + getOwner().openInventory(getInventory()); }); }); + return inventory; } -} +} \ No newline at end of file From 60ae18bcf57e02d2901b4c964ae6b9a0870eda4e Mon Sep 17 00:00:00 2001 From: AxenoDev Date: Wed, 23 Oct 2024 17:15:02 +0200 Subject: [PATCH 12/18] Oops, faut save les limits de homes --- src/main/java/fr/communaywen/core/Managers.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/fr/communaywen/core/Managers.java b/src/main/java/fr/communaywen/core/Managers.java index d126b36e..b00c895e 100644 --- a/src/main/java/fr/communaywen/core/Managers.java +++ b/src/main/java/fr/communaywen/core/Managers.java @@ -169,6 +169,7 @@ public void init(AywenCraftPlugin plugin) { public void cleanup() { /* Besoin de la db */ reportManager.saveReports(); + homesManagers.saveHomesLimits(); DreamTabManager.close(); /* Plus besoin de la db */ From 2978992c40f7a38cfc085b7c1b14f3ad114a4355 Mon Sep 17 00:00:00 2001 From: iambibi Date: Wed, 23 Oct 2024 17:32:45 +0200 Subject: [PATCH 13/18] Add Command Settrade --- .../fr/communaywen/core/AywenCraftPlugin.java | 1 + .../core/commands/contest/ContestCommand.java | 29 ++ .../core/contest/managers/ContestManager.java | 13 + .../core/contest/menu/TradeMenu.java | 289 ++++++++---------- src/main/resources/config.yml | 2 +- 5 files changed, 176 insertions(+), 158 deletions(-) diff --git a/src/main/java/fr/communaywen/core/AywenCraftPlugin.java b/src/main/java/fr/communaywen/core/AywenCraftPlugin.java index d9c036b7..800c331e 100644 --- a/src/main/java/fr/communaywen/core/AywenCraftPlugin.java +++ b/src/main/java/fr/communaywen/core/AywenCraftPlugin.java @@ -268,6 +268,7 @@ public void onEnable() { this.handler.getAutoCompleter().registerSuggestion("featureName", SuggestionProvider.of(managers.getWikiConfig().getKeys(false))); this.handler.getAutoCompleter().registerSuggestion("lbEventsId", SuggestionProvider.of(managers.getLuckyBlockManager().getLuckyBlocksIds())); this.handler.getAutoCompleter().registerSuggestion("colorContest", SuggestionProvider.of(managers.getContestManager().getColorContestList())); + this.handler.getAutoCompleter().registerSuggestion("trade", SuggestionProvider.of(managers.getContestManager().getRessListFromConfig())); this.handler.getAutoCompleter().registerSuggestion("listLeaderboard", SuggestionProvider.of(managers.getLeaderboardManager().getLbList())); this.handler.getAutoCompleter().registerSuggestion("homeWorldsAdd", (args, sender, command) -> { diff --git a/src/main/java/fr/communaywen/core/commands/contest/ContestCommand.java b/src/main/java/fr/communaywen/core/commands/contest/ContestCommand.java index 7e633aaf..d8f0182f 100644 --- a/src/main/java/fr/communaywen/core/commands/contest/ContestCommand.java +++ b/src/main/java/fr/communaywen/core/commands/contest/ContestCommand.java @@ -17,7 +17,9 @@ import java.time.DayOfWeek; import java.time.format.DateTimeFormatter; +import java.util.List; import java.util.Locale; +import java.util.Map; @Feature("Contest") @Credit("iambibi_") @@ -95,6 +97,33 @@ public void setcontest(Player player, String camp1, @Named("colorContest") Strin } } + @Subcommand("settrade") + @Description("Permet de définir un Trade") + @CommandPermission("ayw.command.contest.settrade") + @AutoComplete("@trade") + public void settrade(Player player, @Named("trade") String trade, int amount, int amount_shell) { + FileConfiguration config = plugin.getConfig(); + List> trades = config.getMapList("contest.contestTrades"); + + boolean tradeFound = false; + + for (Map tradeEntry : trades) { + if (tradeEntry.get("ress").equals(trade)) { + ((Map) tradeEntry).put("amount", amount); + ((Map) tradeEntry).put("amount_shell", amount_shell); + tradeFound = true; + break; + } + } + + if (tradeFound) { + plugin.saveConfig(); + MessageManager.sendMessageType(player, "Le trade de " + trade + " a été mis à jour avec " + amount + " pour " + amount_shell + " coquillages de contest.", Prefix.STAFF, MessageType.SUCCESS, true); + } else { + MessageManager.sendMessageType(player, "Le trade n'existe pas.\n/contest settrade ", Prefix.STAFF, MessageType.ERROR, true); + } + } + @Subcommand("addpoints") @Description("Permet d'ajouter des points a un membre") @CommandPermission("ayw.command.contest.addpoints") diff --git a/src/main/java/fr/communaywen/core/contest/managers/ContestManager.java b/src/main/java/fr/communaywen/core/contest/managers/ContestManager.java index 26d2f055..69b7f4f8 100644 --- a/src/main/java/fr/communaywen/core/contest/managers/ContestManager.java +++ b/src/main/java/fr/communaywen/core/contest/managers/ContestManager.java @@ -901,6 +901,19 @@ public double getMultiLuckyFromRang(int rang) { //END CONTEST METHODE + public List getRessListFromConfig() { + FileConfiguration config = plugins.getConfig(); + List> trades = config.getMapList("contest.contestTrades"); + List ressList = new ArrayList<>(); + + for (Map tradeEntry : trades) { + if (tradeEntry.containsKey("ress")) { + ressList.add(tradeEntry.get("ress").toString()); + } + } + return ressList; + } + private void updateSelected(String camp) { List> contestList = config.getMapList("contest.contestList"); List> updatedContestList = new ArrayList<>(); diff --git a/src/main/java/fr/communaywen/core/contest/menu/TradeMenu.java b/src/main/java/fr/communaywen/core/contest/menu/TradeMenu.java index 8889cc19..4ae1defe 100644 --- a/src/main/java/fr/communaywen/core/contest/menu/TradeMenu.java +++ b/src/main/java/fr/communaywen/core/contest/menu/TradeMenu.java @@ -22,6 +22,7 @@ import org.jetbrains.annotations.NotNull; import java.util.*; +import java.util.stream.Collectors; import static fr.communaywen.core.utils.ItemUtils.getSlotNull; import static fr.communaywen.core.utils.ItemUtils.getNumberItemToStack; @@ -51,165 +52,139 @@ public TradeMenu(Player owner, ContestManager manager) { public void onInventoryClick(InventoryClickEvent click) { } - @Override - public @NotNull Map getContent() { - Map inventory = new HashMap<>(); - if (getOwner().getOpenInventory().getTitle()!="§r§f%img_offset_-48%%img_contest_menu%") { - String campName = contestManager.getPlayerCampName(getOwner()); - ChatColor campColor = contestCache.getPlayerColorCache(getOwner()); - Material shell_contest = CustomStack.getInstance("contest:contest_shell").getItemStack().getType(); - - List loreinfo = new ArrayList(); - List lore_trade = new ArrayList(); - - loreinfo.add("§7Apprenez en plus sur les Contest !"); - loreinfo.add("§7Le déroulement..., Les résultats, ..."); - loreinfo.add("§e§lCLIQUEZ ICI POUR EN VOIR PLUS!"); - - lore_trade.add("§7Vendez un maximum de ressources"); - lore_trade.add("§7Contre des §bCoquillages de Contest"); - lore_trade.add("§7Pour faire gagner la " + campColor + "Team " + campName); - - inventory.put(4, new ItemBuilder(this, shell_contest, itemMeta -> { - itemMeta.setDisplayName("§7Les Trades"); - itemMeta.setLore(lore_trade); - itemMeta.setCustomModelData(10000); - })); - List> selectedTrades = contestManager.getTradeSelected(true); - - List slot_trade = new ArrayList(); - slot_trade.add(10); - slot_trade.add(11); - slot_trade.add(12); - slot_trade.add(13); - slot_trade.add(14); - slot_trade.add(15); - slot_trade.add(16); - slot_trade.add(20); - slot_trade.add(21); - slot_trade.add(22); - slot_trade.add(23); - slot_trade.add(24); - - List lore_trades = new ArrayList(); - - int index = 0; - for (Map trade : selectedTrades) { - Integer slot = slot_trade.get(index); - index++; - - Material m = Material.getMaterial((String) trade.get("ress")); - - lore_trades.add("§7Vendez §e" + trade.get("amount") + " de cette ressource §7pour §b" + trade.get("amount_shell") + " Coquillage(s) de Contest"); - lore_trades.add("§e§lCLIQUE-GAUCHE POUR VENDRE UNE FOIS"); - lore_trades.add("§e§lSHIFT-CLIQUE-GAUCHE POUR VENDRE TOUTE CETTE RESSOURCE"); - - inventory.put(slot, new ItemBuilder(this, m, itemMeta -> { - itemMeta.setLore(lore_trades); - }).setOnClick(inventoryClickEvent -> { - String m1 = String.valueOf(inventoryClickEvent.getCurrentItem().getType()); - int amount = (int) trade.get("amount"); - int amount_shell = (int) trade.get("amount_shell"); - ItemStack shell_contestItem = CustomStack.getInstance("contest:contest_shell").getItemStack(); - if (inventoryClickEvent.isLeftClick() && inventoryClickEvent.isShiftClick()) { - int items = 0; - for (ItemStack is : getOwner().getInventory().getContents()) { - if (is != null && is.getType() == inventoryClickEvent.getCurrentItem().getType()) { - items = items + is.getAmount(); - } - } - - if (ItemUtils.hasEnoughItems(getOwner(), inventoryClickEvent.getCurrentItem().getType(), amount)) { - int amount_shell2 = (items / amount) * amount_shell; - int items1 = (amount_shell2 / amount_shell) * amount; - ItemUtils.removeItemsFromInventory(getOwner(), inventoryClickEvent.getCurrentItem().getType(), items1); - int slot_empty = getSlotNull(getOwner()); - int stack_available = slot_empty * 64; - int additem = Math.min(amount_shell2, stack_available); - if (stack_available >=64) { - shell_contestItem.setAmount(additem); - for (ItemStack item : splitAmountIntoStack(shell_contestItem)) { - getOwner().getInventory().addItem(item); - } - int remain1 = amount_shell2 - additem; - if(remain1 != 0) { - int numbertoStack = getNumberItemToStack(getOwner(), shell_contestItem); - if (numbertoStack > 0) { - shell_contestItem.setAmount(numbertoStack); - getOwner().getInventory().addItem(shell_contestItem); - } - - ItemStack newshell_contestItem = CustomStack.getInstance("contest:contest_shell").getItemStack(); - int remain2 = remain1 - numbertoStack; - if (remain2 != 0) { - newshell_contestItem.setAmount(remain2); - List itemlist = splitAmountIntoStack(newshell_contestItem); - ItemStack[] shell_contest_array = itemlist.toArray(new ItemStack[itemlist.size()]); - MailboxManager.sendItems(getOwner(), getOwner(), shell_contest_array); - } - } - } else { - shell_contestItem.setAmount(amount_shell2); - ItemStack[] shell_contest_array = new ItemStack[]{shell_contestItem, shell_contestItem}; - for (ItemStack item : splitAmountIntoStack(shell_contestItem)) { - getOwner().getInventory().addItem(item); - } - - MailboxManager.sendItems(getOwner(), getOwner(), shell_contest_array); - } - - MessageManager.sendMessageType(getOwner(), "§7Vous avez échangé §e" + items1 + " " + m1 + " §7contre§b " + amount_shell2 + " Coquillages(s) de Contest", Prefix.CONTEST, MessageType.SUCCESS, true); - } else { - MessageManager.sendMessageType(getOwner(), "§cVous n'avez pas assez de cette ressource pour pouvoir l'échanger!", Prefix.CONTEST, MessageType.ERROR, true); - } - } else if (inventoryClickEvent.isLeftClick()) { - if (ItemUtils.hasEnoughItems(getOwner(), inventoryClickEvent.getCurrentItem().getType(), amount)) { - - //mettre dans l'inv ou boite mail? - if (Arrays.asList(getOwner().getInventory().getStorageContents()).contains(null)) { - shell_contestItem.setAmount(amount_shell); - for (ItemStack item : splitAmountIntoStack(shell_contestItem)) { - getOwner().getInventory().addItem(item); - } - } else { - shell_contestItem.setAmount(amount_shell); - ItemStack[] shell_contest_array = new ItemStack[]{shell_contestItem}; - MailboxManager.sendItems(getOwner(), getOwner(), shell_contest_array); - } - - ItemUtils.removeItemsFromInventory(getOwner(), inventoryClickEvent.getCurrentItem().getType(), amount); - MessageManager.sendMessageType(getOwner(), "§7Vous avez échangé §e" + amount + " " + m1 + " §7contre§b " + amount_shell + " Coquillages(s) de Contest", Prefix.CONTEST, MessageType.SUCCESS, true); - } else { - MessageManager.sendMessageType(getOwner(), "§cVous n'avez pas assez de cette ressource pour pouvoir l'échanger!", Prefix.CONTEST, MessageType.ERROR, true); - } - } - - })); - - lore_trades.clear(); + @Override + public @NotNull Map getContent() { + Map inventory = new HashMap<>(); + String campName = contestManager.getPlayerCampName(getOwner()); + ChatColor campColor = contestCache.getPlayerColorCache(getOwner()); + Material shell_contest = CustomStack.getInstance("contest:contest_shell").getItemStack().getType(); + + List loreinfo = Arrays.asList( + "§7Apprenez en plus sur les Contest !", + "§7Le déroulement..., Les résultats, ...", + "§e§lCLIQUEZ ICI POUR EN VOIR PLUS!" + ); + + List lore_trade = Arrays.asList( + "§7Vendez un maximum de ressources", + "§7Contre des §bCoquillages de Contest", + "§7Pour faire gagner la " + campColor + "Team " + campName + ); + + inventory.put(4, new ItemBuilder(this, shell_contest, itemMeta -> { + itemMeta.setDisplayName("§7Les Trades"); + itemMeta.setLore(lore_trade); + itemMeta.setCustomModelData(10000); + })); + + List> selectedTrades = contestManager.getTradeSelected(true).stream() + .sorted(Comparator.comparing(trade -> (String) trade.get("ress"))) + .collect(Collectors.toList()); + + List slot_trade = Arrays.asList(10, 11, 12, 13, 14, 15, 16, 20, 21, 22, 23, 24); + + for (int i = 0; i < selectedTrades.size(); i++) { + Map trade = selectedTrades.get(i); + Integer slot = slot_trade.get(i); + + Material m = Material.getMaterial((String) trade.get("ress")); + List lore_trades = Arrays.asList( + "§7Vendez §e" + trade.get("amount") + " de cette ressource §7pour §b" + trade.get("amount_shell") + " Coquillage(s) de Contest", + "§e§lCLIQUE-GAUCHE POUR VENDRE UNE FOIS", + "§e§lSHIFT-CLIQUE-GAUCHE POUR VENDRE TOUTE CETTE RESSOURCE" + ); + + inventory.put(slot, new ItemBuilder(this, m, itemMeta -> { + itemMeta.setLore(lore_trades); + }).setOnClick(inventoryClickEvent -> { + String m1 = String.valueOf(inventoryClickEvent.getCurrentItem().getType()); + int amount = (int) trade.get("amount"); + int amount_shell = (int) trade.get("amount_shell"); + ItemStack shell_contestItem = CustomStack.getInstance("contest:contest_shell").getItemStack(); + if (inventoryClickEvent.isLeftClick() && inventoryClickEvent.isShiftClick()) { + int items = 0; + for (ItemStack is : getOwner().getInventory().getContents()) { + if (is != null && is.getType() == inventoryClickEvent.getCurrentItem().getType()) { + items = items + is.getAmount(); + } + } + + if (ItemUtils.hasEnoughItems(getOwner(), inventoryClickEvent.getCurrentItem().getType(), amount)) { + int amount_shell2 = (items / amount) * amount_shell; + int items1 = (amount_shell2 / amount_shell) * amount; + ItemUtils.removeItemsFromInventory(getOwner(), inventoryClickEvent.getCurrentItem().getType(), items1); + int slot_empty = getSlotNull(getOwner()); + int stack_available = slot_empty * 64; + int additem = Math.min(amount_shell2, stack_available); + if (stack_available >=64) { + shell_contestItem.setAmount(additem); + for (ItemStack item : splitAmountIntoStack(shell_contestItem)) { + getOwner().getInventory().addItem(item); + } + int remain1 = amount_shell2 - additem; + if(remain1 != 0) { + int numbertoStack = getNumberItemToStack(getOwner(), shell_contestItem); + if (numbertoStack > 0) { + shell_contestItem.setAmount(numbertoStack); + getOwner().getInventory().addItem(shell_contestItem); + } + + ItemStack newshell_contestItem = CustomStack.getInstance("contest:contest_shell").getItemStack(); + int remain2 = remain1 - numbertoStack; + if (remain2 != 0) { + newshell_contestItem.setAmount(remain2); + List itemlist = splitAmountIntoStack(newshell_contestItem); + ItemStack[] shell_contest_array = itemlist.toArray(new ItemStack[itemlist.size()]); + MailboxManager.sendItems(getOwner(), getOwner(), shell_contest_array); + } + } + } else { + shell_contestItem.setAmount(amount_shell2); + ItemStack[] shell_contest_array = new ItemStack[]{shell_contestItem, shell_contestItem}; + for (ItemStack item : splitAmountIntoStack(shell_contestItem)) { + getOwner().getInventory().addItem(item); + } + + MailboxManager.sendItems(getOwner(), getOwner(), shell_contest_array); + } + + MessageManager.sendMessageType(getOwner(), "§7Vous avez échangé §e" + items1 + " " + m1 + " §7contre§b " + amount_shell2 + " Coquillages(s) de Contest", Prefix.CONTEST, MessageType.SUCCESS, true); + } else { + MessageManager.sendMessageType(getOwner(), "§cVous n'avez pas assez de cette ressource pour pouvoir l'échanger!", Prefix.CONTEST, MessageType.ERROR, true); + } + } else if (inventoryClickEvent.isLeftClick()) { + if (ItemUtils.hasEnoughItems(getOwner(), inventoryClickEvent.getCurrentItem().getType(), amount)) { + + //mettre dans l'inv ou boite mail? + if (Arrays.asList(getOwner().getInventory().getStorageContents()).contains(null)) { + shell_contestItem.setAmount(amount_shell); + for (ItemStack item : splitAmountIntoStack(shell_contestItem)) { + getOwner().getInventory().addItem(item); + } + } else { + shell_contestItem.setAmount(amount_shell); + ItemStack[] shell_contest_array = new ItemStack[]{shell_contestItem}; + MailboxManager.sendItems(getOwner(), getOwner(), shell_contest_array); + } + + ItemUtils.removeItemsFromInventory(getOwner(), inventoryClickEvent.getCurrentItem().getType(), amount); + MessageManager.sendMessageType(getOwner(), "§7Vous avez échangé §e" + amount + " " + m1 + " §7contre§b " + amount_shell + " Coquillages(s) de Contest", Prefix.CONTEST, MessageType.SUCCESS, true); + } else { + MessageManager.sendMessageType(getOwner(), "§cVous n'avez pas assez de cette ressource pour pouvoir l'échanger!", Prefix.CONTEST, MessageType.ERROR, true); + } } + })); + } - inventory.put(27, new ItemBuilder(this, Material.ARROW, itemMeta -> { - itemMeta.setDisplayName("§r§aRetour"); - }).setBackButton()); - - inventory.put(35, new ItemBuilder(this, Material.EMERALD, itemMeta -> { - itemMeta.setDisplayName("§r§aPlus d'info !"); - itemMeta.setLore(loreinfo); - }).setNextMenu(new MoreInfoMenu(getOwner(), contestManager))); - - return inventory; - } + inventory.put(27, new ItemBuilder(this, Material.ARROW, itemMeta -> { + itemMeta.setDisplayName("§r§aRetour"); + }).setBackButton()); - Inventory currentinv = getOwner().getOpenInventory().getTopInventory(); - Map currentinv_map = new HashMap<>(); + inventory.put(35, new ItemBuilder(this, Material.EMERALD, itemMeta -> { + itemMeta.setDisplayName("§r§aPlus d'info !"); + itemMeta.setLore(loreinfo); + }).setNextMenu(new MoreInfoMenu(getOwner(), contestManager))); - for (int i = 0; i < currentinv.getSize(); i++) { - ItemStack item = currentinv.getItem(i); - if (item != null) { - currentinv_map.put(i, item); - } - } - return currentinv_map; - } + return inventory; + } } diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index ba0ec228..55f53029 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -175,7 +175,7 @@ contest: - ress: HONEYCOMB amount: 2 amount_shell: 1 - selected: falseD + selected: false contestList: - camp1: "Mayonnaise" color1: "YELLOW" From 55b501990d2d63ac25db6c4737c77156c25de736 Mon Sep 17 00:00:00 2001 From: iambibi Date: Wed, 23 Oct 2024 19:56:46 +0200 Subject: [PATCH 14/18] Add command leaderboard updateall --- .../commands/spawn/leaderboard/LeaderboardCommand.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/main/java/fr/communaywen/core/commands/spawn/leaderboard/LeaderboardCommand.java b/src/main/java/fr/communaywen/core/commands/spawn/leaderboard/LeaderboardCommand.java index b4d47ee6..5907c975 100644 --- a/src/main/java/fr/communaywen/core/commands/spawn/leaderboard/LeaderboardCommand.java +++ b/src/main/java/fr/communaywen/core/commands/spawn/leaderboard/LeaderboardCommand.java @@ -77,4 +77,14 @@ public void movestart(Player player, @Named("listLeaderboard") String lb) throws MessageManager.sendMessageType(player, "§cVous devez mettre un nom de leaderboard valable", Prefix.STAFF, MessageType.ERROR, true); } } + @Subcommand("updateall") + @Description("Met a jour les leaderboard") + @CommandPermission("ayw.command.leaderboard.updateall") + public void update(Player player) throws IOException { + LeaderboardManager.updateLeaderboardBalTop(); + LeaderboardManager.updateLeaderboardTeamTop(); + LeaderboardManager.updateLeaderboardContribution(); + LeaderboardManager.updateLeaderboardPlayTime(); + jumpManager.updateLeaderboardLeaderboardRecord(); + } } From c2b2b1cd3a309ff07a69ab4424d822cdca3a0067 Mon Sep 17 00:00:00 2001 From: iambibi Date: Wed, 23 Oct 2024 20:05:02 +0200 Subject: [PATCH 15/18] Fix Freeze of All Data --- src/main/java/fr/communaywen/core/listeners/OnPlayers.java | 5 ----- .../fr/communaywen/core/luckyblocks/utils/LBReminder.java | 4 ---- 2 files changed, 9 deletions(-) diff --git a/src/main/java/fr/communaywen/core/listeners/OnPlayers.java b/src/main/java/fr/communaywen/core/listeners/OnPlayers.java index 61834933..b5ecf08e 100644 --- a/src/main/java/fr/communaywen/core/listeners/OnPlayers.java +++ b/src/main/java/fr/communaywen/core/listeners/OnPlayers.java @@ -156,11 +156,6 @@ public void onPlayerQuit(PlayerQuitEvent event) { Bukkit.getScheduler().runTaskAsynchronously(AywenCraftPlugin.getInstance(), () -> { long timePlayed = player.getStatistic(Statistic.PLAY_ONE_MINUTE); LeaderboardManager.setTimePlayed(player, timePlayed); - - LBReminder reminder = new LBReminder(player, AywenCraftPlugin.getInstance().getManagers().getLbPlayerManager(), AywenCraftPlugin.getInstance()); - - reminder.stopReminder(); - }); } diff --git a/src/main/java/fr/communaywen/core/luckyblocks/utils/LBReminder.java b/src/main/java/fr/communaywen/core/luckyblocks/utils/LBReminder.java index 429e3831..508ec3b3 100644 --- a/src/main/java/fr/communaywen/core/luckyblocks/utils/LBReminder.java +++ b/src/main/java/fr/communaywen/core/luckyblocks/utils/LBReminder.java @@ -47,8 +47,4 @@ public void startReminder() { } }, 0L, 5 * 60 * 20L); } - - public void stopReminder() { - Bukkit.getScheduler().cancelTasks(plugin); - } } From ebe0d2b4783c6c91a41449f9be49db5a1d359242 Mon Sep 17 00:00:00 2001 From: MathiasDPX Date: Wed, 23 Oct 2024 20:20:41 +0200 Subject: [PATCH 16/18] Use batch for saving advancements --- .../listeners/dream/HelldiversManager.java | 45 ++++++++++++++----- 1 file changed, 34 insertions(+), 11 deletions(-) diff --git a/src/main/java/fr/communaywen/core/guideline/listeners/dream/HelldiversManager.java b/src/main/java/fr/communaywen/core/guideline/listeners/dream/HelldiversManager.java index e5cf4216..ae960899 100644 --- a/src/main/java/fr/communaywen/core/guideline/listeners/dream/HelldiversManager.java +++ b/src/main/java/fr/communaywen/core/guideline/listeners/dream/HelldiversManager.java @@ -12,7 +12,9 @@ import java.sql.PreparedStatement; import java.sql.ResultSet; +import java.sql.SQLException; import java.util.HashMap; +import java.util.Map; import java.util.UUID; public class HelldiversManager extends DatabaseConnector implements Listener { @@ -80,19 +82,40 @@ public void close() { private void saveAdvancementData(HashMap advancements, String advancementType) { AywenCraftPlugin.getInstance().getLogger().warning("Saving " + advancementType + " advancements"); - for (UUID player : advancements.keySet()) { - try { - PreparedStatement statement = connection.prepareStatement( - "INSERT INTO advancements (player, advancement, value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE value = ?"); - statement.setString(1, player.toString()); + try { + // Disable auto-commit for batch processing + connection.setAutoCommit(false); + + PreparedStatement statement = connection.prepareStatement( + "INSERT INTO advancements (player, advancement, value) VALUES (?, ?, ?) ON DUPLICATE KEY UPDATE value = ?"); + + // Add all entries to batch + for (Map.Entry entry : advancements.entrySet()) { + statement.setString(1, entry.getKey().toString()); statement.setString(2, advancementType); - statement.setInt(3, advancements.get(player)); - statement.setInt(4, advancements.get(player)); - statement.executeUpdate(); - } catch (Exception e) { - e.printStackTrace(); - AywenCraftPlugin.getInstance().getLogger().severe("Unable to save " + advancementType + " advancements"); + statement.setInt(3, entry.getValue()); + statement.setInt(4, entry.getValue()); + statement.addBatch(); + } + + // Execute batch and commit + statement.executeBatch(); + connection.commit(); + + // Reset auto-commit to true + connection.setAutoCommit(true); + + } catch (SQLException e) { + try { + // Rollback in case of error + connection.rollback(); + connection.setAutoCommit(true); + } catch (SQLException rollbackEx) { + rollbackEx.printStackTrace(); + AywenCraftPlugin.getInstance().getLogger().severe("Failed to rollback transaction for " + advancementType + " advancements"); } + e.printStackTrace(); + AywenCraftPlugin.getInstance().getLogger().severe("Unable to save " + advancementType + " advancements"); } } From 2253c78105b154ba09d9277a61fbcad31a97db2e Mon Sep 17 00:00:00 2001 From: iambibi Date: Wed, 23 Oct 2024 22:41:17 +0200 Subject: [PATCH 17/18] Fix ParticleContest --- .../java/fr/communaywen/core/listeners/ParticleListener.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/fr/communaywen/core/listeners/ParticleListener.java b/src/main/java/fr/communaywen/core/listeners/ParticleListener.java index c681ecec..38fd9a30 100644 --- a/src/main/java/fr/communaywen/core/listeners/ParticleListener.java +++ b/src/main/java/fr/communaywen/core/listeners/ParticleListener.java @@ -59,7 +59,7 @@ public void run() { for (int i = 0; i < 100; i++) { // COULEUR CAMP 1 double x = minLocation.getX() + random.nextDouble() * (maxLocation.getX() - minLocation.getX()); - double y = minLocation.getY() + random.nextDouble() * (85 - 60); + double y = minLocation.getY() + random.nextDouble() * (85 - minLocation.getY()); double z = minLocation.getZ() + random.nextDouble() * (maxLocation.getZ() - minLocation.getZ()); Location particleLocation = new Location(world, x, y, z); @@ -68,7 +68,7 @@ public void run() { // COULEUR CAMP 2 double x2 = minLocation.getX() + random.nextDouble() * (maxLocation.getX() - minLocation.getX()); - double y2 = minLocation.getY() + random.nextDouble() * (85 - 60); + double y2 = minLocation.getY() + random.nextDouble() * (85 - minLocation.getY()); double z2 = minLocation.getZ() + random.nextDouble() * (maxLocation.getZ() - minLocation.getZ()); Location particleLocation2 = new Location(world, x2, y2, z2); From 4cc74c655e04516640de13d4443c53a71f506fd7 Mon Sep 17 00:00:00 2001 From: iambibi Date: Thu, 24 Oct 2024 13:55:10 +0200 Subject: [PATCH 18/18] Fix Bug EconomyManager null --- src/main/java/fr/communaywen/core/Managers.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/fr/communaywen/core/Managers.java b/src/main/java/fr/communaywen/core/Managers.java index d126b36e..7ef7a89f 100644 --- a/src/main/java/fr/communaywen/core/Managers.java +++ b/src/main/java/fr/communaywen/core/Managers.java @@ -124,7 +124,7 @@ public void init(AywenCraftPlugin plugin) { } // Database - // leaderboardManager = new LeaderboardManager(plugin); // desactivé de base + economyManager = new EconomyManager(); jumpManager = new JumpManager(plugin); headManager = new HeadManager(plugin); leaderboardManager = new LeaderboardManager(plugin); @@ -138,7 +138,6 @@ public void init(AywenCraftPlugin plugin) { dreamdimManager = new DimensionManager(plugin); homeManager = new HomeManager(plugin); quizManager = new QuizManager(plugin, quizzesConfig, contestManager); - economyManager = new EconomyManager(); friendsManager = new FriendsManager(databaseManager, plugin); corpseManager = new CorpseManager(); fbeManager = new FallingBlocksExplosionManager();