Resource [Tutorial] Send ActionBar Messages without NMS

Discussion in 'Spigot Plugin Development' started by joblo.2213, Jul 19, 2017.


Was this Thread usefull for you?

  1. Yes

    350 vote(s)
  2. No

    64 vote(s)
  1. I 'have seen a lot of people using NMS-Code in their plugins for sending messages in the action bar of players.
    But this isn't necessary at all as the BungeeCord-Api can be used to simply send messages in the action bar.

    You don't need to hava a BungeeCord server to use this or add aditional libaries, it'll work with spigot.

    So I'dont want to talk long, I'll just show you the code how to do this:

    Code (Text):
            String message = "§6§lJust a simple test message!";
            Player player = Bukkit.getPlayer("ExamplePlayer");
            player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
    Or if you are on a BungeeCord-Server:
    Code (Text):
            player.sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(message));
    This is it!

    Just make sure that you have used the right imports:
    Code (Text):
    import net.md_5.bungee.api.ChatMessageType;
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    The Method Player.Spigot.sendMessage() does need a TextComponent to send, not a String.
    The easyest way to get it is, like I showed in the example, by using the TextComponent.fromLegacyText() method, but you could also create it by using BungeeCords Chat-Component-API, I just don't see a case where this is better.

    This was my first short tutorial, so it would be nice if you could give me some feedback.
    As I'm not a native english speaker I 'm sorry for all the spelling mistakes I made.
    If you spot some just let me know so I can fix them ;)
    #1 joblo.2213, Jul 19, 2017
    Last edited: Jul 20, 2017
    • Useful x 27
    • Like x 12
    • Informative x 3
    • Winner x 2
    • Agree x 1
    • Friendly x 1
    • Optimistic x 1
  2. First, use the resource tag.

    Secondly there a certain reasons why people use NMS over the api.
    My personal things are, more versions, better to understand.

    Also, the wiki page, that elaborates how the api works should be enough for someone to understand the api but thats my opinion
    • Agree Agree x 1
  3. So first of all thanks for your feedback^^

    I agree with you that the wiki page is enought to explain how the API works, but many people who work with spigot don't know that it can be used for action bars.
    In fact if you search on Google for spigot action bar including keywords like no nms or version independent you find nothing about it.
    I also just stumbled about it while searching for some good methods to send chat messages with click events
    • Friendly Friendly x 2
    • Like Like x 1
  4. Thanks for that tutorial. That's just what I was looking for :rolleyes:
    • Agree Agree x 1
    • Winner Winner x 1
    • Friendly Friendly x 1
  5. Idek u can do that
    • Friendly Friendly x 1
  6. Sad this is only 1.9+ if i'm right
    But still nice for the people who use 1.9
  7. Sad that people still use 1.9- and not 1.12.1
    • Agree Agree x 6
    • Funny Funny x 6
    • Like Like x 2
    • Creative Creative x 1
  8. Wow thank you! New server will be 1.12 so going to be helpful! <3
    • Funny Funny x 1
  9. quiero subir Plugins Premiums, No tomen en cuenta este comentario xd
    • Funny Funny x 4
    • Informative Informative x 1
  10. Why do people don't understand, that this is a english forum. I also don't start to write german, only because I am German...
    • Agree Agree x 3
    • Optimistic Optimistic x 1
  11. Pues si we No mames, si yo quiero Tradeceloqefwef :v
    • Creative Creative x 1
  12. Sjees, plz talk english, almost nobody can understand you...
    • Agree Agree x 3
    • Creative Creative x 1
  13. Mas


    If you're still programming for a version which doesn't support this (1.8 and below) you really need to update. Seriously, 1.8 has been out years now.
    As for "better to understand" I think most people would disagree with you there. This version is documented and is much simpler than having to use packets and NMS and change the code for every version.
    • Funny Funny x 2
    • Like Like x 1
    • Agree Agree x 1
  14. You could use Reflection or Abstraction for version independency.
    • Winner Winner x 1
  15. Mas


    But with this, you don't need to, that's the point.
    • Like Like x 2
    • Agree Agree x 2
    • Optimistic Optimistic x 1
  16. sorry for necroposting but this is a really good thread and it's helping me out a lot :D
    • Friendly Friendly x 2
    • Agree Agree x 1
    • Optimistic Optimistic x 1
    • Creative Creative x 1
  17. bruh i have both nms and spigot api 1.16 installed but i can't import net.md_5.bungeecord, can someone help me?

    nvm i did my google search and it worked
  18. I tried following code,


    but I got error "package net.md_5.bungee.api not found".

    Can anyone help me? Thanks!
  19. If you have the maven dependency, try to add the jar file
  20. I would just use Maven, that is not the issue (if Maven is used properly). You are probably linking against the Bukkit API instead of the Spigot API. Be sure to link against the Spigot API instead. If you can’t get it to work, post your pom.xml. And make sure to click the little ‘M’ button hovering in the right corner op your pom.xml to refresh maven stuff.