Solved Problem

Discussion in 'Plugin Development' started by JarFile, Jan 30, 2015.

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

    JarFile

    Heres my code for the command I am making
    Code:
                if(label.equalsIgnoreCase("rawmsg"))
                {
                    if(args.length == 0)
                    {
                        p.playSound(p.getLocation(), Sound.valueOf(plugin.getConfig().getString("errorsound")), 1, 2);
                        p.sendMessage(colorize(plugin.getConfig().getString("prefix")) + " " + colorize(plugin.getConfig().getString("nosyntax")) + " §4</rawmsg [player] [message]>");
                    }
                    if(args.length == 1)
                    {
                        for(Player o : Bukkit.getOnlinePlayers())
                        {
                            if(o.getName().equalsIgnoreCase(args[0]))
                            {
                                if(args.length > 1)
                                {
                                    String msg = " ";
                                    for(String message : args)
                                    {
                                        msg = (msg + message + " ");
                                    }
                                    o.sendMessage("" + ChatColor.translateAlternateColorCodes('&', msg));
                                }
                                else
                                {
                                    p.playSound(p.getLocation(), Sound.valueOf(plugin.getConfig().getString("errorsound")), 1, 2);
                                    p.sendMessage(colorize(plugin.getConfig().getString("prefix")) + " " + colorize(plugin.getConfig().getString("nosyntax")) + " §4</rawmsg [player] [message]>");
                                }
                            }
                            else
                            {
                                p.playSound(p.getLocation(), Sound.valueOf(plugin.getConfig().getString("errorsound")), 1, 2);
                                p.sendMessage(colorize(plugin.getConfig().getString("prefix")) + " §4Player not found.");
                            }
                        }
                    }
                }
    
    When I type in the [message] part of it nothing pops up... I don't know what went wrong, otherwise the command is working. Gives me the errors for syntax and stuff.
     
  2. Offline

    mrCookieSlime

    Moved to Plugin Developement.
     
  3. Offline

    Skionz

    @JarFile Your checking for 1 argument. That means you can only message one word, but if you check for 1 or more arguments it will work if you combine the arguments correctly.
     
  4. Offline

    JarFile

    @Skionz Ok so here is what I did
    Code:
                    if(args.length >= 1)
                    {
                        for(Player o : Bukkit.getOnlinePlayers())
                        {
                            if(o.getName().equalsIgnoreCase(args[0]))
                            {
                                if(args.length > 1)
                                {
                                    String msg = " ";
                                    for(String message : args)
                                    {
                                        msg = (msg + message + " ");
                                    }
                                    o.sendMessage("" + ChatColor.translateAlternateColorCodes('&', msg));
                                }
                                else
                                {
                                    p.playSound(p.getLocation(), Sound.valueOf(plugin.getConfig().getString("errorsound")), 1, 2);
                                    p.sendMessage(colorize(plugin.getConfig().getString("prefix")) + " " + colorize(plugin.getConfig().getString("nosyntax")) + " §4</rawmsg [player] [message]>");
                                }
                            }
                            else
                            {
                                p.playSound(p.getLocation(), Sound.valueOf(plugin.getConfig().getString("errorsound")), 1, 2);
                                p.sendMessage(colorize(plugin.getConfig().getString("prefix")) + " §4Player not found.");
                            }
                        }
                    }
    
    Since it is >= is will include the player's name they typed in, but it also does the message now.
     
  5. Offline

    Sheepii

    @JarFile

    You're also going to want to skip over the first argument (arg[0]) as the message will contain the players name if you don't.

    If this is solved, please update your title with the prefix "Solved".
     
  6. Offline

    JarFile

    @Sheepii Ok, then the message won't send to the player it needs to have args[0]
     
  7. Offline

    Sheepii

    Code:
            int argsTillMessage = 0;
            for(String message : args)
            {
                if(argsTillMessage < 2){
                    argsTillMessage++;
                }else{
                   msg = (msg + message + " ");
                }
            }
    
     
Thread Status:
Not open for further replies.

Share This Page