diff --git a/README.md b/README.md index e5da75f..2361766 100644 --- a/README.md +++ b/README.md @@ -6,8 +6,10 @@ A simple library for storing and retrieving ItemStacks in Bukkit-related environ Version support ------ -Currently, Cardboard Box supports 1.7 through 1.21.3. -Will it need an update for 1.21.4? Maybe. +Currently, Cardboard Box supports 1.7 through 1.21.4. +Requires Java 21. + +Will it need an update for 1.21.5? Maybe. Will it need an update for 1.22? Definitely. Support @@ -50,12 +52,12 @@ maven { ```kotlin -implementation("dev.kitteh:cardboardbox:2.0.2") +implementation("dev.kitteh:cardboardbox:3.0.0") ``` ```xml dev.kitteh cardboardbox - 2.0.2 + 3.0.0 ``` diff --git a/api/build.gradle.kts b/api/build.gradle.kts index a00efa5..5e3e88a 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -1,17 +1,7 @@ plugins { - id("java") -} - -repositories { - mavenCentral() - maven("https://repo.papermc.io/repository/maven-public/") + `meow-conventions` } dependencies { - compileOnly("com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT") -} - -java { - targetCompatibility = JavaVersion.VERSION_17 - sourceCompatibility = JavaVersion.VERSION_17 -} + compileOnly("io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT") +} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 5e3eb86..6595c6e 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1 +1,80 @@ +plugins { + `meow-conventions` + id("io.papermc.paperweight.userdev") version "2.0.0-beta.13" apply false + id("com.gradleup.shadow") version "8.3.5" + id("maven-publish") +} + group = "dev.kitteh" + +dependencies { + compileOnly("io.papermc.paper:paper-api:1.17.1-R0.1-SNAPSHOT") + compileOnly("com.mojang:datafixerupper:1.0.20") + implementation(project(":api")) + implementation(project(":v1.20.6", configuration = "reobf")) + implementation(project(":v1.21", configuration = "reobf")) + implementation(project(":v1.21.3", configuration = "reobf")) + implementation(project(":v1.21.4", configuration = "reobf")) +} + +tasks.assemble { + dependsOn(tasks.shadowJar) +} + +tasks.jar { + archiveClassifier = "original" +} + +tasks.shadowJar { + archiveClassifier = "" +} + +publishing { + publications { + create("cardboardbox") { + artifact(tasks.shadowJar) + groupId = "dev.kitteh" + artifactId = "cardboardbox" + version = "3.0.0" + pom { + name = "CardboardBox" + description = "A Bukkit-related data storage handler" + licenses { + license { + name = "GNU General Public License (GPL) version 3" + url = "https://www.gnu.org/licenses/gpl-3.0.txt" + } + } + developers { + developer { + id = "mbaxter" + name = "Matt Baxter" + email = "matt@kitteh.org" + url = "https://www.kitteh.org/" + organization = "Kitteh" + organizationUrl = "https://www.kitteh.org" + roles = setOf("Lead Developer", "Cat Wrangler") + } + } + issueManagement { + system = "GitHub" + url = "https://github.com/KittehOrg/CardboardBox/issues" + } + scm { + connection = "scm:git:git://github.com/KittehOrg/CardboardBox.git" + developerConnection = "scm:git:git://github.com/KittehOrg/CardboardBox.git" + url = "git@github.com:KittehOrg/CardboardBox.git" + } + repositories { + maven { + name = "DependencyDownload" + val rel = "https://dependency.download/releases" + val snap = "https://dependency.download/snapshots" + url = uri(if (version.toString().endsWith("SNAPSHOT")) snap else rel) + credentials(PasswordCredentials::class) + } + } + } + } + } +} diff --git a/buildSrc/build.gradle.kts b/buildSrc/build.gradle.kts new file mode 100644 index 0000000..8156a89 --- /dev/null +++ b/buildSrc/build.gradle.kts @@ -0,0 +1,7 @@ +plugins { + `kotlin-dsl` +} + +repositories { + gradlePluginPortal() +} \ No newline at end of file diff --git a/buildSrc/src/main/kotlin/meow-conventions.gradle.kts b/buildSrc/src/main/kotlin/meow-conventions.gradle.kts new file mode 100644 index 0000000..45943a0 --- /dev/null +++ b/buildSrc/src/main/kotlin/meow-conventions.gradle.kts @@ -0,0 +1,24 @@ +import org.gradle.jvm.toolchain.JavaLanguageVersion +import org.gradle.kotlin.dsl.maven +import org.gradle.kotlin.dsl.repositories + +plugins { + `java-library` +} + +java { + toolchain.languageVersion = JavaLanguageVersion.of(21) +} + +repositories { + maven("https://repo.papermc.io/repository/maven-public/") +} + +tasks { + withType().configureEach { + options.release = 21 + } + withType().configureEach { + options.encoding = Charsets.UTF_8.name() + } +} diff --git a/combined/build.gradle.kts b/combined/build.gradle.kts deleted file mode 100644 index c8ef1dc..0000000 --- a/combined/build.gradle.kts +++ /dev/null @@ -1,82 +0,0 @@ -plugins { - id("java") - id("com.gradleup.shadow") version "8.3.5" - id("maven-publish") -} - -repositories { - mavenCentral() - maven("https://repo.papermc.io/repository/maven-public/") -} - -dependencies { - compileOnly("com.destroystokyo.paper:paper-api:1.16.5-R0.1-SNAPSHOT") - compileOnly("com.mojang:datafixerupper:1.0.20") - implementation(project(":api")) - implementation(project(":v1.20.6")) - implementation(project(":v1.21")) - implementation(project(":v1.21.3")) -} - -java { - targetCompatibility = JavaVersion.VERSION_17 - sourceCompatibility = JavaVersion.VERSION_17 -} - -tasks.jar { - archiveClassifier = "original" -} - -tasks.shadowJar { - archiveClassifier = "" -} - -publishing { - publications { - create("cardboardbox") { - artifact(tasks.shadowJar) - groupId = "dev.kitteh" - artifactId = "cardboardbox" - version = "2.0.2" - pom { - name = "CardboardBox" - description = "A Bukkit-related data storage handler" - licenses { - license { - name = "GNU General Public License (GPL) version 3" - url = "https://www.gnu.org/licenses/gpl-3.0.txt" - } - } - developers { - developer { - id = "mbaxter" - name = "Matt Baxter" - email = "matt@kitteh.org" - url = "https://www.kitteh.org/" - organization = "Kitteh" - organizationUrl = "https://www.kitteh.org" - roles = setOf("Lead Developer", "Cat Wrangler") - } - } - issueManagement { - system = "GitHub" - url = "https://github.com/KittehOrg/CardboardBox/issues" - } - scm { - connection = "scm:git:git://github.com/KittehOrg/CardboardBox.git" - developerConnection = "scm:git:git://github.com/KittehOrg/CardboardBox.git" - url = "git@github.com:KittehOrg/CardboardBox.git" - } - repositories { - maven { - name = "DependencyDownload" - val rel = "https://dependency.download/releases" - val snap = "https://dependency.download/snapshots" - url = uri(if (version.toString().endsWith("SNAPSHOT")) snap else rel) - credentials(PasswordCredentials::class) - } - } - } - } - } -} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 249e583..e644113 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 3a722c6..cea7a79 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,7 @@ -#Sat Apr 27 15:28:03 EDT 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.12-bin.zip +networkTimeout=10000 +validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index 1b6c787..1aa94a4 100644 --- a/gradlew +++ b/gradlew @@ -55,7 +55,7 @@ # Darwin, MinGW, and NonStop. # # (3) This script is generated from the Groovy template -# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt +# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # within the Gradle project. # # You can find Gradle at https://github.com/gradle/gradle/. @@ -80,13 +80,11 @@ do esac done -APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit - -APP_NAME="Gradle" +# This is normally unused +# shellcheck disable=SC2034 APP_BASE_NAME=${0##*/} - -# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. -DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' +# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036) +APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit # Use the maximum available, or set MAX_FD != -1 to use that value. MAX_FD=maximum @@ -133,22 +131,29 @@ location of your Java installation." fi else JAVACMD=java - which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. + if ! command -v java >/dev/null 2>&1 + then + die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. Please set the JAVA_HOME variable in your environment to match the location of your Java installation." + fi fi # Increase the maximum file descriptors if we can. if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then case $MAX_FD in #( max*) + # In POSIX sh, ulimit -H is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 MAX_FD=$( ulimit -H -n ) || warn "Could not query maximum file descriptor limit" esac case $MAX_FD in #( '' | soft) :;; #( *) + # In POSIX sh, ulimit -n is undefined. That's why the result is checked to see if it worked. + # shellcheck disable=SC2039,SC3045 ulimit -n "$MAX_FD" || warn "Could not set maximum file descriptor limit to $MAX_FD" esac @@ -193,11 +198,15 @@ if "$cygwin" || "$msys" ; then done fi -# Collect all arguments for the java command; -# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of -# shell script including quotes and variable substitutions, so put them in -# double quotes to make sure that they get re-expanded; and -# * put everything else in single quotes, so that it's not re-expanded. + +# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"' + +# Collect all arguments for the java command: +# * DEFAULT_JVM_OPTS, JAVA_OPTS, JAVA_OPTS, and optsEnvironmentVar are not allowed to contain shell fragments, +# and any embedded shellness will be escaped. +# * For example: A user cannot expect ${Hostname} to be expanded, as it is an environment variable and will be +# treated as '${Hostname}' itself on the command line. set -- \ "-Dorg.gradle.appname=$APP_BASE_NAME" \ @@ -205,6 +214,12 @@ set -- \ org.gradle.wrapper.GradleWrapperMain \ "$@" +# Stop when "xargs" is not available. +if ! command -v xargs >/dev/null 2>&1 +then + die "xargs is not available" +fi + # Use "xargs" to parse quoted args. # # With -n1 it outputs one arg per line, with the quotes and backslashes removed. diff --git a/gradlew.bat b/gradlew.bat index 107acd3..25da30d 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -14,7 +14,7 @@ @rem limitations under the License. @rem -@if "%DEBUG%" == "" @echo off +@if "%DEBUG%"=="" @echo off @rem ########################################################################## @rem @rem Gradle startup script for Windows @@ -25,7 +25,8 @@ if "%OS%"=="Windows_NT" setlocal set DIRNAME=%~dp0 -if "%DIRNAME%" == "" set DIRNAME=. +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused set APP_BASE_NAME=%~n0 set APP_HOME=%DIRNAME% @@ -40,13 +41,13 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto execute +if %ERRORLEVEL% equ 0 goto execute -echo. -echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -56,11 +57,11 @@ set JAVA_EXE=%JAVA_HOME%/bin/java.exe if exist "%JAVA_EXE%" goto execute -echo. -echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% -echo. -echo Please set the JAVA_HOME variable in your environment to match the -echo location of your Java installation. +echo. 1>&2 +echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 1>&2 +echo. 1>&2 +echo Please set the JAVA_HOME variable in your environment to match the 1>&2 +echo location of your Java installation. 1>&2 goto fail @@ -75,13 +76,15 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar :end @rem End local scope for the variables with windows NT shell -if "%ERRORLEVEL%"=="0" goto mainEnd +if %ERRORLEVEL% equ 0 goto mainEnd :fail rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of rem the _cmd.exe /c_ return code! -if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 -exit /b 1 +set EXIT_CODE=%ERRORLEVEL% +if %EXIT_CODE% equ 0 set EXIT_CODE=1 +if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE% +exit /b %EXIT_CODE% :mainEnd if "%OS%"=="Windows_NT" endlocal diff --git a/settings.gradle.kts b/settings.gradle.kts index a2f1f21..a517b64 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -3,4 +3,4 @@ include("api") include("v1.20.6") include("v1.21") include("v1.21.3") -include("combined") +include("v1.21.4") diff --git a/combined/src/main/java/dev/kitteh/cardboardbox/CardboardBox.java b/src/main/java/dev/kitteh/cardboardbox/CardboardBox.java similarity index 100% rename from combined/src/main/java/dev/kitteh/cardboardbox/CardboardBox.java rename to src/main/java/dev/kitteh/cardboardbox/CardboardBox.java diff --git a/combined/src/main/java/dev/kitteh/cardboardbox/pre_v1_20_6/Box.java b/src/main/java/dev/kitteh/cardboardbox/pre_v1_20_6/Box.java similarity index 100% rename from combined/src/main/java/dev/kitteh/cardboardbox/pre_v1_20_6/Box.java rename to src/main/java/dev/kitteh/cardboardbox/pre_v1_20_6/Box.java diff --git a/combined/src/main/resources/cardboardbox-credit.txt b/src/main/resources/cardboardbox-credit.txt similarity index 100% rename from combined/src/main/resources/cardboardbox-credit.txt rename to src/main/resources/cardboardbox-credit.txt diff --git a/v1.20.6/build.gradle.kts b/v1.20.6/build.gradle.kts index 38d357b..87c2e24 100644 --- a/v1.20.6/build.gradle.kts +++ b/v1.20.6/build.gradle.kts @@ -1,23 +1,9 @@ plugins { - id("java") - id("io.papermc.paperweight.userdev") version "1.7.4" -} - -java { - toolchain { - languageVersion = JavaLanguageVersion.of(21) - } -} - -repositories { - mavenCentral() + `meow-conventions` + id("io.papermc.paperweight.userdev") } dependencies { paperweight.paperDevBundle("1.20.6-R0.1-SNAPSHOT") compileOnly(project(":api")) } - -tasks.assemble { - dependsOn(tasks.reobfJar) -} diff --git a/v1.21.3/build.gradle.kts b/v1.21.3/build.gradle.kts index 108dd06..237fbcb 100644 --- a/v1.21.3/build.gradle.kts +++ b/v1.21.3/build.gradle.kts @@ -1,23 +1,9 @@ plugins { - id("java") - id("io.papermc.paperweight.userdev") version "1.7.4" -} - -java { - toolchain { - languageVersion = JavaLanguageVersion.of(21) - } -} - -repositories { - mavenCentral() + `meow-conventions` + id("io.papermc.paperweight.userdev") } dependencies { paperweight.paperDevBundle("1.21.3-R0.1-SNAPSHOT") compileOnly(project(":api")) } - -tasks.assemble { - dependsOn(tasks.reobfJar) -} diff --git a/v1.21.4/build.gradle.kts b/v1.21.4/build.gradle.kts new file mode 100644 index 0000000..a8a7a54 --- /dev/null +++ b/v1.21.4/build.gradle.kts @@ -0,0 +1,9 @@ +plugins { + `meow-conventions` + id("io.papermc.paperweight.userdev") +} + +dependencies { + paperweight.paperDevBundle("1.21.4-R0.1-SNAPSHOT") + compileOnly(project(":api")) +} diff --git a/v1.21.4/src/main/java/dev/kitteh/cardboardbox/v1_21_4/Box.java b/v1.21.4/src/main/java/dev/kitteh/cardboardbox/v1_21_4/Box.java new file mode 100644 index 0000000..15684be --- /dev/null +++ b/v1.21.4/src/main/java/dev/kitteh/cardboardbox/v1_21_4/Box.java @@ -0,0 +1,53 @@ +package dev.kitteh.cardboardbox.v1_21_4; + +import com.google.common.base.Preconditions; +import com.mojang.serialization.Dynamic; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtOps; +import net.minecraft.server.MinecraftServer; +import net.minecraft.util.datafix.fixes.References; +import org.bukkit.craftbukkit.inventory.CraftItemStack; +import org.bukkit.craftbukkit.util.CraftMagicNumbers; +import org.bukkit.inventory.ItemStack; + +import java.io.IOException; + +public class Box implements dev.kitteh.cardboardbox.api.Box { + public boolean check(ItemStack itemStack) { + return itemStack.equals(deserializeItem(serializeItem(itemStack))); + } + + private static final int DATA_VERSION = CraftMagicNumbers.INSTANCE.getDataVersion(); + + @Override + public byte[] serializeItem(ItemStack item) { + CompoundTag compound = (net.minecraft.nbt.CompoundTag) CraftItemStack.asNMSCopy(item).save(MinecraftServer.getServer().registryAccess()); + compound.putInt("DataVersion", DATA_VERSION); + java.io.ByteArrayOutputStream outputStream = new java.io.ByteArrayOutputStream(); + try { + net.minecraft.nbt.NbtIo.writeCompressed( + compound, + outputStream + ); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + return outputStream.toByteArray(); + } + + @Override + public ItemStack deserializeItem(byte[] data) { + net.minecraft.nbt.CompoundTag compound; + try { + compound = net.minecraft.nbt.NbtIo.readCompressed( + new java.io.ByteArrayInputStream(data), net.minecraft.nbt.NbtAccounter.unlimitedHeap() + ); + } catch (IOException ex) { + throw new RuntimeException(ex); + } + final int dataVersion = compound.getInt("DataVersion"); + Preconditions.checkArgument(dataVersion <= DATA_VERSION, "Newer version (" + dataVersion + " > " + DATA_VERSION + ")! Server downgrades are not supported!"); + compound = (net.minecraft.nbt.CompoundTag) MinecraftServer.getServer().fixerUpper.update(References.ITEM_STACK, new Dynamic<>(NbtOps.INSTANCE, compound), dataVersion, dataVersion).getValue(); + return CraftItemStack.asCraftMirror(net.minecraft.world.item.ItemStack.parse(MinecraftServer.getServer().registryAccess(), compound).orElseThrow()); + } +} diff --git a/v1.21/build.gradle.kts b/v1.21/build.gradle.kts index 4531c63..bccef5e 100644 --- a/v1.21/build.gradle.kts +++ b/v1.21/build.gradle.kts @@ -1,23 +1,9 @@ plugins { - id("java") - id("io.papermc.paperweight.userdev") version "1.7.4" -} - -java { - toolchain { - languageVersion = JavaLanguageVersion.of(21) - } -} - -repositories { - mavenCentral() + `meow-conventions` + id("io.papermc.paperweight.userdev") } dependencies { paperweight.paperDevBundle("1.21-R0.1-SNAPSHOT") compileOnly(project(":api")) } - -tasks.assemble { - dependsOn(tasks.reobfJar) -}