Configs

Discussion in 'Plugin Development' started by Cooper PluginDev, Apr 12, 2014.

Thread Status:
Not open for further replies.
  1. I've made a plugin where you can create a Arena and such.
    So what I want it to do is when you create a arena but selecting two areas it saves it to a config.
    I've made a config I just don't know how I save the information to a config?
     
  2. Offline

    kreashenz

    Setting:
    Code:
    getConfig().set("path", object);
    Saving:
    Code:
    try {
        getConfig().save(File);
    }
    catch(IOException e) {
        e.printStackTrace();
    }
     
  3. Offline

    coasterman10

    kreashenz Saving is better done with:
    Code:
    saveConfig();
     
    kreashenz likes this.
  4. kreashenz
    getConfig and object aren't methods?
     
  5. Offline

    kreashenz

    coasterman10 Sorry haha I had a blank moment then, I completely forgot about that.
    Cooper PluginDev Are you accessing the config.yml through a different class? Then use plugin.getConfig() or whatever your Main class' variable is. And object can be anything you're trying to set in the config path.
     
  6. kreashenz
    My main class is called "main"
    So I would do "main.getConfig" but this doesn't work?
     
  7. Offline

    kreashenz

    Cooper PluginDev Have you made a constructor setting the variable?
    Code:
    private Main main;
     
    public <Class>(Main main) {
        this.main = main;
    }
    Then you can use main.getConfig()
     
  8. kreashenz
    k. Well how do I add it like. I've got all that and then done "saveconfig" etc. But how do I actually specify it. So when I reload the server the region stays.
     
  9. Offline

    kreashenz

    Cooper PluginDev Just save it then when you want to get it go
    Code:
    main.getConfig().getString("Path to string");
    // or
    main.getConfig().getInt("path to int");
    It's fairly simple, actually.
     
  10. kreashenz
    I've got this, it says "interal error has occured" when I try to make the arena with the command.
    Code:
    Code:java
    1. } else if (args[0].equalsIgnoreCase("create")) {
    2. if (p.hasPermission("SuperHeroes.admin")) {
    3.  
    4. Selection sel = getWorldEdit().getSelection(p);
    5.  
    6. if (sel == null) {
    7. p.sendMessage(ChatColor.BLUE + "Arena> " + ChatColor.GRAY + "You must make a selection.");
    8. return true;
    9. }
    10.  
    11. ProtectedCuboidRegion region = new ProtectedCuboidRegion(
    12. "supersmash_" + p.getName(),
    13. new BlockVector(sel.getNativeMinimumPoint()),
    14. new BlockVector(sel.getNativeMaximumPoint())
    15. );
    16.  
    17.  
    18.  
    19. DefaultDomain owners = new DefaultDomain();
    20. owners.addPlayer(getWorldGuard().wrapPlayer(p));
    21.  
    22.  
    23.  
    24. region.setOwners(owners);
    25.  
    26. getWorldGuard().getRegionManager(p.getWorld()).addRegion(region);
    27.  
    28. main.getConfig().getString("Region Location:");
    29. main.saveConfig();
    30.  
    31.  
    32. p.sendMessage(ChatColor.BLUE + "Arena> " + ChatColor.GRAY + "Create Arena with the ID: " + ChatColor.GREEN + region.getId() + ChatColor.GRAY + ".");
    33. }


    My config.yml:
    Code:java
    1. Region Location:
     
  11. Offline

    kreashenz

    What are you trying to do? I see the "main.getConfig().getString("Region Location:")" but that's not how you do it. Create a setter
    Code:
    public void setRegionLocation(Location loc) {
        main.getConfig().set("region location.world", loc.getWorld().getName());
        main.getConfig().set("region location.x", loc.getBlockX());
    // do ^ for y and z
        main.saveConfig();
    }
    And getting
    Code:
    public Location getRegionLocation() {
        return new Location(Bukkit.getWorld(main.getConfig().getString("region location.world")), main.getConfig().getInt("region location.x"), //x and y);
    }
     
  12. kreashenz
    Ok what I'm trying to do is thus.
    When a player creates a arena (region) by typing /arena create it creates the region. The problem is, when you reload/restart the server the region isn't there anymore. So I figured I need to save my data in a config file. So when a player creates a region it stores it in a file.
     
  13. Offline

    kreashenz

    Cooper PluginDev Alright.. What you'd need to do:
    Get the two locations of it (max and min)
    Set each in the config like I showed ^^ (with different paths of course, maybe region.<name>.min and region.<name>.max)
    Save the config
    When the server loads, run a method that loads up all the regions

    Do you want me to try and give you code for that?
     
  14. Offline

    Areoace

    Stop helping this kid, he's learning nothing, copying and pasting your code without you getting any credit or profit.
     
    blackknight11 likes this.
Thread Status:
Not open for further replies.

Share This Page