-
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.
/is warp
- Loading branch information
Showing
16 changed files
with
234 additions
and
30 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
102 changes: 102 additions & 0 deletions
102
plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/DelWarpSubCommand.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,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)); | ||
} | ||
} |
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
75 changes: 74 additions & 1 deletion
75
plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/WarpSubCommand.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
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
Oops, something went wrong.