Skip to content
This repository was archived by the owner on Aug 3, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions NexEngine/src/main/java/su/nexmedia/engine/NexEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public void enable() {

this.editorManager = new EditorManager(this);
this.editorManager.setup();

this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
}

@Override
Expand All @@ -51,6 +53,8 @@ public void disable() {

if (EngineUtils.hasVault()) VaultHook.shutdown();
PlayerBlockTracker.shutdown();

this.getServer().getMessenger().unregisterOutgoingPluginChannel(this);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,23 @@ else if (this.type == LangMessage.OutputType.TITLES) {
}
}

public void send(@NotNull String playerName) {
Player pTarget = plugin.getServer().getPlayerExact(playerName);
if (pTarget != null) {
send(pTarget);
} else {
if (this.type == LangMessage.OutputType.CHAT) {
if (Bukkit.spigot().getConfig().getBoolean("settings.bungeecord", false)) {
String prefix = hasPrefix ? plugin.getConfigManager().pluginPrefix : "";
this.asList().forEach(line -> {
PlayerUtil.sendBungeeCordMessage(playerName, prefix + line);
});
}
}
}

}

@NotNull
public List<String> asList() {
return this.asList(this.getLocalized());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ public static void sendRichMessage(@NotNull CommandSender sender, @NotNull Strin
NexParser.toMessage(message).send(sender);
}

public static void sendBungeeCordMessage(@NotNull String playerName, @NotNull String message) {
NexParser.toMessage(message).sendByBungeeCord(playerName);
}

public static void sendActionBar(@NotNull Player player, @NotNull String msg) {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, NexParser.toMessage(msg).build());
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package su.nexmedia.engine.utils.message;

import com.google.common.base.Preconditions;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import net.md_5.bungee.api.ChatColor;
import net.md_5.bungee.api.chat.BaseComponent;
import net.md_5.bungee.api.chat.ComponentBuilder;
import net.md_5.bungee.api.chat.TextComponent;
import net.md_5.bungee.chat.ComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;
import su.nexmedia.engine.utils.Colorizer;
import su.nexmedia.engine.utils.EngineUtils;
import su.nexmedia.engine.utils.Reflex;
import su.nexmedia.engine.utils.regex.RegexUtil;

Expand Down Expand Up @@ -99,6 +104,18 @@ public void send(@NotNull CommandSender sender) {
}
}

public void sendByBungeeCord(String playerName) {
for (String line : this.message.split("\n")) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("MessageRaw");
out.writeUTF(playerName);
out.writeUTF(ComponentSerializer.toString(this.build(line)));

System.out.println(playerName + ": " + ComponentSerializer.toString(this.build(line)));
Bukkit.getServer().sendPluginMessage(EngineUtils.ENGINE, "BungeeCord" , out.toByteArray());
}
}

public void send(@NotNull CommandSender... senders) {
Stream.of(senders).forEach(this::send);
}
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<properties>
<maven.compiler.source>16</maven.compiler.source>
<maven.compiler.target>16</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<repositories>
Expand Down