diff --git a/src/main/java/dev/plex/command/impl/KickCMD.java b/src/main/java/dev/plex/command/impl/KickCMD.java new file mode 100644 index 0000000..78282e6 --- /dev/null +++ b/src/main/java/dev/plex/command/impl/KickCMD.java @@ -0,0 +1,71 @@ +package dev.plex.command.impl; + +import dev.plex.cache.DataUtils; +import dev.plex.cache.PlayerCache; +import dev.plex.command.PlexCommand; +import dev.plex.command.annotation.CommandParameters; +import dev.plex.command.annotation.CommandPermissions; +import dev.plex.command.exception.PlayerNotFoundException; +import dev.plex.command.source.RequiredCommandSource; +import dev.plex.player.PlexPlayer; +import dev.plex.player.PunishedPlayer; +import dev.plex.punishment.Punishment; +import dev.plex.punishment.PunishmentType; +import dev.plex.rank.enums.Rank; +import dev.plex.util.PlexUtils; +import java.time.LocalDateTime; +import java.util.UUID; +import net.kyori.adventure.text.Component; +import org.apache.commons.lang.StringUtils; +import org.bukkit.Bukkit; +import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +@CommandParameters(name = "kick", description = "Kicks a player", usage = "/ ") +@CommandPermissions(level = Rank.ADMIN, permission = "plex.kick", source = RequiredCommandSource.ANY) +public class KickCMD extends PlexCommand +{ + @Override + protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) + { + if (args.length == 0) + { + return usage(); + } + + UUID targetUUID = PlexUtils.getFromName(args[0]); + String reason = "No reason provided"; + + if (targetUUID == null || !DataUtils.hasPlayedBefore(targetUUID)) + { + throw new PlayerNotFoundException(); + } + PlexPlayer plexPlayer = DataUtils.getPlayer(targetUUID); + Player player = Bukkit.getPlayer(targetUUID); + + if (player == null) + { + throw new PlayerNotFoundException(); + } + + PunishedPlayer punishedPlayer = PlayerCache.getPunishedPlayer(targetUUID) == null ? new PunishedPlayer(targetUUID) : PlayerCache.getPunishedPlayer(targetUUID); + Punishment punishment = new Punishment(targetUUID, getUUID(sender)); + punishment.setType(PunishmentType.KICK); + if (args.length > 1) + { + reason = StringUtils.join(args, " ", 1, args.length); + punishment.setReason(reason); + } + + punishment.setPunishedUsername(plexPlayer.getName()); + punishment.setEndDate(LocalDateTime.now()); + punishment.setCustomTime(false); + punishment.setActive(false); + plugin.getPunishmentManager().doPunishment(punishedPlayer, punishment); + PlexUtils.broadcast(messageComponent("kickedPlayer", sender.getName(), plexPlayer.getName())); + player.kick(componentFromString(reason)); + return null; + } +} \ No newline at end of file diff --git a/src/main/java/dev/plex/command/impl/PlexCMD.java b/src/main/java/dev/plex/command/impl/PlexCMD.java index ad51b88..de68bc4 100644 --- a/src/main/java/dev/plex/command/impl/PlexCMD.java +++ b/src/main/java/dev/plex/command/impl/PlexCMD.java @@ -20,31 +20,28 @@ import org.jetbrains.annotations.Nullable; @CommandParameters(name = "plex", usage = "/ [reload | redis]", aliases = "plexhelp", description = "Show information about Plex or reload it") public class PlexCMD extends PlexCommand { + // Don't modify this command @Override protected Component execute(@NotNull CommandSender sender, @Nullable Player playerSender, String[] args) { if (args.length == 0) { send(sender, ChatColor.LIGHT_PURPLE + "Plex - A new freedom plugin."); - return componentFromString(ChatColor.LIGHT_PURPLE + "Plugin version: " + ChatColor.GOLD + plugin.getDescription().getVersion()); + send(sender, ChatColor.LIGHT_PURPLE + "Plugin version: " + plugin.getDescription().getVersion()); + return componentFromString(ChatColor.LIGHT_PURPLE + "Authors: " + ChatColor.GOLD + "Telesphoreo, Taahh"); } if (args[0].equalsIgnoreCase("reload")) { checkRank(sender, Rank.SENIOR_ADMIN, "plex.reload"); - - Plex.get().config.load(); + plugin.config.load(); send(sender, "Reloaded config file"); - - Plex.get().messages.load(); + plugin.messages.load(); send(sender, "Reloaded messages file"); - - Plex.get().indefBans.load(); - Plex.get().getPunishmentManager().mergeIndefiniteBans(); + plugin.indefBans.load(); + plugin.getPunishmentManager().mergeIndefiniteBans(); send(sender, "Reloaded indefinite bans"); - - Plex.get().getRankManager().importDefaultRanks(); + plugin.getRankManager().importDefaultRanks(); send(sender, "Imported ranks"); - send(sender, "Plex successfully reloaded."); } else if (args[0].equalsIgnoreCase("redis")) diff --git a/src/main/java/dev/plex/handlers/CommandHandler.java b/src/main/java/dev/plex/handlers/CommandHandler.java index a3e7bb4..e1aa045 100644 --- a/src/main/java/dev/plex/handlers/CommandHandler.java +++ b/src/main/java/dev/plex/handlers/CommandHandler.java @@ -35,6 +35,7 @@ public class CommandHandler extends PlexBase commands.add(new CreativeCMD()); commands.add(new FlatlandsCMD()); commands.add(new FreezeCMD()); + commands.add(new KickCMD()); commands.add(new ListCMD()); commands.add(new LocalSpawnCMD()); commands.add(new LockupCMD()); diff --git a/src/main/java/dev/plex/punishment/PunishmentType.java b/src/main/java/dev/plex/punishment/PunishmentType.java index 887bbd2..22961a4 100644 --- a/src/main/java/dev/plex/punishment/PunishmentType.java +++ b/src/main/java/dev/plex/punishment/PunishmentType.java @@ -2,5 +2,5 @@ package dev.plex.punishment; public enum PunishmentType { - MUTE, FREEZE, BAN; + MUTE, FREEZE, BAN, KICK; } diff --git a/src/main/resources/messages.yml b/src/main/resources/messages.yml index 141e6c9..47f83e5 100644 --- a/src/main/resources/messages.yml +++ b/src/main/resources/messages.yml @@ -35,14 +35,14 @@ oppedPlayer: " - Opped " deoppedPlayer: " - Deopped " # 1. The person who is freezing # 2. The person who has been frozen -frozePlayer: " - Froze " +frozePlayer: " - Froze " # 1. The person who is unfreezing # 2. The person who has been unfrozen unfrozePlayer: " - Unfroze " -# 1. The person who is muting +# 1. The command sender # 2. The person who has been muted -mutedPlayer: " - Muted " -# 1. The person who is unmuting +mutedPlayer: " - Muted " +# 1. The command sender # 2. The person who has been unmuted unmutedPlayer: " - Unmuted " # 1. The person who is locking up @@ -51,7 +51,6 @@ lockedUpPlayer: " - Locking up " # 1. The person who is unlocking # 2. The person who has been unlocked unlockedUpPlayer: " - Unlocking " - noPermission: "You cannot use this command!" # 1. The rank required to use the command noPermissionRank: "You must be at least to use this command!" @@ -114,8 +113,8 @@ playerBanned: "That player is already banned!" playerFrozen: "That player is already frozen!" playerMuted: "That player is already muted!" playerLockedUp: "That player is already locked up!" - muted: "You are currently muted - STFU!" +kickedPlayer: " - Kicking " teleportedToWorldSpawn: "Teleporting to the local spawn" toggleCommandSpy: "CommandSpy has been" enabled: "enabled."