From cf714ec7a97c5878de1335be24c70c74f184bf42 Mon Sep 17 00:00:00 2001 From: Bierque Jason Date: Mon, 15 Jan 2024 22:14:46 +0100 Subject: [PATCH] Plusieurs commandes : /is setwarp /is sethome Fix permissions quand on est owner, on a pas toutes les perms --- .../permissions/PermissionsCommandIsland.java | 6 +- .../subcommands/AccessSubCommand.java | 13 ++-- .../subcommands/DeleteSubCommand.java | 9 ++- .../subcommands/DemoteSubCommand.java | 15 ++-- .../commands/subcommands/HomeSubCommand.java | 5 ++ .../subcommands/InviteSubCommand.java | 17 ++++ .../commands/subcommands/KickSubCommand.java | 14 ++-- .../subcommands/PromoteSubCommand.java | 15 ++-- .../subcommands/SetBiomeSubCommand.java | 17 ++++ .../subcommands/SetHomeSubCommand.java | 57 ++++++++++++-- .../subcommands/SetWarpSubCommand.java | 78 +++++++++++++------ .../skyfolia/configuration/LanguageToml.java | 11 ++- 12 files changed, 197 insertions(+), 60 deletions(-) diff --git a/api/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/permissions/PermissionsCommandIsland.java b/api/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/permissions/PermissionsCommandIsland.java index 54156dd..49a5447 100644 --- a/api/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/permissions/PermissionsCommandIsland.java +++ b/api/src/main/java/fr/euphyllia/skyfolia/api/skyblock/model/permissions/PermissionsCommandIsland.java @@ -9,7 +9,11 @@ public enum PermissionsCommandIsland implements Permissions { DEMOTE(1), PROMOTE(2), KICK(4), - ACCESS(8); + ACCESS(8), + SET_HOME(16), + INVITE(32), + SET_BIOME(64), + SET_WARP(128); private final int permissionValue; diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/AccessSubCommand.java b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/AccessSubCommand.java index 7c998a9..cf99e7a 100644 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/AccessSubCommand.java +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/AccessSubCommand.java @@ -57,13 +57,14 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N } Players executorPlayer = island.getMember(player.getUniqueId()); + if (!executorPlayer.getRoleType().equals(RoleType.OWNER)) { + PermissionRoleIsland permissionRoleIsland = skyblockManager.getPermissionIsland(island.getId(), PermissionsType.COMMANDS, executorPlayer.getRoleType()).join(); - PermissionRoleIsland permissionRoleIsland = skyblockManager.getPermissionIsland(island.getId(), PermissionsType.COMMANDS, executorPlayer.getRoleType()).join(); - - PermissionManager permissionManager = new PermissionManager(permissionRoleIsland.permission()); - if (!executorPlayer.getRoleType().equals(RoleType.OWNER) && !permissionManager.hasPermission(PermissionsCommandIsland.ACCESS)) { - LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied); - return; + PermissionManager permissionManager = new PermissionManager(permissionRoleIsland.permission()); + if (!permissionManager.hasPermission(PermissionsCommandIsland.ACCESS)) { + LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied); + return; + } } boolean statusAccessUpdate = !island.isPrivateIsland(); diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/DeleteSubCommand.java b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/DeleteSubCommand.java index bdc8e49..cff0120 100644 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/DeleteSubCommand.java +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/DeleteSubCommand.java @@ -4,11 +4,15 @@ import fr.euphyllia.skyfolia.api.event.SkyblockRemoveEvent; import fr.euphyllia.skyfolia.api.skyblock.Island; import fr.euphyllia.skyfolia.api.skyblock.Players; +import fr.euphyllia.skyfolia.api.skyblock.model.PermissionRoleIsland; import fr.euphyllia.skyfolia.api.skyblock.model.RoleType; +import fr.euphyllia.skyfolia.api.skyblock.model.permissions.PermissionsCommandIsland; +import fr.euphyllia.skyfolia.api.skyblock.model.permissions.PermissionsType; import fr.euphyllia.skyfolia.commands.SubCommandInterface; import fr.euphyllia.skyfolia.configuration.ConfigToml; import fr.euphyllia.skyfolia.configuration.LanguageToml; import fr.euphyllia.skyfolia.configuration.section.WorldConfig; +import fr.euphyllia.skyfolia.managers.skyblock.PermissionManager; import fr.euphyllia.skyfolia.managers.skyblock.SkyblockManager; import fr.euphyllia.skyfolia.utils.PlayerUtils; import fr.euphyllia.skyfolia.utils.WorldEditUtils; @@ -72,7 +76,10 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerHasNotIsland); return; } - if (!island.getOwnerId().equals(player.getUniqueId())) { + + Players executorPlayer = island.getMember(player.getUniqueId()); + + if (!executorPlayer.getRoleType().equals(RoleType.OWNER)) { LanguageToml.sendMessage(plugin, player, LanguageToml.messageOnlyOwnerCanDeleteIsland); return; } diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/DemoteSubCommand.java b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/DemoteSubCommand.java index 07ea6d6..f3c659f 100644 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/DemoteSubCommand.java +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/DemoteSubCommand.java @@ -56,13 +56,14 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N Players executorPlayer = island.getMember(player.getUniqueId()); - PermissionRoleIsland permissionRoleIsland = skyblockManager.getPermissionIsland(island.getId(), PermissionsType.COMMANDS, executorPlayer.getRoleType()).join(); - - PermissionManager permissionManager = new PermissionManager(permissionRoleIsland.permission()); - - if (!permissionManager.hasPermission(PermissionsCommandIsland.DEMOTE)) { - LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied); - return; + if (!executorPlayer.getRoleType().equals(RoleType.OWNER)) { + PermissionRoleIsland permissionRoleIsland = skyblockManager.getPermissionIsland(island.getId(), PermissionsType.COMMANDS, executorPlayer.getRoleType()).join(); + + PermissionManager permissionManager = new PermissionManager(permissionRoleIsland.permission()); + if (!permissionManager.hasPermission(PermissionsCommandIsland.DEMOTE)) { + LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied); + return; + } } Players players = island.getMember(playerName); diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/HomeSubCommand.java b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/HomeSubCommand.java index 79f51e8..970d4ee 100644 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/HomeSubCommand.java +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/HomeSubCommand.java @@ -37,6 +37,11 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N if (!(sender instanceof Player player)) { return true; } + if (!player.hasPermission("skyfolia.island.command.home")) { + LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied); + return true; + } + player.setGameMode(GameMode.SPECTATOR); ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); try { diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/InviteSubCommand.java b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/InviteSubCommand.java index 8c03681..bfb0c35 100644 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/InviteSubCommand.java +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/InviteSubCommand.java @@ -3,10 +3,14 @@ import fr.euphyllia.skyfolia.Main; import fr.euphyllia.skyfolia.api.skyblock.Island; import fr.euphyllia.skyfolia.api.skyblock.Players; +import fr.euphyllia.skyfolia.api.skyblock.model.PermissionRoleIsland; import fr.euphyllia.skyfolia.api.skyblock.model.RoleType; +import fr.euphyllia.skyfolia.api.skyblock.model.permissions.PermissionsCommandIsland; +import fr.euphyllia.skyfolia.api.skyblock.model.permissions.PermissionsType; import fr.euphyllia.skyfolia.cache.InviteCacheExecution; import fr.euphyllia.skyfolia.commands.SubCommandInterface; import fr.euphyllia.skyfolia.configuration.LanguageToml; +import fr.euphyllia.skyfolia.managers.skyblock.PermissionManager; import fr.euphyllia.skyfolia.managers.skyblock.SkyblockManager; import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; @@ -90,11 +94,24 @@ private void invitePlayer(Main plugin, Player ownerIsland, String playerInvited) return; } + Players executorPlayer = island.getMember(ownerIsland.getUniqueId()); + + if (!executorPlayer.getRoleType().equals(RoleType.OWNER)) { + PermissionRoleIsland permissionRoleIsland = skyblockManager.getPermissionIsland(island.getId(), PermissionsType.COMMANDS, executorPlayer.getRoleType()).join(); + + PermissionManager permissionManager = new PermissionManager(permissionRoleIsland.permission()); + if (!permissionManager.hasPermission(PermissionsCommandIsland.INVITE)) { + LanguageToml.sendMessage(plugin, ownerIsland, LanguageToml.messagePlayerPermissionDenied); + return; + } + } + UUID playerInvitedId = Bukkit.getPlayerUniqueId(playerInvited); if (playerInvitedId == null) { LanguageToml.sendMessage(plugin, ownerIsland, LanguageToml.messagePlayerNotFound); return; } + InviteCacheExecution.addInviteCache(island.getId(), playerInvitedId); LanguageToml.sendMessage(plugin, ownerIsland, LanguageToml.messageInvitePlayerInvited.formatted(playerInvited)); Player bPlayerInvited = Bukkit.getPlayer(playerInvitedId); diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/KickSubCommand.java b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/KickSubCommand.java index 68f4f01..971fe40 100644 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/KickSubCommand.java +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/KickSubCommand.java @@ -52,14 +52,16 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N Players executorPlayer = island.getMember(player.getUniqueId()); - PermissionRoleIsland permissionRoleIsland = skyblockManager.getPermissionIsland(island.getId(), PermissionsType.COMMANDS, executorPlayer.getRoleType()).join(); + if (!executorPlayer.getRoleType().equals(RoleType.OWNER)) { + PermissionRoleIsland permissionRoleIsland = skyblockManager.getPermissionIsland(island.getId(), PermissionsType.COMMANDS, executorPlayer.getRoleType()).join(); - PermissionManager permissionManager = new PermissionManager(permissionRoleIsland.permission()); - - if (!permissionManager.hasPermission(PermissionsCommandIsland.KICK)) { - LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied); - return; + PermissionManager permissionManager = new PermissionManager(permissionRoleIsland.permission()); + if (!permissionManager.hasPermission(PermissionsCommandIsland.KICK)) { + LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied); + return; + } } + String playerKick = args[0]; Players players = island.getMember(playerKick); diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/PromoteSubCommand.java b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/PromoteSubCommand.java index ff37c4e..b9f2917 100644 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/PromoteSubCommand.java +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/PromoteSubCommand.java @@ -56,13 +56,14 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N Players executorPlayer = island.getMember(player.getUniqueId()); - PermissionRoleIsland permissionRoleIsland = skyblockManager.getPermissionIsland(island.getId(), PermissionsType.COMMANDS, executorPlayer.getRoleType()).join(); - - PermissionManager permissionManager = new PermissionManager(permissionRoleIsland.permission()); - - if (!permissionManager.hasPermission(PermissionsCommandIsland.PROMOTE)) { - LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied); - return; + if (!executorPlayer.getRoleType().equals(RoleType.OWNER)) { + PermissionRoleIsland permissionRoleIsland = skyblockManager.getPermissionIsland(island.getId(), PermissionsType.COMMANDS, executorPlayer.getRoleType()).join(); + + PermissionManager permissionManager = new PermissionManager(permissionRoleIsland.permission()); + if (!permissionManager.hasPermission(PermissionsCommandIsland.PROMOTE)) { + LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied); + return; + } } Players players = island.getMember(playerName); diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/SetBiomeSubCommand.java b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/SetBiomeSubCommand.java index 9f2f5aa..3fb7a54 100644 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/SetBiomeSubCommand.java +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/SetBiomeSubCommand.java @@ -3,10 +3,15 @@ import fr.euphyllia.skyfolia.Main; import fr.euphyllia.skyfolia.api.skyblock.Island; import fr.euphyllia.skyfolia.api.skyblock.Players; +import fr.euphyllia.skyfolia.api.skyblock.model.PermissionRoleIsland; import fr.euphyllia.skyfolia.api.skyblock.model.Position; +import fr.euphyllia.skyfolia.api.skyblock.model.RoleType; +import fr.euphyllia.skyfolia.api.skyblock.model.permissions.PermissionsCommandIsland; +import fr.euphyllia.skyfolia.api.skyblock.model.permissions.PermissionsType; import fr.euphyllia.skyfolia.cache.CommandCacheExecution; import fr.euphyllia.skyfolia.commands.SubCommandInterface; import fr.euphyllia.skyfolia.configuration.LanguageToml; +import fr.euphyllia.skyfolia.managers.skyblock.PermissionManager; import fr.euphyllia.skyfolia.managers.skyblock.SkyblockManager; import fr.euphyllia.skyfolia.utils.PlayerUtils; import fr.euphyllia.skyfolia.utils.RegionUtils; @@ -84,6 +89,18 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N return; } + Players executorPlayer = island.getMember(player.getUniqueId()); + + if (!executorPlayer.getRoleType().equals(RoleType.OWNER)) { + PermissionRoleIsland permissionRoleIsland = skyblockManager.getPermissionIsland(island.getId(), PermissionsType.COMMANDS, executorPlayer.getRoleType()).join(); + + PermissionManager permissionManager = new PermissionManager(permissionRoleIsland.permission()); + if (!permissionManager.hasPermission(PermissionsCommandIsland.SET_BIOME)) { + LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied); + return; + } + } + Position islandPosition = island.getPosition(); Position playerRegionPosition = RegionUtils.getRegionInChunk(chunkLocX, chunkLocZ); diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/SetHomeSubCommand.java b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/SetHomeSubCommand.java index 8b0af90..8f6b312 100644 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/SetHomeSubCommand.java +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/SetHomeSubCommand.java @@ -1,9 +1,20 @@ package fr.euphyllia.skyfolia.commands.subcommands; import fr.euphyllia.skyfolia.Main; +import fr.euphyllia.skyfolia.api.skyblock.Island; +import fr.euphyllia.skyfolia.api.skyblock.Players; +import fr.euphyllia.skyfolia.api.skyblock.model.PermissionRoleIsland; +import fr.euphyllia.skyfolia.api.skyblock.model.Position; +import fr.euphyllia.skyfolia.api.skyblock.model.RoleType; +import fr.euphyllia.skyfolia.api.skyblock.model.permissions.PermissionsCommandIsland; +import fr.euphyllia.skyfolia.api.skyblock.model.permissions.PermissionsType; import fr.euphyllia.skyfolia.commands.SubCommandInterface; import fr.euphyllia.skyfolia.configuration.LanguageToml; +import fr.euphyllia.skyfolia.managers.skyblock.PermissionManager; +import fr.euphyllia.skyfolia.managers.skyblock.SkyblockManager; import fr.euphyllia.skyfolia.utils.IslandUtils; +import fr.euphyllia.skyfolia.utils.RegionUtils; +import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.bukkit.Location; @@ -26,18 +37,54 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N if (!(sender instanceof Player player)) { return true; } - Location playerLocation = player.getLocation(); - if (!IslandUtils.isWorldIsland(playerLocation.getWorld().getName())) { - player.sendMessage(plugin.getInterneAPI().getMiniMessage().deserialize(LanguageToml.messagePlayerNotInIsland)); + if (!player.hasPermission("skyfolia.island.command.sethome")) { + LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied); return true; } - + Location playerLocation = player.getLocation(); int regionLocX = playerLocation.getChunk().getX(); int regionLocZ = playerLocation.getChunk().getZ(); ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); try { - executor.execute(() -> SetWarpSubCommand.setWarpRun(plugin, player, regionLocX, regionLocZ, playerLocation, logger, "home")); + executor.execute(() -> { + try { + SkyblockManager skyblockManager = plugin.getInterneAPI().getSkyblockManager(); + Island island = skyblockManager.getIslandByOwner(player.getUniqueId()).join(); + if (island == null) { + LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerHasNotIsland); + return; + } + Position islandPosition = island.getPosition(); + Position playerRegionPosition = RegionUtils.getRegionInChunk(regionLocX, regionLocZ); + + if (islandPosition.regionX() != playerRegionPosition.regionX() || islandPosition.regionZ() != playerRegionPosition.regionZ()) { + LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerNotInIsland); + return; + } + + Players executorPlayer = island.getMember(player.getUniqueId()); + + if (!executorPlayer.getRoleType().equals(RoleType.OWNER)) { + PermissionRoleIsland permissionRoleIsland = skyblockManager.getPermissionIsland(island.getId(), PermissionsType.COMMANDS, executorPlayer.getRoleType()).join(); + PermissionManager permissionManager = new PermissionManager(permissionRoleIsland.permission()); + if (!permissionManager.hasPermission(PermissionsCommandIsland.SET_HOME)) { + LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied); + return; + } + } + + boolean updateOrCreateHome = island.addWarps("home", playerLocation); + if (updateOrCreateHome) { + LanguageToml.sendMessage(plugin, player, LanguageToml.messageHomeCreateSuccess); + } else { + LanguageToml.sendMessage(plugin, player, LanguageToml.messageError); + } + } catch (Exception e) { + logger.log(Level.FATAL, e.getMessage(), e); + LanguageToml.sendMessage(plugin, player, LanguageToml.messageError); + } + }); } finally { executor.shutdown(); } diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/SetWarpSubCommand.java b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/SetWarpSubCommand.java index cfc3f63..45e194b 100644 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/SetWarpSubCommand.java +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/SetWarpSubCommand.java @@ -2,10 +2,16 @@ import fr.euphyllia.skyfolia.Main; import fr.euphyllia.skyfolia.api.skyblock.Island; +import fr.euphyllia.skyfolia.api.skyblock.Players; +import fr.euphyllia.skyfolia.api.skyblock.model.PermissionRoleIsland; import fr.euphyllia.skyfolia.api.skyblock.model.Position; +import fr.euphyllia.skyfolia.api.skyblock.model.RoleType; +import fr.euphyllia.skyfolia.api.skyblock.model.permissions.PermissionsCommandIsland; +import fr.euphyllia.skyfolia.api.skyblock.model.permissions.PermissionsType; import fr.euphyllia.skyfolia.commands.SubCommandInterface; import fr.euphyllia.skyfolia.configuration.ConfigToml; import fr.euphyllia.skyfolia.configuration.LanguageToml; +import fr.euphyllia.skyfolia.managers.skyblock.PermissionManager; import fr.euphyllia.skyfolia.managers.skyblock.SkyblockManager; import fr.euphyllia.skyfolia.utils.RegionUtils; import org.apache.logging.log4j.Level; @@ -26,50 +32,72 @@ public class SetWarpSubCommand implements SubCommandInterface { private final Logger logger = LogManager.getLogger(SetWarpSubCommand.class); - public static void setWarpRun(Main plugin, Player player, int regionLocX, int regionLocZ, Location playerLocation, Logger logger, String warpName) { - SkyblockManager skyblockManager = plugin.getInterneAPI().getSkyblockManager(); - Island island = skyblockManager.getIslandByOwner(player.getUniqueId()).join(); - if (island == null) { - player.sendMessage(plugin.getInterneAPI().getMiniMessage().deserialize(LanguageToml.messagePlayerHasNotIsland)); - return; - } - Position islandPosition = island.getPosition(); - Position playerRegionPosition = RegionUtils.getRegionInChunk(regionLocX, regionLocZ); - - if (islandPosition.regionX() != playerRegionPosition.regionX() || islandPosition.regionZ() != playerRegionPosition.regionZ()) { - player.sendMessage(plugin.getInterneAPI().getMiniMessage().deserialize(LanguageToml.messagePlayerNotInIsland)); - return; - } - - boolean updateOrCreateWarps = island.addWarps(warpName, playerLocation); - if (updateOrCreateWarps) { - player.sendMessage(plugin.getInterneAPI().getMiniMessage().deserialize(LanguageToml.messageWarpCreate)); - } else { - player.sendMessage(plugin.getInterneAPI().getMiniMessage().deserialize(LanguageToml.messageError)); - } - } - @Override public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) { if (!(sender instanceof Player player)) { return true; } if (args.length <= 1) { - logger.log(Level.FATAL, "manque arguments"); + LanguageToml.sendMessage(plugin, player, LanguageToml.messageWarpCommandNotEnoughArgs); + return true; + } + if (!player.hasPermission("skyfolia.island.command.setwarp")) { + LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied); return true; } + Location playerLocation = player.getLocation(); if (!isWorldIsland(playerLocation.getWorld().getName())) { sender.sendMessage("Vous n'êtes pas sur votre ile"); return true; } + String warpName = args[0]; + int regionLocX = playerLocation.getChunk().getX(); int regionLocZ = playerLocation.getChunk().getZ(); ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor(); try { - executor.execute(() -> SetWarpSubCommand.setWarpRun(plugin, player, regionLocX, regionLocZ, playerLocation, logger, args[0])); + executor.execute(() -> { + try { + SkyblockManager skyblockManager = plugin.getInterneAPI().getSkyblockManager(); + Island island = skyblockManager.getIslandByOwner(player.getUniqueId()).join(); + if (island == null) { + LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerHasNotIsland); + return; + } + + Players executorPlayer = island.getMember(player.getUniqueId()); + + if (!executorPlayer.getRoleType().equals(RoleType.OWNER)) { + PermissionRoleIsland permissionRoleIsland = skyblockManager.getPermissionIsland(island.getId(), PermissionsType.COMMANDS, executorPlayer.getRoleType()).join(); + PermissionManager permissionManager = new PermissionManager(permissionRoleIsland.permission()); + if (!permissionManager.hasPermission(PermissionsCommandIsland.SET_WARP)) { + LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied); + return; + } + } + + Position islandPosition = island.getPosition(); + Position playerRegionPosition = RegionUtils.getRegionInChunk(regionLocX, regionLocZ); + + if (islandPosition.regionX() != playerRegionPosition.regionX() || islandPosition.regionZ() != playerRegionPosition.regionZ()) { + LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerNotInIsland); + return; + } + + boolean updateOrCreateWarps = island.addWarps(warpName, playerLocation); + if (updateOrCreateWarps) { + LanguageToml.sendMessage(plugin, player, LanguageToml.messageWarpCreateSuccess); + } else { + LanguageToml.sendMessage(plugin, player, LanguageToml.messageError); + } + } catch (Exception e) { + logger.log(Level.FATAL, e.getMessage(), e); + LanguageToml.sendMessage(plugin, player, LanguageToml.messageError); + } + }); } finally { executor.shutdown(); } diff --git a/plugin/src/main/java/fr/euphyllia/skyfolia/configuration/LanguageToml.java b/plugin/src/main/java/fr/euphyllia/skyfolia/configuration/LanguageToml.java index da487f6..6015b7a 100644 --- a/plugin/src/main/java/fr/euphyllia/skyfolia/configuration/LanguageToml.java +++ b/plugin/src/main/java/fr/euphyllia/skyfolia/configuration/LanguageToml.java @@ -26,7 +26,7 @@ public class LanguageToml { public static String messageIslandAlreadyExist = "Vous avez déjà une île."; public static String messagePlayerNotFound = "Le joueur est introuvable."; public static String messagePlayerNotInIsland = "Vous devez être sur votre île."; - public static String messageWarpCreate = "Votre warp : %s a été crée."; + public static String messageWarpCreateSuccess = "Votre warp : %s a été crée."; public static String messageError = "Une erreur s'est produite. Merci de contacter un administrateur."; public static String messageTransfertSuccess = "Le nouveau propriétaire de l'ile est : %new_owner%"; public static String messageOnlyOwner = "Seul le propriétaire de l'île peut faire ça."; @@ -177,8 +177,10 @@ private static void deleteIslandLanguage() { } public static String messageHomeIslandSuccess = "Vous avez été téléporté sur votre île."; + public static String messageHomeCreateSuccess = "Vous avez modifier votre home !"; private static void homeIslandLanguage() { messageHomeIslandSuccess = getString("island.home.success", messageHomeIslandSuccess); + messageHomeCreateSuccess= getString("island.home.set.success", messageHomeCreateSuccess); } private static void islandGenericLanguage() { @@ -186,7 +188,6 @@ private static void islandGenericLanguage() { messageIslandAlreadyExist = getString("island.generic.player.already-exist", messageIslandAlreadyExist); messagePlayerNotFound = getString("island.generic.player.not-found", messagePlayerNotFound); messagePlayerNotInIsland = getString("island.generic.player.not-in-island", messagePlayerNotInIsland); - messageWarpCreate = getString("island.generic.player.warp-create", messageWarpCreate); messageError = getString("island.generic.error", messageError); messageOnlyOwner = getString("island.generic.only-owner", messageOnlyOwner); messageNotMember = getString("island.generic.not-member", messageNotMember); @@ -220,6 +221,12 @@ private static void islandLeaveLanguage() { messageLeaveFailedIsOwnerIsland = getString("island.leave.he-is-owner", messageLeaveFailedIsOwnerIsland); } + public static String messageWarpCommandNotEnoughArgs = "Vous devez préciser le nom du warp à enregistrer : /skyfolia setwarp "; + private static void islandWarpLanguage() { + messageWarpCommandNotEnoughArgs = getString("island.warp.not-enough-args", messageWarpCommandNotEnoughArgs); + messageWarpCreateSuccess = getString("island.warp.success", messageWarpCreateSuccess); + } + public static void sendMessage(Main plugin, Entity entity, String msg) { if (msg.isEmpty()) return;