send message on spigot

Discussion in 'BungeeCord Plugin Development' started by Gamestyler113, May 10, 2015.

  1. hello!

    i code a ban plugin but i have a question. If i'm banning a player, i will that any player who have a permission that he gets the message: "xx was banned by yy".
    How can I do this?


    Code (text):
    ByteArrayOutputStream b = new ByteArrayOutputStream();
    DataOutputStream out = new DataOutputStream(b);

    for(Player o : Bukkit.getOnlinePlayers()) {
    try {
    out.writeUTF("Message");
    out.writeUTF(o.getName());
    out.writeUTF("testmsg");
    } catch (IOException e) {
    e.printStackTrace();
    }
    o.sendPluginMessage(this.plugin, "BungeeCord", b.toByteArray());
    }
    It's not working.. All players who are in other bungee-servers and have a permissions should have the message..
    I hope you understand what i mean.

    I try it too with: p.sendPluginMessage(this.plugin, "BungeeCord", b.toByteArray()); | It's not working.
     
  2. You have registered the channel?
    Use: getServer().getMessager().registerOutgoingChannel("BungeeCord");
    Also, does it print any errors in console?

    Example:
    Code (Text):
    public void onEnable() {
        this.getServer().getMessenger().registerOutgoingPluginChannel(this, "BungeeCord");
      }

    public void sendBungeeMessage(Player player, String message) {
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("Message");
        out.writeUTF(player.getName());
        out.writeUTF(message);
        player.sendPluginMessage(this, "BungeeCord", out.toByteArray());
    }
    public void sendBungeeMessage(String nickname, String message) {
        ByteArrayDataOutput out = ByteStreams.newDataOutput();
        out.writeUTF("Message");
        out.writeUTF(nickname);
        out.writeUTF(message);
        Player player = Bukkit.getOfflinePlayer(nickname);
        player.sendPluginMessage(this, "BungeeCord", out.toByteArray());
    }
     
     
    #2 Jamezrin, May 10, 2015
    Last edited: May 10, 2015
  3. thank you for your help! :) but this is not what i need.

    Example:
    Player X is in server "lobby".
    Player Y is Server "spawn".
    Player X bans the player Z
    Y is operator and need the message "Z was banned by X". ALL user with permissions should receive the message..
    I hope you understand me..

    in your method i need to have "String nickname" but who / what is String nickname?
    for(Player o : Bukkit.getOnlinePlayer()) is completely wrong because Y never gets the message when X bans z..

    Please help me! :(
     
  4. You dont need this plugin messages thingy.