Solved Help with chat

Discussion in 'Plugin Development' started by sara4012, Mar 31, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    sara4012

    Ok, so I want to make a broadcast plugin in which you can do something like "&new" and it will add a new line, and continue from there. Similar to doing &4 to turn something red.
    Thank you guys in advance for your help.
     
  2. Offline

    Cloaking_Ocean

    Well, I believe what you can do is get the string they want to broadcast and replace the character sequence of "&new" into "\n" because in java this actually creates a new line and in mine craft it just sends a new messages. I believe this should work. If not, ask me l8er and I'll try to compile it at home.
     
  3. Offline

    _Belknap_

    sara4012 Like setting the lores of items, you would create a Java List that stores strings and then set that list as the lore. So if you did :
    Code:java
    1. List<String> newline = new ArrayList<String>();
    2. newline.add("Hello!");
    3. newline.add("Hey!");
    4.  

    it would print out this if you broadcasted it:

    Hello!
    Hey!

    So I don't know how to get the string in front of the &new, but you could instead make an ArrayList that stores player names:
    Code:java
    1. ArrayList<String> inBroadcastSetup = new ArrayList<String>();

    then you could run an AsyncPlayerChatEvent, and if inBroadcastSetup contains that player's name, then it will set the event to cancelled so that the message doesn't get sent, and instead it will add that players message to the List newline like this:
    Code:java
    1. @EventHandler
    2. public void onChat(AsyncPlayerChatEvent e) {
    3. ArrayList<String> inBroadcastSetup = new ArrayList<String>();
    4. Player p = e.getPlayer();
    5. String pname = p.getName();
    6. if (inBroadcastSetup.contains(p.getName)) {
    7. e.setCancelled(true);
    8. newline.add(e.getMessage);
    9. if (e.getMessage().equalsIgnoreCase("stop")) {
    10. p.sendMessage("Set the multi-line broadcast message!")
    11. inBroadcastSetup.remove(p.getName);
    12. }}}

    Then all you have to do to broadcast the message is Bukkit.broadcastMessage(newline);
     
  4. Offline

    AoH_Ruthless

    sara4012
    In your AsyncPlayerChatEvent, replace the '&new' string with '\n', like so:
    Code:java
    1. public void onAsyncChat(AsyncPlayerChatEvent e) {
    2. e.setMessage(e.getMessage().replace("&new", "\n")
    3. }
     
  5. Offline

    sara4012

    AoH_Ruthless Cloaking_Ocean I tried the '\n' thing but it displayed the message as "Hello \nthere!" and not a two line message.
     
  6. Offline

    _Belknap_

  7. Offline

    AoH_Ruthless

  8. Offline

    sara4012

    _Belknap_ i don't mean multi-line when you say something, I am making a plugin where there is a saved list of broadcasts, and it broadcasts one, and I want to be able to do multi-line in those.
    AoH_Ruthless I did do \n the /n I typed in was a typo.
     
  9. Offline

    _Belknap_

    sara4012
    Yes, and what mine does is when you type a command such as /setupbroadcast 1, for every line that you type in, it will add that line that you type to the 1st broadcast message. So if you typed"Hello!" and sent it as a message and then typed "Goodbye!" and sent it as a message, both of those messages wouldn't show up on chat, and instead would be added to that broadcast. Then, if you did "/setupbroadcast stop" or something, it would stop adding what you type to the broadcast. Then when you went to broadcast that message, it would show up as :
    Hello!
    Goodbye!
    in the chat, or you could set it so that the pluginname is in front of those messages, so then it would show up as:
    [PluginName] Hello!
    [PluginName] Goodbye!
    thus making a multi-line broadcast!
     
  10. Offline

    sara4012

    _Belknap_ This is a good idea but I don't want to change the way that you set up broadcasts. I would prefer a system where you type in broadcasts in a config.yml file. In that file you can type in &new and it will make a new line.

    _Belknap_ AoH_Ruthless Oh I figured it out. I did this:
    Code:java
    1. for (String message2 : message.split("%new")){
    2. Bukkit.getServer().broadcastMessage(message2);
    3. }
    4. return;

    That fixes that problem, but I realized another one. I have a setting in the config for if you don't want the universal heading you enter the setting as 'none' I thought it was working, but realized it doesn't. Here's the code:
    Code:java
    1. public void broadcast(int whichOne){
    2. String header = this.getConfig().getString("prefix").replace('&', '§');
    3. int i = whichOne;
    4. String ii = Integer.toString(i);
    5. String message = this.getConfig().getString(ii).replace('&', '§');
    6. // Check if the prefix is 'none'
    7. if (header == "none"){
    8. if (message.split("%new").length == 1){
    9. Bukkit.getServer().broadcastMessage(message);
    10. return;
    11. }
    12. else{
    13. for (String message2 : message.split("%new")){
    14. Bukkit.getServer().broadcastMessage(message2);
    15. }
    16. return;
    17. }
    18. }
    19. //If the config isn't set to 'none'
    20. //I'm pretty sure it's excecuting this code when it shouldn't be.
    21. else{
    22. if (message.split("%new").length == 1){
    23. Bukkit.getServer().broadcastMessage(header + " " + message);
    24. return;
    25. }
    26. else{
    27. for (String message2 : message.split("%new")){
    28. Bukkit.getServer().broadcastMessage(header + " " + message2);
    29. }
    30. return;
    31. }
    32. }
    33. }
    34.  


    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  11. Offline

    _Belknap_

    sara4012
    Gah sry, I'm watching some tutorials on configs right now, so I don't know that much.
     
  12. Offline

    sara4012

    Last edited by a moderator: Jun 7, 2016
  13. Offline

    _Belknap_

    sara4012
    Thanks I'll check it out!

    sara4012
    Oh, and I'm making a chat plugin that configures things like the server motd in the multiplayer menu, the private and join public messages, chat channels, anti spamming/swearing/advertising, chat colors, broadcasting messages etc. so if you don't mind could I borrow a few of your ideas for the broadcasting plugin if I can't think of anything myself?

    sara4012
    Lol sorry for so many messages, but I encounter an error whenever I type /bc, just telling you. If you would like me msg you the error, just tag me in this thread!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  14. Offline

    sara4012

    _Belknap_ Yeah. could you post it in the little comment section on the plugins page? Thanks for using my plugin!

    _Belknap_ Also, yes, you may use my programming techniques. I will update the source code today.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
Thread Status:
Not open for further replies.

Share This Page