From e1e39927f3f46fda88456cfaaadacb45185aa96e Mon Sep 17 00:00:00 2001 From: William Date: Thu, 13 Jun 2024 15:23:01 +0100 Subject: [PATCH] feat: add Fabric 1.20.1/6 support --- .github/workflows/ci.yml | 4 +- .github/workflows/release.yml | 4 +- README.md | 11 +-- build.gradle | 1 + .../uniform/element/ArgumentElement.java | 1 + .../uniform/element/LiteralElement.java | 1 + fabric-1.20.1/build.gradle | 19 +++++ .../uniform/fabric/FabricCommand.java | 70 +++++++++++++++++++ .../uniform/fabric/FabricUniform.java | 70 +++++++++++++++++++ fabric-1.20.6/build.gradle | 19 +++++ .../uniform/fabric/FabricCommand.java | 70 +++++++++++++++++++ .../uniform/fabric/FabricUniform.java | 70 +++++++++++++++++++ settings.gradle | 10 +++ 13 files changed, 341 insertions(+), 9 deletions(-) create mode 100644 fabric-1.20.1/build.gradle create mode 100644 fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricCommand.java create mode 100644 fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricUniform.java create mode 100644 fabric-1.20.6/build.gradle create mode 100644 fabric-1.20.6/src/main/java/net/william278/uniform/fabric/FabricCommand.java create mode 100644 fabric-1.20.6/src/main/java/net/william278/uniform/fabric/FabricUniform.java diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0bd8d2f..be30218 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -18,10 +18,10 @@ jobs: steps: - name: 'Checkout for CI 🛎️' uses: actions/checkout@v4 - - name: 'Set up JDK 17 📦' + - name: 'Set up JDK 21 📦' uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'temurin' - name: 'Build with Gradle 🏗️' uses: gradle/gradle-build-action@v3 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 4cbc6e7..ddd2b39 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,10 +15,10 @@ jobs: steps: - name: 'Checkout for CI 🛎️' uses: actions/checkout@v4 - - name: 'Set up JDK 17 📦' + - name: 'Set up JDK 21 📦' uses: actions/setup-java@v4 with: - java-version: '17' + java-version: '21' distribution: 'temurin' - name: 'Build with Gradle 🏗️' uses: gradle/gradle-build-action@v3 diff --git a/README.md b/README.md index 357033d..c802515 100644 --- a/README.md +++ b/README.md @@ -17,16 +17,17 @@ Uniform _currently_ targets the following platforms, (in addition to `uniform-common` which you can compile against in multi-platform plugins): -| Platform | Artifact | Version | Java | -|----------------|--------------------|------------|:-----:| -| Paper | `uniform-paper` | \>`1.20.4` | >`17` | -| Velocity | `uniform-velocity` | \>`3.3.0` | >`17` | +| Platform | Artifact | Minecraft | Java | +|---------------|-------------------------|:----------:|:-----:| +| Paper | `uniform-paper` | \>`1.20.4` | >`17` | +| Velocity | `uniform-velocity` | \>`3.3.0` | >`17` | +| Fabric 1.20.1 | `uniform-fabric-1.20.1` | =`1.20.1` | >`17` | +| Fabric 1.20.6 | `uniform-fabric-1.20.6` | =`1.20.6` | >`21` | Uniform _plans_ to support the following platforms: | Platform | Version | Java | |----------------|------------|:-----:| -| Fabric | =`1.20.6` | >`21` | | Spigot† | \>`1.17.1` | >`17` | † Brigadier commands are wrapped into non-brigadier Bukkit plugin commands for legacy Spigot support. diff --git a/build.gradle b/build.gradle index c39bc95..f2c4bc0 100644 --- a/build.gradle +++ b/build.gradle @@ -59,6 +59,7 @@ allprojects { mavenCentral() maven { url 'https://repo.papermc.io/repository/maven-public/' } maven { url 'https://libraries.minecraft.net/' } + maven { url 'https://maven.fabricmc.net/' } } dependencies { diff --git a/common/src/main/java/net/william278/uniform/element/ArgumentElement.java b/common/src/main/java/net/william278/uniform/element/ArgumentElement.java index 9365e3a..037f87c 100644 --- a/common/src/main/java/net/william278/uniform/element/ArgumentElement.java +++ b/common/src/main/java/net/william278/uniform/element/ArgumentElement.java @@ -39,4 +39,5 @@ public record ArgumentElement(@NotNull String name, @NotNull ArgumentType< if (this.suggestionProvider != null) builder.suggests(this.suggestionProvider); return builder; } + } \ No newline at end of file diff --git a/common/src/main/java/net/william278/uniform/element/LiteralElement.java b/common/src/main/java/net/william278/uniform/element/LiteralElement.java index 3684658..c18c1b8 100644 --- a/common/src/main/java/net/william278/uniform/element/LiteralElement.java +++ b/common/src/main/java/net/william278/uniform/element/LiteralElement.java @@ -32,4 +32,5 @@ public record LiteralElement(@NotNull String name) implements CommandElement< public ArgumentBuilder toBuilder() { return LiteralArgumentBuilder.literal(this.name); } + } \ No newline at end of file diff --git a/fabric-1.20.1/build.gradle b/fabric-1.20.1/build.gradle new file mode 100644 index 0000000..a01956a --- /dev/null +++ b/fabric-1.20.1/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'fabric-loom' version '1.6-SNAPSHOT' + id 'java-library' + id 'maven-publish' +} + +dependencies { + api project(path: ':common') + + minecraft 'com.mojang:minecraft:1.20.1' + mappings 'net.fabricmc:yarn:1.20.1+build.10:v2' + + modCompileOnly 'net.fabricmc:fabric-loader:0.15.11' + modCompileOnly 'net.fabricmc.fabric-api:fabric-api:0.92.2+1.20.1' + + compileOnly 'org.projectlombok:lombok:1.18.32' + + annotationProcessor 'org.projectlombok:lombok:1.18.32' +} \ No newline at end of file diff --git a/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricCommand.java b/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricCommand.java new file mode 100644 index 0000000..592d1e2 --- /dev/null +++ b/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricCommand.java @@ -0,0 +1,70 @@ +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform.fabric; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.util.Identifier; +import net.minecraft.util.InvalidIdentifierException; +import net.william278.uniform.Command; +import net.william278.uniform.element.ArgumentElement; +import org.jetbrains.annotations.NotNull; + +@SuppressWarnings("unused") +public class FabricCommand extends Command { + + public FabricCommand(@NotNull String name, @NotNull String... aliases) { + super(name, aliases); + } + + protected static ArgumentElement itemArg(String name) { + return registryArg(name, Registries.ITEM); + } + + protected static ArgumentElement blockArg(String name) { + return registryArg(name, Registries.BLOCK); + } + + protected static ArgumentElement registryArg(String name, Registry registry) { + return new ArgumentElement<>(name, reader -> { + String itemId = reader.readString(); + final Identifier id; + try { + id = Identifier.tryParse(itemId); + } catch (InvalidIdentifierException e) { + throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(reader); + } + if (registry.getOrEmpty(id).isEmpty()) { + throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(reader); + } + return registry.get(id); + }, (context, builder) -> { + registry.getIds().forEach(id -> builder.suggest(id.toString())); + return builder.buildFuture(); + }); + } + +} diff --git a/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricUniform.java b/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricUniform.java new file mode 100644 index 0000000..2a768f6 --- /dev/null +++ b/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricUniform.java @@ -0,0 +1,70 @@ +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform.fabric; + + +import com.google.common.collect.Sets; +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.Set; + +/** + * A class for registering commands with the Fabric (1.20.1) server + * + * @since 1.0 + */ +public final class FabricUniform { + + private static FabricUniform INSTANCE; + + private final Set commands = Sets.newHashSet(); + + private FabricUniform() { + CommandRegistrationCallback.EVENT.register((dispatcher, registry, environment) -> + commands.forEach(command -> dispatcher.register(command.build().createBuilder())) + ); + } + + /** + * Get the FabricUniform instance for registering commands + * + * @return The FabricUniform instance + * @since 1.0 + */ + @NotNull + public static FabricUniform getInstance() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new FabricUniform()); + } + + /** + * Register a command to be added to the server's command manager + * + * @param commands The commands to register + * @since 1.0 + */ + public void register(@NotNull FabricCommand... commands) { + Collections.addAll(this.commands, commands); + } + +} diff --git a/fabric-1.20.6/build.gradle b/fabric-1.20.6/build.gradle new file mode 100644 index 0000000..fecb70c --- /dev/null +++ b/fabric-1.20.6/build.gradle @@ -0,0 +1,19 @@ +plugins { + id 'fabric-loom' version '1.6-SNAPSHOT' + id 'java-library' + id 'maven-publish' +} + +dependencies { + api project(path: ':common') + + minecraft 'com.mojang:minecraft:1.20.6' + mappings 'net.fabricmc:yarn:1.20.6+build.3:v2' + + modCompileOnly 'net.fabricmc:fabric-loader:0.15.11' + modCompileOnly 'net.fabricmc.fabric-api:fabric-api:0.100.0+1.20.6' + + compileOnly 'org.projectlombok:lombok:1.18.32' + + annotationProcessor 'org.projectlombok:lombok:1.18.32' +} \ No newline at end of file diff --git a/fabric-1.20.6/src/main/java/net/william278/uniform/fabric/FabricCommand.java b/fabric-1.20.6/src/main/java/net/william278/uniform/fabric/FabricCommand.java new file mode 100644 index 0000000..592d1e2 --- /dev/null +++ b/fabric-1.20.6/src/main/java/net/william278/uniform/fabric/FabricCommand.java @@ -0,0 +1,70 @@ +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform.fabric; + +import com.mojang.brigadier.exceptions.CommandSyntaxException; +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.util.Identifier; +import net.minecraft.util.InvalidIdentifierException; +import net.william278.uniform.Command; +import net.william278.uniform.element.ArgumentElement; +import org.jetbrains.annotations.NotNull; + +@SuppressWarnings("unused") +public class FabricCommand extends Command { + + public FabricCommand(@NotNull String name, @NotNull String... aliases) { + super(name, aliases); + } + + protected static ArgumentElement itemArg(String name) { + return registryArg(name, Registries.ITEM); + } + + protected static ArgumentElement blockArg(String name) { + return registryArg(name, Registries.BLOCK); + } + + protected static ArgumentElement registryArg(String name, Registry registry) { + return new ArgumentElement<>(name, reader -> { + String itemId = reader.readString(); + final Identifier id; + try { + id = Identifier.tryParse(itemId); + } catch (InvalidIdentifierException e) { + throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(reader); + } + if (registry.getOrEmpty(id).isEmpty()) { + throw CommandSyntaxException.BUILT_IN_EXCEPTIONS.dispatcherUnknownArgument().createWithContext(reader); + } + return registry.get(id); + }, (context, builder) -> { + registry.getIds().forEach(id -> builder.suggest(id.toString())); + return builder.buildFuture(); + }); + } + +} diff --git a/fabric-1.20.6/src/main/java/net/william278/uniform/fabric/FabricUniform.java b/fabric-1.20.6/src/main/java/net/william278/uniform/fabric/FabricUniform.java new file mode 100644 index 0000000..b158341 --- /dev/null +++ b/fabric-1.20.6/src/main/java/net/william278/uniform/fabric/FabricUniform.java @@ -0,0 +1,70 @@ +/* + * This file is part of Uniform, licensed under the GNU General Public License v3.0. + * + * Copyright (c) Tofaa2 + * Copyright (c) William278 + * Copyright (c) contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package net.william278.uniform.fabric; + + +import com.google.common.collect.Sets; +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import org.jetbrains.annotations.NotNull; + +import java.util.Collections; +import java.util.Set; + +/** + * A class for registering commands with the Fabric (1.20.6) server + * + * @since 1.0 + */ +public final class FabricUniform { + + private static FabricUniform INSTANCE; + + private final Set commands = Sets.newHashSet(); + + private FabricUniform() { + CommandRegistrationCallback.EVENT.register((dispatcher, registry, environment) -> + commands.forEach(command -> dispatcher.register(command.build().createBuilder())) + ); + } + + /** + * Get the FabricUniform instance for registering commands + * + * @return The FabricUniform instance + * @since 1.0 + */ + @NotNull + public static FabricUniform getInstance() { + return INSTANCE != null ? INSTANCE : (INSTANCE = new FabricUniform()); + } + + /** + * Register a command to be added to the server's command manager + * + * @param commands The commands to register + * @since 1.0 + */ + public void register(@NotNull FabricCommand... commands) { + Collections.addAll(this.commands, commands); + } + +} diff --git a/settings.gradle b/settings.gradle index c5ab759..02238ad 100644 --- a/settings.gradle +++ b/settings.gradle @@ -1,14 +1,24 @@ pluginManagement { repositories { gradlePluginPortal() + maven { url 'https://maven.fabricmc.net/' } } } rootProject.name = 'Uniform' include( 'common', + + // Server Plugins 'paper', + + // Proxy Plugins 'velocity', + // Fabric Server-Side Mods + 'fabric-1.20.1', + 'fabric-1.20.6', + + // Example plugin 'example-plugin' ) \ No newline at end of file