diff --git a/.github/workflows/blob-build.yml b/.github/workflows/blob-build.yml index 8c21d0b..53dfaa8 100644 --- a/.github/workflows/blob-build.yml +++ b/.github/workflows/blob-build.yml @@ -10,17 +10,28 @@ jobs: if: startsWith(github.event.head_commit.message, '[CI skip]') == false runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up JDK 21 uses: actions/setup-java@v4 with: - java-version: 17 + java-version: 21 distribution: temurin - - name: Build with Maven - run: mvn package --file pom.xml + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Build with Gradle + run: ./gradlew clean shadowJar + + - name: Rename jar file + run: mv build/libs/MobCapturer-*.jar build/libs/MobCapturer.jar + - name: Upload to Blob Builds uses: WalshyDev/blob-builds/gh-action@main with: project: MobCapturer + file: ./build/libs/MobCapturer.jar apiToken: ${{ secrets.BLOB_BUILDS_API_TOKEN }} releaseNotes: ${{ github.event.head_commit.message }} diff --git a/.github/workflows/maven.yml b/.github/workflows/ci.yml similarity index 53% rename from .github/workflows/maven.yml rename to .github/workflows/ci.yml index daf83bb..375cb7d 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/ci.yml @@ -13,11 +13,17 @@ jobs: if: startsWith(github.event.head_commit.message, '[CI skip]') == false runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Set up JDK 17 + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Set up JDK 21 uses: actions/setup-java@v4 with: - java-version: 17 + java-version: 21 distribution: temurin - - name: Build with Maven - run: mvn package --file pom.xml + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v4 + + - name: Build with Gradle + run: ./gradlew clean shadowJar diff --git a/.gitignore b/.gitignore index 9249122..0b14b1c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,24 @@ -/bin/ -/.settings/ -/target/ -/.idea/ -*.iml +.gradle +**/build/ +!src/**/build/ + +# Ignore Gradle GUI config +gradle-app.setting + +# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored) +!gradle-wrapper.jar + +# Avoid ignore Gradle wrappper properties +!gradle-wrapper.properties + +# Cache of project +.gradletasknamecache + +# Eclipse Gradle plugin generated files +# Eclipse Core .project +# JDT-specific (Eclipse Java Development Tools) .classpath -dependency-reduced-pom.xml \ No newline at end of file + +.idea/ +vscode/ diff --git a/README.md b/README.md index 5f4b323..face8e8 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,10 @@ The captured mobs will retain attributes, potion effects, fire ticks, custom nam ## :floppy_disk: Download MobCapturer You can download MobCapturer right here: [Dev Builds](https://blob.build/project/MobCapturer) +### Requirements + +- Java 21+ +- Minecraft 1.18+ ## :gear: config You can change the following settings in `config.yml`: diff --git a/build.gradle.kts b/build.gradle.kts new file mode 100644 index 0000000..3cb0c1c --- /dev/null +++ b/build.gradle.kts @@ -0,0 +1,66 @@ +plugins { + id("java") + id("maven-publish") + id("io.freefair.lombok") version "8.7.1" + id("com.gradleup.shadow") version "8.3.0" + id("net.minecrell.plugin-yml.bukkit") version "0.6.0" +} + +repositories { + mavenLocal() + mavenCentral() + maven("https://s01.oss.sonatype.org/content/repositories/snapshots/") + maven("https://repo.papermc.io/repository/maven-public/") + maven("https://jitpack.io") +} + +dependencies { + compileOnly("io.papermc.paper:paper-api:1.21-R0.1-SNAPSHOT") + compileOnly("com.github.Slimefun:Slimefun4:RC-37") + implementation("org.bstats:bstats-bukkit:3.0.3") + implementation("com.google.code.findbugs:jsr305:3.0.2") + implementation("net.guizhanss:guizhanlib-all:2.0.0-SNAPSHOT") +} + +group = "io.github.thebusybiscuit" +version = "UNOFFICIAL" +description = "MobCapturer" + +java { + sourceCompatibility = JavaVersion.VERSION_21 +} + +publishing { + publications.create("maven") { + from(components["java"]) + } +} + +tasks.compileJava { + options.encoding = "UTF-8" +} + +tasks.javadoc { + options.encoding = "UTF-8" +} + +tasks.shadowJar { + fun doRelocate(from: String) { + val last = from.split(".").last() + relocate(from, "io.github.thebusybiscuit.mobcapturer.libs.$last") + } + doRelocate("org.bstats") + doRelocate("javax.annotation") + doRelocate("io.papermc.paperlib") + minimize() + archiveClassifier = "" +} + +bukkit { + main = "io.github.thebusybiscuit.mobcapturer.MobCapturer" + apiVersion = "1.18" + authors = listOf("TheBusyBiscuit", "ybw0014") + description = "A Slimefun Addon that adds a tool that allows you to capture mobs" + website = "https://github.com/Slimefun-Addon-Community/MobCapturer" + depend = listOf("Slimefun") +} diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar new file mode 100644 index 0000000..d64cd49 Binary files /dev/null and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties new file mode 100644 index 0000000..1af9e09 --- /dev/null +++ b/gradle/wrapper/gradle-wrapper.properties @@ -0,0 +1,7 @@ +distributionBase=GRADLE_USER_HOME +distributionPath=wrapper/dists +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip +networkTimeout=10000 +validateDistributionUrl=true +zipStoreBase=GRADLE_USER_HOME +zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew new file mode 100755 index 0000000..1aa94a4 --- /dev/null +++ b/gradlew @@ -0,0 +1,249 @@ +#!/bin/sh + +# +# Copyright © 2015-2021 the original authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# + +############################################################################## +# +# Gradle start up script for POSIX generated by Gradle. +# +# Important for running: +# +# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is +# noncompliant, but you have some other compliant shell such as ksh or +# bash, then to run this script, type that shell name before the whole +# command line, like: +# +# ksh Gradle +# +# Busybox and similar reduced shells will NOT work, because this script +# requires all of these POSIX shell features: +# * functions; +# * expansions «$var», «${var}», «${var:-default}», «${var+SET}», +# «${var#prefix}», «${var%suffix}», and «$( cmd )»; +# * compound commands having a testable exit status, especially «case»; +# * various built-in commands including «command», «set», and «ulimit». +# +# Important for patching: +# +# (2) This script targets any POSIX shell, so it avoids extensions provided +# by Bash, Ksh, etc; in particular arrays are avoided. +# +# The "traditional" practice of packing multiple parameters into a +# space-separated string is a well documented source of bugs and security +# problems, so this is (mostly) avoided, by progressively accumulating +# options in "$@", and eventually passing that to Java. +# +# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS, +# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly; +# see the in-line comments for details. +# +# There are tweaks for specific operating systems such as AIX, CygWin, +# Darwin, MinGW, and NonStop. +# +# (3) This script is generated from the Groovy template +# 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/. +# +############################################################################## + +# Attempt to set APP_HOME + +# Resolve links: $0 may be a link +app_path=$0 + +# Need this for daisy-chained symlinks. +while + APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path + [ -h "$app_path" ] +do + ls=$( ls -ld "$app_path" ) + link=${ls#*' -> '} + case $link in #( + /*) app_path=$link ;; #( + *) app_path=$APP_HOME$link ;; + esac +done + +# This is normally unused +# shellcheck disable=SC2034 +APP_BASE_NAME=${0##*/} +# 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 + +warn () { + echo "$*" +} >&2 + +die () { + echo + echo "$*" + echo + exit 1 +} >&2 + +# OS specific support (must be 'true' or 'false'). +cygwin=false +msys=false +darwin=false +nonstop=false +case "$( uname )" in #( + CYGWIN* ) cygwin=true ;; #( + Darwin* ) darwin=true ;; #( + MSYS* | MINGW* ) msys=true ;; #( + NONSTOP* ) nonstop=true ;; +esac + +CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar + + +# Determine the Java command to use to start the JVM. +if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD=$JAVA_HOME/jre/sh/java + else + JAVACMD=$JAVA_HOME/bin/java + fi + if [ ! -x "$JAVACMD" ] ; then + die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME + +Please set the JAVA_HOME variable in your environment to match the +location of your Java installation." + fi +else + JAVACMD=java + 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 +fi + +# Collect all arguments for the java command, stacking in reverse order: +# * args from the command line +# * the main class name +# * -classpath +# * -D...appname settings +# * --module-path (only if needed) +# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables. + +# For Cygwin or MSYS, switch paths to Windows format before running java +if "$cygwin" || "$msys" ; then + APP_HOME=$( cygpath --path --mixed "$APP_HOME" ) + CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" ) + + JAVACMD=$( cygpath --unix "$JAVACMD" ) + + # Now convert the arguments - kludge to limit ourselves to /bin/sh + for arg do + if + case $arg in #( + -*) false ;; # don't mess with options #( + /?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath + [ -e "$t" ] ;; #( + *) false ;; + esac + then + arg=$( cygpath --path --ignore --mixed "$arg" ) + fi + # Roll the args list around exactly as many times as the number of + # args, so each arg winds up back in the position where it started, but + # possibly modified. + # + # NB: a `for` loop captures its iteration list before it begins, so + # changing the positional parameters here affects neither the number of + # iterations, nor the values presented in `arg`. + shift # remove old arg + set -- "$@" "$arg" # push replacement arg + done +fi + + +# 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" \ + -classpath "$CLASSPATH" \ + 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. +# +# In Bash we could simply go: +# +# readarray ARGS < <( xargs -n1 <<<"$var" ) && +# set -- "${ARGS[@]}" "$@" +# +# but POSIX shell has neither arrays nor command substitution, so instead we +# post-process each arg (as a line of input to sed) to backslash-escape any +# character that might be a shell metacharacter, then use eval to reverse +# that process (while maintaining the separation between arguments), and wrap +# the whole thing up as a single "set" statement. +# +# This will of course break if any of these variables contains a newline or +# an unmatched quote. +# + +eval "set -- $( + printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" | + xargs -n1 | + sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' | + tr '\n' ' ' + )" '"$@"' + +exec "$JAVACMD" "$@" diff --git a/gradlew.bat b/gradlew.bat new file mode 100644 index 0000000..93e3f59 --- /dev/null +++ b/gradlew.bat @@ -0,0 +1,92 @@ +@rem +@rem Copyright 2015 the original author or authors. +@rem +@rem Licensed under the Apache License, Version 2.0 (the "License"); +@rem you may not use this file except in compliance with the License. +@rem You may obtain a copy of the License at +@rem +@rem https://www.apache.org/licenses/LICENSE-2.0 +@rem +@rem Unless required by applicable law or agreed to in writing, software +@rem distributed under the License is distributed on an "AS IS" BASIS, +@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +@rem See the License for the specific language governing permissions and +@rem limitations under the License. +@rem + +@if "%DEBUG%"=="" @echo off +@rem ########################################################################## +@rem +@rem Gradle startup script for Windows +@rem +@rem ########################################################################## + +@rem Set local scope for the variables with windows NT shell +if "%OS%"=="Windows_NT" setlocal + +set DIRNAME=%~dp0 +if "%DIRNAME%"=="" set DIRNAME=. +@rem This is normally unused +set APP_BASE_NAME=%~n0 +set APP_HOME=%DIRNAME% + +@rem Resolve any "." and ".." in APP_HOME to make it shorter. +for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi + +@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. +set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m" + +@rem Find java.exe +if defined JAVA_HOME goto findJavaFromJavaHome + +set JAVA_EXE=java.exe +%JAVA_EXE% -version >NUL 2>&1 +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. + +goto fail + +:findJavaFromJavaHome +set JAVA_HOME=%JAVA_HOME:"=% +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. + +goto fail + +:execute +@rem Setup the command line + +set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar + + +@rem Execute Gradle +"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %* + +:end +@rem End local scope for the variables with windows NT shell +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! +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 + +:omega diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 396a9e2..0000000 --- a/pom.xml +++ /dev/null @@ -1,131 +0,0 @@ - - - 4.0.0 - io.github.thebusybiscuit - MobCapturer - UNOFFICIAL - - - 16 - 16 - UTF-8 - - - - - paper-repo - https://repo.destroystokyo.com/repository/maven-public/ - - - spigot-repo - https://hub.spigotmc.org/nexus/content/repositories/snapshots/ - - - jitpack.io - https://jitpack.io - - - - - ${project.name} v${project.version} - clean package - ${basedir}/src/main/java - - - - ${basedir}/src/main/resources - true - - * - - - - - ${basedir} - - LICENSE - - - - - - - org.apache.maven.plugins - maven-shade-plugin - 3.5.0 - - - true - - - - - org.bstats - io.github.thebusybiscuit.mobcapturer.bstats - - - - - - - *:* - - META-INF/* - - - - - - - - package - - shade - - - - - - - - - - org.spigotmc - spigot-api - 1.20.1-R0.1-SNAPSHOT - provided - - - - com.github.Slimefun - Slimefun4 - RC-36 - provided - - - io.github.baked-libs - dough-api - - - org.bstats - bstats-bukkit - - - - - - org.bstats - bstats-bukkit - 3.0.2 - compile - - - - com.google.code.findbugs - jsr305 - 3.0.2 - - - diff --git a/settings.gradle.kts b/settings.gradle.kts new file mode 100644 index 0000000..bc75d9a --- /dev/null +++ b/settings.gradle.kts @@ -0,0 +1 @@ +rootProject.name = "MobCapturer" diff --git a/src/main/java/io/github/thebusybiscuit/mobcapturer/MobCapturer.java b/src/main/java/io/github/thebusybiscuit/mobcapturer/MobCapturer.java index d80a43c..59666eb 100644 --- a/src/main/java/io/github/thebusybiscuit/mobcapturer/MobCapturer.java +++ b/src/main/java/io/github/thebusybiscuit/mobcapturer/MobCapturer.java @@ -46,7 +46,7 @@ public void onEnable() { Config cfg = new Config(this); new Metrics(this, 6672); - if (cfg.getBoolean("options.auto-update") && getDescription().getVersion().startsWith("Dev - ")) { + if (cfg.getBoolean("options.auto-update") && getPluginVersion().startsWith("Dev")) { new BlobBuildUpdater(this, getFile(), "MobCapturer").start(); } diff --git a/src/main/java/io/github/thebusybiscuit/mobcapturer/adapters/MobAdapter.java b/src/main/java/io/github/thebusybiscuit/mobcapturer/adapters/MobAdapter.java index 925b225..8503806 100644 --- a/src/main/java/io/github/thebusybiscuit/mobcapturer/adapters/MobAdapter.java +++ b/src/main/java/io/github/thebusybiscuit/mobcapturer/adapters/MobAdapter.java @@ -4,7 +4,6 @@ import java.util.LinkedList; import java.util.List; import java.util.Map; -import java.util.UUID; import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; @@ -18,7 +17,6 @@ import org.bukkit.attribute.Attribute; import org.bukkit.attribute.AttributeInstance; import org.bukkit.attribute.AttributeModifier; -import org.bukkit.attribute.AttributeModifier.Operation; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; import org.bukkit.persistence.PersistentDataAdapterContext; @@ -26,6 +24,7 @@ import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffectType; +import io.github.thebusybiscuit.mobcapturer.utils.JsonUtils; import io.github.thebusybiscuit.slimefun4.utils.NumberUtils; /** @@ -85,7 +84,7 @@ default String toPrimitive(JsonObject json, PersistentDataAdapterContext context @ParametersAreNonnullByDefault @Nonnull default JsonObject fromPrimitive(String primitive, PersistentDataAdapterContext context) { - return new JsonParser().parse(primitive).getAsJsonObject(); + return JsonParser.parseString(primitive).getAsJsonObject(); } @ParametersAreNonnullByDefault @@ -109,12 +108,8 @@ default void apply(T entity, JsonObject json) { for (JsonElement modifier : modifiers) { JsonObject obj = modifier.getAsJsonObject(); - String uuid = obj.get("uuid").getAsString(); - String name = obj.get("name").getAsString(); - double amount = obj.get("amount").getAsDouble(); - int operation = obj.get("operation").getAsInt(); + AttributeModifier mod = AttributeModifier.deserialize(JsonUtils.toMap(obj)); - AttributeModifier mod = new AttributeModifier(UUID.fromString(uuid), name, amount, Operation.values()[operation]); instance.addModifier(mod); } } @@ -193,11 +188,11 @@ default JsonObject saveData(@Nonnull T entity) { for (AttributeModifier modifier : instance.getModifiers()) { JsonObject mod = new JsonObject(); + Map serializedMod = modifier.serialize(); - mod.addProperty("uuid", modifier.getUniqueId().toString()); - mod.addProperty("name", modifier.getName()); - mod.addProperty("operation", modifier.getOperation().ordinal()); - mod.addProperty("amount", modifier.getAmount()); + for (var entry : serializedMod.entrySet()) { + mod.addProperty(entry.getKey(), entry.getValue().toString()); + } modifiers.add(mod); } diff --git a/src/main/java/io/github/thebusybiscuit/mobcapturer/adapters/mobs/EndermanAdapter.java b/src/main/java/io/github/thebusybiscuit/mobcapturer/adapters/mobs/EndermanAdapter.java index e73b0ef..2e148a0 100644 --- a/src/main/java/io/github/thebusybiscuit/mobcapturer/adapters/mobs/EndermanAdapter.java +++ b/src/main/java/io/github/thebusybiscuit/mobcapturer/adapters/mobs/EndermanAdapter.java @@ -1,18 +1,18 @@ package io.github.thebusybiscuit.mobcapturer.adapters.mobs; -import com.google.gson.JsonObject; +import java.util.List; -import io.github.thebusybiscuit.mobcapturer.adapters.MobAdapter; +import javax.annotation.Nonnull; +import javax.annotation.ParametersAreNonnullByDefault; + +import com.google.gson.JsonObject; import org.bukkit.Bukkit; import org.bukkit.ChatColor; import org.bukkit.block.data.BlockData; import org.bukkit.entity.Enderman; -import javax.annotation.Nonnull; -import javax.annotation.ParametersAreNonnullByDefault; - -import java.util.List; +import io.github.thebusybiscuit.mobcapturer.adapters.MobAdapter; public class EndermanAdapter implements MobAdapter { diff --git a/src/main/java/io/github/thebusybiscuit/mobcapturer/adapters/mobs/GoatAdapter.java b/src/main/java/io/github/thebusybiscuit/mobcapturer/adapters/mobs/GoatAdapter.java index cad71fc..77d26fb 100644 --- a/src/main/java/io/github/thebusybiscuit/mobcapturer/adapters/mobs/GoatAdapter.java +++ b/src/main/java/io/github/thebusybiscuit/mobcapturer/adapters/mobs/GoatAdapter.java @@ -10,8 +10,7 @@ import org.bukkit.ChatColor; import org.bukkit.entity.Goat; -import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; -import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; +import net.guizhanss.guizhanlib.minecraft.utils.MinecraftVersionUtil; public class GoatAdapter extends AnimalsAdapter { @@ -58,7 +57,7 @@ public JsonObject saveData(@Nonnull Goat entity) { } private boolean hasHornMethods() { - return Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_19); + return MinecraftVersionUtil.isAtLeast(19); } } diff --git a/src/main/java/io/github/thebusybiscuit/mobcapturer/adapters/mobs/WolfAdapter.java b/src/main/java/io/github/thebusybiscuit/mobcapturer/adapters/mobs/WolfAdapter.java index 55d6868..ec484b1 100644 --- a/src/main/java/io/github/thebusybiscuit/mobcapturer/adapters/mobs/WolfAdapter.java +++ b/src/main/java/io/github/thebusybiscuit/mobcapturer/adapters/mobs/WolfAdapter.java @@ -1,6 +1,8 @@ package io.github.thebusybiscuit.mobcapturer.adapters.mobs; +import java.util.HashMap; import java.util.List; +import java.util.Map; import javax.annotation.Nonnull; import javax.annotation.ParametersAreNonnullByDefault; @@ -9,14 +11,32 @@ import org.bukkit.ChatColor; import org.bukkit.DyeColor; +import org.bukkit.NamespacedKey; +import org.bukkit.Registry; import org.bukkit.entity.Wolf; +import org.bukkit.entity.Wolf.Variant; +import org.bukkit.inventory.EquipmentSlot; +import org.bukkit.inventory.ItemStack; +import io.github.thebusybiscuit.mobcapturer.adapters.InventoryAdapter; import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; +import io.papermc.paper.registry.RegistryAccess; +import io.papermc.paper.registry.RegistryKey; -public class WolfAdapter extends AbstractTameableAdapter { +import net.guizhanss.guizhanlib.minecraft.utils.MinecraftVersionUtil; + +public class WolfAdapter extends AbstractTameableAdapter implements InventoryAdapter { + + private final Registry wolfVariantRegistry; public WolfAdapter() { super(Wolf.class); + + if (MinecraftVersionUtil.isAtLeast(20, 5)) { + wolfVariantRegistry = RegistryAccess.registryAccess().getRegistry(RegistryKey.WOLF_VARIANT); + } else { + wolfVariantRegistry = null; + } } @Nonnull @@ -42,6 +62,11 @@ public void apply(Wolf entity, JsonObject json) { entity.setAngry(json.get("angry").getAsBoolean()); entity.setSitting(json.get("sitting").getAsBoolean()); entity.setCollarColor(DyeColor.valueOf(json.get("collarColor").getAsString())); + + // variant added in 1.20.5 + if (MinecraftVersionUtil.isAtLeast(20, 5) && json.has("variant")) { + entity.setVariant((Variant) wolfVariantRegistry.get(NamespacedKey.fromString(json.get("variant").getAsString()))); + } } @Nonnull @@ -53,7 +78,32 @@ public JsonObject saveData(@Nonnull Wolf entity) { json.addProperty("sitting", entity.isSitting()); json.addProperty("collarColor", entity.getCollarColor().name()); + // variant added in 1.20.5 + if (MinecraftVersionUtil.isAtLeast(20, 5)) { + json.addProperty("variant", entity.getVariant().getKey().toString()); + } + return json; } + @Override + public void applyInventory(Wolf entity, Map inventory) { + if (MinecraftVersionUtil.isAtLeast(20, 5)) { + ItemStack wolfArmor = inventory.get("body"); + entity.getEquipment().setItem(EquipmentSlot.BODY, wolfArmor); + } + } + + @Nonnull + @Override + public Map saveInventory(@Nonnull Wolf entity) { + Map inventory = new HashMap<>(); + + if (MinecraftVersionUtil.isAtLeast(20, 5)) { + ItemStack wolfArmor = entity.getEquipment().getItem(EquipmentSlot.BODY); + inventory.put("body", wolfArmor); + } + + return inventory; + } } diff --git a/src/main/java/io/github/thebusybiscuit/mobcapturer/events/MobCaptureEvent.java b/src/main/java/io/github/thebusybiscuit/mobcapturer/events/MobCaptureEvent.java index bd41991..a1e18b4 100644 --- a/src/main/java/io/github/thebusybiscuit/mobcapturer/events/MobCaptureEvent.java +++ b/src/main/java/io/github/thebusybiscuit/mobcapturer/events/MobCaptureEvent.java @@ -39,6 +39,11 @@ public MobCaptureEvent(Player player, LivingEntity entity) { this.entity = entity; } + @Nonnull + public static HandlerList getHandlerList() { + return HANDLER_LIST; + } + @Override public boolean isCancelled() { return this.cancelled; @@ -64,9 +69,4 @@ public LivingEntity getEntity() { public HandlerList getHandlers() { return HANDLER_LIST; } - - @Nonnull - public static HandlerList getHandlerList() { - return HANDLER_LIST; - } } diff --git a/src/main/java/io/github/thebusybiscuit/mobcapturer/items/MobEgg.java b/src/main/java/io/github/thebusybiscuit/mobcapturer/items/MobEgg.java index 40d9263..eb40129 100644 --- a/src/main/java/io/github/thebusybiscuit/mobcapturer/items/MobEgg.java +++ b/src/main/java/io/github/thebusybiscuit/mobcapturer/items/MobEgg.java @@ -40,9 +40,7 @@ /** * The Mob Egg holds data of an entity, and will release the mob while right-clicking on a block. * - * @param - * A {@link LivingEntity}. - * + * @param A {@link LivingEntity}. * @author TheBusyBiscuit */ public class MobEgg extends SimpleSlimefunItem implements NotPlaceable, DistinctiveItem { diff --git a/src/main/java/io/github/thebusybiscuit/mobcapturer/listeners/MobCaptureListener.java b/src/main/java/io/github/thebusybiscuit/mobcapturer/listeners/MobCaptureListener.java index 295e0f3..b0d947e 100644 --- a/src/main/java/io/github/thebusybiscuit/mobcapturer/listeners/MobCaptureListener.java +++ b/src/main/java/io/github/thebusybiscuit/mobcapturer/listeners/MobCaptureListener.java @@ -24,12 +24,8 @@ */ public class MobCaptureListener implements Listener { - private final MobCapturer plugin; - public MobCaptureListener(@Nonnull MobCapturer plugin) { plugin.getServer().getPluginManager().registerEvents(this, plugin); - - this.plugin = plugin; } @EventHandler(priority = EventPriority.LOWEST) diff --git a/src/main/java/io/github/thebusybiscuit/mobcapturer/listeners/PelletListener.java b/src/main/java/io/github/thebusybiscuit/mobcapturer/listeners/PelletListener.java index fa6945e..8cf9f09 100644 --- a/src/main/java/io/github/thebusybiscuit/mobcapturer/listeners/PelletListener.java +++ b/src/main/java/io/github/thebusybiscuit/mobcapturer/listeners/PelletListener.java @@ -14,7 +14,6 @@ import org.bukkit.event.EventHandler; import org.bukkit.event.EventPriority; import org.bukkit.event.Listener; -import org.bukkit.event.entity.EntityDamageByEntityEvent; import org.bukkit.event.entity.ProjectileHitEvent; import org.bukkit.inventory.ItemStack; @@ -62,11 +61,8 @@ && canCapture(player, entity) /** * Check if {@link Player} can capture the specified {@link LivingEntity}. * - * @param p - * The {@link Player} to be checked. - * @param entity - * The specified {@link LivingEntity}. - * + * @param p The {@link Player} to be checked. + * @param entity The specified {@link LivingEntity}. * @return If {@link Player} can capture the specified {@link LivingEntity}. */ @ParametersAreNonnullByDefault @@ -84,13 +80,11 @@ protected boolean canCapture(Player p, LivingEntity entity) { /** * Capture the specified {@link LivingEntity}. * - * @param entity - * The specified {@link LivingEntity}. - * + * @param entity The specified {@link LivingEntity}. * @return The egg {@link ItemStack}. */ @Nonnull - @SuppressWarnings({ "unchecked", "rawtypes" }) + @SuppressWarnings({"unchecked", "rawtypes"}) protected Optional capture(@Nonnull LivingEntity entity) { MobEgg egg = MobCapturer.getRegistry().getAdapters().get(entity.getType()); @@ -109,12 +103,9 @@ protected Optional capture(@Nonnull LivingEntity entity) { *

* If mob eggs to inventory is disabled, drop the egg to the entity's {@link Location}. * - * @param p - * The {@link Player} that is capturing the mob. - * @param item - * The egg {@link ItemStack}. - * @param loc - * The {@link Location} of the {@link LivingEntity}. + * @param p The {@link Player} that is capturing the mob. + * @param item The egg {@link ItemStack}. + * @param loc The {@link Location} of the {@link LivingEntity}. */ @ParametersAreNonnullByDefault protected void dropEgg(Player p, ItemStack item, Location loc) { diff --git a/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/ItemGroups.java b/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/ItemGroups.java index 8469177..58f8b3e 100644 --- a/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/ItemGroups.java +++ b/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/ItemGroups.java @@ -1,16 +1,16 @@ package io.github.thebusybiscuit.mobcapturer.setup; -import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; - import org.bukkit.Material; import org.bukkit.NamespacedKey; import io.github.thebusybiscuit.mobcapturer.MobCapturer; import io.github.thebusybiscuit.slimefun4.api.items.ItemGroup; +import io.github.thebusybiscuit.slimefun4.api.items.SlimefunItemStack; import io.github.thebusybiscuit.slimefun4.api.items.groups.NestedItemGroup; import io.github.thebusybiscuit.slimefun4.api.items.groups.SubItemGroup; import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; -import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; + +import lombok.experimental.UtilityClass; /** * All the {@link ItemGroup}s in MobCapturer. @@ -18,7 +18,9 @@ * @author TheBusyBiscuit * @author ybw0014 */ +@UtilityClass public final class ItemGroups { + public static final NestedItemGroup MAIN = new NestedItemGroup( new NamespacedKey(MobCapturer.getInstance(), "mob_capturer"), new SlimefunItemStack( @@ -43,6 +45,4 @@ public final class ItemGroups { "&aMob Eggs" ) ); - - private ItemGroups() {} } diff --git a/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/ItemStacks.java b/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/ItemStacks.java index ed8644e..c39b17f 100644 --- a/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/ItemStacks.java +++ b/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/ItemStacks.java @@ -10,13 +10,17 @@ import io.github.thebusybiscuit.slimefun4.libraries.commons.lang.Validate; import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; +import lombok.experimental.UtilityClass; + /** * All the {@link SlimefunItemStack}s in MobCapturer. * * @author TheBusyBiscuit * @author ybw0014 */ +@UtilityClass public final class ItemStacks { + public static final SlimefunItemStack MOB_CANNON = new SlimefunItemStack( "MOB_CANNON", Material.BLAZE_ROD, @@ -33,8 +37,6 @@ public final class ItemStacks { "&7Ammunition for your &6Mob Capturing Cannon" ); - private ItemStacks() {} - @Nonnull @ParametersAreNonnullByDefault public static SlimefunItemStack buildMobEgg(EntityType type, String eggTexture) { diff --git a/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/Keys.java b/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/Keys.java index 5948b7d..d18a1df 100644 --- a/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/Keys.java +++ b/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/Keys.java @@ -4,16 +4,18 @@ import io.github.thebusybiscuit.mobcapturer.MobCapturer; +import lombok.experimental.UtilityClass; + /** * All the {@link NamespacedKey}s and key strings in MobCapturer. * * @author TheBusyBiscuit * @author ybw0014 */ +@UtilityClass public final class Keys { + public static final NamespacedKey DATA = new NamespacedKey(MobCapturer.getInstance(), "captured_mob"); public static final NamespacedKey INVENTORY = new NamespacedKey(MobCapturer.getInstance(), "mob_inventory"); public static final String MOB_CAPTURING_PELLET = "mob_capturing_cannon"; - - private Keys() {} } diff --git a/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/RecipeTypes.java b/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/RecipeTypes.java index f318398..c6c83df 100644 --- a/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/RecipeTypes.java +++ b/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/RecipeTypes.java @@ -6,13 +6,18 @@ import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; +import lombok.experimental.UtilityClass; + /** * All the {@link RecipeType}s in MobCapturer. * * @author TheBusyBiscuit * @author ybw0014 */ +@UtilityClass public final class RecipeTypes { + + // @formatter:off public static final RecipeType MOB_CAPTURING = new RecipeType( new NamespacedKey(MobCapturer.getInstance(), "mob_capturing"), new CustomItemStack( @@ -22,6 +27,5 @@ public final class RecipeTypes { "&7to catch the given Mob." ) ); - - private RecipeTypes() {} + // @formatter:on } diff --git a/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/Registry.java b/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/Registry.java index 7e62652..b6924cc 100644 --- a/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/Registry.java +++ b/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/Registry.java @@ -3,33 +3,25 @@ import java.util.EnumMap; import java.util.Map; -import javax.annotation.Nonnull; - import org.bukkit.entity.EntityType; import io.github.thebusybiscuit.mobcapturer.items.MobEgg; import io.github.thebusybiscuit.slimefun4.libraries.dough.config.Config; +import lombok.Getter; + /** * The registry houses adapters and configs of MobCapturer. * * @author ybw0014 */ +@Getter public final class Registry { + private final Map> adapters = new EnumMap<>(EntityType.class); private final Config config; public Registry(Config config) { this.config = config; } - - @Nonnull - public Map> getAdapters() { - return adapters; - } - - @Nonnull - public Config getConfig() { - return config; - } } diff --git a/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/Researches.java b/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/Researches.java index f2964e2..6e87657 100644 --- a/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/Researches.java +++ b/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/Researches.java @@ -5,19 +5,16 @@ import io.github.thebusybiscuit.mobcapturer.MobCapturer; import io.github.thebusybiscuit.slimefun4.api.researches.Research; +import lombok.experimental.UtilityClass; + /** * All the {@link Research}es in MobCapturer. * * @author TheBusyBiscuit * @author ybw0014 */ +@UtilityClass public final class Researches { - public static final Research MOB_CAPTURING = new Research( - new NamespacedKey(MobCapturer.getInstance(), "mob_capturing"), - 32652, - "Capturing Mobs", - 28 - ); - private Researches() {} + public static final Research MOB_CAPTURING = new Research(new NamespacedKey(MobCapturer.getInstance(), "mob_capturing"), 32652, "Capturing Mobs", 28); } diff --git a/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/Setup.java b/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/Setup.java index 80539c9..69b9955 100644 --- a/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/Setup.java +++ b/src/main/java/io/github/thebusybiscuit/mobcapturer/setup/Setup.java @@ -4,8 +4,11 @@ import org.bukkit.ChatColor; import org.bukkit.Material; +import org.bukkit.entity.Armadillo; import org.bukkit.entity.Bat; import org.bukkit.entity.Blaze; +import org.bukkit.entity.Bogged; +import org.bukkit.entity.Breeze; import org.bukkit.entity.Camel; import org.bukkit.entity.CaveSpider; import org.bukkit.entity.Chicken; @@ -97,27 +100,31 @@ import io.github.thebusybiscuit.mobcapturer.items.MobCannon; import io.github.thebusybiscuit.mobcapturer.items.MobEgg; import io.github.thebusybiscuit.mobcapturer.items.MobPellet; -import io.github.thebusybiscuit.slimefun4.api.MinecraftVersion; import io.github.thebusybiscuit.slimefun4.api.recipes.RecipeType; -import io.github.thebusybiscuit.slimefun4.implementation.Slimefun; import io.github.thebusybiscuit.slimefun4.implementation.SlimefunItems; import io.github.thebusybiscuit.slimefun4.libraries.dough.items.CustomItemStack; import io.github.thebusybiscuit.slimefun4.utils.ChatUtils; import io.github.thebusybiscuit.slimefun4.utils.SlimefunUtils; +import net.guizhanss.guizhanlib.minecraft.utils.MinecraftVersionUtil; +import net.guizhanss.guizhanlib.minecraft.utils.compatibility.EntityTypeX; + +import lombok.experimental.UtilityClass; + /** * Setup {@link MobCapturer}. * * @author TheBusyBiscuit * @author ybw0014 */ +@UtilityClass public final class Setup { - private Setup() {} public static void setup() { MobCapturer plugin = MobCapturer.getInstance(); // items + // @formatter:off new MobPellet( ItemGroups.TOOLS, ItemStacks.MOB_CAPTURING_PELLET, @@ -139,6 +146,7 @@ SlimefunItems.MAGIC_LUMP_2, new ItemStack(Material.EGG), SlimefunItems.MAGIC_LUM SlimefunItems.ADVANCED_CIRCUIT_BOARD, SlimefunItems.STEEL_INGOT, null } ).register(plugin); + // @formatter:on setupMobEggs(); @@ -148,7 +156,7 @@ SlimefunItems.MAGIC_LUMP_2, new ItemStack(Material.EGG), SlimefunItems.MAGIC_LUM } private static void setupMobEggs() { - // + // // https://minecraft-heads.com/custom-heads/decoration/935-spawn-egg-cow registerMob(EntityType.COW, new AnimalsAdapter<>(Cow.class), "9419f15ff54dae5d040f9b9d8eb2a8989e676710922a0ca164da613ca61e9"); // https://minecraft-heads.com/custom-heads/decoration/934-spawn-egg-chicken @@ -156,7 +164,7 @@ private static void setupMobEggs() { // https://minecraft-heads.com/custom-heads/decoration/939-spawn-egg-pig registerMob(EntityType.PIG, new PigAdapter(), "527ad51dd773b72dca1c13e6f3547a83181aad91165282999bbdf13a3b3c9"); // https://minecraft-heads.com/custom-heads/decoration/937-spawn-egg-mooshroom - registerMob(EntityType.MUSHROOM_COW, new MooshroomAdapter(), "41b3b02e36ae9850df25aa09c2ca5a17b9c6616ce53e0b141ad360b6c67c"); + registerMob(EntityTypeX.MOOSHROOM, new MooshroomAdapter(), "41b3b02e36ae9850df25aa09c2ca5a17b9c6616ce53e0b141ad360b6c67c"); // https://minecraft-heads.com/custom-heads/decoration/940-spawn-egg-rabbit registerMob(EntityType.RABBIT, new RabbitAdapter(), "63e06ed8809243e317393f6162679b2c1fe6911eda2d30cb99cfc82d347cb"); // https://minecraft-heads.com/custom-heads/decoration/936-spawn-egg-sheep @@ -171,23 +179,26 @@ private static void setupMobEggs() { registerMob(EntityType.FOX, new FoxAdapter(), "fcfd0230988ea3337126fc2c06f24cbc81ecf8ee8011abfe3993824bac33d260"); // https://minecraft-heads.com/custom-heads/decoration/48546-spawn-egg-bee registerMob(EntityType.BEE, new BeeAdapter(), "a5ed2a6d8ba4dba6db2a475dc1ca69f49459d5f95b7095a5b2d8a6d2c944e74e"); - if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_17)) { - // https://minecraft-heads.com/custom-heads/decoration/46398-spawn-egg-axolotl - registerMob(EntityType.AXOLOTL, new AxolotlAdapter(), "62d90ad63dd826df02994abdcc6c2306163e1072d1b9e63ad4e7d7d1cf87cdf9"); - // https://minecraft-heads.com/custom-heads/decoration/46397-spawn-egg-goat - registerMob(EntityType.GOAT, new GoatAdapter(), "33f7fe31285bd2ca74516b07852e079447f524fd9cc0b7d4db003b165d5b4b4"); - } - if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_19)) { + // https://minecraft-heads.com/custom-heads/decoration/46398-spawn-egg-axolotl + registerMob(EntityType.AXOLOTL, new AxolotlAdapter(), "62d90ad63dd826df02994abdcc6c2306163e1072d1b9e63ad4e7d7d1cf87cdf9"); + // https://minecraft-heads.com/custom-heads/decoration/46397-spawn-egg-goat + registerMob(EntityType.GOAT, new GoatAdapter(), "33f7fe31285bd2ca74516b07852e079447f524fd9cc0b7d4db003b165d5b4b4"); + if (MinecraftVersionUtil.isAtLeast(19)) { // https://minecraft-heads.com/custom-heads/decoration/56964-spawn-egg-frog registerMob(EntityType.FROG, new FrogAdapter(), "2d767bfee87d1d301084c74dadade50fc49263a465e4c1065549dbf8403f194c"); } - if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_20)) { - // https://minecraft-heads.com/custom-heads/decoration/62266-sniffer-egg - registerMob(EntityType.SNIFFER, new SnifferAdapter(), "bae445d1392cb559a68b4f4401e1aa3ec5e7f9e89c0b62632bccf0ac3b41b4b"); + if (MinecraftVersionUtil.isAtLeast(20)) { + // https://minecraft-heads.com/custom-heads/head/84109-spawn-egg-sniffer + registerMob(EntityType.SNIFFER, new SnifferAdapter(), "a9946dda3e6162dfaf37921bab6bd31b87a3000624848b65eca1efe73167c960"); + } + if (MinecraftVersionUtil.isAtLeast(20, 5)) { + // https://minecraft-heads.com/custom-heads/head/74256-armadillo + // TODO: use a spawn egg texture when available + registerMob(EntityType.ARMADILLO, new AnimalsAdapter<>(Armadillo.class), "c9c1e96ce985725e22ed6ccf0f4c4810c729a2538b97bda06faeb3b92799c878"); } - // + // - // + // // https://minecraft-heads.com/custom-heads/decoration/961-spawn-egg-slime registerMob(EntityType.SLIME, new SlimeAdapter<>(Slime.class), "9330af17f8512ed3b49e78bca7ef2d83f2dc1e598a8cb542ecc3b6becee9f57"); // https://minecraft-heads.com/custom-heads/decoration/962-spawn-egg-spider @@ -202,13 +213,18 @@ private static void setupMobEggs() { registerMob(EntityType.SILVERFISH, new StandardMobAdapter<>(Silverfish.class), "d06310a8952b265c6e6bed4348239ddea8e5482c8c68be6fff981ba8056bf2e"); // https://minecraft-heads.com/custom-heads/decoration/933-spawn-egg-bat registerMob(EntityType.BAT, new StandardMobAdapter<>(Bat.class), "93c8aa3fde295fa9f9c27f734bdbab11d33a2e43e855accd7465352377413b"); - if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_19)) { + if (MinecraftVersionUtil.isAtLeast(19)) { // https://minecraft-heads.com/custom-heads/decoration/56963-spawn-egg-allay registerMob(EntityType.ALLAY, new AllayAdapter(), "6c3f114efbd908284c7aadd81993769057361dd756bf5e7883b8e0b1cea446e7"); } - // + if (MinecraftVersionUtil.isAtLeast(21)) { + // https://minecraft-heads.com/custom-heads/head/68476-breeze + // TODO: use a spawn egg texture when available + registerMob(EntityType.BREEZE, new StandardMobAdapter<>(Breeze.class), "cd6e602f76f80c0657b5aed64e267eeea702b31e6dae86346c8506f2535ced02"); + } + // - // + // // https://minecraft-heads.com/custom-heads/decoration/942-spawn-egg-squid registerMob(EntityType.SQUID, new StandardMobAdapter<>(Squid.class), "449088861fc1e14b605a5154d79fa7dd65e041a5c635d24744b3e152535"); // https://minecraft-heads.com/custom-heads/decoration/957-spawn-egg-guardian @@ -217,13 +233,11 @@ private static void setupMobEggs() { registerMob(EntityType.ELDER_GUARDIAN, new StandardMobAdapter<>(ElderGuardian.class), "9a839d8256c81cf1db8da8ff3f7b80cce2f865b80c9f66aea5340e697ea3e219"); // https://minecraft-heads.com/custom-heads/decoration/23591-spawn-egg-dolphin registerMob(EntityType.DOLPHIN, new StandardMobAdapter<>(Dolphin.class), "2480cd9577e2173e1c9de5e41318bd859696215a0a7de9242f01c01b8e6c06bf"); - if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_17)) { - // https://minecraft-heads.com/custom-heads/decoration/48544-spawn-egg-glow-squid - registerMob(EntityType.GLOW_SQUID, new GlowSquidAdapter(), "e5d31559261b3e79024751fe07b711c8feef51d56c03635226955805bc42894e"); - } - // + // https://minecraft-heads.com/custom-heads/decoration/48544-spawn-egg-glow-squid + registerMob(EntityType.GLOW_SQUID, new GlowSquidAdapter(), "e5d31559261b3e79024751fe07b711c8feef51d56c03635226955805bc42894e"); + // - // + // // https://minecraft-heads.com/custom-heads/decoration/944-spawn-egg-wolf registerMob(EntityType.WOLF, new WolfAdapter(), "4399c973d6496d1d258492c28d4c95956ac3a253762bf15f7644af1f5728dd"); // https://minecraft-heads.com/custom-heads/decoration/938-spawn-egg-ocelot @@ -232,9 +246,9 @@ private static void setupMobEggs() { registerMob(EntityType.CAT, new CatAdapter(), "f2154e385f9ccb187b53cf290fe9a24f98c7d583c368986c7806c312c3f29d79"); // https://minecraft-heads.com/custom-heads/decoration/23588-spawn-egg-parrot registerMob(EntityType.PARROT, new ParrotAdapter(), "6eabd8fffc0371877e88ffc3cd0315200534dd2fcc6034588000736fb80033e5"); - // + // - // + // // https://minecraft-heads.com/custom-heads/decoration/945-spawn-egg-blaze registerMob(EntityType.BLAZE, new StandardMobAdapter<>(Blaze.class), "533acae6e075a578ccfc7dc2d5a15dbccfa8f59c609f9703889ef54c742c56"); // https://minecraft-heads.com/custom-heads/decoration/958-spawn-egg-magma-cube @@ -253,7 +267,7 @@ private static void setupMobEggs() { registerMob(EntityType.ZOGLIN, new ZoglinAdapter(), "debc97935d49df69911c008145b9c2d8906a11b0aa38effd8d50fe7b9682a7a0"); // https://minecraft-heads.com/custom-heads/decoration/48539-spawn-egg-strider registerMob(EntityType.STRIDER, new StriderAdapter(), "3820f04b3f177c0463a05697766f3bdaf6fa28f1ac163572e27fde7c78afe7be"); - // + // // // https://minecraft-heads.com/custom-heads/decoration/953-spawn-egg-enderman @@ -262,16 +276,16 @@ private static void setupMobEggs() { registerMob(EntityType.SHULKER, new ShulkerAdapter(), "d04252216231b3f744c9ff4ace7084ae9f4164f8b384c65410848a19617af4d"); // https://minecraft-heads.com/custom-heads/decoration/954-spawn-egg-endermite registerMob(EntityType.ENDERMITE, new EndermiteAdapter(), "3beac501e97db1cc035287d068a8eb538e55ef802f5cca25683933a243136c"); - // + // - // + // // unknown source - registerMob(EntityType.SNOWMAN, new SnowmanAdapter(), "2e4385d58fe46dd96422f31d35bbd1568e5819bbdb7a196c9f113424582cf977"); + registerMob(EntityTypeX.SNOW_GOLEM, new SnowmanAdapter(), "2e4385d58fe46dd96422f31d35bbd1568e5819bbdb7a196c9f113424582cf977"); // unknown source registerMob(EntityType.IRON_GOLEM, new IronGolemAdapter(), "c442c228f099fdfc1c6b46dfc80b252d81f7fb1739deb16ee7a597c17f7c9"); - // + // - // + // // https://minecraft-heads.com/custom-heads/decoration/963-spawn-egg-witch registerMob(EntityType.WITCH, new RaiderAdapter<>(Witch.class), "afbdceef773d959b49ddd9615f4269c176e23154d45752667428dc4e3fd4d"); // https://minecraft-heads.com/custom-heads/decoration/23578-spawn-egg-vindicator @@ -286,9 +300,9 @@ private static void setupMobEggs() { registerMob(EntityType.ILLUSIONER, new MagicIllagerAdapter<>(Illusioner.class), "ff1eeb387d55b0886a69b6ec62a6e69706f32aba2547e10583060b976341f9be"); // https://minecraft-heads.com/custom-heads/decoration/23708-spawn-egg-vex registerMob(EntityType.VEX, new VexAdapter(), "dc7eb861fd9999bf87a300e3ddd03c57313ddfba221d1c7d4bd62cef31446ca1"); - // + // - // + // // https://minecraft-heads.com/custom-heads/decoration/23711-spawn-egg-cod-fish registerMob(EntityType.COD, new StandardMobAdapter<>(Cod.class), "bd29b25579f9d3a67b612ae8ef96b31feca6c9e7e6c70ac81156d778cbe7db9d"); // https://minecraft-heads.com/custom-heads/decoration/23586-spawn-egg-salmon @@ -297,13 +311,13 @@ private static void setupMobEggs() { registerMob(EntityType.PUFFERFISH, new PufferFishAdapter(), "5d5e7d191478efafe23a654de802760f42a0dd83dfc9817f87d460fcf32978df"); // https://minecraft-heads.com/custom-heads/decoration/23712-spawn-egg-tropical-fish registerMob(EntityType.TROPICAL_FISH, new TropicalFishAdapter(), "2e4385d58fe46dd96422f31d35bbd1568e5819bbdb7a196c9f113424582cf977"); - if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_19)) { + if (MinecraftVersionUtil.isAtLeast(19)) { // https://minecraft-heads.com/custom-heads/decoration/56962-spawn-egg-tadpole - registerMob(EntityType.TADPOLE, new TadpoleAdapter(), "d1f04d08180a7a5cc63055587a2ecde5ac86f9f48f0e3b0ee3a986638877aeef"); // not egg texture, bucket of tadpole + registerMob(EntityType.TADPOLE, new TadpoleAdapter(), "d1f04d08180a7a5cc63055587a2ecde5ac86f9f48f0e3b0ee3a986638877aeef"); } - // + // - // + // // https://minecraft-heads.com/custom-heads/decoration/936-spawn-egg-horse registerMob(EntityType.HORSE, new HorseAdapter(), "5c6d5abbf68ccb2386bf16af25ac38d8b77bb0e043152461bd97f3f630dbb8bc"); // https://minecraft-heads.com/custom-heads/decoration/23905-spawn-egg-donkey @@ -318,22 +332,27 @@ private static void setupMobEggs() { registerMob(EntityType.LLAMA, new LlamaAdapter<>(Llama.class), "5cbc6bd92728d79cfa6d8f23cbae9d912f495920b9e95ef691a1967fef8a4453"); // https://minecraft-heads.com/custom-heads/decoration/48537-spawn-egg-wandering-trader-llama registerMob(EntityType.TRADER_LLAMA, new LlamaAdapter<>(TraderLlama.class), "73ca3bfb6602a96a57369cbc85eba8bb53df796d0df3dbc3798fa3d8e9e30275"); - if (Slimefun.getMinecraftVersion().isAtLeast(MinecraftVersion.MINECRAFT_1_20)) { - // https://minecraft-heads.com/custom-heads/animals/58939-camel - registerMob(EntityType.CAMEL, new CamelAdapter<>(Camel.class), "74b8a333dfa92e7e5a95ad4ae2d84b1bafa33dc28c054925277f60e79dafc8c4"); // no egg texture + if (MinecraftVersionUtil.isAtLeast(20)) { + // https://minecraft-heads.com/custom-heads/head/84108-spawn-egg-camel + registerMob(EntityType.CAMEL, new CamelAdapter<>(Camel.class), "11e9bf25f3458da2e5dddac0a6ae81ed256c5510b507094781b9c4682cbf5d0d"); } - // + // - // + // // https://minecraft-heads.com/custom-heads/decoration/960-spawn-egg-skeleton registerMob(EntityType.SKELETON, new SkeletonAdapter<>(Skeleton.class), "377055cadacbb0f8f35c1d18acc2ed86e0bcc6d73dda71e4c59f7ea28b7b27b6"); // https://minecraft-heads.com/custom-heads/decoration/23707-spawn-egg-wither-skeleton registerMob(EntityType.WITHER_SKELETON, new SkeletonAdapter<>(WitherSkeleton.class), "337223d01906ab63af1a15988343b8637e85930b905c35125b545b398c59e1c5"); // https://minecraft-heads.com/custom-heads/decoration/23705-spawn-egg-stray registerMob(EntityType.STRAY, new SkeletonAdapter<>(Stray.class), "5b45aae241779f0617ffaff468f3f2cf666d2f8a803002f9ae1ba0f14ed79fdd"); - // + if (MinecraftVersionUtil.isAtLeast(21)) { + // https://minecraft-heads.com/custom-heads/head/87691-bogged + // TODO: use a spawn egg texture when available + registerMob(EntityType.BOGGED, new SkeletonAdapter<>(Bogged.class), "a3b9003ba2d05562c75119b8a62185c67130e9282f7acbac4bc2824c21eb95d9"); + } + // - // + // // https://minecraft-heads.com/custom-heads/decoration/964-spawn-egg-zombie registerMob(EntityType.ZOMBIE, new ZombieAdapter<>(Zombie.class), "77f844bfea25429d45e1fcf96ef6654dfaaa6fc902dc1b6b68c0abc1343447"); // https://minecraft-heads.com/custom-heads/decoration/23590-spawn-egg-drowned @@ -342,14 +361,14 @@ private static void setupMobEggs() { registerMob(EntityType.HUSK, new ZombieAdapter<>(Husk.class), "40fd8d86e7057aae33f5d79dcb03685c88c8137cfcb2349bc874b9f87e934276"); // https://minecraft-heads.com/custom-heads/decoration/23583-spawn-egg-zombie-villager registerMob(EntityType.ZOMBIE_VILLAGER, new ZombieVillagerAdapter(), "364b4c94dda909ecc778db93572b847a5df51c4a49894d6a9df59b8df97842c5"); - // + // } @ParametersAreNonnullByDefault - private static void registerMob(EntityType type, MobAdapter adapter, - String eggTexture) { + private static void registerMob(EntityType type, MobAdapter adapter, String eggTexture) { String name = ChatUtils.humanize(type.name()); + // @formatter:off MobEgg egg = new MobEgg<>( ItemGroups.MOB_EGGS, ItemStacks.buildMobEgg(type, eggTexture), @@ -361,6 +380,7 @@ null, new CustomItemStack(SlimefunUtils.getCustomHead(eggTexture), ChatColor.WHI null, null, null } ); + // @formatter:on egg.register(MobCapturer.getInstance()); diff --git a/src/main/java/io/github/thebusybiscuit/mobcapturer/utils/JsonUtils.java b/src/main/java/io/github/thebusybiscuit/mobcapturer/utils/JsonUtils.java new file mode 100644 index 0000000..1c52f46 --- /dev/null +++ b/src/main/java/io/github/thebusybiscuit/mobcapturer/utils/JsonUtils.java @@ -0,0 +1,29 @@ +package io.github.thebusybiscuit.mobcapturer.utils; + +import java.lang.reflect.Type; +import java.util.Map; + +import javax.annotation.Nonnull; + +import com.google.common.base.Preconditions; +import com.google.gson.Gson; +import com.google.gson.JsonObject; +import com.google.gson.reflect.TypeToken; + +import lombok.experimental.UtilityClass; + +@UtilityClass +public final class JsonUtils { + + private static final Gson GSON = new Gson(); + + @Nonnull + public static Map toMap(@Nonnull JsonObject obj) { + Preconditions.checkArgument(obj != null, "JsonObject cannot be null"); + + // @formatter:off + Type type = new TypeToken>() {}.getType(); + // @formatter:on + return GSON.fromJson(obj, type); + } +} diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml deleted file mode 100644 index 613c0ae..0000000 --- a/src/main/resources/plugin.yml +++ /dev/null @@ -1,10 +0,0 @@ -name: MobCapturer -version: ${project.version} -author: TheBusyBiscuit -description: A Slimefun Addon that adds a tool that allows you to capture mobs -website: https://github.com/TheBusyBiscuit/MobCapturer - -main: io.github.thebusybiscuit.mobcapturer.MobCapturer -depend: [Slimefun] - -api-version: 1.16