Please help, plugin not working and no errors!

Discussion in 'Spigot Plugin Development' started by ZevoGaems, May 14, 2017.

  1. I have a plugin here to try to be able to do math expressions in-game. I don't know why its not working and when you try to do the command it just says /calculate (num) (type) (num)
    Code (Text):
                } else if(cmd.getName().equalsIgnoreCase("calculate")) {
                    if(args.length > 2) {
                        sender.sendMessage(ChatColor.RED + "/calculate (num) (type) (num)");
                    } else if(args.length < 3) {
                        sender.sendMessage(ChatColor.RED + "/calculate (num) (type) (num)");
                    } else if (args.length < 2) {
                        String type = args[1];
                        String num11 = args[0];
                        String num22 = args[2];
                        int num1 = Integer.parseInt(num11);
                        int num2 = Integer.parseInt(num22);
                        if(type == "+") {
                            int solution = Math.addExact(num1, num2);
                            sender.sendMessage(ChatColor.RED + "The answer is " + solution);
                        } else if(type == "x") {
                            int solution = Math.multiplyExact(num1, num2);
                            sender.sendMessage(ChatColor.RED + "The answer is " + solution);
                        } else if(type == "*") {
                            int solution = (int) (800 * 1.0 / num1 / num2);
                            sender.sendMessage(ChatColor.RED + "The answer is " + solution);
                        } else if(type == "-") {
                            int solution = Math.subtractExact(num1, num2);
                            sender.sendMessage(ChatColor.RED + "The answer is " + solution);
                        }
                    }
                }
     
  2. Code (Text):
    if(args.length > 2) {
                        sender.sendMessage(ChatColor.RED + "/calculate (num) (type) (num)");
                    } else if(args.length < 3) {
                        sender.sendMessage(ChatColor.RED + "/calculate (num) (type) (num)");
                    } else if (args.length < 2) {
    You check if the length is less than three and give the correct usage. Then you process to check if the code is less than two, which would still give the usage message as it is in total less than 3.

    Change it to else if (args.length > 3){ and see if it works.
     
  3. Change which one to (args.length > 3)??? do you want me to replace the if (args.length < 2) { with that?