rewrite template for ignite 1.0.0
This commit is contained in:
parent
285e53cbb9
commit
ec138cc92b
21 changed files with 210 additions and 316 deletions
|
@ -2,17 +2,27 @@ plugins {
|
|||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven {
|
||||
url = uri("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
dependencies {
|
||||
implementation(libs.build.paperweight)
|
||||
implementation(libs.build.shadow)
|
||||
implementation(libs.build.spotless)
|
||||
}
|
||||
|
||||
dependencies {
|
||||
val indraVersion = "3.0.1"
|
||||
implementation("net.kyori", "indra-common", indraVersion)
|
||||
implementation("net.kyori", "indra-licenser-spotless", indraVersion)
|
||||
implementation("gradle.plugin.com.github.johnrengelman", "shadow", "7.1.2")
|
||||
implementation("io.papermc.paperweight.userdev", "io.papermc.paperweight.userdev.gradle.plugin", "1.5.0")
|
||||
compileOnly(files(libs.javaClass.superclass.protectionDomain.codeSource.location))
|
||||
}
|
||||
|
||||
java {
|
||||
sourceCompatibility = JavaVersion.VERSION_11
|
||||
targetCompatibility = JavaVersion.VERSION_11
|
||||
}
|
||||
|
||||
kotlin {
|
||||
target {
|
||||
compilations.configureEach {
|
||||
kotlinOptions {
|
||||
jvmTarget = "11"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
14
build-logic/settings.gradle.kts
Normal file
14
build-logic/settings.gradle.kts
Normal file
|
@ -0,0 +1,14 @@
|
|||
rootProject.name = "ignite-template-build-logic"
|
||||
|
||||
dependencyResolutionManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
|
||||
versionCatalogs {
|
||||
register("libs") {
|
||||
from(files("../gradle/libs.versions.toml")) // include from parent project
|
||||
}
|
||||
}
|
||||
}
|
6
build-logic/src/main/kotlin/extensions.kt
Normal file
6
build-logic/src/main/kotlin/extensions.kt
Normal file
|
@ -0,0 +1,6 @@
|
|||
import org.gradle.api.plugins.JavaPluginExtension
|
||||
import org.gradle.jvm.toolchain.JavaLanguageVersion
|
||||
|
||||
fun JavaPluginExtension.javaTarget(version: Int) {
|
||||
toolchain.languageVersion.set(JavaLanguageVersion.of(version))
|
||||
}
|
|
@ -1,60 +1,87 @@
|
|||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar
|
||||
import com.diffplug.gradle.spotless.FormatExtension
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.nio.file.Files
|
||||
import java.util.regex.Pattern
|
||||
import java.util.stream.Collectors
|
||||
|
||||
plugins {
|
||||
id("net.kyori.indra")
|
||||
id("net.kyori.indra.licenser.spotless")
|
||||
`java-library`
|
||||
id("com.diffplug.spotless")
|
||||
|
||||
id("com.github.johnrengelman.shadow")
|
||||
id("io.papermc.paperweight.userdev")
|
||||
}
|
||||
|
||||
configurations {
|
||||
val shadeApi = create("shadeApi")
|
||||
val shadeImplementation = create("shadeImplementation")
|
||||
// Expose version catalog
|
||||
val libs = extensions.getByType(org.gradle.accessors.dm.LibrariesForLibs::class)
|
||||
|
||||
api { extendsFrom(shadeApi) }
|
||||
implementation { extendsFrom(shadeImplementation) }
|
||||
java {
|
||||
javaTarget(17)
|
||||
withSourcesJar()
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven {
|
||||
url = uri("https://oss.sonatype.org/content/groups/public/")
|
||||
}
|
||||
maven {
|
||||
url = uri("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
maven {
|
||||
url = uri("https://repo.spongepowered.org/maven/")
|
||||
}
|
||||
maven("https://oss.sonatype.org/content/groups/public/")
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
maven("https://repo.spongepowered.org/maven/")
|
||||
}
|
||||
|
||||
indra {
|
||||
javaVersions {
|
||||
target(17)
|
||||
}
|
||||
|
||||
mitLicense()
|
||||
dependencies {
|
||||
compileOnlyApi(libs.jetbrains.annotations)
|
||||
}
|
||||
|
||||
val jar = tasks.named<Jar>("jar")
|
||||
spotless {
|
||||
fun FormatExtension.applyCommon() {
|
||||
trimTrailingWhitespace()
|
||||
endWithNewline()
|
||||
indentWithSpaces(2)
|
||||
}
|
||||
|
||||
val shadowJar = tasks.named<ShadowJar>("shadowJar") {
|
||||
configurations = listOf(project.configurations.named("shadeApi").get(), project.configurations.named("shadeImplementation").get())
|
||||
fun formatLicense(): String {
|
||||
val splitPattern = Pattern.compile("\r?\n")
|
||||
val lineSeparator = System.lineSeparator()
|
||||
val headerPrefix = "/*$lineSeparator"
|
||||
val linePrefix = " * "
|
||||
val headerSuffix = "$lineSeparator */"
|
||||
|
||||
from(jar)
|
||||
val headerText = String(Files.readAllBytes(rootProject.file("license_header.txt").toPath()), StandardCharsets.UTF_8)
|
||||
|
||||
return splitPattern.splitAsStream(headerText)
|
||||
.map {
|
||||
StringBuilder(it.length + 4)
|
||||
.append(linePrefix)
|
||||
.append(it)
|
||||
.toString()
|
||||
}
|
||||
.collect(Collectors.joining(
|
||||
lineSeparator,
|
||||
headerPrefix,
|
||||
headerSuffix
|
||||
))
|
||||
}
|
||||
|
||||
|
||||
java {
|
||||
licenseHeader(formatLicense())
|
||||
applyCommon()
|
||||
}
|
||||
|
||||
kotlin {
|
||||
applyCommon()
|
||||
}
|
||||
}
|
||||
|
||||
tasks {
|
||||
build {
|
||||
dependsOn(reobfJar)
|
||||
jar {
|
||||
archiveClassifier.set("dev")
|
||||
}
|
||||
|
||||
reobfJar {
|
||||
remapperArgs.add("--mixin")
|
||||
}
|
||||
}
|
||||
|
||||
artifacts {
|
||||
archives(shadowJar)
|
||||
build {
|
||||
dependsOn(reobfJar)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,13 +1,10 @@
|
|||
plugins {
|
||||
id("mod.base-conventions")
|
||||
id("mod.base-conventions")
|
||||
}
|
||||
|
||||
group = "com.example"
|
||||
version = "1.0.0-SNAPSHOT"
|
||||
|
||||
dependencies {
|
||||
implementation(libs.ignite)
|
||||
implementation(libs.mixin)
|
||||
compileOnly(libs.ignite)
|
||||
compileOnly(libs.mixin)
|
||||
|
||||
paperweight.paperDevBundle("1.19.3-R0.1-SNAPSHOT")
|
||||
paperweight.paperDevBundle(libs.versions.paper)
|
||||
}
|
||||
|
|
5
gradle.properties
Normal file
5
gradle.properties
Normal file
|
@ -0,0 +1,5 @@
|
|||
group=com.example
|
||||
version=1.0.0-SNAPSHOT
|
||||
description=Example mod for Ignite
|
||||
|
||||
org.gradle.parallel=true
|
|
@ -2,12 +2,20 @@ metadata.format.version = "1.1"
|
|||
|
||||
[versions]
|
||||
|
||||
ignite = "0.8.0"
|
||||
jetbrains = "24.1.0"
|
||||
ignite = "1.0.0-SNAPSHOT"
|
||||
mixin = "0.8.5"
|
||||
paperweight = "1.5.11"
|
||||
shadow = "8.1.1"
|
||||
spotless = "6.23.3"
|
||||
paper = "1.20.4-R0.1-SNAPSHOT"
|
||||
|
||||
[libraries]
|
||||
jetbrains-annotations = { module = "org.jetbrains:annotations", version.ref = "jetbrains" }
|
||||
|
||||
ignite = { group = "space.vectrix.ignite", name = "ignite-api", version.ref = "ignite" }
|
||||
mixin = { group = "org.spongepowered", name = "mixin", version.ref = "mixin" }
|
||||
|
||||
|
||||
build-paperweight = { module = "io.papermc.paperweight.userdev:io.papermc.paperweight.userdev.gradle.plugin", version.ref = "paperweight" }
|
||||
build-shadow = { module = "com.github.johnrengelman:shadow", version.ref = "shadow" }
|
||||
build-spotless = { module = "com.diffplug.spotless:spotless-plugin-gradle", version.ref = "spotless" }
|
||||
|
|
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
BIN
gradle/wrapper/gradle-wrapper.jar
vendored
Binary file not shown.
3
gradle/wrapper/gradle-wrapper.properties
vendored
3
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,5 +1,6 @@
|
|||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-bin.zip
|
||||
networkTimeout=10000
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
|
18
gradlew
vendored
18
gradlew
vendored
|
@ -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,10 +80,10 @@ 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##*/}
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
# 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"'
|
||||
|
@ -143,12 +143,16 @@ fi
|
|||
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=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=SC3045
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
|
@ -205,6 +209,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.
|
||||
|
|
15
gradlew.bat
vendored
15
gradlew.bat
vendored
|
@ -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,7 +41,7 @@ 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.
|
||||
|
@ -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
|
||||
|
|
|
@ -1,13 +1,15 @@
|
|||
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
|
||||
enableFeaturePreview("VERSION_CATALOGS")
|
||||
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
includeBuild("build-logic")
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven("https://repo.papermc.io/repository/maven-public/")
|
||||
}
|
||||
}
|
||||
|
||||
rootProject.name = "ignite-mod-template"
|
||||
plugins {
|
||||
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
|
||||
}
|
||||
|
||||
includeBuild("build-logic")
|
||||
enableFeaturePreview("TYPESAFE_PROJECT_ACCESSORS")
|
||||
|
||||
rootProject.name = "ignite-mod-template"
|
||||
|
|
|
@ -1,59 +0,0 @@
|
|||
/*
|
||||
* This file is part of Ignite, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) vectrix.space <https://vectrix.space/>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.example;
|
||||
|
||||
import org.spongepowered.configurate.objectmapping.ConfigSerializable;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Comment;
|
||||
import org.spongepowered.configurate.objectmapping.meta.Setting;
|
||||
|
||||
@ConfigSerializable
|
||||
public final class ExampleConfig {
|
||||
@Setting(value = "test")
|
||||
@Comment(value = "Test configuration property.")
|
||||
private boolean test;
|
||||
|
||||
@Setting(value = "container")
|
||||
@Comment(value = "A test container.")
|
||||
private TestContainer container;
|
||||
|
||||
public boolean test() {
|
||||
return this.test;
|
||||
}
|
||||
|
||||
public TestContainer container() {
|
||||
return this.container;
|
||||
}
|
||||
|
||||
@ConfigSerializable
|
||||
public static class TestContainer {
|
||||
@Setting(value = "foo")
|
||||
@Comment(value = "A test boolean in a container.")
|
||||
private boolean foo;
|
||||
|
||||
public boolean foo() {
|
||||
return this.foo;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,55 +0,0 @@
|
|||
/*
|
||||
* This file is part of Ignite, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) vectrix.space <https://vectrix.space/>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.example;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import space.vectrix.ignite.api.Blackboard;
|
||||
import space.vectrix.ignite.api.config.Configuration;
|
||||
|
||||
import java.nio.file.Path;
|
||||
|
||||
public final class ExampleInfo {
|
||||
private static final @MonotonicNonNull Path CONFIGS_PATH = Blackboard.getProperty(Blackboard.CONFIG_DIRECTORY_PATH);
|
||||
|
||||
private static @MonotonicNonNull Path EXAMPLE_PATH;
|
||||
private static Configuration.@MonotonicNonNull Key<ExampleConfig> EXAMPLE_CONFIG;
|
||||
|
||||
public static @MonotonicNonNull Path getExamplePath() {
|
||||
if (ExampleInfo.EXAMPLE_PATH != null) return ExampleInfo.EXAMPLE_PATH;
|
||||
if (ExampleInfo.CONFIGS_PATH == null) return null;
|
||||
|
||||
return ExampleInfo.EXAMPLE_PATH = ExampleInfo.CONFIGS_PATH.resolve("example");
|
||||
}
|
||||
|
||||
public static Configuration.@NonNull Key<ExampleConfig> getExampleConfig() {
|
||||
if (ExampleInfo.EXAMPLE_CONFIG != null) return ExampleInfo.EXAMPLE_CONFIG;
|
||||
|
||||
final Path examplePath = ExampleInfo.getExamplePath();
|
||||
if (examplePath == null) throw new IllegalStateException("Unable to locate example path.");
|
||||
|
||||
return ExampleInfo.EXAMPLE_CONFIG = Configuration.key(ExampleConfig.class, examplePath.resolve("example.conf"));
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
/*
|
||||
* This file is part of Ignite, licensed under the MIT License (MIT).
|
||||
*
|
||||
* Copyright (c) vectrix.space <https://vectrix.space/>
|
||||
* Copyright (c) contributors
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documentation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furnished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
package com.example;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import space.vectrix.ignite.api.Platform;
|
||||
import space.vectrix.ignite.api.config.Configuration;
|
||||
import space.vectrix.ignite.api.config.Configurations;
|
||||
import space.vectrix.ignite.api.event.Subscribe;
|
||||
import space.vectrix.ignite.api.event.platform.PlatformInitializeEvent;
|
||||
|
||||
public final class ExampleMod {
|
||||
private final Logger logger;
|
||||
private final Platform platform;
|
||||
|
||||
@Inject
|
||||
public ExampleMod(final Logger logger,
|
||||
final Platform platform) {
|
||||
this.logger = logger;
|
||||
this.platform = platform;
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onInitialize(final @NonNull PlatformInitializeEvent event) {
|
||||
this.logger.info("Hello Example!");
|
||||
|
||||
final Configuration<ExampleConfig, CommentedConfigurationNode> configWrapper = Configurations.getOrCreate(Configurations.HOCON_LOADER, ExampleInfo.getExampleConfig());
|
||||
final ExampleConfig config = configWrapper.instance();
|
||||
if (config != null) {
|
||||
this.logger.info("Foo is set to: " + (config.container().foo() ? "Enabled" : "Disabled"));
|
||||
}
|
||||
}
|
||||
}
|
|
@ -29,20 +29,20 @@ import org.bukkit.command.defaults.BukkitCommand;
|
|||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class HelloCommand extends BukkitCommand {
|
||||
public HelloCommand(final @NonNull String name) {
|
||||
super(name);
|
||||
public HelloCommand(final @NonNull String name) {
|
||||
super(name);
|
||||
|
||||
this.setPermission("example.hello");
|
||||
this.setPermission("example.hello");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final @NonNull CommandSender commandSender, final @NonNull String currentAlias, final @NonNull String[] args) {
|
||||
if (!this.testPermission(commandSender)) {
|
||||
return true;
|
||||
} else {
|
||||
commandSender.sendMessage("Hello " + commandSender.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean execute(final @NonNull CommandSender commandSender, final @NonNull String currentAlias, final @NonNull String[] args) {
|
||||
if (!this.testPermission(commandSender)) {
|
||||
return true;
|
||||
} else {
|
||||
commandSender.sendMessage("Hello " + commandSender.getName());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,21 +24,20 @@
|
|||
*/
|
||||
package com.example.mixin.core;
|
||||
|
||||
import org.bukkit.craftbukkit.v1_19_R2.CraftServer;
|
||||
import java.util.logging.Logger;
|
||||
import org.bukkit.craftbukkit.v1_20_R3.CraftServer;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@Mixin(value = CraftServer.class)
|
||||
public abstract class MixinCraftServer {
|
||||
@Shadow public abstract Logger getLogger();
|
||||
@Shadow public abstract Logger getLogger();
|
||||
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
private void onConstruction(CallbackInfo callback) {
|
||||
this.getLogger().info("Hello World!");
|
||||
}
|
||||
@Inject(method = "<init>", at = @At("RETURN"))
|
||||
private void onConstruction(CallbackInfo callback) {
|
||||
this.getLogger().info("Hello World!");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,10 +35,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
|
||||
@Mixin(value = SimpleCommandMap.class)
|
||||
public abstract class MixinSimpleCommandMap {
|
||||
@Shadow public abstract boolean register(String fallbackPrefix, Command command);
|
||||
@Shadow public abstract boolean register(String fallbackPrefix, Command command);
|
||||
|
||||
@Inject(method = "setDefaultCommands()V", at = @At("TAIL"), remap = false)
|
||||
public void registerOwnCommands(CallbackInfo callback) {
|
||||
this.register("example", new HelloCommand("hello"));
|
||||
}
|
||||
@Inject(method = "setDefaultCommands()V", at = @At("TAIL"), remap = false)
|
||||
public void registerOwnCommands(CallbackInfo callback) {
|
||||
this.register("example", new HelloCommand("hello"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,55 +24,43 @@
|
|||
*/
|
||||
package com.example.mixin.plugins;
|
||||
|
||||
import com.example.ExampleConfig;
|
||||
import com.example.ExampleInfo;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
|
||||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import space.vectrix.ignite.api.config.Configuration;
|
||||
import space.vectrix.ignite.api.config.Configurations;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public final class CorePlugin implements IMixinConfigPlugin {
|
||||
@Override
|
||||
public void onLoad(final @NonNull String mixinPackage) {
|
||||
}
|
||||
@Override
|
||||
public void onLoad(final @NotNull String mixinPackage) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String getRefMapperConfig() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public @Nullable String getRefMapperConfig() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldApplyMixin(final @NonNull String targetClassName, final @NonNull String mixinClassName) {
|
||||
final Configuration<ExampleConfig, CommentedConfigurationNode> configWrapper = Configurations.getOrCreate(Configurations.HOCON_LOADER, ExampleInfo.getExampleConfig());
|
||||
final ExampleConfig config = configWrapper.instance();
|
||||
if (config != null) {
|
||||
return config.test();
|
||||
}
|
||||
@Override
|
||||
public boolean shouldApplyMixin(final @NotNull String targetClassName, final @NotNull String mixinClassName) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
public void acceptTargets(final @NotNull Set<String> myTargets, final @NotNull Set<String> otherTargets) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void acceptTargets(final @NonNull Set<String> myTargets, final @NonNull Set<String> otherTargets) {
|
||||
}
|
||||
@Override
|
||||
public @Nullable List<String> getMixins() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable List<String> getMixins() {
|
||||
return null;
|
||||
}
|
||||
@Override
|
||||
public void preApply(final @NotNull String targetClassName, final @NotNull ClassNode targetClass, final @NotNull String mixinClassName, final @NotNull IMixinInfo mixinInfo) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void preApply(final @NonNull String targetClassName, final @NonNull ClassNode targetClass, final @NonNull String mixinClassName, final @NonNull IMixinInfo mixinInfo) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postApply(final @NonNull String targetClassName, final @NonNull ClassNode targetClass, final @NonNull String mixinClassName, final @NonNull IMixinInfo mixinInfo) {
|
||||
}
|
||||
@Override
|
||||
public void postApply(final @NotNull String targetClassName, final @NotNull ClassNode targetClass, final @NotNull String mixinClassName, final @NotNull IMixinInfo mixinInfo) {
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,11 +1,7 @@
|
|||
{
|
||||
"id": "example",
|
||||
"version": "1.0.0",
|
||||
"entry": "com.example.ExampleMod",
|
||||
"dependencies": [
|
||||
"ignite"
|
||||
],
|
||||
"mixins": [
|
||||
"mixins.example.core.json"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,9 +4,9 @@
|
|||
"package": "com.example.mixin.core",
|
||||
"plugin": "com.example.mixin.plugins.CorePlugin",
|
||||
"target": "@env(DEFAULT)",
|
||||
"compatibilityLevel": "JAVA_8",
|
||||
"compatibilityLevel": "JAVA_17",
|
||||
"server": [
|
||||
"MixinCraftServer",
|
||||
"MixinSimpleCommandMap"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue