diff --git a/.gitignore b/.gitignore index c7e53fe1..d2943384 100644 --- a/.gitignore +++ b/.gitignore @@ -27,3 +27,5 @@ hs_err_pid* /.gradle /gradle.properties /copier.bat +run +/examples/fabric-mod/run/ diff --git a/examples/fabric-mod/build.gradle.kts b/examples/fabric-mod/build.gradle.kts new file mode 100644 index 00000000..db586d96 --- /dev/null +++ b/examples/fabric-mod/build.gradle.kts @@ -0,0 +1,45 @@ +buildscript { + repositories { + maven("https://maven.fabricmc.net/") + } +} + +plugins { + id("java") + id("fabric-loom") version "1.8-SNAPSHOT" +} + +repositories { + maven("https://libraries.minecraft.net") + maven("https://maven.fabricmc.net/") +} + +val minecraft_version = "1.21" +val yarn_mappings = "1.21+build.9" +val loader_version = "0.16.7" +val fabric_version = "0.102.0+1.21" +val permissions_version = "0.3.1" + +dependencies { + implementation(project(":common")) + implementation(project(":brigadier")) + modImplementation(project(":fabric")) + mappings("net.fabricmc:yarn:${yarn_mappings}:v2") + minecraft("com.mojang:minecraft:${minecraft_version}") + modImplementation("net.fabricmc:fabric-loader:${loader_version}") + include("me.lucko:fabric-permissions-api:${permissions_version}")?.let { modImplementation(it) } +} + +java.toolchain.languageVersion.set(JavaLanguageVersion.of(21)) + +tasks { + processResources { + filesMatching("fabric.mod.json") { + expand(mapOf( + "version" to project.version, + "loader_version" to loader_version, + "minecraft_version" to minecraft_version + )) + } + } +} diff --git a/examples/fabric-mod/src/main/java/com/example/mod/FabricTestMod.java b/examples/fabric-mod/src/main/java/com/example/mod/FabricTestMod.java new file mode 100644 index 00000000..4e0a7c91 --- /dev/null +++ b/examples/fabric-mod/src/main/java/com/example/mod/FabricTestMod.java @@ -0,0 +1,11 @@ +package com.example.mod; + +import net.fabricmc.api.DedicatedServerModInitializer; +import revxrsal.commands.fabric.FabricLamp; + +public class FabricTestMod implements DedicatedServerModInitializer { + @Override public void onInitializeServer() { + var lamp = FabricLamp.builder().build(); + lamp.register(new GreetCommand()); + } +} diff --git a/examples/fabric-mod/src/main/java/com/example/mod/GreetCommand.java b/examples/fabric-mod/src/main/java/com/example/mod/GreetCommand.java new file mode 100644 index 00000000..d03f57e0 --- /dev/null +++ b/examples/fabric-mod/src/main/java/com/example/mod/GreetCommand.java @@ -0,0 +1,41 @@ +/* + * This file is part of lamp, licensed under the MIT License. + * + * Copyright (c) Revxrsal + * + * 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.mod; + +import org.jetbrains.annotations.NotNull; +import revxrsal.commands.annotation.Command; +import revxrsal.commands.annotation.Default; +import revxrsal.commands.annotation.Description; +import revxrsal.commands.fabric.actor.FabricCommandActor; +import revxrsal.commands.fabric.annotation.CommandPermission; + +public class GreetCommand { + + @Command("greet") + @Description("Sends a greet to the user") + @CommandPermission("lampexample.command.greet") + public void greet(@NotNull FabricCommandActor actor, @Default("world") String who) { + actor.reply("Hello, " + who + "!"); + } +} diff --git a/examples/fabric-mod/src/main/resources/fabric.mod.json b/examples/fabric-mod/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..69ce2527 --- /dev/null +++ b/examples/fabric-mod/src/main/resources/fabric.mod.json @@ -0,0 +1,23 @@ +{ + "schemaVersion": 1, + "id": "lampexample", + "version": "${version}", + "name": "Lamp Example Mod", + "description": "", + "authors": [ + "Camper_Samu", + "Revxrsal" + ], + "contact": {}, + "license": "MIT", + "environment": "server", + "entrypoints": { + "server": [ + "com.example.mod.FabricTestMod" + ] + }, + "depends": { + "fabricloader": ">=${loader_version}", + "minecraft": "${minecraft_version}" + } +} diff --git a/fabric/build.gradle.kts b/fabric/build.gradle.kts index 3f46079d..4801ac28 100644 --- a/fabric/build.gradle.kts +++ b/fabric/build.gradle.kts @@ -6,7 +6,7 @@ buildscript { plugins { id("java") - id("fabric-loom") version "1.7-SNAPSHOT" + id("fabric-loom") version "1.8-SNAPSHOT" } repositories { @@ -14,10 +14,12 @@ repositories { maven("https://maven.fabricmc.net/") } -val minecraft_version = "1.20.1" -val yarn_mappings = "1.20.1+build.6" -val loader_version = "0.14.21" -val fabric_version = "0.86.0+1.20.1" +val minecraft_version = "1.21" +val yarn_mappings = "1.21+build.9" +val loader_version = "0.16.7" +val fabric_version = "0.102.0+1.21" +val permissions_version = "0.3.1" +val java_version = 21 dependencies { implementation(project(":common")) @@ -26,6 +28,21 @@ dependencies { mappings("net.fabricmc:yarn:${yarn_mappings}:v2") modImplementation("net.fabricmc:fabric-loader:${loader_version}") modImplementation("net.fabricmc.fabric-api:fabric-api:${fabric_version}") + include("me.lucko:fabric-permissions-api:${permissions_version}")?.let { modImplementation(it) } } -java.toolchain.languageVersion.set(JavaLanguageVersion.of(21)) +java.toolchain.languageVersion.set(JavaLanguageVersion.of(java_version)) + +tasks { + processResources { + filesMatching("fabric.mod.json") { + expand(mapOf( + "version" to project.version, + "java_version" to java_version, + "loader_version" to loader_version, + "fabric_version" to fabric_version, + "minecraft_version" to minecraft_version + )) + } + } +} diff --git a/fabric/src/main/java/revxrsal/commands/fabric/actor/FabricCommandActor.java b/fabric/src/main/java/revxrsal/commands/fabric/actor/FabricCommandActor.java index bd23ad57..099a4fd3 100644 --- a/fabric/src/main/java/revxrsal/commands/fabric/actor/FabricCommandActor.java +++ b/fabric/src/main/java/revxrsal/commands/fabric/actor/FabricCommandActor.java @@ -190,6 +190,6 @@ default void sendRawError(@NotNull String message) { */ @Override @NotNull default String name() { - return isConsole() ? "Console" : requirePlayer().getEntityName(); + return isConsole() ? "Console" : requirePlayer().getName().getString(); } } diff --git a/fabric/src/main/java/revxrsal/commands/fabric/annotation/CommandPermission.java b/fabric/src/main/java/revxrsal/commands/fabric/annotation/CommandPermission.java index ea3c3199..d4fc942a 100644 --- a/fabric/src/main/java/revxrsal/commands/fabric/annotation/CommandPermission.java +++ b/fabric/src/main/java/revxrsal/commands/fabric/annotation/CommandPermission.java @@ -1,5 +1,7 @@ package revxrsal.commands.fabric.annotation; +import me.lucko.fabric.api.permissions.v0.Permissions; +import net.minecraft.command.CommandSource; import net.minecraft.server.command.ServerCommandSource; import revxrsal.commands.annotation.DistributeOnMethods; import revxrsal.commands.annotation.NotSender; @@ -19,10 +21,17 @@ public @interface CommandPermission { /** - * The permission value. This is passed to {@link ServerCommandSource#hasPermissionLevel(int)} + * The permission string. This is passed to {@link Permissions#check(CommandSource, String, int)} (CommandSource, String)} * * @return The permission value */ - int value(); + String value(); + + /** + * The Vanilla permission value to be used as a fallback. This is passed to {@link Permissions#check(CommandSource, String, int)} + * + * @return The fallback Vanilla permission value + */ + int vanilla() default 4; } diff --git a/fabric/src/main/java/revxrsal/commands/fabric/sender/FabricPermissionFactory.java b/fabric/src/main/java/revxrsal/commands/fabric/sender/FabricPermissionFactory.java index bfee843c..73f72497 100644 --- a/fabric/src/main/java/revxrsal/commands/fabric/sender/FabricPermissionFactory.java +++ b/fabric/src/main/java/revxrsal/commands/fabric/sender/FabricPermissionFactory.java @@ -1,5 +1,6 @@ package revxrsal.commands.fabric.sender; +import me.lucko.fabric.api.permissions.v0.Permissions; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import revxrsal.commands.Lamp; @@ -15,6 +16,6 @@ public enum FabricPermissionFactory implements revxrsal.commands.command.Command CommandPermission permissionAnn = annotations.get(CommandPermission.class); if (permissionAnn == null) return null; - return actor -> actor.source().hasPermissionLevel(permissionAnn.value()); + return actor -> Permissions.check(actor.source(), permissionAnn.value(), permissionAnn.vanilla()); } } diff --git a/fabric/src/main/resources/assets/lamp/icon.png b/fabric/src/main/resources/assets/lamp/icon.png new file mode 100644 index 00000000..8f2f2dac Binary files /dev/null and b/fabric/src/main/resources/assets/lamp/icon.png differ diff --git a/fabric/src/main/resources/fabric.mod.json b/fabric/src/main/resources/fabric.mod.json new file mode 100644 index 00000000..79cde13f --- /dev/null +++ b/fabric/src/main/resources/fabric.mod.json @@ -0,0 +1,32 @@ +{ + "schemaVersion": 1, + "id": "lamp", + "version": "${version}", + "name": "Lamp", + "description": "A modern annotations-driven commands framework for Java and Kotlin", + "authors": [ + "Revxrsal", + "Camper_Samu" + ], + "contact": { + "homepage": "https://foxhut.gitbook.io/lamp-docs", + "sources": "https://github.com/Revxrsal/Lamp", + "issues": "https://github.com/Revxrsal/Lamp/issues" + }, + "license": "GPLv3", + "icon": "assets/lamp/icon.png", + "environment": "*", + "depends": { + "fabricloader": ">=${loader_version}", + "fabric": ">=${fabric_version}", + "minecraft": ">=${minecraft_version}", + "java": ">=${java_version}" + }, + "custom": { + "modmenu": { + "links": { + "modmenu.discord": "https://discord.gg/pEGGF785zp" + } + } + } +} diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 35fb2dfe..4884044d 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,6 +1,6 @@ #Sat Jun 15 14:39:35 EET 2024 distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/settings.gradle.kts b/settings.gradle.kts index ce789f49..9890cb65 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -31,6 +31,7 @@ include("examples") val exampleProjects = listOf( "bukkit-plugin", + "fabric-mod", "jda-bot", "minestom-server", "cli-app"