Skip to content

Commit

Permalink
Fix SetBiome commande
Browse files Browse the repository at this point in the history
Ne plus vérifier le joueur mais l'ile si elle est en execution
Permettre de réutiliser la commande une fois le changement modifié
  • Loading branch information
Euphillya committed Mar 1, 2024
1 parent b30fddf commit 52308e8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,25 @@ public class CommandCacheExecution {

private static final ConcurrentHashMap<UUID, List<String>> commandAlreadyExecution = new ConcurrentHashMap<>();

public static boolean isAlreadyExecute(UUID playerId, String command) {
List<String> listCmd = commandAlreadyExecution.getOrDefault(playerId, null);
public static boolean isAlreadyExecute(UUID uuid, String command) {
List<String> listCmd = commandAlreadyExecution.getOrDefault(uuid, null);
if (listCmd == null) return false;
return listCmd.contains(command);
}

public static void addCommandExecute(UUID playerId, String command) {
List<String> listCmd = commandAlreadyExecution.getOrDefault(playerId, null);
public static void addCommandExecute(UUID uuid, String command) {
List<String> listCmd = commandAlreadyExecution.getOrDefault(uuid, null);
if (listCmd == null) {
listCmd = new ArrayList<>();
}
listCmd.add(command);
commandAlreadyExecution.put(playerId, listCmd);
commandAlreadyExecution.put(uuid, listCmd);
}

public static void removeCommandExec(UUID playerId, String command) {
List<String> listCmd = commandAlreadyExecution.getOrDefault(playerId, null);
public static void removeCommandExec(UUID uuid, String command) {
List<String> listCmd = commandAlreadyExecution.getOrDefault(uuid, null);
if (listCmd == null) return;
listCmd.remove(command);
commandAlreadyExecution.put(playerId, listCmd);
commandAlreadyExecution.put(uuid, listCmd);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;

public class SetBiomeSubCommand implements SubCommandInterface {

Expand All @@ -52,17 +53,12 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N
LanguageToml.sendMessage(plugin, player, LanguageToml.messageBiomeCommandNotEnoughArgs);
return true;
}
if (CommandCacheExecution.isAlreadyExecute(player.getUniqueId(), "biome")) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageCommandAlreadyExecution);
return true;
}

Location playerLocation = player.getLocation();
int chunkLocX = playerLocation.getChunk().getX();
int chunkLocZ = playerLocation.getChunk().getZ();
String selectBiome = args[0];

CommandCacheExecution.addCommandExecute(player.getUniqueId(), "biome");
try {
Biome biome;
try {
Expand All @@ -84,6 +80,12 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerHasNotIsland);
return true;
}
final UUID islandId = island.getId();
if (CommandCacheExecution.isAlreadyExecute(islandId, "biome")) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageCommandAlreadyExecution);
return true;
}
CommandCacheExecution.addCommandExecute(islandId, "biome");

Players executorPlayer = island.getMember(player.getUniqueId());

Expand Down Expand Up @@ -120,6 +122,7 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N
});
}
}
CommandCacheExecution.removeCommandExec(islandId, "biome");
}
} catch (Exception e) {
logger.log(Level.FATAL, e.getMessage(), e);
Expand Down

0 comments on commit 52308e8

Please sign in to comment.