Solved (Need urgent help) Config help

Discussion in 'Plugin Development' started by Plaze_Demon, Jan 24, 2013.

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

    Plaze_Demon

    My plugin allows a user to type /exchange and it will take an item from there inventory and give them something in return. I want to make this configurable so the user(s) can define what what amount(s) of a/an certain item(s) they can recieve/give and what the item(s) is/are.

    This is my current code (CommandExecutor class):

    Code:
    package com.gmail.zacg99.worthexchange;
     
     
    import org.bukkit.ChatColor;
    import org.bukkit.Material;
    import org.bukkit.command.Command;
    import org.bukkit.command.CommandExecutor;
    import org.bukkit.command.CommandSender;
    import org.bukkit.entity.Player;
    import org.bukkit.inventory.ItemStack;
    import org.bukkit.inventory.PlayerInventory;
     
    public class CommandListener implements CommandExecutor
    {
            @Override     
            public boolean onCommand(CommandSender sender , Command cmd, String label, String[] args)
        {
            Player player = (Player)sender;
            PlayerInventory inventory = player.getInventory();
            ItemStack itemstack2 = new ItemStack(Material.COAL, 64);
            ItemStack itemstack4 = new ItemStack(Material.DIAMOND, 3);
            ItemStack cobble = new ItemStack(Material.COBBLESTONE, 64);
            ItemStack log = new ItemStack(Material.LOG, 10);
            ItemStack gold = new ItemStack(Material.GOLD_INGOT, 12);
            ItemStack iron = new ItemStack(Material.IRON_INGOT, 64);
           
     
                if(cmd.getName().equalsIgnoreCase("exchange")){
                    if(args.length == 1) {
                        if(args[0].equalsIgnoreCase("diamond")) {
                            if (sender instanceof Player){
                   
               
                if(player.hasPermission("itemexchange.diamond")){
                   
                    if (inventory.contains(itemstack2)){
                        inventory.removeItem(itemstack2);
                        inventory.addItem(itemstack4);
                    player.sendMessage(ChatColor.AQUA + "Exchanged 64 coal for 3 diamonds");
                    }
                else player.sendMessage(ChatColor.DARK_RED + "You do not have enough coal!");
                }
            else player.sendMessage(ChatColor.DARK_RED + "You do not have permission!");
                        }}}
                }
               
               
            if(cmd.getName().equalsIgnoreCase("exchange")){
                if(args.length == 1) {
                    if(args[0].equalsIgnoreCase("gold")) {
                        if (sender instanceof Player){
                       
               
                     
                      if(player.hasPermission("itemexchange.gold")){
                        if(inventory.contains(iron)){
                            inventory.removeItem(iron);
                            inventory.addItem(gold);
                            player.sendMessage(ChatColor.AQUA + "Exchanged 64 iron ingots for 12 gold ingots");}
                       
                        else player.sendMessage(ChatColor.DARK_RED + "You do not have enough iron");
                  } else player.sendMessage(ChatColor.DARK_RED + "You do not have permission!");}}}}
           
           
               
            if(cmd.getName().equalsIgnoreCase("exchange")){
                if(args.length == 1) {
                    if(args[0].equalsIgnoreCase("log")) {
                        if (sender instanceof Player){
                       
               
               
                if(player.hasPermission("itemexchange.log")){
                    if(inventory.contains(cobble)){
                        inventory.removeItem(cobble);
                        inventory.addItem(log);
                        player.sendMessage(ChatColor.AQUA +"Exchanged 64 cobblestone for 10 logs. ");
                       
                    } else player.sendMessage(ChatColor.DARK_RED + "You do not have enough log!");
                } else player.sendMessage(ChatColor.DARK_RED + ("You do not have permission!"));
                        }}}
           
     
           
                return true;
            }
       
          return false;
           
    } }
       
       
       
    
    I'm not sure where I would put this.getConfig().getInt/getString("path") and all of that. Can anyone give me a heads up on this, also what would I put in my onEnable?
     
  2. Offline

    chasechocolate

    Getting the Item ID is simple:
    Code:java
    1. int id = this.getConfig().getInt("id");
     
  3. Offline

    raGan.

    You can even get whole ItemStacks
    Code:
    ItemStack is = (ItemStack) this.getConfig().get("key")
    Saving is simple as well
    Code:
    this.getConfig().set("key", is)
     
  4. Offline

    Plaze_Demon

    getConfig() is undefined for the type CommandListener. It's in my CommandExecutor and it's called CommandListener
     
  5. Offline

    raGan.

    Do you understand objects, classes, methods and that kind of stuff ?
     
  6. Offline

    Plaze_Demon

  7. Offline

    Rprrr

    You can only call that from the main class... So you'll have to create an instance of your main class.
     
  8. Offline

    Plaze_Demon

    To be honest, I've never really made constructors and stuff before, my plugin has never needed it, and it would be nice to get some help from some real people rather than reading it from a site, which I find confusing.
     
  9. Offline

    Rprrr

    Alright, well I can't come over to your place, so I guess you'll really have to read it from your screen...
     
  10. Offline

    Plaze_Demon

    You know what I mean . . . not reading a tutorial.
     
  11. Offline

    raGan.

    Wrong answer.
     
  12. Offline

    Plaze_Demon

    Thanks for the 'help' guys :)
     
  13. Offline

    CreeperShift

    Define plugin, make a constructor with your plugin as it's Instance, set this.plugin to your instance, voila plugin.anythingthatyouwouldnormallydoinyourmainclassgoeshere(); will work now.

    If you don't know how to do that, learn Java. Or cheat and look at someone else source-code.
     
  14. Offline

    Rprrr

    I told you exactly what you had to do and yet you did not understand it. So what kind of help did you expect, then? Should we feed you the code?
     
  15. Offline

    raGan.

    We did try, however, if you don't understand basic functionality, you should really go check some tutorials. Giving you the code would only make you return back with another simple problem you can't solve. If you don't know "where to put this" or "how to define method there", you need to step a little back and start again.
     
    Plaze_Demon likes this.
Thread Status:
Not open for further replies.

Share This Page