Plex/server/src/main/java/dev/plex/util/BungeeUtil.java

39 lines
1.2 KiB
Java
Raw Normal View History

package dev.plex.util;
import com.google.common.io.ByteArrayDataOutput;
import com.google.common.io.ByteStreams;
import dev.plex.Plex;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
public class BungeeUtil
{
public static boolean isBungeeCord()
{
return Bukkit.spigot().getSpigotConfig().getBoolean("settings.bungeecord");
}
public static boolean isVelocity()
{
return Bukkit.spigot().getPaperConfig().getBoolean("settings.velocity-support.enabled") && !Bukkit.spigot().getPaperConfig().getString("settings.velocity-support.secret", "").isEmpty();
}
public static void kickPlayer(Player player, Component message)
{
2022-05-10 05:00:48 +00:00
if (isBungeeCord() || isVelocity())
{
ByteArrayDataOutput out = ByteStreams.newDataOutput();
out.writeUTF("KickPlayer");
out.writeUTF(player.getName());
out.writeUTF(LegacyComponentSerializer.legacySection().serialize(message));
player.sendPluginMessage(Plex.get(), "BungeeCord", out.toByteArray());
}
else
{
player.kick(message);
}
}
}