From 57daa70dec6f0dea72ff14679633da68ea1f42e6 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Sat, 14 Jan 2012 01:46:22 +0000 Subject: [PATCH] Fixed informing players of supported Plugin Channels By: Nathan Adams --- .../craftbukkit/entity/CraftPlayer.java | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java index e6e233f031..1b965f0d02 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java @@ -1,12 +1,16 @@ package org.bukkit.craftbukkit.entity; import com.google.common.collect.ImmutableSet; +import java.io.ByteArrayOutputStream; +import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set; +import java.util.logging.Level; +import java.util.logging.Logger; import net.minecraft.server.EntityPlayer; import net.minecraft.server.NBTTagCompound; import net.minecraft.server.Packet131ItemData; @@ -645,4 +649,29 @@ public class CraftPlayer extends CraftHumanEntity implements Player { public Set getListeningPluginChannels() { return ImmutableSet.copyOf(channels); } + + public void sendSupportedChannels() { + Set listening = server.getMessenger().getIncomingChannels(); + + if (!listening.isEmpty()) { + Packet250CustomPayload packet = new Packet250CustomPayload(); + + packet.tag = "REGISTER"; + ByteArrayOutputStream stream = new ByteArrayOutputStream(); + + for (String channel : listening) { + try { + stream.write(channel.getBytes("UTF8")); + stream.write((byte)0); + } catch (IOException ex) { + Logger.getLogger(CraftPlayer.class.getName()).log(Level.SEVERE, "Could not send Plugin Channel REGISTER to " + getName(), ex); + } + } + + packet.data = stream.toByteArray(); + packet.length = packet.data.length; + + getHandle().netServerHandler.sendPacket(packet); + } + } }