Solved Check for next message, and set the string to the message.

Discussion in 'Plugin Development' started by stimoze, Jul 31, 2016.

Thread Status:
Not open for further replies.
  1. In my plugin there are announcements. I wanted to make this with "chatcommands".
    Here's my sourcecode:
    Code:
            //Announcements
            if (Commands.input.contains(e.getPlayer()))
            {
                ArrayList<Player> texteditor = new ArrayList<Player>();
                e.setCancelled(true);
                String texts = "Default";
                if (e.getMessage().equalsIgnoreCase("exit"))
                {
                    Commands.input.remove(e.getPlayer());
                    e.getPlayer().sendMessage("§7(§bChatManager+§7) §eYou left §e§lannounce-mode§e!");
                }
                else if (e.getMessage().equalsIgnoreCase("check"))
                {
                    e.getPlayer().sendMessage("§8[§b§lANNOUNCEMENT§8] §fThe current message is: '" + color(texts) + "'");
                }
                else if (e.getMessage().equalsIgnoreCase("text"))
                {
                    if (!texteditor.contains(e.getPlayer()))
                    {
                       //Here's my problem
                        texteditor.add(e.getPlayer());
                        e.getPlayer().sendMessage("§8[§b§lANNOUNCEMENT§8] §fPlease write here the new text.");
                     
                        e.getPlayer().sendMessage("§8[§b§lANNOUNCEMENT§8] §fNew text is: '" + color(texts) + "'");
                    }
                }
                else if (e.getMessage().equalsIgnoreCase("done"))
                {
                    e.setCancelled(true);
                    Bukkit.broadcastMessage("§8====================================================="); 
                    Bukkit.broadcastMessage("");
                    Bukkit.broadcastMessage("                        §b§lA  N  N  O  U  N  C  E  M  E  N  T               ");
                    Bukkit.broadcastMessage("");
                    Bukkit.broadcastMessage("§8=====================================================");
                    Bukkit.broadcastMessage(color(texts));
                    Bukkit.broadcastMessage("§8=====================================================");
                }
            }
    I wan't to set the string to the message what i entered in text mode. What's the best way for this?

    If i wrote the new text, the plugin automatically removes me from the texteditor ArrayList.
     
    Last edited: Jul 31, 2016
  2. Either make it like this: "text this is a example message".

    pseudocode:
    Code:
    if message starts with "text " {
    
    text = message substring "text " length
    
    // code
    }
    Or enter a mode where he needs to write the text in chat like this: "this is a example message".
    Add the player to a list and add else if (player is in list) { ... } to line 36 of the code you showed.
     
  3. I don't understand properly the 3. line of your pseudocode. Can you give me a full example? I'm a bit confused.

    EDIT: Fixed the problem. But what about the 2nd solution? Because It's not the best solution.
    It's a little bit uncomfortable for me.

    My idea is:

    When player types in "text" he'll be moved to a text editor player ArrayList. The plugin will wait until the player assigns a text. Then the plugin sets the entered text to my "texts" string.
    1. How do I "tell" the plugin to pause the code until the player enters a text?
    2. How do I check the "next chat input"?
     
    Last edited: Jul 31, 2016
  4. Offline

    ChipDev

    It removes the first 5 characters of the string.
    "text ".length = 5
     
  5. Thanks, I've already solved it! :) But i realized this solution is a little bit uncomfortable for me.
    I wrote in the edit what would be the best solution. Can you help in it? Anyways thanks to everybody :)
     
  6. The idea is not to "pause" until the player enters a text, but to use the chat event again to get the text. The event get's called everytime the player sends a chat message

    You already added the player to the editor list, so the next step is to check if he is in the list when the event is called.
    Then emove him from the list, get your text with .getMessage(), do whatever you want with it and return.
     
  7. I found a solution, anyways thanks everybody. :)
     
Thread Status:
Not open for further replies.

Share This Page