Skip to content

Commit

Permalink
Plusieurs commandes :
Browse files Browse the repository at this point in the history
/is setwarp
/is sethome

Fix permissions quand on est owner, on a pas toutes les perms
  • Loading branch information
Euphillya committed Jan 15, 2024
1 parent c66a7ab commit cf714ec
Show file tree
Hide file tree
Showing 12 changed files with 197 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
}
Expand Down
Loading

0 comments on commit cf714ec

Please sign in to comment.