mirror of
https://github.com/libraryaddict/LibsDisguises.git
synced 2025-02-09 00:31:37 +01:00
Update for 1.19.3
This commit is contained in:
parent
e94067b9f0
commit
136b3b4334
@ -18,6 +18,7 @@
|
||||
<module>v1_18_R2</module>
|
||||
<module>v1_19_R1</module>
|
||||
<module>v1_19_1_R1</module>
|
||||
<module>v1_19_R2</module>
|
||||
</modules>
|
||||
|
||||
</project>
|
||||
|
@ -42,7 +42,7 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<groupId>com.github.dmulloy2</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -1,6 +1,10 @@
|
||||
package me.libraryaddict.disguise.utilities.reflection.v1_17;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
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;
|
||||
@ -76,6 +80,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@ -229,13 +234,18 @@ public class ReflectionManager implements ReflectionManagerAbstract {
|
||||
return net.minecraft.core.Direction.from2DDataValue(direction);
|
||||
}
|
||||
|
||||
public ClientboundPlayerInfoPacket.Action getEnumPlayerInfoAction(int action) {
|
||||
return ClientboundPlayerInfoPacket.Action.values()[action];
|
||||
}
|
||||
@Override
|
||||
public PacketContainer getTabListPacket(String displayName, WrappedGameProfile gameProfile, EnumWrappers.PlayerInfoAction action, boolean nameVisible) {
|
||||
ClientboundPlayerInfoPacket.PlayerUpdate entry =
|
||||
new ClientboundPlayerInfoPacket.PlayerUpdate((GameProfile) gameProfile.getHandle(), 0, GameType.SURVIVAL, new TextComponent(displayName));
|
||||
|
||||
public ClientboundPlayerInfoPacket.PlayerUpdate getPlayerInfoData(WrappedGameProfile gameProfile) {
|
||||
return new ClientboundPlayerInfoPacket.PlayerUpdate((GameProfile) gameProfile.getHandle(), 0, GameType.SURVIVAL,
|
||||
new TextComponent(gameProfile.getName()));
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
StructureModifier<Object> modifier = packet.getModifier();
|
||||
|
||||
modifier.write(0, ClientboundPlayerInfoPacket.Action.valueOf(action.name()));
|
||||
modifier.write(1, Collections.singletonList(entry));
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
public Object getNmsEntity(Entity entity) {
|
||||
|
@ -41,7 +41,7 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<groupId>com.github.dmulloy2</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
package me.libraryaddict.disguise.utilities.reflection.v1_18_1;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
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;
|
||||
@ -76,6 +80,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@ -229,13 +234,18 @@ public class ReflectionManager implements ReflectionManagerAbstract {
|
||||
return net.minecraft.core.Direction.from2DDataValue(direction);
|
||||
}
|
||||
|
||||
public ClientboundPlayerInfoPacket.Action getEnumPlayerInfoAction(int action) {
|
||||
return ClientboundPlayerInfoPacket.Action.values()[action];
|
||||
}
|
||||
@Override
|
||||
public PacketContainer getTabListPacket(String displayName, WrappedGameProfile gameProfile, EnumWrappers.PlayerInfoAction action, boolean nameVisible) {
|
||||
ClientboundPlayerInfoPacket.PlayerUpdate entry =
|
||||
new ClientboundPlayerInfoPacket.PlayerUpdate((GameProfile) gameProfile.getHandle(), 0, GameType.SURVIVAL, new TextComponent(displayName));
|
||||
|
||||
public ClientboundPlayerInfoPacket.PlayerUpdate getPlayerInfoData(WrappedGameProfile gameProfile) {
|
||||
return new ClientboundPlayerInfoPacket.PlayerUpdate((GameProfile) gameProfile.getHandle(), 0, GameType.SURVIVAL,
|
||||
new TextComponent(gameProfile.getName()));
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
StructureModifier<Object> modifier = packet.getModifier();
|
||||
|
||||
modifier.write(0, ClientboundPlayerInfoPacket.Action.valueOf(action.name()));
|
||||
modifier.write(1, Collections.singletonList(entry));
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
public Object getNmsEntity(Entity entity) {
|
||||
|
@ -41,7 +41,7 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<groupId>com.github.dmulloy2</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
package me.libraryaddict.disguise.utilities.reflection.v1_18_2;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
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;
|
||||
@ -16,6 +20,7 @@ import me.libraryaddict.disguise.utilities.reflection.ReflectionManagerAbstract;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.Vector3f;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.TextComponent;
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
@ -76,6 +81,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@ -229,13 +235,18 @@ public class ReflectionManager implements ReflectionManagerAbstract {
|
||||
return net.minecraft.core.Direction.from2DDataValue(direction);
|
||||
}
|
||||
|
||||
public ClientboundPlayerInfoPacket.Action getEnumPlayerInfoAction(int action) {
|
||||
return ClientboundPlayerInfoPacket.Action.values()[action];
|
||||
}
|
||||
@Override
|
||||
public PacketContainer getTabListPacket(String displayName, WrappedGameProfile gameProfile, EnumWrappers.PlayerInfoAction action, boolean nameVisible) {
|
||||
ClientboundPlayerInfoPacket.PlayerUpdate entry =
|
||||
new ClientboundPlayerInfoPacket.PlayerUpdate((GameProfile) gameProfile.getHandle(), 0, GameType.SURVIVAL, new TextComponent(displayName));
|
||||
|
||||
public ClientboundPlayerInfoPacket.PlayerUpdate getPlayerInfoData(WrappedGameProfile gameProfile) {
|
||||
return new ClientboundPlayerInfoPacket.PlayerUpdate((GameProfile) gameProfile.getHandle(), 0, GameType.SURVIVAL,
|
||||
new TextComponent(gameProfile.getName()));
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
StructureModifier<Object> modifier = packet.getModifier();
|
||||
|
||||
modifier.write(0, ClientboundPlayerInfoPacket.Action.valueOf(action.name()));
|
||||
modifier.write(1, Collections.singletonList(entry));
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
public Object getNmsEntity(Entity entity) {
|
||||
|
@ -41,7 +41,7 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<groupId>com.github.dmulloy2</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
package me.libraryaddict.disguise.utilities.reflection.v1_19_1;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
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;
|
||||
@ -83,6 +87,7 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@ -236,13 +241,18 @@ public class ReflectionManager implements ReflectionManagerAbstract {
|
||||
return net.minecraft.core.Direction.from2DDataValue(direction);
|
||||
}
|
||||
|
||||
public ClientboundPlayerInfoPacket.Action getEnumPlayerInfoAction(int action) {
|
||||
return ClientboundPlayerInfoPacket.Action.values()[action];
|
||||
}
|
||||
@Override
|
||||
public PacketContainer getTabListPacket(String displayName, WrappedGameProfile gameProfile, EnumWrappers.PlayerInfoAction action, boolean nameVisible) {
|
||||
ClientboundPlayerInfoPacket.PlayerUpdate entry =
|
||||
new ClientboundPlayerInfoPacket.PlayerUpdate((GameProfile) gameProfile.getHandle(), 0, GameType.SURVIVAL, Component.literal(displayName), null);
|
||||
|
||||
public ClientboundPlayerInfoPacket.PlayerUpdate getPlayerInfoData(WrappedGameProfile gameProfile) {
|
||||
return new ClientboundPlayerInfoPacket.PlayerUpdate((GameProfile) gameProfile.getHandle(), 0, GameType.SURVIVAL,
|
||||
Component.literal(gameProfile.getName()), null);
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
StructureModifier<Object> modifier = packet.getModifier();
|
||||
|
||||
modifier.write(0, ClientboundPlayerInfoPacket.Action.valueOf(action.name()));
|
||||
modifier.write(1, Collections.singletonList(entry));
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
public Object getNmsEntity(Entity entity) {
|
||||
|
@ -41,7 +41,7 @@
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<groupId>com.github.dmulloy2</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
@ -1,6 +1,10 @@
|
||||
package me.libraryaddict.disguise.utilities.reflection.v1_19;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
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;
|
||||
@ -11,11 +15,13 @@ import com.mojang.authlib.Agent;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import com.mojang.authlib.ProfileLookupCallback;
|
||||
import com.mojang.authlib.minecraft.MinecraftSessionService;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManagerAbstract;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.Vector3f;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.protocol.game.ClientboundPlayerInfoPacket;
|
||||
import net.minecraft.network.syncher.EntityDataAccessor;
|
||||
@ -83,6 +89,8 @@ import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@ -236,13 +244,18 @@ public class ReflectionManager implements ReflectionManagerAbstract {
|
||||
return net.minecraft.core.Direction.from2DDataValue(direction);
|
||||
}
|
||||
|
||||
public ClientboundPlayerInfoPacket.Action getEnumPlayerInfoAction(int action) {
|
||||
return ClientboundPlayerInfoPacket.Action.values()[action];
|
||||
}
|
||||
@Override
|
||||
public PacketContainer getTabListPacket(String displayName, WrappedGameProfile gameProfile, EnumWrappers.PlayerInfoAction action, boolean nameVisible) {
|
||||
ClientboundPlayerInfoPacket.PlayerUpdate entry =
|
||||
new ClientboundPlayerInfoPacket.PlayerUpdate((GameProfile) gameProfile.getHandle(), 0, GameType.SURVIVAL, Component.literal(displayName), null);
|
||||
|
||||
public ClientboundPlayerInfoPacket.PlayerUpdate getPlayerInfoData(WrappedGameProfile gameProfile) {
|
||||
return new ClientboundPlayerInfoPacket.PlayerUpdate((GameProfile) gameProfile.getHandle(), 0, GameType.SURVIVAL,
|
||||
Component.literal(gameProfile.getName()), null);
|
||||
PacketContainer packet = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
StructureModifier<Object> modifier = packet.getModifier();
|
||||
|
||||
modifier.write(0, ClientboundPlayerInfoPacket.Action.valueOf(action.name()));
|
||||
modifier.write(1, Collections.singletonList(entry));
|
||||
|
||||
return packet;
|
||||
}
|
||||
|
||||
public Object getNmsEntity(Entity entity) {
|
||||
|
116
nms/v1_19_R2/pom.xml
Normal file
116
nms/v1_19_R2/pom.xml
Normal 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_19_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.19.3-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.github.dmulloy2</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mojang</groupId>
|
||||
<artifactId>authlib</artifactId>
|
||||
<version>3.3.39</version>
|
||||
<scope>provided</scope>
|
||||
</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>3.5.41</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.mojang</groupId>
|
||||
<artifactId>datafixerupper</artifactId>
|
||||
<version>5.0.28</version>
|
||||
<scope>provided</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>
|
@ -0,0 +1,536 @@
|
||||
package me.libraryaddict.disguise.utilities.reflection.v1_19_R2;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
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.Agent;
|
||||
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.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.damagesource.DamageSource;
|
||||
import net.minecraft.world.effect.MobEffect;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.entity.EntityDimensions;
|
||||
import net.minecraft.world.entity.animal.CatVariant;
|
||||
import net.minecraft.world.entity.animal.FrogVariant;
|
||||
import net.minecraft.world.entity.animal.camel.Camel;
|
||||
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.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_19_R2.CraftArt;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.CraftSound;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.block.data.CraftBlockData;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftEntity;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.craftbukkit.v1_19_R2.util.CraftMagicNumbers;
|
||||
import org.bukkit.craftbukkit.v1_19_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.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.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
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(DamageSource.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("c");
|
||||
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");
|
||||
entity = new ServerPlayer(getMinecraftServer(), world, (GameProfile) gameProfile.getHandle());
|
||||
}/* else if (entityType == net.minecraft.world.entity.EntityType.ENDER_PEARL) {
|
||||
entity = new ThrownEnderpearl(world, (net.minecraft.world.entity.LivingEntity) createEntityInstance("cow"));
|
||||
} else if (entityType == net.minecraft.world.entity.EntityType.FISHING_BOBBER) {
|
||||
entity = new FishingHook((net.minecraft.world.entity.player.Player) createEntityInstance("player"), world, 0, 0);
|
||||
}*/ 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 MobEffect.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 SoundEvent getCraftSound(Sound sound) {
|
||||
return CraftSound.getSoundEffect(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.BukkitToNotch(art).value()).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);
|
||||
}
|
||||
|
||||
public PacketContainer getTabListPacket(String displayName, WrappedGameProfile gameProfile, EnumWrappers.PlayerInfoAction action, boolean nameVisible) {
|
||||
if (action == 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();
|
||||
|
||||
modifier.write(0, EnumSet.of(ClientboundPlayerInfoUpdatePacket.Action.valueOf(action.name())));
|
||||
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.fillProfileProperties((GameProfile) gameProfile.getHandle(), true));
|
||||
}
|
||||
|
||||
public Float getSoundModifier(Object entity) {
|
||||
if (!(entity instanceof net.minecraft.world.entity.LivingEntity)) {
|
||||
return 0.0f;
|
||||
} else {
|
||||
try {
|
||||
Method method = net.minecraft.world.entity.LivingEntity.class.getDeclaredMethod("eC");
|
||||
method.setAccessible(true);
|
||||
|
||||
return (Float) method.invoke(entity);
|
||||
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
return 0f;
|
||||
}
|
||||
|
||||
public void injectCallback(String playername, ProfileLookupCallback callback) {
|
||||
Agent agent = Agent.MINECRAFT;
|
||||
getMinecraftServer().getProfileRepository().findProfilesByNames(new String[]{playername}, agent, 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.getSoundEffect(sound).getLocation().toString(); // TODO
|
||||
}
|
||||
|
||||
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) {
|
||||
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, 1);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public SoundEvent createSoundEffect(String minecraftKey) {
|
||||
throw new UnsupportedOperationException("createSoundEffect has been deprecated with nnew changes");
|
||||
}
|
||||
|
||||
@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_19_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);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
@ -125,7 +125,7 @@
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<groupId>com.github.dmulloy2</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
@ -226,6 +226,14 @@
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>LibsDisguises</groupId>
|
||||
<artifactId>v1_19_R2</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<classifier>remapped-spigot</classifier>
|
||||
<scope>compile</scope>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -1,12 +1,8 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
|
||||
import com.comphenix.protocol.wrappers.PlayerInfoData;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import lombok.AccessLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@ -45,10 +41,8 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.metadata.FixedMetadataValue;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashMap;
|
||||
@ -189,18 +183,15 @@ public abstract class Disguise {
|
||||
|
||||
ArrayList<PacketContainer> packets = DisguiseUtilities.getNamePackets(this, oldName);
|
||||
|
||||
try {
|
||||
for (Player player : DisguiseUtilities.getPerverts(this)) {
|
||||
if (isPlayerDisguise() && LibsDisguises.getInstance().getSkinHandler().isSleeping(player, (PlayerDisguise) this)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (PacketContainer packet : packets) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
for (Player player : DisguiseUtilities.getPerverts(this)) {
|
||||
if (!NmsVersion.v1_19_R2.isSupported() && isPlayerDisguise() &&
|
||||
LibsDisguises.getInstance().getSkinHandler().isSleeping(player, (PlayerDisguise) this)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (PacketContainer packet : packets) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -752,34 +743,23 @@ public abstract class Disguise {
|
||||
PlayerDisguise disguise = (PlayerDisguise) this;
|
||||
|
||||
if (disguise.isDisplayedInTab()) {
|
||||
PacketContainer deleteTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
deleteTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER);
|
||||
deleteTab.getPlayerInfoDataLists().write(0, Collections.singletonList(
|
||||
new PlayerInfoData(disguise.getGameProfile(), 0, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(disguise.getProfileName()))));
|
||||
PacketContainer deleteTab = ReflectionManager.createTablistPacket(disguise, PlayerInfoAction.REMOVE_PLAYER);
|
||||
|
||||
try {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!((TargetedDisguise) this).canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab);
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!((TargetedDisguise) this).canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (getInternalArmorstandIds().length > 0) {
|
||||
try {
|
||||
PacketContainer packet = DisguiseUtilities.getDestroyPacket(getInternalArmorstandIds());
|
||||
PacketContainer packet = DisguiseUtilities.getDestroyPacket(getInternalArmorstandIds());
|
||||
|
||||
for (Player player : getEntity().getWorld().getPlayers()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
for (Player player : getEntity().getWorld().getPlayers()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
}
|
||||
|
||||
@ -803,25 +783,14 @@ public abstract class Disguise {
|
||||
}
|
||||
|
||||
if (isHidePlayer() && getEntity() instanceof Player && ((Player) getEntity()).isOnline()) {
|
||||
PlayerInfoData playerInfo =
|
||||
new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, NativeGameMode.fromBukkit(((Player) getEntity()).getGameMode()),
|
||||
WrappedChatComponent.fromText(DisguiseUtilities.getPlayerListName((Player) getEntity())));
|
||||
PacketContainer addTab = ReflectionManager.updateTablistVisibility((Player) getEntity(), true);
|
||||
|
||||
PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
|
||||
addTab.getPlayerInfoAction().write(0, PlayerInfoAction.ADD_PLAYER);
|
||||
addTab.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfo));
|
||||
|
||||
try {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!((TargetedDisguise) this).canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab);
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!((TargetedDisguise) this).canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1016,18 +985,16 @@ public abstract class Disguise {
|
||||
PlayerDisguise disguise = (PlayerDisguise) this;
|
||||
|
||||
if (disguise.isDisplayedInTab()) {
|
||||
PacketContainer addTab = DisguiseUtilities.getTabPacket(disguise, PlayerInfoAction.ADD_PLAYER);
|
||||
PacketContainer[] addTabs = ReflectionManager.createTablistAddPackets(disguise);
|
||||
|
||||
try {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!((TargetedDisguise) this).canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab);
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!((TargetedDisguise) this).canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (PacketContainer packet : addTabs) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1055,21 +1022,14 @@ public abstract class Disguise {
|
||||
}, 2);
|
||||
|
||||
if (isHidePlayer() && getEntity() instanceof Player) {
|
||||
PacketContainer removeTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
removeTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER);
|
||||
removeTab.getPlayerInfoDataLists().write(0, Collections.singletonList(
|
||||
new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(""))));
|
||||
PacketContainer removeTab = ReflectionManager.updateTablistVisibility((Player) getEntity(), false);
|
||||
|
||||
try {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!((TargetedDisguise) this).canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, removeTab);
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!((TargetedDisguise) this).canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, removeTab);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -132,27 +132,19 @@ class DisguiseRunnable extends BukkitRunnable {
|
||||
|
||||
packet.getIntegers().write(0, disguise.getEntity().getEntityId());
|
||||
|
||||
try {
|
||||
for (Player player : DisguiseUtilities.getPerverts(disguise)) {
|
||||
if (disguise.getEntity() != player) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
continue;
|
||||
} else if (!disguise.isSelfDisguiseVisible() || !(disguise.getEntity() instanceof Player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
PacketContainer selfPacket = packet.shallowClone();
|
||||
|
||||
selfPacket.getModifier().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), selfPacket, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (Player player : DisguiseUtilities.getPerverts(disguise)) {
|
||||
if (disguise.getEntity() != player) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
continue;
|
||||
} else if (!disguise.isSelfDisguiseVisible() || !(disguise.getEntity() instanceof Player)) {
|
||||
continue;
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
PacketContainer selfPacket = packet.shallowClone();
|
||||
|
||||
selfPacket.getModifier().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), selfPacket, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -192,11 +184,7 @@ class DisguiseRunnable extends BukkitRunnable {
|
||||
|
||||
selfLookPacket.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), selfLookPacket, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket((Player) disguise.getEntity(), selfLookPacket, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,14 @@
|
||||
package me.libraryaddict.disguise.disguisetypes;
|
||||
|
||||
import lombok.SneakyThrows;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.reflection.annotations.NmsAddedIn;
|
||||
import me.libraryaddict.disguise.utilities.reflection.annotations.NmsRemovedIn;
|
||||
import me.libraryaddict.disguise.utilities.translations.TranslateType;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.EntityType;
|
||||
|
||||
@ -29,6 +33,8 @@ public enum DisguiseType {
|
||||
|
||||
BOAT(1),
|
||||
|
||||
@NmsAddedIn(NmsVersion.UNSUPPORTED) CAMEL,
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14) CAT,
|
||||
|
||||
CAVE_SPIDER,
|
||||
@ -256,9 +262,7 @@ public enum DisguiseType {
|
||||
@NmsAddedIn(NmsVersion.v1_16) ZOMBIFIED_PIGLIN;
|
||||
|
||||
public static DisguiseType getType(Entity entity) {
|
||||
DisguiseType disguiseType = getType(entity.getType());
|
||||
|
||||
return disguiseType;
|
||||
return getType(entity.getType());
|
||||
}
|
||||
|
||||
public static DisguiseType getType(EntityType entityType) {
|
||||
@ -278,9 +282,9 @@ public enum DisguiseType {
|
||||
private Object nmsType;
|
||||
private int objectId = -1, defaultData = 0;
|
||||
private int typeId;
|
||||
|
||||
private Class<? extends FlagWatcher> watcherClass;
|
||||
|
||||
@SneakyThrows
|
||||
DisguiseType(int... ints) {
|
||||
for (int i = 0; i < ints.length; i++) {
|
||||
int value = ints[i];
|
||||
@ -300,13 +304,20 @@ public enum DisguiseType {
|
||||
}
|
||||
|
||||
try {
|
||||
|
||||
// Why oh why can't isCustom() work :(
|
||||
if (name().startsWith("MODDED_")) {
|
||||
setEntityType(EntityType.UNKNOWN);
|
||||
} else {
|
||||
NmsAddedIn added = DisguiseType.class.getField(name()).getAnnotation(NmsAddedIn.class);
|
||||
|
||||
if (LibsDisguises.getInstance() != null && added != null && !added.value().isSupported()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setEntityType(EntityType.valueOf(name()));
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,6 +19,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.LivingWatcher;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.parser.RandomDefaultValue;
|
||||
import me.libraryaddict.disguise.utilities.reflection.WatcherValue;
|
||||
import me.libraryaddict.disguise.utilities.reflection.annotations.MethodGroupType;
|
||||
import me.libraryaddict.disguise.utilities.reflection.annotations.MethodIgnoredBy;
|
||||
import me.libraryaddict.disguise.utilities.reflection.annotations.MethodOnlyUsedBy;
|
||||
@ -36,7 +37,7 @@ import org.bukkit.inventory.EntityEquipment;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.sql.Ref;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
@ -62,7 +63,7 @@ public class FlagWatcher {
|
||||
private transient boolean hasDied;
|
||||
@Getter
|
||||
private boolean[] modifiedEntityAnimations = new boolean[8];
|
||||
private transient List<WrappedWatchableObject> watchableObjects;
|
||||
private transient List<WatcherValue> watchableObjects;
|
||||
private boolean sleeping;
|
||||
private transient boolean previouslySneaking;
|
||||
@Getter
|
||||
@ -105,12 +106,8 @@ public class FlagWatcher {
|
||||
PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.ENTITY_TELEPORT, getDisguise().getEntity())
|
||||
.createPacket(getDisguise().getEntity());
|
||||
|
||||
try {
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
}
|
||||
|
||||
@ -128,12 +125,8 @@ public class FlagWatcher {
|
||||
PacketContainer packet = ProtocolLibrary.getProtocolManager().createPacketConstructor(Server.ENTITY_TELEPORT, getDisguise().getEntity())
|
||||
.createPacket(getDisguise().getEntity());
|
||||
|
||||
try {
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
}
|
||||
|
||||
@ -180,12 +173,8 @@ public class FlagWatcher {
|
||||
|
||||
mods.write(1, (byte) (int) (loc.getYaw() * 256.0F / 360.0F));
|
||||
|
||||
try {
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, rotateHead);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, rotateHead);
|
||||
}
|
||||
}
|
||||
|
||||
@ -295,16 +284,17 @@ public class FlagWatcher {
|
||||
}
|
||||
}
|
||||
|
||||
public List<WrappedWatchableObject> convert(Player player, List<WrappedWatchableObject> list) {
|
||||
List<WrappedWatchableObject> newList = new ArrayList<>();
|
||||
public List<WatcherValue> convert(Player player, List<WatcherValue> list) {
|
||||
List<WatcherValue> newList = new ArrayList<>();
|
||||
HashSet<Integer> sentValues = new HashSet<>();
|
||||
boolean sendAllCustom = false;
|
||||
|
||||
for (WrappedWatchableObject watch : list) {
|
||||
for (WatcherValue watch : list) {
|
||||
int id = watch.getIndex();
|
||||
MetaIndex index = MetaIndex.getMetaIndex(this, id);
|
||||
sentValues.add(id);
|
||||
|
||||
MetaIndex index = MetaIndex.getMetaIndex(this, id);
|
||||
|
||||
if (index == null) {
|
||||
continue;
|
||||
}
|
||||
@ -325,8 +315,8 @@ public class FlagWatcher {
|
||||
|
||||
value = entityValues.get(id);
|
||||
|
||||
if (index == MetaIndex.LIVING_HEALTH && (float) watch.getRawValue() <= 0) {
|
||||
value = watch.getRawValue();
|
||||
if (index == MetaIndex.LIVING_HEALTH && (float) watch.getValue() <= 0) {
|
||||
value = watch.getValue();
|
||||
}
|
||||
} else if (backupEntityValues.containsKey(id)) {
|
||||
if (backupEntityValues.get(id) == null) {
|
||||
@ -339,46 +329,35 @@ public class FlagWatcher {
|
||||
|
||||
if (value != null) {
|
||||
if (isEntityAnimationsAdded() && (index == MetaIndex.ENTITY_META || (index == MetaIndex.LIVING_META && !usingBackup))) {
|
||||
value = addEntityAnimations(index, (byte) value, (byte) watch.getRawValue());
|
||||
value = addEntityAnimations(index, (byte) value, (byte) watch.getValue());
|
||||
|
||||
if (index == MetaIndex.ENTITY_META) {
|
||||
doSneakCheck((Byte) value);
|
||||
}
|
||||
}
|
||||
|
||||
boolean isDirty = watch.getDirtyState();
|
||||
|
||||
watch = ReflectionManager.createWatchable(index, value);
|
||||
watch = new WatcherValue(index, value);
|
||||
|
||||
if (watch == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isDirty) {
|
||||
watch.setDirtyState(false);
|
||||
}
|
||||
} else {
|
||||
boolean isDirty = watch.getDirtyState();
|
||||
|
||||
watch = ReflectionManager.createWatchable(index, watch.getRawValue());
|
||||
watch = new WatcherValue(index, watch.getValue());
|
||||
|
||||
if (watch == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!isDirty) {
|
||||
watch.setDirtyState(false);
|
||||
}
|
||||
|
||||
if (id == MetaIndex.ENTITY_META.getIndex()) {
|
||||
doSneakCheck((Byte) watch.getRawValue());
|
||||
doSneakCheck((Byte) watch.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
newList.add(watch);
|
||||
|
||||
if (!sendAllCustom && getDisguise().isPlayerDisguise() && index == MetaIndex.LIVING_HEALTH) {
|
||||
float health = ((Number) watch.getRawValue()).floatValue();
|
||||
float health = ((Number) watch.getValue()).floatValue();
|
||||
|
||||
String name = DisguiseConfig.isScoreboardNames() && ((PlayerDisguise) getDisguise()).hasScoreboardName() ?
|
||||
((PlayerDisguise) getDisguise()).getScoreboardName().getPlayer() : ((PlayerDisguise) getDisguise()).getName();
|
||||
@ -400,7 +379,7 @@ public class FlagWatcher {
|
||||
continue;
|
||||
}
|
||||
|
||||
WrappedWatchableObject watch = ReflectionManager.createWatchable(MetaIndex.getMetaIndex(this, id), value);
|
||||
WatcherValue watch = new WatcherValue(MetaIndex.getMetaIndex(this, id), value);
|
||||
|
||||
if (watch == null) {
|
||||
continue;
|
||||
@ -429,10 +408,10 @@ public class FlagWatcher {
|
||||
|
||||
// Here we check for if there is a health packet that says they died.
|
||||
if (getDisguise().isSelfDisguiseVisible() && getDisguise().getEntity() != null && getDisguise().getEntity() instanceof Player) {
|
||||
for (WrappedWatchableObject watch : newList) {
|
||||
for (WatcherValue watch : newList) {
|
||||
// Its a health packet
|
||||
if (watch.getIndex() == MetaIndex.LIVING_HEALTH.getIndex()) {
|
||||
Object value = watch.getRawValue();
|
||||
Object value = watch.getValue();
|
||||
|
||||
if (value instanceof Float) {
|
||||
float newHealth = (Float) value;
|
||||
@ -531,18 +510,15 @@ public class FlagWatcher {
|
||||
|
||||
ArrayList<PacketContainer> packets = DisguiseUtilities.getNamePackets(getDisguise(), new String[0]);
|
||||
|
||||
try {
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
if (getDisguise().isPlayerDisguise() && LibsDisguises.getInstance().getSkinHandler().isSleeping(player, (PlayerDisguise) getDisguise())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (PacketContainer packet : packets) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
if (!NmsVersion.v1_19_R2.isSupported() && getDisguise().isPlayerDisguise() &&
|
||||
LibsDisguises.getInstance().getSkinHandler().isSleeping(player, (PlayerDisguise) getDisguise())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (PacketContainer packet : packets) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@ -708,7 +684,7 @@ public class FlagWatcher {
|
||||
return flagType.getDefault();
|
||||
}
|
||||
|
||||
public List<WrappedWatchableObject> getWatchableObjects() {
|
||||
public List<WatcherValue> getWatchableObjects() {
|
||||
if (watchableObjects == null) {
|
||||
rebuildWatchableObjects();
|
||||
}
|
||||
@ -883,12 +859,12 @@ public class FlagWatcher {
|
||||
watchableObjects = new ArrayList<>();
|
||||
|
||||
for (int i = 0; i <= 31; i++) {
|
||||
WrappedWatchableObject watchable;
|
||||
WatcherValue watchable;
|
||||
|
||||
if (entityValues.containsKey(i) && entityValues.get(i) != null) {
|
||||
watchable = ReflectionManager.createWatchable(MetaIndex.getMetaIndex(this, i), entityValues.get(i));
|
||||
watchable = new WatcherValue(MetaIndex.getMetaIndex(this, i), entityValues.get(i));
|
||||
} else if (backupEntityValues.containsKey(i) && backupEntityValues.get(i) != null) {
|
||||
watchable = ReflectionManager.createWatchable(MetaIndex.getMetaIndex(this, i), backupEntityValues.get(i));
|
||||
watchable = new WatcherValue(MetaIndex.getMetaIndex(this, i), backupEntityValues.get(i));
|
||||
} else {
|
||||
continue;
|
||||
}
|
||||
@ -906,7 +882,7 @@ public class FlagWatcher {
|
||||
return;
|
||||
}
|
||||
|
||||
List<WrappedWatchableObject> list = new ArrayList<>();
|
||||
List<WatcherValue> list = new ArrayList<>();
|
||||
|
||||
for (MetaIndex data : dataValues) {
|
||||
if (data == null) {
|
||||
@ -923,7 +899,7 @@ public class FlagWatcher {
|
||||
value = addEntityAnimations(data, (byte) value, WrappedDataWatcher.getEntityWatcher(disguise.getEntity()).getByte(0));
|
||||
}
|
||||
|
||||
WrappedWatchableObject watch = ReflectionManager.createWatchable(data, value);
|
||||
WatcherValue watch = new WatcherValue(data, value);
|
||||
|
||||
if (watch == null) {
|
||||
continue;
|
||||
@ -933,25 +909,16 @@ public class FlagWatcher {
|
||||
}
|
||||
|
||||
if (!list.isEmpty()) {
|
||||
PacketContainer packet = new PacketContainer(Server.ENTITY_METADATA);
|
||||
|
||||
StructureModifier<Object> mods = packet.getModifier();
|
||||
mods.write(0, getDisguise().getEntity().getEntityId());
|
||||
|
||||
packet.getWatchableCollectionModifier().write(0, list);
|
||||
PacketContainer packet = ReflectionManager.getMetadataPacket(getDisguise().getEntity().getEntityId(), list);
|
||||
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
try {
|
||||
if (player == getDisguise().getEntity()) {
|
||||
PacketContainer temp = packet.shallowClone();
|
||||
temp.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
if (player == getDisguise().getEntity()) {
|
||||
PacketContainer temp = packet.shallowClone();
|
||||
temp.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, temp);
|
||||
} else {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, temp);
|
||||
} else {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1031,11 +998,7 @@ public class FlagWatcher {
|
||||
}
|
||||
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -23,6 +23,7 @@ import me.libraryaddict.disguise.disguisetypes.watchers.BatWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.BeeWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.BlazeWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.BoatWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.CamelWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.CatWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.ChestedHorseWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.CreeperWatcher;
|
||||
@ -261,6 +262,12 @@ public class MetaIndex<Y> {
|
||||
@NmsAddedIn(NmsVersion.v1_13)
|
||||
public static MetaIndex<Integer> BOAT_SHAKE = new MetaIndex<>(BoatWatcher.class, 6, 0);
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_19_R2)
|
||||
public static MetaIndex<Boolean> CAMEL_DASHING = new MetaIndex<>(CamelWatcher.class, 0, false);
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_19_R2)
|
||||
public static MetaIndex<Long> CAMEL_LAST_POSE_CHANGED = new MetaIndex<>(CamelWatcher.class, 1, 0L);
|
||||
|
||||
@NmsAddedIn(NmsVersion.v1_14)
|
||||
@NmsRemovedIn(NmsVersion.v1_19)
|
||||
public static MetaIndex<Integer> CAT_TYPE = new MetaIndex<>(CatWatcher.class, 0, 0);
|
||||
|
@ -4,6 +4,7 @@ import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.PlayerInfoAction;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
import com.google.gson.Gson;
|
||||
import lombok.Getter;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
@ -360,18 +361,14 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
}
|
||||
|
||||
if (isDisplayedInTab()) {
|
||||
PacketContainer addTab = DisguiseUtilities.getTabPacket(this, PlayerInfoAction.UPDATE_DISPLAY_NAME);
|
||||
PacketContainer addTab = ReflectionManager.createTablistPacket(this, PlayerInfoAction.UPDATE_DISPLAY_NAME);
|
||||
|
||||
try {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab);
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@ -525,22 +522,19 @@ public class PlayerDisguise extends TargetedDisguise {
|
||||
}
|
||||
|
||||
if (isDisplayedInTab()) {
|
||||
PacketContainer addTab = DisguiseUtilities.getTabPacket(this, PlayerInfoAction.ADD_PLAYER);
|
||||
PacketContainer[] addTabs = ReflectionManager.createTablistAddPackets(this);
|
||||
PacketContainer deleteTab = ReflectionManager.createTablistPacket(this, PlayerInfoAction.REMOVE_PLAYER);
|
||||
|
||||
PacketContainer deleteTab = addTab.shallowClone();
|
||||
deleteTab.getPlayerInfoAction().write(0, PlayerInfoAction.REMOVE_PLAYER);
|
||||
|
||||
try {
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, addTab);
|
||||
for (Player player : Bukkit.getOnlinePlayers()) {
|
||||
if (!canSee(player)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab);
|
||||
|
||||
for (PacketContainer packet : addTabs) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,7 +13,6 @@ import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@ -56,21 +55,12 @@ public abstract class TargetedDisguise extends Disguise {
|
||||
DisguiseUtilities.refreshTracker(this, playername);
|
||||
|
||||
if (isHidePlayer() && getEntity() instanceof Player) {
|
||||
try {
|
||||
Player player = Bukkit.getPlayerExact(playername);
|
||||
Player player = Bukkit.getPlayerExact(playername);
|
||||
|
||||
if (player != null) {
|
||||
PacketContainer deleteTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
if (player != null) {
|
||||
PacketContainer deleteTab = ReflectionManager.updateTablistVisibility((Player) getEntity(), !canSee(player));
|
||||
|
||||
deleteTab.getPlayerInfoAction().write(0, canSee(player) ? PlayerInfoAction.REMOVE_PLAYER : PlayerInfoAction.ADD_PLAYER);
|
||||
deleteTab.getPlayerInfoDataLists().write(0, Arrays.asList(
|
||||
new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, NativeGameMode.SURVIVAL,
|
||||
WrappedChatComponent.fromText(DisguiseUtilities.getPlayerListName((Player) getEntity())))));
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -126,21 +116,12 @@ public abstract class TargetedDisguise extends Disguise {
|
||||
DisguiseUtilities.refreshTracker(this, playername);
|
||||
|
||||
if (isHidePlayer() && getEntity() instanceof Player) {
|
||||
try {
|
||||
Player player = Bukkit.getPlayerExact(playername);
|
||||
Player player = Bukkit.getPlayerExact(playername);
|
||||
|
||||
if (player != null) {
|
||||
PacketContainer deleteTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
if (player != null) {
|
||||
PacketContainer deleteTab = ReflectionManager.updateTablistVisibility((Player) getEntity(), canSee(player));
|
||||
|
||||
deleteTab.getPlayerInfoAction().write(0, canSee(player) ? PlayerInfoAction.ADD_PLAYER : PlayerInfoAction.REMOVE_PLAYER);
|
||||
deleteTab.getPlayerInfoDataLists().write(0, Arrays.asList(
|
||||
new PlayerInfoData(ReflectionManager.getGameProfile((Player) getEntity()), 0, NativeGameMode.SURVIVAL,
|
||||
WrappedChatComponent.fromText(DisguiseUtilities.getPlayerListName((Player) getEntity())))));
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, deleteTab);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,19 @@
|
||||
package me.libraryaddict.disguise.disguisetypes.watchers;
|
||||
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
|
||||
public class CamelWatcher extends AbstractHorseWatcher {
|
||||
public CamelWatcher(Disguise disguise) {
|
||||
super(disguise);
|
||||
}
|
||||
|
||||
public void setDashing(boolean dashing) {
|
||||
setData(MetaIndex.CAMEL_DASHING, dashing);
|
||||
sendData(MetaIndex.CAMEL_DASHING);
|
||||
}
|
||||
|
||||
public boolean isDashing() {
|
||||
return getData(MetaIndex.CAMEL_DASHING);
|
||||
}
|
||||
}
|
@ -72,19 +72,15 @@ public class FallingBlockWatcher extends FlagWatcher {
|
||||
ints.write(2, (int) conRel(loc.getZ(), loc.getBlockZ() + 0.5));
|
||||
}
|
||||
|
||||
try {
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
if (player == getDisguise().getEntity()) {
|
||||
PacketContainer temp = relMove.shallowClone();
|
||||
temp.getModifier().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
if (player == getDisguise().getEntity()) {
|
||||
PacketContainer temp = relMove.shallowClone();
|
||||
temp.getModifier().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, temp, isGridLocked());
|
||||
} else {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, relMove, isGridLocked());
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, temp, isGridLocked());
|
||||
} else {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, relMove, isGridLocked());
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -184,16 +184,12 @@ public class LivingWatcher extends FlagWatcher {
|
||||
packet.getAttributeCollectionModifier().write(0, attributes);
|
||||
|
||||
for (Player player : DisguiseUtilities.getPerverts(getDisguise())) {
|
||||
try {
|
||||
if (player == getDisguise().getEntity()) {
|
||||
PacketContainer p = packet.shallowClone();
|
||||
p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, p, false);
|
||||
} else {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
if (player == getDisguise().getEntity()) {
|
||||
PacketContainer p = packet.shallowClone();
|
||||
p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, p, false);
|
||||
} else {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,8 +5,6 @@ import com.comphenix.protocol.PacketType.Play.Server;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.ProtocolManager;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.PlayerInfoData;
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
@ -36,6 +34,7 @@ import me.libraryaddict.disguise.disguisetypes.TargetedDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.TargetedDisguise.TargetType;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.ArmorStandWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.PlayerWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.ZombieWatcher;
|
||||
import me.libraryaddict.disguise.utilities.json.SerializerBlockData;
|
||||
import me.libraryaddict.disguise.utilities.json.SerializerChatComponent;
|
||||
@ -54,6 +53,7 @@ import me.libraryaddict.disguise.utilities.reflection.FakeBoundingBox;
|
||||
import me.libraryaddict.disguise.utilities.reflection.LibsProfileLookup;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.reflection.WatcherValue;
|
||||
import me.libraryaddict.disguise.utilities.translations.LibsMsg;
|
||||
import me.libraryaddict.disguise.utilities.watchers.CompileMethods;
|
||||
import net.kyori.adventure.text.Component;
|
||||
@ -104,7 +104,6 @@ import java.io.InputStreamReader;
|
||||
import java.io.PrintWriter;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.ParameterizedType;
|
||||
import java.lang.reflect.Type;
|
||||
@ -113,6 +112,7 @@ import java.net.URL;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
import java.sql.Ref;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Base64;
|
||||
@ -257,7 +257,7 @@ public class DisguiseUtilities {
|
||||
private final static ConcurrentHashMap<String, DScoreTeam> teams = new ConcurrentHashMap<>();
|
||||
private final static boolean java16;
|
||||
private static boolean criedOverJava16;
|
||||
private static HashSet<UUID> warnedSkin = new HashSet<>();
|
||||
private static final HashSet<UUID> warnedSkin = new HashSet<>();
|
||||
private static Boolean adventureTextSupport;
|
||||
|
||||
static {
|
||||
@ -366,7 +366,7 @@ public class DisguiseUtilities {
|
||||
return string;
|
||||
}
|
||||
|
||||
return string.replaceAll("§x§([0-9a-fA-F])§([0-9a-fA-F])§([0-9a-fA-F])§([0-9a-fA-F])§([0-9a-fA-F])§([0-9a-fA-F])", "<#$1$2$3$4$5$6>");
|
||||
return string.replaceAll("§x§([\\da-fA-F])§([\\da-fA-F])§([\\da-fA-F])§([\\da-fA-F])§([\\da-fA-F])§([\\da-fA-F])", "<#$1$2$3$4$5$6>");
|
||||
}
|
||||
|
||||
public static String getDisplayName(String playerName) {
|
||||
@ -424,11 +424,7 @@ public class DisguiseUtilities {
|
||||
}
|
||||
|
||||
public static void removeInvisibleSlime(Player player) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, getDestroyPacket(DisguiseAPI.getEntityAttachmentId()), false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, getDestroyPacket(DisguiseAPI.getEntityAttachmentId()), false);
|
||||
}
|
||||
|
||||
public static void sendInvisibleSlime(Player player, int horseId) {
|
||||
@ -439,31 +435,21 @@ public class DisguiseUtilities {
|
||||
packet.getModifier().write(1, UUID.randomUUID());
|
||||
packet.getModifier().write(2, DisguiseType.SLIME.getTypeId());
|
||||
|
||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||
|
||||
WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager.createDataWatcherObject(MetaIndex.SLIME_SIZE, 0);
|
||||
|
||||
watcher.setObject(obj, 0);
|
||||
|
||||
if (NmsVersion.v1_15.isSupported()) {
|
||||
PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
|
||||
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, DisguiseAPI.getEntityAttachmentId(), watcher, true)
|
||||
.createPacket(DisguiseAPI.getEntityAttachmentId(), watcher, true);
|
||||
PacketContainer metaPacket =
|
||||
ReflectionManager.getMetadataPacket(DisguiseAPI.getEntityAttachmentId(), Collections.singletonList(new WatcherValue(MetaIndex.SLIME_SIZE, 0)));
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, metaPacket, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, metaPacket, false);
|
||||
} else {
|
||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||
|
||||
WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager.createDataWatcherObject(MetaIndex.SLIME_SIZE, 0);
|
||||
watcher.setObject(obj, 0);
|
||||
|
||||
packet.getDataWatcherModifier().write(0, watcher);
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
|
||||
PacketContainer attachHorse = new PacketContainer(Server.MOUNT);
|
||||
@ -474,12 +460,8 @@ public class DisguiseUtilities {
|
||||
attachPlayer.getModifier().write(0, DisguiseAPI.getEntityAttachmentId());
|
||||
attachPlayer.getModifier().write(1, new int[]{player.getEntityId()});
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, attachHorse, false);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, attachPlayer, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, attachHorse, false);
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, attachPlayer, false);
|
||||
}
|
||||
|
||||
public static void loadViewPreferences() {
|
||||
@ -565,7 +547,12 @@ public class DisguiseUtilities {
|
||||
return new String[]{"4.8.0"};
|
||||
}
|
||||
|
||||
return new String[]{"5.0.1", "600"};
|
||||
// If you're on 1.19.1
|
||||
if (!NmsVersion.v1_19_1.isSupported()) {
|
||||
return new String[]{"5.0.1", "600"};
|
||||
}
|
||||
|
||||
return new String[]{"5.0.1", "607"};
|
||||
}
|
||||
|
||||
public static boolean isProtocolLibOutdated() {
|
||||
@ -739,27 +726,27 @@ public class DisguiseUtilities {
|
||||
disguise = disguise.clone();
|
||||
}
|
||||
|
||||
String reference = null;
|
||||
StringBuilder reference = null;
|
||||
int referenceLength = Math.max(2, (int) Math.ceil((0.1D + DisguiseConfig.getMaxClonedDisguises()) / 26D));
|
||||
int attempts = 0;
|
||||
|
||||
while (reference == null && attempts++ < 1000) {
|
||||
reference = "@";
|
||||
reference = new StringBuilder("@");
|
||||
|
||||
for (int i = 0; i < referenceLength; i++) {
|
||||
reference += alphabet[DisguiseUtilities.random.nextInt(alphabet.length)];
|
||||
reference.append(alphabet[DisguiseUtilities.random.nextInt(alphabet.length)]);
|
||||
}
|
||||
|
||||
if (DisguiseUtilities.getClonedDisguise(reference) != null) {
|
||||
if (DisguiseUtilities.getClonedDisguise(reference.toString()) != null) {
|
||||
reference = null;
|
||||
}
|
||||
}
|
||||
|
||||
if (reference != null && DisguiseUtilities.addClonedDisguise(reference, disguise)) {
|
||||
if (reference != null && DisguiseUtilities.addClonedDisguise(reference.toString(), disguise)) {
|
||||
String entityName = DisguiseType.getType(toClone).toReadable();
|
||||
|
||||
LibsMsg.MADE_REF.send(player, entityName, reference);
|
||||
LibsMsg.MADE_REF_EXAMPLE.send(player, reference);
|
||||
LibsMsg.MADE_REF.send(player, entityName, reference.toString());
|
||||
LibsMsg.MADE_REF_EXAMPLE.send(player, reference.toString());
|
||||
} else {
|
||||
LibsMsg.REF_TOO_MANY.send(player);
|
||||
}
|
||||
@ -938,7 +925,7 @@ public class DisguiseUtilities {
|
||||
}
|
||||
|
||||
if ("a%%__USER__%%a".equals("a12345a") ||
|
||||
(LibsPremium.getUserID().matches("[0-9]+") && !("" + Integer.parseInt(LibsPremium.getUserID())).equals(LibsPremium.getUserID()))) {
|
||||
(LibsPremium.getUserID().matches("\\d+") && !("" + Integer.parseInt(LibsPremium.getUserID())).equals(LibsPremium.getUserID()))) {
|
||||
if (Bukkit.getOnlinePlayers().stream().noneMatch(p -> p.isOp() || p.hasPermission("*"))) {
|
||||
World world = Bukkit.getWorlds().get(0);
|
||||
|
||||
@ -1225,7 +1212,7 @@ public class DisguiseUtilities {
|
||||
if (getDisguises().containsKey(entityId)) {
|
||||
Set<TargetedDisguise> disguises = getDisguises().get(entityId);
|
||||
|
||||
return disguises.toArray(new TargetedDisguise[disguises.size()]);
|
||||
return disguises.toArray(new TargetedDisguise[0]);
|
||||
}
|
||||
|
||||
return new TargetedDisguise[0];
|
||||
@ -1545,7 +1532,7 @@ public class DisguiseUtilities {
|
||||
Method m = CompileMethods.class.getMethod("main", String[].class);
|
||||
|
||||
if ((!m.isAnnotationPresent(CompileMethods.CompileMethodsIntfer.class) ||
|
||||
m.getAnnotation(CompileMethods.CompileMethodsIntfer.class).user().matches("[0-9]+")) && !DisguiseConfig.doOutput(true, false).isEmpty()) {
|
||||
m.getAnnotation(CompileMethods.CompileMethodsIntfer.class).user().matches("\\d+")) && !DisguiseConfig.doOutput(true, false).isEmpty()) {
|
||||
DisguiseConfig.setViewDisguises(false);
|
||||
}
|
||||
} catch (NoSuchMethodException e) {
|
||||
@ -1640,7 +1627,7 @@ public class DisguiseUtilities {
|
||||
return new String[0];
|
||||
}
|
||||
|
||||
return ((String) map.get("body")).split("(\\r|\\n)+");
|
||||
return ((String) map.get("body")).split("([\\r\\n])+");
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
|
||||
@ -1894,11 +1881,14 @@ public class DisguiseUtilities {
|
||||
|
||||
removeSelfTracker(player);
|
||||
|
||||
// Resend entity metadata else he will be invisible to himself until its resent
|
||||
// Resend entity metadata else he will be invisible to themselves until its resent
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, ProtocolLibrary.getProtocolManager()
|
||||
.createPacketConstructor(Server.ENTITY_METADATA, player.getEntityId(), WrappedDataWatcher.getEntityWatcher(player), true)
|
||||
.createPacket(player.getEntityId(), WrappedDataWatcher.getEntityWatcher(player), true));
|
||||
List<WatcherValue> list = WrappedDataWatcher.getEntityWatcher(player).getWatchableObjects().stream()
|
||||
.map(v -> new WatcherValue(MetaIndex.getMetaIndex(PlayerWatcher.class, v.getIndex()), v.getRawValue())).collect(Collectors.toList());
|
||||
|
||||
PacketContainer metaPacket = ReflectionManager.getMetadataPacket(player.getEntityId(), list);
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, metaPacket);
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -2154,7 +2144,7 @@ public class DisguiseUtilities {
|
||||
|
||||
String testName = namePrefix + tName + nameSuffix;
|
||||
|
||||
if (!isValidPlayerName(board, testName)) {
|
||||
if (isInvalidPlayerName(board, testName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -2191,7 +2181,7 @@ public class DisguiseUtilities {
|
||||
|
||||
String[] extended = new String[]{prefix, nName, suffix};
|
||||
|
||||
if ((playerName == null || !playerName.equals(extended[1])) && !isValidPlayerName(board, extended[1])) {
|
||||
if ((playerName == null || !playerName.equals(extended[1])) && isInvalidPlayerName(board, extended[1])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@ -2245,35 +2235,10 @@ public class DisguiseUtilities {
|
||||
return builder.reverse().toString();
|
||||
}
|
||||
|
||||
private static boolean isValidPlayerName(Scoreboard board, String name) {
|
||||
return board.getEntryTeam(name) == null && Bukkit.getPlayerExact(name) == null;
|
||||
private static boolean isInvalidPlayerName(Scoreboard board, String name) {
|
||||
return board.getEntryTeam(name) != null || Bukkit.getPlayerExact(name) != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits a string while respecting quotes.
|
||||
* <p>
|
||||
* Re
|
||||
*/
|
||||
/*public static String[] split(String string) {
|
||||
Matcher matcher = Pattern.compile("\"(?:\"(?=\\S)|\\\\\"|[^\"])*(?:[^\\\\]\"(?=\\s|$))|\\S+").matcher(string);
|
||||
|
||||
List<String> list = new ArrayList<>();
|
||||
|
||||
while (matcher.find()) {
|
||||
String match = matcher.group();
|
||||
|
||||
// If the match was quoted, then remove quotes and escapes
|
||||
if (match.matches("\"(?:\"(?=\\S)|\\\\\"|[^\"])*(?:[^\\\\]\")")) {
|
||||
// Replace the match by removing first and last quote
|
||||
// Then remove escaped slashes from the trailing with regex
|
||||
match = match.substring(1, match.length() - 1).replaceAll("\\\\\\\\(?=(\\\\\\\\)*$)", "\\");
|
||||
}
|
||||
|
||||
list.add(matcher.group());
|
||||
}
|
||||
|
||||
return list.toArray(new String[0]);
|
||||
}*/
|
||||
public static String quote(String string) {
|
||||
string = string.replace("\n", "\\n");
|
||||
|
||||
@ -2330,7 +2295,7 @@ public class DisguiseUtilities {
|
||||
}
|
||||
}
|
||||
|
||||
lines.add(builder.toString() + string.substring(last));
|
||||
lines.add(builder + string.substring(last));
|
||||
|
||||
return lines.toArray(new String[0]);
|
||||
}
|
||||
@ -2469,10 +2434,10 @@ public class DisguiseUtilities {
|
||||
// Send the player a packet with himself being spawned
|
||||
manager.sendServerPacket(player, manager.createPacketConstructor(Server.NAMED_ENTITY_SPAWN, player).createPacket(player));
|
||||
|
||||
WrappedDataWatcher dataWatcher = WrappedDataWatcher.getEntityWatcher(player);
|
||||
List<WatcherValue> watcherList = WrappedDataWatcher.getEntityWatcher(player).getWatchableObjects().stream()
|
||||
.map(v -> new WatcherValue(MetaIndex.getMetaIndex(PlayerWatcher.class, v.getIndex()), v.getRawValue())).collect(Collectors.toList());
|
||||
|
||||
sendSelfPacket(player, manager.createPacketConstructor(Server.ENTITY_METADATA, player.getEntityId(), dataWatcher, true)
|
||||
.createPacket(player.getEntityId(), dataWatcher, true));
|
||||
sendSelfPacket(player, ReflectionManager.getMetadataPacket(player.getEntityId(), watcherList));
|
||||
|
||||
boolean isMoving = false;
|
||||
|
||||
@ -2542,11 +2507,11 @@ public class DisguiseUtilities {
|
||||
}
|
||||
|
||||
public static String quoteHex(String string) {
|
||||
return string.replaceAll("(<)(#[0-9a-fA-F]{6}>)", "$1\\$2");
|
||||
return string.replaceAll("(<)(#[\\da-fA-F]{6}>)", "$1\\$2");
|
||||
}
|
||||
|
||||
public static String unquoteHex(String string) {
|
||||
return string.replaceAll("(<)\\\\(#[0-9a-fA-F]{6}>)", "$1$2");
|
||||
return string.replaceAll("(<)\\\\(#[\\da-fA-F]{6}>)", "$1$2");
|
||||
}
|
||||
|
||||
public static void sendMessage(CommandSender sender, String message) {
|
||||
@ -2574,7 +2539,7 @@ public class DisguiseUtilities {
|
||||
public static int[] getNumericVersion(String version) {
|
||||
int[] v = new int[0];
|
||||
for (String split : version.split("[.\\-]")) {
|
||||
if (!split.matches("[0-9]+")) {
|
||||
if (!split.matches("\\d+")) {
|
||||
return v;
|
||||
}
|
||||
|
||||
@ -2630,7 +2595,7 @@ public class DisguiseUtilities {
|
||||
|
||||
public static String translateAlternateColorCodes(String string) {
|
||||
if (NmsVersion.v1_16.isSupported()) {
|
||||
string = string.replaceAll("&(?=#[0-9a-fA-F]{6})", ChatColor.COLOR_CHAR + "");
|
||||
string = string.replaceAll("&(?=#[\\da-fA-F]{6})", ChatColor.COLOR_CHAR + "");
|
||||
}
|
||||
|
||||
return ChatColor.translateAlternateColorCodes('&', string);
|
||||
@ -2690,52 +2655,38 @@ public class DisguiseUtilities {
|
||||
|
||||
LibsPackets transformed = PacketsManager.getPacketsHandler().transformPacket(packet, disguise, player, player);
|
||||
|
||||
try {
|
||||
if (transformed.isUnhandled()) {
|
||||
transformed.addPacket(packet);
|
||||
}
|
||||
|
||||
LibsPackets newPackets = new LibsPackets(disguise);
|
||||
|
||||
for (PacketContainer p : transformed.getPackets()) {
|
||||
p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
|
||||
newPackets.addPacket(p);
|
||||
}
|
||||
|
||||
for (Map.Entry<Integer, ArrayList<PacketContainer>> entry : transformed.getDelayedPacketsMap().entrySet()) {
|
||||
for (PacketContainer newPacket : entry.getValue()) {
|
||||
if (newPacket.getType() != Server.PLAYER_INFO && newPacket.getType() != Server.ENTITY_DESTROY &&
|
||||
newPacket.getIntegers().read(0) == player.getEntityId()) {
|
||||
newPacket.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
}
|
||||
|
||||
newPackets.addDelayedPacket(newPacket, entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
if (disguise.isPlayerDisguise()) {
|
||||
LibsDisguises.getInstance().getSkinHandler().handlePackets(player, (PlayerDisguise) disguise, newPackets);
|
||||
}
|
||||
|
||||
for (PacketContainer p : newPackets.getPackets()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, p, false);
|
||||
}
|
||||
|
||||
newPackets.sendDelayed(player);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
if (transformed.isUnhandled()) {
|
||||
transformed.addPacket(packet);
|
||||
}
|
||||
}
|
||||
|
||||
public static PacketContainer getTabPacket(PlayerDisguise disguise, EnumWrappers.PlayerInfoAction action) {
|
||||
PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
LibsPackets newPackets = new LibsPackets(disguise);
|
||||
|
||||
addTab.getPlayerInfoAction().write(0, action);
|
||||
addTab.getPlayerInfoDataLists().write(0, Collections.singletonList(
|
||||
new PlayerInfoData(disguise.getGameProfile(), 0, EnumWrappers.NativeGameMode.SURVIVAL, WrappedChatComponent.fromText(disguise.getName()))));
|
||||
for (PacketContainer p : transformed.getPackets()) {
|
||||
p.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
|
||||
return addTab;
|
||||
newPackets.addPacket(p);
|
||||
}
|
||||
|
||||
for (Map.Entry<Integer, ArrayList<PacketContainer>> entry : transformed.getDelayedPacketsMap().entrySet()) {
|
||||
for (PacketContainer newPacket : entry.getValue()) {
|
||||
if (newPacket.getType() != Server.PLAYER_INFO && newPacket.getType() != Server.ENTITY_DESTROY &&
|
||||
newPacket.getIntegers().read(0) == player.getEntityId()) {
|
||||
newPacket.getIntegers().write(0, DisguiseAPI.getSelfDisguiseId());
|
||||
}
|
||||
|
||||
newPackets.addDelayedPacket(newPacket, entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
if (disguise.isPlayerDisguise()) {
|
||||
LibsDisguises.getInstance().getSkinHandler().handlePackets(player, (PlayerDisguise) disguise, newPackets);
|
||||
}
|
||||
|
||||
for (PacketContainer p : newPackets.getPackets()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, p, false);
|
||||
}
|
||||
|
||||
newPackets.sendDelayed(player);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2890,38 +2841,26 @@ public class DisguiseUtilities {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new datawatcher but with the 'correct' values
|
||||
*/
|
||||
public static WrappedDataWatcher createSanitizedDataWatcher(Player player, WrappedDataWatcher entityWatcher, FlagWatcher disguiseWatcher) {
|
||||
WrappedDataWatcher newWatcher = new WrappedDataWatcher();
|
||||
public static WrappedDataWatcher createDatawatcher(List<WatcherValue> watcherValues) {
|
||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||
|
||||
try {
|
||||
List<WrappedWatchableObject> list = DisguiseConfig.isMetaPacketsEnabled() ? disguiseWatcher.convert(player, entityWatcher.getWatchableObjects()) :
|
||||
disguiseWatcher.getWatchableObjects();
|
||||
|
||||
for (WrappedWatchableObject watchableObject : list) {
|
||||
if (watchableObject == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Object object = watchableObject.getRawValue();
|
||||
|
||||
if (object == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
MetaIndex metaIndex = MetaIndex.getMetaIndex(disguiseWatcher, watchableObject.getIndex());
|
||||
|
||||
WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager.createDataWatcherObject(metaIndex, object);
|
||||
|
||||
newWatcher.setObject(obj, object);
|
||||
for (WatcherValue value : watcherValues) {
|
||||
if (value == null) {
|
||||
continue;
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
|
||||
watcher.setObject(value.getIndex(), value.getWatchableObject());
|
||||
}
|
||||
|
||||
return newWatcher;
|
||||
return watcher;
|
||||
}
|
||||
|
||||
public static List<WatcherValue> createSanitizedWatcherValues(Player player, WrappedDataWatcher entityWatcher, FlagWatcher flagWatcher) {
|
||||
if (!DisguiseConfig.isMetaPacketsEnabled()) {
|
||||
return flagWatcher.getWatchableObjects();
|
||||
}
|
||||
|
||||
return flagWatcher.convert(player, WatcherValue.getValues(entityWatcher));
|
||||
}
|
||||
|
||||
public static byte getPitch(DisguiseType disguiseType, EntityType entityType, byte value) {
|
||||
@ -3021,8 +2960,6 @@ public class DisguiseUtilities {
|
||||
continue;
|
||||
}
|
||||
|
||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||
|
||||
Object name;
|
||||
|
||||
if (NmsVersion.v1_13.isSupported()) {
|
||||
@ -3031,15 +2968,10 @@ public class DisguiseUtilities {
|
||||
name = ChatColor.translateAlternateColorCodes('&', newNames[i]);
|
||||
}
|
||||
|
||||
WrappedDataWatcher.WrappedDataWatcherObject obj =
|
||||
ReflectionManager.createDataWatcherObject(NmsVersion.v1_13.isSupported() ? MetaIndex.ENTITY_CUSTOM_NAME : MetaIndex.ENTITY_CUSTOM_NAME_OLD,
|
||||
name);
|
||||
MetaIndex index = NmsVersion.v1_13.isSupported() ? MetaIndex.ENTITY_CUSTOM_NAME : MetaIndex.ENTITY_CUSTOM_NAME_OLD;
|
||||
|
||||
watcher.setObject(obj, ReflectionManager.convertInvalidMeta(name));
|
||||
|
||||
PacketContainer metaPacket =
|
||||
ProtocolLibrary.getProtocolManager().createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, 0, watcher, true)
|
||||
.createPacket(standIds[i], watcher, true);
|
||||
PacketContainer metaPacket = ReflectionManager.getMetadataPacket(standIds[i],
|
||||
Collections.singletonList(new WatcherValue(index, ReflectionManager.convertInvalidMeta(name))));
|
||||
|
||||
packets.add(metaPacket);
|
||||
} else if (newNames[i].isEmpty()) {
|
||||
@ -3060,7 +2992,7 @@ public class DisguiseUtilities {
|
||||
packet.getDoubles().write(2, loc.getZ());
|
||||
packets.add(packet);
|
||||
|
||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||
List<WatcherValue> watcherValues = new ArrayList<>();
|
||||
|
||||
for (MetaIndex index : MetaIndex.getMetaIndexes(ArmorStandWatcher.class)) {
|
||||
Object val = index.getDefault();
|
||||
@ -3077,18 +3009,18 @@ public class DisguiseUtilities {
|
||||
val = true;
|
||||
}
|
||||
|
||||
WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager.createDataWatcherObject(index, val);
|
||||
|
||||
watcher.setObject(obj, ReflectionManager.convertInvalidMeta(val));
|
||||
watcherValues.add(new WatcherValue(index, val));
|
||||
}
|
||||
|
||||
if (NmsVersion.v1_15.isSupported()) {
|
||||
PacketContainer metaPacket =
|
||||
ProtocolLibrary.getProtocolManager().createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, standIds[i], watcher, true)
|
||||
.createPacket(standIds[i], watcher, true);
|
||||
PacketContainer metaPacket = ReflectionManager.getMetadataPacket(standIds[i], watcherValues);
|
||||
|
||||
packets.add(metaPacket);
|
||||
} else {
|
||||
WrappedDataWatcher watcher = new WrappedDataWatcher();
|
||||
|
||||
watcherValues.forEach(v -> watcher.setObject(v.getIndex(), ReflectionManager.createDataWatcherObject(v.getMetaIndex(), v.getValue())));
|
||||
|
||||
packet.getDataWatcherModifier().write(0, watcher);
|
||||
}
|
||||
}
|
||||
|
@ -277,11 +277,7 @@ public class DisguiseListener implements Listener {
|
||||
|
||||
packet.getItemModifier().write(0, currentlyHeld);
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
|
||||
org.bukkit.inventory.ItemStack newHeld = player.getInventory().getItem(event.getNewSlot());
|
||||
@ -301,11 +297,7 @@ public class DisguiseListener implements Listener {
|
||||
|
||||
packet.getItemModifier().write(0, new ItemStack(Material.AIR));
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -460,10 +452,8 @@ public class DisguiseListener implements Listener {
|
||||
PlayerDisguise disguise = (PlayerDisguise) targetedDisguise;
|
||||
|
||||
if (disguise.isDisplayedInTab()) {
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(p, DisguiseUtilities.getTabPacket(disguise, PlayerInfoAction.ADD_PLAYER));
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
for (PacketContainer packet : ReflectionManager.createTablistAddPackets(disguise)) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(p, packet);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,6 +21,9 @@ import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.events.UndisguiseEvent;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.reflection.WatcherValue;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
@ -33,6 +36,7 @@ import org.bukkit.scheduler.BukkitRunnable;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@ -161,11 +165,7 @@ public class PlayerSkinHandler implements Listener {
|
||||
|
||||
packet.getModifier().write(0, id);
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
}
|
||||
|
||||
@ -259,11 +259,11 @@ public class PlayerSkinHandler implements Listener {
|
||||
}
|
||||
|
||||
Entity entity = disguise.getEntity();
|
||||
WrappedDataWatcher watcher = DisguiseUtilities.createSanitizedDataWatcher(player, WrappedDataWatcher.getEntityWatcher(entity), disguise.getWatcher());
|
||||
|
||||
PacketContainer metaPacket =
|
||||
ProtocolLibrary.getProtocolManager().createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entity.getEntityId(), watcher, true)
|
||||
.createPacket(entity.getEntityId(), watcher, true);
|
||||
List<WatcherValue> watcherValues =
|
||||
DisguiseUtilities.createSanitizedWatcherValues(player, WrappedDataWatcher.getEntityWatcher(entity), disguise.getWatcher());
|
||||
|
||||
PacketContainer metaPacket = ReflectionManager.getMetadataPacket(entity.getEntityId(), watcherValues);
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, metaPacket, false);
|
||||
}
|
||||
@ -319,16 +319,16 @@ public class PlayerSkinHandler implements Listener {
|
||||
}
|
||||
|
||||
try {
|
||||
for (Map.Entry<Integer, ArrayList<PacketContainer>> entry : skin.getSleptPackets().entrySet()) {
|
||||
if (entry.getKey() == 0) {
|
||||
for (PacketContainer packet : entry.getValue()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
} else {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
if (disguise.isDisguiseInUse()) {
|
||||
for (Map.Entry<Integer, ArrayList<PacketContainer>> entry : skin.getSleptPackets().entrySet()) {
|
||||
if (entry.getKey() == 0) {
|
||||
for (PacketContainer packet : entry.getValue()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
} else {
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (!disguise.isDisguiseInUse()) {
|
||||
return;
|
||||
}
|
||||
@ -336,39 +336,37 @@ public class PlayerSkinHandler implements Listener {
|
||||
for (PacketContainer packet : entry.getValue()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
}
|
||||
}.runTaskLater(LibsDisguises.getInstance(), entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
if (skin.isSleepPackets()) {
|
||||
addTeleport(player, skin);
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
addMetadata(player, skin);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}.runTaskLater(LibsDisguises.getInstance(), entry.getKey());
|
||||
}.runTask(LibsDisguises.getInstance());
|
||||
}
|
||||
}
|
||||
|
||||
if (skin.isSleepPackets()) {
|
||||
addTeleport(player, skin);
|
||||
if (DisguiseConfig.isArmorstandsName() && disguise.isNameVisible() && disguise.getMultiNameLength() > 0) {
|
||||
ArrayList<PacketContainer> packets = DisguiseUtilities.getNamePackets(disguise, new String[0]);
|
||||
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
addMetadata(player, skin);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
for (PacketContainer p : packets) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, p);
|
||||
}
|
||||
}.runTask(LibsDisguises.getInstance());
|
||||
}
|
||||
|
||||
if (DisguiseConfig.isArmorstandsName() && disguise.isNameVisible() && disguise.getMultiNameLength() > 0) {
|
||||
ArrayList<PacketContainer> packets = DisguiseUtilities.getNamePackets(disguise, new String[0]);
|
||||
|
||||
for (PacketContainer p : packets) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, p);
|
||||
}
|
||||
}
|
||||
|
||||
if (skin.isDoTabList()) {
|
||||
PacketContainer packetContainer = DisguiseUtilities.getTabPacket(disguise, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
|
||||
PacketContainer packetContainer = ReflectionManager.createTablistPacket(disguise, EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
|
||||
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packetContainer);
|
||||
}
|
||||
|
@ -77,13 +77,9 @@ public class LibsPackets {
|
||||
packets.removeIf(p -> p.getType() != PacketType.Play.Server.PLAYER_INFO);
|
||||
}
|
||||
|
||||
try {
|
||||
for (PacketContainer packet : entry.getValue()) {
|
||||
// To have right click handled properly, equip packets sent are normal
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, packet.getType() == PacketType.Play.Server.ENTITY_EQUIPMENT);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
for (PacketContainer packet : entry.getValue()) {
|
||||
// To have right click handled properly, equip packets sent are normal
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, packet.getType() == PacketType.Play.Server.ENTITY_EQUIPMENT);
|
||||
}
|
||||
}, entry.getKey());
|
||||
}
|
||||
|
@ -14,11 +14,13 @@ import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
||||
import me.libraryaddict.disguise.utilities.packets.PacketsHandler;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.reflection.WatcherValue;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
|
||||
import java.sql.Ref;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@ -86,11 +88,11 @@ public class PacketHandlerEquipment implements IPacketHandler {
|
||||
slot == EquipmentSlot.OFF_HAND)) {
|
||||
if (itemStack != null && itemStack.getType() != Material.AIR) {
|
||||
// Convert the datawatcher
|
||||
List<WrappedWatchableObject> list = new ArrayList<>();
|
||||
List<WatcherValue> list = new ArrayList<>();
|
||||
|
||||
if (DisguiseConfig.isMetaPacketsEnabled()) {
|
||||
WrappedWatchableObject watch = ReflectionManager.createWatchable(MetaIndex.LIVING_META,
|
||||
WrappedDataWatcher.getEntityWatcher(entity).getByte(MetaIndex.LIVING_META.getIndex()));
|
||||
WatcherValue watch =
|
||||
new WatcherValue(MetaIndex.LIVING_META, WrappedDataWatcher.getEntityWatcher(entity).getByte(MetaIndex.LIVING_META.getIndex()));
|
||||
|
||||
if (watch != null) {
|
||||
list.add(watch);
|
||||
@ -98,7 +100,7 @@ public class PacketHandlerEquipment implements IPacketHandler {
|
||||
|
||||
list = disguise.getWatcher().convert(observer, list);
|
||||
} else {
|
||||
for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) {
|
||||
for (WatcherValue obj : disguise.getWatcher().getWatchableObjects()) {
|
||||
if (obj.getIndex() == MetaIndex.LIVING_META.getIndex()) {
|
||||
list.add(obj);
|
||||
break;
|
||||
@ -107,16 +109,12 @@ public class PacketHandlerEquipment implements IPacketHandler {
|
||||
}
|
||||
|
||||
// Construct the packets to return
|
||||
PacketContainer packetBlock = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
PacketContainer packetBlock = ReflectionManager.getMetadataPacket(entity.getEntityId(), list);
|
||||
|
||||
packetBlock.getModifier().write(0, entity.getEntityId());
|
||||
packetBlock.getWatchableCollectionModifier().write(0, list);
|
||||
list.forEach(v -> v.setValue((byte) 0));
|
||||
|
||||
PacketContainer packetUnblock = packetBlock.deepClone();
|
||||
// Make a packet to send the 'unblock'
|
||||
for (WrappedWatchableObject watcher : packetUnblock.getWatchableCollectionModifier().read(0)) {
|
||||
watcher.setValue((byte) 0);
|
||||
}
|
||||
PacketContainer packetUnblock = ReflectionManager.getMetadataPacket(entity.getEntityId(), list);
|
||||
|
||||
// Send the unblock before the itemstack change so that the 2nd metadata packet works. Why?
|
||||
// Scheduler
|
||||
@ -162,12 +160,11 @@ public class PacketHandlerEquipment implements IPacketHandler {
|
||||
|
||||
if (itemStack != null && itemStack.getType() != Material.AIR) {
|
||||
// Convert the datawatcher
|
||||
List<WrappedWatchableObject> list = new ArrayList<>();
|
||||
List<WatcherValue> list = new ArrayList<>();
|
||||
MetaIndex toUse = NmsVersion.v1_13.isSupported() ? MetaIndex.LIVING_META : MetaIndex.ENTITY_META;
|
||||
|
||||
if (DisguiseConfig.isMetaPacketsEnabled()) {
|
||||
WrappedWatchableObject watch =
|
||||
ReflectionManager.createWatchable(toUse, WrappedDataWatcher.getEntityWatcher(entity).getByte(toUse.getIndex()));
|
||||
WatcherValue watch = new WatcherValue(toUse, WrappedDataWatcher.getEntityWatcher(entity).getByte(toUse.getIndex()));
|
||||
|
||||
if (watch != null) {
|
||||
list.add(watch);
|
||||
@ -175,7 +172,7 @@ public class PacketHandlerEquipment implements IPacketHandler {
|
||||
|
||||
list = disguise.getWatcher().convert(observer, list);
|
||||
} else {
|
||||
for (WrappedWatchableObject obj : disguise.getWatcher().getWatchableObjects()) {
|
||||
for (WatcherValue obj : disguise.getWatcher().getWatchableObjects()) {
|
||||
if (obj.getIndex() == toUse.getIndex()) {
|
||||
list.add(obj);
|
||||
break;
|
||||
@ -184,20 +181,12 @@ public class PacketHandlerEquipment implements IPacketHandler {
|
||||
}
|
||||
|
||||
// Construct the packets to return
|
||||
PacketContainer packetBlock = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
PacketContainer packetBlock = ReflectionManager.getMetadataPacket(entity.getEntityId(), list);
|
||||
|
||||
packetBlock.getModifier().write(0, entity.getEntityId());
|
||||
packetBlock.getWatchableCollectionModifier().write(0, list);
|
||||
list.forEach(v -> v.setValue(NmsVersion.v1_13.isSupported() ? (byte) 0 : (byte) ((byte) v.getValue() & ~(1 << 4))));
|
||||
|
||||
PacketContainer packetUnblock = packetBlock.deepClone();
|
||||
// Make a packet to send the 'unblock'
|
||||
for (WrappedWatchableObject watcher : packetUnblock.getWatchableCollectionModifier().read(0)) {
|
||||
if (NmsVersion.v1_13.isSupported()) {
|
||||
watcher.setValue((byte) 0);
|
||||
} else {
|
||||
watcher.setValue((byte) ((byte) watcher.getRawValue() & ~(1 << 4)));
|
||||
}
|
||||
}
|
||||
PacketContainer packetUnblock = ReflectionManager.getMetadataPacket(entity.getEntityId(), list);
|
||||
|
||||
// Send the unblock before the itemstack change so that the 2nd metadata packet works. Why?
|
||||
// Scheduler
|
||||
|
@ -3,15 +3,20 @@ package me.libraryaddict.disguise.utilities.packets.packethandlers;
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataValue;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
import me.libraryaddict.disguise.DisguiseConfig;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.packets.IPacketHandler;
|
||||
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
||||
import me.libraryaddict.disguise.utilities.packets.PacketsHandler;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.reflection.WatcherValue;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@ -37,21 +42,17 @@ public class PacketHandlerMetadata implements IPacketHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
List<WrappedWatchableObject> watchableObjects = disguise.getWatcher().convert(observer, sentPacket.getWatchableCollectionModifier().read(0));
|
||||
List<WatcherValue> watcherValues = WatcherValue.getValues(disguise.getWatcher(), sentPacket);
|
||||
|
||||
List<WatcherValue> watchableObjects = disguise.getWatcher().convert(observer, watcherValues);
|
||||
|
||||
if (watchableObjects.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
PacketContainer metaPacket = ReflectionManager.getMetadataPacket(entity.getEntityId(), watchableObjects);
|
||||
|
||||
packets.addPacket(metaPacket);
|
||||
|
||||
StructureModifier<Object> newMods = metaPacket.getModifier();
|
||||
|
||||
newMods.write(0, entity.getEntityId());
|
||||
|
||||
metaPacket.getWatchableCollectionModifier().write(0, watchableObjects);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.WrappedAttribute;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
@ -26,6 +27,7 @@ import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
||||
import me.libraryaddict.disguise.utilities.packets.PacketsHandler;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.reflection.WatcherValue;
|
||||
import org.bukkit.Art;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
@ -82,7 +84,6 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
*/
|
||||
private void constructSpawnPackets(final Player observer, LibsPackets packets, Entity disguisedEntity) {
|
||||
Disguise disguise = packets.getDisguise();
|
||||
boolean sendArmor = true;
|
||||
|
||||
Location loc = disguisedEntity.getLocation().clone().add(0, DisguiseUtilities.getYModifier(disguise) + disguise.getWatcher().getYModifier(), 0);
|
||||
|
||||
@ -105,7 +106,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
pitch = DisguiseUtilities.getPitch(disguise.getType(), pitch);
|
||||
}
|
||||
|
||||
boolean normalPlayerDisguise = true;
|
||||
boolean inLineOfSight = true;
|
||||
|
||||
if (disguise.getType() == DisguiseType.EXPERIENCE_ORB) {
|
||||
PacketContainer spawnOrb = new PacketContainer(PacketType.Play.Server.SPAWN_ENTITY_EXPERIENCE_ORB);
|
||||
@ -148,30 +149,29 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
} else if (disguise.getType().isPlayer()) {
|
||||
PlayerDisguise playerDisguise = (PlayerDisguise) disguise;
|
||||
boolean visibleOrNewCompat = playerDisguise.isNameVisible() || DisguiseConfig.isScoreboardNames();
|
||||
double dist = observer.getLocation().toVector().distanceSquared(disguisedEntity.getLocation().toVector());
|
||||
|
||||
// If self disguise, or further than 50 blocks, or not in front of entity
|
||||
inLineOfSight =
|
||||
NmsVersion.v1_19_R2.isSupported() || observer == disguisedEntity || disguisedEntity.getPassengers().contains(observer) || dist > (50 * 50) ||
|
||||
(observer.getLocation().add(observer.getLocation().getDirection().normalize()).toVector()
|
||||
.distanceSquared(disguisedEntity.getLocation().toVector()) - dist) < 0.3;
|
||||
|
||||
int entityId = disguisedEntity.getEntityId();
|
||||
|
||||
PlayerSkinHandler.PlayerSkin skin;
|
||||
|
||||
if (!playerDisguise.isDisplayedInTab() || !playerDisguise.isNameVisible()) {
|
||||
if (NmsVersion.v1_19_R2.isSupported() || !playerDisguise.isDisplayedInTab() || !playerDisguise.isNameVisible()) {
|
||||
// Send player info along with the disguise
|
||||
PacketContainer sendTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
|
||||
// Add player to the list, necessary to spawn them
|
||||
sendTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(0));
|
||||
|
||||
List playerList = Collections.singletonList(ReflectionManager.getPlayerInfoData(sendTab.getHandle(),
|
||||
ReflectionManager.getGameProfileWithThisSkin(playerDisguise.getUUID(), playerDisguise.getProfileName(), playerDisguise.getGameProfile())));
|
||||
sendTab.getModifier().write(1, playerList);
|
||||
|
||||
packets.addPacket(sendTab);
|
||||
|
||||
// Remove player from the list
|
||||
PacketContainer deleteTab = sendTab.shallowClone();
|
||||
deleteTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(4));
|
||||
for (PacketContainer sendTab : ReflectionManager.createTablistAddPackets(playerDisguise)) {
|
||||
packets.addPacket(sendTab);
|
||||
}
|
||||
|
||||
skin = LibsDisguises.getInstance().getSkinHandler().addPlayerSkin(observer, playerDisguise);
|
||||
skin.setDoTabList(!NmsVersion.v1_19_R2.isSupported());
|
||||
|
||||
if (LibsPremium.getPaidInformation() != null && !LibsPremium.getPaidInformation().getBuildNumber().matches("#[0-9]+")) {
|
||||
if (LibsPremium.getPaidInformation() != null && !LibsPremium.getPaidInformation().getBuildNumber().matches("#\\d+")) {
|
||||
skin.getSleptPackets().computeIfAbsent(0, (a) -> new ArrayList<>()).add(new PacketContainer(PacketType.Play.Server.HELD_ITEM_SLOT));
|
||||
}
|
||||
} else {
|
||||
@ -179,23 +179,15 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
skin.setDoTabList(false);
|
||||
}
|
||||
|
||||
skin.setSleepPackets(!inLineOfSight);
|
||||
|
||||
// Spawn the player
|
||||
PacketContainer spawnPlayer = new PacketContainer(PacketType.Play.Server.NAMED_ENTITY_SPAWN);
|
||||
|
||||
spawnPlayer.getIntegers().write(0, entityId); // Id
|
||||
spawnPlayer.getModifier().write(1, playerDisguise.getUUID());
|
||||
|
||||
double dist = observer.getLocation().toVector().distanceSquared(disguisedEntity.getLocation().toVector());
|
||||
|
||||
// If self disguise, or further than 50 blocks, or not in front of entity
|
||||
normalPlayerDisguise = observer == disguisedEntity || disguisedEntity.getPassengers().contains(observer) || dist > (50 * 50) ||
|
||||
(observer.getLocation().add(observer.getLocation().getDirection().normalize()).toVector()
|
||||
.distanceSquared(disguisedEntity.getLocation().toVector()) - dist) < 0.3;
|
||||
sendArmor = normalPlayerDisguise;
|
||||
|
||||
skin.setSleepPackets(!normalPlayerDisguise);
|
||||
|
||||
Location spawnAt = normalPlayerDisguise ? 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();
|
||||
@ -209,26 +201,21 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
|
||||
packets.addPacket(spawnPlayer);
|
||||
|
||||
WrappedDataWatcher toSend;
|
||||
List<WatcherValue> watcherValues;
|
||||
|
||||
if (!normalPlayerDisguise) {
|
||||
toSend = new WrappedDataWatcher();
|
||||
WrappedDataWatcher.WrappedDataWatcherObject obj = ReflectionManager.createDataWatcherObject(MetaIndex.ENTITY_META, (byte) 32);
|
||||
|
||||
// Set invis
|
||||
toSend.setObject(obj, (byte) 32);
|
||||
if (!inLineOfSight) {
|
||||
watcherValues = Collections.singletonList(new WatcherValue(MetaIndex.ENTITY_META, (byte) 32));
|
||||
} else {
|
||||
toSend = DisguiseUtilities.createSanitizedDataWatcher(observer, WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher());
|
||||
watcherValues =
|
||||
DisguiseUtilities.createSanitizedWatcherValues(observer, WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher());
|
||||
}
|
||||
|
||||
if (NmsVersion.v1_15.isSupported()) {
|
||||
PacketContainer metaPacket =
|
||||
ProtocolLibrary.getProtocolManager().createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, entityId, toSend, true)
|
||||
.createPacket(entityId, toSend, true);
|
||||
PacketContainer metaPacket = ReflectionManager.getMetadataPacket(entityId, watcherValues);
|
||||
|
||||
packets.addPacket(metaPacket);
|
||||
} else {
|
||||
spawnPlayer.getDataWatcherModifier().write(0, toSend);
|
||||
spawnPlayer.getDataWatcherModifier().write(0, DisguiseUtilities.createDatawatcher(watcherValues));
|
||||
}
|
||||
} else if (disguise.isMobDisguise() || disguise.getType() == DisguiseType.ARMOR_STAND) {
|
||||
Vector vec = disguisedEntity.getVelocity();
|
||||
@ -303,17 +290,15 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
|
||||
mods.write(11, yaw);
|
||||
|
||||
WrappedDataWatcher newWatcher =
|
||||
DisguiseUtilities.createSanitizedDataWatcher(observer, WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher());
|
||||
List<WatcherValue> watcherValues =
|
||||
DisguiseUtilities.createSanitizedWatcherValues(observer, WrappedDataWatcher.getEntityWatcher(disguisedEntity), disguise.getWatcher());
|
||||
|
||||
if (NmsVersion.v1_15.isSupported()) {
|
||||
PacketContainer metaPacket = ProtocolLibrary.getProtocolManager()
|
||||
.createPacketConstructor(PacketType.Play.Server.ENTITY_METADATA, disguisedEntity.getEntityId(), newWatcher, true)
|
||||
.createPacket(disguisedEntity.getEntityId(), newWatcher, true);
|
||||
PacketContainer metaPacket = ReflectionManager.getMetadataPacket(disguisedEntity.getEntityId(), watcherValues);
|
||||
|
||||
packets.addPacket(metaPacket);
|
||||
} else {
|
||||
spawnEntity.getDataWatcherModifier().write(0, newWatcher);
|
||||
spawnEntity.getDataWatcherModifier().write(0, DisguiseUtilities.createDatawatcher(watcherValues));
|
||||
}
|
||||
} else if (disguise.getType().isMisc()) {
|
||||
int data = ((MiscDisguise) disguise).getData();
|
||||
@ -469,7 +454,7 @@ public class PacketHandlerSpawn implements IPacketHandler {
|
||||
}
|
||||
}
|
||||
|
||||
if (!disguise.isPlayerDisguise() || normalPlayerDisguise) {
|
||||
if (!disguise.isPlayerDisguise() || inLineOfSight) {
|
||||
DisguiseUtilities.getNamePackets(disguise, new String[0]).forEach(packets::addPacket);
|
||||
}
|
||||
|
||||
|
@ -56,12 +56,8 @@ public class PacketListenerClientCustomPayload extends PacketAdapter {
|
||||
|
||||
player.removeMetadata("ld_tabsend", LibsDisguises.getInstance());
|
||||
|
||||
try {
|
||||
for (PacketContainer packet : packets) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
for (PacketContainer packet : packets) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -72,10 +72,6 @@ public class PacketListenerEntityDestroy extends PacketAdapter {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, DisguiseUtilities.getDestroyPacket(toRemove));
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, DisguiseUtilities.getDestroyPacket(toRemove));
|
||||
}
|
||||
}
|
||||
|
@ -95,11 +95,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
|
||||
packet.getItemModifier().write(0, new ItemStack(Material.AIR));
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
}
|
||||
} else if (slot >= 36 && slot <= 45) {
|
||||
@ -122,11 +118,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
|
||||
packet.getItemModifier().write(0, new ItemStack(Material.AIR));
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -185,11 +177,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
|
||||
packet.getItemModifier().write(0, new ItemStack(Material.AIR));
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
// Else if its a hotbar slot
|
||||
} else if (slot >= 36 && slot <= 45) {
|
||||
@ -208,11 +196,7 @@ public class PacketListenerInventory extends PacketAdapter {
|
||||
mods.write(1, ReflectionManager.getIncrementedStateId(player));
|
||||
}
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(player, packet, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
||||
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -69,14 +70,10 @@ public class PacketListenerMain extends PacketAdapter {
|
||||
|
||||
event.setCancelled(true);
|
||||
|
||||
try {
|
||||
for (PacketContainer packet : packets.getPackets()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||
}
|
||||
|
||||
packets.sendDelayed(observer);
|
||||
} catch (InvocationTargetException ex) {
|
||||
ex.printStackTrace();
|
||||
for (PacketContainer packet : packets.getPackets()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, packet, false);
|
||||
}
|
||||
|
||||
packets.sendDelayed(observer);
|
||||
}
|
||||
}
|
||||
|
@ -92,11 +92,7 @@ public class PacketListenerModdedClient extends PacketAdapter {
|
||||
PacketContainer packet = new PacketContainer(PacketType.Login.Client.START);
|
||||
packet.getModifier().write(0, new GameProfile(null, name));
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().recieveClientPacket(player, packet, false);
|
||||
} catch (IllegalAccessException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().receiveClientPacket(player, packet, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,11 +9,14 @@ import com.comphenix.protocol.wrappers.PlayerInfoData;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
import me.libraryaddict.disguise.disguisetypes.Disguise;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class PacketListenerTabList extends PacketAdapter {
|
||||
public PacketListenerTabList(LibsDisguises plugin) {
|
||||
@ -27,17 +30,35 @@ public class PacketListenerTabList extends PacketAdapter {
|
||||
}
|
||||
|
||||
Player observer = event.getPlayer();
|
||||
Set<PlayerInfoAction> actions;
|
||||
|
||||
if (event.getPacket().getPlayerInfoAction().read(0) != PlayerInfoAction.ADD_PLAYER) {
|
||||
if (NmsVersion.v1_19_R2.isSupported()) {
|
||||
actions = event.getPacket().getPlayerInfoActions().read(0);
|
||||
} else {
|
||||
actions = EnumSet.of(event.getPacket().getPlayerInfoAction().read(0));
|
||||
}
|
||||
|
||||
if (actions.stream().noneMatch(a -> a == PlayerInfoAction.ADD_PLAYER)) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<PlayerInfoData> list = event.getPacket().getPlayerInfoDataLists().read(0);
|
||||
List<PlayerInfoData> list = event.getPacket().getPlayerInfoDataLists().read(NmsVersion.v1_19_R2.isSupported() ? 1 : 0);
|
||||
Iterator<PlayerInfoData> itel = list.iterator();
|
||||
Iterator<PlayerInfoAction> actionItel = actions.iterator();
|
||||
|
||||
while (itel.hasNext()) {
|
||||
PlayerInfoData data = itel.next();
|
||||
|
||||
if (NmsVersion.v1_19_R2.isSupported()) {
|
||||
if (actionItel.next() != PlayerInfoAction.ADD_PLAYER) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
if (data == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Player player = Bukkit.getPlayer(data.getProfile().getUUID());
|
||||
|
||||
if (player == null) {
|
||||
@ -55,12 +76,23 @@ public class PacketListenerTabList extends PacketAdapter {
|
||||
}
|
||||
|
||||
itel.remove();
|
||||
|
||||
if (NmsVersion.v1_19_R2.isSupported()) {
|
||||
actionItel.remove();
|
||||
}
|
||||
}
|
||||
|
||||
if (list.isEmpty()) {
|
||||
event.setCancelled(true);
|
||||
} else {
|
||||
event.getPacket().getPlayerInfoDataLists().write(0, list);
|
||||
return;
|
||||
}
|
||||
|
||||
event.getPacket().getPlayerInfoDataLists().write(NmsVersion.v1_19_R2.isSupported() ? 1 : 0, list);
|
||||
|
||||
if (!NmsVersion.v1_19_R2.isSupported()) {
|
||||
return;
|
||||
}
|
||||
|
||||
event.getPacket().getPlayerInfoActions().write(0, actions);
|
||||
}
|
||||
}
|
||||
|
@ -7,6 +7,7 @@ import com.comphenix.protocol.events.PacketAdapter;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.events.PacketEvent;
|
||||
import com.comphenix.protocol.reflect.StructureModifier;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataValue;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
import me.libraryaddict.disguise.DisguiseAPI;
|
||||
import me.libraryaddict.disguise.LibsDisguises;
|
||||
@ -17,7 +18,9 @@ import me.libraryaddict.disguise.utilities.DisguiseUtilities;
|
||||
import me.libraryaddict.disguise.utilities.LibsPremium;
|
||||
import me.libraryaddict.disguise.utilities.packets.LibsPackets;
|
||||
import me.libraryaddict.disguise.utilities.packets.PacketsManager;
|
||||
import me.libraryaddict.disguise.utilities.reflection.NmsVersion;
|
||||
import me.libraryaddict.disguise.utilities.reflection.ReflectionManager;
|
||||
import me.libraryaddict.disguise.utilities.reflection.WatcherValue;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
@ -102,12 +105,8 @@ public class PacketListenerViewSelfDisguise extends PacketAdapter {
|
||||
LibsDisguises.getInstance().getSkinHandler().handlePackets(observer, (PlayerDisguise) disguise, selfTransformed);
|
||||
}
|
||||
|
||||
try {
|
||||
for (PacketContainer newPacket : selfTransformed.getPackets()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, newPacket, false);
|
||||
}
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
for (PacketContainer newPacket : selfTransformed.getPackets()) {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, newPacket, false);
|
||||
}
|
||||
|
||||
selfTransformed.sendDelayed(observer);
|
||||
@ -118,47 +117,50 @@ public class PacketListenerViewSelfDisguise extends PacketAdapter {
|
||||
event.setPacket(packet = packet.deepClone());
|
||||
}
|
||||
|
||||
for (WrappedWatchableObject watch : packet.getWatchableCollectionModifier().read(0)) {
|
||||
if (watch.getIndex() != 0) {
|
||||
continue;
|
||||
if (NmsVersion.v1_19_R2.isSupported()) {
|
||||
for (WrappedDataValue watch : packet.getDataValueCollectionModifier().read(0)) {
|
||||
if (watch.getIndex() != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
byte b = (byte) watch.getRawValue();
|
||||
|
||||
// Add invisibility, remove glowing
|
||||
byte a = (byte) ((b | 1 << 5) & ~(1 << 6));
|
||||
|
||||
watch.setValue(a);
|
||||
}
|
||||
} else {
|
||||
for (WrappedWatchableObject watch : packet.getWatchableCollectionModifier().read(0)) {
|
||||
if (watch.getIndex() != 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
byte b = (byte) watch.getRawValue();
|
||||
byte b = (byte) watch.getRawValue();
|
||||
|
||||
// Add invisibility, remove glowing
|
||||
byte a = (byte) ((b | 1 << 5) & ~(1 << 6));
|
||||
// Add invisibility, remove glowing
|
||||
byte a = (byte) ((b | 1 << 5) & ~(1 << 6));
|
||||
|
||||
watch.setValue(a);
|
||||
watch.setValue(a);
|
||||
}
|
||||
}
|
||||
} else if (event.getPacketType() == Server.NAMED_ENTITY_SPAWN) {
|
||||
event.setCancelled(true);
|
||||
|
||||
PacketContainer metaPacket = new PacketContainer(Server.ENTITY_METADATA);
|
||||
|
||||
StructureModifier<Object> mods = metaPacket.getModifier();
|
||||
|
||||
mods.write(0, observer.getEntityId());
|
||||
|
||||
List<WrappedWatchableObject> watchableList = new ArrayList<>();
|
||||
List<WatcherValue> watchableList = new ArrayList<>();
|
||||
byte b = 1 << 5;
|
||||
|
||||
if (observer.isSprinting()) {
|
||||
b = (byte) (b | 1 << 3);
|
||||
}
|
||||
|
||||
WrappedWatchableObject watch = ReflectionManager.createWatchable(MetaIndex.ENTITY_META, b);
|
||||
WatcherValue watch = new WatcherValue(MetaIndex.ENTITY_META, b);
|
||||
|
||||
if (watch != null) {
|
||||
watchableList.add(watch);
|
||||
}
|
||||
watchableList.add(watch);
|
||||
|
||||
metaPacket.getWatchableCollectionModifier().write(0, watchableList);
|
||||
PacketContainer metaPacket = ReflectionManager.getMetadataPacket(observer.getEntityId(), watchableList);
|
||||
|
||||
try {
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, metaPacket);
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
ProtocolLibrary.getProtocolManager().sendServerPacket(observer, metaPacket);
|
||||
} else if (event.getPacketType() == Server.ANIMATION) {
|
||||
if (packet.getIntegers().read(1) != 2) {
|
||||
event.setCancelled(true);
|
||||
|
@ -12,7 +12,9 @@ public enum NmsVersion {
|
||||
v1_17,
|
||||
v1_18,
|
||||
v1_19,
|
||||
v1_19_1;
|
||||
v1_19_1,
|
||||
v1_19_R2,
|
||||
UNSUPPORTED;
|
||||
|
||||
/**
|
||||
* If this nms version isn't newer than the running version
|
||||
|
@ -1,11 +1,17 @@
|
||||
package me.libraryaddict.disguise.utilities.reflection;
|
||||
|
||||
import com.comphenix.protocol.PacketType;
|
||||
import com.comphenix.protocol.ProtocolLibrary;
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.reflect.FieldAccessException;
|
||||
import com.comphenix.protocol.wrappers.BlockPosition;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers.Direction;
|
||||
import com.comphenix.protocol.wrappers.PlayerInfoData;
|
||||
import com.comphenix.protocol.wrappers.Vector3F;
|
||||
import com.comphenix.protocol.wrappers.WrappedBlockData;
|
||||
import com.comphenix.protocol.wrappers.WrappedChatComponent;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataValue;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher.WrappedDataWatcherObject;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
@ -20,6 +26,7 @@ import me.libraryaddict.disguise.disguisetypes.DisguiseType;
|
||||
import me.libraryaddict.disguise.disguisetypes.EntityPose;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
import me.libraryaddict.disguise.disguisetypes.PlayerDisguise;
|
||||
import me.libraryaddict.disguise.disguisetypes.VillagerData;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.AgeableWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.watchers.ArrowWatcher;
|
||||
@ -100,9 +107,12 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.AbstractMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
@ -523,6 +533,28 @@ public class ReflectionManager {
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static PacketContainer getMetadataPacket(int entityId, List<WatcherValue> values) {
|
||||
Object[] params;
|
||||
|
||||
PacketContainer metaPacket = new PacketContainer(PacketType.Play.Server.ENTITY_METADATA);
|
||||
|
||||
metaPacket.getIntegers().write(0, entityId);
|
||||
|
||||
if (NmsVersion.v1_19_R2.isSupported()) {
|
||||
List<WrappedDataValue> dataValues = new ArrayList<>();
|
||||
values.forEach(v -> dataValues.add(v.getDataValue()));
|
||||
|
||||
metaPacket.getDataValueCollectionModifier().write(0, dataValues);
|
||||
} else {
|
||||
List<WrappedWatchableObject> dataValues = new ArrayList<>();
|
||||
values.forEach(v -> dataValues.add(v.getWatchableObject()));
|
||||
|
||||
metaPacket.getWatchableCollectionModifier().write(0, dataValues);
|
||||
}
|
||||
|
||||
return metaPacket;
|
||||
}
|
||||
|
||||
public static Object getPlayerConnectionOrPlayer(Player player) {
|
||||
if (nmsReflection != null) {
|
||||
return nmsReflection.getPlayerConnectionOrPlayer(player);
|
||||
@ -754,11 +786,10 @@ public class ReflectionManager {
|
||||
}
|
||||
|
||||
version = v;
|
||||
break;
|
||||
}
|
||||
|
||||
if (version == NmsVersion.v1_19 && Bukkit.getVersion().contains("1.19.")) {
|
||||
version = NmsVersion.v1_19_1;
|
||||
if (version == NmsVersion.v1_19_1 && !Bukkit.getVersion().matches("1\\.19\\.[12]")) {
|
||||
version = NmsVersion.v1_19;
|
||||
}
|
||||
}
|
||||
|
||||
@ -917,10 +948,6 @@ public class ReflectionManager {
|
||||
}
|
||||
|
||||
public static Enum getEnumPlayerInfoAction(int action) {
|
||||
if (nmsReflection != null) {
|
||||
return nmsReflection.getEnumPlayerInfoAction(action);
|
||||
}
|
||||
|
||||
try {
|
||||
return enumPlayerInfoAction[action];
|
||||
} catch (Exception ex) {
|
||||
@ -930,15 +957,57 @@ public class ReflectionManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public static Object getPlayerInfoData(Object playerInfoPacket, WrappedGameProfile gameProfile) {
|
||||
public static PacketContainer updateTablistVisibility(Player player, boolean visible) {
|
||||
if (NmsVersion.v1_19_R2.isSupported()) {
|
||||
return nmsReflection.getTabListPacket(player.getPlayerListName(), ReflectionManager.getGameProfile(player),
|
||||
EnumWrappers.PlayerInfoAction.UPDATE_LISTED, visible);
|
||||
}
|
||||
|
||||
PlayerInfoData playerInfo =
|
||||
new PlayerInfoData(ReflectionManager.getGameProfile(player), 0, EnumWrappers.NativeGameMode.fromBukkit((player).getGameMode()),
|
||||
WrappedChatComponent.fromText(DisguiseUtilities.getPlayerListName(player)));
|
||||
|
||||
PacketContainer addTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
|
||||
addTab.getPlayerInfoAction().write(0, visible ? EnumWrappers.PlayerInfoAction.ADD_PLAYER : EnumWrappers.PlayerInfoAction.REMOVE_PLAYER);
|
||||
addTab.getPlayerInfoDataLists().write(0, Collections.singletonList(playerInfo));
|
||||
|
||||
return addTab;
|
||||
}
|
||||
|
||||
public static PacketContainer[] createTablistAddPackets(PlayerDisguise disguise) {
|
||||
if (!NmsVersion.v1_19_R2.isSupported()) {
|
||||
return new PacketContainer[]{createTablistPacket(disguise, EnumWrappers.PlayerInfoAction.ADD_PLAYER)};
|
||||
}
|
||||
|
||||
PacketContainer[] packets = new PacketContainer[disguise.isDisplayedInTab() ? 3 : 2];
|
||||
packets[0] = createTablistPacket(disguise, EnumWrappers.PlayerInfoAction.ADD_PLAYER);
|
||||
packets[1] = createTablistPacket(disguise, EnumWrappers.PlayerInfoAction.UPDATE_DISPLAY_NAME);
|
||||
|
||||
if (disguise.isDisplayedInTab()) {
|
||||
packets[2] = createTablistPacket(disguise, EnumWrappers.PlayerInfoAction.UPDATE_LISTED);
|
||||
}
|
||||
|
||||
return packets;
|
||||
}
|
||||
|
||||
public static PacketContainer createTablistPacket(PlayerDisguise disguise, EnumWrappers.PlayerInfoAction action) {
|
||||
if (nmsReflection != null) {
|
||||
return nmsReflection.getPlayerInfoData(gameProfile);
|
||||
return nmsReflection.getTabListPacket(disguise.getName(), disguise.getGameProfile(), action, disguise.isDisplayedInTab());
|
||||
}
|
||||
|
||||
try {
|
||||
Object playerListName = chatComponentConstructor.newInstance(gameProfile.getName());
|
||||
Object playerListName = chatComponentConstructor.newInstance(disguise.getGameProfile().getName());
|
||||
PacketContainer sendTab = new PacketContainer(PacketType.Play.Server.PLAYER_INFO);
|
||||
|
||||
return packetPlayOutConstructor.newInstance(playerInfoPacket, gameProfile.getHandle(), 0, enumGamemode[1], playerListName);
|
||||
// Add player to the list, necessary to spawn them
|
||||
sendTab.getModifier().write(0, ReflectionManager.getEnumPlayerInfoAction(action.ordinal()));
|
||||
|
||||
List playerList = Collections.singletonList(
|
||||
ReflectionManager.getGameProfileWithThisSkin(disguise.getGameProfile().getUUID(), disguise.getProfileName(), disguise.getGameProfile()));
|
||||
sendTab.getModifier().write(1, playerList);
|
||||
|
||||
return sendTab;
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
@ -1214,6 +1283,7 @@ public class ReflectionManager {
|
||||
Object minecraftServer = getMinecraftServer();
|
||||
|
||||
LibsProfileLookupCaller callback = new LibsProfileLookupCaller();
|
||||
|
||||
if (nmsReflection != null) {
|
||||
nmsReflection.injectCallback(playername, callback);
|
||||
} else {
|
||||
@ -2127,6 +2197,7 @@ public class ReflectionManager {
|
||||
* sound volume
|
||||
* for mob noises. As well as setting their watcher class and entity size.
|
||||
*/
|
||||
@SneakyThrows
|
||||
public static void registerValues() {
|
||||
for (DisguiseType disguiseType : DisguiseType.values()) {
|
||||
if (disguiseType.getEntityType() == null) {
|
||||
@ -2206,6 +2277,7 @@ public class ReflectionManager {
|
||||
case MARKER:
|
||||
case TADPOLE:
|
||||
case WARDEN:
|
||||
case CAMEL:
|
||||
nmsEntityName = disguiseType.toReadable().replace(" ", "");
|
||||
break;
|
||||
case DONKEY:
|
||||
|
@ -0,0 +1,89 @@
|
||||
package me.libraryaddict.disguise.utilities.reflection;
|
||||
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataValue;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedWatchableObject;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import me.libraryaddict.disguise.disguisetypes.FlagWatcher;
|
||||
import me.libraryaddict.disguise.disguisetypes.MetaIndex;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class WatcherValue {
|
||||
private final MetaIndex metaIndex;
|
||||
private final int index;
|
||||
private Object value;
|
||||
|
||||
public WatcherValue(int index, Object value) {
|
||||
this.metaIndex = null;
|
||||
this.index = index;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public WatcherValue(MetaIndex index, Object value) {
|
||||
this.index = index.getIndex();
|
||||
this.metaIndex = index;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public WatcherValue(FlagWatcher flagWatcher, WrappedDataValue dataValue) {
|
||||
this.index = dataValue.getIndex();
|
||||
metaIndex = MetaIndex.getMetaIndex(flagWatcher, dataValue.getIndex());
|
||||
value = dataValue.getRawValue();
|
||||
}
|
||||
|
||||
public WatcherValue(FlagWatcher flagWatcher, WrappedWatchableObject dataValue) {
|
||||
this.index = dataValue.getIndex();
|
||||
metaIndex = MetaIndex.getMetaIndex(flagWatcher, dataValue.getIndex());
|
||||
value = dataValue.getRawValue();
|
||||
}
|
||||
|
||||
public WrappedWatchableObject getWatchableObject() {
|
||||
return ReflectionManager.createWatchable(getMetaIndex(), getValue());
|
||||
}
|
||||
|
||||
public WrappedDataValue getDataValue() {
|
||||
return new WrappedDataValue(getMetaIndex().getIndex(), getMetaIndex().getSerializer(), ReflectionManager.convertInvalidMeta(getValue()));
|
||||
}
|
||||
|
||||
public static List<WatcherValue> getValues(WrappedDataWatcher dataWatcher) {
|
||||
List<WatcherValue> list = new ArrayList<>();
|
||||
|
||||
for (WrappedWatchableObject object : dataWatcher.getWatchableObjects()) {
|
||||
list.add(new WatcherValue(object.getIndex(), object.getRawValue()));
|
||||
}
|
||||
|
||||
return list;
|
||||
}
|
||||
|
||||
public static List<WatcherValue> getValues(FlagWatcher watcher, WrappedDataWatcher dataWatcher) {
|
||||
List<WatcherValue> newList = new ArrayList<>();
|
||||
|
||||
for (WrappedWatchableObject object : dataWatcher.getWatchableObjects()) {
|
||||
newList.add(new WatcherValue(watcher, object));
|
||||
}
|
||||
|
||||
return newList;
|
||||
}
|
||||
|
||||
public static List<WatcherValue> getValues(FlagWatcher watcher, PacketContainer packetContainer) {
|
||||
List<WatcherValue> newList = new ArrayList<>();
|
||||
|
||||
if (NmsVersion.v1_19_R2.isSupported()) {
|
||||
for (WrappedDataValue dataValue : packetContainer.getDataValueCollectionModifier().read(0)) {
|
||||
newList.add(new WatcherValue(watcher, dataValue));
|
||||
}
|
||||
} else {
|
||||
for (WrappedWatchableObject object : packetContainer.getWatchableCollectionModifier().read(0)) {
|
||||
newList.add(new WatcherValue(watcher, object));
|
||||
}
|
||||
}
|
||||
|
||||
return newList;
|
||||
}
|
||||
}
|
@ -33,6 +33,10 @@ public enum DisguiseSoundEnums {
|
||||
|
||||
BOAT(null, Sound.ENTITY_BOAT_PADDLE_WATER, null, null, Sound.ENTITY_BOAT_PADDLE_LAND),
|
||||
|
||||
CAMEL(Sound.ENTITY_CAMEL_HURT, new Sound[]{Sound.ENTITY_CAMEL_STEP, Sound.ENTITY_CAMEL_STEP_SAND}, Sound.ENTITY_CAMEL_DEATH, Sound.ENTITY_CAMEL_AMBIENT,
|
||||
Sound.ENTITY_CAMEL_DASH, Sound.ENTITY_CAMEL_DASH_READY, Sound.ENTITY_CAMEL_EAT, Sound.ENTITY_CAMEL_SADDLE, Sound.ENTITY_CAMEL_SIT,
|
||||
Sound.ENTITY_CAMEL_STAND),
|
||||
|
||||
CAT(Sound.ENTITY_CAT_HURT, null, Sound.ENTITY_CAT_DEATH, Sound.ENTITY_CAT_AMBIENT, Sound.ENTITY_CAT_PURR, Sound.ENTITY_CAT_PURREOW, Sound.ENTITY_CAT_HISS),
|
||||
|
||||
CAVE_SPIDER(Sound.ENTITY_SPIDER_HURT, Sound.ENTITY_SPIDER_STEP, Sound.ENTITY_SPIDER_DEATH, Sound.ENTITY_SPIDER_AMBIENT),
|
||||
@ -52,7 +56,7 @@ public enum DisguiseSoundEnums {
|
||||
new Sound[]{Sound.ENTITY_DOLPHIN_AMBIENT, Sound.ENTITY_DOLPHIN_AMBIENT_WATER}, Sound.ENTITY_DOLPHIN_ATTACK, Sound.ENTITY_DOLPHIN_EAT,
|
||||
Sound.ENTITY_DOLPHIN_SPLASH, Sound.ENTITY_DOLPHIN_PLAY, Sound.ENTITY_DOLPHIN_JUMP, Sound.ENTITY_FISH_SWIM),
|
||||
|
||||
DONKEY(Sound.ENTITY_DONKEY_HURT, new Sound[]{Sound.BLOCK_GRASS_STEP, Sound.ENTITY_HORSE_STEP_WOOD,}, Sound.ENTITY_DONKEY_DEATH, Sound.ENTITY_DONKEY_AMBIENT,
|
||||
DONKEY(Sound.ENTITY_DONKEY_HURT, new Sound[]{Sound.BLOCK_GRASS_STEP, Sound.ENTITY_HORSE_STEP_WOOD}, Sound.ENTITY_DONKEY_DEATH, Sound.ENTITY_DONKEY_AMBIENT,
|
||||
Sound.ENTITY_HORSE_GALLOP, Sound.ENTITY_HORSE_SADDLE, Sound.ENTITY_DONKEY_ANGRY, Sound.ENTITY_HORSE_ARMOR, Sound.ENTITY_HORSE_LAND,
|
||||
Sound.ENTITY_HORSE_JUMP, Sound.ENTITY_HORSE_ANGRY, Sound.ENTITY_DONKEY_CHEST),
|
||||
|
||||
@ -77,8 +81,8 @@ public enum DisguiseSoundEnums {
|
||||
|
||||
EVOKER_FANGS(null, null, null, null, Sound.ENTITY_EVOKER_FANGS_ATTACK),
|
||||
|
||||
FOX(Sound.ENTITY_FOX_HURT, null, Sound.ENTITY_FOX_DEATH, Sound.ENTITY_FOX_AMBIENT, Sound.ENTITY_FOX_AGGRO, Sound.ENTITY_FOX_BITE,
|
||||
Sound.ENTITY_FOX_EAT, Sound.ENTITY_FOX_SCREECH, Sound.ENTITY_FOX_SLEEP, Sound.ENTITY_FOX_SPIT, Sound.ENTITY_FOX_SNIFF, Sound.ENTITY_FOX_TELEPORT),
|
||||
FOX(Sound.ENTITY_FOX_HURT, null, Sound.ENTITY_FOX_DEATH, Sound.ENTITY_FOX_AMBIENT, Sound.ENTITY_FOX_AGGRO, Sound.ENTITY_FOX_BITE, Sound.ENTITY_FOX_EAT,
|
||||
Sound.ENTITY_FOX_SCREECH, Sound.ENTITY_FOX_SLEEP, Sound.ENTITY_FOX_SPIT, Sound.ENTITY_FOX_SNIFF, Sound.ENTITY_FOX_TELEPORT),
|
||||
|
||||
FROG(Sound.ENTITY_FROG_HURT, Sound.ENTITY_FROG_STEP, Sound.ENTITY_FROG_DEATH, Sound.ENTITY_FROG_AMBIENT, Sound.ENTITY_FROG_EAT, Sound.ENTITY_FROG_LAY_SPAWN,
|
||||
Sound.ENTITY_FROG_LONG_JUMP, Sound.ENTITY_FROG_TONGUE),
|
||||
|
20
pom.xml
20
pom.xml
@ -23,8 +23,8 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
||||
<lombok.version>1.18.22</lombok.version>
|
||||
<protocollib.version>4.7.0</protocollib.version>
|
||||
<spigot.version>1.19-R0.1-SNAPSHOT</spigot.version>
|
||||
<protocollib.version>5.0.0-SNAPSHOT</protocollib.version>
|
||||
<spigot.version>1.19.3-R0.1-SNAPSHOT</spigot.version>
|
||||
<junit.version>4.13.2</junit.version>
|
||||
<paper-api.version>1.16.5-R0.1-SNAPSHOT</paper-api.version>
|
||||
<bungeecord-chat.version>1.12-SNAPSHOT</bungeecord-chat.version>
|
||||
@ -35,11 +35,16 @@
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<!--<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>${protocollib.version}</version>
|
||||
<optional>true</optional>
|
||||
</dependency>-->
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<groupId>com.github.dmulloy2</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
<version>${protocollib.version}</version>
|
||||
<optional>true</optional>
|
||||
<version>eebb99f</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
@ -78,6 +83,11 @@
|
||||
<url>https://mvn.lumine.io/repository/maven-public/</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
|
||||
<repository>
|
||||
<id>dmulloy2-repo</id>
|
||||
<url>https://repo.dmulloy2.net/nexus/repository/public/</url>
|
||||
|
@ -29,7 +29,7 @@
|
||||
<artifactId>spigot-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.comphenix.protocol</groupId>
|
||||
<groupId>com.github.dmulloy2</groupId>
|
||||
<artifactId>ProtocolLib</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
@ -1,5 +1,6 @@
|
||||
package me.libraryaddict.disguise.utilities.reflection;
|
||||
|
||||
import com.comphenix.protocol.events.PacketContainer;
|
||||
import com.comphenix.protocol.wrappers.EnumWrappers;
|
||||
import com.comphenix.protocol.wrappers.WrappedDataWatcher;
|
||||
import com.comphenix.protocol.wrappers.WrappedGameProfile;
|
||||
@ -71,9 +72,7 @@ public interface ReflectionManagerAbstract {
|
||||
|
||||
Enum getEnumDirection(int direction);
|
||||
|
||||
Enum getEnumPlayerInfoAction(int action);
|
||||
|
||||
Object getPlayerInfoData(WrappedGameProfile gameProfile);
|
||||
PacketContainer getTabListPacket(String displayName, WrappedGameProfile gameProfile, EnumWrappers.PlayerInfoAction action, boolean nameVisible);
|
||||
|
||||
Object getNmsEntity(Entity entity);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user