Skip to content

Commit

Permalink
Update for CloudburstMC/Protocol v3 and MCBE 1.19.80
Browse files Browse the repository at this point in the history
  • Loading branch information
Crasher508 committed Jun 2, 2023
1 parent dfea0bc commit cfeb934
Show file tree
Hide file tree
Showing 48 changed files with 305 additions and 271 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

- Java 11
- Minecraft: Java Edition v1.19.1/1.19.2
- Bedrock Edition server v1.19.50
- Bedrock Edition server v1.19.80

## Need implemented

Expand Down
30 changes: 19 additions & 11 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,32 @@

<repositories>
<repository>
<id>nukkitx-repo-release</id>
<url>https://repo.nukkitx.com/maven-releases/</url>
<id>opencollab-repo-release</id>
<url>https://repo.opencollab.dev/maven-releases/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>nukkitx-repo-snapshot</id>
<url>https://repo.nukkitx.com/maven-snapshots/</url>
</repository>
<repository>
<id>opencollab</id>
<id>opencollab-repo-snapshot</id>
<url>https://repo.opencollab.dev/maven-snapshots/</url>
<releases>
<enabled>false</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>

<dependencies>
<dependency>
<groupId>com.nukkitx.protocol</groupId>
<artifactId>bedrock-v567</artifactId>
<version>2.9.17-SNAPSHOT</version>
<groupId>org.cloudburstmc.protocol</groupId>
<artifactId>bedrock-connection</artifactId>
<version>3.0.0.Beta1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand All @@ -44,7 +52,7 @@
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>fastjson</artifactId>
<version>2.0.25</version>
<version>2.0.32</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/barrelmc/barrel/math/Vector3.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.barrelmc.barrel.math;

import com.nukkitx.math.GenericMath;
import com.nukkitx.math.vector.Vector3f;
import lombok.Getter;
import lombok.Setter;
import org.cloudburstmc.math.GenericMath;
import org.cloudburstmc.math.vector.Vector3f;

public class Vector3 {

Expand Down
19 changes: 7 additions & 12 deletions src/main/java/org/barrelmc/barrel/network/BedrockBatchHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@

package org.barrelmc.barrel.network;

import com.nukkitx.protocol.bedrock.BedrockPacket;
import com.nukkitx.protocol.bedrock.BedrockSession;
import com.nukkitx.protocol.bedrock.handler.BatchHandler;
import io.netty.buffer.ByteBuf;
import org.barrelmc.barrel.player.Player;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacketHandler;
import org.cloudburstmc.protocol.common.PacketSignal;

import java.util.Collection;

public class BedrockBatchHandler implements BatchHandler {
public class BedrockBatchHandler implements BedrockPacketHandler {

private final Player player;

Expand All @@ -22,10 +19,8 @@ public BedrockBatchHandler(Player player) {
}

@Override
public void handle(BedrockSession bedrockSession, ByteBuf byteBuf, Collection<BedrockPacket> collection) {
for (BedrockPacket packet : collection) {
//System.out.println("Received Bedrock " + packet.toString());
player.getPacketTranslatorManager().translate(packet);
}
public PacketSignal handlePacket(BedrockPacket packet) {
player.getPacketTranslatorManager().translate(packet);
return PacketSignal.HANDLED;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.inventory.ServerboundSeenAdvancementsPacket;
import com.github.steveice10.mc.protocol.packet.ingame.serverbound.player.*;
import com.github.steveice10.packetlib.packet.Packet;
import com.nukkitx.protocol.bedrock.BedrockPacket;
import com.nukkitx.protocol.bedrock.packet.*;
import org.cloudburstmc.protocol.bedrock.packet.*;
import lombok.Getter;
import org.barrelmc.barrel.network.translator.interfaces.BedrockPacketTranslator;
import org.barrelmc.barrel.network.translator.interfaces.JavaPacketTranslator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
package org.barrelmc.barrel.network.translator;

import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.nukkitx.protocol.bedrock.data.GameType;
import org.cloudburstmc.protocol.bedrock.data.GameType;

public class TranslatorUtils {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,26 @@
import com.github.steveice10.mc.protocol.data.game.entity.player.GameMode;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.ClientboundPlayerInfoPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.spawn.ClientboundAddPlayerPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.BedrockPacket;
import com.nukkitx.protocol.bedrock.data.entity.EntityData;
import net.kyori.adventure.text.Component;
import org.barrelmc.barrel.network.translator.interfaces.BedrockPacketTranslator;
import org.barrelmc.barrel.player.Player;
import org.barrelmc.barrel.utils.Utils;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.data.entity.EntityDataTypes;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;

public class AddPlayerPacket implements BedrockPacketTranslator {

@Override
public void translate(BedrockPacket pk, Player player) {
com.nukkitx.protocol.bedrock.packet.AddPlayerPacket packet = (com.nukkitx.protocol.bedrock.packet.AddPlayerPacket) pk;
org.cloudburstmc.protocol.bedrock.packet.AddPlayerPacket packet = (org.cloudburstmc.protocol.bedrock.packet.AddPlayerPacket) pk;

Vector3f position = packet.getPosition();
Vector3f rotation = packet.getRotation();

GameProfile gameProfile = new GameProfile(packet.getUuid(), Utils.lengthCutter(packet.getUsername(), 16));

player.getJavaSession().send(new ClientboundPlayerInfoPacket(PlayerListEntryAction.ADD_PLAYER, new PlayerListEntry[]{new PlayerListEntry(gameProfile, GameMode.SURVIVAL, 10, Component.text(Utils.lengthCutter(packet.getMetadata().getString(EntityData.NAMETAG), 16)), 0L, null, null)}));
player.getJavaSession().send(new ClientboundPlayerInfoPacket(PlayerListEntryAction.ADD_PLAYER, new PlayerListEntry[]{new PlayerListEntry(gameProfile, GameMode.SURVIVAL, 10, Component.text(Utils.lengthCutter(packet.getMetadata().get(EntityDataTypes.NAME), 16)), 0L, null, null)}));
player.getJavaSession().send(new ClientboundAddPlayerPacket((int) packet.getRuntimeEntityId(), packet.getUuid(), position.getX(), position.getY(), position.getZ(), rotation.getY(), rotation.getX()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@

import com.github.steveice10.mc.protocol.data.game.entity.player.Animation;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundAnimatePacket;
import com.nukkitx.protocol.bedrock.BedrockPacket;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;
import org.barrelmc.barrel.network.translator.interfaces.BedrockPacketTranslator;
import org.barrelmc.barrel.player.Player;

public class AnimatePacket implements BedrockPacketTranslator {

@Override
public void translate(BedrockPacket pk, Player player) {
com.nukkitx.protocol.bedrock.packet.AnimatePacket packet = (com.nukkitx.protocol.bedrock.packet.AnimatePacket) pk;
org.cloudburstmc.protocol.bedrock.packet.AnimatePacket packet = (org.cloudburstmc.protocol.bedrock.packet.AnimatePacket) pk;

switch (packet.getAction()) {
case SWING_ARM: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@
import com.github.steveice10.mc.protocol.data.game.level.block.value.ChestValueType;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundBlockEventPacket;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.BedrockPacket;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;
import org.barrelmc.barrel.network.translator.interfaces.BedrockPacketTranslator;
import org.barrelmc.barrel.player.Player;

public class BlockEventPacket implements BedrockPacketTranslator {

@Override
public void translate(BedrockPacket pk, Player player) {
com.nukkitx.protocol.bedrock.packet.BlockEventPacket packet = (com.nukkitx.protocol.bedrock.packet.BlockEventPacket) pk;
org.cloudburstmc.protocol.bedrock.packet.BlockEventPacket packet = (org.cloudburstmc.protocol.bedrock.packet.BlockEventPacket) pk;

if (packet.getEventType() == 1) {
Vector3i pos = packet.getBlockPosition();
Vector3i pos = Vector3i.from(packet.getBlockPosition().getX(), packet.getBlockPosition().getY(), packet.getBlockPosition().getZ());
if (packet.getEventData() == 2) {
player.getJavaSession().send(new ClientboundBlockEventPacket(pos, ChestValueType.VIEWING_PLAYER_COUNT, new ChestValue(1), 54));
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.barrelmc.barrel.network.translator.bedrock;

import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.protocol.bedrock.BedrockPacket;
import com.nukkitx.protocol.bedrock.data.PlayerActionType;
import com.nukkitx.protocol.bedrock.packet.PlayerActionPacket;
import org.cloudburstmc.math.vector.Vector3i;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;
import org.cloudburstmc.protocol.bedrock.data.PlayerActionType;
import org.cloudburstmc.protocol.bedrock.packet.PlayerActionPacket;
import org.barrelmc.barrel.network.translator.interfaces.BedrockPacketTranslator;
import org.barrelmc.barrel.player.Player;

Expand All @@ -17,6 +17,6 @@ public void translate(BedrockPacket pk, Player player) {
playerActionPacket.setResultPosition(Vector3i.ZERO);
playerActionPacket.setFace(0);
playerActionPacket.setRuntimeEntityId(player.getRuntimeEntityId());
player.getBedrockClient().getSession().sendPacket(playerActionPacket);
player.getBedrockClientSession().sendPacket(playerActionPacket);
}
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package org.barrelmc.barrel.network.translator.bedrock;

import com.nukkitx.protocol.bedrock.BedrockPacket;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;
import org.barrelmc.barrel.network.translator.interfaces.BedrockPacketTranslator;
import org.barrelmc.barrel.player.Player;

public class DisconnectPacket implements BedrockPacketTranslator {

@Override
public void translate(BedrockPacket pk, Player player) {
com.nukkitx.protocol.bedrock.packet.DisconnectPacket packet = (com.nukkitx.protocol.bedrock.packet.DisconnectPacket) pk;
org.cloudburstmc.protocol.bedrock.packet.DisconnectPacket packet = (org.cloudburstmc.protocol.bedrock.packet.DisconnectPacket) pk;

player.disconnect(packet.getKickMessage());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,6 @@
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundLevelChunkWithLightPacket;
import com.github.steveice10.opennbt.tag.builtin.CompoundTag;
import com.github.steveice10.opennbt.tag.builtin.LongArrayTag;
import com.nukkitx.nbt.NBTInputStream;
import com.nukkitx.nbt.NbtMap;
import com.nukkitx.nbt.NbtMapBuilder;
import com.nukkitx.nbt.util.stream.NetworkDataInputStream;
import com.nukkitx.network.VarInts;
import com.nukkitx.protocol.bedrock.BedrockPacket;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufInputStream;
import io.netty.buffer.Unpooled;
Expand All @@ -22,6 +16,12 @@
import org.barrelmc.barrel.utils.Utils;
import org.barrelmc.barrel.utils.nukkit.BitArray;
import org.barrelmc.barrel.utils.nukkit.BitArrayVersion;
import org.cloudburstmc.nbt.NBTInputStream;
import org.cloudburstmc.nbt.NbtMap;
import org.cloudburstmc.nbt.NbtMapBuilder;
import org.cloudburstmc.nbt.util.stream.NetworkDataInputStream;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;
import org.cloudburstmc.protocol.common.util.VarInts;

import java.io.IOException;
import java.util.BitSet;
Expand All @@ -31,7 +31,7 @@ public class LevelChunkPacket implements BedrockPacketTranslator {

@Override
public void translate(BedrockPacket pk, Player player) {
com.nukkitx.protocol.bedrock.packet.LevelChunkPacket packet = (com.nukkitx.protocol.bedrock.packet.LevelChunkPacket) pk;
org.cloudburstmc.protocol.bedrock.packet.LevelChunkPacket packet = (org.cloudburstmc.protocol.bedrock.packet.LevelChunkPacket) pk;

int subChunksLength = packet.getSubChunksLength();
ChunkSection[] chunkSections = new ChunkSection[subChunksLength];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@
import com.github.steveice10.mc.protocol.data.game.entity.player.BlockBreakStage;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.level.ClientboundBlockDestructionPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.BedrockPacket;
import com.nukkitx.protocol.bedrock.data.LevelEventType;
import org.cloudburstmc.protocol.bedrock.data.LevelEvent;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;
import org.barrelmc.barrel.network.translator.interfaces.BedrockPacketTranslator;
import org.barrelmc.barrel.player.Player;

public class LevelEventPacket implements BedrockPacketTranslator {

@Override
public void translate(BedrockPacket pk, Player player) {
com.nukkitx.protocol.bedrock.packet.LevelEventPacket packet = (com.nukkitx.protocol.bedrock.packet.LevelEventPacket) pk;
org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket packet = (org.cloudburstmc.protocol.bedrock.packet.LevelEventPacket) pk;

if (packet.getType() == LevelEventType.BLOCK_START_BREAK) {
Vector3f pos = packet.getPosition();
if (packet.getType() == LevelEvent.BLOCK_START_BREAK) {
Vector3f pos = Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ());
player.getJavaSession().send(new ClientboundBlockDestructionPacket(0, pos.toInt(), BlockBreakStage.STAGE_1));
} else if (packet.getType() == LevelEventType.BLOCK_STOP_BREAK) {
Vector3f pos = packet.getPosition();
} else if (packet.getType() == LevelEvent.BLOCK_STOP_BREAK) {
Vector3f pos = Vector3f.from(packet.getPosition().getX(), packet.getPosition().getY(), packet.getPosition().getZ());
player.getJavaSession().send(new ClientboundBlockDestructionPacket(0, pos.toInt(), BlockBreakStage.RESET));
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundRotateHeadPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundTeleportEntityPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.BedrockPacket;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;
import org.barrelmc.barrel.network.translator.interfaces.BedrockPacketTranslator;
import org.barrelmc.barrel.player.Player;

public class MoveEntityAbsolutePacket implements BedrockPacketTranslator {

@Override
public void translate(BedrockPacket pk, Player player) {
com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket packet = (com.nukkitx.protocol.bedrock.packet.MoveEntityAbsolutePacket) pk;
org.cloudburstmc.protocol.bedrock.packet.MoveEntityAbsolutePacket packet = (org.cloudburstmc.protocol.bedrock.packet.MoveEntityAbsolutePacket) pk;
Vector3f position = packet.getPosition(), rotation = packet.getRotation();

player.getJavaSession().send(new ClientboundTeleportEntityPacket((int) packet.getRuntimeEntityId(), position.getX(), position.getY() - 1.62F, position.getZ(), rotation.getY(), rotation.getX(), packet.isOnGround()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundRotateHeadPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.ClientboundTeleportEntityPacket;
import com.github.steveice10.mc.protocol.packet.ingame.clientbound.entity.player.ClientboundPlayerPositionPacket;
import com.nukkitx.math.vector.Vector3f;
import com.nukkitx.protocol.bedrock.BedrockPacket;
import org.cloudburstmc.math.vector.Vector3f;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;
import org.barrelmc.barrel.network.translator.interfaces.BedrockPacketTranslator;
import org.barrelmc.barrel.player.Player;

public class MovePlayerPacket implements BedrockPacketTranslator {

@Override
public void translate(BedrockPacket pk, Player player) {
com.nukkitx.protocol.bedrock.packet.MovePlayerPacket packet = (com.nukkitx.protocol.bedrock.packet.MovePlayerPacket) pk;
org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket packet = (org.cloudburstmc.protocol.bedrock.packet.MovePlayerPacket) pk;
Vector3f position = packet.getPosition(), rotation = packet.getRotation();

if (packet.getRuntimeEntityId() == player.getRuntimeEntityId()) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
package org.barrelmc.barrel.network.translator.bedrock;

import com.nukkitx.protocol.bedrock.BedrockPacket;
import org.cloudburstmc.protocol.bedrock.packet.BedrockPacket;
import org.barrelmc.barrel.network.translator.interfaces.BedrockPacketTranslator;
import org.barrelmc.barrel.player.Player;
import org.barrelmc.barrel.server.ProxyServer;

public class NetworkSettingsPacket implements BedrockPacketTranslator {
@Override
public void translate(BedrockPacket pk, Player player) {
com.nukkitx.protocol.bedrock.packet.NetworkSettingsPacket packet = (com.nukkitx.protocol.bedrock.packet.NetworkSettingsPacket) pk;
player.getBedrockClient().getSession().setCompression(packet.getCompressionAlgorithm());
org.cloudburstmc.protocol.bedrock.packet.NetworkSettingsPacket packet = (org.cloudburstmc.protocol.bedrock.packet.NetworkSettingsPacket) pk;
player.getBedrockClientSession().setCompression(packet.getCompressionAlgorithm());

if (ProxyServer.getInstance().getConfig().getAuth().equals("offline")) {
player.getBedrockClient().getSession().sendPacketImmediately(player.getLoginPacket());
} else {
try {
player.getBedrockClient().getSession().sendPacketImmediately(player.getOnlineLoginPacket());
} catch (Exception e) {
e.printStackTrace();
try {
if (ProxyServer.getInstance().getConfig().getAuth().equals("offline")) {
player.getBedrockClientSession().sendPacketImmediately(player.getLoginPacket());
} else {
player.getBedrockClientSession().sendPacketImmediately(player.getOnlineLoginPacket());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
Loading

0 comments on commit cfeb934

Please sign in to comment.