mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2024-11-04 08:59:47 +01:00
Switch to ProtocolLib MinecraftKeys wrapper
Add in helper method to quickly create DataWatcher.Item objects Typo in last commit, meant to say, disguises will NOT show up. Sorry to those who got excited. :(
This commit is contained in:
parent
2cf48f7916
commit
1576c895b5
@ -109,15 +109,13 @@ public class FlagWatcher {
|
||||
value = this.addEntityAnimations((byte) value, (byte) watch.getValue());
|
||||
}
|
||||
boolean isDirty = watch.getDirtyState();
|
||||
watch = new WrappedWatchableObject(id);
|
||||
watch.setValue(value);
|
||||
watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, value));
|
||||
if (!isDirty) {
|
||||
watch.setDirtyState(false);
|
||||
}
|
||||
} else {
|
||||
boolean isDirty = watch.getDirtyState();
|
||||
watch = new WrappedWatchableObject(id);
|
||||
watch.setValue(watch.getValue());
|
||||
watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, watch.getValue()));
|
||||
if (!isDirty) {
|
||||
watch.setDirtyState(false);
|
||||
}
|
||||
@ -126,16 +124,15 @@ public class FlagWatcher {
|
||||
}
|
||||
if (sendAllCustom) {
|
||||
// Its sending the entire meta data. Better add the custom meta
|
||||
for (int value : entityValues.keySet()) {
|
||||
if (sentValues.contains(value)) {
|
||||
for (int id : entityValues.keySet()) {
|
||||
if (sentValues.contains(id)) {
|
||||
continue;
|
||||
}
|
||||
Object obj = entityValues.get(value);
|
||||
if (obj == null) {
|
||||
Object value = entityValues.get(id);
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
WrappedWatchableObject watch = new WrappedWatchableObject(value);
|
||||
watch.setValue(obj);
|
||||
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(id, value));
|
||||
newList.add(watch);
|
||||
}
|
||||
}
|
||||
@ -246,11 +243,9 @@ public class FlagWatcher {
|
||||
for (int i = 0; i <= 31; i++) {
|
||||
WrappedWatchableObject watchable = null;
|
||||
if (this.entityValues.containsKey(i) && this.entityValues.get(i) != null) {
|
||||
watchable = new WrappedWatchableObject(i);
|
||||
watchable.setValue(entityValues.get(i));
|
||||
watchable = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(i, entityValues.get(i)));
|
||||
} else if (this.backupEntityValues.containsKey(i) && this.backupEntityValues.get(i) != null) {
|
||||
watchable = new WrappedWatchableObject(i);
|
||||
watchable.setValue(backupEntityValues.get(i));
|
||||
watchable = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(i, entityValues.get(i)));
|
||||
}
|
||||
if (watchable != null) {
|
||||
watchableObjects.add(watchable);
|
||||
@ -271,8 +266,7 @@ public class FlagWatcher {
|
||||
if (isEntityAnimationsAdded() && DisguiseConfig.isMetadataPacketsEnabled() && data == 0) {
|
||||
value = addEntityAnimations((byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
|
||||
}
|
||||
WrappedWatchableObject watch = new WrappedWatchableObject(data);
|
||||
watch.setValue(value);
|
||||
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(data, value));
|
||||
list.add(watch);
|
||||
}
|
||||
if (!list.isEmpty()) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package me.libraryaddict.disguise.utilities;
|
||||
|
||||
import com.comphenix.protocol.wrappers.MinecraftKey;
|
||||
import org.bukkit.Sound;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
@ -132,10 +133,8 @@ public enum DisguiseSound {
|
||||
try {
|
||||
Field f_getMinecraftKey = ReflectionManager.getNmsField("SoundEffect", "b");
|
||||
f_getMinecraftKey.setAccessible(true);
|
||||
Object minecraftKey = f_getMinecraftKey.get(soundEffect);
|
||||
Field f_getValue = ReflectionManager.getNmsField("MinecraftKey", "a");
|
||||
String sound = (String) f_getValue.get(soundEffect); //Our prize!
|
||||
return sound;
|
||||
MinecraftKey key = MinecraftKey.fromHandle(f_getMinecraftKey.get(soundEffect));
|
||||
return key.getKey();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
@ -7,13 +7,11 @@ import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
|
||||
@ -593,40 +591,6 @@ public class DisguiseUtilities {
|
||||
return ReflectionManager.getSkullBlob(ReflectionManager.grabProfileAddUUID(playerName));
|
||||
}
|
||||
|
||||
/**
|
||||
* Please note that in the future when 'DualInt' and the like are removed. This should break.. However, that should be negated in the future as I'd be able to set the watcher index's as per the spigot version. Instead of checking on the player's version every single packet..
|
||||
*/
|
||||
public static List<WrappedWatchableObject> rebuildForVersion(Player player, FlagWatcher watcher,
|
||||
List<WrappedWatchableObject> list) {
|
||||
if (true) // Use for future protocol compatibility
|
||||
{
|
||||
return list;
|
||||
}
|
||||
ArrayList<WrappedWatchableObject> rebuiltList = new ArrayList<>();
|
||||
ArrayList<WrappedWatchableObject> backups = new ArrayList<>();
|
||||
for (WrappedWatchableObject obj : list) {
|
||||
if (obj.getValue().getClass().getName().startsWith("org.")) {
|
||||
backups.add(obj);
|
||||
continue;
|
||||
}
|
||||
switch (obj.getIndex()) {
|
||||
// TODO: Future version support
|
||||
}
|
||||
}
|
||||
Iterator<WrappedWatchableObject> itel = backups.iterator();
|
||||
while (itel.hasNext()) {
|
||||
int index = itel.next().getIndex();
|
||||
for (WrappedWatchableObject obj2 : rebuiltList) {
|
||||
if (index == obj2.getIndex()) {
|
||||
itel.remove();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
rebuiltList.addAll(backups);
|
||||
return rebuiltList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Resends the entity to this specific player
|
||||
*/
|
||||
|
@ -364,7 +364,6 @@ public class PacketsManager {
|
||||
try {
|
||||
List<WrappedWatchableObject> list = DisguiseConfig.isMetadataPacketsEnabled() ? flagWatcher.convert(watcher
|
||||
.getWatchableObjects()) : flagWatcher.getWatchableObjects();
|
||||
list = DisguiseUtilities.rebuildForVersion(player, flagWatcher, list);
|
||||
for (WrappedWatchableObject watchableObject : list) {
|
||||
newWatcher.setObject(watchableObject.getIndex(), watchableObject.getValue());
|
||||
}
|
||||
@ -818,11 +817,10 @@ public class PacketsManager {
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, observer.getEntityId());
|
||||
List<WrappedWatchableObject> watchableList = new ArrayList<>();
|
||||
byte b = (byte) 1 << 5;
|
||||
Byte b = 1 << 5;
|
||||
if (observer.isSprinting())
|
||||
b = (byte) (b | 1 << 3);
|
||||
WrappedWatchableObject watch = new WrappedWatchableObject(0);
|
||||
watch.setValue(b);
|
||||
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(0, b));
|
||||
watchableList.add(watch);
|
||||
packet.getWatchableCollectionModifier().write(0, watchableList);
|
||||
try {
|
||||
@ -1313,7 +1311,6 @@ public class PacketsManager {
|
||||
if (DisguiseConfig.isMetadataPacketsEnabled()) {
|
||||
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher().convert(
|
||||
packets[0].getWatchableCollectionModifier().read(0));
|
||||
watchableObjects = DisguiseUtilities.rebuildForVersion(observer, disguise.getWatcher(), watchableObjects);
|
||||
packets[0] = new PacketContainer(sentPacket.getType());
|
||||
StructureModifier<Object> newMods = packets[0].getModifier();
|
||||
newMods.write(0, entity.getEntityId());
|
||||
@ -1422,8 +1419,8 @@ public class PacketsManager {
|
||||
// Convert the datawatcher
|
||||
List<WrappedWatchableObject> list = new ArrayList<>();
|
||||
if (DisguiseConfig.isMetadataPacketsEnabled()) {
|
||||
WrappedWatchableObject watch = new WrappedWatchableObject(0);
|
||||
watch.setValue(WrappedDataWatcher.getEntityWatcher(entity).getByte(0));
|
||||
WrappedWatchableObject watch = new WrappedWatchableObject(ReflectionManager.createDataWatcherItem(0,
|
||||
WrappedDataWatcher.getEntityWatcher(entity).getByte(0)));
|
||||
list.add(watch);
|
||||
list = disguise.getWatcher().convert(list);
|
||||
} else {
|
||||
@ -1434,7 +1431,6 @@ public class PacketsManager {
|
||||
}
|
||||
}
|
||||
}
|
||||
list = DisguiseUtilities.rebuildForVersion(observer, disguise.getWatcher(), list);
|
||||
// Construct the packets to return
|
||||
PacketContainer packetBlock = new PacketContainer(Server.ENTITY_METADATA);
|
||||
packetBlock.getModifier().write(0, entity.getEntityId());
|
||||
|
@ -1,5 +1,8 @@
|
||||
package me.libraryaddict.disguise.utilities;
|
||||
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Registry;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.Serializer;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import org.bukkit.Art;
|
||||
@ -14,6 +17,7 @@ import org.bukkit.potion.PotionEffect;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.Map;
|
||||
@ -457,9 +461,10 @@ public class ReflectionManager {
|
||||
}
|
||||
|
||||
public static void removePlayer(Player player) {
|
||||
|
||||
//Some future remove code if needed
|
||||
}
|
||||
|
||||
|
||||
public static void setAllowSleep(Player player) {
|
||||
try {
|
||||
//TODO: Fix this!
|
||||
@ -471,6 +476,25 @@ public class ReflectionManager {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This creates a DataWatcherItem usable with WrappedWatchableObject
|
||||
* @param id
|
||||
* @param value
|
||||
* @return
|
||||
*/
|
||||
public static Object createDataWatcherItem(int id, Object value) {
|
||||
if (value == null) return null;
|
||||
Serializer serializer = Registry.get(value.getClass());
|
||||
WrappedDataWatcherObject watcherObject = new WrappedDataWatcherObject(id, serializer);
|
||||
Constructor construct = ReflectionManager.getNmsConstructor("DataWatcher$Item", getNmsClass("DataWatcherObject"), Object.class);
|
||||
try {
|
||||
return construct.newInstance(watcherObject.getHandle(), value);
|
||||
} catch (InstantiationException | IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void setBoundingBox(Entity entity, FakeBoundingBox newBox) {
|
||||
try {
|
||||
Location loc = entity.getLocation();
|
||||
|
Loading…
Reference in New Issue
Block a user