diff --git a/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/src/main/java/net/citizensnpcs/commands/NPCCommands.java index 4e485726e..f6452fbc8 100644 --- a/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -4,6 +4,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.List; +import java.util.UUID; import net.citizensnpcs.Citizens; import net.citizensnpcs.Settings.Setting; @@ -62,6 +63,7 @@ import org.bukkit.command.BlockCommandSender; import org.bukkit.command.CommandSender; import org.bukkit.command.ConsoleCommandSender; import org.bukkit.conversations.Conversable; +import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity; import org.bukkit.entity.Ageable; import org.bukkit.entity.Entity; import org.bukkit.entity.EntityType; @@ -933,6 +935,22 @@ public class NPCCommands { Messaging.sendTr(sender, Messages.PROFESSION_SET, npc.getName(), profession); } + @Command( + aliases = { "npc" }, + usage = "randommob [id]", + desc = "Sets randommob", + modifiers = { "randommob" }, + min = 2, + max = 2, + permission = "citizens.npc.randommob") + public void randommob(CommandContext args, CommandSender sender, NPC npc) { + UUID uuid = npc.getEntity().getUniqueId(); + UUID random = new UUID(uuid.getMostSignificantBits(), uuid.getLeastSignificantBits() + | (0x7FFFFFFF + args.getInteger(1))); + net.minecraft.server.v1_6_R3.Entity e = ((CraftEntity) npc.getEntity()).getHandle(); + e.uniqueID = random; + } + @Command( aliases = { "npc" }, usage = "remove|rem (all)", @@ -1113,7 +1131,13 @@ public class NPCCommands { permission = "citizens.npc.spawn") @Requirements(ownership = true) public void spawn(CommandContext args, CommandSender sender, NPC npc) throws CommandException { - NPC respawn = args.argsLength() > 1 ? npcRegistry.getById(args.getInteger(1)) : npc; + NPC respawn = null; + try { + respawn = args.argsLength() > 1 ? npcRegistry.getById(args.getInteger(1)) : npc; + } catch (NumberFormatException ex) { + Messaging.sendTr(sender, Messages.SPAWN_NUMERIC_ID_ONLY); + return; + } if (respawn == null) { if (args.argsLength() > 1) { throw new CommandException(Messages.NO_NPC_WITH_ID_FOUND, args.getInteger(1)); @@ -1163,7 +1187,7 @@ public class NPCCommands { } else { Player player = Bukkit.getPlayer(args.getFlag("target")); if (player != null) - context.addRecipient(player); + context.addRecipient((Entity) player); } } @@ -1383,4 +1407,10 @@ public class NPCCommands { npc.getName()); } } + + public static void main(String[] args) { + long bits = UUID.randomUUID().getLeastSignificantBits(); + int id = (int) (bits & 0x7FFFFFFF); + System.err.println(id); + } } diff --git a/src/main/java/net/citizensnpcs/util/Messages.java b/src/main/java/net/citizensnpcs/util/Messages.java index 513311692..e2a677dd5 100644 --- a/src/main/java/net/citizensnpcs/util/Messages.java +++ b/src/main/java/net/citizensnpcs/util/Messages.java @@ -181,6 +181,7 @@ public class Messages { public static final String SKIPPING_BROKEN_TRAIT = "citizens.notifications.skipping-broken-trait"; public static final String SKIPPING_INVALID_ANCHOR = "citizens.notifications.skipping-invalid-anchor"; public static final String SKIPPING_INVALID_POSE = "citizens.notifications.skipping-invalid-pose"; + public static final String SPAWN_NUMERIC_ID_ONLY = "citizens.commands.npc.spawn.numeric-id-only"; public static final String SPEED_MODIFIER_ABOVE_LIMIT = "citizens.commands.npc.speed.modifier-above-limit"; public static final String SPEED_MODIFIER_SET = "citizens.commands.npc.speed.set"; public static final String TARGETABLE_SET = "citizens.commands.npc.targetable.set"; diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index c13ca6e10..63e6720bf 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -92,6 +92,7 @@ citizens.commands.npc.skeletontype.invalid-type=Invalid skeleton type. citizens.commands.npc.spawn.already-spawned=[[{0}]] is already spawned at another location. Use ''/npc tphere'' to teleport the NPC to your location. citizens.commands.npc.spawn.missing-npc-id=No NPC with the ID {0} exists. citizens.commands.npc.spawn.no-location=No stored location available - command must be used ingame. +citizens.commands.npc.spawn.numeric-id-only=Only numeric IDs can be used for /npc spawn. citizens.commands.npc.spawn.spawned=You spawned [[{0}]]. citizens.commands.npc.speed.modifier-above-limit=Speed is above the limit. citizens.commands.npc.speed.set=NPC speed modifier set to [[{0}]].