Skip to content

Commit

Permalink
Commande /is expel <player>
Browse files Browse the repository at this point in the history
  • Loading branch information
Euphillya committed Jan 15, 2024
1 parent 4bc9162 commit 2606c03
Show file tree
Hide file tree
Showing 6 changed files with 150 additions and 3 deletions.
8 changes: 7 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.

8 changes: 7 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 @@ -15,7 +15,8 @@ public enum PermissionsCommandIsland implements Permissions {
SET_BIOME(64),
SET_WARP(128),
DEL_WARP(256),
TP_WARP(512);
TP_WARP(512),
EXPEL(1021);

private final int permissionValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public enum SubCommands {
DELETE(new DeleteSubCommand()),
DELWARP(new DelWarpSubCommand()),
DEMOTE(new DemoteSubCommand()),
EXPEL(new ExpelSubCommand()),
HOME(new HomeSubCommand()),
INVITE(new InviteSubCommand()),
KICK(new KickSubCommand()),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
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.PlayerUtils;
import fr.euphyllia.skyfolia.utils.RegionUtils;
import fr.euphyllia.skyfolia.utils.WorldUtils;
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.Location;
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 ExpelSubCommand implements SubCommandInterface {

private final Logger logger = LogManager.getLogger(ExpelSubCommand.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("skyfolia.island.command.expel")) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied);
return true;
}
if (args.length < 1) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageExpelCommandNotEnoughArgs);
return true;
}
ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
try {
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.EXPEL)) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied);
return;
}
}

String playerToExpel = args[0];
Player bPlayerToExpel = Bukkit.getPlayerExact(playerToExpel);
if (bPlayerToExpel == null) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerNotFound);
return;
}
if (!bPlayerToExpel.isOnline()) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerNotConnected);
return;
}
if (bPlayerToExpel.hasPermission("skyfolia.island.command.expel.bypass")) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageExpelPlayerFailed);
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.regionX() != playerRegionPosition.regionX() || islandPosition.regionZ() != playerRegionPosition.regionZ()) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageExpelPlayerFailedNotInIsland);
return;
}

PlayerUtils.teleportPlayerSpawn(plugin, bPlayerToExpel);
} 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 null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public class LanguageToml {
public static String messageVisitPlayerHasNotIsland = "Le joueur n'a pas d'île";
public static String messageVisitIslandIsPrivate = "L'île est fermée.";
public static String messageVisitIslandSuccess = "Vous avez été téléporté sur l'île de %player%.";
public static String messageExpelPlayerFailed = "Le joueur ne peut être expulser de votre île.";
public static String messageExpelPlayerFailedNotInIsland = "Le joueur n'est pas sur votre île.";
public static String messageExpelCommandNotEnoughArgs = "La commande n'est pas complète : /skyfolia expel <player>";
public static String messagePlayerNotConnected = "Le joueur n'est pas connecté";
private static boolean verbose;

public static void init(File configFile) {
Expand Down Expand Up @@ -187,6 +191,12 @@ private static void deleteIslandLanguage() {
messageIslandDeleteSuccess = getString("island.delete.success", messageIslandDeleteSuccess);
}

private static void expelIslandLanguage() {
messageExpelCommandNotEnoughArgs = getString("island.expel.not-enough-args", messageExpelCommandNotEnoughArgs);
messageExpelPlayerFailed = getString("island.expel.player-failed", messageExpelPlayerFailed);
messageExpelPlayerFailedNotInIsland = getString("island.expel.player-not-in-island", messageExpelPlayerFailedNotInIsland);
}

private static void homeIslandLanguage() {
messageHomeIslandSuccess = getString("island.home.success", messageHomeIslandSuccess);
messageHomeCreateSuccess = getString("island.home.set.success", messageHomeCreateSuccess);
Expand All @@ -202,6 +212,7 @@ private static void islandGenericLanguage() {
messageNotMember = getString("island.generic.not-member", messageNotMember);
messagePlayerPermissionDenied = getString("island.generic.player.permission-denied", messagePlayerPermissionDenied);
messageCommandAlreadyExecution = getString("island.generic.player.command-already-execution", messageCommandAlreadyExecution);
messagePlayerNotConnected = getString("island.generic.player.offline", messagePlayerNotConnected);
}

private static void islandInviteLanguage() {
Expand Down

0 comments on commit 2606c03

Please sign in to comment.