LibsDisguises/src/me/libraryaddict/disguise/utilities/DisguiseSound.java

353 lines
15 KiB
Java
Raw Normal View History

package me.libraryaddict.disguise.utilities;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Objects;
import org.bukkit.Sound;
/**
* Only living disguises go in here!
*/
public enum DisguiseSound {
2017-06-23 23:21:34 +02:00
ARROW(null, null, null, null, "entity.arrow.hit", "entity.arrow.shoot"),
2017-06-23 23:21:34 +02:00
BAT("entity.bat.hurt", null, "entity.bat.death", "entity.bat.ambient", "entity.player.small_fall",
"entity.bat.loop", "entity.player.big_fall", "entity.bat.takeoff"),
2017-06-23 23:21:34 +02:00
BLAZE("entity.blaze.hurt", null, "entity.blaze.death", "entity.blaze.ambient", "entity.player.small_fall",
"entity.player.big_fall"),
2017-06-23 23:21:34 +02:00
CAVE_SPIDER("entity.spider.ambient", "entity.spider.step", "entity.spider.death", "entity.spider.ambient"),
2017-06-23 23:21:34 +02:00
CHICKEN("entity.chicken.hurt", "entity.chicken.step", "entity.chicken.hurt", "entity.chicken.ambient",
"entity.player.small_fall", "entity.chicken.egg", "entity.player.big_fall"),
2017-06-23 23:21:34 +02:00
COW("entity.cow.hurt", "entity.cow.step", "entity.cow.death", "entity.cow.ambient"),
2017-06-23 23:21:34 +02:00
CREEPER("entity.creeper.hurt", "block.grass.step", "entity.creeper.death", null, "entity.creeper.primed"),
2017-06-23 23:21:34 +02:00
DONKEY("entity.donkey.hurt", "block.grass.step", "entity.donkey.death", "entity.donkey.ambient",
"entity.horse.gallop", "entity.horse.saddle", "entity.donkey.angry", "entity.horse.step_wood",
"entity.horse.armor", "entity.horse.land", "entity.horse.jump", "entity.horse.angry"),
2017-06-23 23:21:34 +02:00
ELDER_GUARDIAN("entity.elder_guardian.hurt", null, "entity.elder_guardian.death", "entity.elder_guardian.ambient"),
2017-06-23 23:21:34 +02:00
ENDER_DRAGON("entity.enderdragon.hurt", null, "entity.enderdragon.death", "entity.enderdragon.ambient",
"entity.player.small_fall", "entity.enderdragon.flap", "entity.player.big_fall"),
2017-06-23 23:21:34 +02:00
ENDERMAN("entity.endermen.hurt", "block.grass.step", "entity.endermen.death", "entity.endermen.ambient",
"entity.endermen.scream", "entity.endermen.teleport", "entity.endermen.stare"),
2017-06-23 23:21:34 +02:00
ENDERMITE("entity.silverfish.hurt", "entity.endermite.step", "entity.endermite.death", "entity.endermite.ambient"),
2017-06-23 23:21:34 +02:00
EVOKER("entity.evocation_illager.hurt", null, "entity.evocation_illager.death", "entity.evocation_illager.ambient",
"entity.evocation_illager.cast_spell", "entity.evocation_illager.prepare_attack",
"entity.evocation_illager.prepare_summon", "entity.evocation_illager.prepare_wololo"),
2017-06-23 23:21:34 +02:00
EVOKER_FANGS(null, null, null, null, "entity.evocation_fangs.attack"),
2017-06-23 23:21:34 +02:00
GHAST("entity.ghast.hurt", null, "entity.ghast.death", "entity.ghast.ambient", "entity.player.small_fall",
"entity.ghast.shoot", "entity.player.big_fall", "entity.ghast.scream", "entity.ghast.warn"),
2017-06-23 23:21:34 +02:00
GIANT("entity.player.hurt", "block.grass.step", null, null),
2017-06-23 23:21:34 +02:00
GUARDIAN("entity.guardian.hurt", null, "entity.guardian.death", "entity.elder_guardian.ambient"),
2017-06-23 23:21:34 +02:00
HORSE("entity.horse.hurt", "block.grass.step", "entity.horse.death", "entity.horse.ambient", "entity.horse.gallop",
"entity.horse.saddle", "entity.donkey.angry", "entity.horse.step_wood", "entity.horse.armor",
"entity.horse.land", "entity.horse.jump", "entity.horse.angry"),
ILLUSIONER("entity.illusion_illager.hurt", null, "entity.illusion_illager.death", "entity.illusion_illager.ambient",
2017-06-23 23:21:34 +02:00
"entity.illusion_illager.cast_spell", "entity.illusion_illager.prepare_blindness",
"entity.illusion_illager.prepare_mirror", "entity.illusion_illager.mirror_move"),
2017-06-23 23:21:34 +02:00
IRON_GOLEM("entity.irongolem.hurt", "entity.irongolem.step", "entity.irongolem.death", "entity.irongolem.attack"),
2017-06-23 23:21:34 +02:00
LLAMA("entity.llama.hurt", "entity.llama.step", "entity.llama.death", "entity.llama.ambient", "entity.llama.angry",
"entity.llama.chest", "entity.llama.eat", "entity.llama.swag"),
2017-06-23 23:21:34 +02:00
MAGMA_CUBE("entity.magmacube.hurt", "entity.magmacube.jump", null, null),
2017-06-23 23:21:34 +02:00
MULE("entity.mule.hurt", "block.grass.step", "entity.mule.death", "entity.mule.ambient"),
2017-06-23 23:21:34 +02:00
MUSHROOM_COW("entity.cow.hurt", "entity.cow.step", "entity.cow.hurt", "entity.cow.ambient"),
2017-06-23 23:21:34 +02:00
OCELOT("entity.cat.hurt", "block.grass.step", "entity.cat.hurt", "entity.cat.ambient", "entity.cat.purr",
"entity.cat.purreow"),
PARROT("entity.parrot.hurt", "entity.parrot.step", "entity.parrot.death", "entity.parrot.ambient",
"entity.parrot.eat", "entity.parrot.fly", "entity.parrot.imitate.blaze", "entity.parrot.imitate.creeper",
"entity.parrot.imitate.elder_guardian", "entity.parrot.imitate.enderdragon",
"entity.parrot.imitate.enderman", "entity.parrot.imitate.endermite",
"entity.parrot.imitate.evocation_illager", "entity.parrot.imitate.ghast", "entity.parrot.imitate.husk",
"entity.parrot.imitate.illusion_illager", "entity.parrot.imitate.magmacube",
"entity.parrot.imitate.polar_bear", "entity.parrot.imitate.shulker", "entity.parrot.imitate.silverfish",
"entity.parrot.imitate.skeleton", "entity.parrot.imitate.slime", "entity.parrot.imitate.spider",
"entity.parrot.imitate.stray", "entity.parrot.imitate.vex", "entity.parrot.imitate.vindication_illager",
"entity.parrot.imitate.witch", "entity.parrot.imitate.wither", "entity.parrot.imitate.wither_skeleton",
"entity.parrot.imitate.wolf", "entity.parrot.imitate.zombie", "entity.parrot.imitate.zombie_pigman",
"entity.parrot.imitate.zombie_villager"),
2017-06-23 23:21:34 +02:00
PIG("entity.pig.hurt", "entity.pig.step", "entity.pig.death", "entity.pig.ambient"),
PIG_ZOMBIE("entity.zombie_pig.hurt", null, "entity.zombie_pig.death", "entity.zombie_pig.ambient",
"entity.zombie_pig.angry"),
2017-06-23 23:21:34 +02:00
PLAYER("entity.player.hurt", "block.stone.step", "block.grass.step", "block.anvil.step", "block.cloth.step",
"block.glass.step", "block.gravel.step", "block.ladder.step", "block.metal.step", "block.sand.step",
"block.slime.step", "block.snow.step", "block.wood.step", "entity.player.death", null),
2017-06-23 23:21:34 +02:00
RABBIT("entity.rabbit.hurt", "entity.rabbit.jump", "entity.rabbit.death", "entity.rabbit.ambient"),
2017-06-23 23:21:34 +02:00
SHEEP("entity.sheep.hurt", "entity.sheep.step", null, "entity.sheep.ambient", "entity.sheep.shear"),
2017-06-23 23:21:34 +02:00
SHULKER("entity.shulker.hurt", null, "entity.shulker.death", "entity.shulker.ambient", "entity.shulker.open",
"entity.shulker.close", "entity.shulker.hurt_closed", "entity.shulker.teleport"),
2017-06-23 23:21:34 +02:00
SILVERFISH("entity.silverfish.hurt", "entity.silverfish.step", "entity.silverfish.death",
"entity.silverfish.ambient"),
2017-06-23 23:21:34 +02:00
SKELETON("entity.skeleton.hurt", "entity.skeleton.step", "entity.skeleton.death", "entity.skeleton.ambient"),
2017-06-23 23:21:34 +02:00
SKELETON_HORSE("entity.skeleton_horse.hurt", "block.grass.step", "entity.skeleton_horse.death",
"entity.skeleton_horse.ambient", "entity.horse.gallop", "entity.horse.saddle", "entity.donkey.angry",
"entity.horse.step_wood", "entity.horse.armor", "entity.horse.land", "entity.horse.jump",
"entity.horse.angry"),
2017-06-23 23:21:34 +02:00
SLIME("entity.slime.hurt", "entity.slime.jump", "entity.slime.death", null),
2017-06-23 23:21:34 +02:00
SNOWMAN("entity.snowman.hurt", null, "entity.snowman.death", "entity.snowman.ambient", "entity.snowman.shoot"),
2017-06-23 23:21:34 +02:00
SPIDER("entity.spider.ambient", "entity.spider.step", "entity.spider.death", "entity.spider.ambient"),
2017-06-23 23:21:34 +02:00
SQUID("entity.squid.hurt", null, "entity.squid.death", "entity.squid.ambient"),
2017-06-23 23:21:34 +02:00
UNDEAD_HORSE("entity.zombie_horse.hurt", "block.grass.step", "entity.zombie_horse.death",
"entity.zombie_horse.ambient", "entity.horse.gallop", "entity.horse.saddle", "entity.donkey.angry",
"entity.horse.step_wood", "entity.horse.armor", "entity.horse.land", "entity.horse.jump",
"entity.horse.angry"),
2017-06-23 23:21:34 +02:00
VEX("entity.vex.hurt", null, "entity.vex.death", "entity.vex.ambient", "entity.vex.charge"),
2017-06-23 23:21:34 +02:00
VILLAGER("entity.villager.hurt", null, "entity.villager.death", "entity.villager.ambient",
"entity.villager.trading", "entity.villager.no", "entity.villager.yes"),
2017-06-23 23:21:34 +02:00
VINDICATOR("entity.vindication_illager.hurt", null, "entity.vindication_illager.death",
"entity.vindication_illager.ambient"),
2017-06-23 23:21:34 +02:00
WITCH("entity.witch.hurt", null, "entity.witch.death", "entity.witch.ambient"),
2017-06-23 23:21:34 +02:00
WITHER("entity.wither.hurt", null, "entity.wither.death", "entity.wither.ambient", "entity.player.small_fall",
"entity.wither.spawn", "entity.player.big_fall", "entity.wither.shoot"),
2017-06-23 23:21:34 +02:00
WITHER_SKELETON("entity.skeleton.hurt", "entity.skeleton.step", "entity.skeleton.death", "entity.skeleton.ambient"),
2017-06-23 23:21:34 +02:00
WOLF("entity.wolf.hurt", "entity.wolf.step", "entity.wolf.death", "entity.wolf.ambient", "entity.wolf.growl",
"entity.wolf.pant", "entity.wolf.howl", "entity.wolf.shake", "entity.wolf.whine"),
2017-06-23 23:21:34 +02:00
ZOMBIE("entity.zombie.hurt", "entity.zombie.step", "entity.zombie.death", "entity.zombie.ambient",
"entity.zombie.infect", "entity.zombie.break_door_wood", "entity.zombie.attack_door_wood",
"entity.zombie.attack_iron_door"),
2017-06-23 23:21:34 +02:00
ZOMBIE_VILLAGER("entity.zombie_villager.hurt", "entity.zombie_villager.step", "entity.zombie_villager.death",
"entity.zombie_villager.ambient", "entity.zombie.infect", "entity.zombie.break_door_wood",
"entity.zombie.attack_door_wood", "entity.zombie.attack_iron_door");
public enum SoundType {
2017-06-23 23:21:34 +02:00
CANCEL,
DEATH,
HURT,
IDLE,
STEP
}
public static DisguiseSound getType(String name) {
try {
return valueOf(name);
}
catch (Exception ex) {
return null;
}
}
private float damageSoundVolume = 1F;
private HashMap<Object, Object> disguiseSounds = new HashMap<>();
DisguiseSound(Object hurt, Object step, Object death, Object idle, Object... sounds) {
addSound(hurt, SoundType.HURT);
addSound(step, SoundType.STEP);
addSound(death, SoundType.DEATH);
addSound(idle, SoundType.IDLE);
for (Object obj : sounds) {
addSound(obj, SoundType.CANCEL);
}
}
DisguiseSound(Object hurt, Object[] step, Object death, Object idle, Object... sounds) {
addSound(hurt, SoundType.HURT);
if (step != null) {
for (Object obj : step) {
addSound(obj, SoundType.STEP);
}
}
addSound(death, SoundType.DEATH);
addSound(idle, SoundType.IDLE);
for (Object obj : sounds) {
addSound(obj, SoundType.CANCEL);
}
}
private void addSound(Object sound, SoundType type) {
String s;
if (sound == null) {
return;
2017-03-21 13:49:27 +01:00
} else if (sound instanceof String) {
s = (String) sound;
2017-03-21 13:49:27 +01:00
} else if (sound instanceof Sound) {
s = ReflectionManager.getCraftSound((Sound) sound);
2017-03-21 13:49:27 +01:00
} else {
throw new RuntimeException("Was given a unknown object " + sound);
}
switch (type) {
2017-03-21 13:49:27 +01:00
case HURT:
disguiseSounds.put(SoundType.HURT, s);
break;
case STEP:
disguiseSounds.put(s, SoundType.STEP);
break;
case DEATH:
disguiseSounds.put(SoundType.DEATH, s);
break;
case IDLE:
disguiseSounds.put(SoundType.IDLE, s);
break;
case CANCEL:
disguiseSounds.put(s, SoundType.CANCEL);
}
}
public float getDamageAndIdleSoundVolume() {
return damageSoundVolume;
}
public String getSound(SoundType type) {
if (type == null) {
return null;
}
if (disguiseSounds.containsKey(type)) {
return (String) disguiseSounds.get(type);
2017-03-21 13:49:27 +01:00
} else if (disguiseSounds.containsValue(type)) {
for (Entry<Object, Object> entry : disguiseSounds.entrySet()) {
if (entry.getValue() != type)
continue;
return (String) entry.getKey();
}
}
return null;
}
public SoundType getSound(String sound) {
if (sound == null) {
return null;
}
if (disguiseSounds.containsKey(sound)) {
return (SoundType) disguiseSounds.get(sound);
2017-03-21 13:49:27 +01:00
} else if (disguiseSounds.containsValue(sound)) {
for (Entry<Object, Object> entry : disguiseSounds.entrySet()) {
if (!Objects.equals(sound, entry.getValue()))
continue;
return (SoundType) entry.getKey();
}
}
return null;
}
/**
* Used to check if this sound name is owned by this disguise sound.
*/
public SoundType getType(String sound, boolean ignoreDamage) {
if (sound == null)
return SoundType.CANCEL;
if (isCancelSound(sound)) {
return SoundType.CANCEL;
}
/*if (disguiseSounds.containsKey(SoundType.STEP) && disguiseSounds.get(SoundType.STEP).startsWith("step.")
&& sound.startsWith("step.")) {
return SoundType.STEP;
}*/
for (SoundType type : SoundType.values()) {
2017-06-23 23:21:34 +02:00
if (!disguiseSounds
.containsKey(type) || type == SoundType.DEATH || (ignoreDamage && type == SoundType.HURT)) {
continue;
}
Object s = disguiseSounds.get(type);
if (s != null) {
if (Objects.equals(s, sound)) {
return type;
}
2017-03-21 13:49:27 +01:00
} else {
for (Entry<Object, Object> entry : disguiseSounds.entrySet()) {
if (!Objects.equals(sound, entry.getKey()))
continue;
return (SoundType) entry.getValue();
}
}
}
return null;
}
public boolean isCancelSound(String sound) {
return getSound(sound) == SoundType.CANCEL;
}
/* public void removeSound(SoundType type, Sound sound) {
removeSound(type, ReflectionManager.getCraftSound(sound));
}
2017-03-21 13:49:27 +01:00
public void removeSound(SoundType type, String sound) {
if (type == SoundType.CANCEL) {
cancelSounds.remove(sound);
}
else {
disguiseSounds.remove(type);
}
}*/
public void setDamageAndIdleSoundVolume(float strength) {
this.damageSoundVolume = strength;
}
/* public void setSound(SoundType type, Sound sound) {
setSound(type, ReflectionManager.getCraftSound(sound));
}
2017-03-21 13:49:27 +01:00
public void setSound(SoundType type, String sound) {
if (type == SoundType.CANCEL) {
cancelSounds.add(sound);
}
else {
disguiseSounds.put(type, sound);
}
}*/
}