ugh... so many problems.

Discussion in 'Spigot Plugin Development' started by XKid1305, Jun 20, 2016.

  1. this time, for my prefix plugin, the problem is that the command echos back a bunch of crap in chat, and doesnt work right, but i have the boolean return set to true!
    Code (Text):
    name: PrefixesPlus
    main: me.xkid1305.pp.pp
    version: 0.2
    commands:
      prefix:
       description: info about the plugin
       usage: /prefix
           /prefix add - sets your own prefix
           /prefix set - sets someone elses prefix
           /prefix delete - deletes your own prefix
           /prefix remove - deletes someone elses prefix
      prefix add:
       description: sets your own prefix
       usage: /prefix add <prefix>
      prefix delete:
       description: deletes your own prefix
       usage: /prefix delete
      prefix set:
       description: set another player's prefix
       usage: /prefix set <player>
      prefix remove:
       description: delete another player's prefix
       usage: /prefix remove <player>
    permissions:
    prefix.*:
            description: all perms
            default: op
            children:
              prefix.add.others: true
              prefix.delete: true
              prefix.add: true
              prefix.delete.others: true
    prefix.add:
            description: /prefix add <prefix>
            default: op
    prefix.delete:
            description: /prefix delete
            default: op
    prefix.delete.others:
            description: /prefix delete <player>
            default: op
    prefix.add.others:
            description: /prefix add <player>
            default: op
    prefix.info:
            description: /prefix
            default: true
     
    Code (Text):
    package me.xkid1305.pp;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class pp extends JavaPlugin{

       
        public boolean onCommand(Command cmd, CommandSender sender, String commandlabel, String[] args) {
            Player p = (Player) sender;
            if (cmd.getName().equalsIgnoreCase("prefix")) {
                if (p.hasPermission("prefix.info")) {
                    p.sendMessage(ChatColor.GREEN + "PrefixesPlus made by XKid1305");
                    p.sendMessage(ChatColor.GREEN + "Please specify a subcommand.");
                    p.sendMessage(ChatColor.GREEN + "usage: /prefix <command>");
                }
               
            }
            if (args[0].equalsIgnoreCase("prefix add")) {
                if (p.hasPermission("prefix.add")) {
                    if (args.length == 0) {
                        p.sendMessage(ChatColor.RED + "Please enter a prefix.");
                    }
                if (args.length != 0) {
                    p.sendMessage(ChatColor.GREEN + "set prefix to: " + args);
                    p.setDisplayName(args + p.getName());
                }
                }
               
            }
            if (args[0].equalsIgnoreCase("prefix delete")) {
                if (p.hasPermission("prefix.delete")) {
                    p.sendMessage(ChatColor.GREEN + "prefix deleted!");
                    p.setDisplayName(p.getName());
                }
               
            }
            @SuppressWarnings("deprecation")
            Player target = Bukkit.getServer().getPlayer(args[0]);
            if (args[0].equalsIgnoreCase("prefix set")) {
                if (p.hasPermission("prefix.set")) {
                    if (args.length == 0) {
                        p.sendMessage(ChatColor.RED + "Please enter a prefix.");
                    }
                if (args.length != 0) {
                    p.sendMessage(ChatColor.GREEN + "set prefix for " + target.getName() + " to " + args);
                    target.setDisplayName(args + target.getName());
                }
                }
               
            }
                if (args[0].equalsIgnoreCase("prefix remove")) {
                    if (p.hasPermission("prefix.remove")) {
                        p.sendMessage(ChatColor.GREEN + "prefix removed!");
                        target.setDisplayName(p.getName());
                    }
                   
                }
           
            return true;
       
        }
       
       
       
       
       
       
    }
     
     
  2. Define
    Code (Text):
    echos back a bunch of crap
     
  3. /prefif /prefix add - sets your own prefix /prefix set - sets someone elses prefix /prefix delete - deletes your own prefix /prefix remove - deletes someone elses prefix
     
  4. Code (Text):
    if (args[0].equalsIgnoreCase("prefix add")) {
    this is literally impossible.

    'args' is an array of the arguments split by spaces. an argument cant contain a space.
    rn you're checking if they typed "/prefix prefix add" which isn't what you're wanting to do.
     
    • Agree Agree x 1
  5. thanks, ill fix that
     
  6. i fixed it, and i still get the problem.
     
  7. Not sure where to really begin... but I'm 99% sure that you can't have sub commands in the plugin.yml. Second of all, make sure you never use args[0].equalsIgnoreCase("command subcommand"), as args is an array of the sub commands. Getting 0 would give you the first subcommand variable, as 1 is the second etc. The command label is how you get the command itself. Also, I can't tell from the snippet, but make sure you don't use tabs in the plugin.yml, spacing is CRITICAL for the parsing to work properly.
     
  8. thanks for being so nice about it guys, and also im gonna try to fix my code redraskal
     
  9. I assume you were looking on the Bukkit wiki, however, try to stay away from using the usage variable in plugin.yml. You are able to use it, however, not using it properly does lead to huge issues.
     
  10. Your command does not work because you aren't
    quite doing it right.

    You need to check for commands being issued like this:

    CommandLabel label -> Will hold the base command being issued.

    Code (Text):
    if(label.equalsIgnoreCase("Prefix")){
        if(args[0].equalsIgnoreCase("add")){
            // Do Stuff
        } else if(//Another Sub Command){
            // Do More Stuff
        }   // Continue...

    }
    When a player issues a command
    the /Prefix add

    Does not all go into args[0]

    Prefix goes into the CommandLabel
    and that is checked against your registered command in
    your plugin.yml

    and the add goes into args[0]

    same goes for the other sub commands.
     
  11. i made a seperate thread for my new problem, so it isnt a misleading title.
     
  12. Choco

    Moderator

    I'm pretty sure you don't understand the definition of "sequence" in programming. You're also not understanding the explanation I made in your other thread because I explained it as clear as could possibly be. You're checking arguments, (false arguments... you're checking the whole damn command once again, only in the arguments array this time), and you're checking them OUTSIDE of the command check. The first index of args will never equal "prefix add" or any of the other ones you're checking for, so it's just going to return false.

    Also, what in the sweet living hell is this
    We told you in the other thread, if you had listened, that you SHOULD NOT REGISTER ARGUMENTS for a command. Yet, you still seem to think you're right in doing so. You're not. The usage for /prefix should not list all arguments either. It should be something along the lines of this
    Code (Text):
    usage: /<command> <add|delete|set|remove>
    Please... for the love of God... just read up on how to register commands
     
    #13 Choco, Jun 20, 2016
    Last edited: Jun 20, 2016
    • Agree Agree x 1
  13. and there you are being mean again.
     
    • Optimistic Optimistic x 1
  14. also with the
    /prefix <add|remove|delete|set>
    do i still need:
    prefix add:
    description: sets your own prefix
    usage: /prefix add <prefix>
    prefix delete:
    description: deletes your own prefix
    usage: /prefix delete
    prefix set:
    description: set another player's prefix
    usage: /prefix set <player>
    prefix remove:
    description: delete another player's prefix
    usage: /prefix remove <player>
     
  15. You're still not using the correct plugin.yml


    This is an example of my plugin.yml.

    There is ONE command. That command is /settings. It is defined ONCE. The command, however, has over 10 Arguments.


    Code (Text):
    name: ServerSettings
    main: me.es359.com.ServerSettings.ServerSettings
    version: 0.0.1
    description: Plugin allows Administrators to control what aspect of their server is operational.
    author: __ES
    website: Spigot. Soon.

    commands:
      settings:
        description: Main command for plugin.
        aliases: [set,ss]
     
     
  16. Also, I want you to just stop using the usage: option completely. Create your own usage message.
     
  17. plugin.yml:
    Code (Text):
    name: PrefixesPlus
    main: me.xkid1305.pp.pp
    version: 0.2
    commands:
      prefix:
       description: info about the plugin
       aliases: [p,pre,pf,pfix,pref]
    permissions:
    prefix.*:
            description: all perms
            default: op
            children:
              prefix.add.others: true
              prefix.delete: true
              prefix.add: true
              prefix.delete.others: true
    prefix.add:
            description: /prefix add <prefix>
            default: op
    prefix.delete:
            description: /prefix delete
            default: op
    prefix.delete.others:
            description: /prefix delete <player>
            default: op
    prefix.add.others:
            description: /prefix add <player>
            default: op
    prefix.info:
            description: /prefix
            default: true
     
    code:
    Code (Text):
    package me.xkid1305.pp;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    public class pp extends JavaPlugin{

       
        public boolean onCommand(Command cmd, CommandSender sender, String commandlabel, String[] args) {
            Player p = (Player) sender;
            if (cmd.getName().equalsIgnoreCase("prefix")) {
                if (p.hasPermission("prefix.info")) {
                    p.sendMessage(ChatColor.GREEN + "PrefixesPlus made by XKid1305");
                    p.sendMessage(ChatColor.GREEN + "Please specify a subcommand.");
            if (args[0].equalsIgnoreCase("add")) {
                if (p.hasPermission("prefix.add")) {
                    if (args.length == 0) {
                        p.sendMessage(ChatColor.RED + "Please enter a prefix.");
                    }
                if (args.length != 0) {
                    p.sendMessage(ChatColor.GREEN + "set prefix to: " + args);
                    p.setDisplayName(args + p.getName());
                }
                }
               
            }
            if (args[0].equalsIgnoreCase("delete")) {
                if (p.hasPermission("prefix.delete")) {
                    p.sendMessage(ChatColor.GREEN + "prefix deleted!");
                    p.setDisplayName(p.getName());
                }
               
            }
            @SuppressWarnings("deprecation")
            Player target = Bukkit.getServer().getPlayer(args[0]);
            if (args[0].equalsIgnoreCase("set")) {
                if (p.hasPermission("prefix.set")) {
                    if (args.length == 0) {
                        p.sendMessage(ChatColor.RED + "Please enter a prefix.");
                    }
                if (args.length != 0) {
                    p.sendMessage(ChatColor.GREEN + "set prefix for " + target.getName() + " to " + args);
                    target.setDisplayName(args + target.getName());
                }
                }
               
            }
                if (args[0].equalsIgnoreCase("remove")) {
                    if (p.hasPermission("prefix.remove")) {
                        p.sendMessage(ChatColor.GREEN + "prefix removed!");
                        target.setDisplayName(p.getName());
                    }
                   
                }
           

       
        }
       
       
       
            }
            return true;
       
        }
    }
     
     
  18. if (commandlabel.equalsIgnoreCase("prefix")) {
    not
    if (cmd.getName().equalsIgnoreCase("prefix")) {
    sorry