mirror of
https://github.com/dmulloy2/ProtocolLib.git
synced 2024-09-01 18:39:38 +02:00
Fix PlayerInfoData constructor
This commit is contained in:
parent
5f4867eb1f
commit
776eeb898f
|
@ -3,14 +3,15 @@
|
||||||
*/
|
*/
|
||||||
package com.comphenix.protocol.wrappers;
|
package com.comphenix.protocol.wrappers;
|
||||||
|
|
||||||
import java.lang.reflect.Constructor;
|
import com.comphenix.protocol.events.PacketContainer;
|
||||||
|
|
||||||
import com.comphenix.protocol.reflect.EquivalentConverter;
|
import com.comphenix.protocol.reflect.EquivalentConverter;
|
||||||
import com.comphenix.protocol.reflect.StructureModifier;
|
import com.comphenix.protocol.reflect.StructureModifier;
|
||||||
import com.comphenix.protocol.utility.MinecraftReflection;
|
import com.comphenix.protocol.utility.MinecraftReflection;
|
||||||
import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;
|
import com.comphenix.protocol.wrappers.EnumWrappers.NativeGameMode;
|
||||||
import com.google.common.base.Objects;
|
import com.google.common.base.Objects;
|
||||||
|
|
||||||
|
import java.lang.reflect.Constructor;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author dmulloy2
|
* @author dmulloy2
|
||||||
*/
|
*/
|
||||||
|
@ -18,12 +19,14 @@ import com.google.common.base.Objects;
|
||||||
public class PlayerInfoData {
|
public class PlayerInfoData {
|
||||||
private static Constructor<?> constructor;
|
private static Constructor<?> constructor;
|
||||||
|
|
||||||
|
protected final PacketContainer packet;
|
||||||
protected final int ping;
|
protected final int ping;
|
||||||
protected final NativeGameMode gameMode;
|
protected final NativeGameMode gameMode;
|
||||||
protected final WrappedGameProfile profile;
|
protected final WrappedGameProfile profile;
|
||||||
protected final WrappedChatComponent displayName;
|
protected final WrappedChatComponent displayName;
|
||||||
|
|
||||||
public PlayerInfoData(int ping, NativeGameMode gameMode, WrappedGameProfile profile, WrappedChatComponent displayName) {
|
public PlayerInfoData(PacketContainer packet, NativeGameMode gameMode, int ping, WrappedGameProfile profile, WrappedChatComponent displayName) {
|
||||||
|
this.packet = packet;
|
||||||
this.ping = ping;
|
this.ping = ping;
|
||||||
this.gameMode = gameMode;
|
this.gameMode = gameMode;
|
||||||
this.profile = profile;
|
this.profile = profile;
|
||||||
|
@ -57,8 +60,9 @@ public class PlayerInfoData {
|
||||||
if (constructor == null) {
|
if (constructor == null) {
|
||||||
try {
|
try {
|
||||||
constructor = MinecraftReflection.getPlayerInfoDataClass().getConstructor(
|
constructor = MinecraftReflection.getPlayerInfoDataClass().getConstructor(
|
||||||
int.class,
|
MinecraftReflection.getMinecraftClass("PacketPlayOutPlayerInfo"),
|
||||||
EnumWrappers.getGameModeClass(),
|
EnumWrappers.getGameModeClass(),
|
||||||
|
int.class,
|
||||||
MinecraftReflection.getGameProfileClass(),
|
MinecraftReflection.getGameProfileClass(),
|
||||||
MinecraftReflection.getIChatBaseComponentClass()
|
MinecraftReflection.getIChatBaseComponentClass()
|
||||||
);
|
);
|
||||||
|
@ -70,8 +74,9 @@ public class PlayerInfoData {
|
||||||
// Construct the underlying PlayerInfoData
|
// Construct the underlying PlayerInfoData
|
||||||
try {
|
try {
|
||||||
Object result = constructor.newInstance(
|
Object result = constructor.newInstance(
|
||||||
specific.ping,
|
specific.packet.getHandle(),
|
||||||
EnumWrappers.getGameModeConverter().getGeneric(EnumWrappers.getGameModeClass(), specific.gameMode),
|
EnumWrappers.getGameModeConverter().getGeneric(EnumWrappers.getGameModeClass(), specific.gameMode),
|
||||||
|
specific.ping,
|
||||||
specific.profile.handle,
|
specific.profile.handle,
|
||||||
specific.displayName.handle
|
specific.displayName.handle
|
||||||
);
|
);
|
||||||
|
@ -90,6 +95,10 @@ public class PlayerInfoData {
|
||||||
StructureModifier<Integer> ints = modifier.withType(int.class);
|
StructureModifier<Integer> ints = modifier.withType(int.class);
|
||||||
int ping = ints.read(0);
|
int ping = ints.read(0);
|
||||||
|
|
||||||
|
StructureModifier<Object> packets = modifier.withType(
|
||||||
|
MinecraftReflection.getMinecraftClass("PacketPlayOutPlayerInfo"));
|
||||||
|
Object packet = packets.read(0);
|
||||||
|
|
||||||
StructureModifier<NativeGameMode> gameModes = modifier.withType(
|
StructureModifier<NativeGameMode> gameModes = modifier.withType(
|
||||||
EnumWrappers.getGameModeClass(), EnumWrappers.getGameModeConverter());
|
EnumWrappers.getGameModeClass(), EnumWrappers.getGameModeConverter());
|
||||||
NativeGameMode gameMode = gameModes.read(0);
|
NativeGameMode gameMode = gameModes.read(0);
|
||||||
|
@ -102,7 +111,7 @@ public class PlayerInfoData {
|
||||||
MinecraftReflection.getIChatBaseComponentClass(), BukkitConverters.getWrappedChatComponentConverter());
|
MinecraftReflection.getIChatBaseComponentClass(), BukkitConverters.getWrappedChatComponentConverter());
|
||||||
WrappedChatComponent displayName = displayNames.read(0);
|
WrappedChatComponent displayName = displayNames.read(0);
|
||||||
|
|
||||||
return new PlayerInfoData(ping, gameMode, gameProfile, displayName);
|
return new PlayerInfoData(PacketContainer.fromPacket(packet), gameMode, ping, gameProfile, displayName);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, return NULL
|
// Otherwise, return NULL
|
||||||
|
|
Loading…
Reference in New Issue
Block a user