diff --git a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java index e1f948d28..070bf7fd5 100644 --- a/src/main/java/net/citizensnpcs/command/command/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/command/command/NPCCommands.java @@ -46,6 +46,7 @@ import net.citizensnpcs.util.StringHelper; import net.citizensnpcs.util.Util; import org.bukkit.Bukkit; +import org.bukkit.GameMode; import org.bukkit.Location; import org.bukkit.World; import org.bukkit.command.CommandSender; @@ -373,6 +374,40 @@ public class NPCCommands { Messaging.sendTr(sender, Messages.NPC_DESPAWNED, npc.getName()); } + @Command( + aliases = { "npc" }, + usage = "gamemode [gamemode]", + desc = "Changes the gamemode", + modifiers = { "gravity" }, + min = 1, + max = 2, + permission = "npc.gravity") + @Requirements(selected = true, ownership = true, types = { EntityType.PLAYER }) + public void gamemode(CommandContext args, CommandSender sender, NPC npc) { + Player player = (Player) npc.getBukkitEntity(); + if (args.argsLength() == 1) { + Messaging.sendTr(sender, Messages.GAMEMODE_DESCRIBE, npc.getName(), player.getGameMode().name() + .toLowerCase()); + return; + } + GameMode mode = null; + try { + int value = args.getInteger(1); + mode = GameMode.getByValue(value); + } catch (NumberFormatException ex) { + try { + mode = GameMode.valueOf(args.getString(1)); + } catch (IllegalArgumentException e) { + } + } + if (mode == null) { + Messaging.sendErrorTr(sender, Messages.GAMEMODE_INVALID, args.getString(1)); + return; + } + player.setGameMode(mode); + Messaging.sendTr(sender, Messages.GAMEMODE_SET, mode.name().toLowerCase()); + } + @Command( aliases = { "npc" }, usage = "gravity", diff --git a/src/main/java/net/citizensnpcs/util/Messages.java b/src/main/java/net/citizensnpcs/util/Messages.java index 4e297a473..5f0e9b1d2 100644 --- a/src/main/java/net/citizensnpcs/util/Messages.java +++ b/src/main/java/net/citizensnpcs/util/Messages.java @@ -175,4 +175,7 @@ public class Messages { public static final String WAYPOINT_PROVIDER_SET = "citizens.waypoints.set-provider"; public static final String WRITING_DEFAULT_SETTING = "citizens.settings.writing-default"; public static final String PATHFINDING_RANGE_SET = "citizens.commands.npc.pathfindingrange.set"; + public static final String GAMEMODE_DESCRIBE = "citizens.commands.npc.gamemode.describe"; + public static final String GAMEMODE_INVALID = "citizens.commands.npc.gamemode.invalid"; + public static final String GAMEMODE_SET = "citizens.commands.npc.gamemode.set"; } diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index 3e2206554..02fa957f2 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -10,6 +10,9 @@ citizens.commands.npc.age.cannot-be-aged=The mob type {0} cannot be aged. citizens.commands.npc.age.help=Can only be used on entities that can become babies. Use the [[-l]] flag to lock age over time (note: relogs may be required to see this). citizens.commands.npc.age.invalid-age=Invalid age. Valid ages are adult, baby, number between -24000 and 0 citizens.commands.npc.age.locked=Age locked. +citizens.commands.npc.gamemode.describe={0}'s gamemode is [[{1}]]. +citizens.commands.npc.gamemode.invalid={0} is not a valid gamemode. +citizens.commands.npc.gamemode.set=Gamemode set to [[{0}]]. citizens.commands.npc.age.set-adult=[[{0}]] is now an adult. citizens.commands.npc.age.set-baby=[[{0}]] is now a baby. citizens.commands.npc.age.set-normal=[[{0}]] is now age [[{1}]].