Solved Set Rank Prices in Config

Discussion in 'Spigot Plugin Development' started by glasseater84, Jun 18, 2016.

  1. Hey guys,

    I've been making a rank shop plugin ingame to comply with the EULA. My only question is how do I make custom prices for the ranks?

    So I have this method but it always removes 50000.

    Code (Text):
      public static void buyRank(String name) {
        int coins = 0;
        if (c.isSet(name + ".coins")) {
          coins = c.getInt(name + ".coins");
        }
        c.set(name + ".coins", Integer.valueOf(coins - 50000));
        save()
      }
    c = private static FileConfiguration c;
    Now how would could I create it so that it gets the price from the config which looks like this

    Code (Text):
    FARMER: (PRICE HERE)
    HUNTER: (PRICE HERE)
    KNIGHT: (PRICE HERE)
    WIZARD: (PRICE HERE)
    OVERLORD: (PRICE HERE)


    And that would go in the current config
     
  2. Just make a FileConfiguration variable. with a value of YamlConfiguration#loadConfiguration(File)
    Then just use it like you would the methods from getConfig()
     
  3. "It's always 50000":
    Code (Text):
    c.set(name + ".coins", Integer.valueOf(coins - 50000));
     
  4. Is name the player's name? You should use their UUID instead as all their data won't be theirs anymore if they change their name.
     
  5. I know thats the reason why, but how can I change that to get the price from the config?
     
  6. coins - config.getInt("path.to.price")
     
  7. How would I use that for multiple ranks though?
     
  8. I already told you how to set this up last time you had problems with this plugin. Make an Enum for each rank so you can make rank specific methods and what not.
     
  9. Oh yeah you did! My fault just did it now, slightly different but same idea and it worked! Thanks!
     
    • Like Like x 1