Skip to content

Commit

Permalink
Mettre des personnes en membre temporaire/confirnace
Browse files Browse the repository at this point in the history
  • Loading branch information
Euphillya committed Jan 29, 2024
1 parent bb23cef commit d787752
Show file tree
Hide file tree
Showing 12 changed files with 261 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .idea/sonarlint/issuestore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion .idea/sonarlint/securityhotspotstore/index.pb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public enum PermissionsCommandIsland implements Permissions {
MANAGE_PERMISSION(2_048),
BAN(4_096),
UNBAN(8_192),
TRUST(16_384),
;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ public enum PermissionsIsland implements Permissions {
INTERACT_ENTITIES(2_048),
KILL_UNKNOWN_ENTITY(4_096),
KILL_NPC(8_192),
INTERACT(16_384)
;
INTERACT(16_384);

private final long permissionValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class PlayersInIslandCache {
private static final Logger logger = LogManager.getLogger(PlayersInIslandCache.class);
private static final ConcurrentHashMap<UUID, CopyOnWriteArrayList<Players>> listPlayersInIsland = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<UUID, UUID> islandIdByPlayerId = new ConcurrentHashMap<>();
private static final ConcurrentHashMap<UUID, CopyOnWriteArrayList<UUID>> listTrustedPlayerByIslandId = new ConcurrentHashMap<>();

public static Players getPlayers(UUID islandId, UUID playerId) {
List<Players> playersInIsland = listPlayersInIsland.getOrDefault(islandId, new CopyOnWriteArrayList<>());
Expand All @@ -41,4 +42,30 @@ public static void delete(UUID islandId) {
public static void add(UUID islandId, CopyOnWriteArrayList<Players> members) {
listPlayersInIsland.put(islandId, members);
}

public static CopyOnWriteArrayList<UUID> getPlayersListTrusted(UUID islandId) {
return listTrustedPlayerByIslandId.getOrDefault(islandId, new CopyOnWriteArrayList<>());
}

public static void addPlayerTrustedInIsland(UUID islandId, UUID playerId) {
CopyOnWriteArrayList<UUID> listPlayer = getPlayersListTrusted(islandId);
listPlayer.add(playerId);
listTrustedPlayerByIslandId.put(islandId, listPlayer);
}

public static boolean removePlayerTrustedInIsland(UUID islandId, UUID playerId) {
CopyOnWriteArrayList<UUID> listPlayer = getPlayersListTrusted(islandId);
boolean isRemoved = listPlayer.remove(playerId);
if (isRemoved) {
listTrustedPlayerByIslandId.put(islandId, listPlayer);
return true;
} else {
return false;
}
}

public static boolean playerIsTrustedInIsland(UUID islandId, UUID playerId) {
CopyOnWriteArrayList<UUID> listPlayer = getPlayersListTrusted(islandId);
return listPlayer.contains(playerId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@ public enum SubCommands {
PERMISSION(new PermissionSubCommand()),
PROMOTE(new PromoteSubCommand()),
TRANSFER(new TransferSubCommand()),
TRUST(new TrustSubCommand()),
SETHOME(new SetHomeSubCommand()),
SETWARP(new SetWarpSubCommand()),
UNBAN(new UnbanSubCommand()),
UNTRUST(new UntrustSubCommand()),
VISIT(new VisitSubCommand()),
WARP(new WarpSubCommand());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
package fr.euphyllia.skyllia.commands.common.subcommands;

import fr.euphyllia.skyllia.Main;
import fr.euphyllia.skyllia.api.skyblock.Island;
import fr.euphyllia.skyllia.api.skyblock.Players;
import fr.euphyllia.skyllia.api.skyblock.model.PermissionRoleIsland;
import fr.euphyllia.skyllia.api.skyblock.model.RoleType;
import fr.euphyllia.skyllia.api.skyblock.model.permissions.PermissionsCommandIsland;
import fr.euphyllia.skyllia.api.skyblock.model.permissions.PermissionsType;
import fr.euphyllia.skyllia.cache.PlayersInIslandCache;
import fr.euphyllia.skyllia.commands.SubCommandInterface;
import fr.euphyllia.skyllia.configuration.LanguageToml;
import fr.euphyllia.skyllia.managers.skyblock.PermissionManager;
import fr.euphyllia.skyllia.managers.skyblock.SkyblockManager;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

public class TrustSubCommand implements SubCommandInterface {

private final Logger logger = LogManager.getLogger(TrustSubCommand.class);

@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 (!player.hasPermission("skyllia.island.command.access")) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied);
return true;
}
if (args.length < 1) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageTrustCommandNotEnoughArgs);
return true;
}
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
try {
executor.execute(() -> {
try {
UUID playerTrustedId = Bukkit.getPlayerUniqueId(args[0]);
if (playerTrustedId == null) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerNotFound);
return;
}

SkyblockManager skyblockManager = plugin.getInterneAPI().getSkyblockManager();
Island island = skyblockManager.getIslandByPlayerId(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.TRUST)) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied);
return;
}
}

PlayersInIslandCache.addPlayerTrustedInIsland(island.getId(), playerTrustedId);
LanguageToml.sendMessage(plugin, player, LanguageToml.messageTrustSuccess);
} catch (Exception e) {
logger.log(Level.FATAL, e.getMessage(), e);
LanguageToml.sendMessage(plugin, player, LanguageToml.messageError);
}
});
} finally {
executor.shutdown();
}
return true;
}

@Override
public @Nullable List<String> onTabComplete(@NotNull Main plugin, @NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
return new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package fr.euphyllia.skyllia.commands.common.subcommands;

import fr.euphyllia.skyllia.Main;
import fr.euphyllia.skyllia.api.skyblock.Island;
import fr.euphyllia.skyllia.api.skyblock.Players;
import fr.euphyllia.skyllia.api.skyblock.model.PermissionRoleIsland;
import fr.euphyllia.skyllia.api.skyblock.model.RoleType;
import fr.euphyllia.skyllia.api.skyblock.model.permissions.PermissionsCommandIsland;
import fr.euphyllia.skyllia.api.skyblock.model.permissions.PermissionsType;
import fr.euphyllia.skyllia.cache.PlayersInIslandCache;
import fr.euphyllia.skyllia.commands.SubCommandInterface;
import fr.euphyllia.skyllia.configuration.LanguageToml;
import fr.euphyllia.skyllia.managers.skyblock.PermissionManager;
import fr.euphyllia.skyllia.managers.skyblock.SkyblockManager;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

public class UntrustSubCommand implements SubCommandInterface {

private final Logger logger = LogManager.getLogger(UntrustSubCommand.class);

@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 (!player.hasPermission("skyllia.island.command.access")) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied);
return true;
}
if (args.length < 1) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageUntrustCommandNotEnoughArgs);
return true;
}
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
try {
executor.execute(() -> {
try {
UUID playerTrustedId = Bukkit.getPlayerUniqueId(args[0]);
if (playerTrustedId == null) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerNotFound);
return;
}

SkyblockManager skyblockManager = plugin.getInterneAPI().getSkyblockManager();
Island island = skyblockManager.getIslandByPlayerId(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.TRUST)) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied);
return;
}
}

boolean isRemove = PlayersInIslandCache.removePlayerTrustedInIsland(island.getId(), playerTrustedId);
if (isRemove) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageUntrustSuccess);
} else {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageUntrustFailed);
}
} catch (Exception e) {
logger.log(Level.FATAL, e.getMessage(), e);
LanguageToml.sendMessage(plugin, player, LanguageToml.messageError);
}
});
} finally {
executor.shutdown();
}
return true;
}

@Override
public @Nullable List<String> onTabComplete(@NotNull Main plugin, @NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
return new ArrayList<>();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ public class LanguageToml {
public static String messageASetSizeNAN = "Vous n'avez pas choisi un nombre entier.";
public static String messageASetSizeFailed = "Le changement n'a pas pu s'effectuer.";
public static String messageASetSizeSuccess = "Le nombre de personne sur l'ile a bien été changé.";
public static String messageTrustSuccess = "Le joueur a été ajouté dans votre liste de confiance jusqu'au prochain redémarrage ou que vous l'enlevier directement. Sachez qu'une personne trust a autant de permission qu'un membre de votre île.";
public static String messageTrustCommandNotEnoughArgs = "La commande est incomplète : /skyllia trust <player>";
public static String messageUntrustFailed = "Une erreur s'est produite lors de la suppression de la personne dans votre liste de confiance. Etait-il bien en confiance sur votre île ?";
public static String messageUntrustSuccess = "Le membre ne fait dorénavant plus partie de vos confiances";
public static String messageUntrustCommandNotEnoughArgs = "La commande est incomplète : /skyllia untrust <player>";
private static boolean verbose;

public static void init(File configFile) {
Expand Down Expand Up @@ -298,13 +303,24 @@ private static void islandPermissionLanguage() {
messagePermissionPlayerFailedHighOrEqualsStatus = getString("island.permission.fail-high-equals-status", messagePermissionPlayerFailedHighOrEqualsStatus);
}

private static void islandTrustLanguage() {
messageTrustSuccess = getString("island.trust.sucess", messageTrustSuccess);
messageTrustCommandNotEnoughArgs = getString("island.trust.not-enough-args", messageTrustCommandNotEnoughArgs);
}

private static void islandUnbanLanguage() {
messageUnbanCommandNotEnoughArgs = getString("island.unban.not-enough-args", messageUnbanCommandNotEnoughArgs);
messageUnbanPlayerNotBanned = getString("island.unban.player-not-banned", messageUnbanPlayerNotBanned);
messageUnBanPlayerSuccess = getString("island.unban.success", messageUnBanPlayerSuccess);
messageUnbanPlayerFailed = getString("island.unban.failed", messageUnbanPlayerFailed);
}

private static void islandUntrustLanguage() {
messageUntrustCommandNotEnoughArgs = getString("island.untrust.not-enough-args", messageUntrustCommandNotEnoughArgs);
messageUntrustSuccess = getString("island.untrust.success", messageUntrustSuccess);
messageUntrustCommandNotEnoughArgs = getString("island.untrust.failed", messageUntrustCommandNotEnoughArgs);
}

private static void islandWarpLanguage() {
messageWarpCommandNotEnoughArgs = getString("island.warp.not-enough-args", messageWarpCommandNotEnoughArgs);
messageWarpCreateSuccess = getString("island.warp.success", messageWarpCreateSuccess);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,12 @@ public class ListenersUtils {
cancellable.setCancelled(true);
return island;
}
PermissionRoleIsland permissionRoleIsland = PermissionRoleInIslandCache.getPermissionRoleIsland(island.getId(), players.getRoleType(), permissionsIsland.getPermissionType());
PermissionRoleIsland permissionRoleIsland;
if (PlayersInIslandCache.playerIsTrustedInIsland(island.getId(), player.getUniqueId())) {
permissionRoleIsland = PermissionRoleInIslandCache.getPermissionRoleIsland(island.getId(), RoleType.MEMBER, permissionsIsland.getPermissionType());
} else {
permissionRoleIsland = PermissionRoleInIslandCache.getPermissionRoleIsland(island.getId(), players.getRoleType(), permissionsIsland.getPermissionType());
}
PermissionManager permissionManager = new PermissionManager(permissionRoleIsland.permission());
if (!permissionManager.hasPermission(permissionsIsland)) {
cancellable.setCancelled(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
import fr.euphyllia.skyllia.listeners.ListenersUtils;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.bukkit.entity.*;
import org.bukkit.entity.Animals;
import org.bukkit.entity.Monster;
import org.bukkit.entity.NPC;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener;
Expand Down
2 changes: 2 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ The plugin has an API that you can use to add feature extensions to customize yo
- Alpha : https://github.com/Euphillya/Skyllia/releases

## API

Gradle Groovy

```groovy
repositories {
maven {
Expand Down

0 comments on commit d787752

Please sign in to comment.