diff --git a/pom.xml b/pom.xml index 995e5be..721c5b8 100644 --- a/pom.xml +++ b/pom.xml @@ -10,9 +10,11 @@ pom - zander-proxy + zander-waterfall + zander-velocity zander-hub zander-auth + zander-bridge 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 new file mode 100644 index 0000000..62717f5 --- /dev/null +++ b/zander-bridge/pom.xml @@ -0,0 +1,67 @@ + + + + zander + org.modularsoft + 1.0 + + 4.0.0 + + zander-bridge + 1.3.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..ce9e8d0 --- /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(); + + saveDefaultConfig(); + } + + @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..7ec4fef --- /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 synchronously on the main server thread + Bukkit.getScheduler().runTask(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); + } +} \ No newline at end of file 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-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 new file mode 100644 index 0000000..bcbab2f --- /dev/null +++ b/zander-velocity/dependency-reduced-pom.xml @@ -0,0 +1,90 @@ + + + 4.0.0 + org.modularsoft + zander-velocity + zander-velocity + 1.3.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.4.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 new file mode 100644 index 0000000..31a6d4b --- /dev/null +++ b/zander-velocity/pom.xml @@ -0,0 +1,142 @@ + + + 4.0.0 + + org.modularsoft + zander-velocity + 1.3.0 + 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-shade-plugin + 3.4.1 + + + + *:* + + META-INF/*.MF + + + + + + dev.dejvokep.boostedyaml + org.modularsoft.zander.velocity.libs + + + + + + package + + shade + + + + + + + + + + + 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.4.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.9.0 + + + com.google.code.gson + gson + 2.8.9 + compile + + + org.slf4j + slf4j-api + 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..4988988 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/ZanderVelocityMain.java @@ -0,0 +1,112 @@ +package org.modularsoft.zander.velocity; + +import com.google.inject.Inject; +import com.velocitypowered.api.command.CommandManager; +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.commands.*; +import org.modularsoft.zander.velocity.events.*; +import org.modularsoft.zander.velocity.util.announcement.TipChatter; +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; +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 + public static ProxyServer proxy; + @Getter + private static YamlDocument config; + @Getter + private final CommandManager commandManager; + + @Subscribe + public void onProxyInitialization(ProxyInitializeEvent event) { + // Event Listeners + proxy.getEventManager().register(this, new UserChatEvent()); + proxy.getEventManager().register(this, new UserCommandSpyEvent()); + proxy.getEventManager().register(this, new UserOnDisconnect()); + proxy.getEventManager().register(this, new UserOnLogin()); + proxy.getEventManager().register(this, new UserOnProxyPing(this)); + proxy.getEventManager().register(this, new UserOnSwitch()); + proxy.getEventManager().register(this, new UserSocialSpyEvent()); + + // Commands + CommandManager commandManager = proxy.getCommandManager(); + + 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()); + commandManager.register(commandManager.metaBuilder("alert").build(), new alert()); + + // Start tasks + Heartbeat.startHeartbeatTask(); + TipChatter.startAnnouncementTipTask(); + CommandProcessor.startBridgeTask(); + ServerSync.startServerSyncTask(); + } + + @Inject + public ZanderVelocityMain( + ProxyServer proxy, + Logger logger, + CommandManager commandManager, + @DataDirectory Path dataDirectory + ) { + this.proxy = proxy; + this.logger = logger; + this.commandManager = commandManager; + + // 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/commands/alert.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/commands/alert.java new file mode 100644 index 0000000..dcaa7a9 --- /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/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/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/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); + } + } +} 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..2140a07 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserChatEvent.java @@ -0,0 +1,75 @@ +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-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..6f02042 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserCommandSpyEvent.java @@ -0,0 +1,61 @@ +package org.modularsoft.zander.velocity.events; + +import com.velocitypowered.api.event.Subscribe; +import com.velocitypowered.api.event.command.CommandExecuteEvent; +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 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.getCommand(); // Get the full command + + ZanderVelocityMain.getLogger().info("Command: {}", command); + + // 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/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..f1ef3ff --- /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 + 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); + } + } +} 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..21bafe2 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserOnProxyPing.java @@ -0,0 +1,71 @@ +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.Builder; +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 { + + 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 { + // Fetch configuration values + String baseAPIURL = plugin.getConfig().getString(Route.from("BaseAPIURL")); + String apiKey = plugin.getConfig().getString(Route.from("APIKey")); + + // Make a GET request to fetch the 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(); + + // Parse and format the MOTD + String colourMessageFormat = JsonPath.read(json, "$.data[0].colourMessageFormat"); + String motdTopLine = plugin.getConfig().getString(Route.from("announcementMOTDTopLine")); + Component serverPingDescription = LegacyComponentSerializer.builder() + .character('&') + .build() + .deserialize(motdTopLine + "\n" + colourMessageFormat); + + // Set the description in the ServerPing.Builder + pingBuilder.description(serverPingDescription); + + } catch (Exception e) { + System.out.print(e); + + // 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"); + + pingBuilder.description(fallbackDescription); + } + + // Set the modified ServerPing back to the event + event.setPing(pingBuilder.build()); + } +} 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..39eab8b --- /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 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(); + 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")); + + logger.info("Player {} is switching to server {}", username, server); + + // Handle Session Switch API + try { + 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()) // Ensure this method works properly + .build(); + + Response switchSessionRes = switchSessionReq.execute(); + logger.info("Session Switch Response ({}): {}", switchSessionRes.getStatusCode(), switchSessionRes.getBody()); + } catch (Exception 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 { + 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()) // Ensure this method works properly + .build(); + + Response discordSwitchRes = discordSwitchReq.execute(); + logger.info("Discord Switch Response ({}): {}", discordSwitchRes.getStatusCode(), discordSwitchRes.getBody()); + } catch (Exception 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 new file mode 100644 index 0000000..15d9be9 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/events/UserSocialSpyEvent.java @@ -0,0 +1,88 @@ +package org.modularsoft.zander.velocity.events; + +import com.velocitypowered.api.event.Subscribe; +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; +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 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("Command: {}", command); + + // 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[] 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 = 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 + 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 = currentServerOpt.get(); + + // Construct the social spy object + DiscordSocialSpy socialSpy = DiscordSocialSpy.builder() + .usernameFrom(player.getUsername()) + .usernameTo(targetPlayer) + .directMessage(directMessage) + .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()) // Ensure proper serialization to JSON + .build(); + + Response socialSpyRes = socialSpyReq.execute(); + logger.info("Social Spy Response ({}): {}", socialSpyRes.getStatusCode(), socialSpyRes.getBody()); + + } catch (Exception 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)); + } + } + } +} diff --git a/zander-proxy/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-proxy/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-proxy/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-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/model/bridge/BridgeCommandProcessor.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/bridge/BridgeCommandProcessor.java new file mode 100644 index 0000000..809dba2 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/model/bridge/BridgeCommandProcessor.java @@ -0,0 +1,17 @@ +package org.modularsoft.zander.velocity.model.bridge; + +import com.google.gson.Gson; +import lombok.Builder; +import lombok.Getter; + +@Builder +public class BridgeCommandProcessor { + + @Getter Integer bridgeId; + + @Override + public String toString() { + return new Gson().toJson(this); + } + +} 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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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/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..129fff7 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/announcement/TipChatter.java @@ -0,0 +1,71 @@ +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 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); + + // 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"); + + // 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(announcementTipPrefix + " " + colourMessageFormat); + + if (link != null && !link.isEmpty()) { + // 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); + }); + } catch (Exception e) { + // Handle exceptions here + 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); + } +} 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..566ff65 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/Heartbeat.java @@ -0,0 +1,60 @@ +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 { + 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); + } +} diff --git a/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/bridge/CommandProcessor.java b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/bridge/CommandProcessor.java new file mode 100644 index 0000000..0675ee4 --- /dev/null +++ b/zander-velocity/src/main/java/org/modularsoft/zander/velocity/util/api/bridge/CommandProcessor.java @@ -0,0 +1,110 @@ +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 org.modularsoft.zander.velocity.ZanderVelocityMain; +import org.modularsoft.zander.velocity.model.bridge.BridgeCommandProcessor; +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 CommandProcessor { + // Initialize the logger + private static final Logger logger = LoggerFactory.getLogger(CommandProcessor.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"); + + // 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"); + 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() + .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 { + BridgeCommandProcessor bridgeCommandProcessor = BridgeCommandProcessor.builder() + .bridgeId(bridgeId) + .build(); + + Request bridgeProcessReq = Request.builder() + .setURL(BaseAPIURL + "/bridge/command/process") + .setMethod(Request.Method.POST) + .addHeader("x-access-token", APIKey) + .setRequestBody(bridgeCommandProcessor.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); + } +} 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-velocity/src/main/resources/config.yml b/zander-velocity/src/main/resources/config.yml new file mode 100644 index 0000000..bf8c2bd --- /dev/null +++ b/zander-velocity/src/main/resources/config.yml @@ -0,0 +1,10 @@ +config-version: 2 + +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 " +announcementTipInterval: 10 +alertCommandPrefix: "&7&l[&6&lALERT&7&l]&r " \ No newline at end of file diff --git a/zander-proxy/dependency-reduced-pom.xml b/zander-waterfall/dependency-reduced-pom.xml similarity index 95% rename from zander-proxy/dependency-reduced-pom.xml rename to zander-waterfall/dependency-reduced-pom.xml index 3d049fe..b4732ec 100644 --- a/zander-proxy/dependency-reduced-pom.xml +++ b/zander-waterfall/dependency-reduced-pom.xml @@ -6,8 +6,8 @@ 1.0 4.0.0 - zander-proxy - 1.0 + zander-waterfall + 1.3.0 diff --git a/zander-proxy/pom.xml b/zander-waterfall/pom.xml similarity index 97% rename from zander-proxy/pom.xml rename to zander-waterfall/pom.xml index 6ab30c2..d9ba52f 100644 --- a/zander-proxy/pom.xml +++ b/zander-waterfall/pom.xml @@ -9,8 +9,8 @@ 4.0.0 - zander-proxy - 1.0 + zander-waterfall + 1.3.0 diff --git a/zander-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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-proxy/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; 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