Fixed Misc disguises

Added AreaEffectCloudWatcher
Readded regular Arrows
Updated object ids
Updated relative look and move packets
Minor changes here and there
This commit is contained in:
NavidK0 2016-03-12 15:19:58 -05:00
parent 7dabbb7ce4
commit 8eb4beba83
16 changed files with 164 additions and 92 deletions

View File

@ -26,7 +26,6 @@ import org.bukkit.inventory.ItemStack;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Collection;
@ -205,13 +204,11 @@ public class DisguiseAPI {
disguise = disguise.clone();
}
try {
Field field = ReflectionManager.getNmsClass("Entity").getDeclaredField("entityCount");
field.setAccessible(true);
int id = field.getInt(null);
int id = ReflectionManager.getNmsField("Entity", "entityCount").getInt(null);
DisguiseUtilities.addFutureDisguise(id, (TargetedDisguise) disguise);
return id;
} catch (NoSuchFieldException | SecurityException | IllegalArgumentException | IllegalAccessException ex) {
ex.printStackTrace(System.out);
} catch (IllegalAccessException e) {
e.printStackTrace();
}
return -1;
}

View File

@ -36,7 +36,6 @@ import org.bukkit.scheduler.BukkitTask;
import java.lang.reflect.InvocationTargetException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;
public class DisguiseListener implements Listener {
@ -218,7 +217,7 @@ public class DisguiseListener implements Listener {
while (reference == null && attempts++ < 1000) {
reference = "@";
for (int i = 0; i < referenceLength; i++) {
reference += alphabet[new Random().nextInt(alphabet.length)];
reference += alphabet[DisguiseUtilities.random.nextInt(alphabet.length)];
}
if (DisguiseUtilities.getClonedDisguise(reference) != null) {
reference = null;

View File

@ -25,7 +25,6 @@ import me.libraryaddict.disguise.disguisetypes.watchers.MinecartWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SkeletonWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.SlimeWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.TameableWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.TippedArrowWatcher;
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
import me.libraryaddict.disguise.utilities.DisguiseSound;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
@ -137,9 +136,6 @@ public class LibsDisguises extends JavaPlugin {
case WITHER_SKELETON:
watcherClass = SkeletonWatcher.class;
break;
case ARROW:
watcherClass = TippedArrowWatcher.class;
break;
default:
watcherClass = Class.forName("me.libraryaddict.disguise.disguisetypes.watchers."
+ toReadable(disguiseType.name()) + "Watcher");
@ -240,7 +236,6 @@ public class LibsDisguises extends JavaPlugin {
for (WrappedWatchableObject watch : watcher.getWatchableObjects()) {
disguiseValues.setMetaValue(watch.getIndex(), watch.getValue());
// Uncomment when I need to find the new datawatcher values for a class..
//TODO: Recomment this section when finished
int id = watch.getIndex();
Object val = watch.getValue();
Class<?> valClazz = val != null ? watch.getValue().getClass() : null;

View File

@ -37,7 +37,6 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.UUID;
public abstract class Disguise {
@ -106,7 +105,7 @@ public abstract class Disguise {
((SkeletonWatcher)getWatcher()).setType(SkeletonType.WITHER);
} // Else if its a zombie, but the disguise type is a zombie villager. Set the value.
else if (getType() == DisguiseType.ZOMBIE_VILLAGER) {
((ZombieWatcher)getWatcher()).setProfession(Profession.values()[new Random().nextInt(Profession.values().length)]);
((ZombieWatcher)getWatcher()).setProfession(Profession.values()[DisguiseUtilities.random.nextInt(Profession.values().length)]);
} else if (getType() == DisguiseType.ELDER_GUARDIAN) {
((GuardianWatcher)getWatcher()).setElder(true);
} // Else if its a horse. Set the horse watcher type
@ -145,6 +144,7 @@ public abstract class Disguise {
case WITHER_SKULL:
velocitySpeed = 0.000001D;
break;
case ARROW:
case TIPPED_ARROW:
case SPECTRAL_ARROW:
case BOAT:

View File

@ -12,47 +12,47 @@ import java.lang.reflect.Method;
public enum DisguiseType {
AREA_EFFECT_CLOUD,
ARMOR_STAND,
ARROW,
AREA_EFFECT_CLOUD(3, 0),
ARMOR_STAND(78),
ARROW(60, 0),
BAT,
BLAZE,
BOAT,
BOAT(1),
CAVE_SPIDER,
CHICKEN,
COW,
CREEPER,
DONKEY,
DRAGON_FIREBALL,
DROPPED_ITEM(1),
EGG,
DRAGON_FIREBALL(93),
DROPPED_ITEM(1, 1),
EGG(62),
ELDER_GUARDIAN,
ENDER_CRYSTAL,
ENDER_CRYSTAL(51),
ENDER_DRAGON,
ENDER_PEARL,
ENDER_SIGNAL,
ENDER_PEARL(65),
ENDER_SIGNAL(72),
ENDERMAN,
ENDERMITE,
EXPERIENCE_ORB,
FALLING_BLOCK(1),
FIREBALL(0),
FIREWORK,
FISHING_HOOK,
FALLING_BLOCK(70, 1),
FIREBALL(63),
FIREWORK(76),
FISHING_HOOK(90),
GHAST,
GIANT,
GUARDIAN,
HORSE,
IRON_GOLEM,
ITEM_FRAME,
LEASH_HITCH,
ITEM_FRAME(71),
LEASH_HITCH(77),
MAGMA_CUBE,
MINECART,
MINECART_CHEST(1),
MINECART_COMMAND(6),
MINECART_FURNACE(2),
MINECART_HOPPER(5),
MINECART_MOB_SPAWNER(4),
MINECART_TNT(5),
MINECART(10),
MINECART_CHEST(10, 1),
MINECART_COMMAND(10, 6),
MINECART_FURNACE(10, 2),
MINECART_HOPPER(10, 5),
MINECART_MOB_SPAWNER(10, 4),
MINECART_TNT(10, 3),
MULE,
MUSHROOM_COW,
OCELOT,
@ -60,30 +60,30 @@ public enum DisguiseType {
PIG,
PIG_ZOMBIE,
PLAYER,
PRIMED_TNT,
PRIMED_TNT(50),
RABBIT,
SHEEP,
SHULKER,
SHULKER_BULLET,
SHULKER_BULLET(67),
SILVERFISH,
SKELETON,
SKELETON_HORSE,
SLIME,
SMALL_FIREBALL(0),
SNOWBALL,
SMALL_FIREBALL(63),
SNOWBALL(61),
SNOWMAN,
SPECTRAL_ARROW,
SPECTRAL_ARROW(91),
SPIDER,
SPLASH_POTION,
SPLASH_POTION(73, 0),
SQUID,
TIPPED_ARROW,
THROWN_EXP_BOTTLE,
TIPPED_ARROW(92),
THROWN_EXP_BOTTLE(75),
UNDEAD_HORSE,
VILLAGER,
WITCH,
WITHER,
WITHER_SKELETON,
WITHER_SKULL,
WITHER_SKULL(66),
WOLF,
ZOMBIE,
ZOMBIE_VILLAGER,
@ -97,6 +97,7 @@ public enum DisguiseType {
for (DisguiseType type : values()) {
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.
@ -117,12 +118,11 @@ public enum DisguiseType {
case ELDER_GUARDIAN:
toUse = DisguiseType.GUARDIAN;
break;
case ARROW:
toUse = DisguiseType.TIPPED_ARROW;
default:
break;
}
type.setEntityType(EntityType.valueOf(toUse.name()));
name = toUse.name();
type.setEntityType(EntityType.valueOf(name));
} catch (Throwable ex) {
// This version of Spigot doesn't have the disguise.
}
@ -199,7 +199,7 @@ public enum DisguiseType {
}
}
private int defaultData = -1;
private int objectId = -1, defaultData = 0;
private EntityType entityType;
private Class<? extends FlagWatcher> watcherClass;
@ -208,6 +208,9 @@ public enum DisguiseType {
int value = ints[i];
switch (i) {
case 0:
objectId = value;
break;
case 1:
defaultData = value;
break;
default:
@ -231,10 +234,24 @@ public enum DisguiseType {
return entityType;
}
/**
* The TYPE id of this entity. Different from the Object Id
* send in spawn packets when spawning miscs.
* @return
*/
public int getTypeId() {
return (int) getEntityType().getTypeId();
}
/**
* The object type send in packets when spawning a misc entity.
* Otherwise, -1.
* @return
*/
public int getObjectId() {
return objectId;
}
public Class getWatcherClass() {
return watcherClass;
}

View File

@ -0,0 +1,50 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
import java.awt.*;
/**
* @author Navid
*/
public class AreaEffectCloudWatcher extends FlagWatcher {
public AreaEffectCloudWatcher(Disguise disguise) {
super(disguise);
}
public float getRadius() {
return (float) getValue(5, 0f);
}
public int getColor() {
return (int) getValue(6, Color.BLACK.getRGB());
}
public boolean isIgnoreRadius() {
return (boolean) getValue(7, false);
}
public int getParticleId() {
return (int) getValue(8, 0);
}
public void setRadius(float radius) {
setValue(5, radius);
}
public void setColor(int color) {
setValue(6, color);
}
public void setIgnoreRadius(boolean ignore) {
setValue(7, ignore);
}
public void setParticleId(int particleId) {
setValue(8, particleId);
}
}

View File

@ -11,7 +11,6 @@ public class FallingBlockWatcher extends FlagWatcher {
private ItemStack block;
//TODO: Check this watcher and make sure it works
public FallingBlockWatcher(Disguise disguise) {
super(disguise);
}

View File

@ -2,21 +2,21 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import com.google.common.base.Optional;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import org.bukkit.Material;
import org.bukkit.entity.Horse.Color;
import org.bukkit.entity.Horse.Style;
import org.bukkit.entity.Horse.Variant;
import org.bukkit.inventory.ItemStack;
import java.util.Random;
import java.util.UUID;
public class HorseWatcher extends AgeableWatcher {
public HorseWatcher(Disguise disguise) {
super(disguise);
setStyle(Style.values()[new Random().nextInt(Style.values().length)]);
setColor(Color.values()[new Random().nextInt(Color.values().length)]);
setStyle(Style.values()[DisguiseUtilities.random.nextInt(Style.values().length)]);
setColor(Color.values()[DisguiseUtilities.random.nextInt(Color.values().length)]);
}
public Variant getVariant() {

View File

@ -2,14 +2,13 @@ package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.disguisetypes.RabbitType;
import java.util.Random;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
public class RabbitWatcher extends AgeableWatcher {
public RabbitWatcher(Disguise disguise) {
super(disguise);
setType(RabbitType.values()[new Random().nextInt(RabbitType.values().length)]);
setType(RabbitType.values()[DisguiseUtilities.random.nextInt(RabbitType.values().length)]);
}
public RabbitType getType() {

View File

@ -1,14 +1,13 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import java.util.Random;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
public class SlimeWatcher extends LivingWatcher {
public SlimeWatcher(Disguise disguise) {
super(disguise);
setSize(new Random().nextInt(4) + 1);
setSize(DisguiseUtilities.random.nextInt(4) + 1);
}
public int getSize() {

View File

@ -1,6 +1,7 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import org.bukkit.Color;
/**
@ -10,6 +11,10 @@ public class TippedArrowWatcher extends ArrowWatcher {
public TippedArrowWatcher(Disguise disguise) {
super(disguise);
int r = DisguiseUtilities.random.nextInt(256);
int g = DisguiseUtilities.random.nextInt(256);
int b = DisguiseUtilities.random.nextInt(256);
setColor(Color.fromRGB(r, g, b));
}
public Color getColor() {

View File

@ -1,15 +1,14 @@
package me.libraryaddict.disguise.disguisetypes.watchers;
import me.libraryaddict.disguise.disguisetypes.Disguise;
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
import org.bukkit.entity.Villager.Profession;
import java.util.Random;
public class VillagerWatcher extends AgeableWatcher {
public VillagerWatcher(Disguise disguise) {
super(disguise);
setProfession(Profession.values()[new Random().nextInt(Profession.values().length)]);
setProfession(Profession.values()[DisguiseUtilities.random.nextInt(Profession.values().length)]);
}
public Profession getProfession() {

View File

@ -48,12 +48,14 @@ import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
public class DisguiseUtilities {
public static final Random random = new Random();
/**
* This is a list of names which was called by other plugins. As such, don't remove from the gameProfiles as its the duty of the plugin to do that.
*/

View File

@ -30,8 +30,6 @@ public class DisguiseValues {
case ZOMBIE_VILLAGER:
type = DisguiseType.ZOMBIE;
break;
case ARROW:
type = DisguiseType.TIPPED_ARROW;
default:
break;
}

View File

@ -57,7 +57,6 @@ import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.UUID;
public class PacketsManager {
@ -280,13 +279,12 @@ public class PacketsManager {
spawnPackets[0].getDataWatcherModifier().write(0, createDataWatcher(WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher()));
entity.addPotionEffect(new PotionEffect(PotionEffectType.INVISIBILITY, 1, Integer.MAX_VALUE, true, false));
entity.remove();
//You know, as cheap as this may seem, this is pretty damn effective
} else if (disguise.getType().isMisc()) {
//TODO: Fix miscs
int id = disguise.getType().getTypeId();
//TODO: Fix falling blocks, BlockPosition Serializer in ProtocolLib
int objectId = disguise.getType().getObjectId();
int data = ((MiscDisguise) disguise).getData();
if (disguise.getType() == DisguiseType.FALLING_BLOCK) {
data = (((MiscDisguise) disguise).getId() + data << 12);
data = ((MiscDisguise) disguise).getId() + (data << 12);
} else if (disguise.getType() == DisguiseType.FISHING_HOOK && data == 0) {
// If the MiscDisguise data isn't set. Then no entity id was provided, so default to the owners entity id
data = disguisedEntity.getEntityId();
@ -295,16 +293,15 @@ public class PacketsManager {
}
Object nmsEntity = ReflectionManager.getNmsEntity(disguisedEntity);
spawnPackets[0] = ProtocolLibrary.getProtocolManager()
.createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, id, data)
.createPacket(nmsEntity, id, data);
spawnPackets[0].getModifier().write(2, (int) Math.floor(loc.getY() * 32D));
spawnPackets[0].getModifier().write(7, pitch);
spawnPackets[0].getModifier().write(8, yaw);
.createPacketConstructor(PacketType.Play.Server.SPAWN_ENTITY, nmsEntity, objectId, data)
.createPacket(nmsEntity, objectId, data);
spawnPackets[0].getModifier().write(8, pitch);
spawnPackets[0].getModifier().write(9, yaw);
if (disguise.getType() == DisguiseType.ITEM_FRAME) {
if (data % 2 == 0) {
spawnPackets[0].getModifier().write(3, (int) Math.floor((loc.getZ() + (data == 0 ? -1 : 1)) * 32D));
spawnPackets[0].getModifier().write(4, (int) Math.floor((loc.getZ() + (data == 0 ? -1 : 1)) * 32D));
} else {
spawnPackets[0].getModifier().write(1, (int) Math.floor((loc.getX() + (data == 3 ? -1 : 1)) * 32D));
spawnPackets[0].getModifier().write(2, (int) Math.floor((loc.getX() + (data == 3 ? -1 : 1)) * 32D));
}
}
}
@ -387,9 +384,13 @@ public class PacketsManager {
value += 64;
break;
case ENDER_DRAGON:
//TODO: Enderdragon direction is... weird, consistently backwards
// value = (byte) (~value & 0xff);
break;
case WITHER_SKULL:
value -= 128;
break;
case ARROW:
case TIPPED_ARROW:
case SPECTRAL_ARROW:
value = (byte) -value;
@ -620,7 +621,7 @@ public class PacketsManager {
// If the pitch is not the expected
if (pitch > 97 || pitch < 111)
return;
pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F;
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.5F;
// Min = 1.5
// Cap = 97.5
// Max = 1.7
@ -629,7 +630,7 @@ public class PacketsManager {
// If the pitch is not the expected
if (pitch >= 63 || pitch <= 76)
return;
pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F;
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.0F;
// Min = 1
// Cap = 63
// Max = 1.2
@ -699,9 +700,9 @@ public class PacketsManager {
mods.write(5, disSound.getDamageAndIdleSoundVolume());
float pitch;
if (disguise instanceof MobDisguise && !((MobDisguise) disguise).isAdult()) {
pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.5F;
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.5F;
} else
pitch = (new Random().nextFloat() - new Random().nextFloat()) * 0.2F + 1.0F;
pitch = (DisguiseUtilities.random.nextFloat() - DisguiseUtilities.random.nextFloat()) * 0.2F + 1.0F;
if (disguise.getType() == DisguiseType.BAT)
pitch *= 95F;
pitch *= 63;
@ -1355,10 +1356,10 @@ public class PacketsManager {
} else if (sentPacket.getType() != Server.REL_ENTITY_MOVE) {
packets[0] = sentPacket.shallowClone();
StructureModifier<Byte> bytes = packets[0].getBytes();
byte yawValue = bytes.read(1);
bytes.write(1, getYaw(disguise.getType(), entity.getType(), yawValue));
byte pitchValue = bytes.read(0);
bytes.write(0, getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), pitchValue));
byte yawValue = bytes.read(0);
bytes.write(0, getYaw(disguise.getType(), entity.getType(), yawValue));
byte pitchValue = bytes.read(1);
bytes.write(1, getPitch(disguise.getType(), DisguiseType.getType(entity.getType()), pitchValue));
if (sentPacket.getType() == Server.ENTITY_TELEPORT && disguise.getType() == DisguiseType.ITEM_FRAME) {
StructureModifier<Double> doubles = packets[0].getDoubles();
Location loc = entity.getLocation();

View File

@ -317,7 +317,9 @@ public class ReflectionManager {
public static Constructor getNmsConstructor(Class clazz, Class<?>... parameters) {
try {
return clazz.getDeclaredConstructor(parameters);
Constructor declaredConstructor = clazz.getDeclaredConstructor(parameters);
declaredConstructor.setAccessible(true);
return declaredConstructor;
} catch (NoSuchMethodException e) {
e.printStackTrace(System.out);
}
@ -339,7 +341,9 @@ public class ReflectionManager {
public static Field getNmsField(Class clazz, String fieldName) {
try {
return clazz.getDeclaredField(fieldName);
Field declaredField = clazz.getDeclaredField(fieldName);
declaredField.setAccessible(true);
return declaredField;
} catch (NoSuchFieldException e) {
e.printStackTrace(System.out);
}
@ -365,7 +369,9 @@ public class ReflectionManager {
public static Method getCraftMethod(Class<?> clazz, String methodName, Class<?>... parameters) {
try {
return clazz.getDeclaredMethod(methodName, parameters);
Method declaredMethod = clazz.getDeclaredMethod(methodName, parameters);
declaredMethod.setAccessible(true);
return declaredMethod;
} catch (NoSuchMethodException e) {
e.printStackTrace(System.out);
}
@ -374,7 +380,9 @@ public class ReflectionManager {
public static Method getNmsMethod(Class<?> clazz, String methodName, Class<?>... parameters) {
try {
return clazz.getDeclaredMethod(methodName, parameters);
Method declaredMethod = clazz.getDeclaredMethod(methodName, parameters);
declaredMethod.setAccessible(true);
return declaredMethod;
} catch (NoSuchMethodException e) {
e.printStackTrace(System.out);
}
@ -523,6 +531,7 @@ public class ReflectionManager {
/**
* Creates the NMS object EnumItemSlot from an EquipmentSlot.
*
* @param slot
* @return null if the equipment slot is null
*/
@ -550,6 +559,7 @@ public class ReflectionManager {
/**
* Creates the Bukkit object EquipmentSlot from an EnumItemSlot object.
*
* @return null if the object isn't an nms EnumItemSlot
*/
public static EquipmentSlot createEquipmentSlot(Object enumItemSlot) {
@ -576,7 +586,8 @@ public class ReflectionManager {
}
/**
* Gets equipment from this entity based on the slot given.
* Gets equipment from this entity based on the slot given.
*
* @param slot
* @return null if the disguisedEntity is not an instance of a living entity
*/
@ -602,6 +613,7 @@ public class ReflectionManager {
/**
* Necessary for 1.9
*
* @return
*/
public static String convertSoundEffectToString(Object soundEffect) {
@ -627,6 +639,7 @@ public class ReflectionManager {
/**
* This creates a DataWatcherItem usable with WrappedWatchableObject
*
* @param id
* @param value
* @return
@ -654,5 +667,4 @@ public class ReflectionManager {
}
return null;
}
}