From 5468697e19f5e371ead6dd7f287e0c46319ce4b4 Mon Sep 17 00:00:00 2001 From: iambibi Date: Tue, 22 Oct 2024 19:27:17 +0200 Subject: [PATCH 1/9] 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 2/9] 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 3/9] 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 4/9] 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 5/9] 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 f693f374d19e53f12f226d363164da1430c430f6 Mon Sep 17 00:00:00 2001 From: iambibi Date: Wed, 23 Oct 2024 11:45:54 +0200 Subject: [PATCH 6/9] 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 7/9] 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 8/9] 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 2978992c40f7a38cfc085b7c1b14f3ad114a4355 Mon Sep 17 00:00:00 2001 From: iambibi Date: Wed, 23 Oct 2024 17:32:45 +0200 Subject: [PATCH 9/9] 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"