Skip to content

Commit

Permalink
Migrate to gradle, java 17 and fix examples
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexProgrammerDE committed Dec 11, 2023
1 parent 7123bf9 commit 0f28b75
Show file tree
Hide file tree
Showing 22 changed files with 587 additions and 326 deletions.
39 changes: 39 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Java CI with Gradle

on: [push, pull_request]

jobs:
build:
# Only run on PRs if the source branch is on someone else's repo
if: "${{ github.event_name != 'pull_request' || github.repository != github.event.pull_request.head.repo.full_name }}"

runs-on: ubuntu-latest

steps:
- name: Checkout repository
# See https://github.com/actions/checkout/commits
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac

- name: Validate Gradle wrapper
# See https://github.com/gradle/wrapper-validation-action/commits
uses: gradle/wrapper-validation-action@342dbebe7272035434f9baccc29a816ec6dd2c7b

- name: Cache Gradle packages
uses: actions/cache@v3
with:
path: |
~/.gradle/caches
~/.gradle/wrapper
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Set up JDK 17
# See https://github.com/actions/setup-java/commits
uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0
with:
java-version: 17
distribution: temurin

- name: Build with Gradle
run: ./gradlew build
4 changes: 2 additions & 2 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ jobs:
# See https://github.com/actions/checkout/commits
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac

- name: Set up JDK 1.8
- name: Set up JDK 17
# See https://github.com/actions/setup-java/commits
uses: actions/setup-java@0ab4596768b603586c0de567f2430c30f5b0d2b0
with:
java-version: 8
java-version: 17
distribution: temurin

- uses: s4u/maven-settings-action@60912582505985be4cc55d2b890eb32767f8de5f
Expand Down
23 changes: 0 additions & 23 deletions .github/workflows/maven.yml

This file was deleted.

34 changes: 26 additions & 8 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,31 @@
bin
lib
target
testing
# Compiled plugin files
target/

.settings
# IDE files
.idea/
.vscode/*
.settings/*
*.iml
*.iws
*.ipr
.classpath
.project
.directory
.factorypath

*.iml
.idea
# UML
*.plantuml

# Gradle
.gradle
**/build/
!src/**/build/
**/run/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache
9 changes: 4 additions & 5 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
pipeline {
agent any
tools {
maven 'Maven 3'
jdk 'Java 8'
jdk 'Java 17'
}
options {
buildDiscarder(logRotator(artifactNumToKeepStr: '20'))
}
stages {
stage ('Build') {
steps {
sh 'mvn clean package'
sh './gradlew clean build'
}
}

Expand All @@ -20,8 +19,8 @@ pipeline {
}

steps {
sh 'mvn javadoc:javadoc'
step([$class: 'JavadocArchiver', javadocDir: 'target/site/apidocs', keepAll: false])
sh './gradlew javadoc'
step([$class: 'JavadocArchiver', javadocDir: 'build/docs/javadoc', keepAll: false])
}
}
}
Expand Down
117 changes: 117 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
plugins {
idea
`java-library`
`maven-publish`
id("net.kyori.indra") version "3.1.3"
id("net.kyori.indra.git") version "3.1.3"
id("net.kyori.indra.publishing") version "3.1.3"
id("net.kyori.indra.checkstyle") version "3.1.3"
id("io.freefair.lombok") version "8.4"
}

indra {
github("GeyserMC", "MCProtocolLib")

mitLicense()
publishReleasesTo("opencollab-release-repo", "https://repo.opencollab.dev/maven-releases/")
publishSnapshotsTo("opencollab-snapshot-repo", "https://repo.opencollab.dev/maven-snapshots/")

configurePublications {
pom {
name.set("MCProtocolLib")
url.set("https://github.com/GeyserMC/MCProtocolLib/")
organization {
name.set("GeyserMC")
url.set("https://github.com/GeyserMC")
}
developers {
developer {
id.set("steveice10")
name.set("Steveice10")
email.set("Steveice10@gmail.com")
}
developer {
id.set("GeyserMC")
name.set("GeyserMC")
url.set("https://geysermc.org/")
}
}
}

versionMapping {
usage(Usage.JAVA_API) { fromResolutionOf(JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME) }
usage(Usage.JAVA_RUNTIME) { fromResolutionResult() }
}
}

javaVersions {
target(17)
strictVersions()
testWith(17)
minimumToolchain(17)
}
}

val repoName = if (version.toString().endsWith("SNAPSHOT")) "maven-snapshots" else "maven-releases"
publishing {
repositories {
maven("https://repo.opencollab.dev/${repoName}/") {
credentials.username = System.getenv("OPENCOLLAB_USERNAME")
credentials.password = System.getenv("OPENCOLLAB_PASSWORD")
name = "opencollab"
}
}
}

dependencies {
// Minecraft related libraries
api("com.github.steveice10:opennbt:1.6")
api("com.github.GeyserMC:mcauthlib:6621fd0")

// Kyori adventure
api("net.kyori:adventure-text-serializer-gson:4.14.0")
api("net.kyori:adventure-text-serializer-gson-legacy-impl:4.14.0")

// Math utilities
api("org.cloudburstmc.math:api:2.0")
api("org.cloudburstmc.math:immutable:2.0")

// Stripped down fastutil
api("com.nukkitx.fastutil:fastutil-object-int-maps:8.5.3")
api("com.nukkitx.fastutil:fastutil-int-object-maps:8.5.3")

// Netty
api("io.netty:netty-all:4.1.99.Final")
api("io.netty:netty-codec-haproxy:4.1.99.Final")
api("io.netty.incubator:netty-incubator-transport-native-io_uring:0.0.23.Final")

// Lombok
compileOnly("org.projectlombok:lombok:1.18.30")
annotationProcessor("org.projectlombok:lombok:1.18.30")

// Test dependencies
testImplementation("org.junit.jupiter:junit-jupiter:5.8.2")
}

group = "com.github.steveice10"
version = "1.20.2-1-SNAPSHOT"
description = "MCProtocolLib is a simple library for communicating with Minecraft clients and servers."

java {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
withSourcesJar()
withJavadocJar()
}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
options.compilerArgs.add("-Xlint:all,-serial,-processing")
}

tasks.withType<Javadoc> {
options.encoding = "UTF-8"
title = "MCProtocolLib Javadocs"
(options as StandardJavadocDocletOptions).addStringOption("Xdoclint:none", "-quiet")
}

7 changes: 7 additions & 0 deletions example/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
plugins {
java
}

dependencies {
implementation(rootProject)
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@

import com.github.steveice10.packetlib.codec.PacketCodecHelper;
import com.github.steveice10.packetlib.packet.Packet;

import java.io.IOException;
import io.netty.buffer.ByteBuf;

public class PingPacket implements Packet {
private final String id;

public PingPacket(ByteBuf buf, PacketCodecHelper codecHelper) throws IOException {
public PingPacket(ByteBuf buf, PacketCodecHelper codecHelper) {
this.id = codecHelper.readString(buf);
}

Expand All @@ -19,14 +18,4 @@ public PingPacket(String id) {
public String getPingId() {
return this.id;
}

@Override
public void write(ByteBuf buf, PacketCodecHelper codecHelper) throws IOException {
codecHelper.writeString(buf, this.id);
}

@Override
public boolean isPriority() {
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import javax.crypto.SecretKey;

public class ServerListener extends ServerAdapter {
private SecretKey key;
private final SecretKey key;

public ServerListener(SecretKey key) {
this.key = key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@

import com.github.steveice10.packetlib.Server;
import com.github.steveice10.packetlib.Session;
import com.github.steveice10.packetlib.codec.BasePacketCodecHelper;
import com.github.steveice10.packetlib.codec.PacketCodecHelper;
import com.github.steveice10.packetlib.codec.PacketDefinition;
import com.github.steveice10.packetlib.codec.PacketSerializer;
import com.github.steveice10.packetlib.crypt.AESEncryption;
import com.github.steveice10.packetlib.crypt.PacketEncryption;
import com.github.steveice10.packetlib.packet.DefaultPacketHeader;
import com.github.steveice10.packetlib.packet.PacketHeader;
import com.github.steveice10.packetlib.packet.PacketProtocol;
import io.netty.buffer.ByteBuf;

import javax.crypto.SecretKey;
import java.security.GeneralSecurityException;
Expand All @@ -28,10 +33,21 @@ public PacketCodecHelper createHelper() {
}

public void setSecretKey(SecretKey key) {
this.register(0, PingPacket.class, PingPacket::new);
this.register(0, PingPacket.class, new PacketSerializer<>() {
@Override
public void serialize(ByteBuf buf, PacketCodecHelper helper, PingPacket packet) {
helper.writeString(buf, packet.getPingId());
}

@Override
public PingPacket deserialize(ByteBuf buf, PacketCodecHelper helper, PacketDefinition<PingPacket, PacketCodecHelper> definition) {
return new PingPacket(buf, helper);
}
});

try {
this.encrypt = new AESEncryption(key);
} catch(GeneralSecurityException e) {
} catch (GeneralSecurityException e) {
e.printStackTrace();
}
}
Expand Down
Binary file added gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
7 changes: 7 additions & 0 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
Loading

0 comments on commit 0f28b75

Please sign in to comment.