From d06ab326e38caeb1151fd0c2144067e100ed8559 Mon Sep 17 00:00:00 2001 From: Vlad <37305073+LuckyValenok@users.noreply.github.com> Date: Sun, 5 Jan 2025 00:39:02 +0300 Subject: [PATCH] feat: use multi-version for fabric (#54) --- build.gradle | 49 +++----- fabric-1.20.1/build.gradle | 42 ------- .../uniform/fabric/FabricCommand.java | 92 -------------- .../uniform/fabric/FabricUniform.java | 117 ------------------ fabric-1.21.1/build.gradle | 42 ------- .../uniform/fabric/FabricCommandUser.java | 61 --------- .../fabric/mixins/ArgumentNodeMixin.java | 53 -------- .../src/main/resources/fabric.mod.json | 32 ----- .../src/main/resources/uniform.accesswidener | 3 - .../src/main/resources/uniform.mixins.json | 13 -- fabric-1.21.4/build.gradle | 42 ------- .../uniform/fabric/FabricCommand.java | 92 -------------- .../uniform/fabric/FabricCommandUser.java | 61 --------- .../uniform/fabric/FabricUniform.java | 117 ------------------ .../fabric/mixins/ArgumentNodeMixin.java | 53 -------- .../src/main/resources/fabric.mod.json | 32 ----- .../src/main/resources/uniform.accesswidener | 3 - .../src/main/resources/uniform.mixins.json | 13 -- fabric/1.20.1/.gitkeep | 0 fabric/1.21.1/.gitkeep | 0 fabric/1.21.4/.gitkeep | 0 fabric/build.gradle | 52 ++++++++ fabric/gradle.properties | 9 ++ fabric/mainProject | 1 + fabric/root.gradle | 12 ++ .../uniform/fabric/FabricCommand.java | 0 .../uniform/fabric/FabricCommandUser.java | 0 .../uniform/fabric/FabricUniform.java | 0 .../fabric/mixins/ArgumentNodeMixin.java | 0 .../src/main/resources/fabric.mod.json | 0 .../src/main/resources/uniform.accesswidener | 0 .../src/main/resources/uniform.mixins.json | 0 gradle.properties | 2 +- gradle/wrapper/gradle-wrapper.properties | 2 +- settings.gradle | 31 ++++- 35 files changed, 119 insertions(+), 907 deletions(-) delete mode 100644 fabric-1.20.1/build.gradle delete mode 100644 fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricCommand.java delete mode 100644 fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricUniform.java delete mode 100644 fabric-1.21.1/build.gradle delete mode 100644 fabric-1.21.1/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java delete mode 100644 fabric-1.21.1/src/main/java/net/william278/uniform/fabric/mixins/ArgumentNodeMixin.java delete mode 100644 fabric-1.21.1/src/main/resources/fabric.mod.json delete mode 100644 fabric-1.21.1/src/main/resources/uniform.accesswidener delete mode 100644 fabric-1.21.1/src/main/resources/uniform.mixins.json delete mode 100644 fabric-1.21.4/build.gradle delete mode 100644 fabric-1.21.4/src/main/java/net/william278/uniform/fabric/FabricCommand.java delete mode 100644 fabric-1.21.4/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java delete mode 100644 fabric-1.21.4/src/main/java/net/william278/uniform/fabric/FabricUniform.java delete mode 100644 fabric-1.21.4/src/main/java/net/william278/uniform/fabric/mixins/ArgumentNodeMixin.java delete mode 100644 fabric-1.21.4/src/main/resources/fabric.mod.json delete mode 100644 fabric-1.21.4/src/main/resources/uniform.accesswidener delete mode 100644 fabric-1.21.4/src/main/resources/uniform.mixins.json create mode 100644 fabric/1.20.1/.gitkeep create mode 100644 fabric/1.21.1/.gitkeep create mode 100644 fabric/1.21.4/.gitkeep create mode 100644 fabric/build.gradle create mode 100644 fabric/gradle.properties create mode 100644 fabric/mainProject create mode 100644 fabric/root.gradle rename {fabric-1.21.1 => fabric}/src/main/java/net/william278/uniform/fabric/FabricCommand.java (100%) rename {fabric-1.20.1 => fabric}/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java (100%) rename {fabric-1.21.1 => fabric}/src/main/java/net/william278/uniform/fabric/FabricUniform.java (100%) rename {fabric-1.20.1 => fabric}/src/main/java/net/william278/uniform/fabric/mixins/ArgumentNodeMixin.java (100%) rename {fabric-1.20.1 => fabric}/src/main/resources/fabric.mod.json (100%) rename {fabric-1.20.1 => fabric}/src/main/resources/uniform.accesswidener (100%) rename {fabric-1.20.1 => fabric}/src/main/resources/uniform.mixins.json (100%) diff --git a/build.gradle b/build.gradle index 3e68210..c224c30 100644 --- a/build.gradle +++ b/build.gradle @@ -2,6 +2,7 @@ import org.apache.tools.ant.filters.ReplaceTokens plugins { id 'org.cadixdev.licenser' version '0.6.1' apply false + id 'gg.essential.multi-version.root' apply false id 'fabric-loom' version "$fabric_loom_version" apply false id 'io.github.goooler.shadow' version '8.1.8' id 'org.ajoberstar.grgit' version '5.3.0' @@ -51,6 +52,10 @@ publishing { } allprojects { + if (project.name == 'fabric') { + return + } + apply plugin: 'io.github.goooler.shadow' apply plugin: 'org.cadixdev.licenser' apply plugin: 'java' @@ -98,12 +103,20 @@ allprojects { } subprojects { - if (project.name.startsWith('fabric')) { + if (project.name == 'fabric') { + return + } + if (project.parent?.name?.equals('fabric')) { apply plugin: 'fabric-loom' } version rootProject.version - archivesBaseName = "${rootProject.name}-${project.name.capitalize()}" + def name = "$rootProject.name" + if (rootProject != project.parent) { + name += "-${project.parent.name.capitalize()}" + } + name += "-${project.name.capitalize()}" + archivesBaseName = name jar { from '../LICENSE' @@ -183,38 +196,12 @@ subprojects { } } - if (['fabric-1.20.1'].contains(project.name)) { - publications { - mavenJavaFabric1_20_1(MavenPublication) { - groupId = 'net.william278.uniform' - artifactId = 'uniform-fabric' - version = "${rootProject.version}+1.20.1" - artifact remapJar - artifact sourcesJar - artifact javadocJar - } - } - } - - if (['fabric-1.21.1'].contains(project.name)) { - publications { - mavenJavaFabric1_21_1(MavenPublication) { - groupId = 'net.william278.uniform' - artifactId = 'uniform-fabric' - version = "${rootProject.version}+1.21.1" - artifact remapJar - artifact sourcesJar - artifact javadocJar - } - } - } - - if (['fabric-1.21.4'].contains(project.name)) { + if (project.parent?.name?.equals('fabric')) { publications { - mavenJavaFabric1_21_4(MavenPublication) { + "mavenJavaFabric_${project.name.replace('.', '_')}"(MavenPublication) { groupId = 'net.william278.uniform' artifactId = 'uniform-fabric' - version = "${rootProject.version}+1.21.4" + version = "$rootProject.version+$project.name" artifact remapJar artifact sourcesJar artifact javadocJar diff --git a/fabric-1.20.1/build.gradle b/fabric-1.20.1/build.gradle deleted file mode 100644 index 3167d40..0000000 --- a/fabric-1.20.1/build.gradle +++ /dev/null @@ -1,42 +0,0 @@ -plugins { - id 'fabric-loom' version "$fabric_loom_version" - id 'java-library' - id 'maven-publish' -} - -dependencies { - minecraft 'com.mojang:minecraft:1.20.1' - mappings 'net.fabricmc:yarn:1.20.1+build.10:v2' - - modCompileOnly 'net.fabricmc:fabric-loader:0.16.9' - modCompileOnly 'net.fabricmc.fabric-api:fabric-api:0.92.2+1.20.1' - modImplementation include('me.lucko:fabric-permissions-api:0.3.1') - - modCompileOnly 'org.projectlombok:lombok:1.18.36' - annotationProcessor 'org.projectlombok:lombok:1.18.36' - - shadow project(path: ':common') -} - -loom.setAccessWidenerPath(file("src/main/resources/uniform.accesswidener")) - -shadowJar { - configurations = [project.configurations.shadow] - destinationDirectory.set(file("$projectDir/build/libs")) - - exclude('net.fabricmc:.*') - exclude('net.kyori:.*') - exclude '/mappings/*' -} - -remapJar { - dependsOn tasks.shadowJar - mustRunAfter tasks.shadowJar - inputFile = shadowJar.archiveFile.get() - addNestedDependencies = true - - destinationDirectory.set(file("$rootDir/target/")) - archiveClassifier.set('') -} - -shadowJar.finalizedBy(remapJar) \ 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 deleted file mode 100644 index 86982b9..0000000 --- a/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricCommand.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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.BaseCommand; -import net.william278.uniform.Command; -import net.william278.uniform.Uniform; -import net.william278.uniform.element.ArgumentElement; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -@SuppressWarnings("unused") -public class FabricCommand extends BaseCommand { - - public FabricCommand(@NotNull Command command) { - super(command); - } - - public FabricCommand(@NotNull String name, @NotNull List aliases) { - super(name, aliases); - } - - public FabricCommand(@NotNull String name, @NotNull String description, - @NotNull List aliases) { - super(name, description, aliases); - } - - public static ArgumentElement item(String name) { - return registry(name, Registries.ITEM); - } - - public static ArgumentElement block(String name) { - return registry(name, Registries.BLOCK); - } - - public static ArgumentElement registry(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(); - }); - } - - @Override - public void addSubCommand(@NotNull Command command) { - addSubCommand(new FabricCommand(command)); - } - - @Override - public Uniform getUniform() { - return FabricUniform.INSTANCE; - } -} 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 deleted file mode 100644 index 047a4df..0000000 --- a/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricUniform.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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 com.mojang.brigadier.builder.LiteralArgumentBuilder; -import lombok.Getter; -import lombok.Setter; -import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; -import net.minecraft.server.command.ServerCommandSource; -import net.william278.uniform.BaseCommand; -import net.william278.uniform.Command; -import net.william278.uniform.CommandUser; -import net.william278.uniform.Uniform; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.Locale; -import java.util.Set; -import java.util.function.Function; - -/** - * A class for registering commands with the Fabric (1.20.1) server - * - * @since 1.0 - */ -@SuppressWarnings("unused") -public final class FabricUniform implements Uniform { - - static FabricUniform INSTANCE; - - private final Set commands = Sets.newHashSet(); - @Getter - private final String modId; - - @Getter - @Setter - Function commandUserSupplier = (user) -> new FabricCommandUser((ServerCommandSource) user); - - private FabricUniform(@NotNull String modId) { - this.modId = modId.toLowerCase(Locale.ENGLISH).replaceAll("[^a-z0-9_-]", ""); - CommandRegistrationCallback.EVENT.register((dispatcher, registry, environment) -> - commands.forEach(command -> { - final LiteralArgumentBuilder builder = command.createBuilder(); - dispatcher.register(builder); - - final Set aliases = Sets.newHashSet(command.getAliases()); - command.getAliases().forEach(a -> aliases.add(modId + ":" + a)); - aliases.add(modId + ":" + command.getName()); - aliases.forEach(alias -> dispatcher.register( - LiteralArgumentBuilder.literal(alias) - .requires(builder.getRequirement()).executes(builder.getCommand()) - .redirect(builder.build()) - )); - }) - ); - - ServerLifecycleEvents.SERVER_STOPPED.register(server -> shutdown()); - } - - /** - * Get the FabricUniform instance for registering commands - * - * @return The FabricUniform instance - * @since 1.0 - */ - @NotNull - public static FabricUniform getInstance(@NotNull String modId) { - return INSTANCE != null ? INSTANCE : (INSTANCE = new FabricUniform(modId)); - } - - /** - * Register a command with the server's command manager - * - * @param commands The commands to register - * @param The command source type - * @param The command type - * @since 1.0 - */ - @SafeVarargs - @Override - public final > void register(T... commands) { - Arrays.stream(commands).map(c -> (FabricCommand) c).forEach(this.commands::add); - } - - /** - * Register a command with the server's command manager - * - * @param commands The commands to register - * @since 1.0 - */ - @Override - public void register(Command... commands) { - register(Arrays.stream(commands).map(FabricCommand::new).toArray(FabricCommand[]::new)); - } - -} diff --git a/fabric-1.21.1/build.gradle b/fabric-1.21.1/build.gradle deleted file mode 100644 index ebbf15f..0000000 --- a/fabric-1.21.1/build.gradle +++ /dev/null @@ -1,42 +0,0 @@ -plugins { - id 'fabric-loom' version "$fabric_loom_version" - id 'java-library' - id 'maven-publish' -} - -dependencies { - minecraft 'com.mojang:minecraft:1.21.1' - mappings 'net.fabricmc:yarn:1.21.1+build.3:v2' - - modCompileOnly 'net.fabricmc:fabric-loader:0.16.9' - modCompileOnly 'net.fabricmc.fabric-api:fabric-api:0.110.0+1.21.1' - modImplementation include('me.lucko:fabric-permissions-api:0.3.1') - - modCompileOnly 'org.projectlombok:lombok:1.18.36' - annotationProcessor 'org.projectlombok:lombok:1.18.36' - - shadow project(path: ':common') -} - -loom.setAccessWidenerPath(file("src/main/resources/uniform.accesswidener")) - -shadowJar { - configurations = [project.configurations.shadow] - destinationDirectory.set(file("$projectDir/build/libs")) - - exclude('net.fabricmc:.*') - exclude('net.kyori:.*') - exclude '/mappings/*' -} - -remapJar { - dependsOn tasks.shadowJar - mustRunAfter tasks.shadowJar - inputFile = shadowJar.archiveFile.get() - addNestedDependencies = true - - destinationDirectory.set(file("$rootDir/target/")) - archiveClassifier.set('') -} - -shadowJar.finalizedBy(remapJar) \ No newline at end of file diff --git a/fabric-1.21.1/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java b/fabric-1.21.1/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java deleted file mode 100644 index 9235845..0000000 --- a/fabric-1.21.1/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 me.lucko.fabric.api.permissions.v0.Permissions; -import net.kyori.adventure.audience.Audience; -import net.minecraft.server.command.ServerCommandSource; -import net.william278.uniform.CommandUser; -import net.william278.uniform.Permission; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.UUID; - -public record FabricCommandUser(@NotNull ServerCommandSource source) implements CommandUser { - - @Override - public @NotNull Audience getAudience() { - return (Audience) source.getPlayer(); - } - - @Override - @Nullable - public String getName() { - return source.getName(); - } - - @Override - @Nullable - public UUID getUuid() { - return source.getPlayer() != null ? source.getPlayer().getUuid() : null; - } - - @Override - public boolean checkPermission(@NotNull Permission permission) { - return Permissions.check( - source, permission.node(), - permission.defaultValue().check(source.hasPermissionLevel(4)) - ); - } - -} diff --git a/fabric-1.21.1/src/main/java/net/william278/uniform/fabric/mixins/ArgumentNodeMixin.java b/fabric-1.21.1/src/main/java/net/william278/uniform/fabric/mixins/ArgumentNodeMixin.java deleted file mode 100644 index e76f3da..0000000 --- a/fabric-1.21.1/src/main/java/net/william278/uniform/fabric/mixins/ArgumentNodeMixin.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.mixins; - -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.arguments.StringArgumentType; -import net.minecraft.command.argument.ArgumentTypes; -import net.minecraft.command.argument.serialize.ArgumentSerializer; -import net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket.ArgumentNode; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(ArgumentNode.class) -public class ArgumentNodeMixin { - - @Redirect( - method = "(Lcom/mojang/brigadier/tree/ArgumentCommandNode;)V", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/command/argument/ArgumentTypes;getArgumentTypeProperties(Lcom/mojang/brigadier/arguments/ArgumentType;)Lnet/minecraft/command/argument/serialize/ArgumentSerializer$ArgumentTypeProperties;" - ) - ) - private static ArgumentSerializer.ArgumentTypeProperties onConstruct(ArgumentType type) { - ArgumentSerializer.ArgumentTypeProperties properties; - try { - properties = ArgumentTypes.getArgumentTypeProperties(type); - } catch (IllegalArgumentException e) { - properties = ArgumentTypes.getArgumentTypeProperties(StringArgumentType.string()); - } - return properties; - } - -} diff --git a/fabric-1.21.1/src/main/resources/fabric.mod.json b/fabric-1.21.1/src/main/resources/fabric.mod.json deleted file mode 100644 index 2892d9e..0000000 --- a/fabric-1.21.1/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "schemaVersion": 1, - "id": "uniform", - "version": "${version}", - "description": "${description}", - "name": "uniform", - "authors": [ - "William278", - "Tofaa2" - ], - "contact": { - "homepage": "https://william278.net/project/uniform", - "issues": "https://github.com/WiIIiam278/Uniform/issues", - "sources": "https://github.com/WiIIiam278/Uniform" - }, - "license": "GPL-3.0", - "custom": { - "modmenu:api": true, - "modmenu": { - "badges": [ - "library" - ] - } - }, - "depends": { - "fabric-api": "*" - }, - "mixins": [ - "uniform.mixins.json" - ], - "accessWidener": "uniform.accesswidener" -} \ No newline at end of file diff --git a/fabric-1.21.1/src/main/resources/uniform.accesswidener b/fabric-1.21.1/src/main/resources/uniform.accesswidener deleted file mode 100644 index 95b5d4d..0000000 --- a/fabric-1.21.1/src/main/resources/uniform.accesswidener +++ /dev/null @@ -1,3 +0,0 @@ -accessWidener v2 named - -extendable class net/minecraft/network/packet/s2c/play/CommandTreeS2CPacket$ArgumentNode \ No newline at end of file diff --git a/fabric-1.21.1/src/main/resources/uniform.mixins.json b/fabric-1.21.1/src/main/resources/uniform.mixins.json deleted file mode 100644 index a838aec..0000000 --- a/fabric-1.21.1/src/main/resources/uniform.mixins.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "net.william278.uniform.fabric.mixins", - "compatibilityLevel": "JAVA_17", - "mixins": [], - "server": [ - "ArgumentNodeMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} \ No newline at end of file diff --git a/fabric-1.21.4/build.gradle b/fabric-1.21.4/build.gradle deleted file mode 100644 index 09ea643..0000000 --- a/fabric-1.21.4/build.gradle +++ /dev/null @@ -1,42 +0,0 @@ -plugins { - id 'fabric-loom' version "$fabric_loom_version" - id 'java-library' - id 'maven-publish' -} - -dependencies { - minecraft 'com.mojang:minecraft:1.21.4' - mappings 'net.fabricmc:yarn:1.21.4+build.1:v2' - - modCompileOnly 'net.fabricmc:fabric-loader:0.16.9' - modCompileOnly 'net.fabricmc.fabric-api:fabric-api:0.111.0+1.21.4' - modImplementation include('me.lucko:fabric-permissions-api:0.3.3') - - modCompileOnly 'org.projectlombok:lombok:1.18.36' - annotationProcessor 'org.projectlombok:lombok:1.18.36' - - shadow project(path: ':common') -} - -loom.setAccessWidenerPath(file("src/main/resources/uniform.accesswidener")) - -shadowJar { - configurations = [project.configurations.shadow] - destinationDirectory.set(file("$projectDir/build/libs")) - - exclude('net.fabricmc:.*') - exclude('net.kyori:.*') - exclude '/mappings/*' -} - -remapJar { - dependsOn tasks.shadowJar - mustRunAfter tasks.shadowJar - inputFile = shadowJar.archiveFile.get() - addNestedDependencies = true - - destinationDirectory.set(file("$rootDir/target/")) - archiveClassifier.set('') -} - -shadowJar.finalizedBy(remapJar) \ No newline at end of file diff --git a/fabric-1.21.4/src/main/java/net/william278/uniform/fabric/FabricCommand.java b/fabric-1.21.4/src/main/java/net/william278/uniform/fabric/FabricCommand.java deleted file mode 100644 index 7636741..0000000 --- a/fabric-1.21.4/src/main/java/net/william278/uniform/fabric/FabricCommand.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * 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.BaseCommand; -import net.william278.uniform.Command; -import net.william278.uniform.Uniform; -import net.william278.uniform.element.ArgumentElement; -import org.jetbrains.annotations.NotNull; - -import java.util.List; - -@SuppressWarnings("unused") -public class FabricCommand extends BaseCommand { - - public FabricCommand(@NotNull Command command) { - super(command); - } - - public FabricCommand(@NotNull String name, @NotNull List aliases) { - super(name, aliases); - } - - public FabricCommand(@NotNull String name, @NotNull String description, - @NotNull List aliases) { - super(name, description, aliases); - } - - public static ArgumentElement item(String name) { - return registry(name, Registries.ITEM); - } - - public static ArgumentElement block(String name) { - return registry(name, Registries.BLOCK); - } - - public static ArgumentElement registry(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.containsId(id)) { - 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(); - }); - } - - @Override - public void addSubCommand(@NotNull Command command) { - addSubCommand(new FabricCommand(command)); - } - - @Override - public Uniform getUniform() { - return FabricUniform.INSTANCE; - } -} diff --git a/fabric-1.21.4/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java b/fabric-1.21.4/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java deleted file mode 100644 index 9235845..0000000 --- a/fabric-1.21.4/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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 me.lucko.fabric.api.permissions.v0.Permissions; -import net.kyori.adventure.audience.Audience; -import net.minecraft.server.command.ServerCommandSource; -import net.william278.uniform.CommandUser; -import net.william278.uniform.Permission; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.UUID; - -public record FabricCommandUser(@NotNull ServerCommandSource source) implements CommandUser { - - @Override - public @NotNull Audience getAudience() { - return (Audience) source.getPlayer(); - } - - @Override - @Nullable - public String getName() { - return source.getName(); - } - - @Override - @Nullable - public UUID getUuid() { - return source.getPlayer() != null ? source.getPlayer().getUuid() : null; - } - - @Override - public boolean checkPermission(@NotNull Permission permission) { - return Permissions.check( - source, permission.node(), - permission.defaultValue().check(source.hasPermissionLevel(4)) - ); - } - -} diff --git a/fabric-1.21.4/src/main/java/net/william278/uniform/fabric/FabricUniform.java b/fabric-1.21.4/src/main/java/net/william278/uniform/fabric/FabricUniform.java deleted file mode 100644 index b90aa6f..0000000 --- a/fabric-1.21.4/src/main/java/net/william278/uniform/fabric/FabricUniform.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * 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 com.mojang.brigadier.builder.LiteralArgumentBuilder; -import lombok.Getter; -import lombok.Setter; -import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; -import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; -import net.minecraft.server.command.ServerCommandSource; -import net.william278.uniform.BaseCommand; -import net.william278.uniform.Command; -import net.william278.uniform.CommandUser; -import net.william278.uniform.Uniform; -import org.jetbrains.annotations.NotNull; - -import java.util.Arrays; -import java.util.Locale; -import java.util.Set; -import java.util.function.Function; - -/** - * A class for registering commands with the Fabric (1.21) server - * - * @since 1.0 - */ -@SuppressWarnings("unused") -public final class FabricUniform implements Uniform { - - static FabricUniform INSTANCE; - - private final Set commands = Sets.newHashSet(); - @Getter - private final String modId; - - @Getter - @Setter - Function commandUserSupplier = (user) -> new FabricCommandUser((ServerCommandSource) user); - - private FabricUniform(@NotNull String modId) { - this.modId = modId.toLowerCase(Locale.ENGLISH).replaceAll("[^a-z0-9_-]", ""); - CommandRegistrationCallback.EVENT.register((dispatcher, registry, environment) -> - commands.forEach(command -> { - final LiteralArgumentBuilder builder = command.createBuilder(); - dispatcher.register(builder); - - final Set aliases = Sets.newHashSet(command.getAliases()); - command.getAliases().forEach(a -> aliases.add(modId + ":" + a)); - aliases.add(modId + ":" + command.getName()); - aliases.forEach(alias -> dispatcher.register( - LiteralArgumentBuilder.literal(alias) - .requires(builder.getRequirement()).executes(builder.getCommand()) - .redirect(builder.build()) - )); - }) - ); - - ServerLifecycleEvents.SERVER_STOPPED.register(server -> shutdown()); - } - - /** - * Get the FabricUniform instance for registering commands - * - * @return The FabricUniform instance - * @since 1.0 - */ - @NotNull - public static FabricUniform getInstance(@NotNull String modId) { - return INSTANCE != null ? INSTANCE : (INSTANCE = new FabricUniform(modId)); - } - - /** - * Register a command with the server's command manager - * - * @param commands The commands to register - * @param The command source type - * @param The command type - * @since 1.0 - */ - @SafeVarargs - @Override - public final > void register(T... commands) { - Arrays.stream(commands).map(c -> (FabricCommand) c).forEach(this.commands::add); - } - - /** - * Register a command with the server's command manager - * - * @param commands The commands to register - * @since 1.0 - */ - @Override - public void register(Command... commands) { - register(Arrays.stream(commands).map(FabricCommand::new).toArray(FabricCommand[]::new)); - } - -} diff --git a/fabric-1.21.4/src/main/java/net/william278/uniform/fabric/mixins/ArgumentNodeMixin.java b/fabric-1.21.4/src/main/java/net/william278/uniform/fabric/mixins/ArgumentNodeMixin.java deleted file mode 100644 index e76f3da..0000000 --- a/fabric-1.21.4/src/main/java/net/william278/uniform/fabric/mixins/ArgumentNodeMixin.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * 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.mixins; - -import com.mojang.brigadier.arguments.ArgumentType; -import com.mojang.brigadier.arguments.StringArgumentType; -import net.minecraft.command.argument.ArgumentTypes; -import net.minecraft.command.argument.serialize.ArgumentSerializer; -import net.minecraft.network.packet.s2c.play.CommandTreeS2CPacket.ArgumentNode; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Redirect; - -@Mixin(ArgumentNode.class) -public class ArgumentNodeMixin { - - @Redirect( - method = "(Lcom/mojang/brigadier/tree/ArgumentCommandNode;)V", - at = @At( - value = "INVOKE", - target = "Lnet/minecraft/command/argument/ArgumentTypes;getArgumentTypeProperties(Lcom/mojang/brigadier/arguments/ArgumentType;)Lnet/minecraft/command/argument/serialize/ArgumentSerializer$ArgumentTypeProperties;" - ) - ) - private static ArgumentSerializer.ArgumentTypeProperties onConstruct(ArgumentType type) { - ArgumentSerializer.ArgumentTypeProperties properties; - try { - properties = ArgumentTypes.getArgumentTypeProperties(type); - } catch (IllegalArgumentException e) { - properties = ArgumentTypes.getArgumentTypeProperties(StringArgumentType.string()); - } - return properties; - } - -} diff --git a/fabric-1.21.4/src/main/resources/fabric.mod.json b/fabric-1.21.4/src/main/resources/fabric.mod.json deleted file mode 100644 index 2892d9e..0000000 --- a/fabric-1.21.4/src/main/resources/fabric.mod.json +++ /dev/null @@ -1,32 +0,0 @@ -{ - "schemaVersion": 1, - "id": "uniform", - "version": "${version}", - "description": "${description}", - "name": "uniform", - "authors": [ - "William278", - "Tofaa2" - ], - "contact": { - "homepage": "https://william278.net/project/uniform", - "issues": "https://github.com/WiIIiam278/Uniform/issues", - "sources": "https://github.com/WiIIiam278/Uniform" - }, - "license": "GPL-3.0", - "custom": { - "modmenu:api": true, - "modmenu": { - "badges": [ - "library" - ] - } - }, - "depends": { - "fabric-api": "*" - }, - "mixins": [ - "uniform.mixins.json" - ], - "accessWidener": "uniform.accesswidener" -} \ No newline at end of file diff --git a/fabric-1.21.4/src/main/resources/uniform.accesswidener b/fabric-1.21.4/src/main/resources/uniform.accesswidener deleted file mode 100644 index 95b5d4d..0000000 --- a/fabric-1.21.4/src/main/resources/uniform.accesswidener +++ /dev/null @@ -1,3 +0,0 @@ -accessWidener v2 named - -extendable class net/minecraft/network/packet/s2c/play/CommandTreeS2CPacket$ArgumentNode \ No newline at end of file diff --git a/fabric-1.21.4/src/main/resources/uniform.mixins.json b/fabric-1.21.4/src/main/resources/uniform.mixins.json deleted file mode 100644 index a838aec..0000000 --- a/fabric-1.21.4/src/main/resources/uniform.mixins.json +++ /dev/null @@ -1,13 +0,0 @@ -{ - "required": true, - "minVersion": "0.8", - "package": "net.william278.uniform.fabric.mixins", - "compatibilityLevel": "JAVA_17", - "mixins": [], - "server": [ - "ArgumentNodeMixin" - ], - "injectors": { - "defaultRequire": 1 - } -} \ No newline at end of file diff --git a/fabric/1.20.1/.gitkeep b/fabric/1.20.1/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/fabric/1.21.1/.gitkeep b/fabric/1.21.1/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/fabric/1.21.4/.gitkeep b/fabric/1.21.4/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/fabric/build.gradle b/fabric/build.gradle new file mode 100644 index 0000000..9f5b910 --- /dev/null +++ b/fabric/build.gradle @@ -0,0 +1,52 @@ +plugins { + id 'gg.essential.multi-version' + id 'gg.essential.defaults' + id 'java-library' +} + +dependencies { + def fabricApiVersion + def fabricPermissionsApiVersion = "0.3.1" + if (platform.mcVersion == 12001) { + fabricApiVersion = "0.92.2+1.20.1" + } else if (platform.mcVersion == 12101) { + fabricApiVersion = "0.110.0+1.21.1" + } else if (platform.mcVersion == 12104) { + fabricApiVersion = "0.111.0+1.21.4" + fabricPermissionsApiVersion = "0.3.3" + } else { + throw org.gradle.api.GradleException("Unsupported platform $platform") + } + + modCompileOnly "net.fabricmc.fabric-api:fabric-api:$fabricApiVersion" + + modImplementation include("me.lucko:fabric-permissions-api:$fabricPermissionsApiVersion") + + modCompileOnly 'org.projectlombok:lombok:1.18.36' + annotationProcessor 'org.projectlombok:lombok:1.18.36' + + shadow project(path: ':common') +} + +loom.setAccessWidenerPath(parent.file("src/main/resources/uniform.accesswidener")) + +shadowJar { + configurations = [project.configurations.shadow] + destinationDirectory.set(file("$projectDir/build/libs")) + + exclude('net.fabricmc:.*') + exclude('net.kyori:.*') + exclude '/mappings/*' +} + +remapJar { + dependsOn tasks.shadowJar + mustRunAfter tasks.shadowJar + inputFile = shadowJar.archiveFile.get() + addNestedDependencies = true + + destinationDirectory.set(file("$rootDir/target/")) + archiveClassifier.set('') +} + +shadowJar.finalizedBy(remapJar) \ No newline at end of file diff --git a/fabric/gradle.properties b/fabric/gradle.properties new file mode 100644 index 0000000..d470a57 --- /dev/null +++ b/fabric/gradle.properties @@ -0,0 +1,9 @@ +loom.platform=fabric + +essential.defaults.loom=1 + +org.gradle.daemon=false +org.gradle.parallel=true +org.gradle.configureoncommand=true +org.gradle.parallel.threads=4 +org.gradle.jvmargs=-Xmx8G \ No newline at end of file diff --git a/fabric/mainProject b/fabric/mainProject new file mode 100644 index 0000000..3d8ac63 --- /dev/null +++ b/fabric/mainProject @@ -0,0 +1 @@ +1.21.4 \ No newline at end of file diff --git a/fabric/root.gradle b/fabric/root.gradle new file mode 100644 index 0000000..f1432dc --- /dev/null +++ b/fabric/root.gradle @@ -0,0 +1,12 @@ +plugins { + id("gg.essential.multi-version.root") +} + +preprocess { + def fabric12104 = createNode("1.21.4", 12104, "yarn") + def fabric12101 = createNode("1.21.1", 12101, "yarn") + def fabric12001 = createNode("1.20.1", 12001, "yarn") + + fabric12101.link(fabric12104, null) + fabric12001.link(fabric12104, null) +} \ No newline at end of file diff --git a/fabric-1.21.1/src/main/java/net/william278/uniform/fabric/FabricCommand.java b/fabric/src/main/java/net/william278/uniform/fabric/FabricCommand.java similarity index 100% rename from fabric-1.21.1/src/main/java/net/william278/uniform/fabric/FabricCommand.java rename to fabric/src/main/java/net/william278/uniform/fabric/FabricCommand.java diff --git a/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java b/fabric/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java similarity index 100% rename from fabric-1.20.1/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java rename to fabric/src/main/java/net/william278/uniform/fabric/FabricCommandUser.java diff --git a/fabric-1.21.1/src/main/java/net/william278/uniform/fabric/FabricUniform.java b/fabric/src/main/java/net/william278/uniform/fabric/FabricUniform.java similarity index 100% rename from fabric-1.21.1/src/main/java/net/william278/uniform/fabric/FabricUniform.java rename to fabric/src/main/java/net/william278/uniform/fabric/FabricUniform.java diff --git a/fabric-1.20.1/src/main/java/net/william278/uniform/fabric/mixins/ArgumentNodeMixin.java b/fabric/src/main/java/net/william278/uniform/fabric/mixins/ArgumentNodeMixin.java similarity index 100% rename from fabric-1.20.1/src/main/java/net/william278/uniform/fabric/mixins/ArgumentNodeMixin.java rename to fabric/src/main/java/net/william278/uniform/fabric/mixins/ArgumentNodeMixin.java diff --git a/fabric-1.20.1/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json similarity index 100% rename from fabric-1.20.1/src/main/resources/fabric.mod.json rename to fabric/src/main/resources/fabric.mod.json diff --git a/fabric-1.20.1/src/main/resources/uniform.accesswidener b/fabric/src/main/resources/uniform.accesswidener similarity index 100% rename from fabric-1.20.1/src/main/resources/uniform.accesswidener rename to fabric/src/main/resources/uniform.accesswidener diff --git a/fabric-1.20.1/src/main/resources/uniform.mixins.json b/fabric/src/main/resources/uniform.mixins.json similarity index 100% rename from fabric-1.20.1/src/main/resources/uniform.mixins.json rename to fabric/src/main/resources/uniform.mixins.json diff --git a/gradle.properties b/gradle.properties index c16534c..aeff3a5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,7 +3,7 @@ javaVersion=17 org.gradle.jvmargs='-Dfile.encoding=UTF-8' org.gradle.daemon=true -fabric_loom_version=1.8-SNAPSHOT +fabric_loom_version=1.9-SNAPSHOT library_version=1.2.3 library_archive=uniform diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 9355b41..94113f2 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.11-bin.zip networkTimeout=10000 validateDistributionUrl=true zipStoreBase=GRADLE_USER_HOME diff --git a/settings.gradle b/settings.gradle index 909dbb2..cbe9b7d 100644 --- a/settings.gradle +++ b/settings.gradle @@ -2,6 +2,15 @@ pluginManagement { repositories { gradlePluginPortal() maven { url 'https://maven.fabricmc.net/' } + maven { url 'https://maven.architectury.dev/' } + maven { url 'https://maven.minecraftforge.net' } + maven { url 'https://repo.essential.gg/repository/maven-public' } + } + + plugins { + def egtVersion = "0.6.5" + id("gg.essential.defaults") version egtVersion + id("gg.essential.multi-version.root") version egtVersion } } @@ -17,11 +26,21 @@ include( // Proxy Plugins 'velocity', - // Fabric Server-Side Mods - 'fabric-1.20.1', - 'fabric-1.21.1', - 'fabric-1.21.4', - // Example plugin 'example-plugin' -) \ No newline at end of file +) + +// Fabric Server-Side Mods +include("fabric") +project(":fabric").with { + projectDir = file("fabric/") + buildFileName = "root.gradle" +} + +file('fabric').listFiles((FileFilter) ((File file) -> file.isDirectory() && file.name ==~ /(\d+)\.(\d+)(\.(\d+))?/)).each { + include("fabric:$it.name") + project(":fabric:$it.name").with { + projectDir = file("fabric/${it.name}") + buildFileName = '../build.gradle' + } +} \ No newline at end of file