Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-5039

Spigot is sending plugin message but BungeeCord doesn't receive it

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Invalid
    • Icon: Major Major
    • None
    • None
    • CPU - Intel(R) Xeon(R) CPU L5420 @ 2.50GHz (2 x 4/4)
      Memory - 48306MB
      Disk Size - 654770MB
      Java - Version 8 Update 211 (Build 1.8.0_211-b12)
      OS - Debian GNU/Linux 9.9 (stretch) (64x)

       

    • git-Spigot-1a3504a-dfa7583 (MC: 1.13.2) & git-Spigot-baafee9-17543ec (MC: 1.14.2)
    • Yes

      Hello, 
      I made an plugin for a private server to switch between server with an GUI.
      But everytime i send a plugin message from spigot to bungeecord the bungeecord doesn't receive the message, i tried to fix it over 1 hour and searched on spigot and other forums for a fix but didn't find one.
      Both plugins (on BungeeCord and Spigot) are loaded normally and i receive channels like minecraft:register or minecraft:branch and the other functions of the spigot plugin are working

      Something to the configuration of the servers.
      Bungeecord is enabled in the config of the spigot servers and the spigot servers are registered on the bungeecord, so i can switch between them with /server <Server>

      I tested the spigot plugin on two versions:
      - git-Spigot-1a3504a-dfa7583 (MC: 1.13.2)
      - git-Spigot-baafee9-17543ec (MC: 1.14.2)

      The BungeeCord is also the newest one and the build version is: git:BungeeCord-Bootstrap:1.14-SNAPSHOT:8fda060:1413

      I think the problem is that spigot doesn't send the plugin messages correct, because it receives the plugin messages from the bungeecord correctly, but the bungeecord can't receive any plugin message, it only receives the normal message of minecraft and all plugin messages from spigot servers below the version 1.13

      Here my sourcecode, maybe i did something wrong but after all that tutorials and thread i read about it i'm not really sure.
      Here the plugins from the sourcecode:

      How to reproduce:
      1. Setup the BungeeCord with one registered spigot server by adding the ip-address of the spigot server in your config.yml of the BungeeCord

      2. Setup the Spigot and enable the setting "bungeecord" by chaning it in the spigot.yml from "false" to "true"

      3. Install the SpigotMessager.jar by putting it in the plugins folder of your spigot server

      4. Install the BungeeCordMessager.jar by putting it in the plugins folder of your bungeecord server

      5. Start both servers

      6. Join on the server

      BungeeCord

      Plugin Message Class

      package net.epicbuilds.bungee;
      
      import java.io.ByteArrayInputStream;
      import java.io.DataInputStream;
      import java.io.IOException;
      import java.util.HashMap;
      
      import net.md_5.bungee.api.event.PluginMessageEvent;
      import net.md_5.bungee.api.plugin.Listener;
      import net.md_5.bungee.api.plugin.Plugin;
      import net.md_5.bungee.api.plugin.PluginManager;
      import net.md_5.bungee.event.EventHandler;
      import net.md_5.bungee.BungeeCord;
      import net.md_5.bungee.api.config.ServerInfo;
      import net.md_5.bungee.api.connection.ProxiedPlayer;
      
      public class SpigotPluginListener implements Listener {
      
      	private static SpigotPluginListener lis;
      	private HashMap<String, SpigotExecutor> hm = new HashMap<>();
      	private String listenChannel = "";
      	
      	protected static SpigotPluginListener getListener() {
      		return lis;
      	}
      	
      	public void start(PluginManager pm, String channel, Plugin pl) {
      		lis = this;
      		
      		pl.getProxy().registerChannel(channel);
      		pm.registerListener(pl, this);
      		
      	}
      	
      	public void reg(String channel, SpigotExecutor ex) {
      		
      		if(!hm.containsKey(channel)) {
      			
      			hm.put(channel, ex);
      			
      		}
      		
      	}
      	
      	@EventHandler
      	public void messageReceived(PluginMessageEvent e) {
      		
      		try {
      			
      			System.out.println(e.getTag());
      			if(!e.getTag().equals(listenChannel)) {
      				return;
      			}
      			
      			
      			DataInputStream in = new DataInputStream(new ByteArrayInputStream(e.getData()));
      			String subChannel = in.readUTF();
      			System.out.println(subChannel);
      			
      			ProxiedPlayer send = BungeeCord.getInstance().getPlayer(e.getReceiver().toString());
      			ServerInfo info = send.getServer().getInfo();
      			
      			if(hm.containsKey(subChannel)) {
      				hm.get(subChannel).complete(send, e.getTag(), subChannel, in, info);
      			}
      			
      		} catch (IOException ex) {
      			
      			ex.printStackTrace();
      			
      		}
      			
      	}
      
      	protected void sendData(ServerInfo info, byte[] byteArray) {
      		info.sendData(listenChannel, byteArray);
      	}
      
      }
      
      

      UniCode (Some utils)

      package net.epicbuilds.bungee;
      
      public class UniCode {
      	
      	public static String arrowsRight() {
      		return "\u00BB";
      	}
      	public static String arrowsLeft() {
      		return "\u00AB";
      	}
      	public static String ue() {
      		return "\u00FC";
      	}
      	public static String oe() {
      		return "\u00F6";
      	}
      	public static String ae() {
      		return "\u00E4";
      	}
      
      }
      

      Plugin Message Subchannel Receiver (interface)

      package net.epicbuilds.bungee;
      
      import java.io.ByteArrayOutputStream;
      import java.io.DataInputStream;
      import java.io.DataOutputStream;
      import java.io.IOException;
      
      import net.md_5.bungee.api.config.ServerInfo;
      import net.md_5.bungee.api.connection.ProxiedPlayer;
      
      public abstract interface SpigotExecutor {
      	
      	public abstract boolean complete(ProxiedPlayer send, String ch, String subChannel, DataInputStream in, ServerInfo info) throws IOException;
      	
      	public default void sendBack(String channel, String message, ServerInfo info) {
      		
              ByteArrayOutputStream stream = new ByteArrayOutputStream();
              DataOutputStream out = new DataOutputStream(stream);
              
              try {
              	
                  out.writeUTF(channel);
                  out.writeUTF(message);
                  
              } catch (IOException e) {
              	
                  e.printStackTrace();
                  
              }
              
              SpigotPluginListener.getListener().sendData(info, stream.toByteArray());
      
          }
      	
      }
      

      Main Class

      package net.epicbuilds.bungee;
      
      import java.io.DataInputStream;
      import java.io.IOException;
      import java.util.UUID;
      
      import net.md_5.bungee.BungeeCord;
      import net.md_5.bungee.api.ChatColor;
      import net.md_5.bungee.api.chat.ClickEvent;
      import net.md_5.bungee.api.chat.TextComponent;
      import net.md_5.bungee.api.config.ServerInfo;
      import net.md_5.bungee.api.connection.ProxiedPlayer;
      import net.md_5.bungee.api.plugin.Plugin;
      import net.md_5.bungee.api.plugin.PluginManager;
      
      public class EpicBungee extends Plugin {
      	
      	private SpigotPluginListener spl = new SpigotPluginListener();
      	private PluginManager pm = BungeeCord.getInstance().getPluginManager();
      	
      	public void onEnable() {
      		
      		spl.start(pm, "eb:epicsystem", this);
      		spl.reg("servers", new RCServer());
      		spl.reg("connect", new RCConnect());
      		
      	}
      	
      }
      
      class RCServer implements SpigotExecutor {
      
      	@Override
      	public boolean complete(ProxiedPlayer send, String ch, String subChannel, DataInputStream in, ServerInfo info)
      			throws IOException {
      		
      		String msg = "" + BungeeCord.getInstance().getServers().keySet().size();
      		
      		String[] servs = BungeeCord.getInstance().getServers().keySet().toArray(new String[0]);
      		
      		for(int i = 0; i < BungeeCord.getInstance().getServers().keySet().size(); i++) {
      			
      			msg = msg + " " + servs[i];
      			
      		}
      		
      		sendBack(subChannel, msg, info);
      		
      	return false;
      	}
      	
      }
      
      class RCConnect implements SpigotExecutor {
      	private TextComponent pre;
      	private TextComponent fix;
      	private TextComponent suffix;
      	private TextComponent text1;
      	private TextComponent text2;
      	private TextComponent text3;
      	
      	RCConnect() {
      		 pre = new TextComponent("Epic");
      		 fix = new TextComponent("Builds");
      		 suffix = new TextComponent(" "+UniCode.arrowsRight()+" ");
      		 text1 = new TextComponent("Du wirst mit dem ");
      		 text2 = new TextComponent("Server ");
      		 text3 = new TextComponent(" verbunden.");
      		 pre.setColor(ChatColor.AQUA);
      		 fix.setColor(ChatColor.YELLOW);
      		 suffix.setColor(ChatColor.DARK_GRAY);
      		 text1.setColor(ChatColor.GRAY);
      		 text2.setColor(ChatColor.DARK_AQUA);
      		 text3.setColor(ChatColor.GRAY);
      		 
      		 ClickEvent click = new ClickEvent(ClickEvent.Action.OPEN_URL, "https://epicbuilds.net/");
      		 pre.setClickEvent(click);
      		 fix.setClickEvent(click);
      	}
      
      
      	@Override
      	public boolean complete(ProxiedPlayer send, String ch, String subChannel, DataInputStream in, ServerInfo info)
      			throws IOException {
      		
      		String msg = in.readUTF();
      		
      		String[] args = msg.split(" ");
      		
      		ServerInfo server = BungeeCord.getInstance().getServers().get(args[0]);
      		ProxiedPlayer play = BungeeCord.getInstance().getPlayer(UUID.fromString(args[1]));
      		
      		play.connect(server);
      		sendMessage(play, server.getName());
      		
      	return false;
      	}
      	
      	private void sendMessage(ProxiedPlayer pp, String server) {
      		TextComponent serv = new TextComponent(server);
      		serv.setColor(ChatColor.AQUA);
      		pp.sendMessage(pre, fix, suffix, text1, text2, serv, text3);
      	}
      	
      }
      
      

      Spigot
      Plugin Message Class

      package net.epicbuilds.system.bungeeTools;
      
      import java.io.ByteArrayInputStream;
      import java.io.ByteArrayOutputStream;
      import java.io.DataInputStream;
      import java.io.DataOutputStream;
      import java.io.IOException;
      import java.util.HashMap;
      
      import org.bukkit.Bukkit;
      import org.bukkit.entity.Player;
      import org.bukkit.plugin.Plugin;
      import org.bukkit.plugin.messaging.PluginMessageListener;
      
      public class BungeePluginListener implements PluginMessageListener {
      	
      	private static BungeePluginListener lis;
      	private String listenChannel = "";
      	
      	public void start(String channel, Plugin pl) {
      		lis = this;
      		listenChannel = channel;
      		
      		pl.getServer().getMessenger().registerIncomingPluginChannel(pl, channel, this);
      		pl.getServer().getMessenger().registerOutgoingPluginChannel(pl, channel);
      		
      	}
      	
      	private HashMap<String, BungeeExecutor> hm = new HashMap<>();
      	
      	public void reg(String channel, BungeeExecutor ex) {
      		
      		
      		if(!hm.containsKey(channel)) {
      			
      			hm.put(channel, ex);
      			
      		}
      		
      	}
      
      	@Override
      	public void onPluginMessageReceived(String ch, Player send, byte[] bytes) {
      		
      		try {
      			
      			if(!ch.equals(listenChannel)) {
      				return;
      			}
      			
      			DataInputStream in = new DataInputStream(new ByteArrayInputStream(bytes));
      			String subChannel = in.readUTF();
      			
      			if(hm.containsKey(subChannel)) {
      				
      				hm.get(subChannel).complete(send, ch, subChannel, in);
      				
      			}
      			
      		} catch (IOException e) {
      			
      			e.printStackTrace();
      			
      		}
      			
      	}
      	
          public void sendBungee(Player send, String channel, String message, Plugin pl){
          	
              ByteArrayOutputStream b = new ByteArrayOutputStream();
              DataOutputStream out = new DataOutputStream(b);
              
              try {
              	
                  out.writeUTF(channel);
                  out.writeUTF(message);
                  
              } catch (IOException e) {
              	
                  e.printStackTrace();
                  
              }
              
              send.sendPluginMessage(pl, listenChannel, b.toByteArray());
              
          }
      	
          public void sendBungee(String channel, String message, Plugin pl){
          	
              ByteArrayOutputStream b = new ByteArrayOutputStream();
              DataOutputStream out = new DataOutputStream(b);
              
              try {
              	
                  out.writeUTF(channel);
                  out.writeUTF(message);
                  
              } catch (IOException e) {
              	
                  e.printStackTrace();
                  
              }
              
              Bukkit.getServer().sendPluginMessage(pl, listenChannel, b.toByteArray());
              
          }
          
          protected void sendData(Player play, Plugin pl, byte[] input) {
          	play.sendPluginMessage(pl, listenChannel, input);
          }
      
          protected static BungeePluginListener getListener() {
      		return lis;
      	}
      
      }
      
      

      Plugin Message Subchannel Receiver (abstract)

      package net.epicbuilds.system.bungeeTools;
      
      import java.io.ByteArrayOutputStream;
      import java.io.DataInputStream;
      import java.io.DataOutputStream;
      import java.io.IOException;
      
      import org.bukkit.entity.Player;
      import org.bukkit.plugin.Plugin;
      
      public abstract interface BungeeExecutor {
      	
      	public abstract boolean complete(Player send, String ch, String subChannel, DataInputStream in) throws IOException;
      	
          public default void sendBungee(Player send, String channel, String message, Plugin pl){
          	
              ByteArrayOutputStream stream = new ByteArrayOutputStream();
              DataOutputStream out = new DataOutputStream(stream);
              
              try {
              	
                  out.writeUTF(channel);
                  out.writeUTF(message);
                  
              } catch (IOException e) {
              	
                  e.printStackTrace();
                  
              }
              
              BungeePluginListener.getListener().sendData(send, pl, stream.toByteArray());
              
          }
          
          default BungeePluginListener getListener() {
          	return BungeePluginListener.getListener();
          }
          
      }
      
      

      Plugin Message Subchannel Executor

      package net.epicbuilds.system.bungeeTools;
      
      import java.io.DataInputStream;
      import java.io.IOException;
      
      import org.bukkit.entity.Player;
      import org.bukkit.event.EventHandler;
      import org.bukkit.event.Listener;
      import org.bukkit.event.player.PlayerJoinEvent;
      
      import net.epicbuilds.system.bungeeTools.BungeeExecutor;
      
      public class ServerReceiver implements Listener, BungeeExecutor {
      	
      	@EventHandler
      	public void onJoinSendMsg(PlayerJoinEvent e) {
      		getListener().sendBungee("servers", "", Core.getCore());
      	}
      
      	@Override
      	public boolean complete(Player send, String ch, String subChannel, DataInputStream in) throws IOException {
      		
      		String msg = in.readUTF();
      		String[] zeugs = msg.split(" ");
      		Integer x = Integer.valueOf(zeugs[0]);
      		System.out.println(subChannel);
      		
      		Core cr = Core.getCore();
      		for(int i = 1; i < (x + 1); i++) {
      			cr.addServer(zeugs[i]);
      		}
      		
      	return false;
      	}
      
      }
      

      Main Class

      package net.epicbuilds.system.bungeeTools;
      
      import java.util.ArrayList;
      import java.util.List;
      
      import org.bukkit.Bukkit;
      import org.bukkit.plugin.PluginManager;
      import org.bukkit.plugin.java.JavaPlugin;
      
      import net.epicbuilds.system.bungeeTools.BungeePluginListener;
      
      public class Core extends JavaPlugin {
      
      	private static Core core;
      
      	private PluginManager pm = Bukkit.getPluginManager();
      	private BungeePluginListener bpl = new BungeePluginListener();
      	private List<String> servers = new ArrayList<>();
      
      	public void onLoad() {
      		core = this;
      		loadup();
      	}
      
      	public void onEnable() {
      
      		setup();
      
      	}
      
      	public void onDisable() {
      		
      	}
      
      	/*
      	 * 
      	 * Utils
      	 * 
      	 */
      
      	private void loadup() {
      		if (!getDataFolder().exists()) {
      			getDataFolder().mkdirs();
      		}
      	}
      
      	private void setup() {
      
      		bpl.start("eb:epicsystem", this);
      		events();
      	}
      
      	private void events() {
      
      		ServerReceiver receiver = new ServerReceiver();
      		bpl.reg("servers", receiver);
      		pm.registerEvents(receiver, this);
      
      	}
      
      	/*
      	 * 
      	 * Getter
      	 * 
      	 */
      
      	/// static
      	// public
      	
      	public static Core getCore() {
      		return core;
      	}
      
      	// non-public
      
      	/// non-static
      	// public
      
      	public List<String> getServers() {
      		return servers;
      	}
      
      	// non-public
      
      	/*
      	 * 
      	 * Setter
      	 * 
      	 */
      
      	/// static
      	// public
      
      	// non-public
      
      	/// non-static
      	// public
      
      	// non-public
      
      	void addServer(String str) {
      		if(!servers.contains(str)) {
      			servers.add(str);
      			System.out.println(str);
      		}
      	}
      
      	/*
      	 * 
      	 * Other
      	 * 
      	 */
      
      }
      

            Unassigned Unassigned
            StevenLPHD Steven
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: