I want to get the arguments of a chat message (AsyncPlayerChatEvent) if possible.

Discussion in 'Plugin Development' started by stimoze, Oct 26, 2016.

Thread Status:
Not open for further replies.
  1. I was gone for 1-2 months because my "hype" for Minecraft was gone but now I started to play again and then I remembered to this community and the plugins, and I had an idea. My idea was to make a plugin what didn't exist (I think...) before. It was a chat assistant plugin what is similar to these speech-to-action things like Cortana (Here came the idea about the plugin) at Windows 10 or S Voice at Samsung phones you know..

    So, I couldn't wait XD and I started to do it. Everything was good until I got to this part. I was making the first function, giving for me or for other players items. My idea was to get the chat arguments, but the problem is that this isn't a command so I couldn't get the args of it. Please if you guys have some tips share them with me.

    Thanks for everybody, Peace <3
     
  2. Offline

    LazerAspect

    Try getting the chat message and then parsing it
     
  3. @stimoze
    What do you mean you can't get the arguments? The chat message you get from AsyncPlayerChatEvent looks something like this:
    Code:text
    1. hello hello hello
    While if you were to do it in a command, the args have just been split off into an array, so you'd get hello as the command, and then an array of "hello, hello" as the arguments.
     
  4. Can you give me a full explanation of it and an example please?

    P.S: Sorry I'm a little bit idiot and i can't understand anything without giving examples :/
     
  5. @stimoze
    I don't understand your question though. In both cases, the arguments are right there for you. In the chat event you get "hello hello hello" as a plain String, but if it were a command you'd get "hello" as the command, and then an array consisting of "hello hello".
     
  6. Uhh. It's a little bit complex plugin what I started to....

    @AlvinB What i want to do, is to grab the message(what is actually a command) and understand it like a command (After every " " space is a new arg)

    Here's an example.
    Code:
    give me 64 of diamond
    Let's say "give" is the 1. arg (the command itself)
    me = 2. arg (the player to give)
    64 =3. arg (amount)
    of = 4. arg (an optional word)
    diamond = 5. arg (as the item name)
     
  7. Offline

    LazerAspect

    I believe he is trying to separate each word in a chat message that was sent.
     
  8. Exactly what you said :)
     
  9. Offline

    krizzdawg

    What is the use of this? If you define what plugin you are trying to make... We may be able to make a substitution or find a solution.
     
  10. @stimoze
    Oh, I get it.

    You can use the String#split() method. If I were to use String.split(" ") on the following String:
    Code:text
    1. hello hello hello
    I'd get a String array with
    Code:text
    1. ["hello", "hello", "hello"]
     
  11. If i got them, i can understand them and give them the item by e.getPlayer().getInventory().addItem(the args here);

    I need an example because I'm a little bit confused :confused:

    Here's my code:
    Code:
    package soleplugin;
    
    import java.util.ArrayList;
    
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;
    
    import com.sun.jna.StringArray;
    
    public class ChatCall implements Listener {
        public static Org plg;
        public ChatCall(Org org) {
            plg = org;
        }
       
        ArrayList<Player> chatting;
        StringArray intp;
       
        @EventHandler
        public void CallingSole(AsyncPlayerChatEvent e){
            if (e.getMessage().contains("hey sole")){
                chatting.add(e.getPlayer());
                e.setCancelled(true);
                e.getPlayer().sendMessage("§bHey " + e.getPlayer().getName() + "! I'm ready for assistance. Remember if you need help just write.");
            }
            if (chatting.contains(e.getPlayer())){
                if (e.getMessage().contains("help")){
                    e.setCancelled(true);
                    e.getPlayer().sendMessage("Here you are, " + e.getPlayer().getName() + "!");
                    e.getPlayer().sendMessage("Here you can find all the commands and words you can use.");
                    e.getPlayer().sendMessage("§cLegend: (optional words) [logic sections] <placeholders>");
                    e.getPlayer().sendMessage("§3Give [(me)/<player name>] <amount> (of) <item-name or ID> §f- §2Give an item to you or a player.");
                }
                if (e.getMessage().contains("bye sole")){
                    e.getPlayer().sendMessage("Bye! See you next time! :)");
                }
                //Commandsection
                if (e.getMessage().contains("give")){
                    e.setCancelled(true);
                   
                }
            }
        }
    
    }
    
    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
  12. Offline

    ChipDev

    PHP:
    String[] ex "hello1 hello2 hello3".split(" "); //splits via space
    String first ex[0];
    First will be equal to "hello1" because you split "hello1 hello2 hello3" by space then get the first (0) argument.
     
Thread Status:
Not open for further replies.

Share This Page