use of com.comphenix.protocol.reflect.FieldAccessException in project InteractiveChat by LOOHP.
the class MapViewer method showMap.
@SuppressWarnings("deprecation")
public static void showMap(Player player, ItemStack item) {
if (!FilledMapUtils.isFilledMap(item)) {
throw new IllegalArgumentException("ItemStack is not a filled map");
}
try {
int mapId = FilledMapUtils.getMapId(item);
MapView mapView = FilledMapUtils.getMapView(item);
PacketContainer packet1;
if (InteractiveChat.version.isOld()) {
packet1 = InteractiveChat.protocolManager.createPacket(PacketType.Play.Server.SET_SLOT);
packet1.getIntegers().write(0, 0);
packet1.getIntegers().write(1, player.getInventory().getHeldItemSlot() + 36);
packet1.getItemModifier().write(0, item);
} else {
packet1 = InteractiveChat.protocolManager.createPacket(PacketType.Play.Server.ENTITY_EQUIPMENT);
packet1.getIntegers().write(0, player.getEntityId());
if (InteractiveChat.version.isNewerOrEqualTo(MCVersion.V1_16)) {
List<Pair<ItemSlot, ItemStack>> list = new ArrayList<>();
list.add(new Pair<ItemSlot, ItemStack>(ItemSlot.MAINHAND, item));
packet1.getSlotStackPairLists().write(0, list);
} else {
packet1.getItemSlots().write(0, ItemSlot.MAINHAND);
packet1.getItemModifier().write(0, item);
}
}
PacketContainer packet2 = InteractiveChat.protocolManager.createPacket(PacketType.Play.Server.MAP);
int mapIconFieldPos = 2;
if (InteractiveChat.version.isNewerOrEqualTo(MCVersion.V1_17)) {
packet2.getIntegers().write(0, mapId);
packet2.getBytes().write(0, (byte) 0);
packet2.getBooleans().write(0, false);
} else {
packet2.getIntegers().write(0, mapId);
packet2.getBytes().write(0, (byte) 0);
if (!InteractiveChat.version.isOld()) {
packet2.getBooleans().write(0, false);
mapIconFieldPos++;
}
if (InteractiveChat.version.isNewerOrEqualTo(MCVersion.V1_14)) {
packet2.getBooleans().write(1, false);
mapIconFieldPos++;
}
packet2.getIntegers().write(1, 0);
packet2.getIntegers().write(2, 0);
packet2.getIntegers().write(3, 128);
packet2.getIntegers().write(4, 128);
}
MAP_VIEWERS.put(player, item);
InteractiveChat.protocolManager.sendServerPacket(player, packet1);
int mapIconFieldPos0 = mapIconFieldPos;
new BukkitRunnable() {
@Override
public void run() {
ItemStack itemStack = MAP_VIEWERS.get(player);
if (itemStack != null && itemStack.equals(item)) {
if (!player.getInventory().containsAtLeast(itemStack, 1)) {
try {
byte[] colors = FilledMapUtils.getColors(mapView, player);
List<MapCursor> mapCursors = FilledMapUtils.getCursors(mapView, player);
Iterator<MapCursor> itr = mapCursors.iterator();
while (itr.hasNext()) {
MapCursor mapCursor = itr.next();
int type = mapCursor.getRawType();
if (type == 0 || type == 6 || type == 7) {
itr.remove();
}
}
if (InteractiveChat.version.isNewerOrEqualTo(MCVersion.V1_17)) {
packet2.getModifier().write(3, FilledMapUtils.toNMSMapIconList(mapCursors));
packet2.getModifier().write(4, FilledMapUtils.getNMSWorldMapBClassConstructor().newInstance(0, 0, 128, 128, colors));
} else {
List<?> nmsMapIconsList = FilledMapUtils.toNMSMapIconList(mapCursors);
Object nmsMapIconsArray = Array.newInstance(FilledMapUtils.getNMSMapIconClass(), nmsMapIconsList.size());
for (int i = 0; i < nmsMapIconsList.size(); i++) {
Object nmsMapIconObject = nmsMapIconsList.get(i);
Array.set(nmsMapIconsArray, i, nmsMapIconObject);
}
packet2.getByteArrays().write(0, colors);
packet2.getModifier().write(mapIconFieldPos0, nmsMapIconsArray);
}
InteractiveChat.protocolManager.sendServerPacket(player, packet2);
} catch (IllegalArgumentException | IllegalAccessException | InvocationTargetException | FieldAccessException | InstantiationException e) {
e.printStackTrace();
}
}
} else {
this.cancel();
}
}
}.runTaskTimer(InteractiveChat.plugin, 0, 1);
} catch (Exception e) {
e.printStackTrace();
}
}
use of com.comphenix.protocol.reflect.FieldAccessException in project LibsDisguises by libraryaddict.
the class ReflectionManager method createNMSValues.
private static void createNMSValues(DisguiseType disguiseType) {
String nmsEntityName = toReadable(disguiseType.name());
Class nmsClass = ReflectionManager.getNmsClassIgnoreErrors("Entity" + nmsEntityName);
if (nmsClass == null || Modifier.isAbstract(nmsClass.getModifiers())) {
String[] split = splitReadable(disguiseType.name());
ArrayUtils.reverse(split);
nmsEntityName = StringUtils.join(split);
nmsClass = ReflectionManager.getNmsClassIgnoreErrors("Entity" + nmsEntityName);
if (nmsClass == null || Modifier.isAbstract(nmsClass.getModifiers())) {
nmsEntityName = null;
}
}
if (nmsEntityName == null) {
switch(disguiseType) {
case AXOLOTL:
nmsEntityName = "Axolotl";
break;
case GOAT:
nmsEntityName = "Goat";
break;
case GLOW_ITEM_FRAME:
nmsEntityName = "GlowItemFrame";
break;
case GLOW_SQUID:
nmsEntityName = "GlowSquid";
break;
case MARKER:
nmsEntityName = "Marker";
break;
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;
case WANDERING_TRADER:
nmsEntityName = "VillagerTrader";
break;
case TRADER_LLAMA:
// Interesting capitalization
nmsEntityName = "LLamaTrader";
break;
case ZOMBIFIED_PIGLIN:
nmsEntityName = "PigZombie";
break;
default:
break;
}
}
try {
if (disguiseType == DisguiseType.UNKNOWN || disguiseType.isCustom()) {
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, 0);
disguiseValues.setAdultBox(new FakeBoundingBox(0, 0, 0));
SoundGroup sound = SoundGroup.getGroup(disguiseType.name());
if (sound != null) {
sound.setDamageAndIdleSoundVolume(1f);
}
return;
}
if (nmsEntityName == null) {
DisguiseUtilities.getLogger().warning("Entity name not found! (" + disguiseType.name() + ")");
return;
}
Object nmsEntity = ReflectionManager.createEntityInstance(disguiseType, nmsReflection != null ? disguiseType.getEntityType().getKey().getKey() : nmsEntityName);
if (nmsEntity == null) {
DisguiseUtilities.getLogger().warning("Entity not found! (" + nmsEntityName + ")");
return;
}
disguiseType.setTypeId(ReflectionManager.getEntityTypeId(disguiseType.getEntityType()));
Entity bukkitEntity = ReflectionManager.getBukkitEntity(nmsEntity);
DisguiseValues disguiseValues = new DisguiseValues(disguiseType, bukkitEntity instanceof Damageable ? ((Damageable) bukkitEntity).getMaxHealth() : 0);
WrappedDataWatcher watcher = WrappedDataWatcher.getEntityWatcher(bukkitEntity);
ArrayList<MetaIndex> indexes = MetaIndex.getMetaIndexes(disguiseType.getWatcherClass());
boolean loggedName = false;
for (WrappedWatchableObject watch : watcher.getWatchableObjects()) {
MetaIndex flagType = MetaIndex.getMetaIndex(disguiseType.getWatcherClass(), watch.getIndex());
if (flagType == null) {
DisguiseUtilities.getLogger().severe("MetaIndex not found for " + disguiseType + "! Index: " + watch.getIndex());
DisguiseUtilities.getLogger().severe("Value: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ") (" + nmsEntity.getClass() + ") & " + disguiseType.getWatcherClass().getSimpleName());
continue;
}
indexes.remove(flagType);
Object ourValue = ReflectionManager.convertInvalidMeta(flagType.getDefault());
Object nmsValue = ReflectionManager.convertInvalidMeta(watch.getRawValue());
if (ourValue.getClass() != nmsValue.getClass()) {
if (!loggedName) {
DisguiseUtilities.getLogger().severe(StringUtils.repeat("=", 20));
DisguiseUtilities.getLogger().severe("MetaIndex mismatch! Disguise " + disguiseType + ", Entity " + nmsEntityName);
loggedName = true;
}
DisguiseUtilities.getLogger().severe(StringUtils.repeat("-", 20));
DisguiseUtilities.getLogger().severe("Index: " + watch.getIndex() + " | " + flagType.getFlagWatcher().getSimpleName() + " | " + MetaIndex.getName(flagType));
Object flagDefault = flagType.getDefault();
DisguiseUtilities.getLogger().severe("LibsDisguises: " + flagDefault + " (" + flagDefault.getClass() + ")");
DisguiseUtilities.getLogger().severe("LibsDisguises Converted: " + ourValue + " (" + ourValue.getClass() + ")");
DisguiseUtilities.getLogger().severe("Minecraft: " + watch.getRawValue() + " (" + watch.getRawValue().getClass() + ")");
DisguiseUtilities.getLogger().severe("Minecraft Converted: " + nmsValue + " (" + nmsValue.getClass() + ")");
DisguiseUtilities.getLogger().severe(StringUtils.repeat("-", 20));
}
}
for (MetaIndex index : indexes) {
DisguiseUtilities.getLogger().severe(disguiseType + " has MetaIndex remaining! " + index.getFlagWatcher().getSimpleName() + " at index " + index.getIndex());
}
SoundGroup sound = SoundGroup.getGroup(disguiseType.name());
if (sound != null) {
Float soundStrength = ReflectionManager.getSoundModifier(nmsEntity);
if (soundStrength != null) {
sound.setDamageAndIdleSoundVolume(soundStrength);
}
}
// Get the bounding box
disguiseValues.setAdultBox(ReflectionManager.getBoundingBox(bukkitEntity));
if (bukkitEntity instanceof Ageable) {
((Ageable) bukkitEntity).setBaby();
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
} else if (bukkitEntity instanceof Zombie) {
((Zombie) bukkitEntity).setBaby(true);
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
} else if (bukkitEntity instanceof ArmorStand) {
((ArmorStand) bukkitEntity).setSmall(true);
disguiseValues.setBabyBox(ReflectionManager.getBoundingBox(bukkitEntity));
}
} catch (SecurityException | IllegalArgumentException | FieldAccessException ex) {
DisguiseUtilities.getLogger().severe("Uh oh! Trouble while making values for the disguise " + disguiseType.name() + "!");
DisguiseUtilities.getLogger().severe("Before reporting this error, " + "please make sure you are using the latest version of LibsDisguises and ProtocolLib.");
DisguiseUtilities.getLogger().severe("Development builds are available at (ProtocolLib) " + "http://ci.dmulloy2.net/job/ProtocolLib/ and (LibsDisguises) https://ci.md-5" + ".net/job/LibsDisguises/");
ex.printStackTrace();
}
}
use of com.comphenix.protocol.reflect.FieldAccessException in project CombatLogX by SirBlobman.
the class ForceFieldAdapter method getLocation0.
@Nullable
private Location getLocation0(World world, PacketContainer packetContainer) {
try {
StructureModifier<BlockPosition> blockPositionModifier = packetContainer.getBlockPositionModifier();
BlockPosition blockPosition = blockPositionModifier.readSafely(0);
if (blockPosition == null) {
return getLocation1(world, packetContainer);
}
return blockPosition.toLocation(world);
} catch (FieldAccessException ex) {
return getLocation1(world, packetContainer);
}
}
use of com.comphenix.protocol.reflect.FieldAccessException in project CombatLogX by SirBlobman.
the class ForceFieldAdapter method getLocation1.
@Nullable
private Location getLocation1(World world, PacketContainer packetContainer) {
try {
StructureModifier<MovingObjectPositionBlock> movingBlockPositionModifier = packetContainer.getMovingBlockPositions();
MovingObjectPositionBlock movingObjectPositionBlock = movingBlockPositionModifier.readSafely(0);
if (movingObjectPositionBlock == null) {
return null;
}
BlockPosition blockPosition = movingObjectPositionBlock.getBlockPosition();
return (blockPosition == null ? null : blockPosition.toLocation(world));
} catch (FieldAccessException ex) {
return null;
}
}
Aggregations