mirror of
https://github.com/CitizensDev/Citizens2.git
synced 2024-11-23 19:16:34 +01:00
Better error message for non-numeric IDs with /npc spawn
This commit is contained in:
parent
63cc59c833
commit
dc1771d911
@ -4,6 +4,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import net.citizensnpcs.Citizens;
|
import net.citizensnpcs.Citizens;
|
||||||
import net.citizensnpcs.Settings.Setting;
|
import net.citizensnpcs.Settings.Setting;
|
||||||
@ -62,6 +63,7 @@ import org.bukkit.command.BlockCommandSender;
|
|||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.command.ConsoleCommandSender;
|
import org.bukkit.command.ConsoleCommandSender;
|
||||||
import org.bukkit.conversations.Conversable;
|
import org.bukkit.conversations.Conversable;
|
||||||
|
import org.bukkit.craftbukkit.v1_6_R3.entity.CraftEntity;
|
||||||
import org.bukkit.entity.Ageable;
|
import org.bukkit.entity.Ageable;
|
||||||
import org.bukkit.entity.Entity;
|
import org.bukkit.entity.Entity;
|
||||||
import org.bukkit.entity.EntityType;
|
import org.bukkit.entity.EntityType;
|
||||||
@ -933,6 +935,22 @@ public class NPCCommands {
|
|||||||
Messaging.sendTr(sender, Messages.PROFESSION_SET, npc.getName(), profession);
|
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(
|
@Command(
|
||||||
aliases = { "npc" },
|
aliases = { "npc" },
|
||||||
usage = "remove|rem (all)",
|
usage = "remove|rem (all)",
|
||||||
@ -1113,7 +1131,13 @@ public class NPCCommands {
|
|||||||
permission = "citizens.npc.spawn")
|
permission = "citizens.npc.spawn")
|
||||||
@Requirements(ownership = true)
|
@Requirements(ownership = true)
|
||||||
public void spawn(CommandContext args, CommandSender sender, NPC npc) throws CommandException {
|
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 (respawn == null) {
|
||||||
if (args.argsLength() > 1) {
|
if (args.argsLength() > 1) {
|
||||||
throw new CommandException(Messages.NO_NPC_WITH_ID_FOUND, args.getInteger(1));
|
throw new CommandException(Messages.NO_NPC_WITH_ID_FOUND, args.getInteger(1));
|
||||||
@ -1163,7 +1187,7 @@ public class NPCCommands {
|
|||||||
} else {
|
} else {
|
||||||
Player player = Bukkit.getPlayer(args.getFlag("target"));
|
Player player = Bukkit.getPlayer(args.getFlag("target"));
|
||||||
if (player != null)
|
if (player != null)
|
||||||
context.addRecipient(player);
|
context.addRecipient((Entity) player);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1383,4 +1407,10 @@ public class NPCCommands {
|
|||||||
npc.getName());
|
npc.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
long bits = UUID.randomUUID().getLeastSignificantBits();
|
||||||
|
int id = (int) (bits & 0x7FFFFFFF);
|
||||||
|
System.err.println(id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -181,6 +181,7 @@ public class Messages {
|
|||||||
public static final String SKIPPING_BROKEN_TRAIT = "citizens.notifications.skipping-broken-trait";
|
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_ANCHOR = "citizens.notifications.skipping-invalid-anchor";
|
||||||
public static final String SKIPPING_INVALID_POSE = "citizens.notifications.skipping-invalid-pose";
|
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_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 SPEED_MODIFIER_SET = "citizens.commands.npc.speed.set";
|
||||||
public static final String TARGETABLE_SET = "citizens.commands.npc.targetable.set";
|
public static final String TARGETABLE_SET = "citizens.commands.npc.targetable.set";
|
||||||
|
@ -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.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.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.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.spawn.spawned=You spawned [[{0}]].
|
||||||
citizens.commands.npc.speed.modifier-above-limit=Speed is above the limit.
|
citizens.commands.npc.speed.modifier-above-limit=Speed is above the limit.
|
||||||
citizens.commands.npc.speed.set=NPC speed modifier set to [[{0}]].
|
citizens.commands.npc.speed.set=NPC speed modifier set to [[{0}]].
|
||||||
|
Loading…
Reference in New Issue
Block a user