From d0dc49560af61cb5e612290cc3a7472b5be7c42a Mon Sep 17 00:00:00 2001 From: obvWolf Date: Tue, 9 Apr 2024 07:26:37 -0500 Subject: [PATCH] Fixed gamemode command --- .../commands/gamemode/GMACommand.java | 37 --------------- .../commands/gamemode/GMCCommand.java | 36 --------------- .../commands/gamemode/GMSCommand.java | 36 --------------- .../commands/gamemode/GMSPCommand.java | 37 --------------- .../commands/gamemode/GamemodeCommand.java | 45 ++++--------------- 5 files changed, 8 insertions(+), 183 deletions(-) delete mode 100644 src/main/java/me/trouper/ultrautils/commands/gamemode/GMACommand.java delete mode 100644 src/main/java/me/trouper/ultrautils/commands/gamemode/GMCCommand.java delete mode 100644 src/main/java/me/trouper/ultrautils/commands/gamemode/GMSCommand.java delete mode 100644 src/main/java/me/trouper/ultrautils/commands/gamemode/GMSPCommand.java diff --git a/src/main/java/me/trouper/ultrautils/commands/gamemode/GMACommand.java b/src/main/java/me/trouper/ultrautils/commands/gamemode/GMACommand.java deleted file mode 100644 index 8bac3b7..0000000 --- a/src/main/java/me/trouper/ultrautils/commands/gamemode/GMACommand.java +++ /dev/null @@ -1,37 +0,0 @@ -package me.trouper.ultrautils.commands.gamemode; - -import io.github.itzispyder.pdk.commands.Args; -import io.github.itzispyder.pdk.commands.CommandRegistry; -import io.github.itzispyder.pdk.commands.CustomCommand; -import io.github.itzispyder.pdk.commands.Permission; -import io.github.itzispyder.pdk.commands.completions.CompletionBuilder; -import me.trouper.ultrautils.functions.Text; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandRegistry(value = "gma",permission = @Permission("ultrautils.gamemode.adventure"),printStackTrace = true) -public class GMACommand implements CustomCommand { - - @Override - public void dispatchCommand(CommandSender commandSender, Command command, String label, Args args) { - Player target = Bukkit.getPlayer(args.get(0).toString()); - if (target == null && (commandSender instanceof Player)) target = (Player) commandSender; - if (target == null) { - commandSender.sendMessage(Text.prefix("Only players may execute that command")); - return; - } - if (!commandSender.hasPermission("ultrautils.gamemode")) { - commandSender.sendMessage(Text.prefix("You do not have the root permission to change gamemode.")); - return; - } - GamemodeCommand.setGameMode(commandSender,target,GameMode.ADVENTURE,"ultrautils.gamemode.adventure"); - } - - @Override - public void dispatchCompletions(CompletionBuilder b, CommandSender sender) { - b.arg(Bukkit.getOnlinePlayers(),Player::getName); - } -} diff --git a/src/main/java/me/trouper/ultrautils/commands/gamemode/GMCCommand.java b/src/main/java/me/trouper/ultrautils/commands/gamemode/GMCCommand.java deleted file mode 100644 index 8927b4a..0000000 --- a/src/main/java/me/trouper/ultrautils/commands/gamemode/GMCCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -package me.trouper.ultrautils.commands.gamemode; - -import io.github.itzispyder.pdk.commands.Args; -import io.github.itzispyder.pdk.commands.CommandRegistry; -import io.github.itzispyder.pdk.commands.CustomCommand; -import io.github.itzispyder.pdk.commands.Permission; -import io.github.itzispyder.pdk.commands.completions.CompletionBuilder; -import me.trouper.ultrautils.functions.Text; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandRegistry(value = "gmc",permission = @Permission("ultrautils.gamemode.creative"),printStackTrace = true) -public class GMCCommand implements CustomCommand { - - @Override - public void dispatchCommand(CommandSender commandSender, Command command, String label, Args args) { - Player target = Bukkit.getPlayer(args.get(0).toString()); - if (target == null && (commandSender instanceof Player)) target = (Player) commandSender; - if (target == null) { - commandSender.sendMessage(Text.prefix("Only players may execute that command")); - return; - } - if (!commandSender.hasPermission("ultrautils.gamemode")) { - commandSender.sendMessage(Text.prefix("You do not have the root permission to change gamemode.")); - return; - } - GamemodeCommand.setGameMode(commandSender,target,GameMode.CREATIVE,"ultrautils.gamemode.creative");} - - @Override - public void dispatchCompletions(CompletionBuilder b, CommandSender sender) { - b.arg(Bukkit.getOnlinePlayers(),Player::getName); - } -} diff --git a/src/main/java/me/trouper/ultrautils/commands/gamemode/GMSCommand.java b/src/main/java/me/trouper/ultrautils/commands/gamemode/GMSCommand.java deleted file mode 100644 index dab8605..0000000 --- a/src/main/java/me/trouper/ultrautils/commands/gamemode/GMSCommand.java +++ /dev/null @@ -1,36 +0,0 @@ -package me.trouper.ultrautils.commands.gamemode; - -import io.github.itzispyder.pdk.commands.Args; -import io.github.itzispyder.pdk.commands.CommandRegistry; -import io.github.itzispyder.pdk.commands.CustomCommand; -import io.github.itzispyder.pdk.commands.Permission; -import io.github.itzispyder.pdk.commands.completions.CompletionBuilder; -import me.trouper.ultrautils.functions.Text; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandRegistry(value = "gms",permission = @Permission("ultrautils.gamemode.survival"),printStackTrace = true) -public class GMSCommand implements CustomCommand { - - @Override - public void dispatchCommand(CommandSender commandSender, Command command, String label, Args args) { - Player target = Bukkit.getPlayer(args.get(0).toString()); - if (target == null && (commandSender instanceof Player)) target = (Player) commandSender; - if (target == null) { - commandSender.sendMessage(Text.prefix("Only players may execute that command")); - return; - } - if (!commandSender.hasPermission("ultrautils.gamemode")) { - commandSender.sendMessage(Text.prefix("You do not have the root permission to change gamemode.")); - return; - } - GamemodeCommand.setGameMode(commandSender,target,GameMode.SURVIVAL,"ultrautils.gamemode.survival");} - - @Override - public void dispatchCompletions(CompletionBuilder b, CommandSender sender) { - b.arg(Bukkit.getOnlinePlayers(),Player::getName); - } -} diff --git a/src/main/java/me/trouper/ultrautils/commands/gamemode/GMSPCommand.java b/src/main/java/me/trouper/ultrautils/commands/gamemode/GMSPCommand.java deleted file mode 100644 index 7b835a7..0000000 --- a/src/main/java/me/trouper/ultrautils/commands/gamemode/GMSPCommand.java +++ /dev/null @@ -1,37 +0,0 @@ -package me.trouper.ultrautils.commands.gamemode; - -import io.github.itzispyder.pdk.commands.Args; -import io.github.itzispyder.pdk.commands.CommandRegistry; -import io.github.itzispyder.pdk.commands.CustomCommand; -import io.github.itzispyder.pdk.commands.Permission; -import io.github.itzispyder.pdk.commands.completions.CompletionBuilder; -import me.trouper.ultrautils.functions.Text; -import org.bukkit.Bukkit; -import org.bukkit.GameMode; -import org.bukkit.command.Command; -import org.bukkit.command.CommandSender; -import org.bukkit.entity.Player; - -@CommandRegistry(value = "gmsp",permission = @Permission("ultrautils.gamemode.spectator"),printStackTrace = true) -public class GMSPCommand implements CustomCommand { - - @Override - public void dispatchCommand(CommandSender commandSender, Command command, String label, Args args) { - Player target = Bukkit.getPlayer(args.get(0).toString()); - if (target == null && (commandSender instanceof Player)) target = (Player) commandSender; - if (target == null) { - commandSender.sendMessage(Text.prefix("Only players may execute that command")); - return; - } - if (!commandSender.hasPermission("ultrautils.gamemode")) { - commandSender.sendMessage(Text.prefix("You do not have the root permission to change gamemode.")); - return; - } - GamemodeCommand.setGameMode(commandSender,target,GameMode.SPECTATOR,"ultrautils.gamemode.spectator"); - } - - @Override - public void dispatchCompletions(CompletionBuilder b, CommandSender sender) { - b.arg(Bukkit.getOnlinePlayers(),Player::getName); - } -} diff --git a/src/main/java/me/trouper/ultrautils/commands/gamemode/GamemodeCommand.java b/src/main/java/me/trouper/ultrautils/commands/gamemode/GamemodeCommand.java index e82ba33..75b956f 100644 --- a/src/main/java/me/trouper/ultrautils/commands/gamemode/GamemodeCommand.java +++ b/src/main/java/me/trouper/ultrautils/commands/gamemode/GamemodeCommand.java @@ -25,42 +25,13 @@ public class GamemodeCommand implements CustomCommand { sender.sendMessage(Text.prefix("Only players may execute that command")); return; } - target.sendMessage("Target: %s, Sender: %s, Command: %s, Label: %s, Args: %s".formatted(target,sender,command,label,args)); - switch (label) { - case "gma" -> { - setGameMode(sender,target,GameMode.ADVENTURE, "ultrautils.gamemode.adventure"); - return; - } - case "gmc" -> { - setGameMode(sender,target,GameMode.CREATIVE,"ultrautils.gamemode.creative"); - return; - } - case "gms" -> { - setGameMode(sender,target,GameMode.SURVIVAL,"ultrautils.gamemode.survival"); - return; - } - case "gmsp" -> { - setGameMode(sender,target,GameMode.SPECTATOR,"ultrautils.gamemode.spectator"); - return; - } - } - switch (args.get(0).toString()) { - case "a","adventure","adv","gma" -> { - setGameMode(sender,target,GameMode.ADVENTURE, "ultrautils.gamemode.adventure"); - return; - } - case "c","creative","cre","gmc" -> { - setGameMode(sender,target,GameMode.CREATIVE,"ultrautils.gamemode.creative"); - return; - } - case "s","survival","sur","gms" -> { - setGameMode(sender,target,GameMode.SURVIVAL,"ultrautils.gamemode.survival"); - return; - } - case "sp","spectator","spec","gmsp" -> { - setGameMode(sender,target,GameMode.SPECTATOR,"ultrautils.gamemode.spectator"); - return; - } + String gamemode = label; + if (label.equals("gamemode")) gamemode = args.get(0).toString(); + switch (gamemode) { + case "a","adventure","adv","gma" -> setGameMode(sender,target,GameMode.ADVENTURE, "ultrautils.gamemode.adventure"); + case "c","creative","cre","gmc" -> setGameMode(sender,target,GameMode.CREATIVE,"ultrautils.gamemode.creative"); + case "s","survival","sur","gms" -> setGameMode(sender,target,GameMode.SURVIVAL,"ultrautils.gamemode.survival"); + case "sp","spectator","spec","gmsp" -> setGameMode(sender,target,GameMode.SPECTATOR,"ultrautils.gamemode.spectator"); } } @@ -73,7 +44,7 @@ public class GamemodeCommand implements CustomCommand { public static void setGameMode(CommandSender user, @Nullable Player target, GameMode gm, String permission) { if (!user.hasPermission(permission)) { - user.sendMessage(Text.prefix("You lack the permission to swith gamemodes to %c%s&7.")); + user.sendMessage(Text.prefix("You lack the permission to switch gamemodes to %c%s&7.")); return; }