Skip to content

Commit

Permalink
Command /skyllia [un]ban player
Browse files Browse the repository at this point in the history
Mise en ordre des langues
  • Loading branch information
Euphillya committed Jan 25, 2024
1 parent 63a2f3d commit 4bcc6c2
Show file tree
Hide file tree
Showing 11 changed files with 286 additions and 35 deletions.
14 changes: 13 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.

14 changes: 13 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 @@ -18,6 +18,8 @@ public enum PermissionsCommandIsland implements Permissions {
TP_WARP(512),
EXPEL(1_024),
MANAGE_PERMISSION(2_048),
BAN(4_096),
UNBAN(8_192),
;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

public enum SubCommands {
ACCESS(new AccessSubCommand()),
BAN(new BanSubCommand()),
BIOME(new SetBiomeSubCommand()),
CREATE(new CreateSubCommand()),
DELETE(new DeleteSubCommand()),
Expand All @@ -20,6 +21,7 @@ public enum SubCommands {
TRANSFER(new TransferSubCommand()),
SETHOME(new SetHomeSubCommand()),
SETWARP(new SetWarpSubCommand()),
UNBAN(new UnbanSubCommand()),
VISIT(new VisitSubCommand()),
WARP(new WarpSubCommand());

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
package fr.euphyllia.skyllia.commands.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.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.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.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

public class BanSubCommand implements SubCommandInterface {

private final Logger logger = LogManager.getLogger(BanSubCommand.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.ban")) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied);
return true;
}
if (args.length < 1) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageBanCommandNotEnoughArgs);
return true;
}
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
try {
executor.execute(() -> {
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.BAN)) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied);
return;
}
}

String playerBan = args[0];
Players players = island.getMember(playerBan);

if (players != null) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageBanImpossiblePlayerInIsland);
return;
}

Player bPlayerBan = Bukkit.getPlayerExact(playerBan);
if (bPlayerBan == null) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerNotFound);
return;
}

players = new Players(bPlayerBan.getUniqueId(), playerBan, island.getId(), RoleType.BAN);

island.updateMember(players);
LanguageToml.sendMessage(plugin, player, LanguageToml.messageBanPlayerSuccess);
ExpelSubCommand.expelPlayer(plugin, island, bPlayerBan, player, true);
});
} 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 null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ public class ExpelSubCommand implements SubCommandInterface {

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

public static void expelPlayer(Main plugin, Island island, Player bPlayerToExpel, Player executor, boolean silent) {
Location bPlayerExpelLocation = bPlayerToExpel.getLocation();
if (Boolean.FALSE.equals(WorldUtils.isWorldSkyblock(bPlayerExpelLocation.getWorld().getName()))) {
if (!silent) LanguageToml.sendMessage(plugin, executor, LanguageToml.messageExpelPlayerFailedNotInIsland);
return;
}

int chunkLocX = bPlayerExpelLocation.getChunk().getX();
int chunkLocZ = bPlayerExpelLocation.getChunk().getZ();

Position islandPosition = island.getPosition();
Position playerRegionPosition = RegionUtils.getRegionInChunk(chunkLocX, chunkLocZ);

if (islandPosition.x() != playerRegionPosition.x() || islandPosition.z() != playerRegionPosition.z()) {
if (!silent) LanguageToml.sendMessage(plugin, executor, LanguageToml.messageExpelPlayerFailedNotInIsland);
return;
}

PlayerUtils.teleportPlayerSpawn(plugin, bPlayerToExpel);
}

@Override
public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
if (!(sender instanceof Player player)) {
Expand Down Expand Up @@ -85,24 +106,8 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N
return;
}

Location bPlayerExpelLocation = bPlayerToExpel.getLocation();
if (Boolean.FALSE.equals(WorldUtils.isWorldSkyblock(bPlayerExpelLocation.getWorld().getName()))) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageExpelPlayerFailedNotInIsland);
return;
}

int chunkLocX = bPlayerExpelLocation.getChunk().getX();
int chunkLocZ = bPlayerExpelLocation.getChunk().getZ();

Position islandPosition = island.getPosition();
Position playerRegionPosition = RegionUtils.getRegionInChunk(chunkLocX, chunkLocZ);

if (islandPosition.x() != playerRegionPosition.x() || islandPosition.z() != playerRegionPosition.z()) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageExpelPlayerFailedNotInIsland);
return;
}
expelPlayer(plugin, island, bPlayerToExpel, player, false);

PlayerUtils.teleportPlayerSpawn(plugin, bPlayerToExpel);
} catch (Exception e) {
logger.log(Level.FATAL, e.getMessage(), e);
LanguageToml.sendMessage(plugin, player, LanguageToml.messageError);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N
return true;
}
if (args.length < 1) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageDemoteCommandNotEnoughArgs);
LanguageToml.sendMessage(plugin, player, LanguageToml.messageKickCommandNotEnoughArgs);
return true;
}
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package fr.euphyllia.skyllia.commands.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.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.LogManager;
import org.apache.logging.log4j.Logger;
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.List;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

public class UnbanSubCommand implements SubCommandInterface {

private final Logger logger = LogManager.getLogger(UnbanSubCommand.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.unban")) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied);
return true;
}
if (args.length < 1) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageUnbanCommandNotEnoughArgs);
return true;
}
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
try {
executor.execute(() -> {
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.UNBAN)) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied);
return;
}
}

String playerBan = args[0];
Players players = island.getMember(playerBan);

if (players == null) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageUnbanPlayerNotBanned);
return;
}

boolean isRemoved = island.removeMember(players);
if (isRemoved) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageUnBanPlayerSuccess);
} else {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageUnbanPlayerFailed);
}

});
} 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 null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

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.RoleType;
import fr.euphyllia.skyllia.api.skyblock.model.WarpIsland;
import fr.euphyllia.skyllia.commands.SubCommandInterface;
import fr.euphyllia.skyllia.configuration.LanguageToml;
Expand Down Expand Up @@ -66,6 +68,11 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N
LanguageToml.sendMessage(plugin, player, LanguageToml.messageVisitIslandIsPrivate);
return;
}
Players memberIsland = island.getMember(player.getUniqueId());
if (memberIsland != null && memberIsland.getRoleType().equals(RoleType.BAN)) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageVisitIslandPlayerBanned);
return;
}
}

WarpIsland warpIsland = island.getWarpByName("home");
Expand Down
Loading

0 comments on commit 4bcc6c2

Please sign in to comment.