Standardize permission nodes

This commit is contained in:
Alessandro Proto 2024-10-23 12:19:24 +02:00
parent 4899a2c14d
commit e3f0d0f72d
4 changed files with 20 additions and 8 deletions

View file

@ -41,21 +41,25 @@ public class RccServer implements ModInitializer {
private static int currentPlayerCount = 0;
private static RccServer INSTANCE;
public static RccServer getInstance() {
return INSTANCE;
}
private ServiceServer serviceServer;
public ServiceServer serviceServer() {
return serviceServer;
}
private LuckPerms luckPerms;
public LuckPerms luckPerms() {
return luckPerms;
}
private AfkTracker afkTracker;
public AfkTracker afkTracker() {
return afkTracker;
}
@ -84,6 +88,10 @@ public class RccServer implements ModInitializer {
CommandRegistrationCallback.EVENT.register(AfkCommand::register);
CommandRegistrationCallback.EVENT.register(TellCommand::register);
CommandRegistrationCallback.EVENT.register(ReplyCommand::register);
CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> {
AfkCommand.register(dispatcher, registryAccess, environment);
TellCommand.register(dispatcher, registryAccess, environment);
ReplyCommand.register(dispatcher, registryAccess, environment);
FlyCommand.register(dispatcher, registryAccess, environment);
GodCommand.register(dispatcher, registryAccess, environment);
});
@ -93,7 +101,7 @@ public class RccServer implements ModInitializer {
afkTracker = new AfkTracker();
Ready.READY.invoker().ready(server, luckPerms);
if(CONFIG.enableHttpApi()) {
if (CONFIG.enableHttpApi()) {
try {
serviceServer = new ServiceServer();
} catch (IOException e) {
@ -110,7 +118,7 @@ public class RccServer implements ModInitializer {
});
ServerLifecycleEvents.SERVER_STOPPING.register(server -> {
if(CONFIG.enableHttpApi()) {
if (CONFIG.enableHttpApi()) {
LOGGER.info("Stopping HTTP services");
serviceServer.httpServer().stop(0);
}
@ -127,7 +135,7 @@ public class RccServer implements ModInitializer {
playerData.setDate(PlayerData.KEYS.firstJoinedDate, new Date());
isNewPlayer = true;
}
if(isNewPlayer) {
if (isNewPlayer) {
PlayerWelcome.PLAYER_WELCOME.invoker().playerWelcome(player, playerData, server);
LOGGER.info("Player {} joined for the first time!", player.getName().getString());
}
@ -141,7 +149,7 @@ public class RccServer implements ModInitializer {
LOGGER.info("{} is AFK. Active time: {} seconds.", player.getGameProfile().getName(), afkTracker.getActiveTime(player));
var displayNameJson = Text.Serializer.toJson(player.getDisplayName());
var displayName = JSONComponentSerializer.json().deserialize(displayNameJson);
var displayName = JSONComponentSerializer.json().deserialize(displayNameJson);
var message = MiniMessage.miniMessage().deserialize(CONFIG.afkMessage(),
Placeholder.component("displayname", displayName),
@ -156,7 +164,7 @@ public class RccServer implements ModInitializer {
LOGGER.info("{} is no longer AFK. Active time: {} seconds.", player.getGameProfile().getName(), afkTracker.getActiveTime(player));
var displayNameJson = Text.Serializer.toJson(player.getDisplayName());
var displayName = JSONComponentSerializer.json().deserialize(displayNameJson);
var displayName = JSONComponentSerializer.json().deserialize(displayNameJson);
var message = MiniMessage.miniMessage().deserialize(CONFIG.afkReturnMessage(),
Placeholder.component("displayname", displayName),
@ -169,13 +177,13 @@ public class RccServer implements ModInitializer {
}
public void broadcastMessage(MinecraftServer server, Text message) {
for(ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
player.sendMessage(message, false);
}
}
public void broadcastMessage(MinecraftServer server, Component message) {
for(ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
player.sendMessage(message);
}
}

View file

@ -13,7 +13,7 @@ import static net.minecraft.server.command.CommandManager.literal;
public class AfkCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
var rootCommand = literal("afk")
.requires(Permissions.require("rcc.afk.command", true))
.requires(Permissions.require("rcc.command.afk", true))
.executes(context -> {
if(!context.getSource().isExecutedByPlayer()) {

View file

@ -3,6 +3,7 @@ package cc.reconnected.server.commands;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.command.CommandRegistryAccess;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.ServerCommandSource;
@ -16,6 +17,7 @@ import static net.minecraft.server.command.CommandManager.*;
public class ReplyCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
var messageNode = dispatcher.register(literal("reply")
.requires(Permissions.require("rcc.command.tell", true))
.then(argument("message", StringArgumentType.greedyString())
.executes(ReplyCommand::execute)));

View file

@ -5,6 +5,7 @@ import cc.reconnected.server.parser.MarkdownParser;
import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.context.CommandContext;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.minecraft.command.CommandRegistryAccess;
@ -26,6 +27,7 @@ public class TellCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
var messageNode = dispatcher.register(literal("msg")
.requires(Permissions.require("rcc.command.tell", true))
.then(argument("player", StringArgumentType.word())
.suggests((context, builder) -> {
var playerManager = context.getSource().getServer().getPlayerManager();