Solved Issue executing method

Discussion in 'Spigot Plugin Development' started by Sonacabon, May 1, 2017.

Thread Status:
Not open for further replies.
  1. Hey, so basically I have this code (not completely some has been changed but still would cause the same issue) and the Action method will not execute on the server yet there are no console errors or anything at all for that matter. (this is using Spigot 1.8.8)
    Code (Text):

        String face;
        String side;
        public boolean onCommand(CommandSender u, Command cmd, String label, String[] args){
            if(cmd.getName().equalsIgnoreCase("create")){
                if(!(u instanceof Player)){
                    System.out.println("non");
                }else{
                    Player p = (Player) u;
                    if(args.length < 1) p.sendMessage(ChatColor.RED + "You need to specify a message!");
                    float yaw = p.getLocation().getYaw();
                    if (yaw < 0) {
                        yaw += 360;
                    }
                    if (yaw >= 315 || yaw < 45) {
                        face = "South";
                    } else if (yaw < 135) {
                        face = "West";
                    } else if (yaw < 225) {
                        face = "North";
                    } else if (yaw < 315) {
                        face = "East";
                    }
                    List<Character> cp = new ArrayList<Character>();
                    for(int i = 0; i > args.length; i++){
                        if(i >= 1) cp.add(' ');
                        for(int g = 0; g > args.length(); g++){
                            cp.add(args.charAt(g));
                        }
                    }
                    Action(cp, p.getLocation()); //This part doesn't execute
                }
            }
            return true;

        @SuppressWarnings("deprecation")
        public void Action(List<Character> letter, Location loc){
            for(Character l : letter){
                switch(l){
                case 'A':
                    // Any Code placed here will not be executed by the system
                    break;
                default:
                    Bukkit.broadcastMessage("Won't be executed");
                }
            }
        }
     
  2. Are you sure that "letter" has values? Try putting a debug message above the for loop.
    Also your method should not start with a capital letter. Only classes should be capitalized in java.
     
  3. They way I read this the "Action" can only execute if there is a capital A in the string. If it had an A it will break and there will be no message, otherwise it should broadcast won't be executed.

    If you're passing an A? You would see nothing if you're not you should see the message.


    Sent from my iPhone using Tapatalk
     
  4. The A does have some code within it, but for the sake of shorting it I removed it and just showed the basics in general neither of them are actually being executed on the server.
     
  5. It appears you're iterating over the args array twice for some reason, are you passing arguments to the command?


    Sent from my iPhone using Tapatalk
     
  6. I have to iterate through the arguments then the characters within them while aswell adding a space between each of them because I have to use each character separately
     
  7. If your arg was Abc def when you add it to the list would be something like.

    A
    ' '
    b
    ' '
    c
    ' '
    ' '
    d

    Not sure you need to add a space or anything. If you're converting it to a list


    Sent from my iPhone using Tapatalk
     
  8. Not completely sure as to what you're speaking of exactly since the list of characters seems to be fine.
     
  9. The only reason one of those two bits of code would not execute is letter is empty, and the for loop is not running

    Add some debug code and see what the size of letter is before the loop

    Sent from my iPhone using Tapatalk
     
  10. just checked and seems that the letter list is infact empty for what so ever reason as it just outputs "[]" when I broadcast "cp.toString()" so I will have to try different methods to add characters to the list, please let me know if you have an idea of doing it.
     
  11. Thanks for everyone's help, but I just realized the stupid mistake I've made which was during the for loops I used the greater than sign (>) instead of of the less than sign (<)...
     
Thread Status:
Not open for further replies.