-
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.
- Loading branch information
Showing
6 changed files
with
150 additions
and
3 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
122 changes: 122 additions & 0 deletions
122
plugin/src/main/java/fr/euphyllia/skyfolia/commands/subcommands/ExpelSubCommand.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,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; | ||
} | ||
} |
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