Skip to content

Commit

Permalink
Merge pull request #118 from CamperSamu/v4
Browse files Browse the repository at this point in the history
Fabric: use Lucko's Fabric Permssion API
  • Loading branch information
Revxrsal authored Dec 29, 2024
2 parents 8b0ec72 + c078b57 commit de15e2f
Show file tree
Hide file tree
Showing 13 changed files with 193 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ hs_err_pid*
/.gradle
/gradle.properties
/copier.bat
run
/examples/fabric-mod/run/
45 changes: 45 additions & 0 deletions examples/fabric-mod/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -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
))
}
}
}
Original file line number Diff line number Diff line change
@@ -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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* This file is part of lamp, licensed under the MIT License.
*
* Copyright (c) Revxrsal <[email protected]>
*
* 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 + "!");
}
}
23 changes: 23 additions & 0 deletions examples/fabric-mod/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -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}"
}
}
29 changes: 23 additions & 6 deletions fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@ buildscript {

plugins {
id("java")
id("fabric-loom") version "1.7-SNAPSHOT"
id("fabric-loom") version "1.8-SNAPSHOT"
}

repositories {
maven("https://libraries.minecraft.net")
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"))
Expand All @@ -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
))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;

}
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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());
}
}
Binary file added fabric/src/main/resources/assets/lamp/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
32 changes: 32 additions & 0 deletions fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
@@ -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"
}
}
}
}
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ include("examples")

val exampleProjects = listOf(
"bukkit-plugin",
"fabric-mod",
"jda-bot",
"minestom-server",
"cli-app"
Expand Down

0 comments on commit de15e2f

Please sign in to comment.