Solved Textcomponent and Bungee Plugin channel?

Discussion in 'Spigot Plugin Development' started by ClientException, Aug 1, 2020.

  1. Hello,

    is there a way to send a player a clickable text via Bungee Plugin channel?
    My Code is below:
    Code (Java):
    public static void sendToBungee(Player player) {
            ByteArrayOutputStream b = new ByteArrayOutputStream();
            DataOutputStream out = new DataOutputStream(b);
            try {

                out.writeUTF("Message");
                out.writeUTF("User");
                TextComponent text = new TextComponent(prefix + "§7Du wurdest von §e" + player.getName() + " §7in eine Party eingeladen\n");
                  TextComponent clickableText = new TextComponent(prefix + "§7Klicke §a§lhier §7um der Party beizutreten");
                  clickableText.setClickEvent(new ClickEvent(ClickEvent.Action.RUN_COMMAND, "/party accept " + player.getName()));
                  text.addExtra(clickableText);
                  out.writeUTF(new TextComponent(text));
            } catch (IOException e) {
                e.printStackTrace();
            }
            player.sendPluginMessage(Main.getPlugin(), "BungeeCord", b.toByteArray());
        }
    Of course the code won't work, because out.writeUTF isn't compatible with TextComponents.

    Best regards
    ClientException
     
  2. I fixed this problem by myself. I just added another Plugin Channel on BungeeCord.
    My Code:
    Spigot:
    Code (Java):
    public static void invitePlayer(Player p, String invited){
            ByteArrayOutputStream b = new ByteArrayOutputStream();
            DataOutputStream out = new DataOutputStream(b);
            try {
                out.writeUTF("PartyInvite");
                out.writeUTF(invited + " " + p.getName());
            } catch (IOException e) {
                e.printStackTrace();
            }
            p.sendPluginMessage(Main.getPlugin(Main.class), "BungeeCord", b.toByteArray());
        }
    BungeeCord:
    Code (Java):
    @EventHandler
        public void onPluginMessage(PluginMessageEvent e) {
             if (e.getTag().equalsIgnoreCase("BungeeCord")) {
                 DataInputStream in = new DataInputStream(new ByteArrayInputStream(e.getData()));
                    try {
                        String channel = in.readUTF();

                        if(channel.equals("PartyInvite")){
                            String input = in.readUTF();
                            ArrayList<String> strings = new ArrayList<>(Arrays.asList(input.split(" ")));
                            String player2 = strings.get(0);
                            String player = strings.get(1);
                             //Textcomponent
                   }
          } catch (IOException e1) {
                       e1.printStackTrace();
                   }
            }

    }