diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 00000000..dd2253bb --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,28 @@ +name: Deploy + +on: + push: + branches: + - master + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + - name: Set up JDK 1.8 + uses: actions/setup-java@v1 + with: + java-version: 8 + distribution: temurin + overwrite-settings: true + server-id: opencollab-snapshot-repo + server-username: MAVEN_USERNAME + server-password: MAVEN_PASSWORD + - name: Deploy with Maven + run: mvn deploy -B -P deploy + env: + MAVEN_USERNAME: ${{ vars.DEPLOY_USER }} + MAVEN_PASSWORD: ${{ secrets.DEPLOY_PASS }} diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index ca8e4aed..6431ded4 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -14,4 +14,4 @@ jobs: with: java-version: 1.8 - name: Build with Maven - run: mvn package --file pom.xml + run: mvn package -B diff --git a/Jenkinsfile b/Jenkinsfile index 22658a3d..ac740f80 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -12,67 +12,17 @@ pipeline { steps { sh 'mvn clean package' } - post { - success { - archiveArtifacts artifacts: 'target/*.jar', excludes: 'target/*-sources.jar', fingerprint: true - } - } } - stage ('Deploy') { - when { - branch "master" - } -pipeline { - agent any - tools { - maven 'Maven 3' - jdk 'Java 8' - } - options { - buildDiscarder(logRotator(artifactNumToKeepStr: '20')) - } - stages { - stage ('Build') { - steps { - sh 'mvn clean package' - } - post { - success { - archiveArtifacts artifacts: 'target/*.jar', excludes: 'target/*-sources.jar', fingerprint: true - } - } - } - - stage ('Deploy') { + stage ('Javadocs') { when { branch "master" } steps { - rtMavenDeployer( - id: "maven-deployer", - serverId: "opencollab-artifactory", - releaseRepo: "maven-releases", - snapshotRepo: "maven-snapshots" - ) - rtMavenResolver( - id: "maven-resolver", - serverId: "opencollab-artifactory", - releaseRepo: "maven-deploy-release", - snapshotRepo: "maven-deploy-snapshot" - ) - rtMavenRun( - pom: 'pom.xml', - goals: 'javadoc:javadoc javadoc:jar source:jar install -DskipTests', - deployerId: "maven-deployer", - resolverId: "maven-resolver" - ) - rtPublishBuildInfo( - serverId: "opencollab-artifactory" - ) + sh 'mvn javadoc:javadoc' step([$class: 'JavadocArchiver', javadocDir: 'target/site/apidocs', keepAll: false]) } } } -} \ No newline at end of file +} diff --git a/pom.xml b/pom.xml index 470f057b..6e41fefc 100644 --- a/pom.xml +++ b/pom.xml @@ -247,4 +247,23 @@ + + + + deploy + + true + + + + opencollab-release-repo + https://repo.opencollab.dev/maven-releases/ + + + opencollab-snapshot-repo + https://repo.opencollab.dev/maven-snapshots/ + + + + diff --git a/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodec.java b/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodec.java index 00d2d279..cbe25e13 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodec.java +++ b/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodec.java @@ -199,9 +199,9 @@ public class MinecraftCodec { } public static final PacketCodec CODEC = PacketCodec.builder() - .protocolVersion((1 << 30) | 120) + .protocolVersion(762) .helper(() -> new MinecraftCodecHelper(LEVEL_EVENTS, SOUND_NAMES)) - .minecraftVersion("1.19.4 Pre-release 1") + .minecraftVersion("1.19.4") .state(ProtocolState.HANDSHAKE, PacketStateCodec.builder() .registerServerboundPacket(0x00, ClientIntentionPacket.class, ClientIntentionPacket::new) ) diff --git a/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodecHelper.java b/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodecHelper.java index 3b85f310..c6cc5ec3 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodecHelper.java +++ b/src/main/java/com/github/steveice10/mc/protocol/codec/MinecraftCodecHelper.java @@ -347,7 +347,7 @@ public class MinecraftCodecHelper extends BasePacketCodecHelper { } public Component readComponent(ByteBuf buf) { - return DefaultComponentSerializer.get().deserialize(this.readString(buf)); + return DefaultComponentSerializer.get().deserialize(this.readString(buf, 262144)); } public void writeComponent(ByteBuf buf, Component component) { diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/command/CommandNode.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/command/CommandNode.java index c30f70a3..ea1be278 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/command/CommandNode.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/command/CommandNode.java @@ -5,6 +5,8 @@ import lombok.AllArgsConstructor; import lombok.Data; import lombok.NonNull; +import java.util.OptionalInt; + @Data @AllArgsConstructor public class CommandNode { @@ -24,9 +26,9 @@ public class CommandNode { private final @NonNull int[] childIndices; /** - * Redirect index, or -1 if none is set. + * Redirect index, or empty if none is set. */ - private final int redirectIndex; + private final OptionalInt redirectIndex; /** * Name of the node, if type is LITERAL or ARGUMENT. diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/recipe/data/ShapedRecipeData.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/recipe/data/ShapedRecipeData.java index 48f45c20..cf93deb4 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/recipe/data/ShapedRecipeData.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/recipe/data/ShapedRecipeData.java @@ -16,4 +16,5 @@ public class ShapedRecipeData implements RecipeData { private final @NonNull CraftingBookCategory category; private final @NonNull Ingredient[] ingredients; private final ItemStack result; + private final boolean showNotification; } diff --git a/src/main/java/com/github/steveice10/mc/protocol/data/game/scoreboard/NameTagVisibility.java b/src/main/java/com/github/steveice10/mc/protocol/data/game/scoreboard/NameTagVisibility.java index 4f8cca9e..9fc1109e 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/data/game/scoreboard/NameTagVisibility.java +++ b/src/main/java/com/github/steveice10/mc/protocol/data/game/scoreboard/NameTagVisibility.java @@ -27,7 +27,7 @@ public enum NameTagVisibility { static { for (NameTagVisibility option : values()) { - VALUES.put(option.name(), option); + VALUES.put(option.getName(), option); } } } diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundCommandsPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundCommandsPacket.java index 1b343fea..18d2b7e8 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundCommandsPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundCommandsPacket.java @@ -12,6 +12,8 @@ import lombok.Data; import lombok.NonNull; import lombok.With; +import java.util.OptionalInt; + @Data @With @AllArgsConstructor @@ -42,9 +44,11 @@ public class ClientboundCommandsPacket implements MinecraftPacket { children[j] = helper.readVarInt(in); } - int redirectIndex = 0; + OptionalInt redirectIndex; if ((flags & FLAG_REDIRECT) != 0) { - redirectIndex = helper.readVarInt(in); + redirectIndex = OptionalInt.of(helper.readVarInt(in)); + } else { + redirectIndex = OptionalInt.empty(); } String name = null; @@ -163,7 +167,7 @@ public class ClientboundCommandsPacket implements MinecraftPacket { flags |= FLAG_EXECUTABLE; } - if (node.getRedirectIndex() != 0) { + if (node.getRedirectIndex().isPresent()) { flags |= FLAG_REDIRECT; } @@ -178,8 +182,8 @@ public class ClientboundCommandsPacket implements MinecraftPacket { helper.writeVarInt(out, childIndex); } - if (node.getRedirectIndex() != 0) { - helper.writeVarInt(out, node.getRedirectIndex()); + if (node.getRedirectIndex().isPresent()) { + helper.writeVarInt(out, node.getRedirectIndex().getAsInt()); } if (node.getType() == CommandType.LITERAL || node.getType() == CommandType.ARGUMENT) { diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundUpdateRecipesPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundUpdateRecipesPacket.java index 4ac6e856..581ccbbe 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundUpdateRecipesPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundUpdateRecipesPacket.java @@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound; import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper; import com.github.steveice10.mc.protocol.codec.MinecraftPacket; -import com.github.steveice10.mc.protocol.data.game.Identifier; import com.github.steveice10.mc.protocol.data.game.entity.metadata.ItemStack; import com.github.steveice10.mc.protocol.data.game.recipe.CraftingBookCategory; import com.github.steveice10.mc.protocol.data.game.recipe.Ingredient; @@ -54,8 +53,9 @@ public class ClientboundUpdateRecipesPacket implements MinecraftPacket { } ItemStack result = helper.readItemStack(in); + boolean showNotification = in.readBoolean(); - data = new ShapedRecipeData(width, height, group, category, ingredients, result); + data = new ShapedRecipeData(width, height, group, category, ingredients, result, showNotification); break; } case SMELTING: @@ -152,6 +152,7 @@ public class ClientboundUpdateRecipesPacket implements MinecraftPacket { } helper.writeItemStack(out, data.getResult()); + out.writeBoolean(data.isShowNotification()); break; } case SMELTING: diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundUpdateTagsPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundUpdateTagsPacket.java index 80b28af3..050cd7fe 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundUpdateTagsPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundUpdateTagsPacket.java @@ -19,14 +19,14 @@ import java.util.Map; public class ClientboundUpdateTagsPacket implements MinecraftPacket { private final @NonNull Map> tags = new HashMap<>(); - public ClientboundUpdateTagsPacket(ByteBuf in, MinecraftCodecHelper helper) throws IOException { + public ClientboundUpdateTagsPacket(ByteBuf in, MinecraftCodecHelper helper) { int totalTagCount = helper.readVarInt(in); for (int i = 0; i < totalTagCount; i++) { Map tag = new HashMap<>(); - String tagName = Identifier.formalize(helper.readString(in)); + String tagName = helper.readResourceLocation(in); int tagsCount = helper.readVarInt(in); for (int j = 0; j < tagsCount; j++) { - String name = helper.readString(in); + String name = helper.readResourceLocation(in); int entriesCount = helper.readVarInt(in); int[] entries = new int[entriesCount]; for (int index = 0; index < entriesCount; index++) { @@ -40,13 +40,13 @@ public class ClientboundUpdateTagsPacket implements MinecraftPacket { } @Override - public void serialize(ByteBuf out, MinecraftCodecHelper helper) throws IOException { + public void serialize(ByteBuf out, MinecraftCodecHelper helper) { helper.writeVarInt(out, tags.size()); for (Map.Entry> tagSet : tags.entrySet()) { - helper.writeString(out, tagSet.getKey()); + helper.writeResourceLocation(out, tagSet.getKey()); helper.writeVarInt(out, tagSet.getValue().size()); for (Map.Entry tag : tagSet.getValue().entrySet()) { - helper.writeString(out, tag.getKey()); + helper.writeResourceLocation(out, tag.getKey()); helper.writeVarInt(out, tag.getValue().length); for (int id : tag.getValue()) { helper.writeVarInt(out, id); diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/level/ClientboundBlockEventPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/level/ClientboundBlockEventPacket.java index d94c017f..b98893aa 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/level/ClientboundBlockEventPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/level/ClientboundBlockEventPacket.java @@ -16,17 +16,17 @@ import org.cloudburstmc.math.vector.Vector3i; @AllArgsConstructor public class ClientboundBlockEventPacket implements MinecraftPacket { // Do we really want these hardcoded values? - private static final int NOTE_BLOCK = 93; - private static final int STICKY_PISTON = 112; - private static final int PISTON = 119; - private static final int MOB_SPAWNER = 165; - private static final int CHEST = 167; - private static final int ENDER_CHEST = 328; - private static final int TRAPPED_CHEST = 392; - private static final int END_GATEWAY = 576; - private static final int SHULKER_BOX_LOWER = 586; - private static final int SHULKER_BOX_HIGHER = 602; - private static final int BELL = 755; + private static final int NOTE_BLOCK = 101; + private static final int STICKY_PISTON = 120; + private static final int PISTON = 127; + private static final int MOB_SPAWNER = 174; + private static final int CHEST = 176; + private static final int ENDER_CHEST = 343; + private static final int TRAPPED_CHEST = 410; + private static final int END_GATEWAY = 600; + private static final int SHULKER_BOX_LOWER = 610; + private static final int SHULKER_BOX_HIGHER = 626; + private static final int BELL = 779; private final @NonNull Vector3i position; private final @NonNull BlockValueType type; diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/scoreboard/ClientboundSetPlayerTeamPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/scoreboard/ClientboundSetPlayerTeamPacket.java index d36b29a9..a9cc1198 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/scoreboard/ClientboundSetPlayerTeamPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/scoreboard/ClientboundSetPlayerTeamPacket.java @@ -2,7 +2,6 @@ package com.github.steveice10.mc.protocol.packet.ingame.clientbound.scoreboard; import com.github.steveice10.mc.protocol.codec.MinecraftCodecHelper; import com.github.steveice10.mc.protocol.codec.MinecraftPacket; -import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer; import com.github.steveice10.mc.protocol.data.game.scoreboard.CollisionRule; import com.github.steveice10.mc.protocol.data.game.scoreboard.NameTagVisibility; import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamAction; @@ -11,6 +10,7 @@ import io.netty.buffer.ByteBuf; import lombok.*; import net.kyori.adventure.text.Component; +import javax.annotation.Nullable; import java.io.IOException; import java.util.Arrays; @@ -26,8 +26,8 @@ public class ClientboundSetPlayerTeamPacket implements MinecraftPacket { private final Component suffix; private final boolean friendlyFire; private final boolean seeFriendlyInvisibles; - private final NameTagVisibility nameTagVisibility; - private final CollisionRule collisionRule; + private final @Nullable NameTagVisibility nameTagVisibility; + private final @Nullable CollisionRule collisionRule; private final TeamColor color; private final String[] players; @@ -147,8 +147,8 @@ public class ClientboundSetPlayerTeamPacket implements MinecraftPacket { if (this.action == TeamAction.CREATE || this.action == TeamAction.UPDATE) { helper.writeComponent(out, this.displayName); out.writeByte((this.friendlyFire ? 0x1 : 0x0) | (this.seeFriendlyInvisibles ? 0x2 : 0x0)); - helper.writeString(out, this.nameTagVisibility.getName()); - helper.writeString(out, this.collisionRule.getName()); + helper.writeString(out, this.nameTagVisibility == null ? "" : this.nameTagVisibility.getName()); + helper.writeString(out, this.collisionRule == null ? "" : this.collisionRule.getName()); helper.writeVarInt(out, this.color.ordinal()); helper.writeComponent(out, this.prefix); helper.writeComponent(out, this.suffix); diff --git a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/serverbound/inventory/ServerboundSeenAdvancementsPacket.java b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/serverbound/inventory/ServerboundSeenAdvancementsPacket.java index e0d2d140..584efbc1 100644 --- a/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/serverbound/inventory/ServerboundSeenAdvancementsPacket.java +++ b/src/main/java/com/github/steveice10/mc/protocol/packet/ingame/serverbound/inventory/ServerboundSeenAdvancementsPacket.java @@ -29,7 +29,7 @@ public class ServerboundSeenAdvancementsPacket implements MinecraftPacket { } /** - * @throws IllegalStateException if {@link #getAction()} is not {@link AdvancementTabAction#OPENED_TAB}. + * @throws IllegalStateException if #getAction() is not {@link AdvancementTabAction#OPENED_TAB}. */ public String getTabId() { if (this.action != AdvancementTabAction.OPENED_TAB) { diff --git a/src/test/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundCommandsPacketTest.java b/src/test/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundCommandsPacketTest.java index e4130c92..c33ec309 100644 --- a/src/test/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundCommandsPacketTest.java +++ b/src/test/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ClientboundCommandsPacketTest.java @@ -9,6 +9,8 @@ import com.github.steveice10.mc.protocol.data.game.command.properties.StringProp import com.github.steveice10.mc.protocol.packet.PacketTest; import org.junit.Before; +import java.util.OptionalInt; + public class ClientboundCommandsPacketTest extends PacketTest { @Before public void setup() { @@ -18,7 +20,7 @@ public class ClientboundCommandsPacketTest extends PacketTest { CommandType.ROOT, true, new int[]{1, 2}, - 0, + OptionalInt.empty(), null, null, null, @@ -28,7 +30,7 @@ public class ClientboundCommandsPacketTest extends PacketTest { CommandType.LITERAL, false, new int[]{3, 4}, - 0, + OptionalInt.empty(), "Literal", null, null, @@ -38,7 +40,7 @@ public class ClientboundCommandsPacketTest extends PacketTest { CommandType.ARGUMENT, false, new int[0], - 3, + OptionalInt.of(3), "Argument1", CommandParser.DOUBLE, new DoubleProperties(), @@ -48,7 +50,7 @@ public class ClientboundCommandsPacketTest extends PacketTest { CommandType.ARGUMENT, false, new int[0], - 0, + OptionalInt.empty(), "Argument2", CommandParser.DOUBLE, new DoubleProperties(0, 100), @@ -58,7 +60,7 @@ public class ClientboundCommandsPacketTest extends PacketTest { CommandType.ARGUMENT, false, new int[0], - 0, + OptionalInt.empty(), "Argument3", CommandParser.STRING, StringProperties.SINGLE_WORD, @@ -68,7 +70,7 @@ public class ClientboundCommandsPacketTest extends PacketTest { CommandType.ARGUMENT, false, new int[0], - 0, + OptionalInt.empty(), "Argument4", CommandParser.STRING, StringProperties.SINGLE_WORD, diff --git a/src/test/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ServerDeclareRecipesTest.java b/src/test/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ServerDeclareRecipesTest.java index a133c2db..4ab7d9ad 100644 --- a/src/test/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ServerDeclareRecipesTest.java +++ b/src/test/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/ServerDeclareRecipesTest.java @@ -62,7 +62,8 @@ public class ServerDeclareRecipesTest extends PacketTest { new ItemStack(6) }) }, - new ItemStack(20) + new ItemStack(20), + true ) ), new Recipe( diff --git a/src/test/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/level/ClientboundSetPlayerTeamPacketTest.java b/src/test/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/level/ClientboundSetPlayerTeamPacketTest.java new file mode 100644 index 00000000..692fa4b1 --- /dev/null +++ b/src/test/java/com/github/steveice10/mc/protocol/packet/ingame/clientbound/level/ClientboundSetPlayerTeamPacketTest.java @@ -0,0 +1,23 @@ +package com.github.steveice10.mc.protocol.packet.ingame.clientbound.level; + +import com.github.steveice10.mc.protocol.data.game.scoreboard.CollisionRule; +import com.github.steveice10.mc.protocol.data.game.scoreboard.NameTagVisibility; +import com.github.steveice10.mc.protocol.data.game.scoreboard.TeamColor; +import com.github.steveice10.mc.protocol.packet.PacketTest; +import com.github.steveice10.mc.protocol.packet.ingame.clientbound.scoreboard.ClientboundSetPlayerTeamPacket; +import net.kyori.adventure.text.Component; +import org.junit.Before; + +public class ClientboundSetPlayerTeamPacketTest extends PacketTest { + + @Before + public void setup() { + // Test nameTagVisibility and collisionRule encoding/decoding + this.setPackets( + new ClientboundSetPlayerTeamPacket("dummy", Component.empty(), Component.empty(), Component.empty(), + true, false, NameTagVisibility.NEVER, CollisionRule.PUSH_OWN_TEAM, TeamColor.RESET), + new ClientboundSetPlayerTeamPacket("dummy", Component.empty(), Component.empty(), Component.empty(), + false, true, NameTagVisibility.HIDE_FOR_OTHER_TEAMS, CollisionRule.PUSH_OTHER_TEAMS, TeamColor.RED) + ); + } +}