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

View File

@ -22,14 +22,20 @@ public enum DisguiseType {
CHICKEN,
COD,
COW,
CREEPER,
DOLPHIN,
DONKEY,
DRAGON_FIREBALL(93),
DROWNED,
DROPPED_ITEM(2, 1),
EGG(62),
@ -110,6 +116,8 @@ public enum DisguiseType {
PARROT,
PHANTOM,
PIG,
PIG_ZOMBIE,
@ -120,8 +128,12 @@ public enum DisguiseType {
PRIMED_TNT(50),
PUFFERFISH,
RABBIT,
SALMON,
SHEEP,
SHULKER,
@ -156,6 +168,12 @@ public enum DisguiseType {
TIPPED_ARROW(60),
TRIDENT(94, 0),
TROPICAL_FISH,
TURTLE,
ZOMBIE_HORSE,
UNKNOWN,
@ -181,37 +199,10 @@ public enum DisguiseType {
ZOMBIE_VILLAGER;
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()) {
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));
}
catch (Throwable ex) {
// This version of Spigot doesn't have the disguise.
}
type.setEntityType(EntityType.valueOf(name));
}
}

View File

@ -1,7 +1,10 @@
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.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.NbtFactory;
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,
false);
public static MetaIndex<Particle> AREA_EFFECT_PARTICLE = new MetaIndex<>(AreaEffectCloudWatcher.class,
3, Particle.SPELL_MOB);
public static MetaIndex<Particle> AREA_EFFECT_PARTICLE = new MetaIndex<>(AreaEffectCloudWatcher.class, 3,
Particle.SPELL_MOB);
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<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,
new ItemStack(Material.STONE));
@ -111,6 +121,8 @@ public class MetaIndex<Y> {
public static MetaIndex<ItemStack> FIREWORK_ITEM = new MetaIndex<>(FireworkWatcher.class, 0,
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> 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<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> 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<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<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<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,
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<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<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<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 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 TRIDENT: // Unknown. Uses 1 + (entityId of target, or shooter)
this.data = id;
break;
default:

View File

@ -1,23 +1,19 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
public class ArrowWatcher extends FlagWatcher
{
public ArrowWatcher(Disguise disguise)
{
public class ArrowWatcher extends FlagWatcher {
public ArrowWatcher(Disguise disguise) {
super(disguise);
}
public boolean isCritical()
{
public boolean isCritical() {
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));
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;
import org.bukkit.Color;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import org.bukkit.Color;
/**
* @author Navid
*/
public class TippedArrowWatcher extends ArrowWatcher
{
public TippedArrowWatcher(Disguise disguise)
{
public class TippedArrowWatcher extends ArrowWatcher {
public TippedArrowWatcher(Disguise disguise) {
super(disguise);
int r = DisguiseUtilities.random.nextInt(256);
@ -23,14 +19,12 @@ public class TippedArrowWatcher extends ArrowWatcher
setColor(Color.fromRGB(r, g, b));
}
public Color getColor()
{
public Color getColor() {
int color = (int) getData(MetaIndex.TIPPED_ARROW_COLOR);
return Color.fromRGB(color);
}
public void setColor(Color color)
{
public void setColor(Color color) {
setData(MetaIndex.TIPPED_ARROW_COLOR, color.asRGB());
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.MetaIndex;
public class VindicatorWatcher extends InsentientWatcher {
public class VindicatorWatcher extends IllagerWatcher {
public VindicatorWatcher(Disguise disguise) {
super(disguise);
}
public void setJohnny(boolean isJohnny) {
setData(MetaIndex.VINDICATOR_JOHNNY, (byte) (isJohnny ? 1 : 0));
sendData(MetaIndex.VINDICATOR_JOHNNY);
setData(MetaIndex.ILLAGER_META, (byte) (isJohnny ? 1 : 0));
sendData(MetaIndex.ILLAGER_META);
}
}

View File

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

View File

@ -1,159 +1,229 @@
package me.libraryaddict.disguise.utilities;
import java.util.HashMap;
import java.util.Map.Entry;
import java.util.Objects;
import org.bukkit.Sound;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.Map.Entry;
/**
* Only living disguises go in here!
*/
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",
"entity.bat.loop", "entity.player.big_fall", "entity.bat.takeoff"),
ARROW(null, null, null, null, Sound.ENTITY_ARROW_HIT, Sound.ENTITY_ARROW_SHOOT),
BLAZE("entity.blaze.hurt", null, "entity.blaze.death", "entity.blaze.ambient", "entity.player.small_fall",
"entity.player.big_fall"),
BAT(Sound.ENTITY_BAT_HURT, null, Sound.ENTITY_BAT_DEATH, Sound.ENTITY_BAT_AMBIENT, Sound.ENTITY_PLAYER_SMALL_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",
"entity.player.small_fall", "entity.chicken.egg", "entity.player.big_fall"),
BOAT(null, Sound.ENTITY_BOAT_PADDLE_WATER, null, null, Sound.ENTITY_BOAT_PADDLE_LAND),
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",
"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"),
COD(Sound.ENTITY_COD_HURT, null, Sound.ENTITY_COD_DEATH, Sound.ENTITY_COD_AMBIENT, Sound.ENTITY_COD_FLOP,
Sound.ENTITY_FISH_SWIM),
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",
"entity.player.small_fall", "entity.enderdragon.flap", "entity.player.big_fall"),
CREEPER(Sound.ENTITY_CREEPER_HURT, Sound.BLOCK_GRASS_STEP, Sound.ENTITY_CREEPER_DEATH, null,
Sound.ENTITY_CREEPER_PRIMED),
ENDERMAN("entity.endermen.hurt", "block.grass.step", "entity.endermen.death", "entity.endermen.ambient",
"entity.endermen.scream", "entity.endermen.teleport", "entity.endermen.stare"),
DOLPHIN(Sound.ENTITY_DOLPHIN_HURT, Sound.ENTITY_DOLPHIN_SWIM, Sound.ENTITY_DOLPHIN_DEATH,
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",
"entity.evocation_illager.cast_spell", "entity.evocation_illager.prepare_attack",
"entity.evocation_illager.prepare_summon", "entity.evocation_illager.prepare_wololo"),
DROWNED(new Sound[]{Sound.ENTITY_DROWNED_HURT, Sound.ENTITY_DROWNED_HURT_WATER},
new Sound[]{Sound.ENTITY_DROWNED_STEP, Sound.ENTITY_DROWNED_SWIM},
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",
"entity.ghast.shoot", "entity.player.big_fall", "entity.ghast.scream", "entity.ghast.warn"),
ENDER_DRAGON(Sound.ENTITY_ENDER_DRAGON_HURT, null, Sound.ENTITY_ENDER_DRAGON_DEATH,
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",
"entity.horse.saddle", "entity.donkey.angry", "entity.horse.step_wood", "entity.horse.armor",
"entity.horse.land", "entity.horse.jump", "entity.horse.angry"),
EVOKER(Sound.ENTITY_EVOKER_HURT, null, Sound.ENTITY_EVOKER_DEATH, Sound.ENTITY_EVOKER_AMBIENT,
Sound.ENTITY_EVOKER_CAST_SPELL, Sound.ENTITY_EVOKER_PREPARE_ATTACK, Sound.ENTITY_EVOKER_PREPARE_SUMMON,
Sound.ENTITY_EVOKER_PREPARE_WOLOLO),
ILLUSIONER("entity.illusion_illager.hurt", null, "entity.illusion_illager.death", "entity.illusion_illager.ambient",
"entity.illusion_illager.cast_spell", "entity.illusion_illager.prepare_blindness",
"entity.illusion_illager.prepare_mirror", "entity.illusion_illager.mirror_move"),
EVOKER_FANGS(null, null, null, null, Sound.ENTITY_EVOKER_FANGS_ATTACK),
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",
"entity.llama.chest", "entity.llama.eat", "entity.llama.swag"),
GIANT(Sound.ENTITY_PLAYER_HURT, Sound.BLOCK_GRASS_STEP, null, null),
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",
"entity.cat.purreow"),
ILLUSIONER(Sound.ENTITY_ILLUSIONER_HURT, null, Sound.ENTITY_ILLUSIONER_DEATH, Sound.ENTITY_ILLUSIONER_AMBIENT,
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",
"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"),
IRON_GOLEM(Sound.ENTITY_IRON_GOLEM_HURT, Sound.ENTITY_IRON_GOLEM_STEP, Sound.ENTITY_IRON_GOLEM_DEATH,
Sound.ENTITY_IRON_GOLEM_ATTACK),
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",
"entity.zombie_pig.angry"),
MAGMA_CUBE(Sound.ENTITY_MAGMA_CUBE_HURT, Sound.ENTITY_MAGMA_CUBE_JUMP,
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",
new String[]{"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),
MULE(Sound.ENTITY_MULE_HURT, Sound.BLOCK_GRASS_STEP, Sound.ENTITY_MULE_DEATH, Sound.ENTITY_MULE_AMBIENT,
Sound.ENTITY_MULE_CHEST),
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",
"entity.shulker.close", "entity.shulker.hurt_closed", "entity.shulker.teleport"),
PARROT(Sound.ENTITY_PARROT_HURT, Sound.ENTITY_PARROT_STEP, Sound.ENTITY_PARROT_DEATH, Sound.ENTITY_PARROT_AMBIENT,
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",
"entity.silverfish.ambient"),
PIG(Sound.ENTITY_PIG_HURT, Sound.ENTITY_PIG_STEP, Sound.ENTITY_PIG_DEATH, Sound.ENTITY_PIG_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",
"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"),
PLAYER(Sound.ENTITY_PLAYER_HURT, Arrays.stream(Sound.values())
.filter(sound -> sound.name().startsWith("BLOCK_") && sound.name().endsWith("_STEP")).toArray(Sound[]::new),
Sound.ENTITY_PLAYER_DEATH, null),
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",
"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"),
SALMON(Sound.ENTITY_SALMON_HURT, null, Sound.ENTITY_SALMON_DEATH, Sound.ENTITY_SALMON_AMBIENT,
Sound.ENTITY_SALMON_FLOP, Sound.ENTITY_FISH_SWIM),
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",
"entity.villager.trading", "entity.villager.no", "entity.villager.yes"),
SHULKER(new Sound[]{Sound.ENTITY_SHULKER_HURT, Sound.ENTITY_SHULKER_HURT_CLOSED}, null, Sound.ENTITY_SHULKER_DEATH,
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",
"entity.vindication_illager.ambient"),
SILVERFISH(Sound.ENTITY_SILVERFISH_HURT, Sound.ENTITY_SILVERFISH_STEP, Sound.ENTITY_SILVERFISH_DEATH,
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",
"entity.wither.spawn", "entity.player.big_fall", "entity.wither.shoot"),
SKELETON_HORSE(Sound.ENTITY_SKELETON_HORSE_HURT, new Sound[]{Sound.BLOCK_GRASS_STEP, Sound.ENTITY_HORSE_STEP_WOOD},
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",
"entity.wolf.pant", "entity.wolf.howl", "entity.wolf.shake", "entity.wolf.whine"),
SNOWMAN(Sound.ENTITY_SNOW_GOLEM_HURT, null, Sound.ENTITY_SNOW_GOLEM_DEATH, Sound.ENTITY_SNOW_GOLEM_AMBIENT,
Sound.ENTITY_SNOW_GOLEM_SHOOT),
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"),
SPIDER(Sound.ENTITY_SPIDER_HURT, Sound.ENTITY_SPIDER_STEP, Sound.ENTITY_SPIDER_DEATH, Sound.ENTITY_SPIDER_AMBIENT),
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");
STRAY(Sound.ENTITY_STRAY_HURT, Sound.ENTITY_STRAY_STEP, Sound.ENTITY_STRAY_DEATH, Sound.ENTITY_STRAY_AMBIENT),
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 {
CANCEL,
@ -173,196 +243,95 @@ public enum DisguiseSound {
}
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(step, SoundType.STEP);
addSound(death, SoundType.DEATH);
addSound(idle, SoundType.IDLE);
for (Object obj : sounds) {
for (Sound 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);
}
}
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) {
String s;
if (sound == null) {
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) {
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);
if (sound instanceof Sound) {
addSound((Sound) sound, type);
} else if (sound instanceof Sound[]) {
for (Sound s : (Sound[]) sound) {
addSound(s, type);
}
} 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() {
return damageSoundVolume;
}
public String getSound(SoundType type) {
public Object getSound(SoundType type) {
if (type == null) {
return null;
}
if (disguiseSounds.containsKey(type)) {
return (String) disguiseSounds.get(type);
} else if (disguiseSounds.containsValue(type)) {
for (Entry<Object, Object> entry : disguiseSounds.entrySet()) {
if (entry.getValue() != type)
continue;
return (String) entry.getKey();
for (Entry<Object, SoundType> entry : disguiseSounds.entrySet()) {
if (entry.getValue() != type) {
continue;
}
return entry.getKey();
}
return null;
}
public SoundType getSound(String sound) {
public SoundType getSound(Object sound) {
if (sound == null) {
return null;
}
if (disguiseSounds.containsKey(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;
return disguiseSounds.get(sound);
}
/**
* 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)) {
public SoundType getType(Object sound, boolean ignoreDamage) {
if (sound == null) {
return SoundType.CANCEL;
}
/*if (disguiseSounds.containsKey(SoundType.STEP) && disguiseSounds.get(SoundType.STEP).startsWith("step.")
&& sound.startsWith("step.")) {
return SoundType.STEP;
}*/
SoundType soundType = getSound(sound);
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) {
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) {
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;
import java.util.HashMap;
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
import java.util.HashMap;
public class DisguiseValues {
private static HashMap<DisguiseType, DisguiseValues> values = new HashMap<>();
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);
}

View File

@ -5,10 +5,7 @@ import com.comphenix.protocol.wrappers.WrappedGameProfile;
import me.libraryaddict.disguise.disguisetypes.*;
import me.libraryaddict.disguise.utilities.DisguiseParser.DisguisePerm;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Art;
import org.bukkit.Material;
import org.bukkit.Particle;
import org.bukkit.TreeSpecies;
import org.bukkit.*;
import org.bukkit.block.BlockFace;
import org.bukkit.entity.*;
import org.bukkit.inventory.ItemStack;
@ -145,7 +142,7 @@ public class ReflectionFlagWatchers {
new ParamInfo(Villager.Profession.class, "Villager Profession",
"View all the professions you can set on a Zombie and Normal Villager");
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");
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");
@ -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(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(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<>();
@ -170,10 +169,11 @@ public class ReflectionFlagWatchers {
materials[i] = Material.values()[i].name();
}
new ParamInfo(ItemStack.class, "Item (id:damage), damage optional",
"An ItemStack compromised of " + "ID:Durability", materials);
new ParamInfo(ItemStack.class, "Item (Material:Damage:Amount:Glow), only Material required",
"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) {
@Override
public String[] getEnums(String tabComplete) {

View File

@ -278,9 +278,10 @@ public class ReflectionManager {
return getCraftConstructor(getCraftClass(className), parameters);
}
public static String getCraftSound(Sound sound) {
public static Object getCraftSound(Sound sound) {
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) {
ex.printStackTrace();
@ -423,6 +424,16 @@ public class ReflectionManager {
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) {
try {
Constructor declaredConstructor = clazz.getDeclaredConstructor(parameters);
@ -618,22 +629,16 @@ public class ReflectionManager {
}
public static Enum getSoundCategory(String category) {
Method method = getNmsMethod("SoundCategory", "a", String.class);
try {
Enum invoke = (Enum) method.invoke(null, category.toLowerCase());
Method method = getNmsMethod("SoundCategory", "a");
if (invoke == null) {
Class<?> clazz = getNmsClass("SoundCategory");
Enum[] enums = clazz != null ? (Enum[]) clazz.getEnumConstants() : null;
for (Enum anEnum : enums != null ? enums : new Enum[0]) {
if (anEnum.name().equals(category.toUpperCase()))
return anEnum;
for (Enum anEnum : (Enum[]) getNmsClass("SoundCategory").getEnumConstants()) {
if (!category.equals(method.invoke(anEnum))) {
continue;
}
}
return invoke;
return anEnum;
}
}
catch (Exception e) {
e.printStackTrace();
@ -747,29 +752,9 @@ public class ReflectionManager {
}
}
/**
* Necessary for 1.9
*
* @return
*/
public static String convertSoundEffectToString(Object soundEffect) {
public static Object getSoundString(Sound sound) {
try {
Field f_getMinecraftKey = getNmsField("SoundEffect", "b");
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);
return getCraftMethod("CraftSound", "getSound", Sound.class).invoke(null, sound);
}
catch (IllegalAccessException | InvocationTargetException e) {
e.printStackTrace();
@ -944,15 +929,16 @@ public class ReflectionManager {
public static int getEntityType(Object nmsEntity) {
try {
Class classType = getNmsClass("EntityTypes");
Field entityTypesField = null;
for (Method m : getNmsClass("Entity").getMethods()) {
if (m.getReturnType() != classType) {
for (Method method : getNmsClass("Entity").getMethods()) {
if (!method.getReturnType().getSimpleName().equals("EntityTypes"))
continue;
}
Object entityType = m.invoke(nmsEntity);
Object registry = classType.getField("REGISTRY").get(null);
Object entityType = method.invoke(nmsEntity);
Class typesClass = getNmsClass("EntityTypes");
Object registry = typesClass.getField("REGISTRY").get(null);
return (int) registry.getClass().getMethod("a", Object.class).invoke(registry, entityType);
}
@ -961,7 +947,7 @@ public class ReflectionManager {
ex.printStackTrace();
}
return 0;
throw new IllegalStateException("Failed to find EntityType for " + nmsEntity.getClass().getSimpleName());
}
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.ReflectionManager;
import org.bukkit.Location;
import org.bukkit.Sound;
import org.bukkit.block.Block;
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"
*/
private static boolean cancelSound;
private Object stepSoundEffect;
public PacketListenerSounds(LibsDisguises plugin) {
super(plugin, ListenerPriority.NORMAL, Server.NAMED_SOUND_EFFECT, Server.ENTITY_STATUS);
stepSoundEffect = ReflectionManager.getCraftSound(Sound.BLOCK_GRASS_STEP);
}
@Override
@ -69,7 +73,7 @@ public class PacketListenerSounds extends PacketAdapter {
Disguise disguise = null;
String soundEffect = ReflectionManager.convertSoundEffectToString(mods.read(0));
Object soundEffectObj = mods.read(0);
Entity[] entities = observer.getWorld().getChunkAt(chunkX, chunkZ).getEntities();
for (Entity entity : entities) {
@ -129,7 +133,7 @@ public class PacketListenerSounds extends PacketAdapter {
ex.printStackTrace();
}
soundType = entitySound.getType(soundEffect, !hasInvun);
soundType = entitySound.getType(soundEffectObj, !hasInvun);
}
if (soundType != null) {
@ -142,12 +146,13 @@ public class PacketListenerSounds extends PacketAdapter {
if (disguise != null && disguise.isSoundsReplaced() &&
(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)
sound = dSound.getSound(soundType);
if (disguiseSound != null) {
sound = disguiseSound.getSound(soundType);
}
if (sound == null) {
event.setCancelled(true);
@ -174,7 +179,7 @@ public class PacketListenerSounds extends PacketAdapter {
// someone is
// sending fake sounds. In which case. Why cancel it.
} else {
mods.write(0, ReflectionManager.getCraftSoundEffect(sound));
mods.write(0, sound);
mods.write(1, ReflectionManager.getSoundCategory(disguise.getType()));
// Time to change the pitch and volume
@ -182,7 +187,7 @@ public class PacketListenerSounds extends PacketAdapter {
soundType == SoundType.IDLE) {
// If the volume is the default
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.
@ -289,7 +294,7 @@ public class PacketListenerSounds extends PacketAdapter {
disSound = DisguiseSound.getType(disguise.getType().name());
if (disSound != null) {
String sound = disSound.getSound(soundType);
Object sound = disSound.getSound(soundType);
if (sound != null) {
Location loc = entity.getLocation();
@ -298,9 +303,7 @@ public class PacketListenerSounds extends PacketAdapter {
mods = packet.getModifier();
Object craftSoundEffect = ReflectionManager.getCraftSoundEffect(sound);
mods.write(0, craftSoundEffect);
mods.write(0, sound);
mods.write(1, ReflectionManager.getSoundCategory(disguise.getType())); // Meh
mods.write(2, (int) (loc.getX() * 8D));
mods.write(3, (int) (loc.getY() * 8D));