diff --git a/build.gradle b/build.gradle
index c65129c..698f74f 100644
--- a/build.gradle
+++ b/build.gradle
@@ -19,6 +19,7 @@ repositories {
maven { url 'https://maven.wispforest.io' }
maven { url 'https://maven.nucleoid.xyz' }
+ maven { url 'https://maven.reconnected.cc/releases' }
}
loom {
@@ -46,6 +47,8 @@ dependencies {
compileOnly "net.luckperms:api:${project.luckpermsapi_version}"
include modImplementation("me.lucko:fabric-permissions-api:${project.permissions_api_version}")
+
+ include modImplementation("net.kyori:adventure-platform-fabric:${project.adventure_version}")
}
processResources {
diff --git a/gradle.properties b/gradle.properties
index 95e40f1..0369a44 100644
--- a/gradle.properties
+++ b/gradle.properties
@@ -19,4 +19,6 @@ fabric_version=0.92.2+1.20.1
owo_version=0.11.2+1.20
luckpermsapi_version=5.4
-permissions_api_version=0.2-SNAPSHOT
\ No newline at end of file
+permissions_api_version=0.2-SNAPSHOT
+
+adventure_version=5.9.1
\ No newline at end of file
diff --git a/src/main/java/cc/reconnected/server/RccServer.java b/src/main/java/cc/reconnected/server/RccServer.java
index e51c36e..5f0a1ad 100644
--- a/src/main/java/cc/reconnected/server/RccServer.java
+++ b/src/main/java/cc/reconnected/server/RccServer.java
@@ -14,6 +14,10 @@ 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 net.kyori.adventure.text.Component;
+import net.kyori.adventure.text.minimessage.MiniMessage;
+import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
+import net.kyori.adventure.text.serializer.json.JSONComponentSerializer;
import net.luckperms.api.LuckPerms;
import net.luckperms.api.LuckPermsProvider;
import net.minecraft.entity.player.PlayerEntity;
@@ -81,16 +85,18 @@ public class RccServer implements ModInitializer {
CommandRegistrationCallback.EVENT.register(RccCommand::register);
CommandRegistrationCallback.EVENT.register(AfkCommand::register);
- try {
- serviceServer = new ServiceServer();
- } catch (IOException e) {
- LOGGER.error("Unable to start HTTP server", e);
- }
-
ServerLifecycleEvents.SERVER_STARTED.register(server -> {
luckPerms = LuckPermsProvider.get();
afkTracker = new AfkTracker();
Ready.READY.invoker().ready(server, luckPerms);
+
+ if(CONFIG.enableHttpApi()) {
+ try {
+ serviceServer = new ServiceServer();
+ } catch (IOException e) {
+ LOGGER.error("Unable to start HTTP server", e);
+ }
+ }
});
ServerTickEvents.END_SERVER_TICK.register(server -> {
@@ -101,8 +107,10 @@ public class RccServer implements ModInitializer {
});
ServerLifecycleEvents.SERVER_STOPPING.register(server -> {
- LOGGER.info("Stopping HTTP services");
- serviceServer.httpServer().stop(0);
+ if(CONFIG.enableHttpApi()) {
+ LOGGER.info("Stopping HTTP services");
+ serviceServer.httpServer().stop(0);
+ }
});
ServerPlayConnectionEvents.JOIN.register((handler, sender, server) -> {
@@ -127,11 +135,31 @@ public class RccServer implements ModInitializer {
});
PlayerActivityEvents.AFK.register((player, server) -> {
- LOGGER.info("{} is AFK. Active time: {} seconds.", player, afkTracker.getActiveTime(player));
+ LOGGER.info("{} is AFK. Active time: {} seconds.", player.getGameProfile().getName(), afkTracker.getActiveTime(player));
+
+ var displayNameJson = Text.Serializer.toJson(player.getDisplayName());
+ var displayName = JSONComponentSerializer.json().deserialize(displayNameJson);
+
+ var message = MiniMessage.miniMessage().deserialize(CONFIG.afkMessage(),
+ Placeholder.component("name", displayName)
+ );
+
+ broadcastMessage(server, message);
});
PlayerActivityEvents.AFK_RETURN.register((player, server) -> {
- LOGGER.info("{} is no longer AFK. Active time: {} seconds.", player, afkTracker.getActiveTime(player));
+ LOGGER.info("{} is no longer AFK. Active time: {} seconds.", player.getGameProfile().getName(), afkTracker.getActiveTime(player));
+
+ var displayNameJson = Text.Serializer.toJson(player.getDisplayName());
+ var displayName = JSONComponentSerializer.json().deserialize(displayNameJson);
+
+ var message = MiniMessage.miniMessage().deserialize(CONFIG.afkReturnMessage(),
+ Placeholder.component("displayname", displayName),
+ Placeholder.unparsed("username", player.getGameProfile().getName()),
+ Placeholder.unparsed("uuid", player.getUuid().toString())
+ );
+
+ broadcastMessage(server, message);
});
}
@@ -141,6 +169,12 @@ public class RccServer implements ModInitializer {
}
}
+ public void broadcastMessage(MinecraftServer server, Component message) {
+ for(ServerPlayerEntity player : server.getPlayerManager().getPlayerList()) {
+ player.sendMessage(message);
+ }
+ }
+
public boolean isPlayerAfk(PlayerEntity player) {
return afkTracker.isPlayerAfk(player.getUuid());
}
diff --git a/src/main/java/cc/reconnected/server/RccServerConfigModel.java b/src/main/java/cc/reconnected/server/RccServerConfigModel.java
index 37743ca..e41f210 100644
--- a/src/main/java/cc/reconnected/server/RccServerConfigModel.java
+++ b/src/main/java/cc/reconnected/server/RccServerConfigModel.java
@@ -8,4 +8,7 @@ public class RccServerConfigModel {
public int httpPort = 25581;
public int afkTimeTrigger = 300;
+
+ public String afkMessage = " is now AFK";
+ public String afkReturnMessage = " is no longer AFK";
}