From 26ba8f4423f48bfc72874aa5cad108a2165b6ecd Mon Sep 17 00:00:00 2001 From: benrobson Date: Wed, 17 Apr 2024 15:12:19 +1000 Subject: [PATCH 01/17] Refactor zander-proxy to zander-waterfall and create zander-velocity. --- pom.xml | 3 ++- .../dependency-reduced-pom.xml | 0 {zander-proxy => zander-waterfall}/pom.xml | 2 +- .../zander/proxy/ConfigurationManager.java | 0 .../modularsoft/zander/proxy/ZanderProxyMain.java | 0 .../modularsoft/zander/proxy/commands/discord.java | 0 .../org/modularsoft/zander/proxy/commands/ping.java | 0 .../modularsoft/zander/proxy/commands/rules.java | 0 .../modularsoft/zander/proxy/commands/website.java | 0 .../zander/proxy/events/UserChatEvent.java | 0 .../zander/proxy/events/UserCommandSpyEvent.java | 0 .../zander/proxy/events/UserOnDisconnect.java | 0 .../zander/proxy/events/UserOnLogin.java | 0 .../zander/proxy/events/UserOnProxyPing.java | 0 .../zander/proxy/events/UserOnSwitch.java | 0 .../zander/proxy/events/UserSocialSpyEvent.java | 0 .../org/modularsoft/zander/proxy/model/Filter.java | 0 .../zander/proxy/model/discord/DiscordChat.java | 0 .../zander/proxy/model/discord/DiscordJoin.java | 0 .../zander/proxy/model/discord/DiscordLeave.java | 0 .../zander/proxy/model/discord/DiscordSwitch.java | 0 .../proxy/model/discord/spy/DiscordCommandSpy.java | 0 .../proxy/model/discord/spy/DiscordSocialSpy.java | 0 .../zander/proxy/model/session/SessionCreate.java | 0 .../zander/proxy/model/session/SessionDestroy.java | 0 .../zander/proxy/model/session/SessionSwitch.java | 0 .../zander/proxy/model/user/UserCreation.java | 0 .../zander/proxy/util/announcement/TipChatter.java | 0 .../zander/proxy/util/api/Heartbeat.java | 0 .../src/main/resources/config.yml | 0 .../src/main/resources/nuvotifier.jar | Bin .../src/main/resources/plugin.yml | 0 32 files changed, 3 insertions(+), 2 deletions(-) rename {zander-proxy => zander-waterfall}/dependency-reduced-pom.xml (100%) rename {zander-proxy => zander-waterfall}/pom.xml (98%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/ConfigurationManager.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/ZanderProxyMain.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/commands/discord.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/commands/ping.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/commands/rules.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/commands/website.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/events/UserChatEvent.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/events/UserCommandSpyEvent.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/events/UserOnDisconnect.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/events/UserOnLogin.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/events/UserOnProxyPing.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/events/UserOnSwitch.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/events/UserSocialSpyEvent.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/model/Filter.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordChat.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordJoin.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordLeave.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordSwitch.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/model/discord/spy/DiscordCommandSpy.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/model/discord/spy/DiscordSocialSpy.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/model/session/SessionCreate.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/model/session/SessionDestroy.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/model/session/SessionSwitch.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/model/user/UserCreation.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/util/announcement/TipChatter.java (100%) rename {zander-proxy => zander-waterfall}/src/main/java/org/modularsoft/zander/proxy/util/api/Heartbeat.java (100%) rename {zander-proxy => zander-waterfall}/src/main/resources/config.yml (100%) rename {zander-proxy => zander-waterfall}/src/main/resources/nuvotifier.jar (100%) rename {zander-proxy => zander-waterfall}/src/main/resources/plugin.yml (100%) diff --git a/pom.xml b/pom.xml index bd49829..75cca0e 100644 --- a/pom.xml +++ b/pom.xml @@ -10,8 +10,9 @@ pom - zander-proxy + zander-waterfall zander-hub + zander-velocity diff --git a/zander-proxy/dependency-reduced-pom.xml b/zander-waterfall/dependency-reduced-pom.xml similarity index 100% rename from zander-proxy/dependency-reduced-pom.xml rename to zander-waterfall/dependency-reduced-pom.xml diff --git a/zander-proxy/pom.xml b/zander-waterfall/pom.xml similarity index 98% rename from zander-proxy/pom.xml rename to zander-waterfall/pom.xml index 604471b..59a9120 100644 --- a/zander-proxy/pom.xml +++ b/zander-waterfall/pom.xml @@ -9,7 +9,7 @@ 4.0.0 - zander-proxy + zander-waterfall 1.0 diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/ConfigurationManager.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/ConfigurationManager.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/ConfigurationManager.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/ConfigurationManager.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/ZanderProxyMain.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/ZanderProxyMain.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/ZanderProxyMain.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/ZanderProxyMain.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/commands/discord.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/discord.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/commands/discord.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/discord.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/commands/ping.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/ping.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/commands/ping.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/ping.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/commands/rules.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/rules.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/commands/rules.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/rules.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/commands/website.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/website.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/commands/website.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/website.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/events/UserChatEvent.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserChatEvent.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/events/UserChatEvent.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserChatEvent.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/events/UserCommandSpyEvent.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserCommandSpyEvent.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/events/UserCommandSpyEvent.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserCommandSpyEvent.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/events/UserOnDisconnect.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnDisconnect.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/events/UserOnDisconnect.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnDisconnect.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/events/UserOnLogin.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnLogin.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/events/UserOnLogin.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnLogin.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/events/UserOnProxyPing.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnProxyPing.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/events/UserOnProxyPing.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnProxyPing.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/events/UserOnSwitch.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnSwitch.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/events/UserOnSwitch.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnSwitch.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/events/UserSocialSpyEvent.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserSocialSpyEvent.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/events/UserSocialSpyEvent.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserSocialSpyEvent.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/Filter.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/Filter.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/Filter.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/Filter.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordChat.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordChat.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordChat.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordChat.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordJoin.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordJoin.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordJoin.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordJoin.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordLeave.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordLeave.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordLeave.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordLeave.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordSwitch.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordSwitch.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordSwitch.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordSwitch.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/discord/spy/DiscordCommandSpy.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/spy/DiscordCommandSpy.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/discord/spy/DiscordCommandSpy.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/spy/DiscordCommandSpy.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/discord/spy/DiscordSocialSpy.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/spy/DiscordSocialSpy.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/discord/spy/DiscordSocialSpy.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/spy/DiscordSocialSpy.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/session/SessionCreate.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/session/SessionCreate.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/session/SessionCreate.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/session/SessionCreate.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/session/SessionDestroy.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/session/SessionDestroy.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/session/SessionDestroy.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/session/SessionDestroy.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/session/SessionSwitch.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/session/SessionSwitch.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/session/SessionSwitch.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/session/SessionSwitch.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/user/UserCreation.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/user/UserCreation.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/model/user/UserCreation.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/user/UserCreation.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/util/announcement/TipChatter.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/util/announcement/TipChatter.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/util/announcement/TipChatter.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/util/announcement/TipChatter.java diff --git a/zander-proxy/src/main/java/org/modularsoft/zander/proxy/util/api/Heartbeat.java b/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/util/api/Heartbeat.java similarity index 100% rename from zander-proxy/src/main/java/org/modularsoft/zander/proxy/util/api/Heartbeat.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/proxy/util/api/Heartbeat.java diff --git a/zander-proxy/src/main/resources/config.yml b/zander-waterfall/src/main/resources/config.yml similarity index 100% rename from zander-proxy/src/main/resources/config.yml rename to zander-waterfall/src/main/resources/config.yml diff --git a/zander-proxy/src/main/resources/nuvotifier.jar b/zander-waterfall/src/main/resources/nuvotifier.jar similarity index 100% rename from zander-proxy/src/main/resources/nuvotifier.jar rename to zander-waterfall/src/main/resources/nuvotifier.jar diff --git a/zander-proxy/src/main/resources/plugin.yml b/zander-waterfall/src/main/resources/plugin.yml similarity index 100% rename from zander-proxy/src/main/resources/plugin.yml rename to zander-waterfall/src/main/resources/plugin.yml From e0a38bdfcdc04d267cc2db5d3349aa63346ae26e Mon Sep 17 00:00:00 2001 From: benrobson Date: Wed, 17 Apr 2024 15:44:36 +1000 Subject: [PATCH 02/17] Start work on main velocity class. --- zander-velocity/pom.xml | 108 ++++++++++++++++++ .../zandervelocity/ZanderVelocityMain.java | 35 ++++++ zander-waterfall/dependency-reduced-pom.xml | 2 +- 3 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 zander-velocity/pom.xml create mode 100644 zander-velocity/src/main/java/org/modularsoft/zandervelocity/ZanderVelocityMain.java diff --git a/zander-velocity/pom.xml b/zander-velocity/pom.xml new file mode 100644 index 0000000..32ac15b --- /dev/null +++ b/zander-velocity/pom.xml @@ -0,0 +1,108 @@ + + + 4.0.0 + + org.modularsoft + zander-velocity + 1.0-SNAPSHOT + jar + + zander-velocity + + + 17 + 11 + 11 + UTF-8 + + + + + + ${project.basedir}/src/main/resources + true + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + + + + + + org.apache.maven.plugins + maven-javadoc-plugin + 3.4.0 + + + + + + + papermc-repo + https://repo.papermc.io/repository/maven-public/ + + + maven2 + https://repo.maven.apache.org/maven2 + + + jitpack.io + https://jitpack.io + + + + + + com.velocitypowered + velocity-api + 3.3.0-SNAPSHOT + provided + + + com.googlecode.json-simple + json-simple + 1.1.1 + compile + + + org.projectlombok + lombok + 1.18.22 + compile + + + io.github.ModularEnigma + Requests + 1.0.3 + + + com.jayway.jsonpath + json-path + 2.8.0 + + + com.google.code.gson + gson + 2.8.9 + compile + + + org.slf4j + slf4j-api + 2.0.12 + compile + + + diff --git a/zander-velocity/src/main/java/org/modularsoft/zandervelocity/ZanderVelocityMain.java b/zander-velocity/src/main/java/org/modularsoft/zandervelocity/ZanderVelocityMain.java new file mode 100644 index 0000000..10fb5bb --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zandervelocity/ZanderVelocityMain.java @@ -0,0 +1,35 @@ +package org.modularsoft.zandervelocity; + +import com.google.inject.Inject; +import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.plugin.Plugin; +import com.velocitypowered.api.proxy.ProxyServer; +import lombok.Getter; +import org.slf4j.Logger; + +@Plugin( + id = "zander-velocity", + name = "zander-velocity", + version = "1.0-SNAPSHOT" +) +public class ZanderVelocityMain { + @Getter + private final Logger logger; + @Getter + private final ProxyServer proxy; + + @Subscribe + public void onProxyInitialization(ProxyInitializeEvent event) { + + } + + @Inject + public ZanderVelocityMain(ProxyServer proxy, Logger logger) { + this.proxy = proxy; + this.logger = logger; + + logger.info("Zander Proxy has started."); + } + +} diff --git a/zander-waterfall/dependency-reduced-pom.xml b/zander-waterfall/dependency-reduced-pom.xml index 3d049fe..68a3538 100644 --- a/zander-waterfall/dependency-reduced-pom.xml +++ b/zander-waterfall/dependency-reduced-pom.xml @@ -6,7 +6,7 @@ 1.0 4.0.0 - zander-proxy + zander-waterfall 1.0 From d2b03c18bbd2866423cbe3c426afc7bf06368da3 Mon Sep 17 00:00:00 2001 From: benrobson Date: Wed, 17 Apr 2024 20:42:39 +1000 Subject: [PATCH 03/17] Separate proxy into velocity and waterfall, start velocity config and events. --- zander-velocity/dependency-reduced-pom.xml | 90 +++++++++++++++++++ zander-velocity/pom.xml | 36 +++++++- .../zander/velocity/ZanderVelocityMain.java | 83 +++++++++++++++++ .../zander/velocity/events/UserChatEvent.java | 76 ++++++++++++++++ .../zander/velocity}/model/Filter.java | 2 +- .../velocity}/model/discord/DiscordChat.java | 2 +- .../velocity}/model/discord/DiscordJoin.java | 2 +- .../velocity}/model/discord/DiscordLeave.java | 2 +- .../model/discord/DiscordSwitch.java | 2 +- .../model/discord/spy/DiscordCommandSpy.java | 2 +- .../model/discord/spy/DiscordSocialSpy.java | 2 +- .../model/session/SessionCreate.java | 2 +- .../model/session/SessionDestroy.java | 2 +- .../model/session/SessionSwitch.java | 2 +- .../velocity}/model/user/UserCreation.java | 2 +- .../zandervelocity/ZanderVelocityMain.java | 35 -------- zander-velocity/src/main/resources/config.yml | 8 ++ .../ConfigurationManager.java | 2 +- .../{proxy => waterfall}/ZanderProxyMain.java | 10 +-- .../commands/discord.java | 6 +- .../{proxy => waterfall}/commands/ping.java | 2 +- .../{proxy => waterfall}/commands/rules.java | 6 +- .../commands/website.java | 6 +- .../events/UserChatEvent.java | 10 +-- .../events/UserCommandSpyEvent.java | 8 +- .../events/UserOnDisconnect.java | 10 +-- .../events/UserOnLogin.java | 12 +-- .../events/UserOnProxyPing.java | 6 +- .../events/UserOnSwitch.java | 10 +-- .../events/UserSocialSpyEvent.java | 9 +- .../zander/waterfall/model/Filter.java | 17 ++++ .../waterfall/model/discord/DiscordChat.java | 19 ++++ .../waterfall/model/discord/DiscordJoin.java | 17 ++++ .../waterfall/model/discord/DiscordLeave.java | 17 ++++ .../model/discord/DiscordSwitch.java | 18 ++++ .../model/discord/spy/DiscordCommandSpy.java | 19 ++++ .../model/discord/spy/DiscordSocialSpy.java | 20 +++++ .../model/session/SessionCreate.java | 20 +++++ .../model/session/SessionDestroy.java | 19 ++++ .../model/session/SessionSwitch.java | 20 +++++ .../waterfall/model/user/UserCreation.java | 20 +++++ .../util/announcement/TipChatter.java | 4 +- .../util/api/Heartbeat.java | 4 +- 43 files changed, 561 insertions(+), 100 deletions(-) create mode 100644 zander-velocity/dependency-reduced-pom.xml create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserChatEvent.java rename {zander-waterfall/src/main/java/org/modularsoft/zander/proxy => zander-velocity/src/main/java/org/modularsoft/zander/velocity}/model/Filter.java (83%) rename {zander-waterfall/src/main/java/org/modularsoft/zander/proxy => zander-velocity/src/main/java/org/modularsoft/zander/velocity}/model/discord/DiscordChat.java (84%) rename {zander-waterfall/src/main/java/org/modularsoft/zander/proxy => zander-velocity/src/main/java/org/modularsoft/zander/velocity}/model/discord/DiscordJoin.java (81%) rename {zander-waterfall/src/main/java/org/modularsoft/zander/proxy => zander-velocity/src/main/java/org/modularsoft/zander/velocity}/model/discord/DiscordLeave.java (81%) rename {zander-waterfall/src/main/java/org/modularsoft/zander/proxy => zander-velocity/src/main/java/org/modularsoft/zander/velocity}/model/discord/DiscordSwitch.java (82%) rename {zander-waterfall/src/main/java/org/modularsoft/zander/proxy => zander-velocity/src/main/java/org/modularsoft/zander/velocity}/model/discord/spy/DiscordCommandSpy.java (83%) rename {zander-waterfall/src/main/java/org/modularsoft/zander/proxy => zander-velocity/src/main/java/org/modularsoft/zander/velocity}/model/discord/spy/DiscordSocialSpy.java (85%) rename {zander-waterfall/src/main/java/org/modularsoft/zander/proxy => zander-velocity/src/main/java/org/modularsoft/zander/velocity}/model/session/SessionCreate.java (83%) rename {zander-waterfall/src/main/java/org/modularsoft/zander/proxy => zander-velocity/src/main/java/org/modularsoft/zander/velocity}/model/session/SessionDestroy.java (82%) rename {zander-waterfall/src/main/java/org/modularsoft/zander/proxy => zander-velocity/src/main/java/org/modularsoft/zander/velocity}/model/session/SessionSwitch.java (83%) rename {zander-waterfall/src/main/java/org/modularsoft/zander/proxy => zander-velocity/src/main/java/org/modularsoft/zander/velocity}/model/user/UserCreation.java (84%) delete mode 100644 zander-velocity/src/main/java/org/modularsoft/zandervelocity/ZanderVelocityMain.java create mode 100644 zander-velocity/src/main/resources/config.yml rename zander-waterfall/src/main/java/org/modularsoft/zander/{proxy => waterfall}/ConfigurationManager.java (97%) rename zander-waterfall/src/main/java/org/modularsoft/zander/{proxy => waterfall}/ZanderProxyMain.java (88%) rename zander-waterfall/src/main/java/org/modularsoft/zander/{proxy => waterfall}/commands/discord.java (91%) rename zander-waterfall/src/main/java/org/modularsoft/zander/{proxy => waterfall}/commands/ping.java (93%) rename zander-waterfall/src/main/java/org/modularsoft/zander/{proxy => waterfall}/commands/rules.java (91%) rename zander-waterfall/src/main/java/org/modularsoft/zander/{proxy => waterfall}/commands/website.java (91%) rename zander-waterfall/src/main/java/org/modularsoft/zander/{proxy => waterfall}/events/UserChatEvent.java (91%) rename zander-waterfall/src/main/java/org/modularsoft/zander/{proxy => waterfall}/events/UserCommandSpyEvent.java (90%) rename zander-waterfall/src/main/java/org/modularsoft/zander/{proxy => waterfall}/events/UserOnDisconnect.java (89%) rename zander-waterfall/src/main/java/org/modularsoft/zander/{proxy => waterfall}/events/UserOnLogin.java (91%) rename zander-waterfall/src/main/java/org/modularsoft/zander/{proxy => waterfall}/events/UserOnProxyPing.java (92%) rename zander-waterfall/src/main/java/org/modularsoft/zander/{proxy => waterfall}/events/UserOnSwitch.java (90%) rename zander-waterfall/src/main/java/org/modularsoft/zander/{proxy => waterfall}/events/UserSocialSpyEvent.java (88%) create mode 100644 zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/Filter.java create mode 100644 zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/DiscordChat.java create mode 100644 zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/DiscordJoin.java create mode 100644 zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/DiscordLeave.java create mode 100644 zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/DiscordSwitch.java create mode 100644 zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/spy/DiscordCommandSpy.java create mode 100644 zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/spy/DiscordSocialSpy.java create mode 100644 zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/session/SessionCreate.java create mode 100644 zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/session/SessionDestroy.java create mode 100644 zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/session/SessionSwitch.java create mode 100644 zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/user/UserCreation.java rename zander-waterfall/src/main/java/org/modularsoft/zander/{proxy => waterfall}/util/announcement/TipChatter.java (95%) rename zander-waterfall/src/main/java/org/modularsoft/zander/{proxy => waterfall}/util/api/Heartbeat.java (95%) diff --git a/zander-velocity/dependency-reduced-pom.xml b/zander-velocity/dependency-reduced-pom.xml new file mode 100644 index 0000000..1325afd --- /dev/null +++ b/zander-velocity/dependency-reduced-pom.xml @@ -0,0 +1,90 @@ + + + 4.0.0 + org.modularsoft + zander-velocity + zander-velocity + 1.2.0 + + + + true + ${project.basedir}/src/main/resources + + + + + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + maven-shade-plugin + 3.4.1 + + + package + + shade + + + + + + + *:* + + META-INF/*.MF + + + + + + dev.dejvokep.boostedyaml + org.modularsoft.zander.velocity.libs + + + + + + + + + papermc-repo + https://repo.papermc.io/repository/maven-public/ + + + maven2 + https://repo.maven.apache.org/maven2 + + + jitpack.io + https://jitpack.io + + + + + com.velocitypowered + velocity-api + 3.3.0-SNAPSHOT + provided + + + + + + maven-javadoc-plugin + 3.4.0 + + + + + 11 + 17 + 11 + UTF-8 + + diff --git a/zander-velocity/pom.xml b/zander-velocity/pom.xml index 32ac15b..5fadab8 100644 --- a/zander-velocity/pom.xml +++ b/zander-velocity/pom.xml @@ -6,7 +6,7 @@ org.modularsoft zander-velocity - 1.0-SNAPSHOT + 1.2.0 jar zander-velocity @@ -35,6 +35,35 @@ ${java.version} + + org.apache.maven.plugins + maven-shade-plugin + 3.4.1 + + + + *:* + + META-INF/*.MF + + + + + + dev.dejvokep.boostedyaml + org.modularsoft.zander.velocity.libs + + + + + + package + + shade + + + + @@ -104,5 +133,10 @@ 2.0.12 compile + + dev.dejvokep + boosted-yaml + 1.3.1 + diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java new file mode 100644 index 0000000..9981f36 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java @@ -0,0 +1,83 @@ +package org.modularsoft.zander.velocity; + +import com.google.inject.Inject; +import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.plugin.Dependency; +import com.velocitypowered.api.plugin.Plugin; +import com.velocitypowered.api.plugin.PluginContainer; +import com.velocitypowered.api.plugin.annotation.DataDirectory; +import com.velocitypowered.api.proxy.ProxyServer; +import dev.dejvokep.boostedyaml.YamlDocument; +import dev.dejvokep.boostedyaml.dvs.versioning.BasicVersioning; +import dev.dejvokep.boostedyaml.settings.dumper.DumperSettings; +import dev.dejvokep.boostedyaml.settings.general.GeneralSettings; +import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings; +import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings; +import lombok.Getter; +import org.modularsoft.zander.velocity.events.UserChatEvent; +import org.slf4j.Logger; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Path; +import java.util.Objects; +import java.util.Optional; + +@Plugin( + id = "zander-velocity", + authors = "ModularSoft", + description = "The proxy that allows the connection and integration of the Zander minecraft suite.", + name = "zander-velocity", + version = "1.2.0", + dependencies = { + @Dependency(id = "signedvelocity") + } +) +public class ZanderVelocityMain { + @Getter + private static Logger logger; + @Getter + private final ProxyServer proxy; + @Getter + private static YamlDocument config; + + @Subscribe + public void onProxyInitialization(ProxyInitializeEvent event) { + // Event Listeners + proxy.getEventManager().register(this, new UserChatEvent()); + + // Commands + + } + + @Inject + public ZanderVelocityMain( + ProxyServer proxy, + Logger logger, + @DataDirectory Path dataDirectory + ) { + this.proxy = proxy; + this.logger = logger; + + // Create configuration file + try { + config = YamlDocument.create(new File(dataDirectory.toFile(), "config.yml"), + Objects.requireNonNull(getClass().getResourceAsStream("/config.yml")), + GeneralSettings.DEFAULT, + LoaderSettings.builder().setAutoUpdate(true).build(), + DumperSettings.DEFAULT, + UpdaterSettings.builder().setVersioning(new BasicVersioning("config-version")) + .setOptionSorting(UpdaterSettings.OptionSorting.SORT_BY_DEFAULTS).build()); + + config.update(); + config.save(); + } catch (IOException e) { + logger.error("Could not create or load plugin configuration, plugin will now be disabled."); + Optional container = proxy.getPluginManager().getPlugin("zander-velocity"); + container.ifPresent(pluginContainer -> pluginContainer.getExecutorService().shutdown()); + } + + logger.info("Zander Proxy has started."); + } +} diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserChatEvent.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserChatEvent.java new file mode 100644 index 0000000..9174a05 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserChatEvent.java @@ -0,0 +1,76 @@ +package org.modularsoft.zander.velocity.events; + +import com.jayway.jsonpath.JsonPath; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.player.PlayerChatEvent; +import com.velocitypowered.api.proxy.Player; +import dev.dejvokep.boostedyaml.route.Route; +import io.github.ModularEnigma.Request; +import io.github.ModularEnigma.Response; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.modularsoft.zander.velocity.ZanderVelocityMain; +import org.modularsoft.zander.velocity.model.Filter; +import org.modularsoft.zander.velocity.model.discord.DiscordChat; + +public class UserChatEvent { + + @Subscribe + public void UserChatEvent(PlayerChatEvent event) { + Player player = event.getPlayer(); + + String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); + String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + + // Filter out commands. + if (event.getMessage().startsWith("/")) return; + + // Check chat for blocked content + try { + Filter phrase = Filter.builder() + .content(event.getMessage().toString()) + .build(); + + Request phraseReq = Request.builder() + .setURL(BaseAPIURL + "/filter") + .setMethod(Request.Method.POST) + .addHeader("x-access-token", APIKey) + .setRequestBody(phrase.toString()) + .build(); + + Response phraseRes = phraseReq.execute(); + String phraseJson = phraseRes.getBody(); + + Boolean success = JsonPath.parse(phraseJson).read("$.success"); + String phraseCaughtMessage = JsonPath.read(phraseJson, "$.message"); + + ZanderVelocityMain.getLogger().info("[FILTER] Response (" + phraseRes.getStatusCode() + "): " + phraseRes.getBody()); + + if (!success) { + Component builder = Component.text(phraseCaughtMessage).color(NamedTextColor.RED); + player.sendMessage(builder); + event.setResult(PlayerChatEvent.ChatResult.denied()); + } else { + DiscordChat chat = DiscordChat.builder() + .username(player.getUsername()) + .server(player.getCurrentServer().get().getServer().getServerInfo().getName()) + .content(event.getMessage().toString()) + .build(); + + Request discordChatReq = Request.builder() + .setURL(BaseAPIURL + "/discord/chat") + .setMethod(Request.Method.POST) + .addHeader("x-access-token", String.valueOf(APIKey)) + .setRequestBody(chat.toString()) + .build(); + + Response discordChatReqRes = discordChatReq.execute(); + ZanderVelocityMain.getLogger().info("Response (" + discordChatReqRes.getStatusCode() + "): " + discordChatReqRes.getBody()); + } + } catch (Exception e) { + Component builder = Component.text("The chat filter could not be reached at this time, there maybe an issue with the API.").color(NamedTextColor.YELLOW); + player.sendMessage(builder); + System.out.println(e); + } + } +} diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/Filter.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/Filter.java similarity index 83% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/Filter.java rename to zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/Filter.java index 32eab6a..f52433c 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/Filter.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/Filter.java @@ -1,4 +1,4 @@ -package org.modularsoft.zander.proxy.model; +package org.modularsoft.zander.velocity.model; import com.google.gson.Gson; import lombok.Builder; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordChat.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/DiscordChat.java similarity index 84% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordChat.java rename to zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/DiscordChat.java index fd8fadc..30e1dd5 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordChat.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/DiscordChat.java @@ -1,4 +1,4 @@ -package org.modularsoft.zander.proxy.model.discord; +package org.modularsoft.zander.velocity.model.discord; import com.google.gson.Gson; import lombok.Builder; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordJoin.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/DiscordJoin.java similarity index 81% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordJoin.java rename to zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/DiscordJoin.java index 056b2c5..6424d10 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordJoin.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/DiscordJoin.java @@ -1,4 +1,4 @@ -package org.modularsoft.zander.proxy.model.discord; +package org.modularsoft.zander.velocity.model.discord; import com.google.gson.Gson; import lombok.Builder; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordLeave.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/DiscordLeave.java similarity index 81% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordLeave.java rename to zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/DiscordLeave.java index 4519355..50f4a28 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordLeave.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/DiscordLeave.java @@ -1,4 +1,4 @@ -package org.modularsoft.zander.proxy.model.discord; +package org.modularsoft.zander.velocity.model.discord; import com.google.gson.Gson; import lombok.Builder; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordSwitch.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/DiscordSwitch.java similarity index 82% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordSwitch.java rename to zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/DiscordSwitch.java index 9806a32..0fae2be 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/DiscordSwitch.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/DiscordSwitch.java @@ -1,4 +1,4 @@ -package org.modularsoft.zander.proxy.model.discord; +package org.modularsoft.zander.velocity.model.discord; import com.google.gson.Gson; import lombok.Builder; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/spy/DiscordCommandSpy.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/spy/DiscordCommandSpy.java similarity index 83% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/spy/DiscordCommandSpy.java rename to zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/spy/DiscordCommandSpy.java index 906a810..12e572a 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/spy/DiscordCommandSpy.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/spy/DiscordCommandSpy.java @@ -1,4 +1,4 @@ -package org.modularsoft.zander.proxy.model.discord.spy; +package org.modularsoft.zander.velocity.model.discord.spy; import com.google.gson.Gson; import lombok.Builder; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/spy/DiscordSocialSpy.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/spy/DiscordSocialSpy.java similarity index 85% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/spy/DiscordSocialSpy.java rename to zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/spy/DiscordSocialSpy.java index 720e948..f0cd649 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/discord/spy/DiscordSocialSpy.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/discord/spy/DiscordSocialSpy.java @@ -1,4 +1,4 @@ -package org.modularsoft.zander.proxy.model.discord.spy; +package org.modularsoft.zander.velocity.model.discord.spy; import com.google.gson.Gson; import lombok.Builder; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/session/SessionCreate.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/session/SessionCreate.java similarity index 83% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/session/SessionCreate.java rename to zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/session/SessionCreate.java index d66a636..bec29b7 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/session/SessionCreate.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/session/SessionCreate.java @@ -1,4 +1,4 @@ -package org.modularsoft.zander.proxy.model.session; +package org.modularsoft.zander.velocity.model.session; import com.google.gson.Gson; import lombok.Builder; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/session/SessionDestroy.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/session/SessionDestroy.java similarity index 82% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/session/SessionDestroy.java rename to zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/session/SessionDestroy.java index a90f0bf..15a9161 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/session/SessionDestroy.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/session/SessionDestroy.java @@ -1,4 +1,4 @@ -package org.modularsoft.zander.proxy.model.session; +package org.modularsoft.zander.velocity.model.session; import com.google.gson.Gson; import lombok.Builder; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/session/SessionSwitch.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/session/SessionSwitch.java similarity index 83% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/session/SessionSwitch.java rename to zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/session/SessionSwitch.java index 45e5cc1..60ccba1 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/session/SessionSwitch.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/session/SessionSwitch.java @@ -1,4 +1,4 @@ -package org.modularsoft.zander.proxy.model.session; +package org.modularsoft.zander.velocity.model.session; import com.google.gson.Gson; import lombok.Builder; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/user/UserCreation.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/user/UserCreation.java similarity index 84% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/user/UserCreation.java rename to zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/user/UserCreation.java index 2d85e33..ea9fdcf 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/model/user/UserCreation.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/user/UserCreation.java @@ -1,4 +1,4 @@ -package org.modularsoft.zander.proxy.model.user; +package org.modularsoft.zander.velocity.model.user; import com.google.gson.Gson; import lombok.Builder; diff --git a/zander-velocity/src/main/java/org/modularsoft/zandervelocity/ZanderVelocityMain.java b/zander-velocity/src/main/java/org/modularsoft/zandervelocity/ZanderVelocityMain.java deleted file mode 100644 index 10fb5bb..0000000 --- a/zander-velocity/src/main/java/org/modularsoft/zandervelocity/ZanderVelocityMain.java +++ /dev/null @@ -1,35 +0,0 @@ -package org.modularsoft.zandervelocity; - -import com.google.inject.Inject; -import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; -import com.velocitypowered.api.event.Subscribe; -import com.velocitypowered.api.plugin.Plugin; -import com.velocitypowered.api.proxy.ProxyServer; -import lombok.Getter; -import org.slf4j.Logger; - -@Plugin( - id = "zander-velocity", - name = "zander-velocity", - version = "1.0-SNAPSHOT" -) -public class ZanderVelocityMain { - @Getter - private final Logger logger; - @Getter - private final ProxyServer proxy; - - @Subscribe - public void onProxyInitialization(ProxyInitializeEvent event) { - - } - - @Inject - public ZanderVelocityMain(ProxyServer proxy, Logger logger) { - this.proxy = proxy; - this.logger = logger; - - logger.info("Zander Proxy has started."); - } - -} diff --git a/zander-velocity/src/main/resources/config.yml b/zander-velocity/src/main/resources/config.yml new file mode 100644 index 0000000..d993184 --- /dev/null +++ b/zander-velocity/src/main/resources/config.yml @@ -0,0 +1,8 @@ +config-version: 1 + +BaseAPIURL: "http://localhost:8080/api" +APIKey: "KEY" + +announcementMOTDTopLine: "&e&lMy &2&nMinecraft&r &6&oServer" +announcementTipPrefix: "&7&l[&6&lTIP&7&l]&r " +announcementTipInterval: 10 \ No newline at end of file diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/ConfigurationManager.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/ConfigurationManager.java similarity index 97% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/ConfigurationManager.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/ConfigurationManager.java index 9198705..9db4c44 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/ConfigurationManager.java +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/ConfigurationManager.java @@ -1,4 +1,4 @@ -package org.modularsoft.zander.proxy; +package org.modularsoft.zander.waterfall; import com.google.common.io.ByteStreams; import net.md_5.bungee.config.Configuration; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/ZanderProxyMain.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/ZanderProxyMain.java similarity index 88% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/ZanderProxyMain.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/ZanderProxyMain.java index c5b59db..1344fcb 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/ZanderProxyMain.java +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/ZanderProxyMain.java @@ -1,13 +1,13 @@ -package org.modularsoft.zander.proxy; +package org.modularsoft.zander.waterfall; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.api.plugin.Plugin; -import org.modularsoft.zander.proxy.commands.*; -import org.modularsoft.zander.proxy.events.*; -import org.modularsoft.zander.proxy.util.announcement.TipChatter; -import org.modularsoft.zander.proxy.util.api.Heartbeat; +import org.modularsoft.zander.waterfall.commands.*; +import org.modularsoft.zander.waterfall.events.*; +import org.modularsoft.zander.waterfall.util.announcement.TipChatter; +import org.modularsoft.zander.waterfall.util.api.Heartbeat; public class ZanderProxyMain extends Plugin implements Listener { private static ZanderProxyMain plugin; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/discord.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/commands/discord.java similarity index 91% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/discord.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/commands/discord.java index abc160f..75ed3ac 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/discord.java +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/commands/discord.java @@ -1,8 +1,8 @@ -package org.modularsoft.zander.proxy.commands; +package org.modularsoft.zander.waterfall.commands; import com.jayway.jsonpath.JsonPath; -import org.modularsoft.zander.proxy.ConfigurationManager; -import org.modularsoft.zander.proxy.ZanderProxyMain; +import org.modularsoft.zander.waterfall.ConfigurationManager; +import org.modularsoft.zander.waterfall.ZanderProxyMain; import io.github.ModularEnigma.Request; import io.github.ModularEnigma.Response; import net.md_5.bungee.api.ChatColor; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/ping.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/commands/ping.java similarity index 93% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/ping.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/commands/ping.java index 2b1432c..a9281f1 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/ping.java +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/commands/ping.java @@ -1,4 +1,4 @@ -package org.modularsoft.zander.proxy.commands; +package org.modularsoft.zander.waterfall.commands; import net.md_5.bungee.api.ChatColor; import net.md_5.bungee.api.CommandSender; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/rules.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/commands/rules.java similarity index 91% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/rules.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/commands/rules.java index ce79751..6eda87f 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/rules.java +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/commands/rules.java @@ -1,8 +1,8 @@ -package org.modularsoft.zander.proxy.commands; +package org.modularsoft.zander.waterfall.commands; import com.jayway.jsonpath.JsonPath; -import org.modularsoft.zander.proxy.ConfigurationManager; -import org.modularsoft.zander.proxy.ZanderProxyMain; +import org.modularsoft.zander.waterfall.ConfigurationManager; +import org.modularsoft.zander.waterfall.ZanderProxyMain; import io.github.ModularEnigma.Request; import io.github.ModularEnigma.Response; import net.md_5.bungee.api.ChatColor; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/website.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/commands/website.java similarity index 91% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/website.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/commands/website.java index 9e2aa32..4096f7d 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/commands/website.java +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/commands/website.java @@ -1,8 +1,8 @@ -package org.modularsoft.zander.proxy.commands; +package org.modularsoft.zander.waterfall.commands; import com.jayway.jsonpath.JsonPath; -import org.modularsoft.zander.proxy.ConfigurationManager; -import org.modularsoft.zander.proxy.ZanderProxyMain; +import org.modularsoft.zander.waterfall.ConfigurationManager; +import org.modularsoft.zander.waterfall.ZanderProxyMain; import io.github.ModularEnigma.Request; import io.github.ModularEnigma.Response; import net.md_5.bungee.api.ChatColor; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserChatEvent.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserChatEvent.java similarity index 91% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserChatEvent.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserChatEvent.java index e2e4580..804d9bb 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserChatEvent.java +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserChatEvent.java @@ -1,9 +1,9 @@ -package org.modularsoft.zander.proxy.events; +package org.modularsoft.zander.waterfall.events; import com.jayway.jsonpath.JsonPath; -import org.modularsoft.zander.proxy.ConfigurationManager; -import org.modularsoft.zander.proxy.ZanderProxyMain; -import org.modularsoft.zander.proxy.model.Filter; +import org.modularsoft.zander.waterfall.ConfigurationManager; +import org.modularsoft.zander.waterfall.ZanderProxyMain; +import org.modularsoft.zander.waterfall.model.Filter; import io.github.ModularEnigma.Request; import io.github.ModularEnigma.Response; import net.md_5.bungee.api.ChatColor; @@ -12,7 +12,7 @@ import net.md_5.bungee.api.event.ChatEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; -import org.modularsoft.zander.proxy.model.discord.DiscordChat; +import org.modularsoft.zander.waterfall.model.discord.DiscordChat; import static com.jayway.jsonpath.Criteria.where; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserCommandSpyEvent.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserCommandSpyEvent.java similarity index 90% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserCommandSpyEvent.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserCommandSpyEvent.java index 529f5ea..f749a15 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserCommandSpyEvent.java +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserCommandSpyEvent.java @@ -1,4 +1,4 @@ -package org.modularsoft.zander.proxy.events; +package org.modularsoft.zander.waterfall.events; import io.github.ModularEnigma.Request; import io.github.ModularEnigma.Response; @@ -7,9 +7,9 @@ import net.md_5.bungee.api.event.ChatEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; -import org.modularsoft.zander.proxy.ConfigurationManager; -import org.modularsoft.zander.proxy.ZanderProxyMain; -import org.modularsoft.zander.proxy.model.discord.spy.DiscordCommandSpy; +import org.modularsoft.zander.waterfall.ConfigurationManager; +import org.modularsoft.zander.waterfall.ZanderProxyMain; +import org.modularsoft.zander.waterfall.model.discord.spy.DiscordCommandSpy; public class UserCommandSpyEvent implements Listener { private ZanderProxyMain plugin = ZanderProxyMain.getInstance(); diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnDisconnect.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserOnDisconnect.java similarity index 89% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnDisconnect.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserOnDisconnect.java index 278426a..2bb0e03 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnDisconnect.java +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserOnDisconnect.java @@ -1,11 +1,11 @@ -package org.modularsoft.zander.proxy.events; +package org.modularsoft.zander.waterfall.events; -import org.modularsoft.zander.proxy.ConfigurationManager; -import org.modularsoft.zander.proxy.ZanderProxyMain; -import org.modularsoft.zander.proxy.model.session.SessionDestroy; +import org.modularsoft.zander.waterfall.ConfigurationManager; +import org.modularsoft.zander.waterfall.ZanderProxyMain; +import org.modularsoft.zander.waterfall.model.session.SessionDestroy; import io.github.ModularEnigma.Request; import io.github.ModularEnigma.Response; -import org.modularsoft.zander.proxy.model.discord.DiscordLeave; +import org.modularsoft.zander.waterfall.model.discord.DiscordLeave; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; import net.md_5.bungee.api.event.PlayerDisconnectEvent; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnLogin.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserOnLogin.java similarity index 91% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnLogin.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserOnLogin.java index fddba6e..fe866df 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnLogin.java +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserOnLogin.java @@ -1,10 +1,10 @@ -package org.modularsoft.zander.proxy.events; +package org.modularsoft.zander.waterfall.events; -import org.modularsoft.zander.proxy.ConfigurationManager; -import org.modularsoft.zander.proxy.ZanderProxyMain; -import org.modularsoft.zander.proxy.model.discord.DiscordJoin; -import org.modularsoft.zander.proxy.model.session.SessionCreate; -import org.modularsoft.zander.proxy.model.user.UserCreation; +import org.modularsoft.zander.waterfall.ConfigurationManager; +import org.modularsoft.zander.waterfall.ZanderProxyMain; +import org.modularsoft.zander.waterfall.model.discord.DiscordJoin; +import org.modularsoft.zander.waterfall.model.session.SessionCreate; +import org.modularsoft.zander.waterfall.model.user.UserCreation; import io.github.ModularEnigma.Request; import io.github.ModularEnigma.Response; import net.md_5.bungee.api.chat.TextComponent; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnProxyPing.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserOnProxyPing.java similarity index 92% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnProxyPing.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserOnProxyPing.java index 2eef48e..9e77780 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnProxyPing.java +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserOnProxyPing.java @@ -1,8 +1,8 @@ -package org.modularsoft.zander.proxy.events; +package org.modularsoft.zander.waterfall.events; import com.jayway.jsonpath.JsonPath; -import org.modularsoft.zander.proxy.ConfigurationManager; -import org.modularsoft.zander.proxy.ZanderProxyMain; +import org.modularsoft.zander.waterfall.ConfigurationManager; +import org.modularsoft.zander.waterfall.ZanderProxyMain; import io.github.ModularEnigma.Request; import io.github.ModularEnigma.Response; import net.md_5.bungee.api.ChatColor; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnSwitch.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserOnSwitch.java similarity index 90% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnSwitch.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserOnSwitch.java index 1c9051b..900a08e 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserOnSwitch.java +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserOnSwitch.java @@ -1,4 +1,4 @@ -package org.modularsoft.zander.proxy.events; +package org.modularsoft.zander.waterfall.events; import io.github.ModularEnigma.Request; import io.github.ModularEnigma.Response; @@ -7,10 +7,10 @@ import net.md_5.bungee.api.event.ServerConnectedEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; -import org.modularsoft.zander.proxy.ConfigurationManager; -import org.modularsoft.zander.proxy.ZanderProxyMain; -import org.modularsoft.zander.proxy.model.discord.DiscordSwitch; -import org.modularsoft.zander.proxy.model.session.SessionSwitch; +import org.modularsoft.zander.waterfall.ConfigurationManager; +import org.modularsoft.zander.waterfall.ZanderProxyMain; +import org.modularsoft.zander.waterfall.model.discord.DiscordSwitch; +import org.modularsoft.zander.waterfall.model.session.SessionSwitch; import java.util.UUID; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserSocialSpyEvent.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserSocialSpyEvent.java similarity index 88% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserSocialSpyEvent.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserSocialSpyEvent.java index 9bab0e0..ee0f99e 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/events/UserSocialSpyEvent.java +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/events/UserSocialSpyEvent.java @@ -1,4 +1,4 @@ -package org.modularsoft.zander.proxy.events; +package org.modularsoft.zander.waterfall.events; import io.github.ModularEnigma.Request; import io.github.ModularEnigma.Response; @@ -7,10 +7,9 @@ import net.md_5.bungee.api.event.ChatEvent; import net.md_5.bungee.api.plugin.Listener; import net.md_5.bungee.event.EventHandler; -import org.modularsoft.zander.proxy.ConfigurationManager; -import org.modularsoft.zander.proxy.ZanderProxyMain; -import org.modularsoft.zander.proxy.model.discord.spy.DiscordCommandSpy; -import org.modularsoft.zander.proxy.model.discord.spy.DiscordSocialSpy; +import org.modularsoft.zander.waterfall.ConfigurationManager; +import org.modularsoft.zander.waterfall.ZanderProxyMain; +import org.modularsoft.zander.waterfall.model.discord.spy.DiscordSocialSpy; import java.util.Arrays; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/Filter.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/Filter.java new file mode 100644 index 0000000..f52ce4a --- /dev/null +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/Filter.java @@ -0,0 +1,17 @@ +package org.modularsoft.zander.waterfall.model; + +import com.google.gson.Gson; +import lombok.Builder; +import lombok.Getter; + +@Builder +public class Filter { + + @Getter String content; + + @Override + public String toString() { + return new Gson().toJson(this); + } + +} diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/DiscordChat.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/DiscordChat.java new file mode 100644 index 0000000..2325604 --- /dev/null +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/DiscordChat.java @@ -0,0 +1,19 @@ +package org.modularsoft.zander.waterfall.model.discord; + +import com.google.gson.Gson; +import lombok.Builder; +import lombok.Getter; + +@Builder +public class DiscordChat { + + @Getter String username; + @Getter String server; + @Getter String content; + + @Override + public String toString() { + return new Gson().toJson(this); + } + +} diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/DiscordJoin.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/DiscordJoin.java new file mode 100644 index 0000000..3378ab0 --- /dev/null +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/DiscordJoin.java @@ -0,0 +1,17 @@ +package org.modularsoft.zander.waterfall.model.discord; + +import com.google.gson.Gson; +import lombok.Builder; +import lombok.Getter; + +@Builder +public class DiscordJoin { + + @Getter String username; + + @Override + public String toString() { + return new Gson().toJson(this); + } + +} diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/DiscordLeave.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/DiscordLeave.java new file mode 100644 index 0000000..63d7342 --- /dev/null +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/DiscordLeave.java @@ -0,0 +1,17 @@ +package org.modularsoft.zander.waterfall.model.discord; + +import com.google.gson.Gson; +import lombok.Builder; +import lombok.Getter; + +@Builder +public class DiscordLeave { + + @Getter String username; + + @Override + public String toString() { + return new Gson().toJson(this); + } + +} diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/DiscordSwitch.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/DiscordSwitch.java new file mode 100644 index 0000000..ed5c772 --- /dev/null +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/DiscordSwitch.java @@ -0,0 +1,18 @@ +package org.modularsoft.zander.waterfall.model.discord; + +import com.google.gson.Gson; +import lombok.Builder; +import lombok.Getter; + +@Builder +public class DiscordSwitch { + + @Getter String username; + @Getter String server; + + @Override + public String toString() { + return new Gson().toJson(this); + } + +} diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/spy/DiscordCommandSpy.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/spy/DiscordCommandSpy.java new file mode 100644 index 0000000..f12738f --- /dev/null +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/spy/DiscordCommandSpy.java @@ -0,0 +1,19 @@ +package org.modularsoft.zander.waterfall.model.discord.spy; + +import com.google.gson.Gson; +import lombok.Builder; +import lombok.Getter; + +@Builder +public class DiscordCommandSpy { + + @Getter String username; + @Getter String command; + @Getter String server; + + @Override + public String toString() { + return new Gson().toJson(this); + } + +} diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/spy/DiscordSocialSpy.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/spy/DiscordSocialSpy.java new file mode 100644 index 0000000..0a6cc8f --- /dev/null +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/discord/spy/DiscordSocialSpy.java @@ -0,0 +1,20 @@ +package org.modularsoft.zander.waterfall.model.discord.spy; + +import com.google.gson.Gson; +import lombok.Builder; +import lombok.Getter; + +@Builder +public class DiscordSocialSpy { + + @Getter String usernameFrom; + @Getter String usernameTo; + @Getter String directMessage; + @Getter String server; + + @Override + public String toString() { + return new Gson().toJson(this); + } + +} diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/session/SessionCreate.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/session/SessionCreate.java new file mode 100644 index 0000000..2bf7448 --- /dev/null +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/session/SessionCreate.java @@ -0,0 +1,20 @@ +package org.modularsoft.zander.waterfall.model.session; + +import com.google.gson.Gson; +import lombok.Builder; +import lombok.Getter; + +import java.util.UUID; + +@Builder +public class SessionCreate { + + @Getter UUID uuid; + @Getter String ipAddress; + + @Override + public String toString() { + return new Gson().toJson(this); + } + +} diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/session/SessionDestroy.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/session/SessionDestroy.java new file mode 100644 index 0000000..e7f875c --- /dev/null +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/session/SessionDestroy.java @@ -0,0 +1,19 @@ +package org.modularsoft.zander.waterfall.model.session; + +import com.google.gson.Gson; +import lombok.Builder; +import lombok.Getter; + +import java.util.UUID; + +@Builder +public class SessionDestroy { + + @Getter UUID uuid; + + @Override + public String toString() { + return new Gson().toJson(this); + } + +} diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/session/SessionSwitch.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/session/SessionSwitch.java new file mode 100644 index 0000000..5bd82c8 --- /dev/null +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/session/SessionSwitch.java @@ -0,0 +1,20 @@ +package org.modularsoft.zander.waterfall.model.session; + +import com.google.gson.Gson; +import lombok.Builder; +import lombok.Getter; + +import java.util.UUID; + +@Builder +public class SessionSwitch { + + @Getter UUID uuid; + @Getter String server; + + @Override + public String toString() { + return new Gson().toJson(this); + } + +} diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/user/UserCreation.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/user/UserCreation.java new file mode 100644 index 0000000..b645099 --- /dev/null +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/model/user/UserCreation.java @@ -0,0 +1,20 @@ +package org.modularsoft.zander.waterfall.model.user; + +import com.google.gson.Gson; +import lombok.Builder; +import lombok.Getter; + +import java.util.UUID; + +@Builder +public class UserCreation { + + @Getter UUID uuid; + @Getter String username; + + @Override + public String toString() { + return new Gson().toJson(this); + } + +} diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/util/announcement/TipChatter.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/util/announcement/TipChatter.java similarity index 95% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/util/announcement/TipChatter.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/util/announcement/TipChatter.java index b0948d8..5e94d3d 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/util/announcement/TipChatter.java +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/util/announcement/TipChatter.java @@ -1,4 +1,4 @@ -package org.modularsoft.zander.proxy.util.announcement; +package org.modularsoft.zander.waterfall.util.announcement; import com.jayway.jsonpath.JsonPath; import io.github.ModularEnigma.Request; @@ -8,7 +8,7 @@ import net.md_5.bungee.api.chat.ClickEvent; import net.md_5.bungee.api.chat.TextComponent; import net.md_5.bungee.api.connection.ProxiedPlayer; -import org.modularsoft.zander.proxy.ConfigurationManager; +import org.modularsoft.zander.waterfall.ConfigurationManager; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; diff --git a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/util/api/Heartbeat.java b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/util/api/Heartbeat.java similarity index 95% rename from zander-waterfall/src/main/java/org/modularsoft/zander/proxy/util/api/Heartbeat.java rename to zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/util/api/Heartbeat.java index 22dd5dd..e31dbba 100644 --- a/zander-waterfall/src/main/java/org/modularsoft/zander/proxy/util/api/Heartbeat.java +++ b/zander-waterfall/src/main/java/org/modularsoft/zander/waterfall/util/api/Heartbeat.java @@ -1,10 +1,10 @@ -package org.modularsoft.zander.proxy.util.api; +package org.modularsoft.zander.waterfall.util.api; import com.jayway.jsonpath.JsonPath; import io.github.ModularEnigma.Request; import io.github.ModularEnigma.Response; import net.md_5.bungee.api.ProxyServer; -import org.modularsoft.zander.proxy.ConfigurationManager; +import org.modularsoft.zander.waterfall.ConfigurationManager; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; From 94d403bde0282fb01be81fde3555685ce053c38b Mon Sep 17 00:00:00 2001 From: benrobson Date: Wed, 17 Apr 2024 21:15:30 +1000 Subject: [PATCH 04/17] Implementation of UserOnSwitch and testing of UserOnSwitch and UserChatEvent --- .../zander/velocity/ZanderVelocityMain.java | 4 + .../zander/velocity/events/UserChatEvent.java | 1 - .../velocity/events/UserCommandSpyEvent.java | 56 ++++++++++++++ .../zander/velocity/events/UserOnSwitch.java | 75 +++++++++++++++++++ 4 files changed, 135 insertions(+), 1 deletion(-) create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserCommandSpyEvent.java create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnSwitch.java diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java index 9981f36..fc8a592 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java @@ -16,6 +16,8 @@ import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings; import lombok.Getter; import org.modularsoft.zander.velocity.events.UserChatEvent; +import org.modularsoft.zander.velocity.events.UserCommandSpyEvent; +import org.modularsoft.zander.velocity.events.UserOnSwitch; import org.slf4j.Logger; import java.io.File; @@ -45,7 +47,9 @@ public class ZanderVelocityMain { @Subscribe public void onProxyInitialization(ProxyInitializeEvent event) { // Event Listeners + proxy.getEventManager().register(this, new UserCommandSpyEvent()); proxy.getEventManager().register(this, new UserChatEvent()); + proxy.getEventManager().register(this, new UserOnSwitch()); // Commands diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserChatEvent.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserChatEvent.java index 9174a05..2140a07 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserChatEvent.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserChatEvent.java @@ -18,7 +18,6 @@ public class UserChatEvent { @Subscribe public void UserChatEvent(PlayerChatEvent event) { Player player = event.getPlayer(); - String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserCommandSpyEvent.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserCommandSpyEvent.java new file mode 100644 index 0000000..975c2b4 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserCommandSpyEvent.java @@ -0,0 +1,56 @@ +package org.modularsoft.zander.velocity.events; + +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.player.PlayerChatEvent; +import com.velocitypowered.api.proxy.Player; +import dev.dejvokep.boostedyaml.route.Route; +import io.github.ModularEnigma.Request; +import io.github.ModularEnigma.Response; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.modularsoft.zander.velocity.ZanderVelocityMain; +import org.modularsoft.zander.velocity.model.discord.spy.DiscordCommandSpy; + +public class UserCommandSpyEvent { + + @Subscribe + public void UserChatEvent(PlayerChatEvent event) { + Player player = event.getPlayer(); + String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); + String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + String command = event.getMessage().substring(1); // Remove the leading slash + + if (event.getMessage().startsWith("/")) { + // Excludes specific commands from being logged in both spy events. + if (command.startsWith("msg") || command.startsWith("tell") || command.startsWith("w") || command.startsWith("message") || command.startsWith("r")) { + return; + } + + // + // Command Spy API POST + // + try { + DiscordCommandSpy commandSpy = DiscordCommandSpy.builder() + .username(player.getUsername()) + .command(command) + .server(player.getCurrentServer().get().getServer().getServerInfo().getName()) + .build(); + + Request commandSpyReq = Request.builder() + .setURL(BaseAPIURL + "/discord/spy/command") + .setMethod(Request.Method.POST) + .addHeader("x-access-token", String.valueOf(APIKey)) + .setRequestBody(commandSpy.toString()) + .build(); + + Response commandSpyRes = commandSpyReq.execute(); + ZanderVelocityMain.getLogger().info("Response (" + commandSpyRes.getStatusCode() + "): " + commandSpyRes.getBody()); + } catch (Exception e) { + Component builder = Component.text("An error has occurred. Is the API down?").color(NamedTextColor.RED); + player.disconnect(builder); + System.out.println(e); + } + } + } + +} diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnSwitch.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnSwitch.java new file mode 100644 index 0000000..688e848 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnSwitch.java @@ -0,0 +1,75 @@ +package org.modularsoft.zander.velocity.events; + +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.player.ServerConnectedEvent; +import com.velocitypowered.api.proxy.Player; +import dev.dejvokep.boostedyaml.route.Route; +import io.github.ModularEnigma.Request; +import io.github.ModularEnigma.Response; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.modularsoft.zander.velocity.ZanderVelocityMain; +import org.modularsoft.zander.velocity.model.discord.DiscordSwitch; +import org.modularsoft.zander.velocity.model.session.SessionSwitch; + +import java.util.UUID; + +public class UserOnSwitch { + @Subscribe + public void onServerConnect(ServerConnectedEvent event) { + Player player = event.getPlayer(); + String username = player.getUsername(); + UUID playerUUID = player.getUniqueId(); + String server = event.getServer().getServerInfo().getName(); + String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); + String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + + try { + // + // Switch Session API POST + // + SessionSwitch switchSession = SessionSwitch.builder() + .uuid(playerUUID) + .server(server) + .build(); + + Request switchSessionReq = Request.builder() + .setURL(BaseAPIURL + "/session/switch") + .setMethod(Request.Method.POST) + .addHeader("x-access-token", APIKey) + .setRequestBody(switchSession.toString()) + .build(); + + Response switchSessionRes = switchSessionReq.execute(); + ZanderVelocityMain.getLogger().info("Response (" + switchSessionRes.getStatusCode() + "): " + switchSessionRes.getBody()); + } catch (Exception e) { + Component builder = Component.text("An error has occurred. Is the API down?").color(NamedTextColor.RED); + player.disconnect(builder); + System.out.println(e); + } + + try { + // + // Discord Switch API POST + // + DiscordSwitch discordSwitch = DiscordSwitch.builder() + .username(username) + .server(server) + .build(); + + Request discordSwitchReq = Request.builder() + .setURL(BaseAPIURL + "/discord/switch") + .setMethod(Request.Method.POST) + .addHeader("x-access-token", APIKey) + .setRequestBody(discordSwitch.toString()) + .build(); + + Response discordSwitchRes = discordSwitchReq.execute(); + ZanderVelocityMain.getLogger().info("Response (" + discordSwitchRes.getStatusCode() + "): " + discordSwitchRes.getBody()); + } catch (Exception e) { + Component builder = Component.text("An error has occurred. Is the API down?").color(NamedTextColor.RED); + player.disconnect(builder); + System.out.println(e); + } + } +} From cb9467df61a8d580d2f0b1296cb21ac48f25642a Mon Sep 17 00:00:00 2001 From: benrobson Date: Wed, 17 Apr 2024 22:01:45 +1000 Subject: [PATCH 05/17] Implementation of UserOnDisconnect and UserOnLogin. --- .../zander/velocity/ZanderVelocityMain.java | 8 +- .../velocity/events/UserOnDisconnect.java | 75 ++++++++++++++++ .../zander/velocity/events/UserOnLogin.java | 85 +++++++++++++++++++ 3 files changed, 164 insertions(+), 4 deletions(-) create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnDisconnect.java create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnLogin.java diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java index fc8a592..c22ac6d 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java @@ -15,9 +15,7 @@ import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings; import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings; import lombok.Getter; -import org.modularsoft.zander.velocity.events.UserChatEvent; -import org.modularsoft.zander.velocity.events.UserCommandSpyEvent; -import org.modularsoft.zander.velocity.events.UserOnSwitch; +import org.modularsoft.zander.velocity.events.*; import org.slf4j.Logger; import java.io.File; @@ -40,7 +38,7 @@ public class ZanderVelocityMain { @Getter private static Logger logger; @Getter - private final ProxyServer proxy; + private static ProxyServer proxy; @Getter private static YamlDocument config; @@ -50,6 +48,8 @@ public void onProxyInitialization(ProxyInitializeEvent event) { proxy.getEventManager().register(this, new UserCommandSpyEvent()); proxy.getEventManager().register(this, new UserChatEvent()); proxy.getEventManager().register(this, new UserOnSwitch()); + proxy.getEventManager().register(this, new UserOnLogin()); + proxy.getEventManager().register(this, new UserOnDisconnect()); // Commands diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnDisconnect.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnDisconnect.java new file mode 100644 index 0000000..67ce9ed --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnDisconnect.java @@ -0,0 +1,75 @@ +package org.modularsoft.zander.velocity.events; + +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.connection.DisconnectEvent; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ProxyServer; +import dev.dejvokep.boostedyaml.route.Route; +import io.github.ModularEnigma.Request; +import io.github.ModularEnigma.Response; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.modularsoft.zander.velocity.ZanderVelocityMain; +import org.modularsoft.zander.velocity.model.discord.DiscordLeave; +import org.modularsoft.zander.velocity.model.session.SessionDestroy; + +public class UserOnDisconnect { + @Subscribe + public void UserDisconnectEvent (DisconnectEvent event) { + Player player = event.getPlayer(); + String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); + String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + + boolean isConnected = isConnected(ZanderVelocityMain.getProxy(), player.getUsername()); + if (isConnected) return; + + // + // Destory Session API POST + // + try { + SessionDestroy destroySession = SessionDestroy.builder() + .uuid(player.getUniqueId()) + .build(); + + Request destroySessionReq = Request.builder() + .setURL(BaseAPIURL + "/session/destroy") + .setMethod(Request.Method.POST) + .addHeader("x-access-token", APIKey) + .setRequestBody(destroySession.toString()) + .build(); + + Response destroySessionRes = destroySessionReq.execute(); + ZanderVelocityMain.getLogger().info("Response (" + destroySessionRes.getStatusCode() + "): " + destroySessionRes.getBody()); + } catch (Exception e) { + Component builder = Component.text("An error has occurred. Is the API down?").color(NamedTextColor.RED); + player.disconnect(builder); + } + + // + // Send Discord API POST for disconnect message + // + try { + DiscordLeave leave = DiscordLeave.builder() + .username(player.getUsername()) + .build(); + + Request discordLeaveReq = Request.builder() + .setURL(BaseAPIURL + "/discord/leave") + .setMethod(Request.Method.POST) + .addHeader("x-access-token", APIKey) + .setRequestBody(leave.toString()) + .build(); + + Response discordLeaveRes = discordLeaveReq.execute(); + ZanderVelocityMain.getLogger().info("Response (" + discordLeaveRes.getStatusCode() + "): " + discordLeaveRes.getBody()); + } catch (Exception e) { + Component builder = Component.text("An error has occurred. Is the API down?").color(NamedTextColor.RED); + player.disconnect(builder); + } + } + + public static boolean isConnected(ProxyServer proxy, String playerName) { + Player player = proxy.getPlayer(playerName).orElse(null); + return player != null; + } +} diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnLogin.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnLogin.java new file mode 100644 index 0000000..d032790 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnLogin.java @@ -0,0 +1,85 @@ +package org.modularsoft.zander.velocity.events; + +import com.velocitypowered.api.event.PostOrder; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.connection.PostLoginEvent; +import com.velocitypowered.api.proxy.Player; +import dev.dejvokep.boostedyaml.route.Route; +import io.github.ModularEnigma.Request; +import io.github.ModularEnigma.Response; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.modularsoft.zander.velocity.ZanderVelocityMain; +import org.modularsoft.zander.velocity.model.discord.DiscordJoin; +import org.modularsoft.zander.velocity.model.session.SessionCreate; +import org.modularsoft.zander.velocity.model.user.UserCreation; + +public class UserOnLogin { + @Subscribe(order = PostOrder.FIRST) + public void UserLoginEvent (PostLoginEvent event) { + Player player = event.getPlayer(); + String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); + String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + + try { + // + // Send User Creation API POST for new user + // + UserCreation createUser = UserCreation.builder() + .uuid(player.getUniqueId()) + .username(player.getUsername()) + .build(); + + Request createUserReq = Request.builder() + .setURL(BaseAPIURL + "/user/create") + .setMethod(Request.Method.POST) + .addHeader("x-access-token", APIKey) + .setRequestBody(createUser.toString()) + .build(); + + Response createUserRes = createUserReq.execute(); + ZanderVelocityMain.getLogger().info("Response (" + createUserRes.getStatusCode() + "): " + createUserRes.getBody()); + + try { + // + // Start Session API POST + // + SessionCreate createSession = SessionCreate.builder() + .uuid(player.getUniqueId()) + .ipAddress(player.getRemoteAddress().getAddress().toString()) + .build(); + + Request createSessionReq = Request.builder() + .setURL(BaseAPIURL + "/session/create") + .setMethod(Request.Method.POST) + .addHeader("x-access-token", APIKey) + .setRequestBody(createSession.toString()) + .build(); + + Response createSessionRes = createSessionReq.execute(); + ZanderVelocityMain.getLogger().info("Response (" + createSessionRes.getStatusCode() + "): " + createSessionRes.getBody()); + + // Send Discord API POST for join message + DiscordJoin join = DiscordJoin.builder() + .username(player.getUsername()) + .build(); + + Request discordJoinReq = Request.builder() + .setURL(BaseAPIURL + "/discord/join") + .setMethod(Request.Method.POST) + .addHeader("x-access-token", APIKey) + .setRequestBody(join.toString()) + .build(); + + Response discordJoinRes = discordJoinReq.execute(); + ZanderVelocityMain.getLogger().info("Response (" + discordJoinRes.getStatusCode() + "): " + discordJoinRes.getBody()); + } catch (Exception e) { + Component builder = Component.text("An error has occurred. Is the API down?").color(NamedTextColor.RED); + player.disconnect(builder); + } + } catch (Exception e) { + Component builder = Component.text("An error has occurred. Is the API down?").color(NamedTextColor.RED); + player.disconnect(builder); + } + } +} From 4c78c7bc7b2e7c04ec0215e6e039474de2501b19 Mon Sep 17 00:00:00 2001 From: benrobson Date: Thu, 18 Apr 2024 00:01:14 +1000 Subject: [PATCH 06/17] Implementation of Discord command and Command Manager. --- .../zander/velocity/ZanderVelocityMain.java | 11 +++++ .../zander/velocity/commands/discord.java | 44 +++++++++++++++++++ .../zander/velocity/events/UserOnLogin.java | 2 +- 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/discord.java diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java index c22ac6d..e0fcea3 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java @@ -1,6 +1,9 @@ package org.modularsoft.zander.velocity; import com.google.inject.Inject; +import com.velocitypowered.api.command.CommandManager; +import com.velocitypowered.api.command.CommandMeta; +import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.plugin.Dependency; @@ -15,6 +18,7 @@ import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings; import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings; import lombok.Getter; +import org.modularsoft.zander.velocity.commands.discord; import org.modularsoft.zander.velocity.events.*; import org.slf4j.Logger; @@ -41,6 +45,8 @@ public class ZanderVelocityMain { private static ProxyServer proxy; @Getter private static YamlDocument config; + @Getter + private final CommandManager commandManager; @Subscribe public void onProxyInitialization(ProxyInitializeEvent event) { @@ -52,6 +58,9 @@ public void onProxyInitialization(ProxyInitializeEvent event) { proxy.getEventManager().register(this, new UserOnDisconnect()); // Commands + CommandManager commandManager = proxy.getCommandManager(); + + commandManager.register("discord", new discord()); } @@ -59,10 +68,12 @@ public void onProxyInitialization(ProxyInitializeEvent event) { public ZanderVelocityMain( ProxyServer proxy, Logger logger, + CommandManager commandManager, @DataDirectory Path dataDirectory ) { this.proxy = proxy; this.logger = logger; + this.commandManager = commandManager; // Create configuration file try { diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/discord.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/discord.java new file mode 100644 index 0000000..cfc9159 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/discord.java @@ -0,0 +1,44 @@ +package org.modularsoft.zander.velocity.commands; + +import com.jayway.jsonpath.JsonPath; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.SimpleCommand; +import dev.dejvokep.boostedyaml.route.Route; +import io.github.ModularEnigma.Request; +import io.github.ModularEnigma.Response; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.format.NamedTextColor; +import org.modularsoft.zander.velocity.ZanderVelocityMain; + +public class discord implements SimpleCommand { + @Override + public void execute(final Invocation invocation) { + CommandSource source = invocation.source(); + String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); + String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + + try { + // GET request to link to discord. + Request req = Request.builder() + .setURL(BaseAPIURL + "/web/configuration") + .setMethod(Request.Method.GET) + .addHeader("x-access-token", APIKey) + .build(); + + Response res = req.execute(); + String json = res.getBody(); + String siteAddress = JsonPath.read(json, "$.data.siteAddress"); + + Component message = Component.text("Get to know the community and join our Discord here: " + siteAddress + "/discord") + .color(NamedTextColor.BLUE); + message = message.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL,siteAddress + "/discord")); + source.sendMessage(message); + return; + } catch (Exception e) { + Component builder = Component.text("An error has occurred. Is the API down?").color(NamedTextColor.RED); + source.sendMessage(builder); + System.out.println(e); + } + } +} diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnLogin.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnLogin.java index d032790..f1ef3ff 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnLogin.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnLogin.java @@ -15,7 +15,7 @@ import org.modularsoft.zander.velocity.model.user.UserCreation; public class UserOnLogin { - @Subscribe(order = PostOrder.FIRST) + @Subscribe public void UserLoginEvent (PostLoginEvent event) { Player player = event.getPlayer(); String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); From 7c3063e27633a6689a500aff4651f315bb6b0283 Mon Sep 17 00:00:00 2001 From: benrobson Date: Thu, 18 Apr 2024 08:20:07 +1000 Subject: [PATCH 07/17] Implementation of Rules and Website command. --- .../zander/velocity/ZanderVelocityMain.java | 7 +-- .../zander/velocity/commands/rules.java | 43 +++++++++++++++++++ .../zander/velocity/commands/website.java | 43 +++++++++++++++++++ 3 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/rules.java create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/website.java diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java index e0fcea3..b1dd679 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java @@ -2,8 +2,6 @@ import com.google.inject.Inject; import com.velocitypowered.api.command.CommandManager; -import com.velocitypowered.api.command.CommandMeta; -import com.velocitypowered.api.command.SimpleCommand; import com.velocitypowered.api.event.proxy.ProxyInitializeEvent; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.plugin.Dependency; @@ -19,6 +17,8 @@ import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings; import lombok.Getter; import org.modularsoft.zander.velocity.commands.discord; +import org.modularsoft.zander.velocity.commands.rules; +import org.modularsoft.zander.velocity.commands.website; import org.modularsoft.zander.velocity.events.*; import org.slf4j.Logger; @@ -61,7 +61,8 @@ public void onProxyInitialization(ProxyInitializeEvent event) { CommandManager commandManager = proxy.getCommandManager(); commandManager.register("discord", new discord()); - + commandManager.register("rules", new rules()); + commandManager.register("website", new website()); } @Inject diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/rules.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/rules.java new file mode 100644 index 0000000..438d97c --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/rules.java @@ -0,0 +1,43 @@ +package org.modularsoft.zander.velocity.commands; + +import com.jayway.jsonpath.JsonPath; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.SimpleCommand; +import dev.dejvokep.boostedyaml.route.Route; +import io.github.ModularEnigma.Request; +import io.github.ModularEnigma.Response; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.format.NamedTextColor; +import org.modularsoft.zander.velocity.ZanderVelocityMain; + +public class rules implements SimpleCommand { + @Override + public void execute(final Invocation invocation) { + CommandSource source = invocation.source(); + String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); + String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + + try { + // GET request to link to discord. + Request req = Request.builder() + .setURL(BaseAPIURL + "/web/configuration") + .setMethod(Request.Method.GET) + .addHeader("x-access-token", APIKey) + .build(); + + Response res = req.execute(); + String json = res.getBody(); + String siteAddress = JsonPath.read(json, "$.data.siteAddress"); + + Component message = Component.text("Please read and abide by the rules which you can find on our website here: " + siteAddress + "/rules") + .color(NamedTextColor.RED); + message = message.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL,siteAddress + "/rules")); + source.sendMessage(message); + } catch (Exception e) { + Component builder = Component.text("An error has occurred. Is the API down?").color(NamedTextColor.RED); + source.sendMessage(builder); + System.out.println(e); + } + } +} diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/website.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/website.java new file mode 100644 index 0000000..39af9b6 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/website.java @@ -0,0 +1,43 @@ +package org.modularsoft.zander.velocity.commands; + +import com.jayway.jsonpath.JsonPath; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.SimpleCommand; +import dev.dejvokep.boostedyaml.route.Route; +import io.github.ModularEnigma.Request; +import io.github.ModularEnigma.Response; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.format.NamedTextColor; +import org.modularsoft.zander.velocity.ZanderVelocityMain; + +public class website implements SimpleCommand { + @Override + public void execute(final Invocation invocation) { + CommandSource source = invocation.source(); + String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); + String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + + try { + // GET request to link to discord. + Request req = Request.builder() + .setURL(BaseAPIURL + "/web/configuration") + .setMethod(Request.Method.GET) + .addHeader("x-access-token", APIKey) + .build(); + + Response res = req.execute(); + String json = res.getBody(); + String siteAddress = JsonPath.read(json, "$.data.siteAddress"); + + Component message = Component.text("For all information regarding the Network, visit our website: " + siteAddress) + .color(NamedTextColor.YELLOW); + message = message.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL,siteAddress)); + source.sendMessage(message); + } catch (Exception e) { + Component builder = Component.text("An error has occurred. Is the API down?").color(NamedTextColor.RED); + source.sendMessage(builder); + System.out.println(e); + } + } +} From 7610765cbd80a36b40884a4dded998027e05725c Mon Sep 17 00:00:00 2001 From: benrobson Date: Thu, 18 Apr 2024 08:39:55 +1000 Subject: [PATCH 08/17] Added Heartbeat and TipChatter for testing. --- .../zander/velocity/ZanderVelocityMain.java | 8 +++ .../util/announcement/TipChatter.java | 59 ++++++++++++++++++ .../zander/velocity/util/api/Heartbeat.java | 62 +++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/announcement/TipChatter.java create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Heartbeat.java diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java index b1dd679..051abc6 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java @@ -20,6 +20,8 @@ import org.modularsoft.zander.velocity.commands.rules; import org.modularsoft.zander.velocity.commands.website; import org.modularsoft.zander.velocity.events.*; +import org.modularsoft.zander.velocity.util.announcement.TipChatter; +import org.modularsoft.zander.velocity.util.api.Heartbeat; import org.slf4j.Logger; import java.io.File; @@ -63,6 +65,12 @@ public void onProxyInitialization(ProxyInitializeEvent event) { commandManager.register("discord", new discord()); commandManager.register("rules", new rules()); commandManager.register("website", new website()); + + // Start the Heartbeat task + Heartbeat.startHeartbeatTask(); + + // Start the Announcement Tip task + TipChatter.startAnnouncementTipTask(); } @Inject diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/announcement/TipChatter.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/announcement/TipChatter.java new file mode 100644 index 0000000..2aaddb5 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/announcement/TipChatter.java @@ -0,0 +1,59 @@ +package org.modularsoft.zander.velocity.util.announcement; + +import com.jayway.jsonpath.JsonPath; +import dev.dejvokep.boostedyaml.route.Route; +import io.github.ModularEnigma.Request; +import io.github.ModularEnigma.Response; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.event.ClickEvent; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.modularsoft.zander.velocity.ZanderVelocityMain; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +public class TipChatter { + public static void startAnnouncementTipTask() { + String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); + String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + + // Create a ScheduledExecutorService with a single thread + ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + + // Schedule the task to run every 10 seconds + scheduler.scheduleAtFixedRate(() -> { + try { + // GET request to fetch Announcement Tip. + Request req = Request.builder() + .setURL(BaseAPIURL + "/announcement/get?announcementType=tip") + .setMethod(Request.Method.GET) + .addHeader("x-access-token", APIKey) + .build(); + + Response res = req.execute(); + String json = res.getBody(); + + String colourMessageFormat = JsonPath.read(json, "$.data[0].colourMessageFormat"); + String link = JsonPath.read(json, "$.data[0].link"); + + // Broadcast the message to all online players + ZanderVelocityMain.getProxy().getAllPlayers().forEach(player -> { + // Send the message to each player + char translate = '&'; + Component message = LegacyComponentSerializer.legacy(translate).deserialize(colourMessageFormat); + + if (link != null && !link.isEmpty()) { + // Set the click event only if link is true + message.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL,link)); + } + player.sendMessage(message); + }); + } catch (Exception e) { + // Handle exceptions here + e.printStackTrace(); + System.out.println("Announcement Tip Failed, will try again in " + ZanderVelocityMain.getConfig().getString(Route.from("announcementTipInterval")) + " minutes."); + } + }, 0, ZanderVelocityMain.getConfig().getInt(Route.from("announcementTipInterval")), TimeUnit.MINUTES); + } +} diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Heartbeat.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Heartbeat.java new file mode 100644 index 0000000..ccc1bf8 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Heartbeat.java @@ -0,0 +1,62 @@ +package org.modularsoft.zander.velocity.util.api; + +import com.jayway.jsonpath.JsonPath; +import dev.dejvokep.boostedyaml.route.Route; +import io.github.ModularEnigma.Request; +import io.github.ModularEnigma.Response; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.modularsoft.zander.velocity.ZanderVelocityMain; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +public class Heartbeat { + public static void startHeartbeatTask() { + String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); + String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + + // Create a ScheduledExecutorService with a single thread + ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + + // Schedule the task to run every 60 seconds + scheduler.scheduleAtFixedRate(() -> { + try { + // Your existing code here + // GET request to link to rules. + Request req = Request.builder() + .setURL(BaseAPIURL + "/heartbeat") + .setMethod(Request.Method.GET) + .addHeader("x-access-token", APIKey) + .build(); + + Response res = req.execute(); + String json = res.getBody(); + Boolean heartbeat = JsonPath.read(json, "$.success"); + System.out.println("API Heartbeat Success"); + + // Check if the heartbeat is not successful + if (!heartbeat) { + // Kick all players + ZanderVelocityMain.getProxy().getAllPlayers().forEach(player -> { + Component message = Component.text("API Heartbeat Failed, the server is temporarily offline.") + .color(NamedTextColor.RED); + player.disconnect(message); + }); + } + } catch (Exception e) { + // Handle exceptions here + e.printStackTrace(); + ZanderVelocityMain.getLogger().error("API Heartbeat Failed, kicking all players until back online."); + + // Kick all players + ZanderVelocityMain.getProxy().getAllPlayers().forEach(player -> { + Component message = Component.text("API Heartbeat Failed, the server is temporarily offline.") + .color(NamedTextColor.RED); + player.disconnect(message); + }); + } + }, 0, 60, TimeUnit.SECONDS); + } +} From 7c850574e212fce1d2b65ee11ac78fe76906f03b Mon Sep 17 00:00:00 2001 From: JaedanC Date: Sat, 17 Aug 2024 16:52:16 +1000 Subject: [PATCH 09/17] Added UserOnProxyPing and UserSocialSpyEvent --- .../velocity/events/UserOnProxyPing.java | 62 +++++++++++++++++++ .../velocity/events/UserSocialSpyEvent.java | 62 +++++++++++++++++++ 2 files changed, 124 insertions(+) create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnProxyPing.java create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserSocialSpyEvent.java diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnProxyPing.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnProxyPing.java new file mode 100644 index 0000000..3444495 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnProxyPing.java @@ -0,0 +1,62 @@ +package org.modularsoft.zander.velocity.events; + +import com.jayway.jsonpath.JsonPath; +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.proxy.ProxyPingEvent; +import com.velocitypowered.api.proxy.server.ServerPing; +import dev.dejvokep.boostedyaml.route.Route; +import io.github.ModularEnigma.Request; +import io.github.ModularEnigma.Response; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.modularsoft.zander.velocity.ZanderVelocityMain; + +public class UserOnProxyPing { + + @Subscribe + public void onProxyPingEvent(ProxyPingEvent event) { + try { + // ServerPing serverPing = event.getPing(); + String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); + String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + + // GET request to fetch MOTD. + Request req = Request.builder() + .setURL(BaseAPIURL + "/announcement/get?announcementType=motd") + .setMethod(Request.Method.GET) + .addHeader("x-access-token", APIKey) + .build(); + + Response res = req.execute(); + String json = res.getBody(); + + String colourMessageFormat = JsonPath.read(json, "$.data[0].colourMessageFormat"); + String motdTopLine = ZanderVelocityMain.getConfig().getString(Route.from("announcementMOTDTopLine")); + Component serverPingDescription = LegacyComponentSerializer.builder() + .character('&') + .build() + .deserialize(motdTopLine + "\n" + colourMessageFormat); + + ServerPing newServerPing = ServerPing.builder() + .description(serverPingDescription) + .build(); + + event.setPing(newServerPing); + } catch (Exception e) { + System.out.print(e); + // ServerPing serverPing = event.getPing(); + + String motdTopLine = ZanderVelocityMain.getConfig().getString(Route.from("announcementMOTDTopLine")); + Component serverPingDescription = LegacyComponentSerializer.builder() + .character('&') + .build() + .deserialize(motdTopLine + "\n" + "&3&lPowered by Zander"); + + ServerPing newServerPing = ServerPing.builder() + .description(serverPingDescription) + .build(); + + event.setPing(newServerPing); + } + } +} diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserSocialSpyEvent.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserSocialSpyEvent.java new file mode 100644 index 0000000..f0d0526 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserSocialSpyEvent.java @@ -0,0 +1,62 @@ +package org.modularsoft.zander.velocity.events; + +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.player.PlayerChatEvent; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ServerConnection; +import dev.dejvokep.boostedyaml.route.Route; +import io.github.ModularEnigma.Request; +import io.github.ModularEnigma.Response; +import net.kyori.adventure.text.Component; +import org.modularsoft.zander.velocity.ZanderVelocityMain; +import org.modularsoft.zander.velocity.model.discord.spy.DiscordSocialSpy; + +import java.util.Arrays; + +public class UserSocialSpyEvent { + + @Subscribe + public void onUserChatEvent(PlayerChatEvent event) { + Player player = event.getPlayer(); + String command = event.getMessage().substring(1); // Remove the leading slash + + if (command.startsWith("msg") || command.startsWith("tell") || command.startsWith("w") || command.startsWith("message") || command.startsWith("r")) { + String[] messageParts = event.getMessage().split(" "); + String targetPlayer = messageParts[1]; + String directMessage = String.join(" ", Arrays.copyOfRange(messageParts, 2, messageParts.length)); + + // + // Social Spy API POST + // + try { + if (player.getCurrentServer().isEmpty()){ + return; + } + + ServerConnection currentServer = player.getCurrentServer().get(); + DiscordSocialSpy socialSpy = DiscordSocialSpy.builder() + .usernameFrom(player.getUsername()) + .usernameTo(targetPlayer) + .directMessage(directMessage) + .server(currentServer.getServerInfo().getName()) + .build(); + + String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); + String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + + Request socialSpyReq = Request.builder() + .setURL(BaseAPIURL + "/discord/spy/directMessage") + .setMethod(Request.Method.POST) + .addHeader("x-access-token", APIKey) + .setRequestBody(socialSpy.toString()) + .build(); + + Response socialSpyRes = socialSpyReq.execute(); + ZanderVelocityMain.getLogger().info("Response (" + socialSpyRes.getStatusCode() + "): " + socialSpyRes.getBody()); + } catch (Exception e) { + player.disconnect(Component.text("An error has occurred. Is the API down?")); + System.out.println(e); + } + } + } +} \ No newline at end of file From 858f53e4df3b08f1522948326d314fe6bd3fbbcf Mon Sep 17 00:00:00 2001 From: benrobson Date: Sun, 22 Sep 2024 14:39:13 +1000 Subject: [PATCH 10/17] Register missing events. --- .../modularsoft/zander/velocity/ZanderVelocityMain.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java index 051abc6..77f8908 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java @@ -53,11 +53,13 @@ public class ZanderVelocityMain { @Subscribe public void onProxyInitialization(ProxyInitializeEvent event) { // Event Listeners - proxy.getEventManager().register(this, new UserCommandSpyEvent()); proxy.getEventManager().register(this, new UserChatEvent()); - proxy.getEventManager().register(this, new UserOnSwitch()); - proxy.getEventManager().register(this, new UserOnLogin()); + proxy.getEventManager().register(this, new UserCommandSpyEvent()); proxy.getEventManager().register(this, new UserOnDisconnect()); + proxy.getEventManager().register(this, new UserOnLogin()); + proxy.getEventManager().register(this, new UserOnProxyPing()); + proxy.getEventManager().register(this, new UserOnSwitch()); + proxy.getEventManager().register(this, new UserSocialSpyEvent()); // Commands CommandManager commandManager = proxy.getCommandManager(); From e50c85f6d03ca740553982a1dba011c46183d714 Mon Sep 17 00:00:00 2001 From: benrobson Date: Mon, 7 Oct 2024 13:49:26 +1100 Subject: [PATCH 11/17] Add report and ping command, fix session events and add announcement tip prefix. --- pom.xml | 3 +- zander-velocity/dependency-reduced-pom.xml | 2 +- zander-velocity/pom.xml | 4 +- .../zander/velocity/ZanderVelocityMain.java | 12 +-- .../zander/velocity/commands/ping.java | 30 ++++++ .../zander/velocity/commands/report.java | 99 +++++++++++++++++++ .../zander/velocity/events/UserOnSwitch.java | 34 +++---- .../velocity/events/UserSocialSpyEvent.java | 51 +++++++--- .../zander/velocity/model/Report.java | 20 ++++ .../util/announcement/TipChatter.java | 18 +++- 10 files changed, 227 insertions(+), 46 deletions(-) create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/ping.java create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/report.java create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/Report.java diff --git a/pom.xml b/pom.xml index 995e5be..9c4ac8b 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,8 @@ pom - zander-proxy + zander-waterfall + zander-velocity zander-hub zander-auth diff --git a/zander-velocity/dependency-reduced-pom.xml b/zander-velocity/dependency-reduced-pom.xml index 1325afd..cc5bbad 100644 --- a/zander-velocity/dependency-reduced-pom.xml +++ b/zander-velocity/dependency-reduced-pom.xml @@ -69,7 +69,7 @@ com.velocitypowered velocity-api - 3.3.0-SNAPSHOT + 3.4.0-SNAPSHOT provided diff --git a/zander-velocity/pom.xml b/zander-velocity/pom.xml index 5fadab8..1927eba 100644 --- a/zander-velocity/pom.xml +++ b/zander-velocity/pom.xml @@ -96,7 +96,7 @@ com.velocitypowered velocity-api - 3.3.0-SNAPSHOT + 3.4.0-SNAPSHOT provided @@ -119,7 +119,7 @@ com.jayway.jsonpath json-path - 2.8.0 + 2.9.0 com.google.code.gson diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java index 77f8908..912d584 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java @@ -16,9 +16,7 @@ import dev.dejvokep.boostedyaml.settings.loader.LoaderSettings; import dev.dejvokep.boostedyaml.settings.updater.UpdaterSettings; import lombok.Getter; -import org.modularsoft.zander.velocity.commands.discord; -import org.modularsoft.zander.velocity.commands.rules; -import org.modularsoft.zander.velocity.commands.website; +import org.modularsoft.zander.velocity.commands.*; import org.modularsoft.zander.velocity.events.*; import org.modularsoft.zander.velocity.util.announcement.TipChatter; import org.modularsoft.zander.velocity.util.api.Heartbeat; @@ -44,7 +42,7 @@ public class ZanderVelocityMain { @Getter private static Logger logger; @Getter - private static ProxyServer proxy; + public static ProxyServer proxy; @Getter private static YamlDocument config; @Getter @@ -54,12 +52,12 @@ public class ZanderVelocityMain { public void onProxyInitialization(ProxyInitializeEvent event) { // Event Listeners proxy.getEventManager().register(this, new UserChatEvent()); - proxy.getEventManager().register(this, new UserCommandSpyEvent()); + proxy.getEventManager().register(this, new UserCommandSpyEvent()); // Issues proxy.getEventManager().register(this, new UserOnDisconnect()); proxy.getEventManager().register(this, new UserOnLogin()); proxy.getEventManager().register(this, new UserOnProxyPing()); proxy.getEventManager().register(this, new UserOnSwitch()); - proxy.getEventManager().register(this, new UserSocialSpyEvent()); + proxy.getEventManager().register(this, new UserSocialSpyEvent()); // Issues // Commands CommandManager commandManager = proxy.getCommandManager(); @@ -67,6 +65,8 @@ public void onProxyInitialization(ProxyInitializeEvent event) { commandManager.register("discord", new discord()); commandManager.register("rules", new rules()); commandManager.register("website", new website()); + commandManager.register("ping", new ping()); + commandManager.register("report", new report()); // Start the Heartbeat task Heartbeat.startHeartbeatTask(); diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/ping.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/ping.java new file mode 100644 index 0000000..d430543 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/ping.java @@ -0,0 +1,30 @@ +package org.modularsoft.zander.velocity.commands; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.SimpleCommand; +import com.velocitypowered.api.proxy.Player; +import lombok.NonNull; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; + +public class ping implements SimpleCommand { + + @Override + public void execute(@NonNull Invocation invocation) { + CommandSource source = invocation.source(); + + // Check if the source is a player + if (source instanceof Player) { + Player player = (Player) source; + long ping = player.getPing(); // getPing() returns a long + + // Send the ping message to the player + Component message = Component.text("Your ping is: ") + .append(Component.text(ping).color(NamedTextColor.GREEN)); + + player.sendMessage(message); + } else { + source.sendMessage(Component.text("This command can only be used by players.").color(NamedTextColor.RED)); + } + } +} \ No newline at end of file diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/report.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/report.java new file mode 100644 index 0000000..996f33d --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/report.java @@ -0,0 +1,99 @@ +package org.modularsoft.zander.velocity.commands; + +import com.jayway.jsonpath.JsonPath; +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.SimpleCommand; +import com.velocitypowered.api.proxy.Player; +import dev.dejvokep.boostedyaml.route.Route; +import io.github.ModularEnigma.Request; +import io.github.ModularEnigma.Response; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.modularsoft.zander.velocity.ZanderVelocityMain; +import org.modularsoft.zander.velocity.model.Report; + +import java.util.ArrayList; +import java.util.List; + +import static org.modularsoft.zander.velocity.ZanderVelocityMain.proxy; + +public class report implements SimpleCommand { + @Override + public void execute(Invocation invocation) { + CommandSource source = invocation.source(); + String[] args = invocation.arguments(); + String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); + String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + + if (source instanceof Player) { + Player player = (Player) source; + + if (args.length < 2) { + player.sendMessage(Component.text("Usage: /report ").color(NamedTextColor.RED)); + return; + } + + String reportedUsername = args[0]; + StringBuilder reasonBuilder = new StringBuilder(); + for (int i = 1; i < args.length; i++) { + reasonBuilder.append(args[i]).append(" "); + } + String reason = reasonBuilder.toString().trim(); + + try { + // Build the report object + Report report = Report.builder() + .reportPlatform("INGAME") + .reportedUser(reportedUsername) + .reporterUser(player.getUsername()) + .reportReason(reason) + .build(); + + // Create and send the request + Request reportReq = Request.builder() + .setURL(BaseAPIURL + "/report/create") + .setMethod(Request.Method.POST) + .addHeader("x-access-token", APIKey) + .setRequestBody(report.toString()) + .build(); + + // Get the response from the API + Response reportRes = reportReq.execute(); + String json = reportRes.getBody(); + Boolean success = JsonPath.read(json, "$.success"); + String message = JsonPath.read(json, "$.message"); + + if (success) { + player.sendMessage(Component.text(message).color(NamedTextColor.GREEN)); + } else { + player.sendMessage(Component.text(message).color(NamedTextColor.RED)); + } + + } catch (Exception e) { + player.sendMessage(Component.text("An error has occurred. Is the API down?").color(NamedTextColor.RED)); + System.out.println(e); + } + } else { + source.sendMessage(Component.text("Only players can use this command.").color(NamedTextColor.RED)); + } + } + + // Tab-completion method + @Override + public List suggest(Invocation invocation) { + CommandSource source = invocation.source(); + String[] args = invocation.arguments(); + List completions = new ArrayList<>(); + + if (args.length == 1 && source instanceof Player) { + // Autocomplete the username (first argument) + for (Player player : proxy.getAllPlayers()) { + if (player.getUsername().toLowerCase().startsWith(args[0].toLowerCase())) { + completions.add(player.getUsername()); + } + } + } + + return completions; + } +} \ No newline at end of file diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnSwitch.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnSwitch.java index 688e848..39eab8b 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnSwitch.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnSwitch.java @@ -11,10 +11,13 @@ import org.modularsoft.zander.velocity.ZanderVelocityMain; import org.modularsoft.zander.velocity.model.discord.DiscordSwitch; import org.modularsoft.zander.velocity.model.session.SessionSwitch; +import org.slf4j.Logger; import java.util.UUID; public class UserOnSwitch { + private static final Logger logger = ZanderVelocityMain.getLogger(); + @Subscribe public void onServerConnect(ServerConnectedEvent event) { Player player = event.getPlayer(); @@ -24,10 +27,10 @@ public void onServerConnect(ServerConnectedEvent event) { String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + logger.info("Player {} is switching to server {}", username, server); + + // Handle Session Switch API try { - // - // Switch Session API POST - // SessionSwitch switchSession = SessionSwitch.builder() .uuid(playerUUID) .server(server) @@ -37,21 +40,19 @@ public void onServerConnect(ServerConnectedEvent event) { .setURL(BaseAPIURL + "/session/switch") .setMethod(Request.Method.POST) .addHeader("x-access-token", APIKey) - .setRequestBody(switchSession.toString()) + .setRequestBody(switchSession.toString()) // Ensure this method works properly .build(); Response switchSessionRes = switchSessionReq.execute(); - ZanderVelocityMain.getLogger().info("Response (" + switchSessionRes.getStatusCode() + "): " + switchSessionRes.getBody()); + logger.info("Session Switch Response ({}): {}", switchSessionRes.getStatusCode(), switchSessionRes.getBody()); } catch (Exception e) { - Component builder = Component.text("An error has occurred. Is the API down?").color(NamedTextColor.RED); - player.disconnect(builder); - System.out.println(e); + logger.error("Error during Session Switch API request", e); + player.disconnect(Component.text("An error has occurred. Please try again later.").color(NamedTextColor.RED)); + return; // Exit if a session switch fails } + // Handle Discord Switch API try { - // - // Discord Switch API POST - // DiscordSwitch discordSwitch = DiscordSwitch.builder() .username(username) .server(server) @@ -61,15 +62,14 @@ public void onServerConnect(ServerConnectedEvent event) { .setURL(BaseAPIURL + "/discord/switch") .setMethod(Request.Method.POST) .addHeader("x-access-token", APIKey) - .setRequestBody(discordSwitch.toString()) + .setRequestBody(discordSwitch.toString()) // Ensure this method works properly .build(); Response discordSwitchRes = discordSwitchReq.execute(); - ZanderVelocityMain.getLogger().info("Response (" + discordSwitchRes.getStatusCode() + "): " + discordSwitchRes.getBody()); + logger.info("Discord Switch Response ({}): {}", discordSwitchRes.getStatusCode(), discordSwitchRes.getBody()); } catch (Exception e) { - Component builder = Component.text("An error has occurred. Is the API down?").color(NamedTextColor.RED); - player.disconnect(builder); - System.out.println(e); + logger.error("Error during Discord Switch API request", e); + player.sendMessage(Component.text("An error occurred, but you can still continue playing.").color(NamedTextColor.RED)); } } -} +} \ No newline at end of file diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserSocialSpyEvent.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserSocialSpyEvent.java index f0d0526..dbf5e93 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserSocialSpyEvent.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserSocialSpyEvent.java @@ -8,32 +8,48 @@ import io.github.ModularEnigma.Request; import io.github.ModularEnigma.Response; import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; import org.modularsoft.zander.velocity.ZanderVelocityMain; import org.modularsoft.zander.velocity.model.discord.spy.DiscordSocialSpy; +import org.slf4j.Logger; import java.util.Arrays; +import java.util.Optional; public class UserSocialSpyEvent { + private static final Logger logger = ZanderVelocityMain.getLogger(); + @Subscribe public void onUserChatEvent(PlayerChatEvent event) { Player player = event.getPlayer(); - String command = event.getMessage().substring(1); // Remove the leading slash + String message = event.getMessage(); + + // Check if the message is a direct message command + if (message.startsWith("/msg") || message.startsWith("/tell") || message.startsWith("/w") || + message.startsWith("/message") || message.startsWith("/r")) { + + // Split the command into parts and check for minimum required arguments + String[] messageParts = message.split(" "); + if (messageParts.length < 3) { + logger.warn("Invalid direct message format from player: {}", player.getUsername()); + return; // Invalid command format, return without processing + } - if (command.startsWith("msg") || command.startsWith("tell") || command.startsWith("w") || command.startsWith("message") || command.startsWith("r")) { - String[] messageParts = event.getMessage().split(" "); - String targetPlayer = messageParts[1]; - String directMessage = String.join(" ", Arrays.copyOfRange(messageParts, 2, messageParts.length)); + String targetPlayer = messageParts[1]; // The player who is being messaged + String directMessage = String.join(" ", Arrays.copyOfRange(messageParts, 2, messageParts.length)); // The actual message - // - // Social Spy API POST - // try { - if (player.getCurrentServer().isEmpty()){ - return; + // Ensure the player is connected to a server + Optional currentServerOpt = player.getCurrentServer(); + if (currentServerOpt.isEmpty()) { + logger.warn("Player {} is not connected to any server", player.getUsername()); + return; // Player is not connected to a server, return early } - ServerConnection currentServer = player.getCurrentServer().get(); + ServerConnection currentServer = currentServerOpt.get(); + + // Construct the social spy object DiscordSocialSpy socialSpy = DiscordSocialSpy.builder() .usernameFrom(player.getUsername()) .usernameTo(targetPlayer) @@ -41,22 +57,25 @@ public void onUserChatEvent(PlayerChatEvent event) { .server(currentServer.getServerInfo().getName()) .build(); + // Fetch API URL and key String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + // Send the social spy request to the API Request socialSpyReq = Request.builder() .setURL(BaseAPIURL + "/discord/spy/directMessage") .setMethod(Request.Method.POST) .addHeader("x-access-token", APIKey) - .setRequestBody(socialSpy.toString()) + .setRequestBody(socialSpy.toString()) // Ensure proper serialization to JSON .build(); Response socialSpyRes = socialSpyReq.execute(); - ZanderVelocityMain.getLogger().info("Response (" + socialSpyRes.getStatusCode() + "): " + socialSpyRes.getBody()); + logger.info("Social Spy Response ({}): {}", socialSpyRes.getStatusCode(), socialSpyRes.getBody()); + } catch (Exception e) { - player.disconnect(Component.text("An error has occurred. Is the API down?")); - System.out.println(e); + logger.error("Error occurred while handling social spy request", e); + player.sendMessage(Component.text("An error occurred, but you can continue playing.").color(NamedTextColor.RED)); } } } -} \ No newline at end of file +} diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/Report.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/Report.java new file mode 100644 index 0000000..8456f65 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/Report.java @@ -0,0 +1,20 @@ +package org.modularsoft.zander.velocity.model; + +import com.google.gson.Gson; +import lombok.Builder; +import lombok.Getter; + +@Builder +public class Report { + + @Getter String reportPlatform; + @Getter String reportedUser; + @Getter String reporterUser; + @Getter String reportReason; + + @Override + public String toString() { + return new Gson().toJson(this); + } + +} \ No newline at end of file diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/announcement/TipChatter.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/announcement/TipChatter.java index 2aaddb5..f744f50 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/announcement/TipChatter.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/announcement/TipChatter.java @@ -8,15 +8,22 @@ import net.kyori.adventure.text.event.ClickEvent; import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; import org.modularsoft.zander.velocity.ZanderVelocityMain; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; public class TipChatter { + + // Initialize the logger + private static final Logger logger = LoggerFactory.getLogger(TipChatter.class); + public static void startAnnouncementTipTask() { String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + String announcementTipPrefix = ZanderVelocityMain.getConfig().getString(Route.from("announcementTipPrefix")); // Create a ScheduledExecutorService with a single thread ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); @@ -37,21 +44,26 @@ public static void startAnnouncementTipTask() { String colourMessageFormat = JsonPath.read(json, "$.data[0].colourMessageFormat"); String link = JsonPath.read(json, "$.data[0].link"); + // Log the color message format and link + logger.info("Announcement Tip: {}", colourMessageFormat); + logger.info("Link: {}", link); + logger.info("JSON: {}", json); + // Broadcast the message to all online players ZanderVelocityMain.getProxy().getAllPlayers().forEach(player -> { // Send the message to each player char translate = '&'; - Component message = LegacyComponentSerializer.legacy(translate).deserialize(colourMessageFormat); + Component message = LegacyComponentSerializer.legacy(translate).deserialize(announcementTipPrefix + " " + colourMessageFormat); if (link != null && !link.isEmpty()) { // Set the click event only if link is true - message.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL,link)); + message.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, link)); } player.sendMessage(message); }); } catch (Exception e) { // Handle exceptions here - e.printStackTrace(); + logger.error("Announcement Tip Failed, will try again later.", e); System.out.println("Announcement Tip Failed, will try again in " + ZanderVelocityMain.getConfig().getString(Route.from("announcementTipInterval")) + " minutes."); } }, 0, ZanderVelocityMain.getConfig().getInt(Route.from("announcementTipInterval")), TimeUnit.MINUTES); From 75f3423f04b682ff3880bc45097d619053d97385 Mon Sep 17 00:00:00 2001 From: benrobson Date: Mon, 7 Oct 2024 20:59:50 +1100 Subject: [PATCH 12/17] Work on spy events and clickable announcements. --- .../zander/velocity/ZanderVelocityMain.java | 10 +++++----- .../zander/velocity/events/UserCommandSpyEvent.java | 4 +++- .../zander/velocity/events/UserSocialSpyEvent.java | 4 +++- .../zander/velocity/util/announcement/TipChatter.java | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java index 912d584..3aa0ad8 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java @@ -62,11 +62,11 @@ public void onProxyInitialization(ProxyInitializeEvent event) { // Commands CommandManager commandManager = proxy.getCommandManager(); - commandManager.register("discord", new discord()); - commandManager.register("rules", new rules()); - commandManager.register("website", new website()); - commandManager.register("ping", new ping()); - commandManager.register("report", new report()); + commandManager.register(commandManager.metaBuilder("discord").build(), new discord()); + commandManager.register(commandManager.metaBuilder("rules").build(), new rules()); + commandManager.register(commandManager.metaBuilder("website").build(), new website()); + commandManager.register(commandManager.metaBuilder("ping").build(), new ping()); + commandManager.register(commandManager.metaBuilder("report").build(), new report()); // Start the Heartbeat task Heartbeat.startHeartbeatTask(); diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserCommandSpyEvent.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserCommandSpyEvent.java index 975c2b4..2741d28 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserCommandSpyEvent.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserCommandSpyEvent.java @@ -14,12 +14,14 @@ public class UserCommandSpyEvent { @Subscribe - public void UserChatEvent(PlayerChatEvent event) { + public void onPlayerCommand(PlayerChatEvent event) { Player player = event.getPlayer(); String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); String command = event.getMessage().substring(1); // Remove the leading slash + ZanderVelocityMain.getLogger().info("Command: {}", command); + if (event.getMessage().startsWith("/")) { // Excludes specific commands from being logged in both spy events. if (command.startsWith("msg") || command.startsWith("tell") || command.startsWith("w") || command.startsWith("message") || command.startsWith("r")) { diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserSocialSpyEvent.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserSocialSpyEvent.java index dbf5e93..2815a49 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserSocialSpyEvent.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserSocialSpyEvent.java @@ -21,10 +21,12 @@ public class UserSocialSpyEvent { private static final Logger logger = ZanderVelocityMain.getLogger(); @Subscribe - public void onUserChatEvent(PlayerChatEvent event) { + public void onUserChatDMEvent(PlayerChatEvent event) { Player player = event.getPlayer(); String message = event.getMessage(); + ZanderVelocityMain.getLogger().info("Message: {}", message); + // Check if the message is a direct message command if (message.startsWith("/msg") || message.startsWith("/tell") || message.startsWith("/w") || message.startsWith("/message") || message.startsWith("/r")) { diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/announcement/TipChatter.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/announcement/TipChatter.java index f744f50..129fff7 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/announcement/TipChatter.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/announcement/TipChatter.java @@ -56,8 +56,8 @@ public static void startAnnouncementTipTask() { Component message = LegacyComponentSerializer.legacy(translate).deserialize(announcementTipPrefix + " " + colourMessageFormat); if (link != null && !link.isEmpty()) { - // Set the click event only if link is true - message.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, link)); + // Set the click event and reassign the modified message to the variable + message = message.clickEvent(ClickEvent.clickEvent(ClickEvent.Action.OPEN_URL, link)); } player.sendMessage(message); }); From 3ebbe013dbebd3ee4547aab66a4b5c2502ab59d6 Mon Sep 17 00:00:00 2001 From: benrobson Date: Sun, 10 Nov 2024 00:05:56 +1100 Subject: [PATCH 13/17] Implement bridge for Proxy. --- .../zander/velocity/ZanderVelocityMain.java | 4 + .../zander/velocity/model/BridgeProcess.java | 17 ++++ .../zander/velocity/util/api/Bridge.java | 98 +++++++++++++++++++ .../zander/velocity/util/api/Heartbeat.java | 2 - zander-velocity/src/main/resources/config.yml | 1 + 5 files changed, 120 insertions(+), 2 deletions(-) create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/BridgeProcess.java create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Bridge.java diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java index 3aa0ad8..b6dc962 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java @@ -19,6 +19,7 @@ import org.modularsoft.zander.velocity.commands.*; import org.modularsoft.zander.velocity.events.*; import org.modularsoft.zander.velocity.util.announcement.TipChatter; +import org.modularsoft.zander.velocity.util.api.Bridge; import org.modularsoft.zander.velocity.util.api.Heartbeat; import org.slf4j.Logger; @@ -73,6 +74,9 @@ public void onProxyInitialization(ProxyInitializeEvent event) { // Start the Announcement Tip task TipChatter.startAnnouncementTipTask(); + + // Start the Bridge task + Bridge.startBridgeTask(); } @Inject diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/BridgeProcess.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/BridgeProcess.java new file mode 100644 index 0000000..20010a4 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/BridgeProcess.java @@ -0,0 +1,17 @@ +package org.modularsoft.zander.velocity.model; + +import com.google.gson.Gson; +import lombok.Builder; +import lombok.Getter; + +@Builder +public class BridgeProcess { + + @Getter Integer bridgeId; + + @Override + public String toString() { + return new Gson().toJson(this); + } + +} diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Bridge.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Bridge.java new file mode 100644 index 0000000..b5c38ba --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Bridge.java @@ -0,0 +1,98 @@ +package org.modularsoft.zander.velocity.util.api; + +import com.jayway.jsonpath.JsonPath; +import dev.dejvokep.boostedyaml.route.Route; +import io.github.ModularEnigma.Request; +import io.github.ModularEnigma.Response; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import org.modularsoft.zander.velocity.ZanderVelocityMain; +import org.modularsoft.zander.velocity.model.BridgeProcess; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.CompletableFuture; + +public class Bridge { + // Initialize the logger + private static final Logger logger = LoggerFactory.getLogger(Bridge.class); + + public static void startBridgeTask() { + String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); + String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + String TargetServerName = ZanderVelocityMain.getConfig().getString(Route.from("TargetServerName")); + + // Create a ScheduledExecutorService with a single thread + ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + + // Schedule the task to run every 60 seconds + scheduler.scheduleAtFixedRate(() -> { + try { + Request req = Request.builder() + .setURL(BaseAPIURL + "/bridge/get?targetServer=" + TargetServerName) + .setMethod(Request.Method.GET) + .addHeader("x-access-token", APIKey) + .build(); + + Response res = req.execute(); + String json = res.getBody(); + + // Extract the list of data objects + List dataList = JsonPath.read(json, "$.data"); + + // Loop through each entry in the data list + for (Object dataEntry : dataList) { + int bridgeId = JsonPath.read(dataEntry, "$.bridgeId"); + String command = JsonPath.read(dataEntry, "$.command"); + + // Execute the command asynchronously + CompletableFuture future = ZanderVelocityMain.getProxy() + .getCommandManager() + .executeImmediatelyAsync(ZanderVelocityMain.getProxy().getConsoleCommandSource(), command); + + // Handle the result when the execution completes + future.thenAccept(executedSuccessfully -> { + if (executedSuccessfully) { + logger.info("Command executed successfully: {}", command); + + // Mark the command as processed + try { + BridgeProcess bridgeProcess = BridgeProcess.builder() + .bridgeId(bridgeId) + .build(); + + Request bridgeProcessReq = Request.builder() + .setURL(BaseAPIURL + "/bridge/command/process") + .setMethod(Request.Method.POST) + .addHeader("x-access-token", APIKey) + .setRequestBody(bridgeProcess.toString()) + .build(); + + Response bridgeProcessRes = bridgeProcessReq.execute(); + ZanderVelocityMain.getLogger().info("Response (" + bridgeProcessRes.getStatusCode() + "): " + bridgeProcessRes.getBody()); + } catch (Exception e) { + e.printStackTrace(); + ZanderVelocityMain.getLogger().error("Failed to process command: {}", bridgeId); + } + } else { + logger.warn("Command execution failed: {}", command); + } + }).exceptionally(ex -> { + // Handle exceptions during command execution + logger.error("Command execution encountered an error: {}", command, ex); + return null; + }); + } + + } catch (Exception e) { + // Handle exceptions here + e.printStackTrace(); + ZanderVelocityMain.getLogger().error("Fetching Bridge actions Failed."); + } + }, 0, 60, TimeUnit.SECONDS); + } +} \ No newline at end of file diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Heartbeat.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Heartbeat.java index ccc1bf8..566ff65 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Heartbeat.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Heartbeat.java @@ -23,8 +23,6 @@ public static void startHeartbeatTask() { // Schedule the task to run every 60 seconds scheduler.scheduleAtFixedRate(() -> { try { - // Your existing code here - // GET request to link to rules. Request req = Request.builder() .setURL(BaseAPIURL + "/heartbeat") .setMethod(Request.Method.GET) diff --git a/zander-velocity/src/main/resources/config.yml b/zander-velocity/src/main/resources/config.yml index d993184..3ac561f 100644 --- a/zander-velocity/src/main/resources/config.yml +++ b/zander-velocity/src/main/resources/config.yml @@ -2,6 +2,7 @@ config-version: 1 BaseAPIURL: "http://localhost:8080/api" APIKey: "KEY" +TargetServerName: "proxy" announcementMOTDTopLine: "&e&lMy &2&nMinecraft&r &6&oServer" announcementTipPrefix: "&7&l[&6&lTIP&7&l]&r " From c31376b60b9f7398a75cd706b536723fc983f98e Mon Sep 17 00:00:00 2001 From: benrobson Date: Tue, 12 Nov 2024 00:12:35 +1100 Subject: [PATCH 14/17] Implement bridge for Paper. --- pom.xml | 1 + zander-bridge/pom.xml | 67 ++++++++++++ .../zander/bridge/ZanderBridgeMain.java | 34 ++++++ .../zander/bridge/model/BridgeProcess.java | 17 +++ .../zander/bridge/util/api/Bridge.java | 103 ++++++++++++++++++ zander-bridge/src/main/resources/config.yml | 3 + zander-bridge/src/main/resources/plugin.yml | 5 + .../zander/velocity/util/api/Bridge.java | 6 + 8 files changed, 236 insertions(+) create mode 100644 zander-bridge/pom.xml create mode 100644 zander-bridge/src/main/java/org/modularsoft/zander/bridge/ZanderBridgeMain.java create mode 100644 zander-bridge/src/main/java/org/modularsoft/zander/bridge/model/BridgeProcess.java create mode 100644 zander-bridge/src/main/java/org/modularsoft/zander/bridge/util/api/Bridge.java create mode 100644 zander-bridge/src/main/resources/config.yml create mode 100644 zander-bridge/src/main/resources/plugin.yml diff --git a/pom.xml b/pom.xml index 9c4ac8b..721c5b8 100644 --- a/pom.xml +++ b/pom.xml @@ -14,6 +14,7 @@ zander-velocity zander-hub zander-auth + zander-bridge diff --git a/zander-bridge/pom.xml b/zander-bridge/pom.xml new file mode 100644 index 0000000..a414fd4 --- /dev/null +++ b/zander-bridge/pom.xml @@ -0,0 +1,67 @@ + + + + zander + org.modularsoft + 1.0 + + 4.0.0 + + zander-bridge + 1.0 + + + + + papermc + https://papermc.io/repo/repository/maven-public/ + + + + + + + io.papermc.paper + paper-api + 1.20.2-R0.1-SNAPSHOT + provided + + + com.googlecode.json-simple + json-simple + 1.1.1 + compile + + + org.projectlombok + lombok + 1.18.22 + compile + + + io.github.ModularEnigma + Requests + 1.0.3 + + + com.jayway.jsonpath + json-path + 2.8.0 + + + com.google.code.gson + gson + 2.8.9 + compile + + + org.slf4j + slf4j-api + 2.0.12 + compile + + + + \ No newline at end of file diff --git a/zander-bridge/src/main/java/org/modularsoft/zander/bridge/ZanderBridgeMain.java b/zander-bridge/src/main/java/org/modularsoft/zander/bridge/ZanderBridgeMain.java new file mode 100644 index 0000000..daf37e1 --- /dev/null +++ b/zander-bridge/src/main/java/org/modularsoft/zander/bridge/ZanderBridgeMain.java @@ -0,0 +1,34 @@ +package org.modularsoft.zander.bridge; + +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.TextComponent; +import net.kyori.adventure.text.format.NamedTextColor; +import org.bukkit.plugin.java.JavaPlugin; +import org.modularsoft.zander.bridge.util.api.Bridge; + +public class ZanderBridgeMain extends JavaPlugin { + public static ZanderBridgeMain plugin; + + @Override + public void onEnable() { + plugin = this; + + // Init Message + TextComponent enabledMessage = Component.empty() + .color(NamedTextColor.GREEN) + .append(Component.text("\n\nZander Bridge has been enabled.\n")) + .append(Component.text("Running Version " + plugin.getDescription().getVersion() + "\n")) + .append(Component.text("GitHub Repository: https://github.com/ModularSoftAU/zander\n")) + .append(Component.text("Created by Modular Software\n\n", NamedTextColor.DARK_PURPLE)); + getServer().sendMessage(enabledMessage); + + // Create an instance of Bridge and start the task + Bridge bridge = new Bridge(this); + bridge.startBridgeTask(); + + saveConfig(); + } + + @Override + public void onDisable() {} +} \ No newline at end of file diff --git a/zander-bridge/src/main/java/org/modularsoft/zander/bridge/model/BridgeProcess.java b/zander-bridge/src/main/java/org/modularsoft/zander/bridge/model/BridgeProcess.java new file mode 100644 index 0000000..fb91bfe --- /dev/null +++ b/zander-bridge/src/main/java/org/modularsoft/zander/bridge/model/BridgeProcess.java @@ -0,0 +1,17 @@ +package org.modularsoft.zander.bridge.model; + +import com.google.gson.Gson; +import lombok.Builder; +import lombok.Getter; + +@Builder +public class BridgeProcess { + + @Getter Integer bridgeId; + + @Override + public String toString() { + return new Gson().toJson(this); + } + +} diff --git a/zander-bridge/src/main/java/org/modularsoft/zander/bridge/util/api/Bridge.java b/zander-bridge/src/main/java/org/modularsoft/zander/bridge/util/api/Bridge.java new file mode 100644 index 0000000..f61b4b9 --- /dev/null +++ b/zander-bridge/src/main/java/org/modularsoft/zander/bridge/util/api/Bridge.java @@ -0,0 +1,103 @@ +package org.modularsoft.zander.bridge.util.api; + +import com.jayway.jsonpath.JsonPath; +import io.github.ModularEnigma.Request; +import io.github.ModularEnigma.Response; +import org.bukkit.Bukkit; +import org.bukkit.command.ConsoleCommandSender; +import org.modularsoft.zander.bridge.ZanderBridgeMain; +import org.modularsoft.zander.bridge.model.BridgeProcess; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; + +public class Bridge { + // Initialize the logger + private static final Logger logger = LoggerFactory.getLogger(Bridge.class); + + private final ZanderBridgeMain plugin; + + // Constructor to get the instance of the plugin + public Bridge(ZanderBridgeMain plugin) { + this.plugin = plugin; + } + + public void startBridgeTask() { + String BaseAPIURL = plugin.getConfig().getString("BaseAPIURL"); + String APIKey = plugin.getConfig().getString("APIKey"); + String TargetServerName = plugin.getConfig().getString("TargetServerName"); + + // Create a ScheduledExecutorService with a single thread + ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + + // Schedule the task to run every 60 seconds + scheduler.scheduleAtFixedRate(() -> { + try { + Request req = Request.builder() + .setURL(BaseAPIURL + "/bridge/get?targetServer=" + TargetServerName) + .setMethod(Request.Method.GET) + .addHeader("x-access-token", APIKey) + .build(); + + Response res = req.execute(); + String json = res.getBody(); + + // Extract the list of data objects + List dataList = JsonPath.read(json, "$.data"); + + // Check if dataList is null or empty + if (dataList == null || dataList.isEmpty()) { + logger.info("No actions found for the bridge."); + return; // Exit the method early if there are no actions + } + + // Loop through each entry in the data list + for (Object dataEntry : dataList) { + int bridgeId = JsonPath.read(dataEntry, "$.bridgeId"); + String command = JsonPath.read(dataEntry, "$.command"); + + // Execute the command asynchronously on the main server thread + Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); + boolean executedSuccessfully = Bukkit.getServer().dispatchCommand(console, command); + + if (executedSuccessfully) { + logger.info("Command executed successfully: {}", command); + + // Mark the command as processed + try { + BridgeProcess bridgeProcess = BridgeProcess.builder() + .bridgeId(bridgeId) + .build(); + + Request bridgeProcessReq = Request.builder() + .setURL(BaseAPIURL + "/bridge/command/process") + .setMethod(Request.Method.POST) + .addHeader("x-access-token", APIKey) + .setRequestBody(bridgeProcess.toString()) + .build(); + + Response bridgeProcessRes = bridgeProcessReq.execute(); + logger.info("Response (" + bridgeProcessRes.getStatusCode() + "): " + bridgeProcessRes.getBody()); + } catch (Exception e) { + e.printStackTrace(); + logger.error("Failed to process command: {}", bridgeId); + } + } else { + logger.warn("Command execution failed: {}", command); + } + }); + } + + } catch (Exception e) { + // Handle exceptions here + e.printStackTrace(); + logger.error("Fetching Bridge actions Failed."); + } + }, 0, 60, TimeUnit.SECONDS); + } +} diff --git a/zander-bridge/src/main/resources/config.yml b/zander-bridge/src/main/resources/config.yml new file mode 100644 index 0000000..f788a9a --- /dev/null +++ b/zander-bridge/src/main/resources/config.yml @@ -0,0 +1,3 @@ +BaseAPIURL: "http://localhost:8080/api" +APIKey: "KEY" +TargetServerName: "server" \ No newline at end of file diff --git a/zander-bridge/src/main/resources/plugin.yml b/zander-bridge/src/main/resources/plugin.yml new file mode 100644 index 0000000..7918f4a --- /dev/null +++ b/zander-bridge/src/main/resources/plugin.yml @@ -0,0 +1,5 @@ +main: org.modularsoft.zander.bridge.ZanderBridgeMain +name: zander-bridge +version: ${project.version} +author: ModularSoft +api-version: 1.19 \ No newline at end of file diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Bridge.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Bridge.java index b5c38ba..a1a444e 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Bridge.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Bridge.java @@ -44,6 +44,12 @@ public static void startBridgeTask() { // Extract the list of data objects List dataList = JsonPath.read(json, "$.data"); + // Check if dataList is null or empty + if (dataList == null || dataList.isEmpty()) { + logger.info("No actions found for the bridge."); + return; // Exit the method early if there are no actions + } + // Loop through each entry in the data list for (Object dataEntry : dataList) { int bridgeId = JsonPath.read(dataEntry, "$.bridgeId"); From 4e129a2c925ff78d9f4ad1afcd71790cbb529b25 Mon Sep 17 00:00:00 2001 From: Ben Robson Date: Sat, 16 Nov 2024 20:07:14 +1100 Subject: [PATCH 15/17] Add a Velocity /alert command and port bridge fixes (#21) * Fix scheduler on main thread for paper bridge, add /alert command on Velocity * Fix plugin configuration generation on paper bridge. --- .../zander/bridge/ZanderBridgeMain.java | 2 +- .../zander/bridge/util/api/Bridge.java | 6 +- .../zander/velocity/ZanderVelocityMain.java | 5 +- .../zander/velocity/commands/alert.java | 44 +++++++++++ .../velocity/events/UserCommandSpyEvent.java | 73 ++++++++++--------- .../velocity/events/UserSocialSpyEvent.java | 29 +++++--- zander-velocity/src/main/resources/config.yml | 5 +- 7 files changed, 109 insertions(+), 55 deletions(-) create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/alert.java diff --git a/zander-bridge/src/main/java/org/modularsoft/zander/bridge/ZanderBridgeMain.java b/zander-bridge/src/main/java/org/modularsoft/zander/bridge/ZanderBridgeMain.java index daf37e1..ce9e8d0 100644 --- a/zander-bridge/src/main/java/org/modularsoft/zander/bridge/ZanderBridgeMain.java +++ b/zander-bridge/src/main/java/org/modularsoft/zander/bridge/ZanderBridgeMain.java @@ -26,7 +26,7 @@ public void onEnable() { Bridge bridge = new Bridge(this); bridge.startBridgeTask(); - saveConfig(); + saveDefaultConfig(); } @Override diff --git a/zander-bridge/src/main/java/org/modularsoft/zander/bridge/util/api/Bridge.java b/zander-bridge/src/main/java/org/modularsoft/zander/bridge/util/api/Bridge.java index f61b4b9..7ec4fef 100644 --- a/zander-bridge/src/main/java/org/modularsoft/zander/bridge/util/api/Bridge.java +++ b/zander-bridge/src/main/java/org/modularsoft/zander/bridge/util/api/Bridge.java @@ -60,8 +60,8 @@ public void startBridgeTask() { int bridgeId = JsonPath.read(dataEntry, "$.bridgeId"); String command = JsonPath.read(dataEntry, "$.command"); - // Execute the command asynchronously on the main server thread - Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> { + // Execute the command synchronously on the main server thread + Bukkit.getScheduler().runTask(plugin, () -> { ConsoleCommandSender console = Bukkit.getServer().getConsoleSender(); boolean executedSuccessfully = Bukkit.getServer().dispatchCommand(console, command); @@ -100,4 +100,4 @@ public void startBridgeTask() { } }, 0, 60, TimeUnit.SECONDS); } -} +} \ No newline at end of file diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java index b6dc962..4bf728d 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java @@ -53,12 +53,12 @@ public class ZanderVelocityMain { public void onProxyInitialization(ProxyInitializeEvent event) { // Event Listeners proxy.getEventManager().register(this, new UserChatEvent()); - proxy.getEventManager().register(this, new UserCommandSpyEvent()); // Issues + proxy.getEventManager().register(this, new UserCommandSpyEvent()); proxy.getEventManager().register(this, new UserOnDisconnect()); proxy.getEventManager().register(this, new UserOnLogin()); proxy.getEventManager().register(this, new UserOnProxyPing()); proxy.getEventManager().register(this, new UserOnSwitch()); - proxy.getEventManager().register(this, new UserSocialSpyEvent()); // Issues + proxy.getEventManager().register(this, new UserSocialSpyEvent()); // Commands CommandManager commandManager = proxy.getCommandManager(); @@ -68,6 +68,7 @@ public void onProxyInitialization(ProxyInitializeEvent event) { commandManager.register(commandManager.metaBuilder("website").build(), new website()); commandManager.register(commandManager.metaBuilder("ping").build(), new ping()); commandManager.register(commandManager.metaBuilder("report").build(), new report()); + commandManager.register(commandManager.metaBuilder("alert").build(), new alert()); // Start the Heartbeat task Heartbeat.startHeartbeatTask(); diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/alert.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/alert.java new file mode 100644 index 0000000..513c5e5 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/alert.java @@ -0,0 +1,44 @@ +package org.modularsoft.zander.velocity.commands; + +import com.velocitypowered.api.command.CommandSource; +import com.velocitypowered.api.command.SimpleCommand; +import net.kyori.adventure.text.Component; +import net.kyori.adventure.text.format.NamedTextColor; +import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer; +import org.modularsoft.zander.velocity.ZanderVelocityMain; +import dev.dejvokep.boostedyaml.route.Route; + +public class alert implements SimpleCommand { + + @Override + public void execute(final Invocation invocation) { + CommandSource source = invocation.source(); + + // Check if the command source has the required permission + if (!source.hasPermission("zander.proxy.command.alert")) { + source.sendMessage(Component.text("You do not have permission to use this command.") + .color(NamedTextColor.RED)); + return; + } + + // Retrieve the announcement tip prefix from the configuration + String alertCommandPrefix = ZanderVelocityMain.getConfig().getString(Route.from("alertCommandPrefix")); + + // Construct the alert message from command arguments + String[] args = invocation.arguments(); + if (args.length == 0) { + source.sendMessage(Component.text("Usage: /alert ").color(NamedTextColor.RED)); + return; + } + + String alertMessage = String.join(" ", args); + + // Use the LegacyComponentSerializer to handle color codes and prefix + char translate = '&'; + Component message = LegacyComponentSerializer.legacy(translate) + .deserialize(alertCommandPrefix + " " + alertMessage); + + // Broadcast the alert message + ZanderVelocityMain.getProxy().sendMessage(message); + } +} diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserCommandSpyEvent.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserCommandSpyEvent.java index 2741d28..6f02042 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserCommandSpyEvent.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserCommandSpyEvent.java @@ -1,7 +1,7 @@ package org.modularsoft.zander.velocity.events; import com.velocitypowered.api.event.Subscribe; -import com.velocitypowered.api.event.player.PlayerChatEvent; +import com.velocitypowered.api.event.command.CommandExecuteEvent; import com.velocitypowered.api.proxy.Player; import dev.dejvokep.boostedyaml.route.Route; import io.github.ModularEnigma.Request; @@ -14,45 +14,48 @@ public class UserCommandSpyEvent { @Subscribe - public void onPlayerCommand(PlayerChatEvent event) { - Player player = event.getPlayer(); + public void onPlayerCommand(CommandExecuteEvent event) { + // Ensure the command source is a player + if (!(event.getCommandSource() instanceof Player)) { + return; + } + + Player player = (Player) event.getCommandSource(); String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); - String command = event.getMessage().substring(1); // Remove the leading slash + String command = event.getCommand(); // Get the full command ZanderVelocityMain.getLogger().info("Command: {}", command); - if (event.getMessage().startsWith("/")) { - // Excludes specific commands from being logged in both spy events. - if (command.startsWith("msg") || command.startsWith("tell") || command.startsWith("w") || command.startsWith("message") || command.startsWith("r")) { - return; - } - - // - // Command Spy API POST - // - try { - DiscordCommandSpy commandSpy = DiscordCommandSpy.builder() - .username(player.getUsername()) - .command(command) - .server(player.getCurrentServer().get().getServer().getServerInfo().getName()) - .build(); - - Request commandSpyReq = Request.builder() - .setURL(BaseAPIURL + "/discord/spy/command") - .setMethod(Request.Method.POST) - .addHeader("x-access-token", String.valueOf(APIKey)) - .setRequestBody(commandSpy.toString()) - .build(); - - Response commandSpyRes = commandSpyReq.execute(); - ZanderVelocityMain.getLogger().info("Response (" + commandSpyRes.getStatusCode() + "): " + commandSpyRes.getBody()); - } catch (Exception e) { - Component builder = Component.text("An error has occurred. Is the API down?").color(NamedTextColor.RED); - player.disconnect(builder); - System.out.println(e); - } + // Check if the command is one we need to log (ignore direct message commands) + if (command.startsWith("msg") || command.startsWith("tell") || command.startsWith("w") + || command.startsWith("message") || command.startsWith("r")) { + return; } - } + // + // Command Spy API POST + // + try { + DiscordCommandSpy commandSpy = DiscordCommandSpy.builder() + .username(player.getUsername()) + .command(command) + .server(player.getCurrentServer().get().getServer().getServerInfo().getName()) + .build(); + + Request commandSpyReq = Request.builder() + .setURL(BaseAPIURL + "/discord/spy/command") + .setMethod(Request.Method.POST) + .addHeader("x-access-token", String.valueOf(APIKey)) + .setRequestBody(commandSpy.toString()) + .build(); + + Response commandSpyRes = commandSpyReq.execute(); + ZanderVelocityMain.getLogger().info("Response (" + commandSpyRes.getStatusCode() + "): " + commandSpyRes.getBody()); + } catch (Exception e) { + Component builder = Component.text("An error has occurred. Is the API down?").color(NamedTextColor.RED); + player.disconnect(builder); + System.out.println(e); + } + } } diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserSocialSpyEvent.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserSocialSpyEvent.java index 2815a49..15d9be9 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserSocialSpyEvent.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserSocialSpyEvent.java @@ -1,7 +1,7 @@ package org.modularsoft.zander.velocity.events; import com.velocitypowered.api.event.Subscribe; -import com.velocitypowered.api.event.player.PlayerChatEvent; +import com.velocitypowered.api.event.command.CommandExecuteEvent; import com.velocitypowered.api.proxy.Player; import com.velocitypowered.api.proxy.ServerConnection; import dev.dejvokep.boostedyaml.route.Route; @@ -21,25 +21,30 @@ public class UserSocialSpyEvent { private static final Logger logger = ZanderVelocityMain.getLogger(); @Subscribe - public void onUserChatDMEvent(PlayerChatEvent event) { - Player player = event.getPlayer(); - String message = event.getMessage(); + public void onUserChatDMEvent(CommandExecuteEvent event) { + // Ensure the command source is a player + if (!(event.getCommandSource() instanceof Player)) { + return; + } + + Player player = (Player) event.getCommandSource(); + String command = event.getCommand(); - ZanderVelocityMain.getLogger().info("Message: {}", message); + ZanderVelocityMain.getLogger().info("Command: {}", command); - // Check if the message is a direct message command - if (message.startsWith("/msg") || message.startsWith("/tell") || message.startsWith("/w") || - message.startsWith("/message") || message.startsWith("/r")) { + // Check if the command is a direct message command + if (command.contains("msg") || command.contains("tell") || command.contains("w") + || command.contains("message") || command.contains("r")) { // Split the command into parts and check for minimum required arguments - String[] messageParts = message.split(" "); - if (messageParts.length < 3) { + String[] commandParts = command.split(" "); + if (commandParts.length < 3) { logger.warn("Invalid direct message format from player: {}", player.getUsername()); return; // Invalid command format, return without processing } - String targetPlayer = messageParts[1]; // The player who is being messaged - String directMessage = String.join(" ", Arrays.copyOfRange(messageParts, 2, messageParts.length)); // The actual message + String targetPlayer = commandParts[1]; // The player who is being messaged + String directMessage = String.join(" ", Arrays.copyOfRange(commandParts, 2, commandParts.length)); // The actual message try { // Ensure the player is connected to a server diff --git a/zander-velocity/src/main/resources/config.yml b/zander-velocity/src/main/resources/config.yml index 3ac561f..bf8c2bd 100644 --- a/zander-velocity/src/main/resources/config.yml +++ b/zander-velocity/src/main/resources/config.yml @@ -1,4 +1,4 @@ -config-version: 1 +config-version: 2 BaseAPIURL: "http://localhost:8080/api" APIKey: "KEY" @@ -6,4 +6,5 @@ TargetServerName: "proxy" announcementMOTDTopLine: "&e&lMy &2&nMinecraft&r &6&oServer" announcementTipPrefix: "&7&l[&6&lTIP&7&l]&r " -announcementTipInterval: 10 \ No newline at end of file +announcementTipInterval: 10 +alertCommandPrefix: "&7&l[&6&lALERT&7&l]&r " \ No newline at end of file From 796133631c3e3851ca51a5f0198f6975415b2964 Mon Sep 17 00:00:00 2001 From: benrobson Date: Sun, 17 Nov 2024 07:29:23 +1100 Subject: [PATCH 16/17] Bump version and add ServerSync to bridge. --- zander-auth/pom.xml | 4 +- zander-bridge/pom.xml | 2 +- zander-hub/pom.xml | 2 +- zander-velocity/dependency-reduced-pom.xml | 2 +- zander-velocity/pom.xml | 2 +- .../zander/velocity/ZanderVelocityMain.java | 12 +- .../zander/velocity/commands/alert.java | 2 +- .../BridgeCommandProcessor.java} | 4 +- .../model/bridge/BridgeServerSync.java | 20 ++++ .../CommandProcessor.java} | 24 ++-- .../velocity/util/api/bridge/ServerSync.java | 108 ++++++++++++++++++ zander-waterfall/dependency-reduced-pom.xml | 2 +- zander-waterfall/pom.xml | 2 +- 13 files changed, 159 insertions(+), 27 deletions(-) rename zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/{BridgeProcess.java => bridge/BridgeCommandProcessor.java} (69%) create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/bridge/BridgeServerSync.java rename zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/{Bridge.java => bridge/CommandProcessor.java} (83%) create mode 100644 zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/bridge/ServerSync.java diff --git a/zander-auth/pom.xml b/zander-auth/pom.xml index ca571ee..b6dd137 100644 --- a/zander-auth/pom.xml +++ b/zander-auth/pom.xml @@ -10,7 +10,7 @@ 4.0.0 zander-auth - 1.0 + 1.3.0 @@ -48,7 +48,7 @@ com.jayway.jsonpath json-path - 2.8.0 + [2.9.0,) com.google.code.gson diff --git a/zander-bridge/pom.xml b/zander-bridge/pom.xml index a414fd4..62717f5 100644 --- a/zander-bridge/pom.xml +++ b/zander-bridge/pom.xml @@ -10,7 +10,7 @@ 4.0.0 zander-bridge - 1.0 + 1.3.0 diff --git a/zander-hub/pom.xml b/zander-hub/pom.xml index 10b1c99..71a3a85 100644 --- a/zander-hub/pom.xml +++ b/zander-hub/pom.xml @@ -10,7 +10,7 @@ 4.0.0 zander-hub - 1.0 + 1.3.0 diff --git a/zander-velocity/dependency-reduced-pom.xml b/zander-velocity/dependency-reduced-pom.xml index cc5bbad..bcbab2f 100644 --- a/zander-velocity/dependency-reduced-pom.xml +++ b/zander-velocity/dependency-reduced-pom.xml @@ -4,7 +4,7 @@ org.modularsoft zander-velocity zander-velocity - 1.2.0 + 1.3.0 diff --git a/zander-velocity/pom.xml b/zander-velocity/pom.xml index 1927eba..31a6d4b 100644 --- a/zander-velocity/pom.xml +++ b/zander-velocity/pom.xml @@ -6,7 +6,7 @@ org.modularsoft zander-velocity - 1.2.0 + 1.3.0 jar zander-velocity diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java index 4bf728d..79feb4f 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java @@ -19,8 +19,9 @@ import org.modularsoft.zander.velocity.commands.*; import org.modularsoft.zander.velocity.events.*; import org.modularsoft.zander.velocity.util.announcement.TipChatter; -import org.modularsoft.zander.velocity.util.api.Bridge; +import org.modularsoft.zander.velocity.util.api.bridge.CommandProcessor; import org.modularsoft.zander.velocity.util.api.Heartbeat; +import org.modularsoft.zander.velocity.util.api.bridge.ServerSync; import org.slf4j.Logger; import java.io.File; @@ -70,14 +71,11 @@ public void onProxyInitialization(ProxyInitializeEvent event) { commandManager.register(commandManager.metaBuilder("report").build(), new report()); commandManager.register(commandManager.metaBuilder("alert").build(), new alert()); - // Start the Heartbeat task + // Start tasks Heartbeat.startHeartbeatTask(); - - // Start the Announcement Tip task TipChatter.startAnnouncementTipTask(); - - // Start the Bridge task - Bridge.startBridgeTask(); + CommandProcessor.startBridgeTask(); + ServerSync.startServerSyncTask(); } @Inject diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/alert.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/alert.java index 513c5e5..dcaa7a9 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/alert.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/alert.java @@ -36,7 +36,7 @@ public void execute(final Invocation invocation) { // Use the LegacyComponentSerializer to handle color codes and prefix char translate = '&'; Component message = LegacyComponentSerializer.legacy(translate) - .deserialize(alertCommandPrefix + " " + alertMessage); + .deserialize(alertCommandPrefix + alertMessage); // Broadcast the alert message ZanderVelocityMain.getProxy().sendMessage(message); diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/BridgeProcess.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/bridge/BridgeCommandProcessor.java similarity index 69% rename from zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/BridgeProcess.java rename to zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/bridge/BridgeCommandProcessor.java index 20010a4..809dba2 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/BridgeProcess.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/bridge/BridgeCommandProcessor.java @@ -1,11 +1,11 @@ -package org.modularsoft.zander.velocity.model; +package org.modularsoft.zander.velocity.model.bridge; import com.google.gson.Gson; import lombok.Builder; import lombok.Getter; @Builder -public class BridgeProcess { +public class BridgeCommandProcessor { @Getter Integer bridgeId; diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/bridge/BridgeServerSync.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/bridge/BridgeServerSync.java new file mode 100644 index 0000000..830b2a0 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/bridge/BridgeServerSync.java @@ -0,0 +1,20 @@ +package org.modularsoft.zander.velocity.model.bridge; + +import com.google.gson.Gson; +import lombok.Builder; +import lombok.Getter; + +import java.util.UUID; + +@Builder +public class BridgeServerSync { + + @Getter Object serverInfo; + @Getter String lastUpdated; + + @Override + public String toString() { + return new Gson().toJson(this); + } + +} diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Bridge.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/bridge/CommandProcessor.java similarity index 83% rename from zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Bridge.java rename to zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/bridge/CommandProcessor.java index a1a444e..0675ee4 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Bridge.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/bridge/CommandProcessor.java @@ -1,13 +1,11 @@ -package org.modularsoft.zander.velocity.util.api; +package org.modularsoft.zander.velocity.util.api.bridge; import com.jayway.jsonpath.JsonPath; import dev.dejvokep.boostedyaml.route.Route; import io.github.ModularEnigma.Request; import io.github.ModularEnigma.Response; -import net.kyori.adventure.text.Component; -import net.kyori.adventure.text.format.NamedTextColor; import org.modularsoft.zander.velocity.ZanderVelocityMain; -import org.modularsoft.zander.velocity.model.BridgeProcess; +import org.modularsoft.zander.velocity.model.bridge.BridgeCommandProcessor; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -17,9 +15,9 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.CompletableFuture; -public class Bridge { +public class CommandProcessor { // Initialize the logger - private static final Logger logger = LoggerFactory.getLogger(Bridge.class); + private static final Logger logger = LoggerFactory.getLogger(CommandProcessor.class); public static void startBridgeTask() { String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); @@ -53,8 +51,16 @@ public static void startBridgeTask() { // Loop through each entry in the data list for (Object dataEntry : dataList) { int bridgeId = JsonPath.read(dataEntry, "$.bridgeId"); + int processedInt = JsonPath.read(dataEntry, "$.processed"); // Read as int + boolean processed = (processedInt == 1); // Convert int to boolean String command = JsonPath.read(dataEntry, "$.command"); + // Skip processing if the command is already processed + if (processed) { + logger.info("Command with bridgeId {} has already been processed, skipping.", bridgeId); + continue; // Skip to the next iteration if already processed + } + // Execute the command asynchronously CompletableFuture future = ZanderVelocityMain.getProxy() .getCommandManager() @@ -67,7 +73,7 @@ public static void startBridgeTask() { // Mark the command as processed try { - BridgeProcess bridgeProcess = BridgeProcess.builder() + BridgeCommandProcessor bridgeCommandProcessor = BridgeCommandProcessor.builder() .bridgeId(bridgeId) .build(); @@ -75,7 +81,7 @@ public static void startBridgeTask() { .setURL(BaseAPIURL + "/bridge/command/process") .setMethod(Request.Method.POST) .addHeader("x-access-token", APIKey) - .setRequestBody(bridgeProcess.toString()) + .setRequestBody(bridgeCommandProcessor.toString()) .build(); Response bridgeProcessRes = bridgeProcessReq.execute(); @@ -101,4 +107,4 @@ public static void startBridgeTask() { } }, 0, 60, TimeUnit.SECONDS); } -} \ No newline at end of file +} diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/bridge/ServerSync.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/bridge/ServerSync.java new file mode 100644 index 0000000..372f815 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/bridge/ServerSync.java @@ -0,0 +1,108 @@ +package org.modularsoft.zander.velocity.util.api.bridge; + +import dev.dejvokep.boostedyaml.route.Route; +import io.github.ModularEnigma.Request; +import io.github.ModularEnigma.Response; +import com.velocitypowered.api.proxy.Player; +import com.velocitypowered.api.proxy.ProxyServer; +import com.velocitypowered.api.proxy.server.RegisteredServer; +import org.modularsoft.zander.velocity.ZanderVelocityMain; +import org.modularsoft.zander.velocity.model.bridge.BridgeServerSync; + +import java.time.Instant; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.time.format.DateTimeFormatter; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; + +public class ServerSync { + private static final ProxyServer proxy = ZanderVelocityMain.getProxy(); + + public static void startServerSyncTask() { + String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); + String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + + // Create a ScheduledExecutorService with a single thread + ScheduledExecutorService scheduler = Executors.newScheduledThreadPool(1); + + // Schedule the task to run every 60 seconds + scheduler.scheduleAtFixedRate(() -> { + try { + // Collect server and player information + List serverInfoList = new ArrayList<>(); + for (RegisteredServer server : proxy.getAllServers()) { + List playerNames = server.getPlayersConnected().stream() + .map(Player::getUsername) + .collect(Collectors.toList()); + + ServerInfo info = new ServerInfo( + server.getServerInfo().getName(), + playerNames.size(), + playerNames + ); + serverInfoList.add(info); + } + + // Get the current time and format it as a DATETIME string + LocalDateTime now = LocalDateTime.ofInstant(Instant.now(), ZoneId.systemDefault()); + DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); + String lastUpdated = now.format(formatter); + + // Build the BridgeServerSync object + BridgeServerSync serverInfo = BridgeServerSync.builder() + .serverInfo(serverInfoList) + .lastUpdated(lastUpdated) + .build(); + + // Prepare the request body + Request serverSyncReq = Request.builder() + .setURL(BaseAPIURL + "/bridge/server/update") + .setMethod(Request.Method.POST) + .addHeader("x-access-token", APIKey) + .setRequestBody(serverInfo.toString()) + .build(); + + // Send the request and get the response + Response serverSyncRes = serverSyncReq.execute(); + if (serverSyncRes.getStatusCode() != 200) { + ZanderVelocityMain.getLogger().error("Error syncing server info: " + serverSyncRes.getBody()); + } + + } catch (Exception e) { + // Handle any exceptions + ZanderVelocityMain.getLogger().error("Error occurred while syncing server info: " + e.getMessage()); + } + }, 0, 60, TimeUnit.SECONDS); + } + + // Helper class to hold server information + public static class ServerInfo { + private final String serverName; + private final int playerCount; + private final List playerNames; + + public ServerInfo(String serverName, int playerCount, List playerNames) { + this.serverName = serverName; + this.playerCount = playerCount; + this.playerNames = playerNames; + } + + // Getters + public String getServerName() { + return serverName; + } + + public int getPlayerCount() { + return playerCount; + } + + public List getPlayerNames() { + return playerNames; + } + } +} \ No newline at end of file diff --git a/zander-waterfall/dependency-reduced-pom.xml b/zander-waterfall/dependency-reduced-pom.xml index 68a3538..b4732ec 100644 --- a/zander-waterfall/dependency-reduced-pom.xml +++ b/zander-waterfall/dependency-reduced-pom.xml @@ -7,7 +7,7 @@ 4.0.0 zander-waterfall - 1.0 + 1.3.0 diff --git a/zander-waterfall/pom.xml b/zander-waterfall/pom.xml index 4f1b606..d9ba52f 100644 --- a/zander-waterfall/pom.xml +++ b/zander-waterfall/pom.xml @@ -10,7 +10,7 @@ 4.0.0 zander-waterfall - 1.0 + 1.3.0 From 8cc5a546ab805e37c31c248a6348a8c48f0e77c6 Mon Sep 17 00:00:00 2001 From: benrobson Date: Sun, 17 Nov 2024 21:21:19 +1100 Subject: [PATCH 17/17] Resolve issues with ServerPing builder and ping event. --- .../zander/velocity/ZanderVelocityMain.java | 2 +- .../velocity/events/UserOnProxyPing.java | 51 +++++++++++-------- 2 files changed, 31 insertions(+), 22 deletions(-) diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java index 79feb4f..4988988 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java @@ -57,7 +57,7 @@ public void onProxyInitialization(ProxyInitializeEvent event) { proxy.getEventManager().register(this, new UserCommandSpyEvent()); proxy.getEventManager().register(this, new UserOnDisconnect()); proxy.getEventManager().register(this, new UserOnLogin()); - proxy.getEventManager().register(this, new UserOnProxyPing()); + proxy.getEventManager().register(this, new UserOnProxyPing(this)); proxy.getEventManager().register(this, new UserOnSwitch()); proxy.getEventManager().register(this, new UserSocialSpyEvent()); diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnProxyPing.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnProxyPing.java index 3444495..21bafe2 100644 --- a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnProxyPing.java +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnProxyPing.java @@ -1,9 +1,10 @@ package org.modularsoft.zander.velocity.events; import com.jayway.jsonpath.JsonPath; +import com.velocitypowered.api.event.PostOrder; import com.velocitypowered.api.event.Subscribe; import com.velocitypowered.api.event.proxy.ProxyPingEvent; -import com.velocitypowered.api.proxy.server.ServerPing; +import com.velocitypowered.api.proxy.server.ServerPing.Builder; import dev.dejvokep.boostedyaml.route.Route; import io.github.ModularEnigma.Request; import io.github.ModularEnigma.Response; @@ -13,50 +14,58 @@ public class UserOnProxyPing { - @Subscribe + private final ZanderVelocityMain plugin; + + public UserOnProxyPing(ZanderVelocityMain plugin) { + this.plugin = plugin; + plugin.getProxy().getEventManager().register(plugin, this); + } + + @Subscribe(order = PostOrder.FIRST) public void onProxyPingEvent(ProxyPingEvent event) { + // Get the existing ServerPing.Builder from the event + Builder pingBuilder = event.getPing().asBuilder(); + try { - // ServerPing serverPing = event.getPing(); - String BaseAPIURL = ZanderVelocityMain.getConfig().getString(Route.from("BaseAPIURL")); - String APIKey = ZanderVelocityMain.getConfig().getString(Route.from("APIKey")); + // Fetch configuration values + String baseAPIURL = plugin.getConfig().getString(Route.from("BaseAPIURL")); + String apiKey = plugin.getConfig().getString(Route.from("APIKey")); - // GET request to fetch MOTD. + // Make a GET request to fetch the MOTD Request req = Request.builder() - .setURL(BaseAPIURL + "/announcement/get?announcementType=motd") + .setURL(baseAPIURL + "/announcement/get?announcementType=motd") .setMethod(Request.Method.GET) - .addHeader("x-access-token", APIKey) + .addHeader("x-access-token", apiKey) .build(); Response res = req.execute(); String json = res.getBody(); + // Parse and format the MOTD String colourMessageFormat = JsonPath.read(json, "$.data[0].colourMessageFormat"); - String motdTopLine = ZanderVelocityMain.getConfig().getString(Route.from("announcementMOTDTopLine")); + String motdTopLine = plugin.getConfig().getString(Route.from("announcementMOTDTopLine")); Component serverPingDescription = LegacyComponentSerializer.builder() .character('&') .build() .deserialize(motdTopLine + "\n" + colourMessageFormat); - ServerPing newServerPing = ServerPing.builder() - .description(serverPingDescription) - .build(); + // Set the description in the ServerPing.Builder + pingBuilder.description(serverPingDescription); - event.setPing(newServerPing); } catch (Exception e) { System.out.print(e); - // ServerPing serverPing = event.getPing(); - String motdTopLine = ZanderVelocityMain.getConfig().getString(Route.from("announcementMOTDTopLine")); - Component serverPingDescription = LegacyComponentSerializer.builder() + // Fallback MOTD in case of an exception + String motdTopLine = plugin.getConfig().getString(Route.from("announcementMOTDTopLine")); + Component fallbackDescription = LegacyComponentSerializer.builder() .character('&') .build() .deserialize(motdTopLine + "\n" + "&3&lPowered by Zander"); - ServerPing newServerPing = ServerPing.builder() - .description(serverPingDescription) - .build(); - - event.setPing(newServerPing); + pingBuilder.description(fallbackDescription); } + + // Set the modified ServerPing back to the event + event.setPing(pingBuilder.build()); } }