Solved Getting Args

Discussion in 'Plugin Development' started by Misteroid, Jun 18, 2015.

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

    Misteroid

    How would I do this?
    I want to create a MineParty plugin that can last for as long as the player started it using /minepartyadmin create <time> How would I get the number that the player inputed for time? I have a layout already setup for the command. Here is my command code:
    Code:
            if (label.equalsIgnoreCase("minepartyadmin")|| label.equalsIgnoreCase("mpa")) {
    
                if (player.hasPermission("BPEssentials.MineParty.Admin")) {
                    if (args.length == 0) {
                        player.sendMessage("§6§lMineParty Help");
                        player.sendMessage("§a/minepartyadmin create §7- §o5(min), 10(min), 15(min), 30(min), 1(hour)");
                        player.sendMessage("§a/minepartyadmin end §7- §oStops current MineParty");
                    }
                    if (args.length == 1) {
                        if (args[1].equalsIgnoreCase("create")) {
                            player.sendMessage("§cInvalid Format try:");
                            player.sendMessage("§a/minepartyadmin create <time> §7- §oInput how long you want the MineParty to last");
                        }
                        if (args[1].equalsIgnoreCase("end")) {
                            Core.plugin.getConfig().set("MineParty" + ".Active",false);
                            Core.plugin.getConfig().set("MineParty." + ".Time", 0);
                            Bukkit.broadcastMessage("§8§l[§b§lMines§8§l] §6§oThe MineParty has ended!");
                            Core.plugin.saveConfig();
                        }
                    }
                    if (args.length == 2) {
                        int time = Core.plugin.getConfig().getInt("MineParty." + ".Time");
                    }
                } else {
                    player.sendMessage("§cYou do not have permission!");
                }
    
            }
     
  2. Offline

    Finn_Bueno_

    in the command /minepartyadmin create <time> , you would get it with args[2]. args[2] is the string the player entered where you put <time>. Hope this helps! :D
     
  3. Offline

    Misteroid

    I know that but HOW do I get what the inputed?
     
  4. Offline

    Lolmewn

    Code:
    if(args.length == 2 && args[0].equalsIgnoreCase("create")){
       try{
            int time = Integer.parseInt(args[1]);
        }catch(NumberFormatException e){
            sender.sendMessage("Time was not a number!");
        }
    }
     
  5. Offline

    Misteroid

    That worked! :) now who do i take that number and put it in my config.yml?

    MineParty:
    Time: <time>

    Here is the updated code
    Code:
            if (label.equalsIgnoreCase("minepartyadmin")|| label.equalsIgnoreCase("mpa")) {
                if (player.hasPermission("BPEssentials.MineParty.Admin")) {
                    if (args.length == 0) {
                        player.sendMessage("§6§lMineParty Help");
                        player.sendMessage("§a/minepartyadmin create §7- §o5(min), 10(min), 15(min), 30(min), 1(hour)");
                        player.sendMessage("§a/minepartyadmin end §7- §oStops current MineParty");
                    }
                    if (args.length == 1) {
                        if (args[0].equalsIgnoreCase("create")) {
                            player.sendMessage("§cInvalid Format try:");
                            player.sendMessage("§a/minepartyadmin create <time> §7- §oInput how long you want the MineParty to last");
                        }
                        if (args[0].equalsIgnoreCase("end")) {
                            Core.plugin.getConfig().set("MineParty" + ".Active",false);
                            Core.plugin.getConfig().set("MineParty." + ".Time", 0);
                            Bukkit.broadcastMessage("§8§l[§b§lMines§8§l] §6§oThe MineParty has ended!");
                            Core.plugin.saveConfig();
                        }
                    }
                    if (args.length == 2 && args[0].equalsIgnoreCase("create")) {
                        int time = Core.plugin.getConfig().getInt("MineParty." + ".Time");
                        try{
                            int timetest = Integer.parseInt(args[1]);
                           
                        }catch(NumberFormatException e){
                            player.sendMessage("That was not a number!");
                        }
                    }
                } else {
                    player.sendMessage("§cYou do not have permission!");
                }
    
            }
     
  6. Offline

    Lolmewn

  7. Offline

    Misteroid

    Will do!

    I have got it working! Thanks @Lolmewn!

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 12, 2016
Thread Status:
Not open for further replies.

Share This Page