Standardize permission nodes
This commit is contained in:
parent
4899a2c14d
commit
e3f0d0f72d
4 changed files with 20 additions and 8 deletions
|
@ -41,21 +41,25 @@ public class RccServer implements ModInitializer {
|
||||||
private static int currentPlayerCount = 0;
|
private static int currentPlayerCount = 0;
|
||||||
|
|
||||||
private static RccServer INSTANCE;
|
private static RccServer INSTANCE;
|
||||||
|
|
||||||
public static RccServer getInstance() {
|
public static RccServer getInstance() {
|
||||||
return INSTANCE;
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ServiceServer serviceServer;
|
private ServiceServer serviceServer;
|
||||||
|
|
||||||
public ServiceServer serviceServer() {
|
public ServiceServer serviceServer() {
|
||||||
return serviceServer;
|
return serviceServer;
|
||||||
}
|
}
|
||||||
|
|
||||||
private LuckPerms luckPerms;
|
private LuckPerms luckPerms;
|
||||||
|
|
||||||
public LuckPerms luckPerms() {
|
public LuckPerms luckPerms() {
|
||||||
return luckPerms;
|
return luckPerms;
|
||||||
}
|
}
|
||||||
|
|
||||||
private AfkTracker afkTracker;
|
private AfkTracker afkTracker;
|
||||||
|
|
||||||
public AfkTracker afkTracker() {
|
public AfkTracker afkTracker() {
|
||||||
return afkTracker;
|
return afkTracker;
|
||||||
}
|
}
|
||||||
|
@ -84,6 +88,10 @@ public class RccServer implements ModInitializer {
|
||||||
CommandRegistrationCallback.EVENT.register(AfkCommand::register);
|
CommandRegistrationCallback.EVENT.register(AfkCommand::register);
|
||||||
CommandRegistrationCallback.EVENT.register(TellCommand::register);
|
CommandRegistrationCallback.EVENT.register(TellCommand::register);
|
||||||
CommandRegistrationCallback.EVENT.register(ReplyCommand::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);
|
FlyCommand.register(dispatcher, registryAccess, environment);
|
||||||
GodCommand.register(dispatcher, registryAccess, environment);
|
GodCommand.register(dispatcher, registryAccess, environment);
|
||||||
});
|
});
|
||||||
|
@ -93,7 +101,7 @@ public class RccServer implements ModInitializer {
|
||||||
afkTracker = new AfkTracker();
|
afkTracker = new AfkTracker();
|
||||||
Ready.READY.invoker().ready(server, luckPerms);
|
Ready.READY.invoker().ready(server, luckPerms);
|
||||||
|
|
||||||
if(CONFIG.enableHttpApi()) {
|
if (CONFIG.enableHttpApi()) {
|
||||||
try {
|
try {
|
||||||
serviceServer = new ServiceServer();
|
serviceServer = new ServiceServer();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -110,7 +118,7 @@ public class RccServer implements ModInitializer {
|
||||||
});
|
});
|
||||||
|
|
||||||
ServerLifecycleEvents.SERVER_STOPPING.register(server -> {
|
ServerLifecycleEvents.SERVER_STOPPING.register(server -> {
|
||||||
if(CONFIG.enableHttpApi()) {
|
if (CONFIG.enableHttpApi()) {
|
||||||
LOGGER.info("Stopping HTTP services");
|
LOGGER.info("Stopping HTTP services");
|
||||||
serviceServer.httpServer().stop(0);
|
serviceServer.httpServer().stop(0);
|
||||||
}
|
}
|
||||||
|
@ -127,7 +135,7 @@ public class RccServer implements ModInitializer {
|
||||||
playerData.setDate(PlayerData.KEYS.firstJoinedDate, new Date());
|
playerData.setDate(PlayerData.KEYS.firstJoinedDate, new Date());
|
||||||
isNewPlayer = true;
|
isNewPlayer = true;
|
||||||
}
|
}
|
||||||
if(isNewPlayer) {
|
if (isNewPlayer) {
|
||||||
PlayerWelcome.PLAYER_WELCOME.invoker().playerWelcome(player, playerData, server);
|
PlayerWelcome.PLAYER_WELCOME.invoker().playerWelcome(player, playerData, server);
|
||||||
LOGGER.info("Player {} joined for the first time!", player.getName().getString());
|
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));
|
LOGGER.info("{} is AFK. Active time: {} seconds.", player.getGameProfile().getName(), afkTracker.getActiveTime(player));
|
||||||
|
|
||||||
var displayNameJson = Text.Serializer.toJson(player.getDisplayName());
|
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(),
|
var message = MiniMessage.miniMessage().deserialize(CONFIG.afkMessage(),
|
||||||
Placeholder.component("displayname", displayName),
|
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));
|
LOGGER.info("{} is no longer AFK. Active time: {} seconds.", player.getGameProfile().getName(), afkTracker.getActiveTime(player));
|
||||||
|
|
||||||
var displayNameJson = Text.Serializer.toJson(player.getDisplayName());
|
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(),
|
var message = MiniMessage.miniMessage().deserialize(CONFIG.afkReturnMessage(),
|
||||||
Placeholder.component("displayname", displayName),
|
Placeholder.component("displayname", displayName),
|
||||||
|
@ -169,13 +177,13 @@ public class RccServer implements ModInitializer {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void broadcastMessage(MinecraftServer server, Text message) {
|
public void broadcastMessage(MinecraftServer server, Text message) {
|
||||||
for(ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
|
for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
|
||||||
player.sendMessage(message, false);
|
player.sendMessage(message, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void broadcastMessage(MinecraftServer server, Component message) {
|
public void broadcastMessage(MinecraftServer server, Component message) {
|
||||||
for(ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
|
for (ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
|
||||||
player.sendMessage(message);
|
player.sendMessage(message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,7 +13,7 @@ import static net.minecraft.server.command.CommandManager.literal;
|
||||||
public class AfkCommand {
|
public class AfkCommand {
|
||||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
|
||||||
var rootCommand = literal("afk")
|
var rootCommand = literal("afk")
|
||||||
.requires(Permissions.require("rcc.afk.command", true))
|
.requires(Permissions.require("rcc.command.afk", true))
|
||||||
.executes(context -> {
|
.executes(context -> {
|
||||||
|
|
||||||
if(!context.getSource().isExecutedByPlayer()) {
|
if(!context.getSource().isExecutedByPlayer()) {
|
||||||
|
|
|
@ -3,6 +3,7 @@ package cc.reconnected.server.commands;
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
import com.mojang.brigadier.context.CommandContext;
|
||||||
|
import me.lucko.fabric.api.permissions.v0.Permissions;
|
||||||
import net.minecraft.command.CommandRegistryAccess;
|
import net.minecraft.command.CommandRegistryAccess;
|
||||||
import net.minecraft.server.command.CommandManager;
|
import net.minecraft.server.command.CommandManager;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
|
@ -16,6 +17,7 @@ import static net.minecraft.server.command.CommandManager.*;
|
||||||
public class ReplyCommand {
|
public class ReplyCommand {
|
||||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
|
||||||
var messageNode = dispatcher.register(literal("reply")
|
var messageNode = dispatcher.register(literal("reply")
|
||||||
|
.requires(Permissions.require("rcc.command.tell", true))
|
||||||
.then(argument("message", StringArgumentType.greedyString())
|
.then(argument("message", StringArgumentType.greedyString())
|
||||||
.executes(ReplyCommand::execute)));
|
.executes(ReplyCommand::execute)));
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,7 @@ import cc.reconnected.server.parser.MarkdownParser;
|
||||||
import com.mojang.brigadier.CommandDispatcher;
|
import com.mojang.brigadier.CommandDispatcher;
|
||||||
import com.mojang.brigadier.arguments.StringArgumentType;
|
import com.mojang.brigadier.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.context.CommandContext;
|
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.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
import net.minecraft.command.CommandRegistryAccess;
|
import net.minecraft.command.CommandRegistryAccess;
|
||||||
|
@ -26,6 +27,7 @@ public class TellCommand {
|
||||||
|
|
||||||
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
|
public static void register(CommandDispatcher<ServerCommandSource> dispatcher, CommandRegistryAccess registryAccess, CommandManager.RegistrationEnvironment environment) {
|
||||||
var messageNode = dispatcher.register(literal("msg")
|
var messageNode = dispatcher.register(literal("msg")
|
||||||
|
.requires(Permissions.require("rcc.command.tell", true))
|
||||||
.then(argument("player", StringArgumentType.word())
|
.then(argument("player", StringArgumentType.word())
|
||||||
.suggests((context, builder) -> {
|
.suggests((context, builder) -> {
|
||||||
var playerManager = context.getSource().getServer().getPlayerManager();
|
var playerManager = context.getSource().getServer().getPlayerManager();
|
||||||
|
|
Loading…
Reference in a new issue