Skip to content

Commit

Permalink
Updated VV API usage
Browse files Browse the repository at this point in the history
  • Loading branch information
RaphiMC committed Aug 21, 2024
1 parent 57e4feb commit 5df783b
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 28 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ repositories {
}

dependencies {
compileOnly "com.viaversion:viaversion-common:5.0.2-SNAPSHOT"
compileOnly "com.viaversion:viaversion-common:5.0.4-SNAPSHOT"
compileOnly "org.yaml:snakeyaml:2.2"
compileOnly "com.google.guava:guava:33.3.0-jre"
compileOnly "io.netty:netty-handler:4.1.112.Final"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,13 @@
*/
package net.raphimc.viabedrock.api.protocol;

import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.protocol.AbstractSimpleProtocol;
import com.viaversion.viaversion.api.protocol.packet.State;
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.base.ServerboundHandshakePackets;
import com.viaversion.viaversion.protocols.base.ServerboundLoginPackets;
import com.viaversion.viaversion.protocols.base.v1_7.ServerboundBaseProtocol1_7;
import net.raphimc.viabedrock.protocol.storage.HandshakeStorage;

public class BedrockBaseProtocol extends AbstractSimpleProtocol {
public class BedrockBaseProtocol extends ServerboundBaseProtocol1_7 {

public static final BedrockBaseProtocol INSTANCE = new BedrockBaseProtocol();

Expand All @@ -35,6 +33,7 @@ private BedrockBaseProtocol() {

@Override
protected void registerPackets() {
super.registerPackets();
this.registerServerbound(State.HANDSHAKE, ServerboundHandshakePackets.CLIENT_INTENTION.getId(), -1, wrapper -> {
wrapper.cancel();
final int protocolVersion = wrapper.read(Types.VAR_INT); // protocol id
Expand All @@ -43,17 +42,6 @@ protected void registerPackets() {

wrapper.user().put(new HandshakeStorage(protocolVersion, hostname, port));
});

// Copied from BaseProtocol1_7
this.registerServerbound(State.LOGIN, ServerboundLoginPackets.LOGIN_ACKNOWLEDGED.getId(), ServerboundLoginPackets.LOGIN_ACKNOWLEDGED.getId(), wrapper -> {
final ProtocolInfo info = wrapper.user().getProtocolInfo();
info.setState(State.CONFIGURATION);
});
}

@Override
public boolean isBaseProtocol() {
return true;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,10 @@
*/
package net.raphimc.viabedrock.protocol.packet;

import com.google.common.base.Joiner;
import com.vdurmont.semver4j.Semver;
import com.viaversion.nbt.tag.CompoundTag;
import com.viaversion.nbt.tag.IntArrayTag;
import com.viaversion.nbt.tag.Tag;
import com.viaversion.viaversion.api.Via;
import com.viaversion.viaversion.api.connection.ProtocolInfo;
import com.viaversion.viaversion.api.connection.UserConnection;
import com.viaversion.viaversion.api.minecraft.RegistryEntry;
Expand All @@ -34,6 +32,7 @@
import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.libs.fastutil.ints.IntIntImmutablePair;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.protocols.base.v1_7.ClientboundBaseProtocol1_7;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21;
import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21;
import net.raphimc.viabedrock.ViaBedrock;
Expand Down Expand Up @@ -135,8 +134,8 @@ public static void register(final BedrockProtocol protocol) {
}

if (status == PlayStatus.LoginSuccess) {
wrapper.setPacketType(ClientboundLoginPackets.GAME_PROFILE);
final AuthChainData authChainData = wrapper.user().get(AuthChainData.class);
wrapper.setPacketType(ClientboundLoginPackets.GAME_PROFILE);
wrapper.write(Types.UUID, authChainData.getIdentity()); // uuid
wrapper.write(Types.STRING, authChainData.getDisplayName()); // username
wrapper.write(Types.VAR_INT, 0); // properties length
Expand All @@ -145,15 +144,7 @@ public static void register(final BedrockProtocol protocol) {
final ProtocolInfo info = wrapper.user().getProtocolInfo();
info.setUsername(authChainData.getDisplayName());
info.setUuid(authChainData.getIdentity());

// Parts of BaseProtocol1_7 GAME_PROFILE handler
Via.getManager().getConnectionManager().onLoginSuccess(wrapper.user());
if (!info.getPipeline().hasNonBaseProtocols()) {
wrapper.user().setActive(false);
}
if (Via.getManager().isDebug()) {
ViaBedrock.getPlatform().getLogger().log(Level.INFO, "{0} logged in with protocol {1}, Route: {2}", new Object[]{info.getUsername(), info.protocolVersion().getName(), Joiner.on(", ").join(info.getPipeline().pipes(), ", ")});
}
ClientboundBaseProtocol1_7.onLoginSuccess(wrapper.user());

sendClientCacheStatus(wrapper.user());
} else {
Expand Down

0 comments on commit 5df783b

Please sign in to comment.