Move ProtocolInfo into its own field

This commit is contained in:
KennyTV 2020-06-07 12:19:36 +02:00
parent f2d6691af7
commit 529da10615
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
37 changed files with 81 additions and 66 deletions

View File

@ -17,7 +17,7 @@ public class BukkitBlockConnectionProvider extends BlockConnectionProvider {
@Override
public int getWorldBlockData(UserConnection user, int bx, int by, int bz) {
UUID uuid = user.get(ProtocolInfo.class).getUuid();
UUID uuid = user.getProtocolInfo().getUuid();
Player player = Bukkit.getPlayer(uuid);
if (player != null) {
World world = player.getWorld();

View File

@ -24,7 +24,7 @@ public class BukkitPacketHandler extends MessageToMessageEncoder {
info.setLastPacket(o);
/* This transformer is more for fixing issues which we find hard at packet level :) */
if (info.isActive()) {
if (info.get(ProtocolInfo.class).getPipeline().filter(o, list)) {
if (info.getProtocolInfo().getPipeline().filter(o, list)) {
return;
}
}

View File

@ -75,7 +75,7 @@ public class PlayerSneakListener extends ViaBukkitListener {
Player player = event.getPlayer();
UserConnection userConnection = getUserConnection(player);
if (userConnection == null) return;
ProtocolInfo info = userConnection.get(ProtocolInfo.class);
ProtocolInfo info = userConnection.getProtocolInfo();
if (info == null) return;
int protocolVersion = info.getProtocolVersion();

View File

@ -35,7 +35,7 @@ public class BukkitViaAPI implements ViaAPI<Player> {
public int getPlayerVersion(UUID uuid) {
if (!isInjected(uuid))
return getExternalVersion(Bukkit.getPlayer(uuid));
return Via.getManager().getConnection(uuid).get(ProtocolInfo.class).getProtocolVersion();
return Via.getManager().getConnection(uuid).getProtocolInfo().getProtocolVersion();
}
private int getExternalVersion(Player player) {

View File

@ -120,11 +120,11 @@ public class BukkitViaLoader implements ViaPlatformLoader {
@Override
public Item getHandItem(final UserConnection info) {
if (handItemCache != null) {
return handItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid());
return handItemCache.getHandItem(info.getProtocolInfo().getUuid());
}
try {
return Bukkit.getScheduler().callSyncMethod(Bukkit.getPluginManager().getPlugin("ViaVersion"), () -> {
UUID playerUUID = info.get(ProtocolInfo.class).getUuid();
UUID playerUUID = info.getProtocolInfo().getUuid();
Player player = Bukkit.getPlayer(playerUUID);
if (player != null) {
return HandItemCache.convert(player.getItemInHand());

View File

@ -63,7 +63,7 @@ public class BukkitInventoryQuickMoveProvider extends InventoryQuickMoveProvider
}
}
}
ProtocolInfo info = userConnection.get(ProtocolInfo.class);
ProtocolInfo info = userConnection.getProtocolInfo();
UUID uuid = info.getUuid();
BukkitInventoryUpdateTask updateTask = updateTasks.get(uuid);
final boolean registered = updateTask != null;

View File

@ -81,7 +81,7 @@ public class BukkitViaMovementTransmitter extends MovementTransmitterProvider {
@Override
public void sendPlayer(UserConnection info) {
if (USE_NMS) {
Player player = Bukkit.getPlayer(info.get(ProtocolInfo.class).getUuid());
Player player = Bukkit.getPlayer(info.getProtocolInfo().getUuid());
if (player != null) {
try {
// Tick player

View File

@ -77,13 +77,13 @@ public class BungeeServerHandler implements Listener {
}
int protocolId = ProtocolDetectorService.getProtocolId(e.getTarget().getName());
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(user.get(ProtocolInfo.class).getProtocolVersion(), protocolId);
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(user.getProtocolInfo().getProtocolVersion(), protocolId);
// Check if ViaVersion can support that version
try {
//Object pendingConnection = getPendingConnection.invoke(e.getPlayer());
Object handshake = getHandshake.invoke(e.getPlayer().getPendingConnection());
setProtocol.invoke(handshake, protocols == null ? user.get(ProtocolInfo.class).getProtocolVersion() : protocolId);
setProtocol.invoke(handshake, protocols == null ? user.getProtocolInfo().getProtocolVersion() : protocolId);
} catch (InvocationTargetException | IllegalAccessException e1) {
e1.printStackTrace();
}
@ -145,7 +145,7 @@ public class BungeeServerHandler implements Listener {
if (storage.getBossbar() != null) {
// TODO: Verify whether this packet needs to be sent when 1.8 -> 1.9 protocol isn't present in the pipeline
// This ensures we can encode it properly as only the 1.9 protocol is currently implemented.
if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9To1_8.class)) {
if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) {
for (UUID uuid : storage.getBossbar()) {
PacketWrapper wrapper = new PacketWrapper(0x0C, null, user);
wrapper.write(Type.UUID, uuid);
@ -157,12 +157,12 @@ public class BungeeServerHandler implements Listener {
}
}
ProtocolInfo info = user.get(ProtocolInfo.class);
ProtocolInfo info = user.getProtocolInfo();
int previousServerProtocol = info.getServerProtocolVersion();
// Refresh the pipes
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocolId);
ProtocolPipeline pipeline = user.get(ProtocolInfo.class).getPipeline();
ProtocolPipeline pipeline = user.getProtocolInfo().getPipeline();
user.clearStoredObjects();
pipeline.cleanPipes();
if (protocols == null) {

View File

@ -28,7 +28,7 @@ public class ElytraPatch implements Listener {
if (user == null) return;
try {
if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9To1_8.class)) {
if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) {
int entityId = user.get(EntityTracker1_9.class).getProvidedEntityId();
PacketWrapper wrapper = new PacketWrapper(0x39, null, user);

View File

@ -26,7 +26,7 @@ public class BungeeViaAPI implements ViaAPI<ProxiedPlayer> {
if (conn == null) {
return player.getPendingConnection().getVersion();
}
return conn.get(ProtocolInfo.class).getProtocolVersion();
return conn.getProtocolInfo().getProtocolVersion();
}
@Override

View File

@ -26,7 +26,7 @@ public class BungeeMainHandProvider extends MainHandProvider {
@Override
public void setMainHand(UserConnection user, int hand) {
ProtocolInfo info = user.get(ProtocolInfo.class);
ProtocolInfo info = user.getProtocolInfo();
if (info == null || info.getUuid() == null) return;
ProxiedPlayer player = ProxyServer.getInstance().getPlayer(info.getUuid());
if (player == null) return;

View File

@ -21,7 +21,7 @@ public class BungeeMovementTransmitter extends MovementTransmitterProvider {
}
public void sendPlayer(UserConnection userConnection) {
if (userConnection.get(ProtocolInfo.class).getState() == State.PLAY) {
if (userConnection.getProtocolInfo().getState() == State.PLAY) {
PacketWrapper wrapper = new PacketWrapper(0x03, null, userConnection);
wrapper.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround());
try {

View File

@ -34,7 +34,7 @@ public class BungeeVersionProvider extends VersionProvider {
List<Integer> sorted = new ArrayList<>(list);
Collections.sort(sorted);
ProtocolInfo info = user.get(ProtocolInfo.class);
ProtocolInfo info = user.getProtocolInfo();
// Bungee supports it
if (sorted.contains(info.getProtocolVersion()))

View File

@ -319,7 +319,7 @@ public class PacketWrapper {
*/
private ByteBuf constructPacket(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, Direction direction) throws Exception {
// Apply current pipeline
List<Protocol> protocols = new ArrayList<>(user().get(ProtocolInfo.class).getPipeline().pipes());
List<Protocol> protocols = new ArrayList<>(user().getProtocolInfo().getPipeline().pipes());
if (direction == Direction.OUTGOING) {
// Other way if outgoing
Collections.reverse(protocols);
@ -337,7 +337,7 @@ public class PacketWrapper {
resetReader();
// Apply other protocols
apply(direction, user().get(ProtocolInfo.class).getState(), index, protocols);
apply(direction, user().getProtocolInfo().getState(), index, protocols);
// Send
ByteBuf output = inputBuffer == null ? user().getChannel().alloc().buffer() : inputBuffer.alloc().buffer();
writeToBuffer(output);

View File

@ -35,7 +35,7 @@ public abstract class ViaListener {
protected boolean isOnPipe(UUID uuid) {
UserConnection userConnection = getUserConnection(uuid);
return userConnection != null &&
(requiredPipeline == null || userConnection.get(ProtocolInfo.class).getPipeline().contains(requiredPipeline));
(requiredPipeline == null || userConnection.getProtocolInfo().getPipeline().contains(requiredPipeline));
}
/**

View File

@ -26,6 +26,7 @@ public class UserConnection {
private static final AtomicLong IDS = new AtomicLong();
private final long id = IDS.incrementAndGet();
private final Channel channel;
private ProtocolInfo protocolInfo;
Map<Class, StoredObject> storedObjects = new ConcurrentHashMap<>();
private boolean active = true;
private boolean pendingDisconnect;
@ -193,7 +194,7 @@ public class UserConnection {
if (!channel.isOpen() || pendingDisconnect) return;
pendingDisconnect = true;
UUID uuid = get(ProtocolInfo.class).getUuid();
UUID uuid = protocolInfo.getUuid();
if (uuid == null) {
channel.close(); // Just disconnect, we don't know what the connection is
return;
@ -318,9 +319,8 @@ public class UserConnection {
if (id == PacketWrapper.PASSTHROUGH_ID) return;
PacketWrapper wrapper = new PacketWrapper(id, draft, this);
ProtocolInfo protInfo = get(ProtocolInfo.class);
try {
protInfo.getPipeline().transform(direction, protInfo.getState(), wrapper);
protocolInfo.getPipeline().transform(direction, protocolInfo.getState(), wrapper);
} catch (CancelException ex) {
throw cancelSupplier.apply(ex);
}
@ -343,6 +343,20 @@ public class UserConnection {
return channel;
}
@Nullable
public ProtocolInfo getProtocolInfo() {
return protocolInfo;
}
public void setProtocolInfo(@Nullable ProtocolInfo protocolInfo) {
this.protocolInfo = protocolInfo;
if (protocolInfo != null) {
storedObjects.put(ProtocolInfo.class, protocolInfo);
} else {
storedObjects.remove(ProtocolInfo.class);
}
}
public Map<Class, StoredObject> getStoredObjects() {
return storedObjects;
}

View File

@ -17,7 +17,7 @@ public class ViaConnectionManager {
public void onLoginSuccess(UserConnection connection) {
Objects.requireNonNull(connection, "connection is null!");
UUID id = connection.get(ProtocolInfo.class).getUuid();
UUID id = connection.getProtocolInfo().getUuid();
connections.add(connection);
clients.put(id, connection);
@ -28,7 +28,7 @@ public class ViaConnectionManager {
public void onDisconnect(UserConnection connection) {
Objects.requireNonNull(connection, "connection is null!");
UUID id = connection.get(ProtocolInfo.class).getUuid();
UUID id = connection.getProtocolInfo().getUuid();
connections.remove(connection);
clients.remove(id);
}

View File

@ -1,6 +1,7 @@
package us.myles.ViaVersion.api.protocol;
import com.google.common.base.Preconditions;
import jdk.nashorn.internal.ir.CallNode;
import org.jetbrains.annotations.Nullable;
import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.Via;
@ -422,14 +423,14 @@ public abstract class Protocol<C1 extends ClientboundPacketType, C2 extends Clie
throw e;
}
Class<? extends PacketType> packetTypeClass = direction == Direction.OUTGOING ? oldClientboundPacketEnum : newServerboundPacketEnum;
Class<? extends PacketType> packetTypeClass = state == State.PLAY ? (direction == Direction.OUTGOING ? oldClientboundPacketEnum : newServerboundPacketEnum) : null;
if (packetTypeClass != null) {
PacketType[] enumConstants = packetTypeClass.getEnumConstants();
PacketType packetType = oldId < enumConstants.length && oldId >= 0 ? enumConstants[oldId] : null;
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName() + " IN REMAP OF " + packetType + " (" + oldId + ")");
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName() + " IN REMAP OF " + packetType + " (" + toNiceHex(oldId) + ")");
} else {
Via.getPlatform().getLogger().warning("ERROR IN " + getClass().getSimpleName()
+ " IN REMAP OF 0x" + Integer.toHexString(oldId) + "->0x" + Integer.toHexString(newId));
+ " IN REMAP OF 0x" + toNiceHex(oldId) + "->0x" + toNiceHex(newId));
}
throw e;
}
@ -439,6 +440,11 @@ public abstract class Protocol<C1 extends ClientboundPacketType, C2 extends Clie
}
}
private String toNiceHex(int id) {
String hex = Integer.toHexString(id).toUpperCase();
return (hex.length() == 1 ? "0x0" : "0x") + hex;
}
/**
* @param packetType packet type
* @param isValid expression to check the packet's validity

View File

@ -37,7 +37,7 @@ public class ProtocolPipeline extends SimpleProtocol {
ProtocolInfo protocolInfo = new ProtocolInfo(userConnection);
protocolInfo.setPipeline(this);
userConnection.put(protocolInfo);
userConnection.setProtocolInfo(protocolInfo);
/* Init through all our pipes */
for (Protocol protocol : protocolList) {
@ -83,11 +83,11 @@ public class ProtocolPipeline extends SimpleProtocol {
if (Via.getManager().isDebug()) {
// Debug packet
int serverProtocol = userConnection.get(ProtocolInfo.class).getServerProtocolVersion();
int clientProtocol = userConnection.get(ProtocolInfo.class).getProtocolVersion();
int serverProtocol = userConnection.getProtocolInfo().getServerProtocolVersion();
int clientProtocol = userConnection.getProtocolInfo().getProtocolVersion();
ViaPlatform platform = Via.getPlatform();
String actualUsername = packetWrapper.user().get(ProtocolInfo.class).getUsername();
String actualUsername = packetWrapper.user().getProtocolInfo().getUsername();
String username = actualUsername != null ? actualUsername + " " : "";
platform.getLogger().log(Level.INFO, "{0}{1} {2}: {3} (0x{4}) -> {5} (0x{6}) [{7}] {8}",

View File

@ -38,7 +38,7 @@ public class BaseProtocol extends SimpleProtocol {
int protVer = wrapper.get(Type.VAR_INT, 0);
int state = wrapper.get(Type.VAR_INT, 1);
ProtocolInfo info = wrapper.user().get(ProtocolInfo.class);
ProtocolInfo info = wrapper.user().getProtocolInfo();
info.setProtocolVersion(protVer);
// Ensure the server has a version provider
if (Via.getManager().getProviders().get(VersionProvider.class) == null) {
@ -55,7 +55,7 @@ public class BaseProtocol extends SimpleProtocol {
protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocol);
}
ProtocolPipeline pipeline = wrapper.user().get(ProtocolInfo.class).getPipeline();
ProtocolPipeline pipeline = wrapper.user().getProtocolInfo().getPipeline();
if (protocols != null) {
for (Pair<Integer, Protocol> prot : protocols) {
pipeline.add(prot.getValue());

View File

@ -38,7 +38,7 @@ public class BaseProtocol1_7 extends SimpleProtocol {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ProtocolInfo info = wrapper.user().get(ProtocolInfo.class);
ProtocolInfo info = wrapper.user().getProtocolInfo();
String originalStatus = wrapper.get(Type.STRING, 0);
try {
JsonElement json = GsonUtil.getGson().fromJson(originalStatus, JsonElement.class);
@ -113,7 +113,7 @@ public class BaseProtocol1_7 extends SimpleProtocol {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ProtocolInfo info = wrapper.user().get(ProtocolInfo.class);
ProtocolInfo info = wrapper.user().getProtocolInfo();
info.setState(State.PLAY);
if (info.getServerProtocolVersion() >= ProtocolVersion.v1_16.getId()) {
@ -170,7 +170,7 @@ public class BaseProtocol1_7 extends SimpleProtocol {
handler(new PacketHandler() {
@Override
public void handle(final PacketWrapper wrapper) throws Exception {
int protocol = wrapper.user().get(ProtocolInfo.class).getProtocolVersion();
int protocol = wrapper.user().getProtocolInfo().getProtocolVersion();
if (Via.getConfig().getBlockedProtocols().contains(protocol)) {
if (!wrapper.user().getChannel().isOpen()) return;

View File

@ -2,14 +2,14 @@ package us.myles.ViaVersion.protocols.protocol1_13to1_12_2;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.storage.TabCompleteTracker;
public class TabCompleteThread implements Runnable {
@Override
public void run() {
for (UserConnection info : Via.getManager().getConnections()) {
if (info.has(ProtocolInfo.class) && info.get(ProtocolInfo.class).getPipeline().contains(Protocol1_13To1_12_2.class)) {
if (info.getProtocolInfo() == null) continue;
if (info.getProtocolInfo().getPipeline().contains(Protocol1_13To1_12_2.class)) {
if (info.getChannel().isOpen()) {
info.get(TabCompleteTracker.class).sendPacketToServer();
}

View File

@ -44,7 +44,7 @@ public abstract class AbstractFenceConnectionHandler extends ConnectionHandler {
protected byte getStates(UserConnection user, Position position, int blockState) {
byte states = 0;
boolean pre1_12 = user.get(ProtocolInfo.class).getServerProtocolVersion() < ProtocolVersion.v1_12.getId();
boolean pre1_12 = user.getProtocolInfo().getServerProtocolVersion() < ProtocolVersion.v1_12.getId();
if (connects(BlockFace.EAST, getBlockData(user, position.getRelative(BlockFace.EAST)), pre1_12)) states |= 1;
if (connects(BlockFace.NORTH, getBlockData(user, position.getRelative(BlockFace.NORTH)), pre1_12)) states |= 2;
if (connects(BlockFace.SOUTH, getBlockData(user, position.getRelative(BlockFace.SOUTH)), pre1_12)) states |= 4;

View File

@ -41,7 +41,7 @@ public class GlassConnectionHandler extends AbstractFenceConnectionHandler {
byte states = super.getStates(user, position, blockState);
if (states != 0) return states;
ProtocolInfo protocolInfo = user.get(ProtocolInfo.class);
ProtocolInfo protocolInfo = user.getProtocolInfo();
return protocolInfo.getServerProtocolVersion() <= 47
&& protocolInfo.getServerProtocolVersion() != -1 ? 0xF : states;
}

View File

@ -11,7 +11,6 @@ import us.myles.ViaVersion.api.type.PartialType;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.api.type.types.minecraft.BaseChunkType;
import us.myles.ViaVersion.api.type.types.version.Types1_9;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_10to1_9_3.Protocol1_10To1_9_3_4;
import us.myles.ViaVersion.protocols.protocol1_9_3to1_9_1_2.storage.ClientWorld;
@ -26,7 +25,7 @@ public class Chunk1_9_1_2Type extends PartialType<Chunk, ClientWorld> {
@Override
public Chunk read(ByteBuf input, ClientWorld world) throws Exception {
boolean replacePistons = world.getUser().get(ProtocolInfo.class).getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons();
boolean replacePistons = world.getUser().getProtocolInfo().getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons();
int replacementId = Via.getConfig().getPistonReplacementId();
int chunkX = input.readInt();

View File

@ -10,7 +10,7 @@ public class ViaIdleThread implements Runnable {
@Override
public void run() {
for (UserConnection info : Via.getManager().getConnections()) {
ProtocolInfo protocolInfo = info.get(ProtocolInfo.class);
ProtocolInfo protocolInfo = info.getProtocolInfo();
if (protocolInfo != null && protocolInfo.getPipeline().contains(Protocol1_9To1_8.class)) {
long nextIdleUpdate = info.get(MovementTracker.class).getNextIdlePacket();
if (nextIdleUpdate <= System.currentTimeMillis()) {

View File

@ -126,7 +126,7 @@ public class PlayerPackets {
if (mode == 0 || mode == 3 || mode == 4) {
String[] players = wrapper.passthrough(Type.STRING_ARRAY); // Players
final EntityTracker1_9 entityTracker = wrapper.user().get(EntityTracker1_9.class);
String myName = wrapper.user().get(ProtocolInfo.class).getUsername();
String myName = wrapper.user().getProtocolInfo().getUsername();
String teamName = wrapper.get(Type.STRING, 0);
for (String player : players) {
if (entityTracker.isAutoTeam() && player.equalsIgnoreCase(myName)) {

View File

@ -191,7 +191,7 @@ public class EntityTracker1_9 extends EntityTracker {
}
}
}
UUID uuid = getUser().get(ProtocolInfo.class).getUuid();
UUID uuid = getUser().getProtocolInfo().getUuid();
// Boss bar
if (Via.getConfig().isBossbarPatch()) {
if (type == EntityType.ENDER_DRAGON || type == EntityType.WITHER) {
@ -256,7 +256,7 @@ public class EntityTracker1_9 extends EntityTracker {
} else {
wrapper.write(Type.BYTE, (byte) 3);
}
wrapper.write(Type.STRING_ARRAY, new String[]{getUser().get(ProtocolInfo.class).getUsername()});
wrapper.write(Type.STRING_ARRAY, new String[]{getUser().getProtocolInfo().getUsername()});
} else {
wrapper.write(Type.BYTE, (byte) 1); // remove team
}
@ -283,7 +283,7 @@ public class EntityTracker1_9 extends EntityTracker {
PacketWrapper wrapper = new PacketWrapper(0x39, null, getUser());
wrapper.write(Type.VAR_INT, entityId);
wrapper.write(Types1_9.METADATA_LIST, metadataList);
getUser().get(ProtocolInfo.class).getPipeline().getProtocol(Protocol1_9To1_8.class).get(MetadataRewriter1_9To1_8.class)
getUser().getProtocolInfo().getPipeline().getProtocol(Protocol1_9To1_8.class).get(MetadataRewriter1_9To1_8.class)
.handleMetadata(entityId, metadataList, getUser());
handleMetadata(entityId, metadataList);
if (!metadataList.isEmpty()) {

View File

@ -48,7 +48,7 @@ public class Chunk1_9to1_8Type extends PartialType<Chunk, ClientChunks> {
@Override
public Chunk read(ByteBuf input, ClientChunks param) throws Exception {
boolean replacePistons = param.getUser().get(ProtocolInfo.class).getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons();
boolean replacePistons = param.getUser().getProtocolInfo().getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons();
int replacementId = Via.getConfig().getPistonReplacementId();
int chunkX = input.readInt();

View File

@ -24,7 +24,7 @@ public class SpongePacketHandler extends MessageToMessageEncoder {
info.setLastPacket(o);
/* This transformer is more for fixing issues which we find hard at packet level :) */
if (info.isActive()) {
if (info.get(ProtocolInfo.class).getPipeline().filter(o, list)) {
if (info.getProtocolInfo().getPipeline().filter(o, list)) {
return;
}
}

View File

@ -26,7 +26,7 @@ public class SpongeViaAPI implements ViaAPI<Player> {
public int getPlayerVersion(UUID uuid) {
if (!isInjected(uuid))
return ProtocolRegistry.SERVER_PROTOCOL;
return Via.getManager().getConnection(uuid).get(ProtocolInfo.class).getProtocolVersion();
return Via.getManager().getConnection(uuid).getProtocolInfo().getProtocolVersion();
}
@Override

View File

@ -76,7 +76,7 @@ public class SpongeViaLoader implements ViaPlatformLoader {
@Override
public Item getHandItem(final UserConnection info) {
if (HandItemCache.CACHE) {
return HandItemCache.getHandItem(info.get(ProtocolInfo.class).getUuid());
return HandItemCache.getHandItem(info.getProtocolInfo().getUuid());
} else {
return super.getHandItem(info);
}

View File

@ -26,8 +26,6 @@ import java.util.Collection;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.Semaphore;
import java.util.concurrent.TimeUnit;
public class VelocityServerHandler {
private static Method setProtocolVersion;
@ -62,12 +60,12 @@ public class VelocityServerHandler {
}
int protocolId = ProtocolDetectorService.getProtocolId(e.getOriginalServer().getServerInfo().getName());
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(user.get(ProtocolInfo.class).getProtocolVersion(), protocolId);
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(user.getProtocolInfo().getProtocolVersion(), protocolId);
// Check if ViaVersion can support that version
Object connection = getMinecraftConnection.invoke(e.getPlayer());
setNextProtocolVersion.invoke(connection, ProtocolVersion.getProtocolVersion(protocols == null
? user.get(ProtocolInfo.class).getProtocolVersion()
? user.getProtocolInfo().getProtocolVersion()
: protocolId));
} catch (IllegalAccessException | InvocationTargetException e1) {
@ -105,7 +103,7 @@ public class VelocityServerHandler {
if (storage.getBossbar() != null) {
// TODO: Verify whether this packet needs to be sent when 1.8 -> 1.9 protocol isn't present in the pipeline
// This ensures we can encode it properly as only the 1.9 protocol is currently implemented.
if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9To1_8.class)) {
if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) {
for (UUID uuid : storage.getBossbar()) {
PacketWrapper wrapper = new PacketWrapper(0x0C, null, user);
wrapper.write(Type.UUID, uuid);
@ -117,12 +115,12 @@ public class VelocityServerHandler {
}
}
ProtocolInfo info = user.get(ProtocolInfo.class);
ProtocolInfo info = user.getProtocolInfo();
int previousServerProtocol = info.getServerProtocolVersion();
// Refresh the pipes
List<Pair<Integer, Protocol>> protocols = ProtocolRegistry.getProtocolPath(info.getProtocolVersion(), protocolId);
ProtocolPipeline pipeline = user.get(ProtocolInfo.class).getPipeline();
ProtocolPipeline pipeline = info.getPipeline();
user.clearStoredObjects();
pipeline.cleanPipes();
if (protocols == null) {

View File

@ -27,7 +27,7 @@ public class ElytraPatch {
if (user == null) return;
try {
if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9To1_8.class)) {
if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) {
int entityId = user.get(EntityTracker1_9.class).getProvidedEntityId();
PacketWrapper wrapper = new PacketWrapper(0x39, null, user);

View File

@ -22,7 +22,7 @@ public class VelocityViaAPI implements ViaAPI<Player> {
public int getPlayerVersion(Player player) {
if (!isInjected(player.getUniqueId()))
return player.getProtocolVersion().getProtocol();
return Via.getManager().getConnection(player.getUniqueId()).get(ProtocolInfo.class).getProtocolVersion();
return Via.getManager().getConnection(player.getUniqueId()).getProtocolInfo().getProtocolVersion();
}
@Override

View File

@ -4,7 +4,6 @@ import us.myles.ViaVersion.api.PacketWrapper;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.type.Type;
import us.myles.ViaVersion.packets.State;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.Protocol1_9To1_8;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.providers.MovementTransmitterProvider;
import us.myles.ViaVersion.protocols.protocol1_9to1_8.storage.MovementTracker;
@ -21,7 +20,7 @@ public class VelocityMovementTransmitter extends MovementTransmitterProvider {
}
public void sendPlayer(UserConnection userConnection) {
if (userConnection.get(ProtocolInfo.class).getState() == State.PLAY) {
if (userConnection.getProtocolInfo().getState() == State.PLAY) {
PacketWrapper wrapper = new PacketWrapper(0x03, null, userConnection);
wrapper.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround());
try {

View File

@ -4,7 +4,6 @@ import us.myles.ViaVersion.VelocityPlugin;
import us.myles.ViaVersion.api.Via;
import us.myles.ViaVersion.api.data.UserConnection;
import us.myles.ViaVersion.api.protocol.ProtocolVersion;
import us.myles.ViaVersion.protocols.base.ProtocolInfo;
import us.myles.ViaVersion.protocols.base.VersionProvider;
import us.myles.ViaVersion.velocity.platform.VelocityViaInjector;
@ -15,7 +14,7 @@ public class VelocityVersionProvider extends VersionProvider {
@Override
public int getServerProtocol(UserConnection user) throws Exception {
int playerVersion = user.get(ProtocolInfo.class).getProtocolVersion();
int playerVersion = user.getProtocolInfo().getProtocolVersion();
IntStream versions = com.velocitypowered.api.network.ProtocolVersion.SUPPORTED_VERSIONS.stream()
.mapToInt(com.velocitypowered.api.network.ProtocolVersion::getProtocol);