Dynaprice is a very simple economy plugin. It creates a global server shop where players can buy and sell their blocks and items. It doesn't use vault or any built-in economy; instead, it relies on items as currency.
Each time an item is bought, its value increases, and each time an item is sold, its value decreases. Even if prices are poorly set initially, the dynamic pricing will ensure that the price becomes more reasonable.
All items are priced relative to a "currency" item. By default, this item is emerald. At any time, either one item will have the value of a whole number of currency items (for example, one diamond is equivalent to eight emeralds) or a whole number of items will have the value of a single currency item (for example, six steak is equivalent to one emerald). This is similar to the way that villager trades are priced.
Each time a player buys an item, its value increases by one. Each time a player sells an item, its value decreases by one. This means that:
- If a player buys a diamond for eight emeralds, the next diamond would cost nine diamonds.
- If a player sells a diamond chestplate for 24 diamonds, the next diamond chestplate could be sold for 23 diamonds.
- If a player buys six steak for one emerald, the next time, they could buy five steak for one emerald.
- If a player sells 64 wood for one emerald, the next time, they would have to sell 65 wood for one emerald.
- If a player sells a golden apple for one emerald, the next time, they would have to sell two golden apples for an emerald.
Note that the system is more responsive (in terms of % change in value) for items that have values closer to one.
The prices are set up so that the buy-price is always one more than the sell-price. This is to prevent players from making a ton of money by buying items at a low cost and then selling at a high cost repeatedly. If a player buys an item and then sells it back to the shop, they will always break even.
The value command allows you to get the value of an item. You can use it like this:
/value [item name] [amount]
This will give you both the buy-price and the sell-price of your item. If you don't put an item name, you will get the value of whatever is in your hand. If you don't put an amount, it will assume that you want to buy/sell the lowest amount possible. I explain how the amount parameter works below.
The buy command allows you to buy an item. You can use it like this:
/buy [item name] [amount]
This command works exactly like the value command, except that it actually executes the trade. This means that if you use /value and then immediately buy, the price will be the same unless someone else buys/sells the item between your running the value command and the buy command.
The sell command is for selling items. Use it like this:
/sell [item name] [amount]
Again, this command works the same way as the buy command, except instead of taking currency and giving items, it takes items and gives currency. Note that this command can be run right after the buy command. Because the buy-price will be the same as the sell-price, you can essentially "undo" a buy with a sell, losing no money in the process.
All of these commands have an [amount] parameter. This parameter allows a player to specify the amount of the item that they need. It works by repeatedly running the commands, changing the prices each time.
For example, let's say a player wants to buy three diamonds, and the current buy-price of a diamond is eight emeralds:
- They buy one diamond for eight emeralds. The buy-price increases.
- They buy one diamond for nine emeralds. The buy-price increases again.
- They buy one diamond for ten emeralds. The buy-price increases again.
Players do not see the individual steps, so all the player would see is that they bought three diamonds for 27 emeralds and that the price of a diamond is now eleven emeralds. This command also works on the value command.
If the transaction cannot be completed with the number of items specified, the number of items used depends on whether the player is buying or selling. If the player is buying, they will always buy at least the amount specified. If the player is selling, they will always sell at most the amount specified.
For example, let's assume that the sell-price of steak is one emerald for six steak, and a player wishes to sell 64:
- They sell six steak for one emerald. The sell-price decreases.
- They sell seven steak for one emerald. The sell-price decreases again.
- They sell eight steak for one emerald. The sell-price decreases again.
- They sell nine steak for one emerald. The sell-price decreases again.
- They sell ten steak for one emerald. The sell-price decreases again.
- They sell eleven steak for one emerald. The sell-price decreases again.
- They sell twelve steak for one emerald. The sell-price decreases again.
Even though they intended to sell 64, they could only sell 63, because the next transaction would have required thirteen steak. Remember, the player doesn't see these steps, but they can see the price of the entire transaction with the /value command.
For the /sell and /value commands, the player can also use the word "all" instead of the amount. This will sell (or get the value of) every item of that type in the player's inventory.
- /buy diamond
- /buy diamond 3
- /sell goldenapple 2
- /sell golden_apple 2
- /sell golden apple 2 (yes, spaces are allowed)
- /value bed 5
- /value bed all
- /value all (will use item in hand)
- /sell all
If no permissions are specified, all of these default to true.
- dynaprice.buy: allows use of the /buy command
- dynaprice.sell: allows use of the /sell command
- dynaprice.value: allows use of the /value command
All configuration can be done in the config.yml file. Here is an example config.yml:
auto-update: true buy-sell-difference: 1 price-change: 1 currency: name: Emerald bukkit-name: EMERALD items: Oak Wood: bukkit-name: LOG aliases: - Wood value: -64 Spruce Wood: bukkit-name: LOG data: 1 value: -64 Birch Wood: bukkit-name: LOG data: 2 value: -64 Jungle Wood: bukkit-name: LOG data: 3 value: -64 Block of Emerald: bukkit-name: EMERALD_BLOCK static: true value: 9 Diamond: bukkit-name: DIAMOND value: 8 Raw Beef: bukkit-name: RAW_BEEF aliases: - beef value: -9 Steak: bukkit-name: COOKED_BEEF value: -6
If auto-update is true, it will automatically update this plugin on startup.
The buy-sell-difference is the price difference between the buy-price and the sell-price. By default, it is one. This value cannot be less than price-change or it would allow players to make lots of money by repeatedly buying and selling the same item.
The price-change defines how much the price will change after a player buys or sells an item. By default it is one.
This is where you define what item is your server's currency. By default, this is emerald. You must define a name that is displayed to players, as well as the "bukkit-name". The list of Bukkit material names can be found here.
You may optionally add a "data" key, specifying a damage value for the currency item. (For example, if you wanted the currency to be an enchanted golden apple, bukkit-name would be GOLDEN_APPLE and data would be 1.) If you do not add a data value, it defaults to 0.
This is where the bulk of your configuration goes, defining each item that can be bought or sold. Each item has several parts.
The Item Name is how your players will see the name of the item. This is the header for each item, like "Oak Wood" in the example above. No two of these names can be the same. In the default config, these names are generally the in-game names, except for certain items with the same name. (For example, snow blocks and snow layers are both named "Snow," so I use "Snow Layer" to represent the layer version.)
Like I explained in the currency section, the bukkit-name must match a Material name in the Bukkit library.
Here you define the damage value or metadata for your item. For items like wood, the damage value defines the type of wood. It can also be used to define colors, like with wool and stained glass. All damage values are available on the Minecraft Wiki.
You can list aliases for any item here. This can help users find item names more easily. For something like a "Red Mushroom Block," you may also want to accept "Huge Red Mushroom" or even just "Mushroom Block."
This value must be true or false. If it's true, it means that the item's price won't change and that the buy-price will always be equal to the sell-price. (It is unaffected by buy-sell-difference.) In this example, an Emerald Block will always be worth nine emeralds.
This is what determines the buy-price of the item; the sell price is then calculated using buy-sell-difference. If value is positive, it means that the item is worth that much currency. (For example, one diamond can be bought for eight emerald.) If value is negative, it means that that much of the item is worth one currency. (For example, 64 oak wood can be bought for one emerald.)
The default config that comes with this plugin has reasonable starting prices that are based on rarity and usefulness of items. Note that there are some items in there that are unobtainable (bedrock and mob heads) that are priced high, but you may want to remove. There are also some items omitted that are obtainable, but aren't useful unless created by a player (maps and written books) or that just have too many varieties (potions). Change the config however you want, and feel free to give me suggestions for the default values.
MCStats and Updater
I use MCStats to track statistics about the usage of this plugin and Updater to automatically update this plugin. You can opt-out of Updater in the config. MCStats will create a PluginMetrics folder with its own config file where you can opt-out. Neither of these services are harmful to your server in any way, and no intrusive data is collected from your server. Please only opt-out of these services if you have a good reason.
This project's source is available on GitHub.