Add new disguises, update metadata, change how sounds are stored and work, update item parsing message, added Pattern and DyeColor to parsables

This commit is contained in:
libraryaddict 2018-08-06 21:48:19 +12:00
parent f43ccb67d2
commit 39bbeec442
22 changed files with 709 additions and 450 deletions

View File

@ -7,6 +7,8 @@ import me.libraryaddict.disguise.commands.*;
import me.libraryaddict.disguise.disguisetypes.*; import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.disguisetypes.watchers.*; import me.libraryaddict.disguise.disguisetypes.watchers.*;
import me.libraryaddict.disguise.utilities.*; import me.libraryaddict.disguise.utilities.*;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.command.CommandExecutor; import org.bukkit.command.CommandExecutor;
import org.bukkit.command.PluginCommand; import org.bukkit.command.PluginCommand;
@ -16,6 +18,7 @@ import org.bukkit.plugin.java.JavaPlugin;
import java.io.File; import java.io.File;
import java.lang.reflect.Field; import java.lang.reflect.Field;
import java.lang.reflect.Modifier;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
@ -284,6 +287,13 @@ public class LibsDisguises extends JavaPlugin {
try { try {
switch (disguiseType) { switch (disguiseType) {
case ARROW:
watcherClass = TippedArrowWatcher.class;
break;
case COD:
case SALMON:
watcherClass = FishWatcher.class;
break;
case SPECTRAL_ARROW: case SPECTRAL_ARROW:
watcherClass = ArrowWatcher.class; watcherClass = ArrowWatcher.class;
break; break;
@ -291,8 +301,6 @@ public class LibsDisguises extends JavaPlugin {
watcherClass = TNTWatcher.class; watcherClass = TNTWatcher.class;
break; break;
case MINECART_CHEST: case MINECART_CHEST:
case MINECART_COMMAND:
case MINECART_FURNACE:
case MINECART_HOPPER: case MINECART_HOPPER:
case MINECART_MOB_SPAWNER: case MINECART_MOB_SPAWNER:
case MINECART_TNT: case MINECART_TNT:
@ -302,11 +310,9 @@ public class LibsDisguises extends JavaPlugin {
case CAVE_SPIDER: case CAVE_SPIDER:
watcherClass = SpiderWatcher.class; watcherClass = SpiderWatcher.class;
break; break;
case ZOMBIE_VILLAGER:
watcherClass = ZombieVillagerWatcher.class;
break;
case PIG_ZOMBIE: case PIG_ZOMBIE:
case HUSK: case HUSK:
case DROWNED:
watcherClass = ZombieWatcher.class; watcherClass = ZombieWatcher.class;
break; break;
case MAGMA_CUBE: case MAGMA_CUBE:
@ -323,6 +329,9 @@ public class LibsDisguises extends JavaPlugin {
case EVOKER: case EVOKER:
watcherClass = IllagerWizardWatcher.class; watcherClass = IllagerWizardWatcher.class;
break; break;
case PUFFERFISH:
watcherClass = PufferFishWatcher.class;
break;
default: default:
watcherClass = Class.forName( watcherClass = Class.forName(
"me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) + "me.libraryaddict.disguise.disguisetypes.watchers." + toReadable(disguiseType.name()) +
@ -343,6 +352,8 @@ public class LibsDisguises extends JavaPlugin {
watcherClass = InsentientWatcher.class; watcherClass = InsentientWatcher.class;
} else if (LivingEntity.class.isAssignableFrom(entityClass)) { } else if (LivingEntity.class.isAssignableFrom(entityClass)) {
watcherClass = LivingWatcher.class; watcherClass = LivingWatcher.class;
} else if (Fish.class.isAssignableFrom(entityClass)) {
watcherClass = FishWatcher.class;
} else { } else {
watcherClass = FlagWatcher.class; watcherClass = FlagWatcher.class;
} }
@ -363,34 +374,27 @@ public class LibsDisguises extends JavaPlugin {
} }
String nmsEntityName = toReadable(disguiseType.name()); String nmsEntityName = toReadable(disguiseType.name());
Class nmsClass = ReflectionManager.getNmsClassIgnoreErrors("Entity" + nmsEntityName);
if (nmsClass == null || Modifier.isAbstract(nmsClass.getModifiers())) {
String[] split = splitReadable(disguiseType.name());
ArrayUtils.reverse(split);
nmsEntityName = StringUtils.join(split);
nmsClass = ReflectionManager.getNmsClassIgnoreErrors("Entity" + nmsEntityName);
if (nmsClass == null || Modifier.isAbstract(nmsClass.getModifiers())) {
nmsEntityName = null;
}
}
if (nmsEntityName == null) {
switch (disguiseType) { switch (disguiseType) {
case WITHER_SKELETON:
case ZOMBIE_VILLAGER:
case DONKEY: case DONKEY:
case MULE: nmsEntityName = "HorseDonkey";
case ZOMBIE_HORSE:
case SKELETON_HORSE:
case STRAY:
case HUSK:
continue;
case PRIMED_TNT:
nmsEntityName = "TNTPrimed";
break; break;
case MINECART_TNT: case ARROW:
nmsEntityName = "MinecartTNT"; nmsEntityName = "TippedArrow";
break;
case MINECART:
nmsEntityName = "MinecartRideable";
break;
case FIREWORK:
nmsEntityName = "Fireworks";
break;
case SPLASH_POTION:
nmsEntityName = "Potion";
break;
case GIANT:
nmsEntityName = "GiantZombie";
break; break;
case DROPPED_ITEM: case DROPPED_ITEM:
nmsEntityName = "Item"; nmsEntityName = "Item";
@ -398,25 +402,59 @@ public class LibsDisguises extends JavaPlugin {
case FIREBALL: case FIREBALL:
nmsEntityName = "LargeFireball"; nmsEntityName = "LargeFireball";
break; break;
case LEASH_HITCH: case FIREWORK:
nmsEntityName = "Leash"; nmsEntityName = "Fireworks";
break; break;
case ELDER_GUARDIAN: case GIANT:
nmsEntityName = "Guardian"; nmsEntityName = "GiantZombie";
break; break;
case ARROW: case HUSK:
case SPECTRAL_ARROW: nmsEntityName = "ZombieHusk";
nmsEntityName = "TippedArrow";
break; break;
case ILLUSIONER: case ILLUSIONER:
nmsEntityName = "IllagerIllusioner"; nmsEntityName = "IllagerIllusioner";
break; break;
case LEASH_HITCH:
nmsEntityName = "Leash";
break;
case MINECART:
nmsEntityName = "MinecartRideable";
break;
case MINECART_COMMAND:
nmsEntityName = "MinecartCommandBlock";
break;
case MINECART_TNT:
nmsEntityName = "MinecartTNT";
break;
case MULE:
nmsEntityName = "HorseMule";
break;
case PRIMED_TNT:
nmsEntityName = "TNTPrimed";
break;
case PUFFERFISH:
nmsEntityName = "PufferFish";
break;
case SPLASH_POTION:
nmsEntityName = "Potion";
break;
case STRAY:
nmsEntityName = "SkeletonStray";
break;
case TRIDENT:
nmsEntityName = "ThrownTrident";
break;
default: default:
break; break;
} }
if (nmsEntityName != null) {
nmsClass = ReflectionManager.getNmsClass("Entity" + nmsEntityName);
}
}
try { try {
if (nmsEntityName.equalsIgnoreCase("Unknown")) { if (disguiseType == DisguiseType.UNKNOWN) {
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0, 0); DisguiseValues disguiseValues = new DisguiseValues(disguiseType, null, 0, 0);
disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0)); disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0));
@ -430,17 +468,21 @@ public class LibsDisguises extends JavaPlugin {
continue; continue;
} }
if (nmsEntityName == null) {
getLogger().warning("Entity name not found! (" + disguiseType.name() + ")");
continue;
}
Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName); Object nmsEntity = ReflectionManager.createEntityInstance(nmsEntityName);
if (nmsEntity == null) { if (nmsEntity == null) {
getLogger().warning("Entity not found! (" + nmsEntityName + ")"); getLogger().warning("Entity not found! (" + nmsEntityName + ")");
continue; continue;
} }
disguiseType.setTypeId(ReflectionManager.getEntityType(nmsEntity)); disguiseType.setTypeId(ReflectionManager.getEntityType(nmsEntity));
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity); Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
int entitySize = 0; int entitySize = 0;
for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) { for (Field field : ReflectionManager.getNmsClass("Entity").getFields()) {
@ -532,14 +574,18 @@ public class LibsDisguises extends JavaPlugin {
} }
} }
private String toReadable(String string) { private String[] splitReadable(String string) {
StringBuilder builder = new StringBuilder(); String[] split = string.split("_");
for (String s : string.split("_")) { for (int i = 0; i < split.length; i++) {
builder.append(s.substring(0, 1)).append(s.substring(1).toLowerCase()); split[i] = split[i].substring(0, 1) + split[i].substring(1).toLowerCase();
} }
return builder.toString(); return split;
}
private String toReadable(String string) {
return StringUtils.join(splitReadable(string));
} }
public DisguiseListener getListener() { public DisguiseListener getListener() {

View File

@ -22,14 +22,20 @@ public enum DisguiseType {
CHICKEN, CHICKEN,
COD,
COW, COW,
CREEPER, CREEPER,
DOLPHIN,
DONKEY, DONKEY,
DRAGON_FIREBALL(93), DRAGON_FIREBALL(93),
DROWNED,
DROPPED_ITEM(2, 1), DROPPED_ITEM(2, 1),
EGG(62), EGG(62),
@ -110,6 +116,8 @@ public enum DisguiseType {
PARROT, PARROT,
PHANTOM,
PIG, PIG,
PIG_ZOMBIE, PIG_ZOMBIE,
@ -120,8 +128,12 @@ public enum DisguiseType {
PRIMED_TNT(50), PRIMED_TNT(50),
PUFFERFISH,
RABBIT, RABBIT,
SALMON,
SHEEP, SHEEP,
SHULKER, SHULKER,
@ -156,6 +168,12 @@ public enum DisguiseType {
TIPPED_ARROW(60), TIPPED_ARROW(60),
TRIDENT(94, 0),
TROPICAL_FISH,
TURTLE,
ZOMBIE_HORSE, ZOMBIE_HORSE,
UNKNOWN, UNKNOWN,
@ -181,38 +199,11 @@ public enum DisguiseType {
ZOMBIE_VILLAGER; ZOMBIE_VILLAGER;
static { static {
// We set the entity type in this so that we can safely ignore disguisetypes which don't exist in older
// versions of MC.
// Without erroring up everything.
for (DisguiseType type : values()) { for (DisguiseType type : values()) {
String name = type.name();
try {
DisguiseType toUse = type;
String name;
/* switch (type) {
// Disguise item frame isn't supported. So we don't give it a entity type which should prevent it
from being..
// Usable.
case ITEM_FRAME:
break;
case ZOMBIE_VILLAGER:
case HUSK:
toUse = DisguiseType.ZOMBIE;
break;
default:
break;
}*/
name = toUse.name();
type.setEntityType(EntityType.valueOf(name)); type.setEntityType(EntityType.valueOf(name));
} }
catch (Throwable ex) {
// This version of Spigot doesn't have the disguise.
}
}
} }
public static DisguiseType getType(Entity entity) { public static DisguiseType getType(Entity entity) {

View File

@ -1,7 +1,10 @@
package me.libraryaddict.disguise.disguisetypes; package me.libraryaddict.disguise.disguisetypes;
import com.comphenix.protocol.wrappers.*; import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.EnumWrappers.Direction; import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
import com.comphenix.protocol.wrappers.Vector3F;
import com.comphenix.protocol.wrappers.WrappedBlockData;
import com.comphenix.protocol.wrappers.WrappedChatComponent;
import com.comphenix.protocol.wrappers.nbt.NbtBase; import com.comphenix.protocol.wrappers.nbt.NbtBase;
import com.comphenix.protocol.wrappers.nbt.NbtFactory; import com.comphenix.protocol.wrappers.nbt.NbtFactory;
import com.comphenix.protocol.wrappers.nbt.NbtType; import com.comphenix.protocol.wrappers.nbt.NbtType;
@ -26,8 +29,8 @@ public class MetaIndex<Y> {
public static MetaIndex<Boolean> AREA_EFFECT_IGNORE_RADIUS = new MetaIndex<>(AreaEffectCloudWatcher.class, 2, public static MetaIndex<Boolean> AREA_EFFECT_IGNORE_RADIUS = new MetaIndex<>(AreaEffectCloudWatcher.class, 2,
false); false);
public static MetaIndex<Particle> AREA_EFFECT_PARTICLE = new MetaIndex<>(AreaEffectCloudWatcher.class, public static MetaIndex<Particle> AREA_EFFECT_PARTICLE = new MetaIndex<>(AreaEffectCloudWatcher.class, 3,
3, Particle.SPELL_MOB); Particle.SPELL_MOB);
public static MetaIndex<Float> AREA_EFFECT_RADIUS = new MetaIndex<>(AreaEffectCloudWatcher.class, 0, 0F); public static MetaIndex<Float> AREA_EFFECT_RADIUS = new MetaIndex<>(AreaEffectCloudWatcher.class, 0, 0F);
@ -77,6 +80,13 @@ public class MetaIndex<Y> {
public static MetaIndex<Integer> CREEPER_STATE = new MetaIndex<>(CreeperWatcher.class, 0, -1); public static MetaIndex<Integer> CREEPER_STATE = new MetaIndex<>(CreeperWatcher.class, 0, -1);
public static MetaIndex<BlockPosition> DOLPHIN_TREASURE_POS = new MetaIndex<>(DolphinWatcher.class, 0,
BlockPosition.ORIGIN);
public static MetaIndex<Boolean> DOLPHIN_HAS_FISH = new MetaIndex<>(DolphinWatcher.class, 1, false);
public static MetaIndex<Integer> DOLPHIN_BREATH = new MetaIndex<>(DolphinWatcher.class, 2, 2400);
public static MetaIndex<ItemStack> DROPPED_ITEM = new MetaIndex<>(DroppedItemWatcher.class, 0, public static MetaIndex<ItemStack> DROPPED_ITEM = new MetaIndex<>(DroppedItemWatcher.class, 0,
new ItemStack(Material.STONE)); new ItemStack(Material.STONE));
@ -111,6 +121,8 @@ public class MetaIndex<Y> {
public static MetaIndex<ItemStack> FIREWORK_ITEM = new MetaIndex<>(FireworkWatcher.class, 0, public static MetaIndex<ItemStack> FIREWORK_ITEM = new MetaIndex<>(FireworkWatcher.class, 0,
new ItemStack(Material.AIR)); new ItemStack(Material.AIR));
public static MetaIndex<Boolean> FISH_FROM_BUCKET = new MetaIndex<>(FishWatcher.class, 0, false);
public static MetaIndex<Integer> FIREWORK_ATTACHED_ENTITY = new MetaIndex<>(FireworkWatcher.class, 1, 0); public static MetaIndex<Integer> FIREWORK_ATTACHED_ENTITY = new MetaIndex<>(FireworkWatcher.class, 1, 0);
public static MetaIndex<Integer> FISHING_HOOK_HOOKED = new MetaIndex<>(FishingHookWatcher.class, 0, 0); public static MetaIndex<Integer> FISHING_HOOK_HOOKED = new MetaIndex<>(FishingHookWatcher.class, 0, 0);
@ -174,10 +186,19 @@ public class MetaIndex<Y> {
public static MetaIndex<Integer> MINECART_SHAKING_POWER = new MetaIndex<>(MinecartWatcher.class, 0, 0); public static MetaIndex<Integer> MINECART_SHAKING_POWER = new MetaIndex<>(MinecartWatcher.class, 0, 0);
public static MetaIndex<String> MINECART_COMMAND_STRING = new MetaIndex<>(MinecartCommandWatcher.class, 0, "");
public static MetaIndex<WrappedChatComponent> MINECART_COMMAND_LAST_OUTPUT = new MetaIndex<>(
MinecartCommandWatcher.class, 1, WrappedChatComponent.fromText(""));
public static MetaIndex<Boolean> MINECART_FURANCE_FUELED = new MetaIndex<>(MinecartFurnaceWatcher.class, 0, false);
public static MetaIndex<Integer> OCELOT_TYPE = new MetaIndex<>(OcelotWatcher.class, 0, 0); public static MetaIndex<Integer> OCELOT_TYPE = new MetaIndex<>(OcelotWatcher.class, 0, 0);
public static MetaIndex<Integer> PARROT_VARIANT = new MetaIndex<>(ParrotWatcher.class, 0, 0); public static MetaIndex<Integer> PARROT_VARIANT = new MetaIndex<>(ParrotWatcher.class, 0, 0);
public static MetaIndex<Integer> PHANTOM_SIZE = new MetaIndex<>(PhantomWatcher.class, 0, 0);
public static MetaIndex<Boolean> PIG_SADDLED = new MetaIndex<>(PigWatcher.class, 0, false); public static MetaIndex<Boolean> PIG_SADDLED = new MetaIndex<>(PigWatcher.class, 0, false);
public static MetaIndex<Integer> PIG_BOOST = new MetaIndex<>(PigWatcher.class, 1, 0); public static MetaIndex<Integer> PIG_BOOST = new MetaIndex<>(PigWatcher.class, 1, 0);
@ -198,6 +219,8 @@ public class MetaIndex<Y> {
public static MetaIndex<Boolean> POLAR_BEAR_STANDING = new MetaIndex<>(PolarBearWatcher.class, 0, false); public static MetaIndex<Boolean> POLAR_BEAR_STANDING = new MetaIndex<>(PolarBearWatcher.class, 0, false);
public static MetaIndex<Integer> PUFFERFISH_PUFF_STATE = new MetaIndex<>(PufferFishWatcher.class, 0, 0);
public static MetaIndex<Integer> RABBIT_TYPE = new MetaIndex<>(RabbitWatcher.class, 0, 0); public static MetaIndex<Integer> RABBIT_TYPE = new MetaIndex<>(RabbitWatcher.class, 0, 0);
public static MetaIndex<Byte> SHEEP_WOOL = new MetaIndex<>(SheepWatcher.class, 0, (byte) 0); public static MetaIndex<Byte> SHEEP_WOOL = new MetaIndex<>(SheepWatcher.class, 0, (byte) 0);
@ -226,16 +249,33 @@ public class MetaIndex<Y> {
public static MetaIndex<Optional<UUID>> TAMEABLE_OWNER = new MetaIndex<>(TameableWatcher.class, 1, public static MetaIndex<Optional<UUID>> TAMEABLE_OWNER = new MetaIndex<>(TameableWatcher.class, 1,
Optional.empty()); Optional.empty());
public static MetaIndex<Integer> TIPPED_ARROW_COLOR = new MetaIndex<>(ArrowWatcher.class, 1, Color.WHITE.asRGB()); public static MetaIndex<Integer> TIPPED_ARROW_COLOR = new MetaIndex<>(TippedArrowWatcher.class, 0,
Color.WHITE.asRGB());
public static MetaIndex<Integer> TNT_FUSE_TICKS = new MetaIndex<>(TNTWatcher.class, 0, Integer.MAX_VALUE); public static MetaIndex<Integer> TNT_FUSE_TICKS = new MetaIndex<>(TNTWatcher.class, 0, Integer.MAX_VALUE);
public static MetaIndex<Byte> TRIDENT_ENCHANTS = new MetaIndex<>(TridentWatcher.class, 0, (byte) 0);
public static MetaIndex<Integer> TROPICAL_FISH_VARIANT = new MetaIndex<>(TropicalFishWatcher.class, 0, 0);
public static MetaIndex<BlockPosition> TURTLE_HOME_POSITION = new MetaIndex<>(TurtleWatcher.class, 0,
BlockPosition.ORIGIN);
public static MetaIndex<Boolean> TURTLE_HAS_EGG = new MetaIndex<>(TurtleWatcher.class, 1, false);
public static MetaIndex<Boolean> TURTLE_UNKNOWN_3 = new MetaIndex<>(TurtleWatcher.class, 2, false);
public static MetaIndex<BlockPosition> TURTLE_TRAVEL_POSITION = new MetaIndex<>(TurtleWatcher.class, 3,
BlockPosition.ORIGIN);
public static MetaIndex<Boolean> TURTLE_UNKNOWN_1 = new MetaIndex<>(TurtleWatcher.class, 4, false);
public static MetaIndex<Boolean> TURTLE_UNKNOWN_2 = new MetaIndex<>(TurtleWatcher.class, 5, false);
public static MetaIndex<Byte> VEX_ANGRY = new MetaIndex<>(VexWatcher.class, 0, (byte) 0); public static MetaIndex<Byte> VEX_ANGRY = new MetaIndex<>(VexWatcher.class, 0, (byte) 0);
public static MetaIndex<Integer> VILLAGER_PROFESSION = new MetaIndex<>(VillagerWatcher.class, 0, 0); public static MetaIndex<Integer> VILLAGER_PROFESSION = new MetaIndex<>(VillagerWatcher.class, 0, 0);
public static MetaIndex<Byte> VINDICATOR_JOHNNY = new MetaIndex<>(VindicatorWatcher.class, 0, (byte) 0);
public static MetaIndex<Boolean> WITCH_AGGRESSIVE = new MetaIndex<>(WitchWatcher.class, 0, false); public static MetaIndex<Boolean> WITCH_AGGRESSIVE = new MetaIndex<>(WitchWatcher.class, 0, false);
public static MetaIndex<Integer> WITHER_INVUL = new MetaIndex<>(WitherWatcher.class, 3, 0); public static MetaIndex<Integer> WITHER_INVUL = new MetaIndex<>(WitherWatcher.class, 3, 0);

View File

@ -76,6 +76,7 @@ public class MiscDisguise extends TargetedDisguise {
case SMALL_FIREBALL: // Unknown. Uses entity id of shooter. 0 if no shooter case SMALL_FIREBALL: // Unknown. Uses entity id of shooter. 0 if no shooter
case FIREBALL: // Unknown. Uses entity id of shooter. 0 if no shooter case FIREBALL: // Unknown. Uses entity id of shooter. 0 if no shooter
case WITHER_SKULL: // Unknown. Uses entity id of shooter. 0 if no shooter case WITHER_SKULL: // Unknown. Uses entity id of shooter. 0 if no shooter
case TRIDENT: // Unknown. Uses 1 + (entityId of target, or shooter)
this.data = id; this.data = id;
break; break;
default: default:

View File

@ -1,23 +1,19 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher; import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
public class ArrowWatcher extends FlagWatcher public class ArrowWatcher extends FlagWatcher {
{ public ArrowWatcher(Disguise disguise) {
public ArrowWatcher(Disguise disguise)
{
super(disguise); super(disguise);
} }
public boolean isCritical() public boolean isCritical() {
{
return (byte) getData(MetaIndex.ARROW_CRITICAL) == 1; return (byte) getData(MetaIndex.ARROW_CRITICAL) == 1;
} }
public void setCritical(boolean critical) public void setCritical(boolean critical) {
{
setData(MetaIndex.ARROW_CRITICAL, (byte) (critical ? 1 : 0)); setData(MetaIndex.ARROW_CRITICAL, (byte) (critical ? 1 : 0));
sendData(MetaIndex.ARROW_CRITICAL); sendData(MetaIndex.ARROW_CRITICAL);
} }

View File

@ -0,0 +1,12 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
/**
* Created by libraryaddict on 6/08/2018.
*/
public class DolphinWatcher extends InsentientWatcher {
public DolphinWatcher(Disguise disguise) {
super(disguise);
}
}

View File

@ -0,0 +1,13 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
/**
* Created by libraryaddict on 6/08/2018.
*/
public class FishWatcher extends InsentientWatcher {
public FishWatcher(Disguise disguise) {
super(disguise);
}
}

View File

@ -0,0 +1,12 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
/**
* Created by libraryaddict on 6/08/2018.
*/
public class MinecartCommandWatcher extends MinecartWatcher {
public MinecartCommandWatcher(Disguise disguise) {
super(disguise);
}
}

View File

@ -0,0 +1,22 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
/**
* Created by libraryaddict on 6/08/2018.
*/
public class MinecartFurnaceWatcher extends MinecartWatcher {
public MinecartFurnaceWatcher(Disguise disguise) {
super(disguise);
}
public boolean isFueled() {
return getData(MetaIndex.MINECART_FURANCE_FUELED);
}
public void setFueled(boolean fueled) {
setData(MetaIndex.MINECART_FURANCE_FUELED, fueled);
sendData(MetaIndex.MINECART_FURANCE_FUELED);
}
}

View File

@ -0,0 +1,22 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
/**
* Created by libraryaddict on 6/08/2018.
*/
public class PhantomWatcher extends InsentientWatcher {
public PhantomWatcher(Disguise disguise) {
super(disguise);
}
public void setSize(int size) {
setData(MetaIndex.PHANTOM_SIZE, Math.min(Math.max(size, -50), 50));
sendData(MetaIndex.PHANTOM_SIZE);
}
public int getSize() {
return getData(MetaIndex.PHANTOM_SIZE);
}
}

View File

@ -0,0 +1,22 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
/**
* Created by libraryaddict on 6/08/2018.
*/
public class PufferFishWatcher extends FishWatcher {
public PufferFishWatcher(Disguise disguise) {
super(disguise);
}
public void setPuffState(int puffState) {
setData(MetaIndex.PUFFERFISH_PUFF_STATE, Math.min(Math.max(puffState, 0), 2));
sendData(MetaIndex.PUFFERFISH_PUFF_STATE);
}
public int getPuffState() {
return getData(MetaIndex.PUFFERFISH_PUFF_STATE);
}
}

View File

@ -1,19 +1,15 @@
package me.libraryaddict.disguise.disguisetypes.watchers; package me.libraryaddict.disguise.disguisetypes.watchers;
import org.bukkit.Color;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import org.bukkit.Color;
/** /**
* @author Navid * @author Navid
*/ */
public class TippedArrowWatcher extends ArrowWatcher public class TippedArrowWatcher extends ArrowWatcher {
{ public TippedArrowWatcher(Disguise disguise) {
public TippedArrowWatcher(Disguise disguise)
{
super(disguise); super(disguise);
int r = DisguiseUtilities.random.nextInt(256); int r = DisguiseUtilities.random.nextInt(256);
@ -23,14 +19,12 @@ public class TippedArrowWatcher extends ArrowWatcher
setColor(Color.fromRGB(r, g, b)); setColor(Color.fromRGB(r, g, b));
} }
public Color getColor() public Color getColor() {
{
int color = (int) getData(MetaIndex.TIPPED_ARROW_COLOR); int color = (int) getData(MetaIndex.TIPPED_ARROW_COLOR);
return Color.fromRGB(color); return Color.fromRGB(color);
} }
public void setColor(Color color) public void setColor(Color color) {
{
setData(MetaIndex.TIPPED_ARROW_COLOR, color.asRGB()); setData(MetaIndex.TIPPED_ARROW_COLOR, color.asRGB());
sendData(MetaIndex.TIPPED_ARROW_COLOR); sendData(MetaIndex.TIPPED_ARROW_COLOR);
} }

View File

@ -0,0 +1,12 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
/**
* Created by libraryaddict on 6/08/2018.
*/
public class TridentWatcher extends ArrowWatcher {
public TridentWatcher(Disguise disguise) {
super(disguise);
}
}

View File

@ -0,0 +1,109 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import org.bukkit.DyeColor;
import org.bukkit.entity.TropicalFish;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
/**
* Created by libraryaddict on 6/08/2018.
*/
public class TropicalFishWatcher extends FishWatcher {
private enum CraftPattern {
KOB("KOB", 0, 0, false),
SUNSTREAK("SUNSTREAK", 1, 1, false),
SNOOPER("SNOOPER", 2, 2, false),
DASHER("DASHER", 3, 3, false),
BRINELY("BRINELY", 4, 4, false),
SPOTTY("SPOTTY", 5, 5, false),
FLOPPER("FLOPPER", 6, 0, true),
STRIPEY("STRIPEY", 7, 1, true),
GLITTER("GLITTER", 8, 2, true),
BLOCKFISH("BLOCKFISH", 9, 3, true),
BETTY("BETTY", 10, 4, true),
CLAYFISH("CLAYFISH", 11, 5, true);
private final int variant;
private final boolean large;
private static final Map<Integer, TropicalFish.Pattern> BY_DATA;
static {
BY_DATA = new HashMap<>();
CraftPattern[] values;
for (int length = (values = values()).length, i = 0; i < length; ++i) {
final CraftPattern type = values[i];
CraftPattern.BY_DATA.put(type.getDataValue(), TropicalFish.Pattern.values()[type.ordinal()]);
}
}
static TropicalFish.Pattern fromData(final int data) {
return CraftPattern.BY_DATA.get(data);
}
CraftPattern(final String s, final int n, final int variant, final boolean large) {
this.variant = variant;
this.large = large;
}
public int getDataValue() {
return this.variant << 8 | (this.large ? 1 : 0);
}
}
public TropicalFishWatcher(Disguise disguise) {
super(disguise);
Random random = new Random();
int n = random.nextInt(2);
int n2 = random.nextInt(6);
int n3 = random.nextInt(15);
int n4 = random.nextInt(15);
this.setVariant(n | n2 << 8 | n3 << 16 | n4 << 24);
}
public DyeColor getPatternColor() {
return DyeColor.getByWoolData((byte) (getVariant() >> 24 & 0xFF));
}
public void setPatternColor(DyeColor dyeColor) {
setVariant(getData(dyeColor, getBodyColor(), getPattern()));
}
private int getData(final DyeColor patternColor, final DyeColor bodyColor, final TropicalFish.Pattern type) {
return patternColor.getWoolData() << 24 | bodyColor.getWoolData() << 16 |
CraftPattern.values()[type.ordinal()].getDataValue();
}
public DyeColor getBodyColor() {
return DyeColor.getByWoolData((byte) (getVariant() >> 16 & 0xFF));
}
public void setBodyColor(DyeColor dyeColor) {
setVariant(getData(dyeColor, dyeColor, getPattern()));
}
public TropicalFish.Pattern getPattern() {
return CraftPattern.fromData(getVariant() & 0xFFFF);
}
public void setPattern(TropicalFish.Pattern pattern) {
setVariant(getData(getPatternColor(), getBodyColor(), pattern));
}
@Deprecated
public int getVariant() {
return getData(MetaIndex.TROPICAL_FISH_VARIANT);
}
@Deprecated
public void setVariant(int variant) {
setData(MetaIndex.TROPICAL_FISH_VARIANT, variant);
sendData(MetaIndex.TROPICAL_FISH_VARIANT);
}
}

View File

@ -0,0 +1,22 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
/**
* Created by libraryaddict on 6/08/2018.
*/
public class TurtleWatcher extends AgeableWatcher {
public TurtleWatcher(Disguise disguise) {
super(disguise);
}
public void setEgg(boolean egg) {
setData(MetaIndex.TURTLE_HAS_EGG, egg);
sendData(MetaIndex.TURTLE_HAS_EGG);
}
public boolean isEgg() {
return getData(MetaIndex.TURTLE_HAS_EGG);
}
}

View File

@ -3,15 +3,15 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise; import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex; import me.libraryaddict.disguise.disguisetypes.MetaIndex;
public class VindicatorWatcher extends InsentientWatcher { public class VindicatorWatcher extends IllagerWatcher {
public VindicatorWatcher(Disguise disguise) { public VindicatorWatcher(Disguise disguise) {
super(disguise); super(disguise);
} }
public void setJohnny(boolean isJohnny) { public void setJohnny(boolean isJohnny) {
setData(MetaIndex.VINDICATOR_JOHNNY, (byte) (isJohnny ? 1 : 0)); setData(MetaIndex.ILLAGER_META, (byte) (isJohnny ? 1 : 0));
sendData(MetaIndex.VINDICATOR_JOHNNY); sendData(MetaIndex.ILLAGER_META);
} }
} }

View File

@ -4,10 +4,7 @@ import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.WrappedGameProfile; import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.DisguiseConfig; import me.libraryaddict.disguise.DisguiseConfig;
import me.libraryaddict.disguise.disguisetypes.*; import me.libraryaddict.disguise.disguisetypes.*;
import org.bukkit.Art; import org.bukkit.*;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
@ -624,6 +621,7 @@ public class DisguiseParser {
case SMALL_FIREBALL: case SMALL_FIREBALL:
case FIREBALL: case FIREBALL:
case WITHER_SKULL: case WITHER_SKULL:
case TRIDENT:
break; break;
default: default:
throw new DisguiseParseException(LibsMsg.PARSE_TOO_MANY_ARGS, throw new DisguiseParseException(LibsMsg.PARSE_TOO_MANY_ARGS,
@ -797,6 +795,20 @@ public class DisguiseParser {
catch (Exception ex) { catch (Exception ex) {
throw parseToException(param, valueString, methodName); throw parseToException(param, valueString, methodName);
} }
} else if (param == TropicalFish.Pattern.class) {
try {
value = TropicalFish.Pattern.valueOf(valueString.toUpperCase());
}
catch (Exception ex) {
throw parseToException(param, valueString, methodName);
}
} else if (param == DyeColor.class) {
try {
value = DyeColor.valueOf(valueString.toUpperCase());
}
catch (Exception ex) {
throw parseToException(param, valueString, methodName);
}
} else if (param == ItemStack.class) { } else if (param == ItemStack.class) {
// Parse to itemstack // Parse to itemstack
value = parseToItemstack(param, methodName, valueString); value = parseToItemstack(param, methodName, valueString);

View File

@ -1,159 +1,229 @@
package me.libraryaddict.disguise.utilities; package me.libraryaddict.disguise.utilities;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Objects;
import org.bukkit.Sound; import org.bukkit.Sound;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
/** /**
* Only living disguises go in here! * Only living disguises go in here!
*/ */
public enum DisguiseSound { public enum DisguiseSound {
ARROW(null, null, null, null, "entity.arrow.hit", "entity.arrow.shoot"), ARMOR_STAND(Sound.ENTITY_ARMOR_STAND_HIT, null, Sound.ENTITY_ARMOR_STAND_BREAK, Sound.ENTITY_ARMOR_STAND_FALL,
Sound.ENTITY_ARMOR_STAND_PLACE),
BAT("entity.bat.hurt", null, "entity.bat.death", "entity.bat.ambient", "entity.player.small_fall", ARROW(null, null, null, null, Sound.ENTITY_ARROW_HIT, Sound.ENTITY_ARROW_SHOOT),
"entity.bat.loop", "entity.player.big_fall", "entity.bat.takeoff"),
BLAZE("entity.blaze.hurt", null, "entity.blaze.death", "entity.blaze.ambient", "entity.player.small_fall", BAT(Sound.ENTITY_BAT_HURT, null, Sound.ENTITY_BAT_DEATH, Sound.ENTITY_BAT_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL,
"entity.player.big_fall"), Sound.ENTITY_BAT_LOOP, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_BAT_TAKEOFF),
CAVE_SPIDER("entity.spider.ambient", "entity.spider.step", "entity.spider.death", "entity.spider.ambient"), BLAZE(Sound.ENTITY_BLAZE_HURT, null, Sound.ENTITY_BLAZE_DEATH, Sound.ENTITY_BLAZE_AMBIENT,
Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_PLAYER_BIG_FALL, Sound.ENTITY_BLAZE_BURN,
Sound.ENTITY_BLAZE_SHOOT),
CHICKEN("entity.chicken.hurt", "entity.chicken.step", "entity.chicken.hurt", "entity.chicken.ambient", BOAT(null, Sound.ENTITY_BOAT_PADDLE_WATER, null, null, Sound.ENTITY_BOAT_PADDLE_LAND),
"entity.player.small_fall", "entity.chicken.egg", "entity.player.big_fall"),
COW("entity.cow.hurt", "entity.cow.step", "entity.cow.death", "entity.cow.ambient"), CAVE_SPIDER(Sound.ENTITY_SPIDER_HURT, Sound.ENTITY_SPIDER_STEP, Sound.ENTITY_SPIDER_DEATH,
Sound.ENTITY_SPIDER_AMBIENT),
CREEPER("entity.creeper.hurt", "block.grass.step", "entity.creeper.death", null, "entity.creeper.primed"), CHICKEN(Sound.ENTITY_CHICKEN_HURT, Sound.ENTITY_CHICKEN_STEP, Sound.ENTITY_CHICKEN_DEATH,
Sound.ENTITY_CHICKEN_AMBIENT, Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_CHICKEN_EGG,
Sound.ENTITY_PLAYER_BIG_FALL),
DONKEY("entity.donkey.hurt", "block.grass.step", "entity.donkey.death", "entity.donkey.ambient", COD(Sound.ENTITY_COD_HURT, null, Sound.ENTITY_COD_DEATH, Sound.ENTITY_COD_AMBIENT, Sound.ENTITY_COD_FLOP,
"entity.horse.gallop", "entity.horse.saddle", "entity.donkey.angry", "entity.horse.step_wood", Sound.ENTITY_FISH_SWIM),
"entity.horse.armor", "entity.horse.land", "entity.horse.jump", "entity.horse.angry"),
ELDER_GUARDIAN("entity.elder_guardian.hurt", null, "entity.elder_guardian.death", "entity.elder_guardian.ambient"), COW(Sound.ENTITY_COW_HURT, Sound.ENTITY_COW_STEP, Sound.ENTITY_COW_DEATH, Sound.ENTITY_COW_AMBIENT),
ENDER_DRAGON("entity.enderdragon.hurt", null, "entity.enderdragon.death", "entity.enderdragon.ambient", CREEPER(Sound.ENTITY_CREEPER_HURT, Sound.BLOCK_GRASS_STEP, Sound.ENTITY_CREEPER_DEATH, null,
"entity.player.small_fall", "entity.enderdragon.flap", "entity.player.big_fall"), Sound.ENTITY_CREEPER_PRIMED),
ENDERMAN("entity.endermen.hurt", "block.grass.step", "entity.endermen.death", "entity.endermen.ambient", DOLPHIN(Sound.ENTITY_DOLPHIN_HURT, Sound.ENTITY_DOLPHIN_SWIM, Sound.ENTITY_DOLPHIN_DEATH,
"entity.endermen.scream", "entity.endermen.teleport", "entity.endermen.stare"), new Sound[]{Sound.ENTITY_DOLPHIN_AMBIENT, Sound.ENTITY_DOLPHIN_AMBIENT_WATER}, Sound.ENTITY_DOLPHIN_ATTACK,
Sound.ENTITY_DOLPHIN_EAT, Sound.ENTITY_DOLPHIN_SPLASH, Sound.ENTITY_DOLPHIN_PLAY, Sound.ENTITY_DOLPHIN_JUMP,
Sound.ENTITY_FISH_SWIM),
ENDERMITE("entity.silverfish.hurt", "entity.endermite.step", "entity.endermite.death", "entity.endermite.ambient"), DONKEY(Sound.ENTITY_DONKEY_HURT, new Sound[]{Sound.BLOCK_GRASS_STEP, Sound.ENTITY_HORSE_STEP_WOOD,},
Sound.ENTITY_DONKEY_DEATH, Sound.ENTITY_DONKEY_AMBIENT, Sound.ENTITY_HORSE_GALLOP,
Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND,
Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_HORSE_ANGRY, Sound.ENTITY_DONKEY_CHEST),
EVOKER("entity.evocation_illager.hurt", null, "entity.evocation_illager.death", "entity.evocation_illager.ambient", DROWNED(new Sound[]{Sound.ENTITY_DROWNED_HURT, Sound.ENTITY_DROWNED_HURT_WATER},
"entity.evocation_illager.cast_spell", "entity.evocation_illager.prepare_attack", new Sound[]{Sound.ENTITY_DROWNED_STEP, Sound.ENTITY_DROWNED_SWIM},
"entity.evocation_illager.prepare_summon", "entity.evocation_illager.prepare_wololo"), new Sound[]{Sound.ENTITY_DROWNED_DEATH, Sound.ENTITY_DROWNED_DEATH_WATER},
new Sound[]{Sound.ENTITY_DROWNED_AMBIENT, Sound.ENTITY_DROWNED_AMBIENT_WATER}, Sound.ENTITY_DROWNED_SHOOT),
EVOKER_FANGS(null, null, null, null, "entity.evocation_fangs.attack"), ELDER_GUARDIAN(new Sound[]{Sound.ENTITY_ELDER_GUARDIAN_HURT, Sound.ENTITY_ELDER_GUARDIAN_HURT_LAND}, null,
new Sound[]{Sound.ENTITY_ELDER_GUARDIAN_DEATH, Sound.ENTITY_ELDER_GUARDIAN_DEATH_LAND},
new Sound[]{Sound.ENTITY_ELDER_GUARDIAN_AMBIENT, Sound.ENTITY_ELDER_GUARDIAN_AMBIENT_LAND},
Sound.ENTITY_ELDER_GUARDIAN_FLOP),
GHAST("entity.ghast.hurt", null, "entity.ghast.death", "entity.ghast.ambient", "entity.player.small_fall", ENDER_DRAGON(Sound.ENTITY_ENDER_DRAGON_HURT, null, Sound.ENTITY_ENDER_DRAGON_DEATH,
"entity.ghast.shoot", "entity.player.big_fall", "entity.ghast.scream", "entity.ghast.warn"), Sound.ENTITY_ENDER_DRAGON_AMBIENT, Sound.ENTITY_GENERIC_SMALL_FALL, Sound.ENTITY_GENERIC_BIG_FALL,
Sound.ENTITY_ENDER_DRAGON_FLAP, Sound.ENTITY_ENDER_DRAGON_GROWL),
GIANT("entity.player.hurt", "block.grass.step", null, null), ENDERMAN(Sound.ENTITY_ENDERMAN_HURT, Sound.BLOCK_GRASS_STEP, Sound.ENTITY_ENDERMAN_DEATH,
Sound.ENTITY_ENDERMAN_AMBIENT, Sound.ENTITY_ENDERMAN_SCREAM, Sound.ENTITY_ENDERMAN_TELEPORT,
Sound.ENTITY_ENDERMAN_STARE),
GUARDIAN("entity.guardian.hurt", null, "entity.guardian.death", "entity.elder_guardian.ambient"), ENDERMITE(Sound.ENTITY_ENDERMITE_HURT, Sound.ENTITY_ENDERMITE_STEP, Sound.ENTITY_ENDERMITE_DEATH,
Sound.ENTITY_ENDERMITE_AMBIENT),
HORSE("entity.horse.hurt", "block.grass.step", "entity.horse.death", "entity.horse.ambient", "entity.horse.gallop", EVOKER(Sound.ENTITY_EVOKER_HURT, null, Sound.ENTITY_EVOKER_DEATH, Sound.ENTITY_EVOKER_AMBIENT,
"entity.horse.saddle", "entity.donkey.angry", "entity.horse.step_wood", "entity.horse.armor", Sound.ENTITY_EVOKER_CAST_SPELL, Sound.ENTITY_EVOKER_PREPARE_ATTACK, Sound.ENTITY_EVOKER_PREPARE_SUMMON,
"entity.horse.land", "entity.horse.jump", "entity.horse.angry"), Sound.ENTITY_EVOKER_PREPARE_WOLOLO),
ILLUSIONER("entity.illusion_illager.hurt", null, "entity.illusion_illager.death", "entity.illusion_illager.ambient", EVOKER_FANGS(null, null, null, null, Sound.ENTITY_EVOKER_FANGS_ATTACK),
"entity.illusion_illager.cast_spell", "entity.illusion_illager.prepare_blindness",
"entity.illusion_illager.prepare_mirror", "entity.illusion_illager.mirror_move"),
IRON_GOLEM("entity.irongolem.hurt", "entity.irongolem.step", "entity.irongolem.death", "entity.irongolem.attack"), GHAST(Sound.ENTITY_GHAST_HURT, null, Sound.ENTITY_GHAST_DEATH, Sound.ENTITY_GHAST_AMBIENT,
Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_GHAST_SHOOT, Sound.ENTITY_PLAYER_BIG_FALL,
Sound.ENTITY_GHAST_SCREAM, Sound.ENTITY_GHAST_WARN),
LLAMA("entity.llama.hurt", "entity.llama.step", "entity.llama.death", "entity.llama.ambient", "entity.llama.angry", GIANT(Sound.ENTITY_PLAYER_HURT, Sound.BLOCK_GRASS_STEP, null, null),
"entity.llama.chest", "entity.llama.eat", "entity.llama.swag"),
MAGMA_CUBE("entity.magmacube.hurt", "entity.magmacube.jump", null, null), GUARDIAN(new Sound[]{Sound.ENTITY_GUARDIAN_HURT, Sound.ENTITY_GUARDIAN_HURT_LAND}, null,
new Sound[]{Sound.ENTITY_GUARDIAN_DEATH, Sound.ENTITY_GUARDIAN_DEATH_LAND},
new Sound[]{Sound.ENTITY_GUARDIAN_AMBIENT, Sound.ENTITY_GUARDIAN_AMBIENT_LAND}, Sound.ENTITY_GUARDIAN_FLOP),
MULE("entity.mule.hurt", "block.grass.step", "entity.mule.death", "entity.mule.ambient"), HORSE(Sound.ENTITY_HORSE_HURT, new Sound[]{Sound.ENTITY_HORSE_STEP, Sound.ENTITY_HORSE_STEP_WOOD},
Sound.ENTITY_HORSE_DEATH, Sound.ENTITY_HORSE_AMBIENT, Sound.ENTITY_HORSE_GALLOP, Sound.ENTITY_HORSE_SADDLE,
Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP,
Sound.ENTITY_HORSE_ANGRY, Sound.ENTITY_HORSE_EAT, Sound.ENTITY_HORSE_BREATHE),
MUSHROOM_COW("entity.cow.hurt", "entity.cow.step", "entity.cow.hurt", "entity.cow.ambient"), HUSK(Sound.ENTITY_HUSK_HURT, Sound.ENTITY_HUSK_STEP, Sound.ENTITY_HUSK_DEATH, Sound.ENTITY_HUSK_AMBIENT,
Sound.ENTITY_HUSK_CONVERTED_TO_ZOMBIE),
OCELOT("entity.cat.hurt", "block.grass.step", "entity.cat.hurt", "entity.cat.ambient", "entity.cat.purr", ILLUSIONER(Sound.ENTITY_ILLUSIONER_HURT, null, Sound.ENTITY_ILLUSIONER_DEATH, Sound.ENTITY_ILLUSIONER_AMBIENT,
"entity.cat.purreow"), Sound.ENTITY_ILLUSIONER_CAST_SPELL, Sound.ENTITY_ILLUSIONER_PREPARE_BLINDNESS,
Sound.ENTITY_ILLUSIONER_PREPARE_MIRROR, Sound.ENTITY_ILLUSIONER_MIRROR_MOVE),
PARROT("entity.parrot.hurt", "entity.parrot.step", "entity.parrot.death", "entity.parrot.ambient", IRON_GOLEM(Sound.ENTITY_IRON_GOLEM_HURT, Sound.ENTITY_IRON_GOLEM_STEP, Sound.ENTITY_IRON_GOLEM_DEATH,
"entity.parrot.eat", "entity.parrot.fly", "entity.parrot.imitate.blaze", "entity.parrot.imitate.creeper", Sound.ENTITY_IRON_GOLEM_ATTACK),
"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"),
PIG("entity.pig.hurt", "entity.pig.step", "entity.pig.death", "entity.pig.ambient"), LLAMA(Sound.ENTITY_LLAMA_HURT, Sound.ENTITY_LLAMA_STEP, Sound.ENTITY_LLAMA_DEATH, Sound.ENTITY_LLAMA_AMBIENT,
Sound.ENTITY_LLAMA_ANGRY, Sound.ENTITY_LLAMA_CHEST, Sound.ENTITY_LLAMA_EAT, Sound.ENTITY_LLAMA_SWAG),
PIG_ZOMBIE("entity.zombie_pig.hurt", null, "entity.zombie_pig.death", "entity.zombie_pig.ambient", MAGMA_CUBE(Sound.ENTITY_MAGMA_CUBE_HURT, Sound.ENTITY_MAGMA_CUBE_JUMP,
"entity.zombie_pig.angry"), new Sound[]{Sound.ENTITY_MAGMA_CUBE_DEATH, Sound.ENTITY_MAGMA_CUBE_DEATH_SMALL}, null,
Sound.ENTITY_MAGMA_CUBE_SQUISH, Sound.ENTITY_MAGMA_CUBE_SQUISH_SMALL),
PLAYER("entity.player.hurt", MULE(Sound.ENTITY_MULE_HURT, Sound.BLOCK_GRASS_STEP, Sound.ENTITY_MULE_DEATH, Sound.ENTITY_MULE_AMBIENT,
new String[]{"block.stone.step", "block.grass.step", "block.anvil.step", "block.cloth.step", Sound.ENTITY_MULE_CHEST),
"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),
RABBIT("entity.rabbit.hurt", "entity.rabbit.jump", "entity.rabbit.death", "entity.rabbit.ambient"), MUSHROOM_COW(Sound.ENTITY_COW_HURT, Sound.ENTITY_COW_STEP, Sound.ENTITY_COW_DEATH, Sound.ENTITY_COW_AMBIENT),
SHEEP("entity.sheep.hurt", "entity.sheep.step", null, "entity.sheep.ambient", "entity.sheep.shear"), OCELOT(Sound.ENTITY_CAT_HURT, Sound.BLOCK_GRASS_STEP, Sound.ENTITY_CAT_DEATH,
new Sound[]{Sound.ENTITY_CAT_AMBIENT, Sound.ENTITY_CAT_PURR, Sound.ENTITY_CAT_PURREOW},
Sound.ENTITY_CAT_HISS),
SHULKER("entity.shulker.hurt", null, "entity.shulker.death", "entity.shulker.ambient", "entity.shulker.open", PARROT(Sound.ENTITY_PARROT_HURT, Sound.ENTITY_PARROT_STEP, Sound.ENTITY_PARROT_DEATH, Sound.ENTITY_PARROT_AMBIENT,
"entity.shulker.close", "entity.shulker.hurt_closed", "entity.shulker.teleport"), Arrays.stream(Sound.values())
.filter(sound -> sound.name().contains("PARROT_IMITATE") || sound == Sound.ENTITY_PARROT_EAT ||
sound == Sound.ENTITY_PARROT_FLY).toArray(Sound[]::new)),
SILVERFISH("entity.silverfish.hurt", "entity.silverfish.step", "entity.silverfish.death", PIG(Sound.ENTITY_PIG_HURT, Sound.ENTITY_PIG_STEP, Sound.ENTITY_PIG_DEATH, Sound.ENTITY_PIG_AMBIENT),
"entity.silverfish.ambient"),
SKELETON("entity.skeleton.hurt", "entity.skeleton.step", "entity.skeleton.death", "entity.skeleton.ambient"), PIG_ZOMBIE(Sound.ENTITY_ZOMBIE_PIGMAN_HURT, null, Sound.ENTITY_ZOMBIE_PIGMAN_DEATH,
Sound.ENTITY_ZOMBIE_PIGMAN_AMBIENT, Sound.ENTITY_ZOMBIE_PIGMAN_ANGRY),
SKELETON_HORSE("entity.skeleton_horse.hurt", "block.grass.step", "entity.skeleton_horse.death", PLAYER(Sound.ENTITY_PLAYER_HURT, Arrays.stream(Sound.values())
"entity.skeleton_horse.ambient", "entity.horse.gallop", "entity.horse.saddle", "entity.donkey.angry", .filter(sound -> sound.name().startsWith("BLOCK_") && sound.name().endsWith("_STEP")).toArray(Sound[]::new),
"entity.horse.step_wood", "entity.horse.armor", "entity.horse.land", "entity.horse.jump", Sound.ENTITY_PLAYER_DEATH, null),
"entity.horse.angry"),
SLIME("entity.slime.hurt", "entity.slime.jump", "entity.slime.death", null), PHANTOM(Sound.ENTITY_PHANTOM_HURT, new Sound[]{Sound.ENTITY_PHANTOM_FLAP, Sound.ENTITY_PHANTOM_SWOOP},
Sound.ENTITY_PHANTOM_DEATH, Sound.ENTITY_PHANTOM_AMBIENT, Sound.ENTITY_PHANTOM_BITE),
SNOWMAN("entity.snowman.hurt", null, "entity.snowman.death", "entity.snowman.ambient", "entity.snowman.shoot"), POLAR_BEAR(Sound.ENTITY_POLAR_BEAR_HURT, Sound.ENTITY_POLAR_BEAR_STEP, Sound.ENTITY_POLAR_BEAR_DEATH,
new Sound[]{Sound.ENTITY_POLAR_BEAR_AMBIENT, Sound.ENTITY_POLAR_BEAR_AMBIENT_BABY},
Sound.ENTITY_POLAR_BEAR_WARNING),
SPIDER("entity.spider.ambient", "entity.spider.step", "entity.spider.death", "entity.spider.ambient"), PUFFERFISH(Sound.ENTITY_PUFFER_FISH_HURT, null, Sound.ENTITY_PUFFER_FISH_DEATH, Sound.ENTITY_PUFFER_FISH_AMBIENT,
Sound.ENTITY_PUFFER_FISH_BLOW_OUT, Sound.ENTITY_PUFFER_FISH_BLOW_UP, Sound.ENTITY_PUFFER_FISH_FLOP,
Sound.ENTITY_PUFFER_FISH_STING, Sound.ENTITY_FISH_SWIM),
SQUID("entity.squid.hurt", null, "entity.squid.death", "entity.squid.ambient"), RABBIT(Sound.ENTITY_RABBIT_HURT, Sound.ENTITY_RABBIT_JUMP, Sound.ENTITY_RABBIT_DEATH, Sound.ENTITY_RABBIT_AMBIENT,
Sound.ENTITY_RABBIT_ATTACK),
ZOMBIE_HORSE("entity.zombie_horse.hurt", "block.grass.step", "entity.zombie_horse.death", SALMON(Sound.ENTITY_SALMON_HURT, null, Sound.ENTITY_SALMON_DEATH, Sound.ENTITY_SALMON_AMBIENT,
"entity.zombie_horse.ambient", "entity.horse.gallop", "entity.horse.saddle", "entity.donkey.angry", Sound.ENTITY_SALMON_FLOP, Sound.ENTITY_FISH_SWIM),
"entity.horse.step_wood", "entity.horse.armor", "entity.horse.land", "entity.horse.jump",
"entity.horse.angry"),
VEX("entity.vex.hurt", null, "entity.vex.death", "entity.vex.ambient", "entity.vex.charge"), SHEEP(Sound.ENTITY_SHEEP_HURT, Sound.ENTITY_SHEEP_STEP, Sound.ENTITY_SHEEP_DEATH, Sound.ENTITY_SHEEP_AMBIENT,
Sound.ENTITY_SHEEP_SHEAR),
VILLAGER("entity.villager.hurt", null, "entity.villager.death", "entity.villager.ambient", SHULKER(new Sound[]{Sound.ENTITY_SHULKER_HURT, Sound.ENTITY_SHULKER_HURT_CLOSED}, null, Sound.ENTITY_SHULKER_DEATH,
"entity.villager.trading", "entity.villager.no", "entity.villager.yes"), Sound.ENTITY_SHULKER_AMBIENT, Sound.ENTITY_SHULKER_OPEN, Sound.ENTITY_SHULKER_CLOSE,
Sound.ENTITY_SHULKER_TELEPORT),
VINDICATOR("entity.vindication_illager.hurt", null, "entity.vindication_illager.death", SILVERFISH(Sound.ENTITY_SILVERFISH_HURT, Sound.ENTITY_SILVERFISH_STEP, Sound.ENTITY_SILVERFISH_DEATH,
"entity.vindication_illager.ambient"), Sound.ENTITY_SILVERFISH_AMBIENT),
WITCH("entity.witch.hurt", null, "entity.witch.death", "entity.witch.ambient"), SKELETON(Sound.ENTITY_SKELETON_HURT, Sound.ENTITY_SKELETON_STEP, Sound.ENTITY_SKELETON_DEATH,
Sound.ENTITY_SKELETON_AMBIENT),
WITHER("entity.wither.hurt", null, "entity.wither.death", "entity.wither.ambient", "entity.player.small_fall", SKELETON_HORSE(Sound.ENTITY_SKELETON_HORSE_HURT, new Sound[]{Sound.BLOCK_GRASS_STEP, Sound.ENTITY_HORSE_STEP_WOOD},
"entity.wither.spawn", "entity.player.big_fall", "entity.wither.shoot"), Sound.ENTITY_SKELETON_HORSE_DEATH,
new Sound[]{Sound.ENTITY_SKELETON_HORSE_AMBIENT, Sound.ENTITY_SKELETON_HORSE_AMBIENT_WATER},
Sound.ENTITY_HORSE_GALLOP, Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND,
Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_SKELETON_HORSE_GALLOP_WATER, Sound.ENTITY_SKELETON_HORSE_JUMP_WATER,
Sound.ENTITY_SKELETON_HORSE_SWIM, Sound.ENTITY_SKELETON_HORSE_STEP_WATER),
WITHER_SKELETON("entity.skeleton.hurt", "entity.skeleton.step", "entity.skeleton.death", "entity.skeleton.ambient"), SLIME(new Sound[]{Sound.ENTITY_SLIME_HURT, Sound.ENTITY_SLIME_HURT_SMALL},
new Sound[]{Sound.ENTITY_SLIME_JUMP, Sound.ENTITY_SLIME_JUMP_SMALL},
new Sound[]{Sound.ENTITY_SLIME_DEATH, Sound.ENTITY_SLIME_DEATH_SMALL}, null, Sound.ENTITY_SLIME_ATTACK,
Sound.ENTITY_SLIME_SQUISH, Sound.ENTITY_SLIME_SQUISH_SMALL),
WOLF("entity.wolf.hurt", "entity.wolf.step", "entity.wolf.death", "entity.wolf.ambient", "entity.wolf.growl", SNOWMAN(Sound.ENTITY_SNOW_GOLEM_HURT, null, Sound.ENTITY_SNOW_GOLEM_DEATH, Sound.ENTITY_SNOW_GOLEM_AMBIENT,
"entity.wolf.pant", "entity.wolf.howl", "entity.wolf.shake", "entity.wolf.whine"), Sound.ENTITY_SNOW_GOLEM_SHOOT),
ZOMBIE("entity.zombie.hurt", "entity.zombie.step", "entity.zombie.death", "entity.zombie.ambient", SPIDER(Sound.ENTITY_SPIDER_HURT, Sound.ENTITY_SPIDER_STEP, Sound.ENTITY_SPIDER_DEATH, Sound.ENTITY_SPIDER_AMBIENT),
"entity.zombie.infect", "entity.zombie.break_door_wood", "entity.zombie.attack_door_wood",
"entity.zombie.attack_iron_door"),
ZOMBIE_VILLAGER("entity.zombie_villager.hurt", "entity.zombie_villager.step", "entity.zombie_villager.death", STRAY(Sound.ENTITY_STRAY_HURT, Sound.ENTITY_STRAY_STEP, Sound.ENTITY_STRAY_DEATH, Sound.ENTITY_STRAY_AMBIENT),
"entity.zombie_villager.ambient", "entity.zombie.infect", "entity.zombie.break_door_wood",
"entity.zombie.attack_door_wood", "entity.zombie.attack_iron_door"); SQUID(Sound.ENTITY_SQUID_HURT, null, Sound.ENTITY_SQUID_DEATH, Sound.ENTITY_SQUID_AMBIENT,
Sound.ENTITY_SQUID_SQUIRT, Sound.ENTITY_FISH_SWIM),
TROPICAL_FISH(Sound.ENTITY_TROPICAL_FISH_HURT, null, Sound.ENTITY_TROPICAL_FISH_DEATH,
Sound.ENTITY_TROPICAL_FISH_AMBIENT, Sound.ENTITY_TROPICAL_FISH_FLOP, Sound.ENTITY_FISH_SWIM),
TURTLE(new Sound[]{Sound.ENTITY_TURTLE_HURT, Sound.ENTITY_TURTLE_HURT_BABY},
new Sound[]{Sound.ENTITY_TURTLE_SHAMBLE, Sound.ENTITY_TURTLE_SHAMBLE_BABY},
new Sound[]{Sound.ENTITY_TURTLE_DEATH, Sound.ENTITY_TURTLE_DEATH_BABY}, Sound.ENTITY_TURTLE_AMBIENT_LAND,
Sound.ENTITY_TURTLE_LAY_EGG),
VEX(Sound.ENTITY_VEX_HURT, null, Sound.ENTITY_VEX_DEATH, Sound.ENTITY_VEX_AMBIENT, Sound.ENTITY_VEX_CHARGE),
VILLAGER(Sound.ENTITY_VILLAGER_HURT, null, Sound.ENTITY_VILLAGER_DEATH, Sound.ENTITY_VILLAGER_AMBIENT,
Sound.ENTITY_VILLAGER_TRADE, Sound.ENTITY_VILLAGER_NO, Sound.ENTITY_VILLAGER_YES),
VINDICATOR(Sound.ENTITY_VINDICATOR_HURT, null, Sound.ENTITY_VINDICATOR_DEATH, Sound.ENTITY_VINDICATOR_AMBIENT),
WITCH(Sound.ENTITY_WITCH_HURT, null, Sound.ENTITY_WITCH_DEATH, Sound.ENTITY_WITCH_AMBIENT),
WITHER(Sound.ENTITY_WITHER_HURT, null, Sound.ENTITY_WITHER_DEATH, Sound.ENTITY_WITHER_AMBIENT,
Sound.ENTITY_PLAYER_SMALL_FALL, Sound.ENTITY_WITHER_SPAWN, Sound.ENTITY_PLAYER_BIG_FALL,
Sound.ENTITY_WITHER_SHOOT),
WITHER_SKELETON(Sound.ENTITY_WITHER_SKELETON_HURT, Sound.ENTITY_WITHER_SKELETON_STEP,
Sound.ENTITY_WITHER_SKELETON_DEATH, Sound.ENTITY_WITHER_SKELETON_AMBIENT),
WOLF(Sound.ENTITY_WOLF_HURT, Sound.ENTITY_WOLF_STEP, Sound.ENTITY_WOLF_DEATH, Sound.ENTITY_WOLF_AMBIENT,
Sound.ENTITY_WOLF_GROWL, Sound.ENTITY_WOLF_PANT, Sound.ENTITY_WOLF_HOWL, Sound.ENTITY_WOLF_SHAKE,
Sound.ENTITY_WOLF_WHINE),
ZOMBIE(Sound.ENTITY_ZOMBIE_HURT, Sound.ENTITY_ZOMBIE_STEP, Sound.ENTITY_ZOMBIE_DEATH, Sound.ENTITY_ZOMBIE_AMBIENT,
Sound.ENTITY_ZOMBIE_INFECT, Sound.ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR, Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR,
Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR),
ZOMBIE_HORSE(Sound.ENTITY_ZOMBIE_HORSE_HURT, new Sound[]{Sound.BLOCK_GRASS_STEP, Sound.ENTITY_HORSE_STEP_WOOD},
Sound.ENTITY_ZOMBIE_HORSE_DEATH, Sound.ENTITY_ZOMBIE_HORSE_AMBIENT, Sound.ENTITY_HORSE_GALLOP,
Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND, Sound.ENTITY_HORSE_JUMP,
Sound.ENTITY_HORSE_ANGRY),
ZOMBIE_VILLAGER(Sound.ENTITY_ZOMBIE_VILLAGER_HURT, Sound.ENTITY_ZOMBIE_VILLAGER_STEP,
Sound.ENTITY_ZOMBIE_VILLAGER_DEATH, Sound.ENTITY_ZOMBIE_VILLAGER_AMBIENT, Sound.ENTITY_ZOMBIE_INFECT,
Sound.ENTITY_ZOMBIE_ATTACK_WOODEN_DOOR, Sound.ENTITY_ZOMBIE_BREAK_WOODEN_DOOR,
Sound.ENTITY_ZOMBIE_ATTACK_IRON_DOOR);
public enum SoundType { public enum SoundType {
CANCEL, CANCEL,
@ -173,196 +243,95 @@ public enum DisguiseSound {
} }
private float damageSoundVolume = 1F; private float damageSoundVolume = 1F;
private HashMap<Object, Object> disguiseSounds = new HashMap<>(); private LinkedHashMap<Object, SoundType> disguiseSounds = new LinkedHashMap<>();
DisguiseSound(Object hurt, Object step, Object death, Object idle, Object... sounds) { DisguiseSound(Object hurt, Object step, Object death, Object idle, Sound... sounds) {
addSound(hurt, SoundType.HURT); addSound(hurt, SoundType.HURT);
addSound(step, SoundType.STEP); addSound(step, SoundType.STEP);
addSound(death, SoundType.DEATH); addSound(death, SoundType.DEATH);
addSound(idle, SoundType.IDLE); addSound(idle, SoundType.IDLE);
for (Object obj : sounds) { for (Sound obj : sounds) {
addSound(obj, SoundType.CANCEL); 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);
}
}
public static void replace(String oldString, String newString) {
for (DisguiseSound sound : DisguiseSound.values()) {
if (sound.disguiseSounds.containsKey(oldString)) {
sound.disguiseSounds.put(newString, sound.disguiseSounds.get(oldString));
}
for (Entry<Object, Object> entry : sound.disguiseSounds.entrySet()) {
if (entry.getValue() == null || !entry.getValue().equals(oldString))
continue;
entry.setValue(newString);
}
}
}
private void addSound(Object sound, SoundType type) { private void addSound(Object sound, SoundType type) {
String s;
if (sound == null) { if (sound == null) {
return; return;
} else if (sound instanceof String) {
s = (String) sound;
} else if (sound instanceof Sound) {
s = ReflectionManager.getCraftSound((Sound) sound);
} else {
throw new RuntimeException("Was given a unknown object " + sound);
} }
switch (type) { if (sound instanceof Sound) {
case HURT: addSound((Sound) sound, type);
disguiseSounds.put(SoundType.HURT, s); } else if (sound instanceof Sound[]) {
break; for (Sound s : (Sound[]) sound) {
case STEP: addSound(s, type);
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);
} }
} else {
throw new IllegalArgumentException("Was given an unknown object " + sound);
}
}
private void addSound(Sound sound, SoundType type) {
Object soundEffect = ReflectionManager.getCraftSound(sound);
if (disguiseSounds.containsKey(soundEffect)) {
System.out.println("Already doing " + sound);
}
disguiseSounds.put(soundEffect, type);
} }
public float getDamageAndIdleSoundVolume() { public float getDamageAndIdleSoundVolume() {
return damageSoundVolume; return damageSoundVolume;
} }
public String getSound(SoundType type) { public Object getSound(SoundType type) {
if (type == null) { if (type == null) {
return null; return null;
} }
if (disguiseSounds.containsKey(type)) { for (Entry<Object, SoundType> entry : disguiseSounds.entrySet()) {
return (String) disguiseSounds.get(type); if (entry.getValue() != type) {
} else if (disguiseSounds.containsValue(type)) {
for (Entry<Object, Object> entry : disguiseSounds.entrySet()) {
if (entry.getValue() != type)
continue; continue;
return (String) entry.getKey();
} }
return entry.getKey();
} }
return null; return null;
} }
public SoundType getSound(String sound) { public SoundType getSound(Object sound) {
if (sound == null) { if (sound == null) {
return null; return null;
} }
if (disguiseSounds.containsKey(sound)) { return disguiseSounds.get(sound);
return (SoundType) disguiseSounds.get(sound);
} 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. * Used to check if this sound name is owned by this disguise sound.
*/ */
public SoundType getType(String sound, boolean ignoreDamage) { public SoundType getType(Object sound, boolean ignoreDamage) {
if (sound == null) if (sound == null) {
return SoundType.CANCEL;
if (isCancelSound(sound)) {
return SoundType.CANCEL; return SoundType.CANCEL;
} }
/*if (disguiseSounds.containsKey(SoundType.STEP) && disguiseSounds.get(SoundType.STEP).startsWith("step.") SoundType soundType = getSound(sound);
&& sound.startsWith("step.")) {
return SoundType.STEP;
}*/
for (SoundType type : SoundType.values()) {
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;
}
} else {
for (Entry<Object, Object> entry : disguiseSounds.entrySet()) {
if (!Objects.equals(sound, entry.getKey()))
continue;
return (SoundType) entry.getValue();
}
}
}
if (soundType == SoundType.DEATH || (ignoreDamage && soundType == SoundType.HURT)) {
return null; return null;
} }
return soundType;
}
public boolean isCancelSound(String sound) { public boolean isCancelSound(String sound) {
return getSound(sound) == SoundType.CANCEL; return getSound(sound) == SoundType.CANCEL;
} }
/* public void removeSound(SoundType type, Sound sound) {
removeSound(type, ReflectionManager.getCraftSound(sound));
}
public void removeSound(SoundType type, String sound) {
if (type == SoundType.CANCEL) {
cancelSounds.remove(sound);
}
else {
disguiseSounds.remove(type);
}
}*/
public void setDamageAndIdleSoundVolume(float strength) { public void setDamageAndIdleSoundVolume(float strength) {
this.damageSoundVolume = strength; this.damageSoundVolume = strength;
} }
/* public void setSound(SoundType type, Sound sound) {
setSound(type, ReflectionManager.getCraftSound(sound));
}
public void setSound(SoundType type, String sound) {
if (type == SoundType.CANCEL) {
cancelSounds.add(sound);
}
else {
disguiseSounds.put(type, sound);
}
}*/
} }

View File

@ -1,39 +1,14 @@
package me.libraryaddict.disguise.utilities; package me.libraryaddict.disguise.utilities;
import java.util.HashMap;
import me.libraryaddict.disguise.disguisetypes.DisguiseType; import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import java.util.HashMap;
public class DisguiseValues { public class DisguiseValues {
private static HashMap<DisguiseType, DisguiseValues> values = new HashMap<>(); private static HashMap<DisguiseType, DisguiseValues> values = new HashMap<>();
public static DisguiseValues getDisguiseValues(DisguiseType type) { public static DisguiseValues getDisguiseValues(DisguiseType type) {
switch (type) {
case DONKEY:
case MULE:
case ZOMBIE_HORSE:
case SKELETON_HORSE:
type = DisguiseType.HORSE;
break;
case MINECART_CHEST:
case MINECART_COMMAND:
case MINECART_FURNACE:
case MINECART_HOPPER:
case MINECART_TNT:
case MINECART_MOB_SPAWNER:
type = DisguiseType.MINECART;
break;
case WITHER_SKELETON:
case STRAY:
type = DisguiseType.SKELETON;
break;
case ZOMBIE_VILLAGER:
type = DisguiseType.ZOMBIE;
break;
default:
break;
}
return values.get(type); return values.get(type);
} }

View File

@ -5,10 +5,7 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.disguisetypes.*; import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm; import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.bukkit.Art; import org.bukkit.*;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.TreeSpecies;
import org.bukkit.block.BlockFace; import org.bukkit.block.BlockFace;
import org.bukkit.entity.*; import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
@ -145,7 +142,7 @@ public class ReflectionFlagWatchers {
new ParamInfo(Villager.Profession.class, "Villager Profession", new ParamInfo(Villager.Profession.class, "Villager Profession",
"View all the professions you can set on a Zombie and Normal Villager"); "View all the professions you can set on a Zombie and Normal Villager");
new ParamInfo(BlockFace.class, Arrays.copyOf(BlockFace.values(), 6), new ParamInfo(BlockFace.class, Arrays.copyOf(BlockFace.values(), 6),
"Direction (North, East, South, West, " + "Up, Down)", "Direction (North, East, South, West, Up, Down)",
"View the directions usable on player setSleeping and shulker direction"); "View the directions usable on player setSleeping and shulker direction");
new ParamInfo(RabbitType.class, "Rabbit Type", "View the kinds of rabbits you can turn into"); new ParamInfo(RabbitType.class, "Rabbit Type", "View the kinds of rabbits you can turn into");
new ParamInfo(TreeSpecies.class, "Tree Species", "View the different types of tree species"); new ParamInfo(TreeSpecies.class, "Tree Species", "View the different types of tree species");
@ -154,6 +151,8 @@ public class ReflectionFlagWatchers {
new ParamInfo(Llama.Color.class, "Llama Color", "View all the colors you can use for a llama color"); new ParamInfo(Llama.Color.class, "Llama Color", "View all the colors you can use for a llama color");
new ParamInfo(Parrot.Variant.class, "Parrot Variant", "View the different colors a parrot can be"); new ParamInfo(Parrot.Variant.class, "Parrot Variant", "View the different colors a parrot can be");
new ParamInfo(Particle.class, "Particle", "The different particles of Minecraft"); new ParamInfo(Particle.class, "Particle", "The different particles of Minecraft");
new ParamInfo(TropicalFish.Pattern.class, "Pattern", "Patterns of a tropical fish");
new ParamInfo(DyeColor.class, "DyeColor", "Dye colors of many different colors");
ArrayList<String> potionEnums = new ArrayList<>(); ArrayList<String> potionEnums = new ArrayList<>();
@ -170,10 +169,11 @@ public class ReflectionFlagWatchers {
materials[i] = Material.values()[i].name(); materials[i] = Material.values()[i].name();
} }
new ParamInfo(ItemStack.class, "Item (id:damage), damage optional", new ParamInfo(ItemStack.class, "Item (Material:Damage:Amount:Glow), only Material required",
"An ItemStack compromised of " + "ID:Durability", materials); "An ItemStack compromised of Material:Durability", materials);
new ParamInfo(ItemStack[].class, "Four ItemStacks (id:damage,id:damage..), damage optional", new ParamInfo(ItemStack[].class,
"Four ItemStacks (Material:Damage:Amount:Glow,Material:Damage:Amount:Glow..), only Material required",
"Four ItemStacks separated by an ,", materials) { "Four ItemStacks separated by an ,", materials) {
@Override @Override
public String[] getEnums(String tabComplete) { public String[] getEnums(String tabComplete) {

View File

@ -278,9 +278,10 @@ public class ReflectionManager {
return getCraftConstructor(getCraftClass(className), parameters); return getCraftConstructor(getCraftClass(className), parameters);
} }
public static String getCraftSound(Sound sound) { public static Object getCraftSound(Sound sound) {
try { try {
return (String) getCraftClass("CraftSound").getMethod("getSound", Sound.class).invoke(null, sound); return getCraftClass("CraftSound").getMethod("getSoundEffect", String.class)
.invoke(null, getSoundString(sound));
} }
catch (Exception ex) { catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
@ -423,6 +424,16 @@ public class ReflectionManager {
return null; return null;
} }
public static Class getNmsClassIgnoreErrors(String className) {
try {
return Class.forName("net.minecraft.server." + getBukkitVersion() + "." + className);
}
catch (Exception ignored) {
}
return null;
}
public static Constructor getNmsConstructor(Class clazz, Class<?>... parameters) { public static Constructor getNmsConstructor(Class clazz, Class<?>... parameters) {
try { try {
Constructor declaredConstructor = clazz.getDeclaredConstructor(parameters); Constructor declaredConstructor = clazz.getDeclaredConstructor(parameters);
@ -618,23 +629,17 @@ public class ReflectionManager {
} }
public static Enum getSoundCategory(String category) { public static Enum getSoundCategory(String category) {
Method method = getNmsMethod("SoundCategory", "a", String.class);
try { try {
Enum invoke = (Enum) method.invoke(null, category.toLowerCase()); Method method = getNmsMethod("SoundCategory", "a");
if (invoke == null) { for (Enum anEnum : (Enum[]) getNmsClass("SoundCategory").getEnumConstants()) {
Class<?> clazz = getNmsClass("SoundCategory"); if (!category.equals(method.invoke(anEnum))) {
Enum[] enums = clazz != null ? (Enum[]) clazz.getEnumConstants() : null; continue;
}
for (Enum anEnum : enums != null ? enums : new Enum[0]) {
if (anEnum.name().equals(category.toUpperCase()))
return anEnum; return anEnum;
} }
} }
return invoke;
}
catch (Exception e) { catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
@ -747,29 +752,9 @@ public class ReflectionManager {
} }
} }
/** public static Object getSoundString(Sound sound) {
* Necessary for 1.9
*
* @return
*/
public static String convertSoundEffectToString(Object soundEffect) {
try { try {
Field f_getMinecraftKey = getNmsField("SoundEffect", "b"); return getCraftMethod("CraftSound", "getSound", Sound.class).invoke(null, sound);
f_getMinecraftKey.setAccessible(true);
MinecraftKey key = MinecraftKey.fromHandle(f_getMinecraftKey.get(soundEffect));
return key.getKey();
}
catch (IllegalAccessException e) {
e.printStackTrace();
}
return null;
}
public static Object getCraftSoundEffect(String sound) {
try {
return getCraftMethod("CraftSound", "getSoundEffect", String.class).invoke(null, sound);
} }
catch (IllegalAccessException | InvocationTargetException e) { catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace(); e.printStackTrace();
@ -944,15 +929,16 @@ public class ReflectionManager {
public static int getEntityType(Object nmsEntity) { public static int getEntityType(Object nmsEntity) {
try { try {
Class classType = getNmsClass("EntityTypes"); Field entityTypesField = null;
for (Method m : getNmsClass("Entity").getMethods()) { for (Method method : getNmsClass("Entity").getMethods()) {
if (m.getReturnType() != classType) { if (!method.getReturnType().getSimpleName().equals("EntityTypes"))
continue; continue;
}
Object entityType = m.invoke(nmsEntity); Object entityType = method.invoke(nmsEntity);
Object registry = classType.getField("REGISTRY").get(null); Class typesClass = getNmsClass("EntityTypes");
Object registry = typesClass.getField("REGISTRY").get(null);
return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityType); return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityType);
} }
@ -961,7 +947,7 @@ public class ReflectionManager {
ex.printStackTrace(); ex.printStackTrace();
} }
return 0; throw new IllegalStateException("Failed to find EntityType for " + nmsEntity.getClass().getSimpleName());
} }
public static WrappedWatchableObject createWatchable(int index, Object obj) { public static WrappedWatchableObject createWatchable(int index, Object obj) {

View File

@ -17,6 +17,7 @@ import me.libraryaddict.disguise.utilities.DisguiseSound.SoundType;
import me.libraryaddict.disguise.utilities.DisguiseUtilities; import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import me.libraryaddict.disguise.utilities.ReflectionManager; import me.libraryaddict.disguise.utilities.ReflectionManager;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.block.Block; import org.bukkit.block.Block;
import org.bukkit.entity.*; import org.bukkit.entity.*;
@ -28,9 +29,12 @@ public class PacketListenerSounds extends PacketAdapter {
* "I can't separate the sounds from the sounds the player heard, and the sounds of the entity tracker heard" * "I can't separate the sounds from the sounds the player heard, and the sounds of the entity tracker heard"
*/ */
private static boolean cancelSound; private static boolean cancelSound;
private Object stepSoundEffect;
public PacketListenerSounds(LibsDisguises plugin) { public PacketListenerSounds(LibsDisguises plugin) {
super(plugin, ListenerPriority.NORMAL, Server.NAMED_SOUND_EFFECT, Server.ENTITY_STATUS); super(plugin, ListenerPriority.NORMAL, Server.NAMED_SOUND_EFFECT, Server.ENTITY_STATUS);
stepSoundEffect = ReflectionManager.getCraftSound(Sound.BLOCK_GRASS_STEP);
} }
@Override @Override
@ -69,7 +73,7 @@ public class PacketListenerSounds extends PacketAdapter {
Disguise disguise = null; Disguise disguise = null;
String soundEffect = ReflectionManager.convertSoundEffectToString(mods.read(0)); Object soundEffectObj = mods.read(0);
Entity[] entities = observer.getWorld().getChunkAt(chunkX, chunkZ).getEntities(); Entity[] entities = observer.getWorld().getChunkAt(chunkX, chunkZ).getEntities();
for (Entity entity : entities) { for (Entity entity : entities) {
@ -129,7 +133,7 @@ public class PacketListenerSounds extends PacketAdapter {
ex.printStackTrace(); ex.printStackTrace();
} }
soundType = entitySound.getType(soundEffect, !hasInvun); soundType = entitySound.getType(soundEffectObj, !hasInvun);
} }
if (soundType != null) { if (soundType != null) {
@ -142,12 +146,13 @@ public class PacketListenerSounds extends PacketAdapter {
if (disguise != null && disguise.isSoundsReplaced() && if (disguise != null && disguise.isSoundsReplaced() &&
(disguise.isSelfDisguiseSoundsReplaced() || disguisedEntity != observer)) { (disguise.isSelfDisguiseSoundsReplaced() || disguisedEntity != observer)) {
String sound = null; Object sound = null;
DisguiseSound dSound = DisguiseSound.getType(disguise.getType().name()); DisguiseSound disguiseSound = DisguiseSound.getType(disguise.getType().name());
if (dSound != null) if (disguiseSound != null) {
sound = dSound.getSound(soundType); sound = disguiseSound.getSound(soundType);
}
if (sound == null) { if (sound == null) {
event.setCancelled(true); event.setCancelled(true);
@ -174,7 +179,7 @@ public class PacketListenerSounds extends PacketAdapter {
// someone is // someone is
// sending fake sounds. In which case. Why cancel it. // sending fake sounds. In which case. Why cancel it.
} else { } else {
mods.write(0, ReflectionManager.getCraftSoundEffect(sound)); mods.write(0, sound);
mods.write(1, ReflectionManager.getSoundCategory(disguise.getType())); mods.write(1, ReflectionManager.getSoundCategory(disguise.getType()));
// Time to change the pitch and volume // Time to change the pitch and volume
@ -182,7 +187,7 @@ public class PacketListenerSounds extends PacketAdapter {
soundType == SoundType.IDLE) { soundType == SoundType.IDLE) {
// If the volume is the default // If the volume is the default
if (mods.read(5).equals(entitySound.getDamageAndIdleSoundVolume())) { if (mods.read(5).equals(entitySound.getDamageAndIdleSoundVolume())) {
mods.write(5, dSound.getDamageAndIdleSoundVolume()); mods.write(5, disguiseSound.getDamageAndIdleSoundVolume());
} }
// Here I assume its the default pitch as I can't calculate if its real. // Here I assume its the default pitch as I can't calculate if its real.
@ -289,7 +294,7 @@ public class PacketListenerSounds extends PacketAdapter {
disSound = DisguiseSound.getType(disguise.getType().name()); disSound = DisguiseSound.getType(disguise.getType().name());
if (disSound != null) { if (disSound != null) {
String sound = disSound.getSound(soundType); Object sound = disSound.getSound(soundType);
if (sound != null) { if (sound != null) {
Location loc = entity.getLocation(); Location loc = entity.getLocation();
@ -298,9 +303,7 @@ public class PacketListenerSounds extends PacketAdapter {
mods = packet.getModifier(); mods = packet.getModifier();
Object craftSoundEffect = ReflectionManager.getCraftSoundEffect(sound); mods.write(0, sound);
mods.write(0, craftSoundEffect);
mods.write(1, ReflectionManager.getSoundCategory(disguise.getType())); // Meh mods.write(1, ReflectionManager.getSoundCategory(disguise.getType())); // Meh
mods.write(2, (int) (loc.getX() * 8D)); mods.write(2, (int) (loc.getX() * 8D));
mods.write(3, (int) (loc.getY() * 8D)); mods.write(3, (int) (loc.getY() * 8D));