Solved Create a Global placeholder (that works everywhere)

Discussion in 'Spigot Plugin Development' started by Bart_, May 17, 2016.

  1. Hello guys,
    I need your experience!
    I have to create a placeholder in my plugin, it should work everywhere.
    For example, i create the placeholder %time% and it should work both in chat and in the scoreboard.

    For the chat can be used
    Code (Text):

        public void onChat(AsyncPlayerChatEvent e){
         String message = e.getMessage(); //get the message

         e.setCancelled(true); //cancel the event, so no message is sent (yet)

         for(Player on : Bukkit.getOnlinePlayers()){ //loop threw all online players
           if(message.contains(on.getName())){ //check if the message contains the player's name
             String newMessage = message.replaceAll(on.getName(), ChatColor.BLUE + ChatColor.UNDERLINE + on.getName() + ChatColor.WHITE); //format the message
             //change ChatColor.BLUE + ChatColor.UNDERLINE to the formatting you want
             on.sendMessage(newMessage); //send the player the message
             on.playNote(on.getLocation(), Instrument.PIANO, Note.natural(1, Tone.A)); //send the player the music
             on.sendMessage(message); //else send the player the regular message
    But for the scoreboard? It should work in any scoreboard, not in my plugin.
    For example, the player can put the placeholder where he want and it must be replaced everywhere it is.

  2. No one? i am surprised.
  3. Not possible unless you create an API the other plugin is hooking into.
  4. Ah ok, another question?
    With AsyncPlayerChatEvent I can get all messages sent in chat by player and console or only player? Thanks! For the console what?
    Because most popular broadcast plugin message use Bukkit.broadcastMessage () so I want to manipulate it when sent.

    Inviato dal mio SM-G930F utilizzando Tapatalk
  5. Obviously, the asyncplayerchatevent is only for players. To get the messages of the consolesender, you would use