From 33a0f4250edf14ff0434cedcf8a75a1c70403e31 Mon Sep 17 00:00:00 2001 From: david Date: Sat, 11 Nov 2023 12:04:20 +0100 Subject: [PATCH] using paper adapter for connections --- build.gradle.kts | 3 ++- .../java/net/thenextlvl/tweaks/TweaksPlugin.java | 8 ++------ .../tweaks/command/server/LobbyCommand.java | 12 +++--------- 3 files changed, 7 insertions(+), 16 deletions(-) diff --git a/build.gradle.kts b/build.gradle.kts index 672db70..8da5a5f 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,7 +10,7 @@ plugins { } group = "net.thenextlvl" -version = "2.0.3" +version = "2.0.4" repositories { mavenCentral() @@ -28,6 +28,7 @@ dependencies { implementation("net.thenextlvl.core:nbt:1.3.5") implementation("net.thenextlvl.core:api:4.0.2") implementation("net.thenextlvl.core:i18n:1.0.8") + implementation("net.thenextlvl.core:paper:1.2.3") implementation("org.bstats:bstats-bukkit:3.0.2") annotationProcessor("org.projectlombok:lombok:1.18.28") diff --git a/src/main/java/net/thenextlvl/tweaks/TweaksPlugin.java b/src/main/java/net/thenextlvl/tweaks/TweaksPlugin.java index d7cbc28..7e66ff8 100644 --- a/src/main/java/net/thenextlvl/tweaks/TweaksPlugin.java +++ b/src/main/java/net/thenextlvl/tweaks/TweaksPlugin.java @@ -3,6 +3,7 @@ import core.annotation.FieldsAreNotNullByDefault; import core.api.file.format.GsonFile; import core.i18n.file.ComponentBundle; +import core.paper.messenger.PluginMessenger; import lombok.Getter; import lombok.experimental.Accessors; import net.kyori.adventure.text.minimessage.MiniMessage; @@ -83,7 +84,6 @@ public void onLoad() { @Override public void onEnable() { - registerMessageChannel(); registerListeners(); registerCommands(); } @@ -93,10 +93,6 @@ public void onDisable() { metrics.shutdown(); } - private void registerMessageChannel() { - Bukkit.getMessenger().registerOutgoingPluginChannel(this, "BungeeCord"); - } - private void registerListeners() { Bukkit.getPluginManager().registerEvents(new ChatListener(this), this); Bukkit.getPluginManager().registerEvents(new ConnectionListener(this), this); @@ -129,7 +125,7 @@ private void registerCommands() { // Server registerCommand(new BroadcastCommand(this)); if (isLobbyCommandEnabled()) - registerCommand(new LobbyCommand(this)); + registerCommand(new LobbyCommand(this, new PluginMessenger(this))); // Item registerCommand(new HeadCommand(this)); diff --git a/src/main/java/net/thenextlvl/tweaks/command/server/LobbyCommand.java b/src/main/java/net/thenextlvl/tweaks/command/server/LobbyCommand.java index 3e3480e..d5bdbc2 100644 --- a/src/main/java/net/thenextlvl/tweaks/command/server/LobbyCommand.java +++ b/src/main/java/net/thenextlvl/tweaks/command/server/LobbyCommand.java @@ -1,6 +1,6 @@ package net.thenextlvl.tweaks.command.server; -import com.google.common.io.ByteStreams; +import core.paper.messenger.PluginMessenger; import lombok.RequiredArgsConstructor; import net.thenextlvl.tweaks.TweaksPlugin; import net.thenextlvl.tweaks.command.api.CommandInfo; @@ -18,18 +18,12 @@ @RequiredArgsConstructor public class LobbyCommand implements CommandExecutor { private final TweaksPlugin plugin; + private final PluginMessenger messenger; @Override public boolean onCommand(CommandSender sender, Command command, String label, String[] args) { if (!(sender instanceof Player player)) throw new CommandSenderException(); - connect(player, plugin.config().serverConfig().lobbyServerName()); + messenger.connect(player, plugin.config().serverConfig().lobbyServerName()); return true; } - - private void connect(Player player, String server) { - var dataOutput = ByteStreams.newDataOutput(); - dataOutput.writeUTF("Connect"); - dataOutput.writeUTF(server); - player.sendPluginMessage(plugin, "BungeeCord", dataOutput.toByteArray()); - } }