use of net.md_5.bungee.api.event.PluginMessageEvent in project ConnectorPlugin by Phoenix616.
the class PluginMessageConnector method onPluginMessage.
@EventHandler
public void onPluginMessage(PluginMessageEvent event) {
if (event.isCancelled() || !event.getTag().equals(plugin.getMessageChannel())) {
return;
}
if (event.getSender() instanceof ProxiedPlayer) {
event.setCancelled(true);
return;
}
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
String group = in.readUTF();
String target = in.readUTF();
int messageLength = in.readInt();
byte[] messageData = new byte[messageLength];
in.readFully(messageData);
try {
Message message = Message.fromByteArray(group, messageData);
switch(message.getTarget()) {
case ALL_WITH_PLAYERS:
sendToAllWithPlayers(event.getData(), null);
break;
case ALL_QUEUE:
sendToAllAndQueue(event.getData(), null);
break;
case OTHERS_WITH_PLAYERS:
sendToAllWithPlayers(event.getData(), ((ProxiedPlayer) event.getSender()).getServer().getInfo());
break;
case OTHERS_QUEUE:
sendToAllAndQueue(event.getData(), ((ProxiedPlayer) event.getSender()).getServer().getInfo());
break;
case PROXY:
case ALL_PROXIES:
handle(target, message);
break;
case SERVER:
if (!target.isEmpty()) {
ServerInfo server = getTargetServer(target);
if (server != null) {
server.sendData(plugin.getMessageChannel(), event.getData(), true);
} else {
plugin.logDebug(target + " doesn't exist?");
}
} else {
plugin.logError(message.getTarget() + " message target requires explicit target!");
}
break;
default:
plugin.logError("Receiving " + message.getTarget() + " is not supported!");
}
} catch (IllegalArgumentException e) {
plugin.logError("Invalid message target! " + e.getMessage());
} catch (VersionMismatchException e) {
plugin.getLogger().log(Level.WARNING, e.getMessage() + ". Ignoring message!");
}
}
use of net.md_5.bungee.api.event.PluginMessageEvent in project CommandBridge by SouthplexStudio.
the class PluginMessageMode method onPluginMessage.
@EventHandler
public void onPluginMessage(PluginMessageEvent event) {
if (event.getTag().equals("BungeeCord")) {
ByteArrayDataInput in = ByteStreams.newDataInput(event.getData());
String subchannel = in.readUTF();
if (!subchannel.equals("commandbridge"))
return;
String password = in.readUTF();
// System.out.println(password+" "+password.equals(configUtil.getPassword()));
if (!password.equals(CommandBridgeBungee.getInstance().getConfigUtil().getPassword()))
return;
CommandBridgeBungee.getInstance().getProxy().getPluginManager().dispatchCommand(CommandBridgeBungee.getInstance().getProxy().getConsole(), in.readUTF());
}
}
use of net.md_5.bungee.api.event.PluginMessageEvent in project BungeeCord by SpigotMC.
the class DownstreamBridge method handle.
@Override
@SuppressWarnings("checkstyle:avoidnestedblocks")
public void handle(PluginMessage pluginMessage) throws Exception {
DataInput in = pluginMessage.getStream();
PluginMessageEvent event = new PluginMessageEvent(server, con, pluginMessage.getTag(), pluginMessage.getData().clone());
if (bungee.getPluginManager().callEvent(event).isCancelled()) {
throw CancelSendSignal.INSTANCE;
}
if (pluginMessage.getTag().equals(con.getPendingConnection().getVersion() >= ProtocolConstants.MINECRAFT_1_13 ? "minecraft:brand" : "MC|Brand")) {
ByteBuf brand = Unpooled.wrappedBuffer(pluginMessage.getData());
String serverBrand = DefinedPacket.readString(brand);
brand.release();
Preconditions.checkState(!serverBrand.contains(bungee.getName()), "Cannot connect proxy to itself!");
brand = ByteBufAllocator.DEFAULT.heapBuffer();
DefinedPacket.writeString(bungee.getName() + " (" + bungee.getVersion() + ")" + " <- " + serverBrand, brand);
pluginMessage.setData(DefinedPacket.toArray(brand));
brand.release();
// changes in the packet are ignored so we need to send it manually
con.unsafe().sendPacket(pluginMessage);
throw CancelSendSignal.INSTANCE;
}
if (pluginMessage.getTag().equals("BungeeCord")) {
ByteArrayDataOutput out = ByteStreams.newDataOutput();
String subChannel = in.readUTF();
switch(subChannel) {
case "ForwardToPlayer":
{
ProxiedPlayer target = bungee.getPlayer(in.readUTF());
if (target != null) {
// Read data from server
String channel = in.readUTF();
short len = in.readShort();
byte[] data = new byte[len];
in.readFully(data);
// Prepare new data to send
out.writeUTF(channel);
out.writeShort(data.length);
out.write(data);
byte[] payload = out.toByteArray();
target.getServer().sendData("BungeeCord", payload);
}
// Null out stream, important as we don't want to send to ourselves
out = null;
break;
}
case "Forward":
{
// Read data from server
String target = in.readUTF();
String channel = in.readUTF();
short len = in.readShort();
byte[] data = new byte[len];
in.readFully(data);
// Prepare new data to send
out.writeUTF(channel);
out.writeShort(data.length);
out.write(data);
byte[] payload = out.toByteArray();
// Null out stream, important as we don't want to send to ourselves
out = null;
switch(target) {
case "ALL":
for (ServerInfo server : bungee.getServers().values()) {
if (server != this.server.getInfo()) {
server.sendData("BungeeCord", payload);
}
}
break;
case "ONLINE":
for (ServerInfo server : bungee.getServers().values()) {
if (server != this.server.getInfo()) {
server.sendData("BungeeCord", payload, false);
}
}
break;
default:
ServerInfo server = bungee.getServerInfo(target);
if (server != null) {
server.sendData("BungeeCord", payload);
}
break;
}
break;
}
case "Connect":
{
ServerInfo server = bungee.getServerInfo(in.readUTF());
if (server != null) {
con.connect(server, ServerConnectEvent.Reason.PLUGIN_MESSAGE);
}
break;
}
case "ConnectOther":
{
ProxiedPlayer player = bungee.getPlayer(in.readUTF());
if (player != null) {
ServerInfo server = bungee.getServerInfo(in.readUTF());
if (server != null) {
player.connect(server);
}
}
break;
}
case "IP":
out.writeUTF("IP");
if (con.getSocketAddress() instanceof InetSocketAddress) {
out.writeUTF(con.getAddress().getHostString());
out.writeInt(con.getAddress().getPort());
} else {
out.writeUTF("unix://" + ((DomainSocketAddress) con.getSocketAddress()).path());
out.writeInt(0);
}
break;
case "IPOther":
{
ProxiedPlayer player = bungee.getPlayer(in.readUTF());
if (player != null) {
out.writeUTF("IPOther");
out.writeUTF(player.getName());
if (player.getSocketAddress() instanceof InetSocketAddress) {
InetSocketAddress address = (InetSocketAddress) player.getSocketAddress();
out.writeUTF(address.getHostString());
out.writeInt(address.getPort());
} else {
out.writeUTF("unix://" + ((DomainSocketAddress) player.getSocketAddress()).path());
out.writeInt(0);
}
}
break;
}
case "PlayerCount":
{
String target = in.readUTF();
out.writeUTF("PlayerCount");
if (target.equals("ALL")) {
out.writeUTF("ALL");
out.writeInt(bungee.getOnlineCount());
} else {
ServerInfo server = bungee.getServerInfo(target);
if (server != null) {
out.writeUTF(server.getName());
out.writeInt(server.getPlayers().size());
}
}
break;
}
case "PlayerList":
{
String target = in.readUTF();
out.writeUTF("PlayerList");
if (target.equals("ALL")) {
out.writeUTF("ALL");
out.writeUTF(Util.csv(bungee.getPlayers()));
} else {
ServerInfo server = bungee.getServerInfo(target);
if (server != null) {
out.writeUTF(server.getName());
out.writeUTF(Util.csv(server.getPlayers()));
}
}
break;
}
case "GetServers":
{
out.writeUTF("GetServers");
out.writeUTF(Util.csv(bungee.getServers().keySet()));
break;
}
case "Message":
{
String target = in.readUTF();
String message = in.readUTF();
if (target.equals("ALL")) {
for (ProxiedPlayer player : bungee.getPlayers()) {
player.sendMessage(message);
}
} else {
ProxiedPlayer player = bungee.getPlayer(target);
if (player != null) {
player.sendMessage(message);
}
}
break;
}
case "MessageRaw":
{
String target = in.readUTF();
BaseComponent[] message = ComponentSerializer.parse(in.readUTF());
if (target.equals("ALL")) {
for (ProxiedPlayer player : bungee.getPlayers()) {
player.sendMessage(message);
}
} else {
ProxiedPlayer player = bungee.getPlayer(target);
if (player != null) {
player.sendMessage(message);
}
}
break;
}
case "GetServer":
{
out.writeUTF("GetServer");
out.writeUTF(server.getInfo().getName());
break;
}
case "UUID":
{
out.writeUTF("UUID");
out.writeUTF(con.getUUID());
break;
}
case "UUIDOther":
{
ProxiedPlayer player = bungee.getPlayer(in.readUTF());
if (player != null) {
out.writeUTF("UUIDOther");
out.writeUTF(player.getName());
out.writeUTF(player.getUUID());
}
break;
}
case "ServerIP":
{
ServerInfo info = bungee.getServerInfo(in.readUTF());
if (info != null && !info.getAddress().isUnresolved()) {
out.writeUTF("ServerIP");
out.writeUTF(info.getName());
out.writeUTF(info.getAddress().getAddress().getHostAddress());
out.writeShort(info.getAddress().getPort());
}
break;
}
case "KickPlayer":
{
ProxiedPlayer player = bungee.getPlayer(in.readUTF());
if (player != null) {
String kickReason = in.readUTF();
player.disconnect(new TextComponent(kickReason));
}
break;
}
}
// Check we haven't set out to null, and we have written data, if so reply back back along the BungeeCord channel
if (out != null) {
byte[] b = out.toByteArray();
if (b.length != 0) {
server.sendData("BungeeCord", b);
}
}
throw CancelSendSignal.INSTANCE;
}
}
use of net.md_5.bungee.api.event.PluginMessageEvent in project XConomy by YiC200333.
the class BCsync method on.
@SuppressWarnings(value = { "UnstableApiUsage", "unused" })
@EventHandler
public void on(PluginMessageEvent event) {
if (!(event.getSender() instanceof Server)) {
return;
}
if (!event.getTag().equalsIgnoreCase("xconomy:acb")) {
return;
}
ByteArrayDataInput input = ByteStreams.newDataInput(event.getData());
Server senderServer = (Server) event.getSender();
ByteArrayDataOutput output = ByteStreams.newDataOutput();
output.writeUTF(input.readUTF());
String sv = input.readUTF();
output.writeUTF(sv);
String svv = sv;
if (svv.contains(".")) {
svv = "versions §f" + svv;
} else {
svv = "§fold versions";
}
if (!sv.equals(XConomyBungee.syncversion)) {
XConomyBungee.getInstance().getLogger().warning("§cReceived data from " + svv + ", §cunable to synchronize, Current plugin version §f" + XConomyBungee.syncversion);
return;
}
String type = input.readUTF();
if (type.equalsIgnoreCase("updateplayer")) {
output.writeUTF("updateplayer");
output.writeUTF(input.readUTF());
} else if (type.equalsIgnoreCase("message") || type.equalsIgnoreCase("message#semi")) {
output.writeUTF("message");
String uid = input.readUTF();
ProxiedPlayer p = ProxyServer.getInstance().getPlayer(UUID.fromString(uid));
if (type.equalsIgnoreCase("message") && p == null) {
return;
}
output.writeUTF(uid);
output.writeUTF(input.readUTF());
} else if (type.equalsIgnoreCase("balanceall")) {
output.writeUTF("balanceall");
output.writeUTF(input.readUTF());
output.writeUTF(input.readUTF());
output.writeUTF(input.readUTF());
} else if (type.equalsIgnoreCase("broadcast")) {
output.writeUTF("broadcast");
output.writeUTF(input.readUTF());
} else if (type.equalsIgnoreCase("syncOnlineUUID")) {
output.writeUTF("syncOnlineUUID");
output.writeUTF(input.readUTF());
output.writeUTF(input.readUTF());
output.writeUTF(input.readUTF());
}
for (ServerInfo s : ProxyServer.getInstance().getServers().values()) {
if (!s.getName().equals(senderServer.getInfo().getName()) && s.getPlayers().size() > 0) {
ProxyServer.getInstance().getScheduler().runAsync(XConomyBungee.getInstance(), () -> SendMessTaskB(s, output));
}
}
}
use of net.md_5.bungee.api.event.PluginMessageEvent in project LuckPerms by lucko.
the class PluginMessageMessenger method onPluginMessage.
@EventHandler
public void onPluginMessage(PluginMessageEvent e) {
if (!e.getTag().equals(CHANNEL)) {
return;
}
e.setCancelled(true);
if (e.getSender() instanceof ProxiedPlayer) {
return;
}
byte[] data = e.getData();
ByteArrayDataInput in = ByteStreams.newDataInput(data);
String msg = in.readUTF();
if (this.consumer.consumeIncomingMessageAsString(msg)) {
// Forward to other servers
this.plugin.getBootstrap().getScheduler().executeAsync(() -> dispatchMessage(data));
}
}
Aggregations