diff --git a/src/main/java/net/citizensnpcs/commands/NPCCommands.java b/src/main/java/net/citizensnpcs/commands/NPCCommands.java index 5b83090e7..1bf55bc76 100644 --- a/src/main/java/net/citizensnpcs/commands/NPCCommands.java +++ b/src/main/java/net/citizensnpcs/commands/NPCCommands.java @@ -1160,22 +1160,13 @@ public class NPCCommands { ambientSound = deathSound = hurtSound = null; } else { if (args.hasValueFlag("death")) { - deathSound = args.getFlag("death"); - if (deathSound.equals("d")) { - deathSound = null; - } + deathSound = args.getFlag("death").equals("d") ? null : NMS.getSound(args.getFlag("death")); } if (args.hasValueFlag("ambient")) { - ambientSound = args.getFlag("ambient"); - if (ambientSound.equals("d")) { - ambientSound = null; - } + ambientSound = args.getFlag("ambient").equals("d") ? null : NMS.getSound(args.getFlag("ambient")); } if (args.hasValueFlag("hurt")) { - hurtSound = args.getFlag("hurt"); - if (hurtSound.equals("d")) { - hurtSound = null; - } + hurtSound = args.getFlag("hurt").equals("d") ? null : NMS.getSound(args.getFlag("hurt")); } } npc.data().setPersistent(NPC.DEATH_SOUND_METADATA, deathSound); diff --git a/src/main/java/net/citizensnpcs/util/Messages.java b/src/main/java/net/citizensnpcs/util/Messages.java index 6ea2a8df6..5ef46b396 100644 --- a/src/main/java/net/citizensnpcs/util/Messages.java +++ b/src/main/java/net/citizensnpcs/util/Messages.java @@ -100,6 +100,7 @@ public class Messages { public static final String INVALID_POSE_NAME = "citizens.commands.npc.pose.invalid-name"; public static final String INVALID_PROFESSION = "citizens.commands.npc.profession.invalid-profession"; public static final String INVALID_SKELETON_TYPE = "citizens.commands.npc.skeletontype.invalid-type"; + public static final String INVALID_SOUND = "citizens.commands.npc.sound.invalid-sound"; public static final String INVALID_SPAWN_LOCATION = "citizens.commands.npc.create.invalid-location"; public static final String INVALID_TRIGGER_TELEPORT_FORMAT = "citizens.editors.waypoints.triggers.teleport.invalid-format"; public static final String ITEM_SET = "citizens.commands.npc.item.item-set"; diff --git a/src/main/java/net/citizensnpcs/util/NMS.java b/src/main/java/net/citizensnpcs/util/NMS.java index d86e25f68..6b602b78b 100644 --- a/src/main/java/net/citizensnpcs/util/NMS.java +++ b/src/main/java/net/citizensnpcs/util/NMS.java @@ -10,6 +10,7 @@ import java.util.Map; import java.util.Random; import java.util.WeakHashMap; +import net.citizensnpcs.api.command.exception.CommandException; import net.citizensnpcs.api.npc.NPC; import net.citizensnpcs.api.util.Messaging; import net.citizensnpcs.npc.entity.EntityHumanNPC; @@ -37,6 +38,8 @@ import net.minecraft.server.v1_7_R1.World; import org.apache.commons.lang.Validate; import org.bukkit.Bukkit; import org.bukkit.Location; +import org.bukkit.Sound; +import org.bukkit.craftbukkit.CraftSound; import org.bukkit.craftbukkit.v1_7_R1.CraftServer; import org.bukkit.craftbukkit.v1_7_R1.CraftWorld; import org.bukkit.craftbukkit.v1_7_R1.entity.CraftEntity; @@ -171,7 +174,7 @@ public class NMS { } private static Constructor getCustomEntityConstructor(Class clazz, EntityType type) throws SecurityException, - NoSuchMethodException { + NoSuchMethodException { Constructor constructor = ENTITY_CONSTRUCTOR_CACHE.get(clazz); if (constructor == null) { constructor = clazz.getConstructor(World.class); @@ -212,6 +215,17 @@ public class NMS { : handle instanceof EntityHumanNPC ? ((EntityHumanNPC) handle).getNavigation() : null; } + public static String getSound(String flag) throws CommandException { + try { + String ret = CraftSound.getSound(Sound.valueOf(flag.toUpperCase())); + if (ret == null) + throw new CommandException(Messages.INVALID_SOUND); + return ret; + } catch (Exception e) { + throw new CommandException(Messages.INVALID_SOUND); + } + } + public static float getSpeedFor(NPC npc) { if (!npc.isSpawned() || !(npc instanceof LivingEntity)) return DEFAULT_SPEED; @@ -505,9 +519,7 @@ public class NMS { private static Field NETWORK_ADDRESS = getField(NetworkManager.class, "l"); private static Field NETWORK_CHANNEL = getField(NetworkManager.class, "k"); private static final Location PACKET_CACHE_LOCATION = new Location(null, 0, 0, 0); - private static Field PATHFINDING_RANGE = getField(Navigation.class, "e"); - private static final Random RANDOM = Util.getFastRandom(); // true field above false and three synchronised lists diff --git a/src/main/resources/messages_en.properties b/src/main/resources/messages_en.properties index 1f9df2bba..5429c0c51 100644 --- a/src/main/resources/messages_en.properties +++ b/src/main/resources/messages_en.properties @@ -91,6 +91,7 @@ citizens.commands.npc.respawn.describe=Respawn delay is currently [[{0}]]. citizens.commands.npc.select.already-selected=You already have that NPC selected. citizens.commands.npc.size.description={0}''s size is [[{1}]]. citizens.commands.npc.size.set={0}''s size set to [[{1}]]. +citizens.commands.npc.sound.invalid-sound=Invalid sound. citizens.commands.npc.skeletontype.set={0}''s skeleton type set to [[{1}]]. 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.