Skip to content

Commit

Permalink
FIx de l'Update de ce Soir (#472)
Browse files Browse the repository at this point in the history
*Avez vous lu le [Code de
Conduite](https://github.com/Margouta/PluginOpenMC/blob/main/CODE_OF_CONDUCT.md)?*:
oui

*Votre code se compile t-il en local ?*: oui

*Avez-vous supprimez les imports inutilisés ?*: oui
## Decrivez vos changements
*Clairement et avec des screenshots si nécessaires*
Des fixes autour de l'update de ce soir
  • Loading branch information
AxenoDev authored Oct 23, 2024
2 parents e3c5a17 + 2978992 commit d6c6741
Show file tree
Hide file tree
Showing 15 changed files with 400 additions and 331 deletions.
1 change: 1 addition & 0 deletions src/main/java/fr/communaywen/core/AywenCraftPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) -> {

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/fr/communaywen/core/QuizManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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_")
Expand Down Expand Up @@ -95,11 +97,38 @@ 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<Map<?, ?>> trades = config.getMapList("contest.contestTrades");

boolean tradeFound = false;

for (Map<?, ?> tradeEntry : trades) {
if (tradeEntry.get("ress").equals(trade)) {
((Map<String, Object>) tradeEntry).put("amount", amount);
((Map<String, Object>) 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 <mat> <amount> <amount_shell>", Prefix.STAFF, MessageType.ERROR, true);
}
}

@Subcommand("addpoints")
@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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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, () -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -464,8 +464,7 @@ public void initPhase3(JavaPlugin plugin, FileConfiguration eventConfig) {
System.out.println("[CONTEST] Fermeture du Contest");
}

public static CompletableFuture<String> 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();
Expand All @@ -476,11 +475,9 @@ public static CompletableFuture<String> getString(String table, String column) {
throw new RuntimeException(e);
}
return null;
});
}

public static CompletableFuture<Integer> 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();
Expand All @@ -491,7 +488,6 @@ public static CompletableFuture<Integer> getInt(String table, String column) {
throw new RuntimeException(e);
}
return -1;
});
}

public static String getTimeUntilNextMonday() {
Expand All @@ -508,8 +504,7 @@ public static String getTimeUntilNextMonday() {
return String.format("%dd %dh %dm", days, hours, minutes);
}

public CompletableFuture<Integer> getPlayerPoints(Player player) {
return CompletableFuture.supplyAsync(() -> {
public Integer getPlayerPoints(Player player) {
UUID playerUUID = player.getUniqueId();

String sql = "SELECT * FROM camps WHERE minecraft_uuid = ?";
Expand All @@ -523,7 +518,6 @@ public CompletableFuture<Integer> getPlayerPoints(Player player) {
throw new RuntimeException(e);
}
return -1;
});
}


Expand Down Expand Up @@ -564,17 +558,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() {
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -907,6 +901,19 @@ public double getMultiLuckyFromRang(int rang) {

//END CONTEST METHODE

public List<String> getRessListFromConfig() {
FileConfiguration config = plugins.getConfig();
List<Map<?, ?>> trades = config.getMapList("contest.contestTrades");
List<String> 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<Map<?, ?>> contestList = config.getMapList("contest.contestList");
List<Map<String, Object>> updatedContestList = new ArrayList<>();
Expand Down
45 changes: 32 additions & 13 deletions src/main/java/fr/communaywen/core/contest/menu/ConfirmMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
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;
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;

Expand All @@ -25,12 +27,15 @@ public class ConfirmMenu extends Menu {
private final ContestManager contestManager;
private final AywenCraftPlugin plugin;

private Map<Integer, ItemStack> 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
Expand All @@ -46,20 +51,29 @@ public ConfirmMenu(Player owner, AywenCraftPlugin plugins, String camp, String c
@Override
public void onInventoryClick(InventoryClickEvent click) {}


@Override
public @NotNull Map<Integer, ItemStack> getContent() {
Map<Integer, ItemStack> inventory = new HashMap<>();

String campNameFinal = contestManager.getString("contest", getCampName).join();;
String campColor = contestManager.getString("contest", getColor).join();;
ChatColor colorFinal = ChatColor.valueOf(campColor);
if (isInventoryPrepared) {
return inventory;
}

inventory = new HashMap<>();
isInventoryPrepared = true;

List<String> lore1 = new ArrayList<String>();
lore1.add("§7Vous allez rejoindre " + colorFinal + "La Team " + campNameFinal);
lore1.add("§c§lATTENTION! Vous ne pourrez changer de choix !");
Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> {
String campName = ContestManager.getString("contest", getCampName);
String campColor = ContestManager.getString("contest", getColor);

List<String> lore0 = new ArrayList<String>();
lore0.add("§7Vous allez annuler votre choix : " + colorFinal + "La Team " + campNameFinal);
Bukkit.getScheduler().runTask(plugin, () -> {
ChatColor colorFinal = ChatColor.valueOf(campColor);
List<String> lore1 = new ArrayList<>();
lore1.add("§7Vous allez rejoindre " + colorFinal + "La Team " + campName);
lore1.add("§c§lATTENTION! Vous ne pourrez changer de choix !");

List<String> 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");
Expand All @@ -76,9 +90,14 @@ 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;

getOwner().openInventory(getInventory());
});
});

return inventory;
}
}
}
Loading

0 comments on commit d6c6741

Please sign in to comment.