-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Mettre des personnes en membre temporaire/confirnace
- Loading branch information
Showing
12 changed files
with
261 additions
and
6 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
plugin/src/main/java/fr/euphyllia/skyllia/commands/common/subcommands/TrustSubCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<>(); | ||
} | ||
} |
98 changes: 98 additions & 0 deletions
98
plugin/src/main/java/fr/euphyllia/skyllia/commands/common/subcommands/UntrustSubCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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<>(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters