Changing config in game

Discussion in 'Plugin Development' started by jacklin213, Aug 13, 2012.

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

    jacklin213

    this is the code i have at the moment for the onCommand() function
    What i have (open)

    Code:
    public boolean onCommand(CommandSender sender, Command cmd, String commandLabel, String[] args) {
            if (commandLabel.equalsIgnoreCase("sushi")) {
                if (args.length == 1) {
                    // sushi info command (start)
                    if (args[0].equalsIgnoreCase("info")) {
                        sender.sendMessage(ChatColor.DARK_GREEN
                                + "+------------------------------+");
                        sender.sendMessage(ChatColor.DARK_AQUA
                                + "      Sushi: Spawn me Sushi!");
                        sender.sendMessage(ChatColor.GREEN + "      By jacklin213");
                        sender.sendMessage(ChatColor.YELLOW + "      Version: "
                                + pdfFile.getVersion());
                        sender.sendMessage(ChatColor.DARK_GREEN
                                + "+------------------------------+");
                        return true;
                    }
                    // sushi info command (end)
                    // sushi reload command (start)
                    if (args[0].equalsIgnoreCase("reload")) {
                      if  (!sender.hasPermission("sushi.reload")) {
                      sender.sendMessage(ChatColor.RED
                            + "You DO NOT have the permission to do this");     
                    }else{
                        createconfig();
                        loadconfig();
                        this.reloadConfig();
                        sender.sendMessage(ChatColor.RED + "[Sushi]"
                                + ChatColor.GREEN + " Config reloaded!");
                     
                    }
                      return true;
                    }
                    //sushi reload command (end)
                    //sushi help command (start)
                    if (args[0].equalsIgnoreCase("help")) {
                        sender.sendMessage(ChatColor.RED + "Error, Incorrect usage");
                        sender.sendMessage(ChatColor.GREEN + "Correct usage /help sushi");
                        return true;
                    }
                    //sushi help command (end)
                    else{
                    sender.sendMessage(ChatColor.RED + "This is not a valid command !" );
                    sender.sendMessage(ChatColor.GREEN + "Type /help sushi for help");
                }
                    return true;
                }
             
                // end of sushi "" commands
                // Continue to check if the command was typed by a player
                if (!(sender instanceof Player)) {
                    sender.sendMessage("This command can only be used by players");
                    return true;
                }
                if (!sender.hasPermission("sushi.use")) {
                    sender.sendMessage(ChatColor.RED
                            + "You DO NOT have the permission to do this");
                    return true;
                } else {
                    int value = getConfig().getInt("Sushi.RawFishAmount");
                ItemStack itemstack = new ItemStack(Material.RAW_FISH, value );
                Player player = (Player) sender;
                PlayerInventory inventory = player.getInventory();
                inventory.addItem(itemstack);
                sender.sendMessage(ChatColor.BLUE + "You have been givin Fish!");
                return true;
                }
            }
         
         
         
            return false;
        } //End of whole command 


    i want to add a command so when someone does
    /sushi set rawfishamount [amount]
    i realised that right now my code will screw up if ... so hard to explain
    any way heres what i think i should have to get the result ( i know its wrong)
    /sushi set rawfishamount [amount]
    What im adding (open)

    Code:
    if (args.length == 3){
                    if (args[0].equalsIgnoreCase("set")){
                        if (args[1].equalsIgnoreCase("rawfishammount")){
                            if (sender.hasPermission("sushi.setrawfishammount")){
                                String string = args[2];
                                this.getConfig().set("Sushi.RawFishAmmount", string);
                                this.saveConfig();
                                sender.sendMessage("RawFishAmmount set to " + args[2]);
                            }else{
                                sender.sendMessage("Sorry you do not have the permission to do this");
                                return true;
                            }
                        }else{
                            sender.sendMessage(ChatColor.RED + "Not enought arguments, Correct usage /sushi set rawfishammount [ammount]");
                        }
                        }else{
                        sender.sendMessage(ChatColor.RED + "Not enought arguments, Correct usage /sushi set rawfishammount [ammount]");
                    return true;
                    }
                 
                    return true;
                }


    i did get it to work somehow but it had a few glitches and when i went to fix the glitches more came up and so on. In the end i forgot how i did it (look at the code so messy :( )

    plz tell me what im doing wrong

    or can someone provide a different way to set /sushi set rawfishammount

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 27, 2016
  2. Offline

    JOPHESTUS

  3. Offline

    jacklin213

    i seen all of that already i know how to make the config part im just stuck on the command part
     
  4. Offline

    TheSmallBones

    This.getConfig().set("sushi", int);
     
  5. Offline

    jacklin213

    nvm i used the String to int method. but i changed the way of my whole command works.... cause they args[0],args[1] clash together. The string method i used is this

    Code:
    public boolean onCommand (Commandsender sender, Command cmd, String commandLabel, string args[]){
     
      if (commandLabel.equalsIgnoreCase("Basic")){
     
          if (args.length == 1){
     
            if (args[0].equalsIgnoreCase("set")){
     
                String value = args[1];
     
                int rfa = rInteger.parseInt(value);
       
       
    }
     
    }
     
    }[/
    
     
Thread Status:
Not open for further replies.

Share This Page