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

@@ -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;
}
}