Compare commits

...

10 commits

39 changed files with 186 additions and 548 deletions

View file

@ -19,6 +19,7 @@ repositories {
maven { url 'https://maven.nucleoid.xyz' } maven { url 'https://maven.nucleoid.xyz' }
maven { url 'https://maven.reconnected.cc/releases' } maven { url 'https://maven.reconnected.cc/releases' }
mavenLocal()
} }
loom { loom {
@ -41,6 +42,8 @@ dependencies {
// Fabric API. This is technically optional, but you probably want it anyway. // Fabric API. This is technically optional, but you probably want it anyway.
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}" modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "cc.reconnected:rcc-lib:${project.rcclib_version}"
compileOnly "net.luckperms:api:${project.luckpermsapi_version}" compileOnly "net.luckperms:api:${project.luckpermsapi_version}"
include modImplementation("me.lucko:fabric-permissions-api:${project.permissions_api_version}") include modImplementation("me.lucko:fabric-permissions-api:${project.permissions_api_version}")

View file

@ -9,13 +9,15 @@ yarn_mappings=1.20.1+build.10
loader_version=0.16.8 loader_version=0.16.8
# Mod Properties # Mod Properties
mod_version=1.17.1 mod_version=1.17.4
maven_group=cc.reconnected maven_group=cc.reconnected
archives_base_name=rcc-server archives_base_name=rcc-server
# Dependencies # Dependencies
fabric_version=0.92.2+1.20.1 fabric_version=0.92.2+1.20.1
rcclib_version=1.0.0
luckpermsapi_version=5.4 luckpermsapi_version=5.4
permissions_api_version=0.2-SNAPSHOT permissions_api_version=0.2-SNAPSHOT

View file

@ -1,5 +1,6 @@
package cc.reconnected.server; package cc.reconnected.server;
import cc.reconnected.library.config.ConfigManager;
import cc.reconnected.server.api.events.RccEvents; import cc.reconnected.server.api.events.RccEvents;
import cc.reconnected.server.commands.admin.*; import cc.reconnected.server.commands.admin.*;
import cc.reconnected.server.commands.home.DeleteHomeCommand; import cc.reconnected.server.commands.home.DeleteHomeCommand;
@ -19,8 +20,6 @@ import cc.reconnected.server.commands.tell.TellCommand;
import cc.reconnected.server.commands.warp.DeleteWarpCommand; import cc.reconnected.server.commands.warp.DeleteWarpCommand;
import cc.reconnected.server.commands.warp.SetWarpCommand; import cc.reconnected.server.commands.warp.SetWarpCommand;
import cc.reconnected.server.commands.warp.WarpCommand; import cc.reconnected.server.commands.warp.WarpCommand;
import cc.reconnected.server.config.Config;
import cc.reconnected.server.config.ConfigManager;
import cc.reconnected.server.core.*; import cc.reconnected.server.core.*;
import cc.reconnected.server.core.customChat.CustomChatMessage; import cc.reconnected.server.core.customChat.CustomChatMessage;
import cc.reconnected.server.data.StateManager; import cc.reconnected.server.data.StateManager;
@ -52,7 +51,7 @@ public class RccServer implements ModInitializer {
public static final String MOD_ID = "rcc-server"; public static final String MOD_ID = "rcc-server";
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID);
public static Config CONFIG = ConfigManager.load(); public static RccServerConfig CONFIG;
public static final StateManager state = new StateManager(); public static final StateManager state = new StateManager();
@ -62,10 +61,6 @@ public class RccServer implements ModInitializer {
return INSTANCE; return INSTANCE;
} }
public RccServer() {
INSTANCE = this;
}
private LuckPerms luckPerms; private LuckPerms luckPerms;
public LuckPerms luckPerms() { public LuckPerms luckPerms() {
@ -85,11 +80,23 @@ public class RccServer implements ModInitializer {
} }
public static final RegistryKey<MessageType> CHAT_TYPE = RegistryKey.of(RegistryKeys.MESSAGE_TYPE, new Identifier(MOD_ID, "chat")); public static final RegistryKey<MessageType> CHAT_TYPE = RegistryKey.of(RegistryKeys.MESSAGE_TYPE, new Identifier(MOD_ID, "chat"));
private static boolean warnedAboutUnsignedMessages = false;
public RccServer() {
INSTANCE = this;
}
@Override @Override
public void onInitialize() { public void onInitialize() {
LOGGER.info("Starting rcc-server"); LOGGER.info("Starting rcc-server");
try {
CONFIG = ConfigManager.load(RccServerConfig.class);
} catch (Exception e) {
LOGGER.error("Failed to load config. Refusing to continue.", e);
return;
}
ServerLifecycleEvents.SERVER_STARTING.register(server -> { ServerLifecycleEvents.SERVER_STARTING.register(server -> {
RccServer.server = server; RccServer.server = server;
state.register(server.getSavePath(WorldSavePath.ROOT).resolve("data").resolve(RccServer.MOD_ID)); state.register(server.getSavePath(WorldSavePath.ROOT).resolve("data").resolve(RccServer.MOD_ID));
@ -135,7 +142,6 @@ public class RccServer implements ModInitializer {
TeleportTracker.register(); TeleportTracker.register();
BackTracker.register(); BackTracker.register();
TabList.register(); TabList.register();
HttpApiServer.register();
BossBarManager.register(); BossBarManager.register();
AutoRestart.register(); AutoRestart.register();
@ -196,4 +202,20 @@ public class RccServer implements ModInitializer {
} }
} }
public static void warnUnsignedMessages() {
if (warnedAboutUnsignedMessages)
return;
warnedAboutUnsignedMessages = true;
LOGGER.warn(
"""
!!! --- WARNING --- !!!
Cannot retrieve message sender UUID!
If you are using FabricProxy-Lite, consider disabling
the `hackMessageChain` configuration!
"""
);
}
} }

View file

@ -1,15 +1,14 @@
package cc.reconnected.server.config; package cc.reconnected.server;
import cc.reconnected.library.config.Config;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
public class Config { @Config(RccServer.MOD_ID)
Config() { public class RccServerConfig {
}
public HttpApi httpApi = new HttpApi();
public Afk afk = new Afk(); public Afk afk = new Afk();
public TeleportRequests teleportRequests = new TeleportRequests(); public TeleportRequests teleportRequests = new TeleportRequests();
public Homes homes = new Homes(); public Homes homes = new Homes();
@ -19,11 +18,6 @@ public class Config {
public Chat chat = new Chat(); public Chat chat = new Chat();
public TextFormats textFormats = new TextFormats(); public TextFormats textFormats = new TextFormats();
public static class HttpApi {
public boolean enableHttpApi = true;
public int httpPort = 25581;
}
public static class Afk { public static class Afk {
public int afkTimeTrigger = 300; public int afkTimeTrigger = 300;
} }

View file

@ -18,11 +18,7 @@ public class FlyCommand {
var rootCommand = literal("fly") var rootCommand = literal("fly")
.requires(Permissions.require("rcc.command.fly", 3)) .requires(Permissions.require("rcc.command.fly", 3))
.executes(context -> { .executes(context -> {
if (!context.getSource().isExecutedByPlayer()) { var player = context.getSource().getPlayerOrThrow();
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1;
}
var player = context.getSource().getPlayer();
context.getSource().sendFeedback(() -> toggleFlight(player), true); context.getSource().sendFeedback(() -> toggleFlight(player), true);
return 1; return 1;

View file

@ -18,11 +18,7 @@ public class GodCommand {
var rootCommand = literal("god") var rootCommand = literal("god")
.requires(Permissions.require("rcc.command.god", 3)) .requires(Permissions.require("rcc.command.god", 3))
.executes(context -> { .executes(context -> {
if (!context.getSource().isExecutedByPlayer()) { var player = context.getSource().getPlayerOrThrow();
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1;
}
var player = context.getSource().getPlayer();
context.getSource().sendFeedback(() -> toggleGod(player), true); context.getSource().sendFeedback(() -> toggleGod(player), true);
return 1; return 1;

View file

@ -1,27 +1,53 @@
package cc.reconnected.server.commands.admin; package cc.reconnected.server.commands.admin;
import cc.reconnected.library.config.ConfigManager;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.RccServerConfig;
import cc.reconnected.server.api.events.RccEvents; import cc.reconnected.server.api.events.RccEvents;
import cc.reconnected.server.config.ConfigManager; import cc.reconnected.server.util.Components;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import me.lucko.fabric.api.permissions.v0.Permissions; import me.lucko.fabric.api.permissions.v0.Permissions;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import java.util.Map;
import static net.minecraft.server.command.CommandManager.literal; import static net.minecraft.server.command.CommandManager.literal;
public class RccCommand { public class RccCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
var rootCommand = literal("rcc") var rootCommand = literal("rcc")
.requires(Permissions.require("rcc.command.rcc", 3)) .requires(Permissions.require("rcc.command.rcc", 3))
.executes(context -> {
var modContainer = FabricLoader.getInstance().getModContainer(RccServer.MOD_ID).orElse(null);
if(modContainer == null) {
context.getSource().sendFeedback(() -> Text.of("Could not find self in mod list???"), false);
return 1;
}
var metadata = modContainer.getMetadata();
var placeholders = Map.of(
"name", Text.of(metadata.getName()),
"version", Text.of(metadata.getVersion().getFriendlyString())
);
var text = Placeholder.parse(
"<gold>${name} v${version}</gold>",
placeholders);
context.getSource().sendFeedback(() -> text, false);
return 1;
})
.then(literal("reload") .then(literal("reload")
.requires(Permissions.require("rcc.command.rcc.reload", 3)) .requires(Permissions.require("rcc.command.rcc.reload", 3))
.executes(context -> { .executes(context -> {
context.getSource().sendFeedback(() -> Text.of("Reloading RCC config..."), true); context.getSource().sendFeedback(() -> Text.of("Reloading RCC config..."), true);
try { try {
RccServer.CONFIG = ConfigManager.load(); RccServer.CONFIG = ConfigManager.load(RccServerConfig.class);
} catch(Exception e) { } catch (Exception e) {
RccServer.LOGGER.error("Failed to load RCC config", e); RccServer.LOGGER.error("Failed to load RCC config", e);
context.getSource().sendFeedback(() -> Text.of("Failed to load RCC config. Check console for more info."), true); context.getSource().sendFeedback(() -> Text.of("Failed to load RCC config. Check console for more info."), true);
return 1; return 1;

View file

@ -1,10 +1,12 @@
package cc.reconnected.server.commands.home; package cc.reconnected.server.commands.home;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.util.Components; import cc.reconnected.server.util.Components;
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 com.mojang.brigadier.exceptions.CommandSyntaxException;
import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.PlaceholderContext;
import me.lucko.fabric.api.permissions.v0.Permissions; import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
@ -34,12 +36,8 @@ public class DeleteHomeCommand {
dispatcher.register(rootCommand); dispatcher.register(rootCommand);
} }
private static int execute(CommandContext<ServerCommandSource> context, String name) { private static int execute(CommandContext<ServerCommandSource> context, String name) throws CommandSyntaxException {
if (!context.getSource().isExecutedByPlayer()) { var player = context.getSource().getPlayerOrThrow();
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1;
}
var player = context.getSource().getPlayer();
var playerState = RccServer.state.getPlayerState(player.getUuid()); var playerState = RccServer.state.getPlayerState(player.getUuid());
var homes = playerState.homes; var homes = playerState.homes;
var playerContext = PlaceholderContext.of(context.getSource().getPlayer()); var playerContext = PlaceholderContext.of(context.getSource().getPlayer());
@ -49,7 +47,7 @@ public class DeleteHomeCommand {
); );
if (!homes.containsKey(name)) { if (!homes.containsKey(name)) {
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.home.homeNotFound, RccServer.CONFIG.textFormats.commands.home.homeNotFound,
playerContext, playerContext,
placeholders placeholders
@ -60,7 +58,7 @@ public class DeleteHomeCommand {
homes.remove(name); homes.remove(name);
RccServer.state.savePlayerState(player.getUuid(), playerState); RccServer.state.savePlayerState(player.getUuid(), playerState);
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.home.homeDeleted, RccServer.CONFIG.textFormats.commands.home.homeDeleted,
playerContext, playerContext,
placeholders placeholders

View file

@ -1,10 +1,12 @@
package cc.reconnected.server.commands.home; package cc.reconnected.server.commands.home;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.util.Components; import cc.reconnected.server.util.Components;
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 com.mojang.brigadier.exceptions.CommandSyntaxException;
import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.PlaceholderContext;
import me.lucko.fabric.api.permissions.v0.Permissions; import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
@ -34,12 +36,8 @@ public class HomeCommand {
dispatcher.register(rootCommand); dispatcher.register(rootCommand);
} }
private static int execute(CommandContext<ServerCommandSource> context, String name) { private static int execute(CommandContext<ServerCommandSource> context, String name) throws CommandSyntaxException {
if (!context.getSource().isExecutedByPlayer()) { var player = context.getSource().getPlayerOrThrow();
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1;
}
var player = context.getSource().getPlayer();
var playerState = RccServer.state.getPlayerState(player.getUuid()); var playerState = RccServer.state.getPlayerState(player.getUuid());
var homes = playerState.homes; var homes = playerState.homes;
var playerContext = PlaceholderContext.of(context.getSource().getPlayer()); var playerContext = PlaceholderContext.of(context.getSource().getPlayer());
@ -50,7 +48,7 @@ public class HomeCommand {
if (!homes.containsKey(name)) { if (!homes.containsKey(name)) {
context.getSource().sendFeedback(() -> context.getSource().sendFeedback(() ->
Components.parse( Placeholder.parse(
RccServer.CONFIG.textFormats.commands.home.homeNotFound, RccServer.CONFIG.textFormats.commands.home.homeNotFound,
playerContext, playerContext,
placeholders placeholders
@ -60,7 +58,7 @@ public class HomeCommand {
} }
context.getSource().sendFeedback(() -> context.getSource().sendFeedback(() ->
Components.parse( Placeholder.parse(
RccServer.CONFIG.textFormats.commands.home.teleporting, RccServer.CONFIG.textFormats.commands.home.teleporting,
playerContext, playerContext,
placeholders placeholders

View file

@ -1,5 +1,6 @@
package cc.reconnected.server.commands.home; package cc.reconnected.server.commands.home;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.struct.ServerPosition; import cc.reconnected.server.struct.ServerPosition;
import cc.reconnected.server.util.Components; import cc.reconnected.server.util.Components;
@ -7,6 +8,7 @@ import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.arguments.BoolArgumentType; import com.mojang.brigadier.arguments.BoolArgumentType;
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 com.mojang.brigadier.exceptions.CommandSyntaxException;
import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.PlaceholderContext;
import me.lucko.fabric.api.permissions.v0.Permissions; import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
@ -36,12 +38,8 @@ public class SetHomeCommand {
dispatcher.register(rootCommand); dispatcher.register(rootCommand);
} }
private static int execute(CommandContext<ServerCommandSource> context, String name, boolean forced) { private static int execute(CommandContext<ServerCommandSource> context, String name, boolean forced) throws CommandSyntaxException {
if (!context.getSource().isExecutedByPlayer()) { var player = context.getSource().getPlayerOrThrow();
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1;
}
var player = context.getSource().getPlayer();
var playerState = RccServer.state.getPlayerState(player.getUuid()); var playerState = RccServer.state.getPlayerState(player.getUuid());
var homes = playerState.homes; var homes = playerState.homes;
var playerContext = PlaceholderContext.of(player); var playerContext = PlaceholderContext.of(player);
@ -57,7 +55,7 @@ public class SetHomeCommand {
var exists = homes.containsKey(name); var exists = homes.containsKey(name);
if (exists && !forced) { if (exists && !forced) {
var text = Components.parse( var text = Placeholder.parse(
RccServer.CONFIG.textFormats.commands.home.homeExists, RccServer.CONFIG.textFormats.commands.home.homeExists,
playerContext, playerContext,
placeholders placeholders
@ -69,8 +67,8 @@ public class SetHomeCommand {
} }
var maxHomes = RccServer.CONFIG.homes.maxHomes; var maxHomes = RccServer.CONFIG.homes.maxHomes;
if(homes.size() >= maxHomes && !exists) { if(maxHomes >= 0 && homes.size() >= maxHomes && !exists) {
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.home.maxHomesReached, RccServer.CONFIG.textFormats.commands.home.maxHomesReached,
playerContext, playerContext,
placeholders placeholders
@ -83,7 +81,7 @@ public class SetHomeCommand {
RccServer.state.savePlayerState(player.getUuid(), playerState); RccServer.state.savePlayerState(player.getUuid(), playerState);
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.home.homeSetSuccess, RccServer.CONFIG.textFormats.commands.home.homeSetSuccess,
playerContext, playerContext,
placeholders placeholders

View file

@ -13,13 +13,7 @@ public class AfkCommand {
var rootCommand = literal("afk") var rootCommand = literal("afk")
.requires(Permissions.require("rcc.command.afk", true)) .requires(Permissions.require("rcc.command.afk", true))
.executes(context -> { .executes(context -> {
var player = context.getSource().getPlayerOrThrow();
if (!context.getSource().isExecutedByPlayer()) {
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1;
}
var player = context.getSource().getPlayer();
AfkTracker.getInstance().setPlayerAfk(player, true); AfkTracker.getInstance().setPlayerAfk(player, true);
return 1; return 1;

View file

@ -1,5 +1,6 @@
package cc.reconnected.server.commands.misc; package cc.reconnected.server.commands.misc;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.util.Components; import cc.reconnected.server.util.Components;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
@ -22,21 +23,9 @@ public class NearCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
var rootCommand = literal("near") var rootCommand = literal("near")
.requires(Permissions.require("rcc.command.near", 2)) .requires(Permissions.require("rcc.command.near", 2))
.executes(context -> { .executes(context -> execute(context, RccServer.CONFIG.nearCommand.nearCommandDefaultRange, context.getSource().getPlayerOrThrow()))
if (!context.getSource().isExecutedByPlayer()) {
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1;
}
return execute(context, RccServer.CONFIG.nearCommand.nearCommandDefaultRange, context.getSource().getPlayer());
})
.then(argument("radius", IntegerArgumentType.integer(0, RccServer.CONFIG.nearCommand.nearCommandMaxRange)) .then(argument("radius", IntegerArgumentType.integer(0, RccServer.CONFIG.nearCommand.nearCommandMaxRange))
.executes(context -> { .executes(context -> execute(context, IntegerArgumentType.getInteger(context, "radius"), context.getSource().getPlayerOrThrow())));
if (!context.getSource().isExecutedByPlayer()) {
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1;
}
return execute(context, IntegerArgumentType.getInteger(context, "radius"), context.getSource().getPlayer());
}));
dispatcher.register(rootCommand); dispatcher.register(rootCommand);
} }
@ -55,7 +44,7 @@ public class NearCommand {
}); });
if (list.isEmpty()) { if (list.isEmpty()) {
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.near.noOne, RccServer.CONFIG.textFormats.commands.near.noOne,
playerContext playerContext
), false); ), false);
@ -65,7 +54,7 @@ public class NearCommand {
list.sort(Comparator.comparingDouble(ClosePlayers::distance)); list.sort(Comparator.comparingDouble(ClosePlayers::distance));
var listText = Text.empty(); var listText = Text.empty();
var comma = Components.parse(RccServer.CONFIG.textFormats.commands.near.comma); var comma = Placeholder.parse(RccServer.CONFIG.textFormats.commands.near.comma);
for (int i = 0; i < list.size(); i++) { for (int i = 0; i < list.size(); i++) {
var player = list.get(i); var player = list.get(i);
if (i > 0) { if (i > 0) {
@ -78,7 +67,7 @@ public class NearCommand {
var targetContext = PlaceholderContext.of(sourcePlayer); var targetContext = PlaceholderContext.of(sourcePlayer);
listText = listText.append(Components.parse( listText = listText.append(Placeholder.parse(
RccServer.CONFIG.textFormats.commands.near.format, RccServer.CONFIG.textFormats.commands.near.format,
targetContext, targetContext,
placeholders placeholders
@ -88,7 +77,7 @@ public class NearCommand {
var placeholders = Map.of( var placeholders = Map.of(
"playerList", (Text) listText "playerList", (Text) listText
); );
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.near.nearestPlayers, RccServer.CONFIG.textFormats.commands.near.nearestPlayers,
playerContext, playerContext,
placeholders placeholders

View file

@ -15,12 +15,7 @@ public class SetSpawnCommand {
var rootCommand = literal("setspawn") var rootCommand = literal("setspawn")
.requires(Permissions.require("rcc.command.setspawn", 3)) .requires(Permissions.require("rcc.command.setspawn", 3))
.executes(context -> { .executes(context -> {
if (!context.getSource().isExecutedByPlayer()) { var player = context.getSource().getPlayerOrThrow();
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1;
}
var player = context.getSource().getPlayer();
var spawnPosition = new ServerPosition(player); var spawnPosition = new ServerPosition(player);
var serverState = RccServer.state.getServerState(); var serverState = RccServer.state.getServerState();

View file

@ -1,5 +1,6 @@
package cc.reconnected.server.commands.spawn; package cc.reconnected.server.commands.spawn;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.struct.ServerPosition; import cc.reconnected.server.struct.ServerPosition;
import cc.reconnected.server.util.Components; import cc.reconnected.server.util.Components;
@ -16,12 +17,7 @@ public class SpawnCommand {
var rootCommand = literal("spawn") var rootCommand = literal("spawn")
.requires(Permissions.require("rcc.command.spawn", true)) .requires(Permissions.require("rcc.command.spawn", true))
.executes(context -> { .executes(context -> {
if (!context.getSource().isExecutedByPlayer()) { var player = context.getSource().getPlayerOrThrow();
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1;
}
var player = context.getSource().getPlayer();
var serverState = RccServer.state.getServerState(); var serverState = RccServer.state.getServerState();
var playerContext = PlaceholderContext.of(player); var playerContext = PlaceholderContext.of(player);
var spawnPosition = serverState.spawn; var spawnPosition = serverState.spawn;
@ -31,7 +27,7 @@ public class SpawnCommand {
spawnPosition = new ServerPosition(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), 0, 0, server.getOverworld()); spawnPosition = new ServerPosition(spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), 0, 0, server.getOverworld());
} }
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.spawn.teleporting, RccServer.CONFIG.textFormats.commands.spawn.teleporting,
playerContext playerContext
), false); ), false);

View file

@ -1,5 +1,6 @@
package cc.reconnected.server.commands.teleport; package cc.reconnected.server.commands.teleport;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.core.BackTracker; import cc.reconnected.server.core.BackTracker;
import cc.reconnected.server.util.Components; import cc.reconnected.server.util.Components;
@ -16,24 +17,19 @@ public class BackCommand {
var rootCommand = literal("back") var rootCommand = literal("back")
.requires(Permissions.require("rcc.command.back", true)) .requires(Permissions.require("rcc.command.back", true))
.executes(context -> { .executes(context -> {
if (!context.getSource().isExecutedByPlayer()) { var player = context.getSource().getPlayerOrThrow();
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1;
}
var player = context.getSource().getPlayer();
var playerContext = PlaceholderContext.of(player); var playerContext = PlaceholderContext.of(player);
var lastPosition = BackTracker.lastPlayerPositions.get(player.getUuid()); var lastPosition = BackTracker.lastPlayerPositions.get(player.getUuid());
if (lastPosition == null) { if (lastPosition == null) {
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.back.noPosition, RccServer.CONFIG.textFormats.commands.back.noPosition,
playerContext playerContext
), false); ), false);
return 1; return 1;
} }
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.back.teleporting, RccServer.CONFIG.textFormats.commands.back.teleporting,
playerContext playerContext
), false); ), false);

View file

@ -1,5 +1,6 @@
package cc.reconnected.server.commands.teleport; package cc.reconnected.server.commands.teleport;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.core.TeleportTracker; import cc.reconnected.server.core.TeleportTracker;
import cc.reconnected.server.struct.ServerPosition; import cc.reconnected.server.struct.ServerPosition;
@ -20,12 +21,7 @@ public class TeleportAcceptCommand {
public static void register(CommandDispatcher<ServerCommandSource> dispatcher) { public static void register(CommandDispatcher<ServerCommandSource> dispatcher) {
var node = dispatcher.register(literal("tpaccept") var node = dispatcher.register(literal("tpaccept")
.executes(context -> { .executes(context -> {
if (!context.getSource().isExecutedByPlayer()) { var player = context.getSource().getPlayerOrThrow();
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1;
}
var player = context.getSource().getPlayer();
var playerUuid = player.getUuid(); var playerUuid = player.getUuid();
var playerRequests = TeleportTracker.teleportRequests.get(playerUuid); var playerRequests = TeleportTracker.teleportRequests.get(playerUuid);
var playerContext = PlaceholderContext.of(player); var playerContext = PlaceholderContext.of(player);
@ -33,7 +29,7 @@ public class TeleportAcceptCommand {
var request = playerRequests.pollLast(); var request = playerRequests.pollLast();
if (request == null) { if (request == null) {
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.teleportRequest.noPending, RccServer.CONFIG.textFormats.commands.teleportRequest.noPending,
playerContext playerContext
), false); ), false);
@ -59,7 +55,7 @@ public class TeleportAcceptCommand {
var request = playerRequests.stream().filter(req -> req.requestId.equals(uuid)).findFirst().orElse(null); var request = playerRequests.stream().filter(req -> req.requestId.equals(uuid)).findFirst().orElse(null);
if (request == null) { if (request == null) {
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.teleportRequest.unavailable, RccServer.CONFIG.textFormats.commands.teleportRequest.unavailable,
playerContext playerContext
), false); ), false);
@ -88,7 +84,7 @@ public class TeleportAcceptCommand {
var playerContext = PlaceholderContext.of(player); var playerContext = PlaceholderContext.of(player);
if (sourcePlayer == null || targetPlayer == null) { if (sourcePlayer == null || targetPlayer == null) {
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.teleportRequest.playerUnavailable, RccServer.CONFIG.textFormats.commands.teleportRequest.playerUnavailable,
playerContext playerContext
), false); ), false);
@ -98,23 +94,23 @@ public class TeleportAcceptCommand {
if (player.getUuid().equals(request.target)) { if (player.getUuid().equals(request.target)) {
var sourceContext = PlaceholderContext.of(sourcePlayer); var sourceContext = PlaceholderContext.of(sourcePlayer);
// accepted a tpa from other to self // accepted a tpa from other to self
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.teleportRequest.requestAcceptedResult, RccServer.CONFIG.textFormats.commands.teleportRequest.requestAcceptedResult,
playerContext playerContext
), false); ), false);
sourcePlayer.sendMessage(Components.parse( sourcePlayer.sendMessage(Placeholder.parse(
RccServer.CONFIG.textFormats.commands.teleportRequest.teleporting, RccServer.CONFIG.textFormats.commands.teleportRequest.teleporting,
sourceContext sourceContext
), false); ), false);
} else { } else {
var targetContext = PlaceholderContext.of(targetPlayer); var targetContext = PlaceholderContext.of(targetPlayer);
// accepted a tpa from self to other // accepted a tpa from self to other
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.teleportRequest.teleporting, RccServer.CONFIG.textFormats.commands.teleportRequest.teleporting,
playerContext playerContext
), false); ), false);
targetPlayer.sendMessage(Components.parse( targetPlayer.sendMessage(Placeholder.parse(
RccServer.CONFIG.textFormats.commands.teleportRequest.requestAccepted, RccServer.CONFIG.textFormats.commands.teleportRequest.requestAccepted,
targetContext, targetContext,
Map.of("player", sourcePlayer.getDisplayName()) Map.of("player", sourcePlayer.getDisplayName())

View file

@ -1,11 +1,13 @@
package cc.reconnected.server.commands.teleport; package cc.reconnected.server.commands.teleport;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.core.TeleportTracker; import cc.reconnected.server.core.TeleportTracker;
import cc.reconnected.server.util.Components; import cc.reconnected.server.util.Components;
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 com.mojang.brigadier.exceptions.CommandSyntaxException;
import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.PlaceholderContext;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
@ -34,15 +36,11 @@ public class TeleportAskCommand {
dispatcher.register(literal("tpask").redirect(node)); dispatcher.register(literal("tpask").redirect(node));
} }
private static void execute(CommandContext<ServerCommandSource> context) { private static void execute(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
var source = context.getSource(); var source = context.getSource();
if (!source.isExecutedByPlayer()) { var player = context.getSource().getPlayerOrThrow();
source.sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return;
}
var server = source.getServer(); var server = source.getServer();
var player = source.getPlayer();
var targetName = StringArgumentType.getString(context, "player"); var targetName = StringArgumentType.getString(context, "player");
var playerManager = server.getPlayerManager(); var playerManager = server.getPlayerManager();
var target = playerManager.getPlayer(targetName); var target = playerManager.getPlayer(targetName);
@ -51,7 +49,7 @@ public class TeleportAskCommand {
var placeholders = Map.of( var placeholders = Map.of(
"targetPlayer", Text.of(targetName) "targetPlayer", Text.of(targetName)
); );
source.sendFeedback(() -> Components.parse( source.sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.teleportRequest.playerNotFound, RccServer.CONFIG.textFormats.commands.teleportRequest.playerNotFound,
playerContext, playerContext,
placeholders placeholders
@ -75,13 +73,13 @@ public class TeleportAskCommand {
"/tpdeny " + request.requestId) "/tpdeny " + request.requestId)
); );
target.sendMessage(Components.parse( target.sendMessage(Placeholder.parse(
RccServer.CONFIG.textFormats.commands.teleportRequest.pendingTeleport, RccServer.CONFIG.textFormats.commands.teleportRequest.pendingTeleport,
targetContext, targetContext,
placeholders placeholders
)); ));
source.sendFeedback(() -> Components.parse( source.sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.teleportRequest.requestSent, RccServer.CONFIG.textFormats.commands.teleportRequest.requestSent,
playerContext playerContext
), false); ), false);

View file

@ -1,11 +1,13 @@
package cc.reconnected.server.commands.teleport; package cc.reconnected.server.commands.teleport;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.core.TeleportTracker; import cc.reconnected.server.core.TeleportTracker;
import cc.reconnected.server.util.Components; import cc.reconnected.server.util.Components;
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 com.mojang.brigadier.exceptions.CommandSyntaxException;
import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.PlaceholderContext;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
@ -34,15 +36,10 @@ public class TeleportAskHereCommand {
dispatcher.register(literal("tpaskhere").redirect(node)); dispatcher.register(literal("tpaskhere").redirect(node));
} }
private static void execute(CommandContext<ServerCommandSource> context) { private static void execute(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
var source = context.getSource(); var source = context.getSource();
if (!source.isExecutedByPlayer()) { var player = context.getSource().getPlayerOrThrow();
source.sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return;
}
var server = source.getServer(); var server = source.getServer();
var player = source.getPlayer();
var targetName = StringArgumentType.getString(context, "player"); var targetName = StringArgumentType.getString(context, "player");
var playerManager = server.getPlayerManager(); var playerManager = server.getPlayerManager();
var target = playerManager.getPlayer(targetName); var target = playerManager.getPlayer(targetName);
@ -51,7 +48,7 @@ public class TeleportAskHereCommand {
var placeholders = Map.of( var placeholders = Map.of(
"targetPlayer", Text.of(targetName) "targetPlayer", Text.of(targetName)
); );
source.sendFeedback(() -> Components.parse( source.sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.teleportRequest.playerNotFound, RccServer.CONFIG.textFormats.commands.teleportRequest.playerNotFound,
playerContext, playerContext,
placeholders placeholders
@ -76,13 +73,13 @@ public class TeleportAskHereCommand {
"/tpdeny " + request.requestId) "/tpdeny " + request.requestId)
); );
target.sendMessage(Components.parse( target.sendMessage(Placeholder.parse(
RccServer.CONFIG.textFormats.commands.teleportRequest.pendingTeleportHere, RccServer.CONFIG.textFormats.commands.teleportRequest.pendingTeleportHere,
targetContext, targetContext,
placeholders placeholders
)); ));
source.sendFeedback(() -> Components.parse( source.sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.teleportRequest.requestSent, RccServer.CONFIG.textFormats.commands.teleportRequest.requestSent,
playerContext playerContext
), false); ), false);

View file

@ -1,5 +1,6 @@
package cc.reconnected.server.commands.teleport; package cc.reconnected.server.commands.teleport;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.core.TeleportTracker; import cc.reconnected.server.core.TeleportTracker;
import cc.reconnected.server.util.Components; import cc.reconnected.server.util.Components;
@ -33,7 +34,7 @@ public class TeleportDenyCommand {
var request = playerRequests.pollLast(); var request = playerRequests.pollLast();
if (request == null) { if (request == null) {
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.teleportRequest.noPending, RccServer.CONFIG.textFormats.commands.teleportRequest.noPending,
playerContext playerContext
), false); ), false);
@ -46,12 +47,7 @@ public class TeleportDenyCommand {
}) })
.then(argument("uuid", UuidArgumentType.uuid()) .then(argument("uuid", UuidArgumentType.uuid())
.executes(context -> { .executes(context -> {
if (!context.getSource().isExecutedByPlayer()) { var player = context.getSource().getPlayerOrThrow();
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1;
}
var player = context.getSource().getPlayer();
var uuid = UuidArgumentType.getUuid(context, "uuid"); var uuid = UuidArgumentType.getUuid(context, "uuid");
var playerUuid = player.getUuid(); var playerUuid = player.getUuid();
var playerRequests = TeleportTracker.teleportRequests.get(playerUuid); var playerRequests = TeleportTracker.teleportRequests.get(playerUuid);
@ -59,7 +55,7 @@ public class TeleportDenyCommand {
var request = playerRequests.stream().filter(req -> req.requestId.equals(uuid)).findFirst().orElse(null); var request = playerRequests.stream().filter(req -> req.requestId.equals(uuid)).findFirst().orElse(null);
if (request == null) { if (request == null) {
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.teleportRequest.unavailable, RccServer.CONFIG.textFormats.commands.teleportRequest.unavailable,
playerContext playerContext
), false); ), false);
@ -92,14 +88,14 @@ public class TeleportDenyCommand {
if (otherPlayer != null) { if (otherPlayer != null) {
var otherContext = PlaceholderContext.of(otherPlayer); var otherContext = PlaceholderContext.of(otherPlayer);
otherPlayer.sendMessage(Components.parse( otherPlayer.sendMessage(Placeholder.parse(
RccServer.CONFIG.textFormats.commands.teleportRequest.requestRefused, RccServer.CONFIG.textFormats.commands.teleportRequest.requestRefused,
otherContext, otherContext,
Map.of("player", player.getDisplayName()) Map.of("player", player.getDisplayName())
), false); ), false);
} }
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.teleportRequest.requestRefusedResult, RccServer.CONFIG.textFormats.commands.teleportRequest.requestRefusedResult,
playerContext playerContext
), false); ), false);

View file

@ -1,5 +1,6 @@
package cc.reconnected.server.commands.tell; package cc.reconnected.server.commands.tell;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.util.Components; import cc.reconnected.server.util.Components;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
@ -30,7 +31,7 @@ public class ReplyCommand {
if (!TellCommand.lastSender.containsKey(senderName)) { if (!TellCommand.lastSender.containsKey(senderName)) {
var playerContext = PlaceholderContext.of(context.getSource()); var playerContext = PlaceholderContext.of(context.getSource());
source.sendFeedback(() -> Components.parse( source.sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.tell.noLastSenderReply, RccServer.CONFIG.textFormats.commands.tell.noLastSenderReply,
playerContext playerContext
), false); ), false);

View file

@ -1,5 +1,6 @@
package cc.reconnected.server.commands.tell; package cc.reconnected.server.commands.tell;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.util.Components; import cc.reconnected.server.util.Components;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
@ -62,7 +63,7 @@ public class TellCommand {
); );
var sourceContext = PlaceholderContext.of(source); var sourceContext = PlaceholderContext.of(source);
source.sendFeedback(() -> Components.parse( source.sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.tell.playerNotFound, RccServer.CONFIG.textFormats.commands.tell.playerNotFound,
sourceContext, sourceContext,
placeholders placeholders
@ -84,7 +85,7 @@ public class TellCommand {
} }
var you = Components.parse(RccServer.CONFIG.textFormats.commands.tell.you); var you = Placeholder.parse(RccServer.CONFIG.textFormats.commands.tell.you);
var placeholdersToSource = Map.of( var placeholdersToSource = Map.of(
"sourcePlayer", you, "sourcePlayer", you,
@ -104,22 +105,22 @@ public class TellCommand {
"message", parsedMessage "message", parsedMessage
); );
var sourceText = Components.parse( var sourceText = Placeholder.parse(
RccServer.CONFIG.textFormats.commands.tell.message, RccServer.CONFIG.textFormats.commands.tell.message,
sourceContext, sourceContext,
placeholdersToSource placeholdersToSource
); );
var targetText = Components.parse( var targetText = Placeholder.parse(
RccServer.CONFIG.textFormats.commands.tell.message, RccServer.CONFIG.textFormats.commands.tell.message,
targetContext, targetContext,
placeholdersToTarget placeholdersToTarget
); );
var genericText = Components.parse( var genericText = Placeholder.parse(
RccServer.CONFIG.textFormats.commands.tell.message, RccServer.CONFIG.textFormats.commands.tell.message,
serverContext, serverContext,
placeholders placeholders
); );
var spyText = Components.parse( var spyText = Placeholder.parse(
RccServer.CONFIG.textFormats.commands.tell.messageSpy, RccServer.CONFIG.textFormats.commands.tell.messageSpy,
serverContext, serverContext,
placeholders placeholders

View file

@ -31,11 +31,6 @@ public class DeleteWarpCommand {
} }
private static int execute(CommandContext<ServerCommandSource> context, String name) { private static int execute(CommandContext<ServerCommandSource> context, String name) {
if (!context.getSource().isExecutedByPlayer()) {
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1;
}
var player = context.getSource().getPlayer();
var serverState = RccServer.state.getServerState(); var serverState = RccServer.state.getServerState();
var warps = serverState.warps; var warps = serverState.warps;

View file

@ -5,6 +5,7 @@ import cc.reconnected.server.struct.ServerPosition;
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 com.mojang.brigadier.exceptions.CommandSyntaxException;
import me.lucko.fabric.api.permissions.v0.Permissions; import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.Text; import net.minecraft.text.Text;
@ -24,12 +25,8 @@ public class SetWarpCommand {
dispatcher.register(rootCommand); dispatcher.register(rootCommand);
} }
private static int execute(CommandContext<ServerCommandSource> context, String name) { private static int execute(CommandContext<ServerCommandSource> context, String name) throws CommandSyntaxException {
if (!context.getSource().isExecutedByPlayer()) { var player = context.getSource().getPlayerOrThrow();
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1;
}
var player = context.getSource().getPlayer();
var serverState = RccServer.state.getServerState(); var serverState = RccServer.state.getServerState();
var warps = serverState.warps; var warps = serverState.warps;

View file

@ -1,10 +1,12 @@
package cc.reconnected.server.commands.warp; package cc.reconnected.server.commands.warp;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.util.Components; import cc.reconnected.server.util.Components;
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 com.mojang.brigadier.exceptions.CommandSyntaxException;
import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.PlaceholderContext;
import me.lucko.fabric.api.permissions.v0.Permissions; import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.command.CommandSource; import net.minecraft.command.CommandSource;
@ -33,25 +35,21 @@ public class WarpCommand {
dispatcher.register(rootCommand); dispatcher.register(rootCommand);
} }
private static int execute(CommandContext<ServerCommandSource> context, String name) { private static int execute(CommandContext<ServerCommandSource> context, String name) throws CommandSyntaxException {
if (!context.getSource().isExecutedByPlayer()) { var player = context.getSource().getPlayerOrThrow();
context.getSource().sendFeedback(() -> Text.of("This command can only be executed by players!"), false);
return 1;
}
var player = context.getSource().getPlayer();
var serverState = RccServer.state.getServerState(); var serverState = RccServer.state.getServerState();
var warps = serverState.warps; var warps = serverState.warps;
var playerContext = PlaceholderContext.of(player); var playerContext = PlaceholderContext.of(player);
if (!warps.containsKey(name)) { if (!warps.containsKey(name)) {
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.warp.warpNotFound, RccServer.CONFIG.textFormats.commands.warp.warpNotFound,
playerContext playerContext
), false); ), false);
return 1; return 1;
} }
context.getSource().sendFeedback(() -> Components.parse( context.getSource().sendFeedback(() -> Placeholder.parse(
RccServer.CONFIG.textFormats.commands.warp.teleporting, RccServer.CONFIG.textFormats.commands.warp.teleporting,
playerContext, playerContext,
Map.of( Map.of(

View file

@ -1,46 +0,0 @@
package cc.reconnected.server.config;
import cc.reconnected.server.RccServer;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import net.fabricmc.loader.api.FabricLoader;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.FileWriter;
import java.nio.charset.StandardCharsets;
import java.nio.file.Path;
public class ConfigManager {
private static final Gson gson = new GsonBuilder()
.disableHtmlEscaping()
.setPrettyPrinting()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ssXXX")
.create();
private static final Path configFilePath = FabricLoader.getInstance().getConfigDir().resolve(RccServer.MOD_ID + ".json");
private static Config config = null;
public static Config load() {
if (!configFilePath.toFile().exists()) {
config = new Config();
save();
return config;
}
try (var bf = new BufferedReader(new FileReader(configFilePath.toFile(), StandardCharsets.UTF_8))) {
config = gson.fromJson(bf, Config.class);
save();
} catch (Exception e) {
RccServer.LOGGER.error("Error loading the RccServer config file.", e);
}
return config;
}
public static void save() {
var json = gson.toJson(config);
try (var fw = new FileWriter(configFilePath.toFile(), StandardCharsets.UTF_8)) {
fw.write(json);
} catch (Exception e) {
RccServer.LOGGER.error("Error saving the RccServer config file.", e);
}
}
}

View file

@ -1,5 +1,6 @@
package cc.reconnected.server.core; package cc.reconnected.server.core;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.api.events.PlayerActivityEvents; import cc.reconnected.server.api.events.PlayerActivityEvents;
import cc.reconnected.server.api.events.RccEvents; import cc.reconnected.server.api.events.RccEvents;
@ -55,7 +56,7 @@ public class AfkTracker {
var playerContext = PlaceholderContext.of(player); var playerContext = PlaceholderContext.of(player);
RccServer.getInstance().broadcast(Components.parse( RccServer.getInstance().broadcast(Placeholder.parse(
RccServer.CONFIG.textFormats.commands.afk.goneAfk, RccServer.CONFIG.textFormats.commands.afk.goneAfk,
playerContext playerContext
)); ));
@ -66,7 +67,7 @@ public class AfkTracker {
var playerContext = PlaceholderContext.of(player); var playerContext = PlaceholderContext.of(player);
RccServer.getInstance().broadcast(Components.parse( RccServer.getInstance().broadcast(Placeholder.parse(
RccServer.CONFIG.textFormats.commands.afk.returnAfk, RccServer.CONFIG.textFormats.commands.afk.returnAfk,
playerContext playerContext
)); ));

View file

@ -1,104 +0,0 @@
package cc.reconnected.server.core;
import cc.reconnected.server.RccServer;
import com.sun.net.httpserver.HttpExchange;
import com.sun.net.httpserver.HttpHandler;
import com.sun.net.httpserver.HttpServer;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents;
import java.io.IOException;
import java.net.InetSocketAddress;
public class HttpApiServer {
private static HttpApiServer instance;
public static HttpApiServer getInstance() {
return instance;
}
private static float currentTps = 0;
private static float currentMspt = 0;
private static int currentPlayerCount = 0;
public static void register() {
if (!RccServer.CONFIG.httpApi.enableHttpApi)
return;
try {
instance = new HttpApiServer();
} catch (IOException e) {
RccServer.LOGGER.error("Could not start HTTP API server", e);
return;
}
new Thread(() -> instance.httpServer().start());
ServerLifecycleEvents.SERVER_STOPPING.register(server -> {
RccServer.LOGGER.info("Stopping HTTP services");
instance.httpServer().stop(0);
});
ServerTickEvents.END_SERVER_TICK.register(server -> {
currentMspt = server.getTickTime();
if (currentMspt != 0) {
currentTps = Math.min(20, 1000 / currentMspt);
}
});
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
currentPlayerCount = server.getCurrentPlayerCount() + 1;
});
ServerPlayConnectionEvents.DISCONNECT.register((handler, server) -> {
currentPlayerCount = server.getCurrentPlayerCount() - 1;
});
}
private final HttpServer server;
public HttpServer httpServer() {
return this.server;
}
private HttpApiServer() throws IOException {
server = HttpServer.create(new InetSocketAddress(RccServer.CONFIG.httpApi.httpPort), 0);
server.createContext("/tps", new TPSHandler());
server.createContext("/mspt", new MSPTHandler());
server.createContext("/player", new PlayerCountHandler());
server.setExecutor(null);
}
static class TPSHandler implements HttpHandler {
@Override
public void handle(HttpExchange t) throws IOException {
var tps = String.valueOf(currentTps);
t.sendResponseHeaders(200, tps.length());
var body = t.getResponseBody();
body.write(tps.getBytes());
body.close();
}
}
static class MSPTHandler implements HttpHandler {
@Override
public void handle(HttpExchange t) throws IOException {
var tps = String.valueOf(currentTps);
t.sendResponseHeaders(200, tps.length());
var body = t.getResponseBody();
body.write(tps.getBytes());
body.close();
}
}
static class PlayerCountHandler implements HttpHandler {
@Override
public void handle(HttpExchange t) throws IOException {
var tps = String.valueOf(currentPlayerCount);
t.sendResponseHeaders(200, tps.length());
var body = t.getResponseBody();
body.write(tps.getBytes());
body.close();
}
}
}

View file

@ -1,5 +1,6 @@
package cc.reconnected.server.core.customChat; package cc.reconnected.server.core.customChat;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.util.Components; import cc.reconnected.server.util.Components;
import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.PlaceholderContext;
@ -28,7 +29,7 @@ public class CustomChatMessage {
Text messageText = Components.chat(message, player); Text messageText = Components.chat(message, player);
var playerContext = PlaceholderContext.of(player); var playerContext = PlaceholderContext.of(player);
var text = Components.parse( var text = Placeholder.parse(
RccServer.CONFIG.textFormats.chatFormat, RccServer.CONFIG.textFormats.chatFormat,
playerContext, playerContext,
Map.of( Map.of(

View file

@ -1,5 +1,6 @@
package cc.reconnected.server.core.customChat; package cc.reconnected.server.core.customChat;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.util.Components; import cc.reconnected.server.util.Components;
import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.PlaceholderContext;
@ -11,7 +12,7 @@ import java.util.Map;
public class CustomConnectionMessage { public class CustomConnectionMessage {
public static Text onJoin(ServerPlayerEntity player) { public static Text onJoin(ServerPlayerEntity player) {
var playerContext = PlaceholderContext.of(player); var playerContext = PlaceholderContext.of(player);
return Components.parse( return Placeholder.parse(
RccServer.CONFIG.textFormats.joinFormat, RccServer.CONFIG.textFormats.joinFormat,
playerContext playerContext
); );
@ -19,7 +20,7 @@ public class CustomConnectionMessage {
public static Text onJoinRenamed(ServerPlayerEntity player, String previousName) { public static Text onJoinRenamed(ServerPlayerEntity player, String previousName) {
var playerContext = PlaceholderContext.of(player); var playerContext = PlaceholderContext.of(player);
return Components.parse( return Placeholder.parse(
RccServer.CONFIG.textFormats.joinRenamedFormat, RccServer.CONFIG.textFormats.joinRenamedFormat,
playerContext, playerContext,
Map.of("previousName", Text.of(previousName)) Map.of("previousName", Text.of(previousName))
@ -28,7 +29,7 @@ public class CustomConnectionMessage {
public static Text onLeave(ServerPlayerEntity player) { public static Text onLeave(ServerPlayerEntity player) {
var playerContext = PlaceholderContext.of(player); var playerContext = PlaceholderContext.of(player);
return Components.parse( return Placeholder.parse(
RccServer.CONFIG.textFormats.leaveFormat, RccServer.CONFIG.textFormats.leaveFormat,
playerContext playerContext
); );

View file

@ -1,5 +1,6 @@
package cc.reconnected.server.core.customChat; package cc.reconnected.server.core.customChat;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.util.Components; import cc.reconnected.server.util.Components;
import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.PlaceholderContext;
@ -14,7 +15,7 @@ public class CustomDeathMessage {
var deathMessage = instance.getDeathMessage(); var deathMessage = instance.getDeathMessage();
var playerContext = PlaceholderContext.of(player); var playerContext = PlaceholderContext.of(player);
return Components.parse( return Placeholder.parse(
RccServer.CONFIG.textFormats.deathFormat, RccServer.CONFIG.textFormats.deathFormat,
playerContext, playerContext,
Map.of("message", deathMessage) Map.of("message", deathMessage)

View file

@ -1,5 +1,6 @@
package cc.reconnected.server.core.customChat; package cc.reconnected.server.core.customChat;
import cc.reconnected.library.text.Placeholder;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.util.Components; import cc.reconnected.server.util.Components;
import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.PlaceholderContext;
@ -19,7 +20,7 @@ public class CustomEmoteMessage {
Text messageText = Components.chat(message, player); Text messageText = Components.chat(message, player);
var text = Components.parse( var text = Placeholder.parse(
RccServer.CONFIG.textFormats.emoteFormat, RccServer.CONFIG.textFormats.emoteFormat,
playerContext, playerContext,
Map.of( Map.of(

View file

@ -1,5 +1,6 @@
package cc.reconnected.server.mixin; package cc.reconnected.server.mixin;
import cc.reconnected.server.RccServer;
import cc.reconnected.server.core.customChat.CustomSentMessage; import cc.reconnected.server.core.customChat.CustomSentMessage;
import net.minecraft.network.message.SentMessage; import net.minecraft.network.message.SentMessage;
import net.minecraft.network.message.SignedMessage; import net.minecraft.network.message.SignedMessage;
@ -10,11 +11,11 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(SentMessage.class) @Mixin(SentMessage.class)
public interface SentMessageMixin { public interface SentMessageMixin {
@Inject(method = "of", at = @At("HEAD"), cancellable = true) @Inject(method = "of", at = @At("HEAD"), cancellable = true)
private static void rccServer$of(SignedMessage message, CallbackInfoReturnable<SentMessage> cir) { private static void rccServer$of(SignedMessage message, CallbackInfoReturnable<SentMessage> cir) {
if(message.isSenderMissing()) { if (message.isSenderMissing()) {
RccServer.warnUnsignedMessages();
cir.setReturnValue(new SentMessage.Profileless(message.getContent())); cir.setReturnValue(new SentMessage.Profileless(message.getContent()));
} else { } else {
cir.setReturnValue(new CustomSentMessage(message)); cir.setReturnValue(new CustomSentMessage(message));

View file

@ -19,7 +19,7 @@ import java.util.EnumSet;
import java.util.List; import java.util.List;
@Mixin(ServerPlayNetworkHandler.class) @Mixin(ServerPlayNetworkHandler.class)
public abstract class ServerPlayNetworkManagerMixin { public abstract class ServerPlayNetworkHandlerMixin {
@Shadow @Shadow
@Final @Final
private MinecraftServer server; private MinecraftServer server;

View file

@ -1,13 +1,17 @@
package cc.reconnected.server.mixin; package cc.reconnected.server.mixin;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.core.BackTracker;
import cc.reconnected.server.core.customChat.CustomDeathMessage; import cc.reconnected.server.core.customChat.CustomDeathMessage;
import cc.reconnected.server.struct.ServerPosition;
import eu.pb4.placeholders.api.PlaceholderContext; import eu.pb4.placeholders.api.PlaceholderContext;
import eu.pb4.placeholders.api.Placeholders; import eu.pb4.placeholders.api.Placeholders;
import eu.pb4.placeholders.api.parsers.NodeParser; import eu.pb4.placeholders.api.parsers.NodeParser;
import eu.pb4.placeholders.api.parsers.TextParserV1; import eu.pb4.placeholders.api.parsers.TextParserV1;
import net.minecraft.entity.damage.DamageTracker; import net.minecraft.entity.damage.DamageTracker;
import net.minecraft.network.packet.s2c.play.PositionFlag;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.Unique;
@ -16,6 +20,8 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import java.util.Set;
@Mixin(ServerPlayerEntity.class) @Mixin(ServerPlayerEntity.class)
public class ServerPlayerEntityMixin { public class ServerPlayerEntityMixin {
@Unique @Unique
@ -36,4 +42,10 @@ public class ServerPlayerEntityMixin {
var player = (ServerPlayerEntity) (Object) this; var player = (ServerPlayerEntity) (Object) this;
return CustomDeathMessage.onDeath(player, instance); return CustomDeathMessage.onDeath(player, instance);
} }
@Inject(method = "teleport(Lnet/minecraft/server/world/ServerWorld;DDDLjava/util/Set;FF)Z", at = @At("HEAD"))
public void rccServer$requestTeleport(ServerWorld world, double destX, double destY, double destZ, Set<PositionFlag> flags, float yaw, float pitch, CallbackInfoReturnable<Boolean> cir) {
var player = (ServerPlayerEntity) (Object) this;
BackTracker.lastPlayerPositions.put(player.getUuid(), new ServerPosition(player));
}
} }

View file

@ -1,99 +0,0 @@
package cc.reconnected.server.parser;
import cc.reconnected.server.RccServer;
import cc.reconnected.server.util.Components;
import eu.pb4.placeholders.api.node.DirectTextNode;
import eu.pb4.placeholders.api.node.LiteralNode;
import eu.pb4.placeholders.api.node.TextNode;
import eu.pb4.placeholders.api.node.parent.ParentNode;
import eu.pb4.placeholders.api.parsers.NodeParser;
import net.minecraft.text.ClickEvent;
import net.minecraft.text.HoverEvent;
import net.minecraft.text.Style;
import net.minecraft.text.Text;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
public class LinkParser implements NodeParser {
public static final Pattern URL_REGEX = Pattern.compile("https?:\\/\\/(www\\.)?[-a-zA-Z0-9@:%._\\+~#=]{1,256}\\.[a-zA-Z0-9()]{1,6}\\b([-a-zA-Z0-9()@:%_\\+.~#?&//=]*)");
@Override
public TextNode[] parseNodes(TextNode node) {
if (node instanceof LiteralNode literalNode) {
var input = literalNode.value();
var list = new ArrayList<TextNode>();
var inputLength = input.length();
var matcher = URL_REGEX.matcher(input);
int pos = 0;
while (matcher.find()) {
if (inputLength <= matcher.start()) {
break;
}
String betweenText = input.substring(pos, matcher.start());
if (!betweenText.isEmpty()) {
list.add(new LiteralNode(betweenText));
}
var link = matcher.group();
var url = Text.of(link);
var placeholders = Map.of(
"url", url,
"label", url
);
var display = Components.parse(
RccServer.CONFIG.textFormats.link,
placeholders
);
var hover = Components.parse(
RccServer.CONFIG.textFormats.linkHover,
placeholders
);
var text = Text.empty()
.append(display)
.setStyle(Style.EMPTY
.withHoverEvent(
new HoverEvent(HoverEvent.Action.SHOW_TEXT, hover)
)
.withClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, link))
);
list.add(new DirectTextNode(text));
pos = matcher.end();
}
if (pos < inputLength) {
var text = input.substring(pos, inputLength);
if (!text.isEmpty()) {
list.add(new LiteralNode(text));
}
}
return list.toArray(TextNode[]::new);
} else if (node instanceof ParentNode parentNode) {
var list = new ArrayList<TextNode>();
for (var child : parentNode.getChildren()) {
list.addAll(List.of(this.parseNodes(child)));
}
return new TextNode[]{
parentNode.copyWith(list.toArray(TextNode[]::new))
};
}
return TextNode.array(node);
}
}

View file

@ -1,52 +0,0 @@
package cc.reconnected.server.parser;
import cc.reconnected.server.RccServer;
import cc.reconnected.server.util.Components;
import eu.pb4.placeholders.api.node.TextNode;
import eu.pb4.placeholders.api.node.parent.ClickActionNode;
import eu.pb4.placeholders.api.node.parent.FormattingNode;
import eu.pb4.placeholders.api.node.parent.HoverNode;
import net.minecraft.text.ClickEvent;
import net.minecraft.util.Formatting;
import java.util.Map;
public class MarkdownComponentParser {
public static TextNode spoilerFormatting(TextNode[] textNodes) {
var text = TextNode.asSingle(textNodes);
return new HoverNode<>(
TextNode.array(
new FormattingNode(TextNode.array(TextNode.of("\u258C".repeat(text.toText().getString().length()))), Formatting.DARK_GRAY)
),
HoverNode.Action.TEXT, text);
}
public static TextNode quoteFormatting(TextNode[] textNodes) {
return new ClickActionNode(
TextNode.array(
new HoverNode<>(
TextNode.array(new FormattingNode(textNodes, Formatting.GRAY)),
HoverNode.Action.TEXT, TextNode.of("Click to copy"))
),
ClickEvent.Action.COPY_TO_CLIPBOARD, TextNode.asSingle(textNodes)
);
}
public static TextNode urlFormatting(TextNode[] textNodes, TextNode url) {
var placeholders = Map.of(
"label", TextNode.wrap(textNodes).toText(),
"url", url.toText()
);
var text = Components.parse(RccServer.CONFIG.textFormats.link, placeholders);
var hover = Components.parse(RccServer.CONFIG.textFormats.linkHover, placeholders);
return new HoverNode<>(TextNode.array(
new ClickActionNode(
TextNode.array(
TextNode.convert(text)
),
ClickEvent.Action.OPEN_URL, url)),
HoverNode.Action.TEXT, TextNode.convert(hover)
);
}
}

View file

@ -1,32 +0,0 @@
package cc.reconnected.server.parser;
import eu.pb4.placeholders.api.parsers.MarkdownLiteParserV1;
import eu.pb4.placeholders.api.parsers.NodeParser;
import static eu.pb4.placeholders.api.parsers.MarkdownLiteParserV1.MarkdownFormat;
public class MarkdownParser {
public static final MarkdownFormat[] ALL = new MarkdownFormat[]{
MarkdownFormat.QUOTE,
MarkdownFormat.BOLD,
MarkdownFormat.ITALIC,
MarkdownFormat.UNDERLINE,
MarkdownFormat.STRIKETHROUGH,
MarkdownFormat.SPOILER,
MarkdownFormat.URL
};
public static final NodeParser defaultParser = createParser(ALL);
public static NodeParser createParser(MarkdownFormat[] capabilities) {
var mdParser = new MarkdownLiteParserV1(
MarkdownComponentParser::spoilerFormatting,
MarkdownComponentParser::quoteFormatting,
MarkdownComponentParser::urlFormatting,
capabilities
);
return NodeParser.merge(mdParser, new LinkParser());
}
}

View file

@ -1,16 +1,12 @@
package cc.reconnected.server.util; package cc.reconnected.server.util;
import cc.reconnected.library.text.parser.MarkdownParser;
import cc.reconnected.server.RccServer; import cc.reconnected.server.RccServer;
import cc.reconnected.server.parser.MarkdownParser;
import eu.pb4.placeholders.api.PlaceholderContext;
import eu.pb4.placeholders.api.Placeholders; import eu.pb4.placeholders.api.Placeholders;
import eu.pb4.placeholders.api.TextParserUtils; import eu.pb4.placeholders.api.TextParserUtils;
import eu.pb4.placeholders.api.node.TextNode;
import eu.pb4.placeholders.api.parsers.NodeParser; import eu.pb4.placeholders.api.parsers.NodeParser;
import eu.pb4.placeholders.api.parsers.PatternPlaceholderParser; import eu.pb4.placeholders.api.parsers.PatternPlaceholderParser;
import eu.pb4.placeholders.api.parsers.TextParserV1; import eu.pb4.placeholders.api.parsers.TextParserV1;
import net.fabricmc.fabric.api.entity.event.v1.ServerPlayerEvents;
import net.fabricmc.fabric.api.message.v1.ServerMessageEvents;
import net.kyori.adventure.text.Component; import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.ComponentLike; import net.kyori.adventure.text.ComponentLike;
import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.event.ClickEvent;
@ -65,31 +61,6 @@ public class Components {
return Text.Serializer.fromJson(json); return Text.Serializer.fromJson(json);
} }
public static Text parse(String text) {
return TextParserUtils.formatText(text);
}
public static Text parse(TextNode textNode, PlaceholderContext context, Map<String, Text> placeholders) {
var predefinedNode = Placeholders.parseNodes(textNode, PatternPlaceholderParser.PREDEFINED_PLACEHOLDER_PATTERN, placeholders);
return Placeholders.parseText(predefinedNode, context);
}
public static Text parse(Text text, PlaceholderContext context, Map<String, Text> placeholders) {
return parse(TextNode.convert(text), context, placeholders);
}
public static Text parse(String text, PlaceholderContext context, Map<String, Text> placeholders) {
return parse(parse(text), context, placeholders);
}
public static Text parse(String text, PlaceholderContext context) {
return parse(parse(text), context, Map.of());
}
public static Text parse(String text, Map<String, Text> placeholders) {
return Placeholders.parseText(parse(text), PatternPlaceholderParser.PREDEFINED_PLACEHOLDER_PATTERN, placeholders);
}
public static Text chat(SignedMessage message, ServerPlayerEntity player) { public static Text chat(SignedMessage message, ServerPlayerEntity player) {
var luckperms = RccServer.getInstance().luckPerms(); var luckperms = RccServer.getInstance().luckPerms();

View file

@ -12,7 +12,7 @@
"RegistryLoaderMixin", "RegistryLoaderMixin",
"SentMessageMixin", "SentMessageMixin",
"ServerPlayerEntityMixin", "ServerPlayerEntityMixin",
"ServerPlayNetworkManagerMixin", "ServerPlayNetworkHandlerMixin",
"PlayerManagerMixin" "PlayerManagerMixin"
], ],