Compare commits
No commits in common. "8dcd83144370774fe3ae29e87130931545060162" and "822a8607565e8940e0f30c17f66791d5b97cc13a" have entirely different histories.
8dcd831443
...
822a860756
39 changed files with 548 additions and 186 deletions
|
|
@ -19,7 +19,6 @@ 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 {
|
||||||
|
|
@ -42,8 +41,6 @@ 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}")
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -9,15 +9,13 @@ 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.4
|
mod_version=1.17.1
|
||||||
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
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
@ -20,6 +19,8 @@ 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;
|
||||||
|
|
@ -51,7 +52,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 RccServerConfig CONFIG;
|
public static Config CONFIG = ConfigManager.load();
|
||||||
|
|
||||||
public static final StateManager state = new StateManager();
|
public static final StateManager state = new StateManager();
|
||||||
|
|
||||||
|
|
@ -61,6 +62,10 @@ 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() {
|
||||||
|
|
@ -80,23 +85,11 @@ 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));
|
||||||
|
|
@ -142,6 +135,7 @@ 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();
|
||||||
|
|
||||||
|
|
@ -202,20 +196,4 @@ 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!
|
|
||||||
"""
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -18,7 +18,11 @@ 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 -> {
|
||||||
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();
|
||||||
context.getSource().sendFeedback(() -> toggleFlight(player), true);
|
context.getSource().sendFeedback(() -> toggleFlight(player), true);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,11 @@ 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 -> {
|
||||||
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();
|
||||||
context.getSource().sendFeedback(() -> toggleGod(player), true);
|
context.getSource().sendFeedback(() -> toggleGod(player), true);
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
||||||
|
|
@ -1,53 +1,27 @@
|
||||||
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.util.Components;
|
import cc.reconnected.server.config.ConfigManager;
|
||||||
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(RccServerConfig.class);
|
RccServer.CONFIG = ConfigManager.load();
|
||||||
} 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;
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
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;
|
||||||
|
|
@ -36,8 +34,12 @@ public class DeleteHomeCommand {
|
||||||
dispatcher.register(rootCommand);
|
dispatcher.register(rootCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int execute(CommandContext<ServerCommandSource> context, String name) throws CommandSyntaxException {
|
private static int execute(CommandContext<ServerCommandSource> context, String name) {
|
||||||
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();
|
||||||
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());
|
||||||
|
|
@ -47,7 +49,7 @@ public class DeleteHomeCommand {
|
||||||
);
|
);
|
||||||
|
|
||||||
if (!homes.containsKey(name)) {
|
if (!homes.containsKey(name)) {
|
||||||
context.getSource().sendFeedback(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.home.homeNotFound,
|
RccServer.CONFIG.textFormats.commands.home.homeNotFound,
|
||||||
playerContext,
|
playerContext,
|
||||||
placeholders
|
placeholders
|
||||||
|
|
@ -58,7 +60,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(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.home.homeDeleted,
|
RccServer.CONFIG.textFormats.commands.home.homeDeleted,
|
||||||
playerContext,
|
playerContext,
|
||||||
placeholders
|
placeholders
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
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;
|
||||||
|
|
@ -36,8 +34,12 @@ public class HomeCommand {
|
||||||
dispatcher.register(rootCommand);
|
dispatcher.register(rootCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int execute(CommandContext<ServerCommandSource> context, String name) throws CommandSyntaxException {
|
private static int execute(CommandContext<ServerCommandSource> context, String name) {
|
||||||
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();
|
||||||
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());
|
||||||
|
|
@ -48,7 +50,7 @@ public class HomeCommand {
|
||||||
|
|
||||||
if (!homes.containsKey(name)) {
|
if (!homes.containsKey(name)) {
|
||||||
context.getSource().sendFeedback(() ->
|
context.getSource().sendFeedback(() ->
|
||||||
Placeholder.parse(
|
Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.home.homeNotFound,
|
RccServer.CONFIG.textFormats.commands.home.homeNotFound,
|
||||||
playerContext,
|
playerContext,
|
||||||
placeholders
|
placeholders
|
||||||
|
|
@ -58,7 +60,7 @@ public class HomeCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
context.getSource().sendFeedback(() ->
|
context.getSource().sendFeedback(() ->
|
||||||
Placeholder.parse(
|
Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.home.teleporting,
|
RccServer.CONFIG.textFormats.commands.home.teleporting,
|
||||||
playerContext,
|
playerContext,
|
||||||
placeholders
|
placeholders
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
@ -8,7 +7,6 @@ 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;
|
||||||
|
|
@ -38,8 +36,12 @@ public class SetHomeCommand {
|
||||||
dispatcher.register(rootCommand);
|
dispatcher.register(rootCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int execute(CommandContext<ServerCommandSource> context, String name, boolean forced) throws CommandSyntaxException {
|
private static int execute(CommandContext<ServerCommandSource> context, String name, boolean forced) {
|
||||||
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();
|
||||||
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);
|
||||||
|
|
@ -55,7 +57,7 @@ public class SetHomeCommand {
|
||||||
|
|
||||||
var exists = homes.containsKey(name);
|
var exists = homes.containsKey(name);
|
||||||
if (exists && !forced) {
|
if (exists && !forced) {
|
||||||
var text = Placeholder.parse(
|
var text = Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.home.homeExists,
|
RccServer.CONFIG.textFormats.commands.home.homeExists,
|
||||||
playerContext,
|
playerContext,
|
||||||
placeholders
|
placeholders
|
||||||
|
|
@ -67,8 +69,8 @@ public class SetHomeCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
var maxHomes = RccServer.CONFIG.homes.maxHomes;
|
var maxHomes = RccServer.CONFIG.homes.maxHomes;
|
||||||
if(maxHomes >= 0 && homes.size() >= maxHomes && !exists) {
|
if(homes.size() >= maxHomes && !exists) {
|
||||||
context.getSource().sendFeedback(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.home.maxHomesReached,
|
RccServer.CONFIG.textFormats.commands.home.maxHomesReached,
|
||||||
playerContext,
|
playerContext,
|
||||||
placeholders
|
placeholders
|
||||||
|
|
@ -81,7 +83,7 @@ public class SetHomeCommand {
|
||||||
|
|
||||||
RccServer.state.savePlayerState(player.getUuid(), playerState);
|
RccServer.state.savePlayerState(player.getUuid(), playerState);
|
||||||
|
|
||||||
context.getSource().sendFeedback(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.home.homeSetSuccess,
|
RccServer.CONFIG.textFormats.commands.home.homeSetSuccess,
|
||||||
playerContext,
|
playerContext,
|
||||||
placeholders
|
placeholders
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,13 @@ 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;
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
@ -23,9 +22,21 @@ 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 -> execute(context, RccServer.CONFIG.nearCommand.nearCommandDefaultRange, context.getSource().getPlayerOrThrow()))
|
.executes(context -> {
|
||||||
|
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 -> execute(context, IntegerArgumentType.getInteger(context, "radius"), context.getSource().getPlayerOrThrow())));
|
.executes(context -> {
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
@ -44,7 +55,7 @@ public class NearCommand {
|
||||||
});
|
});
|
||||||
|
|
||||||
if (list.isEmpty()) {
|
if (list.isEmpty()) {
|
||||||
context.getSource().sendFeedback(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.near.noOne,
|
RccServer.CONFIG.textFormats.commands.near.noOne,
|
||||||
playerContext
|
playerContext
|
||||||
), false);
|
), false);
|
||||||
|
|
@ -54,7 +65,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 = Placeholder.parse(RccServer.CONFIG.textFormats.commands.near.comma);
|
var comma = Components.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) {
|
||||||
|
|
@ -67,7 +78,7 @@ public class NearCommand {
|
||||||
|
|
||||||
var targetContext = PlaceholderContext.of(sourcePlayer);
|
var targetContext = PlaceholderContext.of(sourcePlayer);
|
||||||
|
|
||||||
listText = listText.append(Placeholder.parse(
|
listText = listText.append(Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.near.format,
|
RccServer.CONFIG.textFormats.commands.near.format,
|
||||||
targetContext,
|
targetContext,
|
||||||
placeholders
|
placeholders
|
||||||
|
|
@ -77,7 +88,7 @@ public class NearCommand {
|
||||||
var placeholders = Map.of(
|
var placeholders = Map.of(
|
||||||
"playerList", (Text) listText
|
"playerList", (Text) listText
|
||||||
);
|
);
|
||||||
context.getSource().sendFeedback(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.near.nearestPlayers,
|
RccServer.CONFIG.textFormats.commands.near.nearestPlayers,
|
||||||
playerContext,
|
playerContext,
|
||||||
placeholders
|
placeholders
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,12 @@ 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 -> {
|
||||||
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();
|
||||||
var spawnPosition = new ServerPosition(player);
|
var spawnPosition = new ServerPosition(player);
|
||||||
|
|
||||||
var serverState = RccServer.state.getServerState();
|
var serverState = RccServer.state.getServerState();
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
@ -17,7 +16,12 @@ 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 -> {
|
||||||
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();
|
||||||
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;
|
||||||
|
|
@ -27,7 +31,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(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.spawn.teleporting,
|
RccServer.CONFIG.textFormats.commands.spawn.teleporting,
|
||||||
playerContext
|
playerContext
|
||||||
), false);
|
), false);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
@ -17,19 +16,24 @@ 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 -> {
|
||||||
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();
|
||||||
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(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.back.noPosition,
|
RccServer.CONFIG.textFormats.commands.back.noPosition,
|
||||||
playerContext
|
playerContext
|
||||||
), false);
|
), false);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.getSource().sendFeedback(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.back.teleporting,
|
RccServer.CONFIG.textFormats.commands.back.teleporting,
|
||||||
playerContext
|
playerContext
|
||||||
), false);
|
), false);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
@ -21,7 +20,12 @@ 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 -> {
|
||||||
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();
|
||||||
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);
|
||||||
|
|
@ -29,7 +33,7 @@ public class TeleportAcceptCommand {
|
||||||
var request = playerRequests.pollLast();
|
var request = playerRequests.pollLast();
|
||||||
|
|
||||||
if (request == null) {
|
if (request == null) {
|
||||||
context.getSource().sendFeedback(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.teleportRequest.noPending,
|
RccServer.CONFIG.textFormats.commands.teleportRequest.noPending,
|
||||||
playerContext
|
playerContext
|
||||||
), false);
|
), false);
|
||||||
|
|
@ -55,7 +59,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(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.teleportRequest.unavailable,
|
RccServer.CONFIG.textFormats.commands.teleportRequest.unavailable,
|
||||||
playerContext
|
playerContext
|
||||||
), false);
|
), false);
|
||||||
|
|
@ -84,7 +88,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(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.teleportRequest.playerUnavailable,
|
RccServer.CONFIG.textFormats.commands.teleportRequest.playerUnavailable,
|
||||||
playerContext
|
playerContext
|
||||||
), false);
|
), false);
|
||||||
|
|
@ -94,23 +98,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(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.teleportRequest.requestAcceptedResult,
|
RccServer.CONFIG.textFormats.commands.teleportRequest.requestAcceptedResult,
|
||||||
playerContext
|
playerContext
|
||||||
), false);
|
), false);
|
||||||
sourcePlayer.sendMessage(Placeholder.parse(
|
sourcePlayer.sendMessage(Components.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(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.teleportRequest.teleporting,
|
RccServer.CONFIG.textFormats.commands.teleportRequest.teleporting,
|
||||||
playerContext
|
playerContext
|
||||||
), false);
|
), false);
|
||||||
|
|
||||||
targetPlayer.sendMessage(Placeholder.parse(
|
targetPlayer.sendMessage(Components.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())
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,11 @@
|
||||||
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;
|
||||||
|
|
@ -36,11 +34,15 @@ public class TeleportAskCommand {
|
||||||
dispatcher.register(literal("tpask").redirect(node));
|
dispatcher.register(literal("tpask").redirect(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void execute(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
private static void execute(CommandContext<ServerCommandSource> context) {
|
||||||
var source = context.getSource();
|
var source = context.getSource();
|
||||||
var player = context.getSource().getPlayerOrThrow();
|
if (!source.isExecutedByPlayer()) {
|
||||||
|
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);
|
||||||
|
|
@ -49,7 +51,7 @@ public class TeleportAskCommand {
|
||||||
var placeholders = Map.of(
|
var placeholders = Map.of(
|
||||||
"targetPlayer", Text.of(targetName)
|
"targetPlayer", Text.of(targetName)
|
||||||
);
|
);
|
||||||
source.sendFeedback(() -> Placeholder.parse(
|
source.sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.teleportRequest.playerNotFound,
|
RccServer.CONFIG.textFormats.commands.teleportRequest.playerNotFound,
|
||||||
playerContext,
|
playerContext,
|
||||||
placeholders
|
placeholders
|
||||||
|
|
@ -73,13 +75,13 @@ public class TeleportAskCommand {
|
||||||
"/tpdeny " + request.requestId)
|
"/tpdeny " + request.requestId)
|
||||||
);
|
);
|
||||||
|
|
||||||
target.sendMessage(Placeholder.parse(
|
target.sendMessage(Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.teleportRequest.pendingTeleport,
|
RccServer.CONFIG.textFormats.commands.teleportRequest.pendingTeleport,
|
||||||
targetContext,
|
targetContext,
|
||||||
placeholders
|
placeholders
|
||||||
));
|
));
|
||||||
|
|
||||||
source.sendFeedback(() -> Placeholder.parse(
|
source.sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.teleportRequest.requestSent,
|
RccServer.CONFIG.textFormats.commands.teleportRequest.requestSent,
|
||||||
playerContext
|
playerContext
|
||||||
), false);
|
), false);
|
||||||
|
|
|
||||||
|
|
@ -1,13 +1,11 @@
|
||||||
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;
|
||||||
|
|
@ -36,10 +34,15 @@ public class TeleportAskHereCommand {
|
||||||
dispatcher.register(literal("tpaskhere").redirect(node));
|
dispatcher.register(literal("tpaskhere").redirect(node));
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void execute(CommandContext<ServerCommandSource> context) throws CommandSyntaxException {
|
private static void execute(CommandContext<ServerCommandSource> context) {
|
||||||
var source = context.getSource();
|
var source = context.getSource();
|
||||||
var player = context.getSource().getPlayerOrThrow();
|
if (!source.isExecutedByPlayer()) {
|
||||||
|
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);
|
||||||
|
|
@ -48,7 +51,7 @@ public class TeleportAskHereCommand {
|
||||||
var placeholders = Map.of(
|
var placeholders = Map.of(
|
||||||
"targetPlayer", Text.of(targetName)
|
"targetPlayer", Text.of(targetName)
|
||||||
);
|
);
|
||||||
source.sendFeedback(() -> Placeholder.parse(
|
source.sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.teleportRequest.playerNotFound,
|
RccServer.CONFIG.textFormats.commands.teleportRequest.playerNotFound,
|
||||||
playerContext,
|
playerContext,
|
||||||
placeholders
|
placeholders
|
||||||
|
|
@ -73,13 +76,13 @@ public class TeleportAskHereCommand {
|
||||||
"/tpdeny " + request.requestId)
|
"/tpdeny " + request.requestId)
|
||||||
);
|
);
|
||||||
|
|
||||||
target.sendMessage(Placeholder.parse(
|
target.sendMessage(Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.teleportRequest.pendingTeleportHere,
|
RccServer.CONFIG.textFormats.commands.teleportRequest.pendingTeleportHere,
|
||||||
targetContext,
|
targetContext,
|
||||||
placeholders
|
placeholders
|
||||||
));
|
));
|
||||||
|
|
||||||
source.sendFeedback(() -> Placeholder.parse(
|
source.sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.teleportRequest.requestSent,
|
RccServer.CONFIG.textFormats.commands.teleportRequest.requestSent,
|
||||||
playerContext
|
playerContext
|
||||||
), false);
|
), false);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
@ -34,7 +33,7 @@ public class TeleportDenyCommand {
|
||||||
var request = playerRequests.pollLast();
|
var request = playerRequests.pollLast();
|
||||||
|
|
||||||
if (request == null) {
|
if (request == null) {
|
||||||
context.getSource().sendFeedback(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.teleportRequest.noPending,
|
RccServer.CONFIG.textFormats.commands.teleportRequest.noPending,
|
||||||
playerContext
|
playerContext
|
||||||
), false);
|
), false);
|
||||||
|
|
@ -47,7 +46,12 @@ public class TeleportDenyCommand {
|
||||||
})
|
})
|
||||||
.then(argument("uuid", UuidArgumentType.uuid())
|
.then(argument("uuid", UuidArgumentType.uuid())
|
||||||
.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();
|
||||||
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);
|
||||||
|
|
@ -55,7 +59,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(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.teleportRequest.unavailable,
|
RccServer.CONFIG.textFormats.commands.teleportRequest.unavailable,
|
||||||
playerContext
|
playerContext
|
||||||
), false);
|
), false);
|
||||||
|
|
@ -88,14 +92,14 @@ public class TeleportDenyCommand {
|
||||||
|
|
||||||
if (otherPlayer != null) {
|
if (otherPlayer != null) {
|
||||||
var otherContext = PlaceholderContext.of(otherPlayer);
|
var otherContext = PlaceholderContext.of(otherPlayer);
|
||||||
otherPlayer.sendMessage(Placeholder.parse(
|
otherPlayer.sendMessage(Components.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(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.teleportRequest.requestRefusedResult,
|
RccServer.CONFIG.textFormats.commands.teleportRequest.requestRefusedResult,
|
||||||
playerContext
|
playerContext
|
||||||
), false);
|
), false);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
@ -31,7 +30,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(() -> Placeholder.parse(
|
source.sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.tell.noLastSenderReply,
|
RccServer.CONFIG.textFormats.commands.tell.noLastSenderReply,
|
||||||
playerContext
|
playerContext
|
||||||
), false);
|
), false);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
@ -63,7 +62,7 @@ public class TellCommand {
|
||||||
);
|
);
|
||||||
var sourceContext = PlaceholderContext.of(source);
|
var sourceContext = PlaceholderContext.of(source);
|
||||||
|
|
||||||
source.sendFeedback(() -> Placeholder.parse(
|
source.sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.tell.playerNotFound,
|
RccServer.CONFIG.textFormats.commands.tell.playerNotFound,
|
||||||
sourceContext,
|
sourceContext,
|
||||||
placeholders
|
placeholders
|
||||||
|
|
@ -85,7 +84,7 @@ public class TellCommand {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var you = Placeholder.parse(RccServer.CONFIG.textFormats.commands.tell.you);
|
var you = Components.parse(RccServer.CONFIG.textFormats.commands.tell.you);
|
||||||
|
|
||||||
var placeholdersToSource = Map.of(
|
var placeholdersToSource = Map.of(
|
||||||
"sourcePlayer", you,
|
"sourcePlayer", you,
|
||||||
|
|
@ -105,22 +104,22 @@ public class TellCommand {
|
||||||
"message", parsedMessage
|
"message", parsedMessage
|
||||||
);
|
);
|
||||||
|
|
||||||
var sourceText = Placeholder.parse(
|
var sourceText = Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.tell.message,
|
RccServer.CONFIG.textFormats.commands.tell.message,
|
||||||
sourceContext,
|
sourceContext,
|
||||||
placeholdersToSource
|
placeholdersToSource
|
||||||
);
|
);
|
||||||
var targetText = Placeholder.parse(
|
var targetText = Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.tell.message,
|
RccServer.CONFIG.textFormats.commands.tell.message,
|
||||||
targetContext,
|
targetContext,
|
||||||
placeholdersToTarget
|
placeholdersToTarget
|
||||||
);
|
);
|
||||||
var genericText = Placeholder.parse(
|
var genericText = Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.tell.message,
|
RccServer.CONFIG.textFormats.commands.tell.message,
|
||||||
serverContext,
|
serverContext,
|
||||||
placeholders
|
placeholders
|
||||||
);
|
);
|
||||||
var spyText = Placeholder.parse(
|
var spyText = Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.tell.messageSpy,
|
RccServer.CONFIG.textFormats.commands.tell.messageSpy,
|
||||||
serverContext,
|
serverContext,
|
||||||
placeholders
|
placeholders
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,11 @@ 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;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,6 @@ 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;
|
||||||
|
|
@ -25,8 +24,12 @@ public class SetWarpCommand {
|
||||||
dispatcher.register(rootCommand);
|
dispatcher.register(rootCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int execute(CommandContext<ServerCommandSource> context, String name) throws CommandSyntaxException {
|
private static int execute(CommandContext<ServerCommandSource> context, String name) {
|
||||||
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();
|
||||||
var serverState = RccServer.state.getServerState();
|
var serverState = RccServer.state.getServerState();
|
||||||
|
|
||||||
var warps = serverState.warps;
|
var warps = serverState.warps;
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,10 @@
|
||||||
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;
|
||||||
|
|
@ -35,21 +33,25 @@ public class WarpCommand {
|
||||||
dispatcher.register(rootCommand);
|
dispatcher.register(rootCommand);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int execute(CommandContext<ServerCommandSource> context, String name) throws CommandSyntaxException {
|
private static int execute(CommandContext<ServerCommandSource> context, String name) {
|
||||||
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();
|
||||||
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(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.warp.warpNotFound,
|
RccServer.CONFIG.textFormats.commands.warp.warpNotFound,
|
||||||
playerContext
|
playerContext
|
||||||
), false);
|
), false);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
context.getSource().sendFeedback(() -> Placeholder.parse(
|
context.getSource().sendFeedback(() -> Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.warp.teleporting,
|
RccServer.CONFIG.textFormats.commands.warp.teleporting,
|
||||||
playerContext,
|
playerContext,
|
||||||
Map.of(
|
Map.of(
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,15 @@
|
||||||
package cc.reconnected.server;
|
package cc.reconnected.server.config;
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@Config(RccServer.MOD_ID)
|
public class Config {
|
||||||
public class RccServerConfig {
|
Config() {
|
||||||
|
}
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
@ -18,6 +19,11 @@ public class RccServerConfig {
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
@ -0,0 +1,46 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
@ -56,7 +55,7 @@ public class AfkTracker {
|
||||||
|
|
||||||
var playerContext = PlaceholderContext.of(player);
|
var playerContext = PlaceholderContext.of(player);
|
||||||
|
|
||||||
RccServer.getInstance().broadcast(Placeholder.parse(
|
RccServer.getInstance().broadcast(Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.afk.goneAfk,
|
RccServer.CONFIG.textFormats.commands.afk.goneAfk,
|
||||||
playerContext
|
playerContext
|
||||||
));
|
));
|
||||||
|
|
@ -67,7 +66,7 @@ public class AfkTracker {
|
||||||
|
|
||||||
var playerContext = PlaceholderContext.of(player);
|
var playerContext = PlaceholderContext.of(player);
|
||||||
|
|
||||||
RccServer.getInstance().broadcast(Placeholder.parse(
|
RccServer.getInstance().broadcast(Components.parse(
|
||||||
RccServer.CONFIG.textFormats.commands.afk.returnAfk,
|
RccServer.CONFIG.textFormats.commands.afk.returnAfk,
|
||||||
playerContext
|
playerContext
|
||||||
));
|
));
|
||||||
|
|
|
||||||
104
src/main/java/cc/reconnected/server/core/HttpApiServer.java
Normal file
104
src/main/java/cc/reconnected/server/core/HttpApiServer.java
Normal file
|
|
@ -0,0 +1,104 @@
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
@ -29,7 +28,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 = Placeholder.parse(
|
var text = Components.parse(
|
||||||
RccServer.CONFIG.textFormats.chatFormat,
|
RccServer.CONFIG.textFormats.chatFormat,
|
||||||
playerContext,
|
playerContext,
|
||||||
Map.of(
|
Map.of(
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
@ -12,7 +11,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 Placeholder.parse(
|
return Components.parse(
|
||||||
RccServer.CONFIG.textFormats.joinFormat,
|
RccServer.CONFIG.textFormats.joinFormat,
|
||||||
playerContext
|
playerContext
|
||||||
);
|
);
|
||||||
|
|
@ -20,7 +19,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 Placeholder.parse(
|
return Components.parse(
|
||||||
RccServer.CONFIG.textFormats.joinRenamedFormat,
|
RccServer.CONFIG.textFormats.joinRenamedFormat,
|
||||||
playerContext,
|
playerContext,
|
||||||
Map.of("previousName", Text.of(previousName))
|
Map.of("previousName", Text.of(previousName))
|
||||||
|
|
@ -29,7 +28,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 Placeholder.parse(
|
return Components.parse(
|
||||||
RccServer.CONFIG.textFormats.leaveFormat,
|
RccServer.CONFIG.textFormats.leaveFormat,
|
||||||
playerContext
|
playerContext
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
@ -15,7 +14,7 @@ public class CustomDeathMessage {
|
||||||
var deathMessage = instance.getDeathMessage();
|
var deathMessage = instance.getDeathMessage();
|
||||||
var playerContext = PlaceholderContext.of(player);
|
var playerContext = PlaceholderContext.of(player);
|
||||||
|
|
||||||
return Placeholder.parse(
|
return Components.parse(
|
||||||
RccServer.CONFIG.textFormats.deathFormat,
|
RccServer.CONFIG.textFormats.deathFormat,
|
||||||
playerContext,
|
playerContext,
|
||||||
Map.of("message", deathMessage)
|
Map.of("message", deathMessage)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
@ -20,7 +19,7 @@ public class CustomEmoteMessage {
|
||||||
|
|
||||||
Text messageText = Components.chat(message, player);
|
Text messageText = Components.chat(message, player);
|
||||||
|
|
||||||
var text = Placeholder.parse(
|
var text = Components.parse(
|
||||||
RccServer.CONFIG.textFormats.emoteFormat,
|
RccServer.CONFIG.textFormats.emoteFormat,
|
||||||
playerContext,
|
playerContext,
|
||||||
Map.of(
|
Map.of(
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,5 @@
|
||||||
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;
|
||||||
|
|
@ -11,11 +10,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));
|
||||||
|
|
|
||||||
|
|
@ -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 ServerPlayNetworkHandlerMixin {
|
public abstract class ServerPlayNetworkManagerMixin {
|
||||||
@Shadow
|
@Shadow
|
||||||
@Final
|
@Final
|
||||||
private MinecraftServer server;
|
private MinecraftServer server;
|
||||||
|
|
@ -1,17 +1,13 @@
|
||||||
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;
|
||||||
|
|
@ -20,8 +16,6 @@ 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
|
||||||
|
|
@ -42,10 +36,4 @@ 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));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
99
src/main/java/cc/reconnected/server/parser/LinkParser.java
Normal file
99
src/main/java/cc/reconnected/server/parser/LinkParser.java
Normal file
|
|
@ -0,0 +1,99 @@
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,52 @@
|
||||||
|
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)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,32 @@
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,12 +1,16 @@
|
||||||
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;
|
||||||
|
|
@ -61,6 +65,31 @@ 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();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@
|
||||||
"RegistryLoaderMixin",
|
"RegistryLoaderMixin",
|
||||||
"SentMessageMixin",
|
"SentMessageMixin",
|
||||||
"ServerPlayerEntityMixin",
|
"ServerPlayerEntityMixin",
|
||||||
"ServerPlayNetworkHandlerMixin",
|
"ServerPlayNetworkManagerMixin",
|
||||||
"PlayerManagerMixin"
|
"PlayerManagerMixin"
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue