Tweak /npc sound command to allow arbitrary sounds (as long as they are registered with NMS)
This commit is contained in:
parent
ad023c3bd5
commit
6d5f881b91
|
@ -19,6 +19,7 @@ import org.bukkit.GameMode;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.OfflinePlayer;
|
import org.bukkit.OfflinePlayer;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.block.BlockFace;
|
import org.bukkit.block.BlockFace;
|
||||||
|
@ -2884,8 +2885,8 @@ public class NPCCommands {
|
||||||
max = 1,
|
max = 1,
|
||||||
permission = "citizens.npc.sound")
|
permission = "citizens.npc.sound")
|
||||||
@Requirements(selected = true, ownership = true, livingEntity = true)
|
@Requirements(selected = true, ownership = true, livingEntity = true)
|
||||||
public void sound(CommandContext args, CommandSender sender, NPC npc, @Flag("death") String death,
|
public void sound(CommandContext args, CommandSender sender, NPC npc, @Flag("death") Sound death,
|
||||||
@Flag("ambient") String ambient, @Flag("hurt") String hurt) throws CommandException {
|
@Flag("ambient") Sound ambient, @Flag("hurt") Sound hurt) throws CommandException {
|
||||||
String ambientSound = npc.data().get(NPC.Metadata.AMBIENT_SOUND);
|
String ambientSound = npc.data().get(NPC.Metadata.AMBIENT_SOUND);
|
||||||
String deathSound = npc.data().get(NPC.Metadata.DEATH_SOUND);
|
String deathSound = npc.data().get(NPC.Metadata.DEATH_SOUND);
|
||||||
String hurtSound = npc.data().get(NPC.Metadata.HURT_SOUND);
|
String hurtSound = npc.data().get(NPC.Metadata.HURT_SOUND);
|
||||||
|
@ -2906,13 +2907,21 @@ public class NPCCommands {
|
||||||
npc.data().setPersistent(NPC.Metadata.SILENT, false);
|
npc.data().setPersistent(NPC.Metadata.SILENT, false);
|
||||||
} else {
|
} else {
|
||||||
if (death != null) {
|
if (death != null) {
|
||||||
deathSound = death.equals("d") ? null : NMS.getSound(death);
|
deathSound = NMS.getSoundPath(death);
|
||||||
|
} else if (args.hasValueFlag("death")) {
|
||||||
|
deathSound = args.getFlag("death").equals("d") ? null : args.getFlag("death");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ambient != null) {
|
if (ambient != null) {
|
||||||
ambientSound = ambient.equals("d") ? null : NMS.getSound(ambient);
|
ambientSound = NMS.getSoundPath(ambient);
|
||||||
|
} else if (args.hasValueFlag("ambient")) {
|
||||||
|
ambientSound = args.getFlag("ambient").equals("d") ? null : args.getFlag("ambient");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hurt != null) {
|
if (hurt != null) {
|
||||||
hurtSound = hurt.equals("d") ? null : NMS.getSound(hurt);
|
hurtSound = NMS.getSoundPath(hurt);
|
||||||
|
} else if (args.hasValueFlag("hurt")) {
|
||||||
|
hurtSound = args.getFlag("hurt").equals("d") ? null : args.getFlag("hurt");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (deathSound == null) {
|
if (deathSound == null) {
|
||||||
|
|
|
@ -14,6 +14,7 @@ import java.util.stream.Collectors;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.attribute.Attribute;
|
import org.bukkit.attribute.Attribute;
|
||||||
import org.bukkit.attribute.AttributeInstance;
|
import org.bukkit.attribute.AttributeInstance;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
|
@ -526,8 +527,8 @@ public class NMS {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getSound(String flag) throws CommandException {
|
public static String getSoundPath(Sound flag) throws CommandException {
|
||||||
return BRIDGE.getSound(flag);
|
return BRIDGE.getSoundPath(flag);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Entity getSource(BlockCommandSender sender) {
|
public static Entity getSource(BlockCommandSender sender) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Sound;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.block.Block;
|
import org.bukkit.block.Block;
|
||||||
import org.bukkit.command.BlockCommandSender;
|
import org.bukkit.command.BlockCommandSender;
|
||||||
|
@ -95,7 +96,7 @@ public interface NMSBridge {
|
||||||
|
|
||||||
public GameProfile getProfile(SkullMeta meta);
|
public GameProfile getProfile(SkullMeta meta);
|
||||||
|
|
||||||
public String getSound(String flag) throws CommandException;
|
public String getSoundPath(Sound flag) throws CommandException;
|
||||||
|
|
||||||
public Entity getSource(BlockCommandSender sender);
|
public Entity getSource(BlockCommandSender sender);
|
||||||
|
|
||||||
|
|
|
@ -572,9 +572,9 @@ public class NMSImpl implements NMSBridge {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSound(String flag) throws CommandException {
|
public String getSoundPath(Sound flag) throws CommandException {
|
||||||
try {
|
try {
|
||||||
String ret = CraftSound.getSound(Sound.valueOf(flag.toUpperCase()));
|
String ret = CraftSound.getSound(flag);
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
throw new CommandException(Messages.INVALID_SOUND);
|
throw new CommandException(Messages.INVALID_SOUND);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -592,9 +592,9 @@ public class NMSImpl implements NMSBridge {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSound(String flag) throws CommandException {
|
public String getSoundPath(Sound flag) throws CommandException {
|
||||||
try {
|
try {
|
||||||
String ret = CraftSound.getSound(Sound.valueOf(flag.toUpperCase()));
|
String ret = CraftSound.getSound(flag);
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
throw new CommandException(Messages.INVALID_SOUND);
|
throw new CommandException(Messages.INVALID_SOUND);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -592,9 +592,9 @@ public class NMSImpl implements NMSBridge {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSound(String flag) throws CommandException {
|
public String getSoundPath(Sound flag) throws CommandException {
|
||||||
try {
|
try {
|
||||||
String ret = CraftSound.getSound(Sound.valueOf(flag.toUpperCase()));
|
String ret = CraftSound.getSound(flag);
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
throw new CommandException(Messages.INVALID_SOUND);
|
throw new CommandException(Messages.INVALID_SOUND);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -620,9 +620,9 @@ public class NMSImpl implements NMSBridge {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSound(String flag) throws CommandException {
|
public String getSoundPath(Sound flag) throws CommandException {
|
||||||
try {
|
try {
|
||||||
String ret = CraftSound.getSound(Sound.valueOf(flag.toUpperCase()));
|
String ret = CraftSound.getSound(flag);
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
throw new CommandException(Messages.INVALID_SOUND);
|
throw new CommandException(Messages.INVALID_SOUND);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -655,9 +655,9 @@ public class NMSImpl implements NMSBridge {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSound(String flag) throws CommandException {
|
public String getSoundPath(Sound flag) throws CommandException {
|
||||||
try {
|
try {
|
||||||
String ret = CraftSound.getSound(Sound.valueOf(flag.toUpperCase()));
|
String ret = CraftSound.getSound(flag);
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
throw new CommandException(Messages.INVALID_SOUND);
|
throw new CommandException(Messages.INVALID_SOUND);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -670,9 +670,9 @@ public class NMSImpl implements NMSBridge {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSound(String flag) throws CommandException {
|
public String getSoundPath(Sound flag) throws CommandException {
|
||||||
try {
|
try {
|
||||||
String ret = CraftSound.getSound(Sound.valueOf(flag.toUpperCase()));
|
String ret = CraftSound.getSound(flag);
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
throw new CommandException(Messages.INVALID_SOUND);
|
throw new CommandException(Messages.INVALID_SOUND);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -686,9 +686,8 @@ public class NMSImpl implements NMSBridge {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSound(String flag) throws CommandException {
|
public String getSoundPath(Sound sound) throws CommandException {
|
||||||
try {
|
try {
|
||||||
Sound sound = Sound.valueOf(flag.toUpperCase());
|
|
||||||
if (CRAFTSOUND_GETSOUND != null) {
|
if (CRAFTSOUND_GETSOUND != null) {
|
||||||
String ret = (String) CRAFTSOUND_GETSOUND.invoke(sound);
|
String ret = (String) CRAFTSOUND_GETSOUND.invoke(sound);
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
|
|
|
@ -695,10 +695,9 @@ public class NMSImpl implements NMSBridge {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSound(String flag) throws CommandException {
|
public String getSoundPath(Sound flag) throws CommandException {
|
||||||
try {
|
try {
|
||||||
Sound sound = Sound.valueOf(flag.toUpperCase());
|
SoundEvent effect = CraftSound.getSoundEffect(flag);
|
||||||
SoundEvent effect = CraftSound.getSoundEffect(sound);
|
|
||||||
if (effect == null)
|
if (effect == null)
|
||||||
throw new CommandException(Messages.INVALID_SOUND);
|
throw new CommandException(Messages.INVALID_SOUND);
|
||||||
return effect.getLocation().getPath();
|
return effect.getLocation().getPath();
|
||||||
|
|
|
@ -702,10 +702,9 @@ public class NMSImpl implements NMSBridge {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSound(String flag) throws CommandException {
|
public String getSoundPath(Sound flag) throws CommandException {
|
||||||
try {
|
try {
|
||||||
Sound sound = Sound.valueOf(flag.toUpperCase());
|
SoundEvent effect = CraftSound.getSoundEffect(flag);
|
||||||
SoundEvent effect = CraftSound.getSoundEffect(sound);
|
|
||||||
if (effect == null)
|
if (effect == null)
|
||||||
throw new CommandException(Messages.INVALID_SOUND);
|
throw new CommandException(Messages.INVALID_SOUND);
|
||||||
return effect.getLocation().getPath();
|
return effect.getLocation().getPath();
|
||||||
|
|
|
@ -735,10 +735,9 @@ public class NMSImpl implements NMSBridge {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSound(String flag) throws CommandException {
|
public String getSoundPath(Sound flag) throws CommandException {
|
||||||
try {
|
try {
|
||||||
Sound sound = Sound.valueOf(flag.toUpperCase());
|
SoundEvent effect = CraftSound.getSoundEffect(flag);
|
||||||
SoundEvent effect = CraftSound.getSoundEffect(sound);
|
|
||||||
if (effect == null)
|
if (effect == null)
|
||||||
throw new CommandException(Messages.INVALID_SOUND);
|
throw new CommandException(Messages.INVALID_SOUND);
|
||||||
return effect.getLocation().getPath();
|
return effect.getLocation().getPath();
|
||||||
|
|
|
@ -734,10 +734,9 @@ public class NMSImpl implements NMSBridge {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSound(String flag) throws CommandException {
|
public String getSoundPath(Sound flag) throws CommandException {
|
||||||
try {
|
try {
|
||||||
Sound sound = Sound.valueOf(flag.toUpperCase());
|
SoundEvent effect = CraftSound.getSoundEffect(flag);
|
||||||
SoundEvent effect = CraftSound.getSoundEffect(sound);
|
|
||||||
if (effect == null)
|
if (effect == null)
|
||||||
throw new CommandException(Messages.INVALID_SOUND);
|
throw new CommandException(Messages.INVALID_SOUND);
|
||||||
return effect.getLocation().getPath();
|
return effect.getLocation().getPath();
|
||||||
|
|
|
@ -520,9 +520,9 @@ public class NMSImpl implements NMSBridge {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getSound(String flag) throws CommandException {
|
public String getSoundPath(Sound flag) throws CommandException {
|
||||||
try {
|
try {
|
||||||
String ret = CraftSound.getSound(Sound.valueOf(flag.toUpperCase()));
|
String ret = CraftSound.getSound(flag);
|
||||||
if (ret == null)
|
if (ret == null)
|
||||||
throw new CommandException(Messages.INVALID_SOUND);
|
throw new CommandException(Messages.INVALID_SOUND);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
Loading…
Reference in New Issue