diff --git a/pom.xml b/pom.xml index e40a75d..46fafea 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ gamemodecommandfix GamemodeCommandFix - 1.0.1 + 1.0.2 jar GamemodeCommandFix diff --git a/src/main/java/com/yj0524/commands/Gm.java b/src/main/java/com/yj0524/commands/Gm.java index 22c20dc..6930795 100644 --- a/src/main/java/com/yj0524/commands/Gm.java +++ b/src/main/java/com/yj0524/commands/Gm.java @@ -9,90 +9,93 @@ public class Gm implements CommandExecutor { @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { - // /gm <0, 1, 2, 3, survival, creative, adventure, spectator> [player] - if (args.length == 1) { - if (args[0].equalsIgnoreCase("0") || args[0].equalsIgnoreCase("survival")) { - if (sender instanceof Player) { - ((Player) sender).setGameMode(GameMode.SURVIVAL); - sender.sendMessage("Gamemode has been changed to survival."); - return true; - } - sender.sendMessage("You must be a player to use this command."); - } - if (args[0].equalsIgnoreCase("1") || args[0].equalsIgnoreCase("creative")) { - if (sender instanceof Player) { - ((Player) sender).setGameMode(GameMode.CREATIVE); - sender.sendMessage("Gamemode has been changed to creative."); - return true; - } - sender.sendMessage("You must be a player to use this command."); - } - if (args[0].equalsIgnoreCase("2") || args[0].equalsIgnoreCase("adventure")) { - if (sender instanceof Player) { - ((Player) sender).setGameMode(GameMode.ADVENTURE); - sender.sendMessage("Gamemode has been changed to adventure."); - return true; - } - sender.sendMessage("You must be a player to use this command."); - } - if (args[0].equalsIgnoreCase("3") || args[0].equalsIgnoreCase("spectator")) { - if (sender instanceof Player) { - ((Player) sender).setGameMode(GameMode.SPECTATOR); - sender.sendMessage("Gamemode has been changed to spectator."); - return true; - } - sender.sendMessage("You must be a player to use this command."); - } - } - if (args.length == 2) { - String targetPlayer = args[1]; - if (sender.getServer().getPlayer(targetPlayer) == null) { - sender.sendMessage("§cPlayer not found."); - return true; - } - else { + if (sender.isOp()) { + // /gm <0, 1, 2, 3, survival, creative, adventure, spectator> [player] + if (args.length == 1) { if (args[0].equalsIgnoreCase("0") || args[0].equalsIgnoreCase("survival")) { if (sender instanceof Player) { - sender.getServer().getPlayer(targetPlayer).setGameMode(GameMode.SURVIVAL); - sender.sendMessage("Gamemode for " + args[1] + " has been changed to survival."); + ((Player) sender).setGameMode(GameMode.SURVIVAL); + sender.sendMessage("Gamemode has been changed to survival."); return true; - } else { - sender.sendMessage("You must be a player to use this command."); } + sender.sendMessage("You must be a player to use this command."); } if (args[0].equalsIgnoreCase("1") || args[0].equalsIgnoreCase("creative")) { if (sender instanceof Player) { - sender.getServer().getPlayer(targetPlayer).setGameMode(GameMode.CREATIVE); - sender.sendMessage("Gamemode for " + args[1] + " has been changed to creative."); + ((Player) sender).setGameMode(GameMode.CREATIVE); + sender.sendMessage("Gamemode has been changed to creative."); return true; - } else { - sender.sendMessage("You must be a player to use this command."); } + sender.sendMessage("You must be a player to use this command."); } if (args[0].equalsIgnoreCase("2") || args[0].equalsIgnoreCase("adventure")) { if (sender instanceof Player) { - sender.getServer().getPlayer(targetPlayer).setGameMode(GameMode.ADVENTURE); - sender.sendMessage("Gamemode for " + args[1] + " has been changed to adventure."); + ((Player) sender).setGameMode(GameMode.ADVENTURE); + sender.sendMessage("Gamemode has been changed to adventure."); return true; - } else { - sender.sendMessage("You must be a player to use this command."); } + sender.sendMessage("You must be a player to use this command."); } if (args[0].equalsIgnoreCase("3") || args[0].equalsIgnoreCase("spectator")) { if (sender instanceof Player) { - sender.getServer().getPlayer(targetPlayer).setGameMode(GameMode.SPECTATOR); - sender.sendMessage("Gamemode for " + args[1] + " has been changed to spectator."); + ((Player) sender).setGameMode(GameMode.SPECTATOR); + sender.sendMessage("Gamemode has been changed to spectator."); return true; - } else { - sender.sendMessage("You must be a player to use this command."); } + sender.sendMessage("You must be a player to use this command."); } } - } - else { - sender.sendMessage("§cUsage: /gm <0, 1, 2, 3, survival, creative, adventure, spectator> [player]"); + if (args.length == 2) { + String targetPlayer = args[1]; + if (sender.getServer().getPlayer(targetPlayer) == null) { + sender.sendMessage("§cPlayer not found."); + return true; + } else { + if (args[0].equalsIgnoreCase("0") || args[0].equalsIgnoreCase("survival")) { + if (sender instanceof Player) { + sender.getServer().getPlayer(targetPlayer).setGameMode(GameMode.SURVIVAL); + sender.sendMessage("Gamemode for " + args[1] + " has been changed to survival."); + return true; + } else { + sender.sendMessage("You must be a player to use this command."); + } + } + if (args[0].equalsIgnoreCase("1") || args[0].equalsIgnoreCase("creative")) { + if (sender instanceof Player) { + sender.getServer().getPlayer(targetPlayer).setGameMode(GameMode.CREATIVE); + sender.sendMessage("Gamemode for " + args[1] + " has been changed to creative."); + return true; + } else { + sender.sendMessage("You must be a player to use this command."); + } + } + if (args[0].equalsIgnoreCase("2") || args[0].equalsIgnoreCase("adventure")) { + if (sender instanceof Player) { + sender.getServer().getPlayer(targetPlayer).setGameMode(GameMode.ADVENTURE); + sender.sendMessage("Gamemode for " + args[1] + " has been changed to adventure."); + return true; + } else { + sender.sendMessage("You must be a player to use this command."); + } + } + if (args[0].equalsIgnoreCase("3") || args[0].equalsIgnoreCase("spectator")) { + if (sender instanceof Player) { + sender.getServer().getPlayer(targetPlayer).setGameMode(GameMode.SPECTATOR); + sender.sendMessage("Gamemode for " + args[1] + " has been changed to spectator."); + return true; + } else { + sender.sendMessage("You must be a player to use this command."); + } + } + } + } else { + sender.sendMessage("§cUsage: /gm <0, 1, 2, 3, survival, creative, adventure, spectator> [player]"); + return true; + } + return false; + } else { + sender.sendMessage("§cYou do not have permission to use this command."); return true; } - return false; } }