Skip to content

Commit

Permalink
op error fix
Browse files Browse the repository at this point in the history
  • Loading branch information
yj0524 committed May 1, 2023
1 parent 8e05e6d commit 5fe5a14
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 63 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>gamemodecommandfix</groupId>
<artifactId>GamemodeCommandFix</artifactId>
<version>1.0.1</version>
<version>1.0.2</version>
<packaging>jar</packaging>

<name>GamemodeCommandFix</name>
Expand Down
127 changes: 65 additions & 62 deletions src/main/java/com/yj0524/commands/Gm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

0 comments on commit 5fe5a14

Please sign in to comment.