Update for 1.20.2

This commit is contained in:
libraryaddict 2023-09-30 06:27:14 +13:00
parent d9e14aec31
commit 2cb01ddc75
18 changed files with 900 additions and 126 deletions

View File

@ -20,6 +20,7 @@
<module>v1_19_R2</module>
<module>v1_19_R3</module>
<module>v1_20_R1</module>
<module>v1_20_R2</module>
</modules>
</project>

View File

@ -1,4 +1,4 @@
package me.libraryaddict.disguise.utilities.reflection.v1_20;
package me.libraryaddict.disguise.utilities.reflection.v1_20_R1;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;

116
nms/v1_20_R2/pom.xml Normal file
View File

@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>nms</artifactId>
<groupId>LibsDisguises</groupId>
<version>1.0-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>v1_20_R2</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<spigot.version>1.20.2-R0.1-SNAPSHOT</spigot.version>
</properties>
<dependencies>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>${spigot.version}</version>
<classifier>remapped-mojang</classifier>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>${spigot.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>LibsDisguises</groupId>
<artifactId>shared</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.comphenix.protocol</groupId>
<artifactId>ProtocolLib</artifactId>
</dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
<version>8.5.8</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>authlib</artifactId>
<version>5.0.47</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>datafixerupper</artifactId>
<version>5.0.28</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.mojang</groupId>
<artifactId>brigadier</artifactId>
<version>1.0.18</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>net.md-5</groupId>
<artifactId>specialsource-maven-plugin</artifactId>
<version>1.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-obf</id>
<configuration>
<srgIn>org.spigotmc:minecraft-server:${spigot.version}:txt:maps-mojang</srgIn>
<reverse>true</reverse>
<remappedDependencies>org.spigotmc:spigot:${spigot.version}:jar:remapped-mojang</remappedDependencies>
<remappedClassifierName>remapped-mojang</remappedClassifierName>
<remappedArtifactAttached>true</remappedArtifactAttached>
</configuration>
</execution>
<execution>
<phase>package</phase>
<goals>
<goal>remap</goal>
</goals>
<id>remap-spigot</id>
<configuration>
<inputFile>target/${project.build.finalName}-remapped-mojang.jar</inputFile>
<srgIn>org.spigotmc:minecraft-server:${spigot.version}:csrg:maps-spigot</srgIn>
<remappedDependencies>org.spigotmc:spigot:${spigot.version}:jar:remapped-obf</remappedDependencies>
<remappedClassifierName>remapped-spigot</remappedClassifierName>
<remappedArtifactAttached>true</remappedArtifactAttached>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -0,0 +1,587 @@
package me.libraryaddict.disguise.utilities.reflection.v1_20_R2;
import com.comphenix.protocol.PacketType;
import com.comphenix.protocol.events.PacketContainer;
import com.comphenix.protocol.events.PacketEvent;
import com.comphenix.protocol.reflect.StructureModifier;
import com.comphenix.protocol.wrappers.BlockPosition;
import com.comphenix.protocol.wrappers.EnumWrappers;
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.WrappedDataWatcher;
import com.comphenix.protocol.wrappers.WrappedGameProfile;
import com.mojang.authlib.GameProfile;
import com.mojang.authlib.ProfileLookupCallback;
import com.mojang.authlib.minecraft.MinecraftSessionService;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import me.libraryaddict.disguise.utilities.reflection.ReflectionManagerAbstract;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.core.Vector3f;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundPlayerInfoUpdatePacket;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.level.ChunkMap;
import net.minecraft.server.level.ClientInformation;
import net.minecraft.server.level.ServerChunkCache;
import net.minecraft.server.level.ServerEntity;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.server.network.ServerGamePacketListenerImpl;
import net.minecraft.server.network.ServerPlayerConnection;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.entity.EntityDimensions;
import net.minecraft.world.entity.HumanoidArm;
import net.minecraft.world.entity.animal.CatVariant;
import net.minecraft.world.entity.animal.FrogVariant;
import net.minecraft.world.entity.decoration.PaintingVariant;
import net.minecraft.world.entity.npc.VillagerData;
import net.minecraft.world.entity.npc.VillagerProfession;
import net.minecraft.world.entity.npc.VillagerType;
import net.minecraft.world.entity.player.ChatVisiblity;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.level.GameType;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.bukkit.Art;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.NamespacedKey;
import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.data.BlockData;
import org.bukkit.craftbukkit.v1_20_R2.CraftArt;
import org.bukkit.craftbukkit.v1_20_R2.CraftServer;
import org.bukkit.craftbukkit.v1_20_R2.CraftSound;
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData;
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftEntity;
import org.bukkit.craftbukkit.v1_20_R2.entity.CraftPlayer;
import org.bukkit.craftbukkit.v1_20_R2.inventory.CraftItemStack;
import org.bukkit.craftbukkit.v1_20_R2.util.CraftMagicNumbers;
import org.bukkit.craftbukkit.v1_20_R2.util.CraftNamespacedKey;
import org.bukkit.entity.Cat;
import org.bukkit.entity.Entity;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Frog;
import org.bukkit.entity.Player;
import org.bukkit.entity.Sniffer;
import org.bukkit.entity.Villager;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.util.EulerAngle;
import org.bukkit.util.Vector;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import java.util.stream.Collectors;
public class ReflectionManager implements ReflectionManagerAbstract {
public boolean hasInvul(Entity entity) {
net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (nmsEntity instanceof net.minecraft.world.entity.LivingEntity) {
return nmsEntity.invulnerableTime > 0;
} else {
return nmsEntity.isInvulnerableTo(nmsEntity.damageSources().generic());
}
}
public int getIncrementedStateId(Player player) {
ServerPlayer serverPlayer = ((CraftPlayer) player).getHandle();
return serverPlayer.containerMenu.incrementStateId(); // TODO Check correct container
}
public int getNewEntityId() {
return getNewEntityId(true);
}
public int getNewEntityId(boolean increment) {
try {
Field entityCounter = net.minecraft.world.entity.Entity.class.getDeclaredField("d");
entityCounter.setAccessible(true);
AtomicInteger atomicInteger = (AtomicInteger) entityCounter.get(null);
if (increment) {
return atomicInteger.incrementAndGet();
} else {
return atomicInteger.get();
}
} catch (ReflectiveOperationException e) {
e.printStackTrace();
}
return -1;
}
public ServerGamePacketListenerImpl getPlayerConnectionOrPlayer(Player player) {
return ((CraftPlayer) player).getHandle().connection;
}
public net.minecraft.world.entity.Entity createEntityInstance(String entityName) {
Optional<net.minecraft.world.entity.EntityType<?>> optional = net.minecraft.world.entity.EntityType.byString(entityName.toLowerCase(Locale.ROOT));
if (optional.isPresent()) {
net.minecraft.world.entity.EntityType<?> entityType = optional.get();
ServerLevel world = getWorldServer(Bukkit.getWorlds().get(0));
net.minecraft.world.entity.Entity entity;
if (entityType == net.minecraft.world.entity.EntityType.PLAYER) {
WrappedGameProfile gameProfile = ReflectionManagerAbstract.getGameProfile(new UUID(0, 0), "Steve");
ClientInformation information = new ClientInformation("english", 10, ChatVisiblity.FULL, true, 0, HumanoidArm.RIGHT, true, true);
entity = new ServerPlayer(getMinecraftServer(), world, (GameProfile) gameProfile.getHandle(), information);
} else {
entity = entityType.create(world);
}
if (entity == null) {
return null;
}
// Workaround for paper being 2 smart 4 me
entity.setPos(1.0, 1.0, 1.0);
entity.setPos(0.0, 0.0, 0.0);
return entity;
}
return null;
}
public MobEffect getMobEffectList(int id) {
return BuiltInRegistries.MOB_EFFECT.byId(id);
}
public MobEffectInstance createMobEffect(PotionEffect effect) {
return createMobEffect(effect.getType().getId(), effect.getDuration(), effect.getAmplifier(), effect.isAmbient(), effect.hasParticles());
}
public MobEffectInstance createMobEffect(int id, int duration, int amplification, boolean ambient, boolean particles) {
return new MobEffectInstance(getMobEffectList(id), duration, amplification, ambient, particles);
}
public AABB getBoundingBox(Entity entity) {
return ((CraftEntity) entity).getHandle().getBoundingBox();
}
public double getXBoundingBox(Entity entity) {
return getBoundingBox(entity).maxX - getBoundingBox(entity).minX;
}
public double getYBoundingBox(Entity entity) {
return getBoundingBox(entity).maxY - getBoundingBox(entity).minY;
}
public double getZBoundingBox(Entity entity) {
return getBoundingBox(entity).maxZ - getBoundingBox(entity).minZ;
}
public ServerPlayer getPlayerFromPlayerConnection(Object nmsEntity) {
return ((ServerPlayerConnection) nmsEntity).getPlayer();
}
public Entity getBukkitEntity(Object nmsEntity) {
return ((net.minecraft.world.entity.Entity) nmsEntity).getBukkitEntity();
}
public ItemStack getBukkitItem(Object nmsItem) {
return CraftItemStack.asBukkitCopy((net.minecraft.world.item.ItemStack) nmsItem);
}
public ItemStack getCraftItem(ItemStack bukkitItem) {
return CraftItemStack.asCraftCopy(bukkitItem);
}
public Holder<SoundEvent> getCraftSound(Sound sound) {
return CraftSound.bukkitToMinecraftHolder(sound);
}
public ServerEntity getEntityTrackerEntry(Entity target) throws Exception {
ServerLevel world = ((CraftWorld) target.getWorld()).getHandle();
ServerChunkCache chunkSource = world.getChunkSource();
ChunkMap chunkMap = chunkSource.chunkMap;
Int2ObjectMap<ChunkMap.TrackedEntity> entityMap = chunkMap.entityMap;
ChunkMap.TrackedEntity trackedEntity = entityMap.get(target.getEntityId());
if (trackedEntity == null) {
return null;
}
Field field = ChunkMap.TrackedEntity.class.getDeclaredField("b");
field.setAccessible(true);
return (ServerEntity) field.get(trackedEntity);
}
public DedicatedServer getMinecraftServer() {
return ((CraftServer) Bukkit.getServer()).getServer();
}
public String getEnumArt(Art art) {
return BuiltInRegistries.PAINTING_VARIANT.getKey(CraftArt.bukkitToMinecraft(art)).getPath();
}
public BlockPos getBlockPosition(int x, int y, int z) {
return new BlockPos(x, y, z);
}
public net.minecraft.core.Direction getEnumDirection(int direction) {
return net.minecraft.core.Direction.from2DDataValue(direction);
}
@Override
public void handleTablistPacket(PacketEvent event, Function<UUID, Boolean> shouldRemove) {
ClientboundPlayerInfoUpdatePacket packet = (ClientboundPlayerInfoUpdatePacket) event.getPacket().getHandle();
if (!packet.actions().contains(ClientboundPlayerInfoUpdatePacket.Action.ADD_PLAYER)) {
return;
}
List<ClientboundPlayerInfoUpdatePacket.Entry> canKeep = new ArrayList<>();
for (ClientboundPlayerInfoUpdatePacket.Entry entry : packet.entries()) {
if (shouldRemove.apply(entry.profileId())) {
continue;
}
canKeep.add(entry);
}
if (canKeep.size() == packet.entries().size()) {
return;
}
if (canKeep.isEmpty()) {
event.setCancelled(true);
return;
}
event.getPacket().getModifier().write(1, canKeep);
}
public PacketContainer getTabListPacket(String displayName, WrappedGameProfile gameProfile, boolean nameVisible, EnumWrappers.PlayerInfoAction... actions) {
if (actions[0] == EnumWrappers.PlayerInfoAction.REMOVE_PLAYER) {
PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO_REMOVE);
packet.getModifier().write(0, Collections.singletonList(gameProfile.getUUID()));
return packet;
}
ClientboundPlayerInfoUpdatePacket.Entry entry =
new ClientboundPlayerInfoUpdatePacket.Entry(gameProfile.getUUID(), (GameProfile) gameProfile.getHandle(), nameVisible, 0, GameType.SURVIVAL,
Component.literal(displayName), null);
PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
StructureModifier<Object> modifier = packet.getModifier();
EnumSet<ClientboundPlayerInfoUpdatePacket.Action> enumSet =
EnumSet.copyOf(Arrays.stream(actions).map(action -> ClientboundPlayerInfoUpdatePacket.Action.valueOf(action.name())).collect(Collectors.toList()));
modifier.write(0, enumSet);
modifier.write(1, Collections.singletonList(entry));
return packet;
}
public Object getNmsEntity(Entity entity) {
return ((CraftEntity) entity).getHandle();
}
public double getPing(Player player) {
return player.getPing();
}
public float[] getSize(Entity entity) {
net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
EntityDimensions dimensions = nmsEntity.getDimensions(net.minecraft.world.entity.Pose.STANDING);
return new float[]{dimensions.width, nmsEntity.getEyeHeight()};
}
public WrappedGameProfile getSkullBlob(WrappedGameProfile gameProfile) {
DedicatedServer minecraftServer = getMinecraftServer();
MinecraftSessionService sessionService = minecraftServer.getSessionService();
return WrappedGameProfile.fromHandle(sessionService.fetchProfile(gameProfile.getUUID(), true).profile());
}
public Float getSoundModifier(Object entity) {
// Default is 1.0F on EntityLiving
if (!(entity instanceof net.minecraft.world.entity.LivingEntity)) {
return 0.0f;
} else {
try {
Method method = net.minecraft.world.entity.LivingEntity.class.getDeclaredMethod("eV");
method.setAccessible(true);
return (Float) method.invoke(entity);
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
e.printStackTrace();
}
}
return 0f;
}
public void injectCallback(String playername, ProfileLookupCallback callback) {
getMinecraftServer().getProfileRepository().findProfilesByNames(new String[]{playername}, callback);
}
public void setBoundingBox(Entity entity, double x, double y, double z) {
Location loc = entity.getLocation();
((CraftEntity) entity).getHandle()
.setBoundingBox(new AABB(loc.getX() - x / 2, loc.getY() - y / 2, loc.getZ() - z / 2, loc.getX() + x / 2, loc.getY() + y / 2, loc.getZ() + z / 2));
}
public Enum getSoundCategory(String category) {
return Arrays.stream(SoundSource.values()).filter(soundSource -> category.equalsIgnoreCase(soundSource.getName())).findAny().get();
}
/**
* Creates the NMS object EnumItemSlot from an EquipmentSlot.
*
* @param slot
* @return null if the equipment slot is null
*/
public Enum createEnumItemSlot(EquipmentSlot slot) {
switch (slot) {
case HAND:
return net.minecraft.world.entity.EquipmentSlot.MAINHAND;
case OFF_HAND:
return net.minecraft.world.entity.EquipmentSlot.OFFHAND;
case FEET:
return net.minecraft.world.entity.EquipmentSlot.FEET;
case LEGS:
return net.minecraft.world.entity.EquipmentSlot.LEGS;
case CHEST:
return net.minecraft.world.entity.EquipmentSlot.CHEST;
case HEAD:
return net.minecraft.world.entity.EquipmentSlot.HEAD;
default:
return null;
}
}
public Object getSoundString(Sound sound) {
return CraftSound.bukkitToMinecraft(sound).getLocation().toString();
}
public Optional<?> convertOptional(Object val) {
if (val instanceof BlockPosition) {
BlockPosition pos = (BlockPosition) val;
return Optional.of(getBlockPosition(pos.getX(), pos.getY(), pos.getZ()));
} else if (val instanceof WrappedBlockData) {
Object obj = ((WrappedBlockData) val).getHandle();
return Optional.of(obj);
} else if (val instanceof ItemStack) {
Object obj = getNmsItem((ItemStack) val);
return Optional.of(obj);
} else if (val instanceof WrappedChatComponent) {
Object obj = ((WrappedChatComponent) val).getHandle();
return Optional.of(obj);
}
return Optional.of(val);
}
public Vector3f convertVec3(Object object) {
if (object instanceof Vector3F) {
Vector3F vector3F = (Vector3F) object;
return new Vector3f(vector3F.getX(), vector3F.getY(), vector3F.getZ());
} else if (object instanceof EulerAngle) {
EulerAngle eulerAngle = (EulerAngle) object;
return new Vector3f((float) eulerAngle.getX(), (float) eulerAngle.getY(), (float) eulerAngle.getZ());
}
return null;
}
public net.minecraft.core.Direction convertDirection(Direction direction) {
return net.minecraft.core.Direction.from3DDataValue(direction.ordinal());
}
public Material getMaterial(String name) {
return CraftMagicNumbers.INSTANCE.getMaterial(name, CraftMagicNumbers.INSTANCE.getDataVersion());
}
public String getItemName(Material material) {
return BuiltInRegistries.ITEM.getKey(CraftMagicNumbers.getItem(material)).getPath();
}
public net.minecraft.world.item.ItemStack getNmsItem(ItemStack itemStack) {
return CraftItemStack.asNMSCopy(itemStack);
}
public VillagerData getNmsVillagerData(Villager.Type villagerType, Villager.Profession villagerProfession, int level) {
VillagerType nmsVillagerType = BuiltInRegistries.VILLAGER_TYPE.get(CraftNamespacedKey.toMinecraft(villagerType.getKey()));
VillagerProfession nmsVillagerProfession = BuiltInRegistries.VILLAGER_PROFESSION.get(CraftNamespacedKey.toMinecraft(villagerProfession.getKey()));
return new net.minecraft.world.entity.npc.VillagerData(nmsVillagerType, nmsVillagerProfession, level);
}
public VillagerType getVillagerType(Villager.Type type) {
return BuiltInRegistries.VILLAGER_TYPE.get(CraftNamespacedKey.toMinecraft(type.getKey()));
}
public VillagerProfession getVillagerProfession(Villager.Profession profession) {
return BuiltInRegistries.VILLAGER_PROFESSION.get(CraftNamespacedKey.toMinecraft(profession.getKey()));
}
public <T> SynchedEntityData.DataItem<T> createDataWatcherItem(WrappedDataWatcher.WrappedDataWatcherObject wrappedDataWatcherObject, T metaItem) {
return new SynchedEntityData.DataItem<>((EntityDataAccessor<T>) wrappedDataWatcherObject.getHandle(), metaItem);
}
public Holder<SoundEvent> createSoundEvent(String minecraftKey) {
return BuiltInRegistries.SOUND_EVENT.wrapAsHolder(SoundEvent.createVariableRangeEvent(createMinecraftKey(minecraftKey)));
}
@Override
public ResourceLocation createMinecraftKey(String name) {
return new ResourceLocation(name);
}
public Vec3 getVec3D(Vector vector) {
return new Vec3(vector.getX(), vector.getY(), vector.getZ());
}
public net.minecraft.world.entity.EntityType getEntityType(EntityType entityType) {
return net.minecraft.world.entity.EntityType.byString(
entityType.getName() == null ? entityType.name().toLowerCase(Locale.ENGLISH) : entityType.getName()).orElse(null);
}
public Object registerEntityType(NamespacedKey key) {
net.minecraft.world.entity.EntityType<net.minecraft.world.entity.Entity> newEntity =
new net.minecraft.world.entity.EntityType<>(null, null, false, false, false, false, null, null, 0, 0, FeatureFlagSet.of());
Registry.register(BuiltInRegistries.ENTITY_TYPE, CraftNamespacedKey.toMinecraft(key), newEntity);
newEntity.getDescriptionId();
return newEntity; // TODO ??? Some reflection in legacy that I'm unsure about
}
public int getEntityTypeId(Object entityTypes) {
net.minecraft.world.entity.EntityType entityType = (net.minecraft.world.entity.EntityType) entityTypes;
return BuiltInRegistries.ENTITY_TYPE.getId(entityType);
}
public int getEntityTypeId(EntityType entityType) {
return getEntityTypeId(getEntityType(entityType));
}
public Object getEntityType(NamespacedKey name) {
return BuiltInRegistries.ENTITY_TYPE.get(CraftNamespacedKey.toMinecraft(name));
}
public Object getNmsEntityPose(String enumPose) {
return net.minecraft.world.entity.Pose.valueOf(enumPose);
}
public int getCombinedIdByBlockData(BlockData data) {
BlockState state = ((CraftBlockData) data).getState();
return Block.getId(state);
}
public int getCombinedIdByItemStack(ItemStack itemStack) {
Block block = CraftMagicNumbers.getBlock(itemStack.getType());
return Block.getId(block.defaultBlockState());
}
public BlockData getBlockDataByCombinedId(int id) {
return CraftBlockData.fromData(Block.stateById(id));
}
public ItemStack getItemStackByCombinedId(int id) {
return new ItemStack(CraftMagicNumbers.getMaterial(Block.stateById(id).getBlock()));
}
public ServerLevel getWorldServer(World w) {
return ((CraftWorld) w).getHandle();
}
public ItemMeta getDeserializedItemMeta(Map<String, Object> meta) {
try {
Class<?> aClass = Class.forName("org.bukkit.craftbukkit.v1_20_R2.inventory.CraftMetaItem$SerializableMeta");
Method deserialize = aClass.getDeclaredMethod("deserialize", Map.class);
Object itemMeta = deserialize.invoke(null, meta);
return (ItemMeta) itemMeta;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
@Override
public Object convertInvalidMeta(Object value) {
if (value instanceof Frog.Variant) {
return getFrogVariant((Frog.Variant) value);
}
if (value instanceof Cat.Type) {
return getCatVariant((Cat.Type) value);
}
if (value instanceof Art) {
return getArtVariant((Art) value);
}
if (value instanceof BlockData) {
return ((CraftBlockData) value).getState();
}
if (value instanceof Sniffer.State) {
return net.minecraft.world.entity.animal.sniffer.Sniffer.State.values()[((Sniffer.State) value).ordinal()];
}
return value;
}
private FrogVariant getFrogVariant(Frog.Variant variant) {
switch (variant) {
case COLD:
return FrogVariant.COLD;
case WARM:
return FrogVariant.WARM;
case TEMPERATE:
return FrogVariant.TEMPERATE;
}
return null;
}
private CatVariant getCatVariant(Cat.Type type) {
return BuiltInRegistries.CAT_VARIANT.byId(type.ordinal());
}
private Holder.Reference<PaintingVariant> getArtVariant(Art art) {
return BuiltInRegistries.PAINTING_VARIANT.getHolder(art.ordinal()).get();
}
@Override
public Class getNmsClass(Class cl) {
if (Sniffer.State.class.isAssignableFrom(cl)) {
return net.minecraft.world.entity.animal.sniffer.Sniffer.State.class;
}
return cl;
}
}

View File

@ -251,6 +251,14 @@
<scope>compile</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>LibsDisguises</groupId>
<artifactId>v1_20_R2</artifactId>
<version>1.0-SNAPSHOT</version>
<classifier>remapped-spigot</classifier>
<scope>compile</scope>
<optional>true</optional>
</dependency>
<!-- Libraries -->
<dependency>
<groupId>it.unimi.dsi</groupId>

View File

@ -33,7 +33,7 @@ public enum DisguiseType {
BOAT(1),
@NmsAddedIn(NmsVersion.v1_20) CAMEL,
@NmsAddedIn(NmsVersion.v1_20_R1) CAMEL,
@NmsAddedIn(NmsVersion.v1_14) CAT,
@ -203,7 +203,7 @@ public enum DisguiseType {
SMALL_FIREBALL(63),
@NmsAddedIn(NmsVersion.v1_20) SNIFFER,
@NmsAddedIn(NmsVersion.v1_20_R1) SNIFFER,
SNOWBALL(61),

View File

@ -317,36 +317,39 @@ public class MetaIndex<Y> {
public static MetaIndex<Integer> DISPLAY_INTERPOLATION_DURATION = new MetaIndex<>(DisplayWatcher.class, 1, 0);
@NmsAddedIn(NmsVersion.v1_20_R2)
public static MetaIndex<Integer> DISPLAY_POS_ROT_INTERPOLATION_DURATION = new MetaIndex<>(DisplayWatcher.class, 2, 0);
@NmsAddedIn(NmsVersion.v1_19_R3)
public static MetaIndex<Vector3f> DISPLAY_TRANSLATION = new MetaIndex<>(DisplayWatcher.class, 2, NmsVersion.v1_19_R3.isSupported() ? new Vector3f() : null);
public static MetaIndex<Vector3f> DISPLAY_TRANSLATION = new MetaIndex<>(DisplayWatcher.class, 3, NmsVersion.v1_19_R3.isSupported() ? new Vector3f() : null);
@NmsAddedIn(NmsVersion.v1_19_R3)
public static MetaIndex<Vector3f> DISPLAY_SCALE =
new MetaIndex<>(DisplayWatcher.class, 3, NmsVersion.v1_19_R3.isSupported() ? new Vector3f(1F, 1F, 1F) : null);
new MetaIndex<>(DisplayWatcher.class, 4, NmsVersion.v1_19_R3.isSupported() ? new Vector3f(1F, 1F, 1F) : null);
@NmsAddedIn(NmsVersion.v1_19_R3)
public static MetaIndex<Quaternionf> DISPLAY_LEFT_ROTATION =
new MetaIndex<>(DisplayWatcher.class, 4, NmsVersion.v1_19_R3.isSupported() ? new Quaternionf() : null);
new MetaIndex<>(DisplayWatcher.class, 5, NmsVersion.v1_19_R3.isSupported() ? new Quaternionf() : null);
@NmsAddedIn(NmsVersion.v1_19_R3)
public static MetaIndex<Quaternionf> DISPLAY_RIGHT_ROTATION =
new MetaIndex<>(DisplayWatcher.class, 5, NmsVersion.v1_19_R3.isSupported() ? new Quaternionf() : null);
new MetaIndex<>(DisplayWatcher.class, 6, NmsVersion.v1_19_R3.isSupported() ? new Quaternionf() : null);
public static MetaIndex<Byte> DISPLAY_BILLBOARD_RENDER_CONSTRAINTS = new MetaIndex<>(DisplayWatcher.class, 6, (byte) 0);
public static MetaIndex<Byte> DISPLAY_BILLBOARD_RENDER_CONSTRAINTS = new MetaIndex<>(DisplayWatcher.class, 7, (byte) 0);
public static MetaIndex<Integer> DISPLAY_BRIGHTNESS_OVERRIDE = new MetaIndex<>(DisplayWatcher.class, 7, -1);
public static MetaIndex<Integer> DISPLAY_BRIGHTNESS_OVERRIDE = new MetaIndex<>(DisplayWatcher.class, 8, -1);
public static MetaIndex<Float> DISPLAY_VIEW_RANGE = new MetaIndex<>(DisplayWatcher.class, 8, 1F);
public static MetaIndex<Float> DISPLAY_VIEW_RANGE = new MetaIndex<>(DisplayWatcher.class, 9, 1F);
public static MetaIndex<Float> DISPLAY_SHADOW_RADIUS = new MetaIndex<>(DisplayWatcher.class, 9, 0F);
public static MetaIndex<Float> DISPLAY_SHADOW_RADIUS = new MetaIndex<>(DisplayWatcher.class, 10, 0F);
public static MetaIndex<Float> DISPLAY_SHADOW_STRENGTH = new MetaIndex<>(DisplayWatcher.class, 10, 1F);
public static MetaIndex<Float> DISPLAY_SHADOW_STRENGTH = new MetaIndex<>(DisplayWatcher.class, 11, 1F);
public static MetaIndex<Float> DISPLAY_WIDTH = new MetaIndex<>(DisplayWatcher.class, 11, 0F);
public static MetaIndex<Float> DISPLAY_WIDTH = new MetaIndex<>(DisplayWatcher.class, 12, 0F);
public static MetaIndex<Float> DISPLAY_HEIGHT = new MetaIndex<>(DisplayWatcher.class, 12, 0F);
public static MetaIndex<Float> DISPLAY_HEIGHT = new MetaIndex<>(DisplayWatcher.class, 13, 0F);
public static MetaIndex<Integer> DISPLAY_GLOW_COLOR_OVERRIDE = new MetaIndex<>(DisplayWatcher.class, 13, -1);
public static MetaIndex<Integer> DISPLAY_GLOW_COLOR_OVERRIDE = new MetaIndex<>(DisplayWatcher.class, 14, -1);
/**
* No visible effect
@ -745,7 +748,7 @@ public class MetaIndex<Y> {
public static MetaIndex<Byte> SNOWMAN_DERP = new MetaIndex<>(SnowmanWatcher.class, 0, (byte) 16);
public static MetaIndex<Sniffer.State> SNIFFER_STATE =
new MetaIndex<>(SnifferWatcher.class, 0, NmsVersion.v1_20.isSupported() ? Sniffer.State.IDLING : null);
new MetaIndex<>(SnifferWatcher.class, 0, NmsVersion.v1_20_R1.isSupported() ? Sniffer.State.IDLING : null);
public static MetaIndex<Integer> SNIFFER_DROP_SEED_AT_TICK = new MetaIndex<>(SnifferWatcher.class, 1, 0);

View File

@ -174,4 +174,13 @@ public abstract class DisplayWatcher extends FlagWatcher {
setData(MetaIndex.DISPLAY_BRIGHTNESS_OVERRIDE, brightness == null ? -1 : brightness.getBlockLight() << 4 | brightness.getSkyLight() << 20);
sendData(MetaIndex.DISPLAY_BRIGHTNESS_OVERRIDE);
}
public int getTeleportDuration() {
return getData(MetaIndex.DISPLAY_POS_ROT_INTERPOLATION_DURATION);
}
public void setTeleportDuration(int duration) {
setData(MetaIndex.DISPLAY_POS_ROT_INTERPOLATION_DURATION, Math.max(0, Math.min(59, duration)));
sendData(MetaIndex.DISPLAY_POS_ROT_INTERPOLATION_DURATION);
}
}

View File

@ -89,6 +89,7 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.metadata.FixedMetadataValue;
import org.bukkit.persistence.PersistentDataContainer;
import org.bukkit.persistence.PersistentDataType;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.potion.PotionEffect;
import org.bukkit.scheduler.BukkitRunnable;
@ -603,11 +604,29 @@ public class DisguiseUtilities {
requiredVersion = new String[]{"5.0.0", "630"};
}
// If you're on 1.20.2
if (NmsVersion.v1_20_R2.isSupported()) {
requiredVersion = new String[]{"5.1.1", "669"};
}
return requiredVersion;
}
public static boolean isProtocolLibOutdated() {
String plVersion = Bukkit.getPluginManager().getPlugin("ProtocolLib").getDescription().getVersion();
Plugin plugin = Bukkit.getPluginManager().getPlugin("ProtocolLib");
if (plugin == null) {
return true;
}
String plVersion;
try {
plVersion = plugin.getDescription().getVersion();
} catch (Throwable throwable) {
return true;
}
String[] reqVersion = getProtocolLibRequiredVersion();
// If this is also checking for a custom build, and PL has the custom build in..
@ -638,12 +657,16 @@ public class DisguiseUtilities {
public static File updateProtocolLib() throws Exception {
File dest = new File(LibsDisguises.getInstance().getDataFolder().getAbsoluteFile().getParentFile(), "ProtocolLib.jar");
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null) {
try {
Method getFile = JavaPlugin.class.getDeclaredMethod("getFile");
getFile.setAccessible(true);
File theirFile = (File) getFile.invoke(ProtocolLibrary.getPlugin());
dest = new File(Bukkit.getUpdateFolderFile(), theirFile.getName());
} catch (Throwable throwable) {
if (Bukkit.getPluginManager().getPlugin("ProtocolLib") != null && dest.exists()) {
dest = new File(Bukkit.getUpdateFolderFile(), "ProtocolLib.jar");
}
}
if (!dest.exists()) {
@ -2591,8 +2614,10 @@ public class DisguiseUtilities {
}
ProtocolManager manager = ProtocolLibrary.getProtocolManager();
// Send the player a packet with himself being spawned
manager.sendServerPacket(player, manager.createPacketConstructor(Server.NAMED_ENTITY_SPAWN, player).createPacket(player));
// Send the player a packet with themselves being spawned
manager.sendServerPacket(player,
manager.createPacketConstructor(NmsVersion.v1_20_R2.isSupported() ? Server.SPAWN_ENTITY : Server.NAMED_ENTITY_SPAWN, player)
.createPacket(player));
List<WatcherValue> watcherList = WrappedDataWatcher.getEntityWatcher(player).getWatchableObjects().stream()
.map(v -> new WatcherValue(MetaIndex.getMetaIndex(PlayerWatcher.class, v.getIndex()), v.getRawValue())).collect(Collectors.toList());
@ -2603,7 +2628,7 @@ public class DisguiseUtilities {
try {
// TODO Store the field
Field field = ReflectionManager.getNmsClass("EntityTrackerEntry").getDeclaredField(
Field field = ReflectionManager.getNmsClass("EntityTrackerEntry").getDeclaredField(NmsVersion.v1_20_R2.isSupported() ? "i" :
NmsVersion.v1_19_R1.isSupported() ? "p" : NmsVersion.v1_17.isSupported() ? "r" : NmsVersion.v1_14.isSupported() ? "q" : "isMoving");
field.setAccessible(true);
isMoving = field.getBoolean(entityTrackerEntry);
@ -2818,7 +2843,7 @@ public class DisguiseUtilities {
}
/**
* Method to send a packet to the self disguise, translate his entity ID to the fake id.
* Method to send a packet to the self disguise, translate their entity ID to the fake id.
*/
private static void sendSelfPacket(final Player player, final PacketContainer packet) {
final Disguise disguise = DisguiseAPI.getDisguise(player, player);
@ -2835,6 +2860,7 @@ public class DisguiseUtilities {
}
LibsPackets newPackets = new LibsPackets(disguise);
newPackets.setSkinHandling(transformed.isSkinHandling());
for (PacketContainer p : transformed.getPackets()) {
p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());

View File

@ -168,7 +168,7 @@ public class PlayerSkinHandler implements Listener {
}
public void handlePackets(Player player, PlayerDisguise disguise, LibsPackets packets) {
boolean spawn = packets.getPackets().stream().anyMatch(p -> p.getType() == Server.NAMED_ENTITY_SPAWN);
boolean spawn = packets.isSkinHandling();
List<PlayerSkin> skins = getCache().getIfPresent(player);

View File

@ -34,6 +34,7 @@ public class LibsPackets {
private final HashMap<Integer, ArrayList<PacketContainer>> delayedPacketsMap = new HashMap<>();
private final Disguise disguise;
private boolean unhandled;
private boolean skinHandling;
public Disguise getDisguise() {
return disguise;

View File

@ -124,7 +124,10 @@ public class PacketsManager {
ArrayList<PacketType> packetsToListen = new ArrayList<>();
// Add spawn packets
{
packetsToListen.add(Server.NAMED_ENTITY_SPAWN);
if (!NmsVersion.v1_20_R2.isSupported()) {
packetsToListen.add(Server.NAMED_ENTITY_SPAWN);
}
packetsToListen.add(Server.SPAWN_ENTITY_EXPERIENCE_ORB);
packetsToListen.add(Server.SPAWN_ENTITY);

View File

@ -55,16 +55,21 @@ public class PacketHandlerSpawn implements IPacketHandler {
@Override
public PacketType[] getHandledPackets() {
PacketType[] packets = new PacketType[]{PacketType.Play.Server.NAMED_ENTITY_SPAWN, PacketType.Play.Server.SPAWN_ENTITY_EXPERIENCE_ORB,
PacketType.Play.Server.SPAWN_ENTITY};
List<PacketType> packets = new ArrayList<>();
if (!NmsVersion.v1_19_R1.isSupported()) {
packets = Arrays.copyOf(packets, packets.length + 2);
packets[packets.length - 2] = PacketType.Play.Server.SPAWN_ENTITY_LIVING;
packets[packets.length - 1] = PacketType.Play.Server.SPAWN_ENTITY_PAINTING;
if (!NmsVersion.v1_20_R2.isSupported()) {
packets.add(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
}
return packets;
packets.add(PacketType.Play.Server.SPAWN_ENTITY_EXPERIENCE_ORB);
packets.add(PacketType.Play.Server.SPAWN_ENTITY);
if (!NmsVersion.v1_19_R1.isSupported()) {
packets.add(PacketType.Play.Server.SPAWN_ENTITY_LIVING);
packets.add(PacketType.Play.Server.SPAWN_ENTITY_PAINTING);
}
return packets.toArray(new PacketType[0]);
}
@Override
@ -176,26 +181,32 @@ public class PacketHandlerSpawn implements IPacketHandler {
}
skin.setSleepPackets(!inLineOfSight);
packets.setSkinHandling(true);
PacketContainer spawnPlayer;
// Spawn the player
PacketContainer spawnPlayer = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
if (NmsVersion.v1_20_R2.isSupported()) {
spawnPlayer = constructLivingPacket(observer, packets, disguisedEntity, loc, pitch, yaw);
} else {
// Spawn the player
spawnPlayer = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
spawnPlayer.getIntegers().write(0, entityId); // Id
spawnPlayer.getModifier().write(1, playerDisguise.getUUID());
spawnPlayer.getIntegers().write(0, entityId); // Id
spawnPlayer.getModifier().write(1, playerDisguise.getUUID());
Location spawnAt = inLineOfSight ? loc : observer.getLocation().add(observer.getLocation().getDirection().normalize().multiply(10));
Location spawnAt = inLineOfSight ? loc : observer.getLocation().add(observer.getLocation().getDirection().normalize().multiply(10));
// Spawn him in front of the observer
StructureModifier<Double> doubles = spawnPlayer.getDoubles();
doubles.write(0, spawnAt.getX());
doubles.write(1, spawnAt.getY());
doubles.write(2, spawnAt.getZ());
// Spawn them in front of the observer
StructureModifier<Double> doubles = spawnPlayer.getDoubles();
doubles.write(0, spawnAt.getX());
doubles.write(1, spawnAt.getY());
doubles.write(2, spawnAt.getZ());
StructureModifier<Byte> bytes = spawnPlayer.getBytes();
bytes.write(0, yaw);
bytes.write(1, pitch);
StructureModifier<Byte> bytes = spawnPlayer.getBytes();
bytes.write(0, yaw);
bytes.write(1, pitch);
packets.addPacket(spawnPlayer);
packets.addPacket(spawnPlayer);
}
List<WatcherValue> watcherValues;
@ -214,77 +225,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
spawnPlayer.getDataWatcherModifier().write(0, DisguiseUtilities.createDatawatcher(watcherValues));
}
} else if (disguise.isMobDisguise() || disguise.getType() == DisguiseType.ARMOR_STAND) {
Vector vec = disguisedEntity.getVelocity();
if (disguise.getType() == DisguiseType.SQUID && disguisedEntity.getType() != EntityType.SQUID) {
vec = new Vector();
}
PacketContainer spawnEntity =
new PacketContainer(NmsVersion.v1_19_R1.isSupported() ? PacketType.Play.Server.SPAWN_ENTITY : PacketType.Play.Server.SPAWN_ENTITY_LIVING);
packets.addPacket(spawnEntity);
StructureModifier<Object> mods = spawnEntity.getModifier();
mods.write(0, disguisedEntity.getEntityId());
mods.write(1, disguise.getUUID());
if (NmsVersion.v1_19_R1.isSupported()) {
if (!disguise.getType().isCustom()) {
mods.write(2, disguise.getType().getNmsEntityType());
} else {
mods.write(2, ((ModdedDisguise) disguise).getModdedEntity().getEntityType());
}
} else {
if (!disguise.getType().isCustom()) {
mods.write(2, disguise.getType().getTypeId());
} else {
mods.write(2, ((ModdedDisguise) disguise).getModdedEntity().getTypeId());
}
}
// region Vector calculations
double d1 = 3.9D;
double d2 = vec.getX();
double d3 = vec.getY();
double d4 = vec.getZ();
if (d2 < -d1) {
d2 = -d1;
}
if (d3 < -d1) {
d3 = -d1;
}
if (d4 < -d1) {
d4 = -d1;
}
if (d2 > d1) {
d2 = d1;
}
if (d3 > d1) {
d3 = d1;
}
if (d4 > d1) {
d4 = d1;
}
// endregion
mods.write(3, loc.getX());
mods.write(4, loc.getY());
mods.write(5, loc.getZ());
mods.write(6, (int) (d2 * 8000.0D));
mods.write(7, (int) (d3 * 8000.0D));
mods.write(8, (int) (d4 * 8000.0D));
// Prior to 1.19, it's Y, X, Y
if (!NmsVersion.v1_19_R1.isSupported()) {
mods.write(9, yaw);
mods.write(10, pitch);
} else {
mods.write(9, pitch);
mods.write(10, yaw);
}
mods.write(11, yaw);
PacketContainer spawnEntity = constructLivingPacket(observer, packets, disguisedEntity, loc, pitch, yaw);
List<WatcherValue> watcherValues =
DisguiseUtilities.createSanitizedWatcherValues(observer, WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher());
@ -505,4 +446,81 @@ public class PacketHandlerSpawn implements IPacketHandler {
}
}
}
private static PacketContainer constructLivingPacket(Player observer, LibsPackets packets, Entity disguisedEntity, Location loc, byte pitch, byte yaw) {
Disguise disguise = packets.getDisguise();
Vector vec = disguisedEntity.getVelocity();
if (disguise.getType() == DisguiseType.SQUID && disguisedEntity.getType() != EntityType.SQUID) {
vec = new Vector();
}
PacketContainer spawnEntity =
new PacketContainer(NmsVersion.v1_19_R1.isSupported() ? PacketType.Play.Server.SPAWN_ENTITY : PacketType.Play.Server.SPAWN_ENTITY_LIVING);
packets.addPacket(spawnEntity);
StructureModifier<Object> mods = spawnEntity.getModifier();
mods.write(0, disguisedEntity.getEntityId());
mods.write(1, disguise.getUUID());
if (NmsVersion.v1_19_R1.isSupported()) {
if (!disguise.getType().isCustom()) {
mods.write(2, disguise.getType().getNmsEntityType());
} else {
mods.write(2, ((ModdedDisguise) disguise).getModdedEntity().getEntityType());
}
} else {
if (!disguise.getType().isCustom()) {
mods.write(2, disguise.getType().getTypeId());
} else {
mods.write(2, ((ModdedDisguise) disguise).getModdedEntity().getTypeId());
}
}
// region Vector calculations
double d1 = 3.9D;
double d2 = vec.getX();
double d3 = vec.getY();
double d4 = vec.getZ();
if (d2 < -d1) {
d2 = -d1;
}
if (d3 < -d1) {
d3 = -d1;
}
if (d4 < -d1) {
d4 = -d1;
}
if (d2 > d1) {
d2 = d1;
}
if (d3 > d1) {
d3 = d1;
}
if (d4 > d1) {
d4 = d1;
}
// endregion
mods.write(3, loc.getX());
mods.write(4, loc.getY());
mods.write(5, loc.getZ());
mods.write(6, (int) (d2 * 8000.0D));
mods.write(7, (int) (d3 * 8000.0D));
mods.write(8, (int) (d4 * 8000.0D));
// Prior to 1.19, it's Y, X, Y
if (!NmsVersion.v1_19_R1.isSupported()) {
mods.write(9, yaw);
mods.write(10, pitch);
} else {
mods.write(9, pitch);
mods.write(10, yaw);
}
mods.write(11, yaw);
return spawnEntity;
}
}

View File

@ -31,9 +31,10 @@ import java.util.Map;
public class PacketListenerViewSelfDisguise extends PacketAdapter {
public PacketListenerViewSelfDisguise(LibsDisguises plugin) {
super(plugin, ListenerPriority.HIGH, Server.NAMED_ENTITY_SPAWN, Server.ATTACH_ENTITY, Server.REL_ENTITY_MOVE, Server.REL_ENTITY_MOVE_LOOK,
Server.ENTITY_LOOK, Server.ENTITY_TELEPORT, Server.ENTITY_HEAD_ROTATION, Server.ENTITY_METADATA, Server.ENTITY_EQUIPMENT, Server.ANIMATION,
Server.ENTITY_EFFECT, Server.ENTITY_VELOCITY, Server.UPDATE_ATTRIBUTES, Server.ENTITY_STATUS);
super(plugin, ListenerPriority.HIGH, NmsVersion.v1_20_R2.isSupported() ? Server.SPAWN_ENTITY : Server.NAMED_ENTITY_SPAWN, Server.ATTACH_ENTITY,
Server.REL_ENTITY_MOVE, Server.REL_ENTITY_MOVE_LOOK, Server.ENTITY_LOOK, Server.ENTITY_TELEPORT, Server.ENTITY_HEAD_ROTATION,
Server.ENTITY_METADATA, Server.ENTITY_EQUIPMENT, Server.ANIMATION, Server.ENTITY_EFFECT, Server.ENTITY_VELOCITY, Server.UPDATE_ATTRIBUTES,
Server.ENTITY_STATUS);
}
@Override
@ -74,6 +75,7 @@ public class PacketListenerViewSelfDisguise extends PacketAdapter {
}
LibsPackets selfTransformed = new LibsPackets(disguise);
selfTransformed.setSkinHandling(transformed.isSkinHandling());
for (PacketContainer newPacket : transformed.getPackets()) {
if (newPacket.getType() != Server.PLAYER_INFO && newPacket.getType() != Server.ENTITY_DESTROY &&
@ -145,7 +147,7 @@ public class PacketListenerViewSelfDisguise extends PacketAdapter {
watch.setValue(a);
}
}
} else if (event.getPacketType() == Server.NAMED_ENTITY_SPAWN) {
} else if (event.getPacketType() == Server.NAMED_ENTITY_SPAWN || event.getPacketType() == Server.SPAWN_ENTITY) {
event.setCancelled(true);
List<WatcherValue> watchableList = new ArrayList<>();

View File

@ -161,7 +161,7 @@ public class ParamInfoTypes {
}
}
if (NmsVersion.v1_20.isSupported()) {
if (NmsVersion.v1_20_R1.isSupported()) {
paramInfos.add(new ParamInfoEnum(Sniffer.State.class, "Sniffer State", "The current mindset of a Sniffer"));
}

View File

@ -14,7 +14,8 @@ public enum NmsVersion {
v1_19_R1, // 1.19.0, 1.19.1, 1.19.2
v1_19_R2, // 1.19.3
v1_19_R3, // 1.19.4
v1_20, // 1.20
v1_20_R1, // 1.20 & 1.20.1
v1_20_R2, // 1.20.2
UNSUPPORTED;
/**

View File

@ -79,7 +79,6 @@ import org.bukkit.entity.Frog;
import org.bukkit.entity.LivingEntity;
import org.bukkit.entity.Monster;
import org.bukkit.entity.Player;
import org.bukkit.entity.Sniffer;
import org.bukkit.entity.Tameable;
import org.bukkit.entity.Villager;
import org.bukkit.entity.Zombie;
@ -1270,13 +1269,13 @@ public class ReflectionManager {
*/
public static WrappedGameProfile grabProfileAddUUID(String playername) {
try {
Object minecraftServer = getMinecraftServer();
LibsProfileLookupCaller callback = new LibsProfileLookupCaller();
if (nmsReflection != null) {
nmsReflection.injectCallback(playername, callback);
} else {
Object minecraftServer = getMinecraftServer();
for (Method method : getNmsClass("MinecraftServer").getMethods()) {
if (method.getReturnType().getSimpleName().equals("GameProfileRepository")) {
Object agent = Class.forName("com.mojang.authlib.Agent").getDeclaredField("MINECRAFT").get(null);

View File

@ -24,7 +24,7 @@
<lombok.version>1.18.26</lombok.version>
<protocollib.version>5.0.0</protocollib.version>
<spigot.version>1.20-R0.1-SNAPSHOT</spigot.version>
<spigot.version>1.20.2-R0.1-SNAPSHOT</spigot.version>
<junit.version>4.13.2</junit.version>
<junit-jupiter.version>5.9.3</junit-jupiter.version>
<paper-api.version>1.19.4-R0.1-SNAPSHOT</paper-api.version>