Solved Config Question

Discussion in 'Plugin Development' started by bobthefish, Jul 17, 2014.

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

    bobthefish

    Hi,

    So I am trying to do something with the config that Im not really sure how to explain, so Ill show you my code and my config and try to explain it from there. Basically what I am trying to do is convert from hard coding everything in, to going off of the config file.

    Config file:

    Code:
    Arenas:
      number: 1
      IcyForest:
        price: 0
        world: test
        x: 159.0
        y: 5.0
        z: -979.0
        item: STONE
        color: f
        SlotNumber: 0
    and here is my code for my inventory class and my command class:

    Inventory:

    Code:java
    1. if(e.getSlot() == 0){
    2. e.setCancelled(true);
    3. World w = Bukkit.getWorld("test");
    4. p.teleport(new Location(w, 159, 6, -979));
    5. plugin.playerConfig.set("Players." + p.getName() + ".Arena", "IcyForest");
    6.  
    7. try {
    8. plugin.playerConfig.save(plugin.playerYml);
    9. } catch (IOException ee) {}
    10.  
    11. p.getInventory().clear();
    12. p.getInventory().addItem(pickKit);
    13. p.getInventory().setItem(8, bts);
    14. p.setGameMode(GameMode.SURVIVAL);
    15. }



    Command:

    Code:java
    1. }
    2. else if(args.length == 4){
    3. plugin.getConfig().createSection("Arenas." + args[0]);
    4. plugin.getConfig().set("Arenas." + args[0] + ".price", Integer.parseInt(args[1]));
    5. plugin.getConfig().set("Arenas." + args[0] + ".world", p.getWorld().getName().toString());
    6. plugin.getConfig().set("Arenas." + args[0] + ".x", p.getLocation().getX());
    7. plugin.getConfig().set("Arenas." + args[0] + ".y", p.getLocation().getY());
    8. plugin.getConfig().set("Arenas." + args[0] + ".z", p.getLocation().getZ());
    9. plugin.getConfig().set("Arenas." + args[0] + ".item", args[2]);
    10. plugin.getConfig().set("Arenas." + args[0] + ".color", args[3]);
    11. plugin.getConfig().set("Arenas.number:", plugin.getConfig().getInt("Arenas.number") + 1);
    12. plugin.getConfig().set("Arenas." + args[0] + ".SlotNumber", plugin.getConfig().getInt("Arenas.number") - 1);
    13. plugin.saveConfig();
    14. }



    so I need to be able find which arena in my Config has the Slot number 0, which has 1, and so on... after that, I think i can do the rest...

    Anybody help me?

    Nevermind, I figured it out :p

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

Share This Page