Skip to content

Commit

Permalink
using paper adapter for connections
Browse files Browse the repository at this point in the history
  • Loading branch information
NonSwag committed Nov 11, 2023
1 parent f37c9d8 commit 33a0f42
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 16 deletions.
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ plugins {
}

group = "net.thenextlvl"
version = "2.0.3"
version = "2.0.4"

repositories {
mavenCentral()
Expand All @@ -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")
Expand Down
8 changes: 2 additions & 6 deletions src/main/java/net/thenextlvl/tweaks/TweaksPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -83,7 +84,6 @@ public void onLoad() {

@Override
public void onEnable() {
registerMessageChannel();
registerListeners();
registerCommands();
}
Expand All @@ -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);
Expand Down Expand Up @@ -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));
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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());
}
}

0 comments on commit 33a0f42

Please sign in to comment.