From 86455639dcc572bf7f3dab880bcdb71c9b793794 Mon Sep 17 00:00:00 2001 From: Leander <47365075+Le4nderS@users.noreply.github.com> Date: Sun, 3 Sep 2023 23:58:33 +0200 Subject: [PATCH] Initial commit --- .gitignore | 2 + TerraPlusMinusBungeeBridge.iml | 46 ++++++++++++ pom.xml | 71 +++++++++++++++++++ .../TerraPlusMinusBungeeBridge.java | 23 ++++++ .../listener/PluginMessageListener.java | 51 +++++++++++++ src/main/resources/bungee.yml | 4 ++ 6 files changed, 197 insertions(+) create mode 100644 .gitignore create mode 100644 TerraPlusMinusBungeeBridge.iml create mode 100644 pom.xml create mode 100644 src/main/java/de/btegermany/terraplusminusbungeebridge/TerraPlusMinusBungeeBridge.java create mode 100644 src/main/java/de/btegermany/terraplusminusbungeebridge/listener/PluginMessageListener.java create mode 100644 src/main/resources/bungee.yml diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..744289d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Project exclude paths +/target/ \ No newline at end of file diff --git a/TerraPlusMinusBungeeBridge.iml b/TerraPlusMinusBungeeBridge.iml new file mode 100644 index 0000000..1932263 --- /dev/null +++ b/TerraPlusMinusBungeeBridge.iml @@ -0,0 +1,46 @@ + + + + + + + BUNGEECORD + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..acc03e7 --- /dev/null +++ b/pom.xml @@ -0,0 +1,71 @@ + + + 4.0.0 + + de.btegermany + TerraPlusMinusBungeeBridge + 1.0-SNAPSHOT + jar + + TerraPlusMinusBungeeBridge + + + 1.8 + UTF-8 + + + + clean package + + + org.apache.maven.plugins + maven-compiler-plugin + 3.8.1 + + ${java.version} + ${java.version} + + + + org.apache.maven.plugins + maven-shade-plugin + 3.2.4 + + + package + + shade + + + false + + + + + + + + src/main/resources + true + + + + + + + sonatype + https://oss.sonatype.org/content/groups/public/ + + + + + + net.md-5 + bungeecord-api + 1.20-R0.1-SNAPSHOT + provided + + + diff --git a/src/main/java/de/btegermany/terraplusminusbungeebridge/TerraPlusMinusBungeeBridge.java b/src/main/java/de/btegermany/terraplusminusbungeebridge/TerraPlusMinusBungeeBridge.java new file mode 100644 index 0000000..6f3dcc7 --- /dev/null +++ b/src/main/java/de/btegermany/terraplusminusbungeebridge/TerraPlusMinusBungeeBridge.java @@ -0,0 +1,23 @@ +package de.btegermany.terraplusminusbungeebridge; + +import de.btegermany.terraplusminusbungeebridge.listener.PluginMessageListener; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.plugin.Plugin; + +public final class TerraPlusMinusBungeeBridge extends Plugin { + + @Override + public void onEnable() { + ProxyServer.getInstance().registerChannel("BungeeCord"); + ProxyServer.getInstance().registerChannel("bungeecord:terraplusminus"); + ProxyServer.getInstance().getPluginManager().registerListener(this, new PluginMessageListener()); + // Plugin startup logic + } + + @Override + public void onDisable() { + // Unregister plugin messaging channel + ProxyServer.getInstance().getPluginManager().unregisterListeners(this); + // -------------------------- + } +} diff --git a/src/main/java/de/btegermany/terraplusminusbungeebridge/listener/PluginMessageListener.java b/src/main/java/de/btegermany/terraplusminusbungeebridge/listener/PluginMessageListener.java new file mode 100644 index 0000000..13648ea --- /dev/null +++ b/src/main/java/de/btegermany/terraplusminusbungeebridge/listener/PluginMessageListener.java @@ -0,0 +1,51 @@ +package de.btegermany.terraplusminusbungeebridge.listener; + +import com.google.common.io.ByteArrayDataInput; +import com.google.common.io.ByteStreams; +import net.md_5.bungee.api.ProxyServer; +import net.md_5.bungee.api.connection.ProxiedPlayer; +import net.md_5.bungee.api.event.PluginMessageEvent; +import net.md_5.bungee.api.plugin.Listener; +import net.md_5.bungee.event.EventHandler; + +import java.io.ByteArrayOutputStream; +import java.io.DataOutputStream; +import java.io.IOException; +import java.util.UUID; + +public class PluginMessageListener implements Listener { + @EventHandler + public void onPluginMessage(PluginMessageEvent event) { + if (!event.getTag().equalsIgnoreCase("bungeecord:terraplusminus")) return; + // get uuid and coordinates from message + ByteArrayDataInput dataInput = ByteStreams.newDataInput(event.getData()); + String uuid = dataInput.readUTF(); + UUID playerUUID = UUID.fromString(uuid); + + String servername = dataInput.readUTF(); + String coordinates = dataInput.readUTF(); + + // Assuming you have a method to get the player by UUID + ProxiedPlayer player = ProxyServer.getInstance().getPlayer(playerUUID); + if (player != null) { + // Move the player to the specified server + sendMessageToBukkitServer(player,servername, coordinates); + player.connect(ProxyServer.getInstance().getServerInfo(servername)); + } + } + + // method to send message via messaging channel to bukkit server + public void sendMessageToBukkitServer(ProxiedPlayer player, String servername, String coordinates) { + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + DataOutputStream out = new DataOutputStream(stream); + try { + out.writeUTF(player.getUniqueId().toString()); + out.writeUTF(coordinates); + } catch (IOException e) { + e.printStackTrace(); + } + ProxyServer.getInstance().getServers().get(servername).sendData("bungeecord:terraplusminus", stream.toByteArray()); + } + + +} diff --git a/src/main/resources/bungee.yml b/src/main/resources/bungee.yml new file mode 100644 index 0000000..99d40d5 --- /dev/null +++ b/src/main/resources/bungee.yml @@ -0,0 +1,4 @@ +name: TerraPlusMinusBungeeBridge +version: '${project.version}' +main: de.btegermany.terraplusminusbungeebridge.TerraPlusMinusBungeeBridge +author: Leander