Skip to content

Commit

Permalink
Commande : /is delwarp
Browse files Browse the repository at this point in the history
/is warp
  • Loading branch information
Euphillya committed Jan 15, 2024
1 parent cf714ec commit 1b0e2e3
Show file tree
Hide file tree
Showing 16 changed files with 234 additions and 30 deletions.
4 changes: 3 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.

4 changes: 3 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 @@ -27,6 +27,8 @@ public abstract class Island {

public abstract boolean addWarps(String name, Location loc);

public abstract boolean delWarp(String name);

public abstract boolean isDisable();

public abstract void setDisable(boolean disable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ public enum PermissionsCommandIsland implements Permissions {
SET_HOME(16),
INVITE(32),
SET_BIOME(64),
SET_WARP(128);
SET_WARP(128),
DEL_WARP(256),
TP_WARP(512);

private final int permissionValue;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public enum SubCommands {
BIOME(new SetBiomeSubCommand()),
CREATE(new CreateSubCommand()),
DELETE(new DeleteSubCommand()),
DELWARP(new DelWarpSubCommand()),
DEMOTE(new DemoteSubCommand()),
HOME(new HomeSubCommand()),
INVITE(new InviteSubCommand()),
Expand All @@ -16,7 +17,8 @@ public enum SubCommands {
PROMOTE(new PromoteSubCommand()),
TRANSFER(new TransferSubCommand()),
SETHOME(new SetHomeSubCommand()),
SETWARP(new SetWarpSubCommand());
SETWARP(new SetWarpSubCommand()),
WARP(new WarpSubCommand());

private final SubCommandInterface commandInterface;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
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.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.managers.skyblock.PermissionManager;
import fr.euphyllia.skyfolia.managers.skyblock.SkyblockManager;
import org.apache.logging.log4j.Level;
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 DelWarpSubCommand implements SubCommandInterface {

private final Logger logger = LogManager.getLogger(DelWarpSubCommand.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 (args.length <= 1) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageWarpCommandNotEnoughArgs);
return true;
}
if (!player.hasPermission("skyfolia.island.command.delwarp")) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied);
return true;
}

String warpName = args[0];

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;
}

if (warpName.equalsIgnoreCase("home")) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageIslandNotDeleteHome);
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.DEL_WARP)) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied);
return;
}
}

boolean deleteWarp = island.delWarp(warpName);
if (deleteWarp) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageWarpDeleteSuccess);
} 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();
}


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;
}

private boolean isWorldIsland(String worldName) {
return ConfigToml.worldConfigs.stream().anyMatch(wc -> wc.name().equalsIgnoreCase(worldName));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,11 @@
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
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public class HomeSubCommand implements SubCommandInterface {
private final Logger logger = LogManager.getLogger(HomeSubCommand.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)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
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;
Expand Down Expand Up @@ -80,7 +79,7 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N
} else {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageError);
}
} catch (Exception e) {
} 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 @@ -93,7 +93,7 @@ public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @N
} else {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageError);
}
} catch (Exception e) {
} 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
@@ -1,18 +1,91 @@
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.RoleType;
import fr.euphyllia.skyfolia.api.skyblock.model.WarpIsland;
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 org.apache.logging.log4j.Level;
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 WarpSubCommand implements SubCommandInterface {

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

@Override
public boolean onCommand(@NotNull Main plugin, @NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
return false;
if (!(sender instanceof Player player)) {
return true;
}
if (args.length <= 1) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageWarpCommandNotEnoughArgs);
return true;
}
if (!player.hasPermission("skyfolia.island.command.warp")) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied);
return true;
}

String warpName = args[0];

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.TP_WARP)) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messagePlayerPermissionDenied);
return;
}
}

WarpIsland warp = island.getWarpByName(warpName);
if (warp == null) {
LanguageToml.sendMessage(plugin, player, LanguageToml.messageWarpNotExist);
return;
}

player.teleportAsync(warp.location());
LanguageToml.sendMessage(plugin, player, LanguageToml.messageWarpTeleportSuccess);
} catch (Exception e) {
logger.log(Level.FATAL, e.getMessage(), e);
LanguageToml.sendMessage(plugin, player, LanguageToml.messageError);
}
});
} finally {
executor.shutdown();
}


return true;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ public class LanguageToml {
public static String messageLeavePlayerFailed = "Vous n'avez pas pu quitter votre île. Si le problème persiste, contacter un administrateur";
public static String messageAccessIslandOpen = "Votre île est maintenant ouverte.";
public static String messageAccessIslandClose = "Votre île est maintenant fermée.";
public static String messageHomeIslandSuccess = "Vous avez été téléporté sur votre île.";
public static String messageHomeCreateSuccess = "Vous avez modifier votre home !";
public static String messageWarpCommandNotEnoughArgs = "Vous devez préciser le nom du warp à enregistrer : /skyfolia setwarp <warp_name>";
public static String messageIslandNotDeleteHome = "Vous ne pouvez pas supprimer le warp home.";
public static String messageWarpDeleteSuccess = "Le warp a été supprimé.";
public static String messageWarpNotExist = "Le warp demandé n'existe pas.";
public static String messageWarpTeleportSuccess = "Vous avez été téléporter sur le warp demandé.";
private static boolean verbose;

public static void init(File configFile) {
Expand Down Expand Up @@ -176,11 +183,9 @@ private static void deleteIslandLanguage() {
messageIslandDeleteSuccess = getString("island.delete.success", messageIslandDeleteSuccess);
}

public static String messageHomeIslandSuccess = "Vous avez été téléporté sur votre île.";
public static String messageHomeCreateSuccess = "Vous avez modifier votre home !";
private static void homeIslandLanguage() {
messageHomeIslandSuccess = getString("island.home.success", messageHomeIslandSuccess);
messageHomeCreateSuccess= getString("island.home.set.success", messageHomeCreateSuccess);
messageHomeCreateSuccess = getString("island.home.set.success", messageHomeCreateSuccess);
}

private static void islandGenericLanguage() {
Expand Down Expand Up @@ -221,10 +226,13 @@ private static void islandLeaveLanguage() {
messageLeaveFailedIsOwnerIsland = getString("island.leave.he-is-owner", messageLeaveFailedIsOwnerIsland);
}

public static String messageWarpCommandNotEnoughArgs = "Vous devez préciser le nom du warp à enregistrer : /skyfolia setwarp <warp_name>";
private static void islandWarpLanguage() {
messageWarpCommandNotEnoughArgs = getString("island.warp.not-enough-args", messageWarpCommandNotEnoughArgs);
messageWarpCreateSuccess = getString("island.warp.success", messageWarpCreateSuccess);
messageIslandNotDeleteHome = getString("island.warp.delete.can-not-delete-home", messageIslandNotDeleteHome);
messageWarpDeleteSuccess = getString("island.warp.delete.success", messageWarpDeleteSuccess);
messageWarpNotExist = getString("island.warp.teleport.not-exist", messageWarpNotExist);
messageWarpTeleportSuccess = getString("island.warp.teleport.success", messageWarpTeleportSuccess);
}


Expand Down
Loading

0 comments on commit 1b0e2e3

Please sign in to comment.