Skip to content

Commit 6e578c9

Browse files
committed
Update/fix Fabric Permission API support
1 parent a41b8c0 commit 6e578c9

7 files changed

Lines changed: 82 additions & 92 deletions

File tree

README.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ If you have any questions, you can ask them on my [Discord](https://pb4.eu/disco
2020

2121

2222
## Commands (and permissions):
23-
- `/styledchat` - Main command (`styledchat.main`, available by default)
24-
- `/styledchat reload` - Reloads configuration and styles (requires `styledchat.reload`)
25-
- `/styledchat set <player> <type> <value>` - Changes personal <player>'s style of <type> to <value> (requires `styledchat.set`)
26-
- `/styledchat get <player> <type>` - Sends <player>'s style of <type> (requires `styledchat.get`)
27-
- `/styledchat clear <player> <type>` - Clears <player>'s style of <type> (requires `styledchat.clear`)
23+
- `/styledchat` - Main command (`styledchat:main`, available by default)
24+
- `/styledchat reload` - Reloads configuration and styles (requires `styledchat:reload`)
25+
- `/styledchat set <player> <type> <value>` - Changes personal <player>'s style of <type> to <value> (requires `styledchat:set`)
26+
- `/styledchat get <player> <type>` - Sends <player>'s style of <type> (requires `styledchat:get`)
27+
- `/styledchat clear <player> <type>` - Clears <player>'s style of <type> (requires `styledchat:clear`)
2828

2929
## Configuration:
3030
You can find config file in `./config/styled-chat.json`.
@@ -174,7 +174,7 @@ Additionally, every message type has few own local variables.
174174
```
175175

176176
## In chat formatting
177-
If player has a required permissions (`styledchat.format.[tag_name]`, where `[tagname]` is Text Parser tag), then they can use Simplified Text tags from within their chat.
177+
If player has a required permissions (`styledchat:format/[tag_name]`, where `[tagname]` is Text Parser tag), then they can use Simplified Text tags from within their chat.
178178
Additionally, you can enable markdown and legacy (&X) formatting in the config
179179

180180

build.gradle

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ dependencies {
4040
//modCompileOnly fabricApi.module("fabric-api-base", project.fabric_version)
4141
//modLocalRuntime fabricApi.module("fabric-api-base", project.fabric_version)
4242

43-
implementation include("eu.pb4:predicate-api:0.8.1+26.1")
44-
implementation include("eu.pb4:placeholder-api:3.0.0-beta.2+26.1")
45-
implementation include("eu.pb4:player-data-api:0.10.0+26.1")
46-
implementation include("me.lucko:fabric-permissions-api:0.7.0")
43+
implementation include("eu.pb4:predicate-api:0.8.2+26.1")
44+
implementation include("eu.pb4:placeholder-api:3.0.0+26.1")
45+
implementation include("eu.pb4:player-data-api:0.10.1+26.1")
46+
compileOnly "me.lucko:fabric-permissions-api:0.7.0"
4747

4848
//compileOnly("maven.modrinth:vanish:1.5.2+1.20.4")
4949
//modLocalRuntime("fr.catcore:server-translations-api:1.4.17+1.19.2")
@@ -54,10 +54,6 @@ dependencies {
5454
}
5555

5656
loom {
57-
enableTransitiveAccessWideners = false
58-
interfaceInjection {
59-
enableDependencyInterfaceInjection = false
60-
}
6157
accessWidenerPath = file("src/main/resources/styledchat.accesswidener")
6258
}
6359

gradle.properties

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@ org.gradle.jvmargs=-Xmx1G
33

44
# Fabric Properties
55
# check these on https://fabricmc.net/use
6-
minecraft_version=26.1
6+
minecraft_version=26.1.2
77
loader_version=0.18.4
88
loom_version=1.15-SNAPSHOT
99

1010
# Fabric API
11-
fabric_api_version=0.144.0+26.1
11+
fabric_api_version=0.149.1+26.1.2
1212

1313
# Mod Properties
14-
mod_version = 2.12.0-pre.1+26.1
14+
mod_version = 2.12.0+26.1.2
1515
maven_group = eu.pb4
1616
archives_base_name = styled-chat
1717

src/main/java/eu/pb4/styledchat/StyledChatUtils.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,10 @@
1919
import eu.pb4.styledchat.config.data.VersionedChatStyleData;
2020
import eu.pb4.styledchat.ducks.ExtPlayNetworkHandler;
2121
import eu.pb4.styledchat.ducks.ExtPlayerChatMessage;
22+
import eu.pb4.styledchat.other.FabricPermissionBridge;
2223
import eu.pb4.styledchat.parser.LinkParser;
2324
import eu.pb4.styledchat.parser.MentionParser;
2425
import eu.pb4.styledchat.parser.SpoilerNode;
25-
import me.lucko.fabric.api.permissions.v0.Permissions;
26-
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
2726
import net.minecraft.ChatFormatting;
2827
import net.minecraft.commands.CommandSourceStack;
2928
import net.minecraft.commands.arguments.selector.EntitySelector;
@@ -36,8 +35,10 @@
3635
import net.minecraft.network.chat.TextColor;
3736
import net.minecraft.network.chat.contents.PlainTextContents;
3837
import net.minecraft.network.protocol.game.ClientboundCustomChatCompletionsPacket;
38+
import net.minecraft.resources.Identifier;
3939
import net.minecraft.resources.ResourceKey;
4040
import net.minecraft.server.level.ServerPlayer;
41+
import net.minecraft.server.permissions.PermissionLevel;
4142
import net.minecraft.world.scores.PlayerTeam;
4243
import org.jetbrains.annotations.Nullable;
4344

@@ -60,8 +61,8 @@ public final class StyledChatUtils {
6061
public static JsonDataStorage<VersionedChatStyleData> PLAYER_DATA = new JsonDataStorage<>("styled_chat_style", VersionedChatStyleData.class);
6162
public static final TextTag SPOILER_TEXT_TAG_NEW = TextTag.enclosing(SPOILER_TAG, List.of("hide"), "styledchat", true, ((nodes, arg, parser) -> new SpoilerNode(nodes)));
6263

63-
public static final String FORMAT_PERMISSION_BASE = "styledchat.format.";
64-
public static final String FORMAT_PERMISSION_UNSAFE = "styledchat.unsafe_format.";
64+
public static final String FORMAT_PERMISSION_BASE = "format/";
65+
public static final String FORMAT_PERMISSION_UNSAFE = "unsafe_format/";
6566

6667

6768
public static final TagLikeParser.Format EMOTE_FORMAT = TagLikeParser.Format.of(':', ':');
@@ -119,6 +120,10 @@ public static NodeParser createParser(ServerPlaceholderContext context) {
119120
form.add(MarkdownLiteParserV1.MarkdownFormat.URL);
120121
}
121122

123+
if (tags.getTag("quote") != null) {
124+
form.add(MarkdownLiteParserV1.MarkdownFormat.QUOTE);
125+
}
126+
122127
builder.markdown(SpoilerNode::new, MarkdownLiteParserV1::defaultQuoteFormatting, MarkdownLiteParserV1::defaultUrlFormatting,
123128
form.toArray(new MarkdownLiteParserV1.MarkdownFormat[0]));
124129
}
@@ -155,15 +160,15 @@ public static TagRegistry getTextTagRegistry(CommandSourceStack source) {
155160

156161
for (var entry : TagRegistry.DEFAULT.getTags()) {
157162
if (allowedFormatting.getBoolean(entry.name())
158-
|| Permissions.check(source, (entry.userSafe() ? FORMAT_PERMISSION_BASE : FORMAT_PERMISSION_UNSAFE) + entry.name(), entry.userSafe() ? 2 : 4)
159-
|| Permissions.check(source, (entry.userSafe() ? FORMAT_PERMISSION_BASE : FORMAT_PERMISSION_UNSAFE) + ".type." + entry.type(), entry.userSafe() ? 2 : 4)
163+
|| FabricPermissionBridge.checkPermission(source, id((entry.userSafe() ? FORMAT_PERMISSION_BASE : FORMAT_PERMISSION_UNSAFE) + entry.name()), entry.userSafe() ? PermissionLevel.GAMEMASTERS : PermissionLevel.ADMINS)
164+
|| FabricPermissionBridge.checkPermission(source, id((entry.userSafe() ? FORMAT_PERMISSION_BASE : FORMAT_PERMISSION_UNSAFE) + "type/" + entry.type()), entry.userSafe() ? PermissionLevel.GAMEMASTERS : PermissionLevel.ADMINS)
160165
) {
161166
registry.register(entry);
162167
}
163168
}
164169

165170
if (allowedFormatting.getBoolean(SPOILER_TAG)
166-
|| Permissions.check(source, FORMAT_PERMISSION_BASE + SPOILER_TAG, 2)) {
171+
|| FabricPermissionBridge.checkPermission(source, id(FORMAT_PERMISSION_BASE + SPOILER_TAG), PermissionLevel.GAMEMASTERS)) {
167172
registry.register(SPOILER_TEXT_TAG_NEW);
168173
}
169174

@@ -471,4 +476,8 @@ public static ChatStyle createStyleOf(ServerPlayer player) {
471476
public static ChatType.Bound createParameters(Component override) {
472477
return ChatType.bind(StyledChatMod.MESSAGE_TYPE_ID, StyledChatMod.server.registryAccess(), override);
473478
}
479+
480+
public static Identifier id(String path) {
481+
return Identifier.fromNamespaceAndPath("styledchat", path);
482+
}
474483
}

src/main/java/eu/pb4/styledchat/command/Commands.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,15 @@
66
import com.mojang.brigadier.builder.ArgumentBuilder;
77
import com.mojang.brigadier.context.CommandContext;
88
import com.mojang.brigadier.exceptions.CommandSyntaxException;
9-
import eu.pb4.placeholders.api.PlaceholderContext;
109
import eu.pb4.placeholders.api.Placeholders;
1110
import eu.pb4.placeholders.api.ServerPlaceholderContext;
1211
import eu.pb4.placeholders.api.node.TextNode;
1312
import eu.pb4.styledchat.StyledChatMod;
1413
import eu.pb4.styledchat.StyledChatUtils;
1514
import eu.pb4.styledchat.config.ConfigManager;
1615
import eu.pb4.styledchat.config.data.ChatStyleData;
16+
import eu.pb4.styledchat.other.FabricPermissionBridge;
1717
import eu.pb4.styledchat.other.GenericModInfo;
18-
import me.lucko.fabric.api.permissions.v0.Permissions;
1918
import net.minecraft.ChatFormatting;
2019
import net.minecraft.commands.CommandBuildContext;
2120
import net.minecraft.commands.CommandSourceStack;
@@ -24,26 +23,29 @@
2423
import net.minecraft.core.registries.Registries;
2524
import net.minecraft.network.chat.Component;
2625
import net.minecraft.server.level.ServerPlayer;
26+
import net.minecraft.server.permissions.PermissionLevel;
27+
2728
import java.util.function.BiConsumer;
2829
import java.util.function.Function;
2930

31+
import static eu.pb4.styledchat.StyledChatUtils.id;
3032
import static net.minecraft.commands.Commands.argument;
3133
import static net.minecraft.commands.Commands.literal;
3234

3335
public class Commands {
3436
public static void register(CommandDispatcher<CommandSourceStack> dispatcher, CommandBuildContext registryAccess, net.minecraft.commands.Commands.CommandSelection environment) {
3537
dispatcher.register(
3638
literal("styledchat")
37-
.requires(Permissions.require("styledchat.main", true))
39+
.requires(FabricPermissionBridge.require(id("main"), true))
3840
.executes(Commands::about)
3941

4042
.then(literal("reload")
41-
.requires(Permissions.require("styledchat.reload", 3))
43+
.requires(FabricPermissionBridge.require(id("reload"), PermissionLevel.ADMINS))
4244
.executes(Commands::reloadConfig)
4345
)
4446

4547
.then(literal("set")
46-
.requires(Permissions.require("styledchat.set", 2))
48+
.requires(FabricPermissionBridge.require(id("set"), PermissionLevel.MODERATORS))
4749
.then(fillWithProperties(argument("players", EntityArgument.players()),
4850
(x, p) -> x.then(argument("value", StringArgumentType.greedyString())
4951
.executes((ctx) -> Commands.setProperty(ctx, p.apply(ctx)))
@@ -52,14 +54,14 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, Co
5254
)
5355

5456
.then(literal("get")
55-
.requires(Permissions.require("styledchat.get", 2))
57+
.requires(FabricPermissionBridge.require(id("get"), PermissionLevel.MODERATORS))
5658
.then(fillWithProperties(argument("player", EntityArgument.player()),
5759
(x, p) -> x.executes((ctx) -> Commands.getProperty(ctx, p.apply(ctx)))
5860
))
5961
)
6062

6163
.then(literal("clear")
62-
.requires(Permissions.require("styledchat.clear", 3))
64+
.requires(FabricPermissionBridge.require(id("clear"), PermissionLevel.ADMINS))
6365
.then(fillWithProperties(argument("players", EntityArgument.players()),
6466
(x, p) -> x.executes((ctx) -> Commands.clearProperty(ctx, p.apply(ctx)))
6567
).then(literal("*").executes((ctx) -> Commands.clearProperty(ctx, null))))
@@ -68,7 +70,7 @@ public static void register(CommandDispatcher<CommandSourceStack> dispatcher, Co
6870

6971
dispatcher.register(
7072
literal("tellform")
71-
.requires(Permissions.require("styledchat.tellform", 2))
73+
.requires(FabricPermissionBridge.require(id("tellform"), PermissionLevel.GAMEMASTERS))
7274

7375
.then(argument("targets", EntityArgument.players())
7476
.then(argument("message", StringArgumentType.greedyString())

src/main/java/eu/pb4/styledchat/config/data/ChatStyleData.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import com.google.gson.annotations.SerializedName;
55
import eu.pb4.styledchat.StyledChatUtils;
6-
import me.lucko.fabric.api.permissions.v0.Options;
6+
import eu.pb4.styledchat.other.FabricPermissionBridge;
77
import net.minecraft.ChatFormatting;
88
import net.minecraft.commands.CommandSourceStack;
99
import org.jetbrains.annotations.Nullable;
@@ -15,6 +15,8 @@
1515
import java.util.Map;
1616
import java.util.Objects;
1717

18+
import static eu.pb4.styledchat.StyledChatUtils.id;
19+
1820
public class ChatStyleData implements Cloneable {
1921
public static ChatStyleData DEFAULT = createDefault();
2022
public static final Map<String, PropertyGetSet> PROPERTIES;
@@ -106,10 +108,10 @@ public ChatStyleData clone() {
106108
public void fillPermissionOptionProvider(CommandSourceStack source) {
107109
for (var prop : PROPERTIES.entrySet()) {
108110
if (prop.getValue().get(this) == null) {
109-
var value = Options.get(source, "styled_chat." + prop.getKey());
111+
var value = FabricPermissionBridge.checkPermissionString(source, id("style/" + prop.getKey()));
110112

111-
if (value.isPresent()) {
112-
prop.getValue().set(this, value.get());
113+
if (value != null) {
114+
prop.getValue().set(this, value);
113115
}
114116
}
115117
}
@@ -147,6 +149,7 @@ public static ChatStyleData createDefault() {
147149
data.formatting.put("italic", true);
148150
data.formatting.put("strikethrough", true);
149151
data.formatting.put("underline", true);
152+
data.formatting.put("quote", true);
150153

151154
for (var formatting : ChatFormatting.values()) {
152155
if (formatting.isColor()) {

0 commit comments

Comments
 (0)