Problem showing item price in TokenShop plugin

Discussion in 'Plugin Development' started by XvXRainbowzZ3D, Jul 18, 2015.

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

    XvXRainbowzZ3D

    Hello everyone,

    I recently made a TokenShop plugin for my server and have decided to make it public, and I needed to add customizable messages in config.

    While adding this I ran into the issue of not being able to replace the %cost placeholder with the item cost as I get a error while trying to use my method to get the item price.

    Here is my getPrice method
    Code:
    public int getPrice(int num) {
            File items = new File(TokenShop.getInstance().getDataFolder(), "items.yml");
            FileConfiguration cfg = YamlConfiguration.loadConfiguration(items);
            int price = cfg.getInt("Shop." + num + ".Price");
            return price;
        }
    and here is the message I am trying to send to the player
    Code:
    if (inv.getTitle().equals(TokenShop.getInstance().getConfig().getString("TokeShop-Inventory-Name"))) {
                    if (e.getRawSlot() == 0) {
                        if (API.getTokens(p) < getPrice(1)) {
                            e.setCancelled(true);
                            p.closeInventory();
                            p.sendMessage(this.prefix + TokenShop.getInstance().getConfig().getString("Not-Enough-Tokens").replaceAll("%cost", getPrice(1)));
                        }
                    }
                }
    Thank you in advance for your help and just ask if you need any more information!
     
    Last edited: Jul 19, 2015
  2. Offline

    arkolly

    You don't need to create the new file items every time you call the message. Just have it as a public variable in your Main class. Then just call it from the main class :) Also, I'm not sure if you need ReplaceAll, try just Replace
     
    mine-care likes this.
  3. Offline

    mine-care

    @arkolly i agree completely! creating, loading, editing, saving is a big load for the server. And yes indeed replaceAll() is for RegEx'es instead replace() is the method needed in this case.
     
Thread Status:
Not open for further replies.

Share This Page