2013-11-22 21:10:20 +01:00
|
|
|
package me.libraryaddict.disguise.utilities;
|
2013-05-29 00:29:36 +02:00
|
|
|
|
2016-01-22 06:41:45 +01:00
|
|
|
import org.bukkit.Sound;
|
|
|
|
|
2013-05-29 00:29:36 +02:00
|
|
|
import java.util.HashMap;
|
|
|
|
import java.util.HashSet;
|
|
|
|
|
2013-11-14 21:10:35 +01:00
|
|
|
/**
|
|
|
|
* Only living disguises go in here!
|
|
|
|
*/
|
2013-05-29 00:29:36 +02:00
|
|
|
public enum DisguiseSound {
|
|
|
|
|
2016-03-14 05:55:36 +01:00
|
|
|
//TODO: Sounds need to be updated to reflect new 1.9 sounds... oh god...
|
2015-08-03 00:39:44 +02:00
|
|
|
ARROW(null, null, null, null, "random.bowhit"),
|
2016-03-10 06:44:11 +01:00
|
|
|
BAT("entity.bat.hurt", null, "entity.bat.death", "entity.bat.idle", "damage.fallsmall", "entity.bat.loop", "damage.fallbig",
|
|
|
|
"entity.bat.takeoff"),
|
|
|
|
BLAZE("entity.blaze.hit", null, "entity.blaze.death", "entity.blaze.breathe", "damage.fallsmall", "damage.fallbig"),
|
|
|
|
CAVE_SPIDER("entity.spider.ambient", "entity.spider.step", "entity.spider.death", "entity.spider.ambient"),
|
|
|
|
CHICKEN("entity.chicken.hurt", "entity.chicken.step", "entity.chicken.hurt", "entity.chicken.ambient", "damage.fallsmall",
|
|
|
|
"entity.chicken.plop", "damage.fallbig"),
|
|
|
|
COW("entity.cow.hurt", "entity.cow.step", "entity.cow.hurt", "entity.cow.ambient"),
|
|
|
|
CREEPER("entity.creeper.ambient", "step.grass", "entity.creeper.death", null),
|
|
|
|
DONKEY("entity.horse.donkey.hit", "step.grass", "entity.horse.donkey.death", "entity.horse.donkey.idle", "entity.horse.gallop",
|
|
|
|
"entity.horse.leather", "entity.horse.donkey.angry", "entity.horse.wood", "entity.horse.armor", "entity.horse.soft",
|
|
|
|
"entity.horse.land", "entity.horse.jump", "entity.horse.angry"),
|
|
|
|
ELDER_GUARDIAN("entity.guardian.elder.hit", null, "entity.guardian.elder.death", "entity.guardian.elder.death"),
|
|
|
|
ENDER_DRAGON("entity.enderdragon.hit", null, "entity.enderdragon.end", "entity.enderdragon.growl", "damage.fallsmall",
|
|
|
|
"entity.enderdragon.wings", "damage.fallbig"),
|
2016-03-14 05:55:36 +01:00
|
|
|
ENDERMAN("entity.endermen.hit", "step.grass", "entity.endermen.death", "entity.endermen.idle", "entity.endermen.scream",
|
|
|
|
"entity.endermen.portal", "entity.endermen.stare"),
|
2016-03-10 06:44:11 +01:00
|
|
|
ENDERMITE("entity.silverfish.hit", "entity.silverfish.step", "entity.silverfish.kill", "entity.silverfish.ambient"),
|
|
|
|
GHAST("entity.ghast.scream", null, "entity.ghast.death", "entity.ghast.moan", "damage.fallsmall", "entity.ghast.fireball",
|
|
|
|
"damage.fallbig", "entity.ghast.affectionate_scream", "entity.ghast.charge"),
|
2013-11-22 15:15:26 +01:00
|
|
|
GIANT("damage.hit", "step.grass", null, null),
|
2016-03-10 06:44:11 +01:00
|
|
|
GUARDIAN("entity.guardian.hit", null, "entity.guardian.death", "entity.guardian.death"),
|
|
|
|
HORSE("entity.horse.hit", "step.grass", "entity.horse.death", "entity.horse.idle", "entity.horse.gallop", "entity.horse.leather",
|
|
|
|
"entity.horse.wood", "entity.horse.armor", "entity.horse.soft", "entity.horse.land", "entity.horse.jump", "entity.horse.angry",
|
|
|
|
"entity.horse.leather"),
|
|
|
|
IRON_GOLEM("entity.irongolem.hit", "entity.irongolem.walk", "entity.irongolem.death", "entity.irongolem.throw"),
|
|
|
|
MAGMA_CUBE("entity.slime.attack", "entity.slime.big", null, null, "entity.slime.small"),
|
|
|
|
MULE("entity.horse.donkey.hit", "step.grass", "entity.horse.donkey.death", "entity.horse.donkey.idle"),
|
|
|
|
MUSHROOM_COW("entity.cow.hurt", "entity.cow.step", "entity.cow.hurt", "entity.cow.ambient"),
|
|
|
|
OCELOT("entity.cat.hitt", "step.grass", "entity.cat.hitt", "entity.cat.meow", "entity.cat.purreow", "entity.cat.purr"),
|
|
|
|
PIG("entity.pig.ambient", "entity.pig.step", "entity.pig.death", "entity.pig.ambient"),
|
|
|
|
PIG_ZOMBIE("entity.zombiepig.zpighurt", null, "entity.zombiepig.zpigdeath", "entity.zombiepig.zpig", "entity.zombiepig.zpigangry"),
|
2016-03-14 05:55:36 +01:00
|
|
|
PLAYER("entity.player.hurt", "step.grass", "entity.player.hurt", null),
|
2016-03-10 06:44:11 +01:00
|
|
|
RABBIT("entity.rabbit.hurt", "entity.rabbit.hop", "entity.rabbit.death", "entity.rabbit.idle"),
|
|
|
|
SHEEP("entity.sheep.ambient", "entity.sheep.step", null, "entity.sheep.ambient", "entity.sheep.shear"),
|
2016-03-05 03:02:39 +01:00
|
|
|
SHULKER("entity.shulker.hurt", null, "entity.shulker.death", "entity.shulker.ambient", "entity.shulker.open",
|
|
|
|
"entity.shulker.hurt_closed", "entity.shulker.close", "entity.shulker.teleport", "entity.shulker_bullet.hit",
|
|
|
|
"entity.shulker_bullet.hurt"),
|
2016-03-10 06:44:11 +01:00
|
|
|
SILVERFISH("entity.silverfish.hit", "entity.silverfish.step", "entity.silverfish.kill", "entity.silverfish.ambient"),
|
|
|
|
SKELETON("entity.skeleton.hurt", "entity.skeleton.step", "entity.skeleton.death", "entity.skeleton.ambient"),
|
|
|
|
SKELETON_HORSE("entity.horse.skeleton.hit", "step.grass", "entity.horse.skeleton.death", "entity.horse.skeleton.idle",
|
|
|
|
"entity.horse.gallop", "entity.horse.leather", "entity.horse.wood", "entity.horse.armor", "entity.horse.soft", "entity.horse.land",
|
|
|
|
"entity.horse.jump", "entity.horse.angry"),
|
|
|
|
SLIME("entity.slime.attack", "entity.slime.big", null, null, "entity.slime.small"),
|
2013-07-29 04:53:32 +02:00
|
|
|
SNOWMAN(),
|
2016-03-10 06:44:11 +01:00
|
|
|
SPIDER("entity.spider.ambient", "entity.spider.step", "entity.spider.death", "entity.spider.ambient"),
|
2013-07-29 04:53:32 +02:00
|
|
|
SQUID(),
|
2016-03-10 06:44:11 +01:00
|
|
|
UNDEAD_HORSE("entity.horse.zombie.hit", "step.grass", "entity.horse.zombie.death", "entity.horse.zombie.idle", "entity.horse.gallop",
|
|
|
|
"entity.horse.leather", "entity.horse.wood", "entity.horse.armor", "entity.horse.soft", "entity.horse.land", "entity.horse.jump",
|
|
|
|
"entity.horse.angry"),
|
|
|
|
VILLAGER("entity.villager.hit", null, "entity.villager.death", "entity.villager.idle", "entity.villager.haggle", "entity.villager.no",
|
|
|
|
"entity.villager.yes"),
|
|
|
|
WITCH("entity.witch.hurt", null, "entity.witch.death", "entity.witch.idle"),
|
|
|
|
WITHER("entity.wither.hurt", null, "entity.wither.death", "entity.wither.idle", "damage.fallsmall", "entity.wither.spawn",
|
|
|
|
"damage.fallbig", "entity.wither.shoot"),
|
|
|
|
WITHER_SKELETON("entity.skeleton.hurt", "entity.skeleton.step", "entity.skeleton.death", "entity.skeleton.ambient"),
|
|
|
|
WOLF("entity.wolf.hurt", "entity.wolf.step", "entity.wolf.death", "entity.wolf.bark", "entity.wolf.panting", "entity.wolf.whine",
|
|
|
|
"entity.wolf.howl", "entity.wolf.growl", "entity.wolf.shake"),
|
|
|
|
ZOMBIE("entity.zombie.hurt", "entity.zombie.step", "entity.zombie.death", "entity.zombie.ambient", "entity.zombie.infect",
|
|
|
|
"entity.zombie.break_wood_door", "entity.zombie.attack_wood_door", "entity.zombie.break_wood_door"),
|
|
|
|
ZOMBIE_VILLAGER("entity.zombie.hurt", "entity.zombie.step", "entity.zombie.death", "entity.zombie.ambient", "entity.zombie.infect",
|
|
|
|
"entity.zombie.break_wood_door", "entity.zombie.attack_wood_door", "entity.zombie.break_wood_door");
|
2013-05-29 02:27:58 +02:00
|
|
|
|
2013-05-29 00:29:36 +02:00
|
|
|
public enum SoundType {
|
2016-01-22 06:41:45 +01:00
|
|
|
CANCEL, DEATH, HURT, IDLE, STEP
|
2013-05-29 00:52:54 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public static DisguiseSound getType(String name) {
|
|
|
|
try {
|
|
|
|
return valueOf(name);
|
|
|
|
} catch (Exception ex) {
|
|
|
|
return null;
|
|
|
|
}
|
2013-05-29 00:29:36 +02:00
|
|
|
}
|
|
|
|
|
2015-05-30 15:34:38 +02:00
|
|
|
private HashSet<String> cancelSounds = new HashSet<>();
|
2013-07-22 15:31:11 +02:00
|
|
|
private float damageSoundVolume = 1F;
|
2015-05-30 15:34:38 +02:00
|
|
|
private HashMap<SoundType, String> disguiseSounds = new HashMap<>();
|
2013-05-29 00:52:54 +02:00
|
|
|
|
2016-01-22 06:41:45 +01:00
|
|
|
DisguiseSound(Object... sounds) {
|
2013-05-29 00:29:36 +02:00
|
|
|
for (int i = 0; i < sounds.length; i++) {
|
2013-07-22 15:31:11 +02:00
|
|
|
Object obj = sounds[i];
|
|
|
|
String s;
|
2015-08-03 00:39:44 +02:00
|
|
|
if (obj == null) {
|
2013-07-22 15:31:11 +02:00
|
|
|
continue;
|
2015-08-03 00:39:44 +02:00
|
|
|
} else if (obj instanceof String) {
|
2013-07-22 15:31:11 +02:00
|
|
|
s = (String) obj;
|
2013-11-22 15:15:26 +01:00
|
|
|
} else if (obj instanceof Sound) {
|
2013-11-18 12:49:04 +01:00
|
|
|
s = ReflectionManager.getCraftSound((Sound) obj);
|
2014-04-04 07:30:20 +02:00
|
|
|
System.out.print("Warning! The sound " + obj + " needs to be converted to a string");
|
2013-11-22 15:15:26 +01:00
|
|
|
} else {
|
2013-07-22 15:31:11 +02:00
|
|
|
throw new RuntimeException("Was given a unknown object " + obj);
|
2013-11-22 15:15:26 +01:00
|
|
|
}
|
2013-07-22 15:31:11 +02:00
|
|
|
switch (i) {
|
2015-08-03 00:39:44 +02:00
|
|
|
case 0:
|
|
|
|
disguiseSounds.put(SoundType.HURT, s);
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
disguiseSounds.put(SoundType.STEP, s);
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
disguiseSounds.put(SoundType.DEATH, s);
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
disguiseSounds.put(SoundType.IDLE, s);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
cancelSounds.add(s);
|
|
|
|
break;
|
2013-07-22 15:31:11 +02:00
|
|
|
}
|
2013-05-29 00:29:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-18 20:39:23 +01:00
|
|
|
public float getDamageAndIdleSoundVolume() {
|
2013-07-22 15:31:11 +02:00
|
|
|
return damageSoundVolume;
|
|
|
|
}
|
|
|
|
|
|
|
|
public String getSound(SoundType type) {
|
2015-08-03 00:39:44 +02:00
|
|
|
if (type == null || !disguiseSounds.containsKey(type)) {
|
2013-05-29 00:29:36 +02:00
|
|
|
return null;
|
2015-08-03 00:39:44 +02:00
|
|
|
}
|
2013-05-29 00:29:36 +02:00
|
|
|
return disguiseSounds.get(type);
|
|
|
|
}
|
|
|
|
|
2013-07-22 15:31:11 +02:00
|
|
|
public HashSet<String> getSoundsToCancel() {
|
2013-05-29 00:29:36 +02:00
|
|
|
return cancelSounds;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2013-05-29 19:17:48 +02:00
|
|
|
* Used to check if this sound name is owned by this disguise sound.
|
2013-05-29 00:29:36 +02:00
|
|
|
*/
|
2013-07-28 01:00:43 +02:00
|
|
|
public SoundType getType(String sound, boolean ignoreDamage) {
|
2016-03-05 03:02:39 +01:00
|
|
|
if (sound == null) return SoundType.CANCEL;
|
2015-08-03 00:39:44 +02:00
|
|
|
if (isCancelSound(sound)) {
|
2013-05-29 00:29:36 +02:00
|
|
|
return SoundType.CANCEL;
|
2015-08-03 00:39:44 +02:00
|
|
|
}
|
2013-07-22 16:06:19 +02:00
|
|
|
if (disguiseSounds.containsKey(SoundType.STEP) && disguiseSounds.get(SoundType.STEP).startsWith("step.")
|
2015-08-03 00:39:44 +02:00
|
|
|
&& sound.startsWith("step.")) {
|
2013-05-29 00:29:36 +02:00
|
|
|
return SoundType.STEP;
|
2015-08-03 00:39:44 +02:00
|
|
|
}
|
2013-05-29 02:27:58 +02:00
|
|
|
for (SoundType type : SoundType.values()) {
|
2015-08-03 00:39:44 +02:00
|
|
|
if (!disguiseSounds.containsKey(type) || type == SoundType.DEATH || (ignoreDamage && type == SoundType.HURT)) {
|
2013-05-29 02:27:58 +02:00
|
|
|
continue;
|
2015-08-03 00:39:44 +02:00
|
|
|
}
|
2013-07-22 15:31:11 +02:00
|
|
|
String s = disguiseSounds.get(type);
|
2013-05-29 20:20:50 +02:00
|
|
|
if (s != null) {
|
2015-08-03 00:39:44 +02:00
|
|
|
if (s.equals(sound)) {
|
2013-05-29 00:29:36 +02:00
|
|
|
return type;
|
2015-08-03 00:39:44 +02:00
|
|
|
}
|
2013-05-29 20:20:50 +02:00
|
|
|
}
|
2013-05-29 00:29:36 +02:00
|
|
|
}
|
|
|
|
return null;
|
|
|
|
}
|
2013-05-29 21:12:08 +02:00
|
|
|
|
|
|
|
public boolean isCancelSound(String sound) {
|
2013-07-22 15:31:11 +02:00
|
|
|
return getSoundsToCancel().contains(sound);
|
2013-05-29 21:12:08 +02:00
|
|
|
}
|
2013-07-22 16:18:34 +02:00
|
|
|
|
2013-07-29 01:19:59 +02:00
|
|
|
public void removeSound(SoundType type, Sound sound) {
|
2013-11-18 12:49:04 +01:00
|
|
|
removeSound(type, ReflectionManager.getCraftSound(sound));
|
2013-07-29 01:19:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void removeSound(SoundType type, String sound) {
|
2015-08-03 00:39:44 +02:00
|
|
|
if (type == SoundType.CANCEL) {
|
2013-07-29 01:19:59 +02:00
|
|
|
cancelSounds.remove(sound);
|
2015-08-03 00:39:44 +02:00
|
|
|
} else {
|
2013-07-29 01:19:59 +02:00
|
|
|
disguiseSounds.remove(type);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-18 20:39:23 +01:00
|
|
|
public void setDamageAndIdleSoundVolume(float strength) {
|
2013-07-22 16:18:34 +02:00
|
|
|
this.damageSoundVolume = strength;
|
|
|
|
}
|
2013-07-29 01:19:59 +02:00
|
|
|
|
|
|
|
public void setSound(SoundType type, Sound sound) {
|
2013-11-18 12:49:04 +01:00
|
|
|
setSound(type, ReflectionManager.getCraftSound(sound));
|
2013-07-29 01:19:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public void setSound(SoundType type, String sound) {
|
2015-08-03 00:39:44 +02:00
|
|
|
if (type == SoundType.CANCEL) {
|
2013-07-29 01:19:59 +02:00
|
|
|
cancelSounds.add(sound);
|
2015-08-03 00:39:44 +02:00
|
|
|
} else {
|
2013-07-29 01:19:59 +02:00
|
|
|
disguiseSounds.put(type, sound);
|
|
|
|
}
|
|
|
|
}
|
2013-05-29 00:29:36 +02:00
|
|
|
}
|