Mirror von
https://github.com/TheSilentPro/HeadDB.git
synchronisiert 2024-12-27 11:20:05 +01:00
Implement basic economy using Vault.
Prices for heads can be set for each category in the config file.
Dieser Commit ist enthalten in:
Ursprung
267bb78cf3
Commit
7a9b974c77
7
pom.xml
7
pom.xml
@ -68,6 +68,13 @@
|
|||||||
<artifactId>anvilgui</artifactId>
|
<artifactId>anvilgui</artifactId>
|
||||||
<version>1.5.0-SNAPSHOT</version>
|
<version>1.5.0-SNAPSHOT</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<!-- Vault -->
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.github.MilkBowl</groupId>
|
||||||
|
<artifactId>VaultAPI</artifactId>
|
||||||
|
<version>1.7</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -13,12 +13,15 @@ import tsp.headdb.listener.MenuListener;
|
|||||||
import tsp.headdb.util.Log;
|
import tsp.headdb.util.Log;
|
||||||
import tsp.headdb.util.Metrics;
|
import tsp.headdb.util.Metrics;
|
||||||
import tsp.headdb.util.Utils;
|
import tsp.headdb.util.Utils;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
public class HeadDB extends JavaPlugin {
|
public class HeadDB extends JavaPlugin {
|
||||||
|
|
||||||
private static HeadDB instance;
|
private static HeadDB instance;
|
||||||
private Config config;
|
private Config config;
|
||||||
private Json playerdata;
|
private Json playerdata;
|
||||||
|
private Economy economy = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@ -28,6 +31,17 @@ public class HeadDB extends JavaPlugin {
|
|||||||
config = LightningBuilder.fromPath("config.yml", "plugins/HeadDB").createConfig().addDefaultsFromInputStream();
|
config = LightningBuilder.fromPath("config.yml", "plugins/HeadDB").createConfig().addDefaultsFromInputStream();
|
||||||
playerdata = LightningBuilder.fromPath("playerdata.json", "plugins/HeadDB").createJson();
|
playerdata = LightningBuilder.fromPath("playerdata.json", "plugins/HeadDB").createJson();
|
||||||
|
|
||||||
|
if (config.getBoolean("economy.enable"))
|
||||||
|
{
|
||||||
|
Log.debug("Starting economy...");
|
||||||
|
this.economy = this.setupEconomy();
|
||||||
|
if (this.economy == null) {
|
||||||
|
Log.error("Economy support requires Vault and an economy provider plugin.");
|
||||||
|
} else {
|
||||||
|
Log.info("Economy provider: " + this.economy.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Log.debug("Starting metrics...");
|
Log.debug("Starting metrics...");
|
||||||
new Metrics(this, Utils.METRICS_ID);
|
new Metrics(this, Utils.METRICS_ID);
|
||||||
|
|
||||||
@ -52,6 +66,15 @@ public class HeadDB extends JavaPlugin {
|
|||||||
Log.info("Done!");
|
Log.info("Done!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Economy setupEconomy() {
|
||||||
|
if (!this.getServer().getPluginManager().isPluginEnabled("Vault")) return null;
|
||||||
|
|
||||||
|
RegisteredServiceProvider<Economy> economyProvider = this.getServer().getServicesManager().getRegistration(Economy.class);
|
||||||
|
if (economyProvider == null) return null;
|
||||||
|
|
||||||
|
return this.economy = economyProvider.getProvider();
|
||||||
|
}
|
||||||
|
|
||||||
public Config getCfg() {
|
public Config getCfg() {
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
@ -64,4 +87,7 @@ public class HeadDB extends JavaPlugin {
|
|||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Economy getEconomy() {
|
||||||
|
return this.economy;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,14 @@ import org.bukkit.event.inventory.ClickType;
|
|||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
import org.bukkit.inventory.ItemStack;
|
import org.bukkit.inventory.ItemStack;
|
||||||
import org.bukkit.inventory.meta.ItemMeta;
|
import org.bukkit.inventory.meta.ItemMeta;
|
||||||
|
import tsp.headdb.HeadDB;
|
||||||
import tsp.headdb.api.Head;
|
import tsp.headdb.api.Head;
|
||||||
import tsp.headdb.api.HeadAPI;
|
import tsp.headdb.api.HeadAPI;
|
||||||
import tsp.headdb.api.LocalHead;
|
import tsp.headdb.api.LocalHead;
|
||||||
import tsp.headdb.database.Category;
|
import tsp.headdb.database.Category;
|
||||||
import tsp.headdb.util.Utils;
|
import tsp.headdb.util.Utils;
|
||||||
import tsp.headdb.util.XMaterial;
|
import tsp.headdb.util.XMaterial;
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
@ -27,13 +29,11 @@ public class InventoryUtils {
|
|||||||
for (LocalHead localHead : heads) {
|
for (LocalHead localHead : heads) {
|
||||||
pane.addButton(new Button(localHead.getItemStack(), e -> {
|
pane.addButton(new Button(localHead.getItemStack(), e -> {
|
||||||
if (e.getClick() == ClickType.SHIFT_LEFT) {
|
if (e.getClick() == ClickType.SHIFT_LEFT) {
|
||||||
ItemStack item = localHead.getItemStack();
|
purchaseItem(player, localHead.getItemStack(), 64, "local", localHead.getName());
|
||||||
item.setAmount(64);
|
|
||||||
player.getInventory().addItem(item);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (e.getClick() == ClickType.LEFT) {
|
if (e.getClick() == ClickType.LEFT) {
|
||||||
player.getInventory().addItem(localHead.getItemStack());
|
purchaseItem(player, localHead.getItemStack(), 1, "local", localHead.getName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (e.getClick() == ClickType.RIGHT) {
|
if (e.getClick() == ClickType.RIGHT) {
|
||||||
@ -53,13 +53,11 @@ public class InventoryUtils {
|
|||||||
for (Head head : heads) {
|
for (Head head : heads) {
|
||||||
pane.addButton(new Button(head.getItemStack(), e -> {
|
pane.addButton(new Button(head.getItemStack(), e -> {
|
||||||
if (e.getClick() == ClickType.SHIFT_LEFT) {
|
if (e.getClick() == ClickType.SHIFT_LEFT) {
|
||||||
ItemStack item = head.getItemStack();
|
purchaseItem(player, head.getItemStack(), 64, head.getCategory().getName(), head.getName());
|
||||||
item.setAmount(64);
|
|
||||||
player.getInventory().addItem(item);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (e.getClick() == ClickType.LEFT) {
|
if (e.getClick() == ClickType.LEFT) {
|
||||||
player.getInventory().addItem(head.getItemStack());
|
purchaseItem(player, head.getItemStack(), 1, head.getCategory().getName(), head.getName());
|
||||||
}
|
}
|
||||||
if (e.getClick() == ClickType.RIGHT) {
|
if (e.getClick() == ClickType.RIGHT) {
|
||||||
HeadAPI.removeFavoriteHead(player.getUniqueId(), head.getId());
|
HeadAPI.removeFavoriteHead(player.getUniqueId(), head.getId());
|
||||||
@ -79,13 +77,11 @@ public class InventoryUtils {
|
|||||||
for (Head head : heads) {
|
for (Head head : heads) {
|
||||||
pane.addButton(new Button(head.getItemStack(), e -> {
|
pane.addButton(new Button(head.getItemStack(), e -> {
|
||||||
if (e.getClick() == ClickType.SHIFT_LEFT) {
|
if (e.getClick() == ClickType.SHIFT_LEFT) {
|
||||||
ItemStack item = head.getItemStack();
|
purchaseItem(player, head.getItemStack(), 64, head.getCategory().getName(), head.getName());
|
||||||
item.setAmount(64);
|
|
||||||
player.getInventory().addItem(item);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (e.getClick() == ClickType.LEFT) {
|
if (e.getClick() == ClickType.LEFT) {
|
||||||
player.getInventory().addItem(head.getItemStack());
|
purchaseItem(player, head.getItemStack(), 1, head.getCategory().getName(), head.getName());
|
||||||
}
|
}
|
||||||
if (e.getClick() == ClickType.RIGHT) {
|
if (e.getClick() == ClickType.RIGHT) {
|
||||||
HeadAPI.addFavoriteHead(player.getUniqueId(), head.getId());
|
HeadAPI.addFavoriteHead(player.getUniqueId(), head.getId());
|
||||||
@ -105,13 +101,11 @@ public class InventoryUtils {
|
|||||||
for (Head head : heads) {
|
for (Head head : heads) {
|
||||||
pane.addButton(new Button(head.getItemStack(), e -> {
|
pane.addButton(new Button(head.getItemStack(), e -> {
|
||||||
if (e.getClick() == ClickType.SHIFT_LEFT) {
|
if (e.getClick() == ClickType.SHIFT_LEFT) {
|
||||||
ItemStack item = head.getItemStack();
|
purchaseItem(player, head.getItemStack(), 64, head.getCategory().getName(), head.getName());
|
||||||
item.setAmount(64);
|
|
||||||
player.getInventory().addItem(item);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (e.getClick() == ClickType.LEFT) {
|
if (e.getClick() == ClickType.LEFT) {
|
||||||
player.getInventory().addItem(head.getItemStack());
|
purchaseItem(player, head.getItemStack(), 1, head.getCategory().getName(), head.getName());
|
||||||
}
|
}
|
||||||
if (e.getClick() == ClickType.RIGHT) {
|
if (e.getClick() == ClickType.RIGHT) {
|
||||||
HeadAPI.addFavoriteHead(player.getUniqueId(), head.getId());
|
HeadAPI.addFavoriteHead(player.getUniqueId(), head.getId());
|
||||||
@ -130,13 +124,11 @@ public class InventoryUtils {
|
|||||||
for (Head head : heads) {
|
for (Head head : heads) {
|
||||||
pane.addButton(new Button(head.getItemStack(), e -> {
|
pane.addButton(new Button(head.getItemStack(), e -> {
|
||||||
if (e.getClick() == ClickType.SHIFT_LEFT) {
|
if (e.getClick() == ClickType.SHIFT_LEFT) {
|
||||||
ItemStack item = head.getItemStack();
|
purchaseItem(player, head.getItemStack(), 64, head.getCategory().getName(), head.getName());
|
||||||
item.setAmount(64);
|
|
||||||
player.getInventory().addItem(item);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (e.getClick() == ClickType.LEFT) {
|
if (e.getClick() == ClickType.LEFT) {
|
||||||
player.getInventory().addItem(head.getItemStack());
|
purchaseItem(player, head.getItemStack(), 1, head.getCategory().getName(), head.getName());
|
||||||
}
|
}
|
||||||
if (e.getClick() == ClickType.RIGHT) {
|
if (e.getClick() == ClickType.RIGHT) {
|
||||||
HeadAPI.addFavoriteHead(player.getUniqueId(), head.getId());
|
HeadAPI.addFavoriteHead(player.getUniqueId(), head.getId());
|
||||||
@ -222,4 +214,26 @@ public class InventoryUtils {
|
|||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void purchaseItem(Player player, ItemStack item, int amount, String costCfg, String description) {
|
||||||
|
Economy economy = HeadDB.getInstance().getEconomy();
|
||||||
|
if (economy != null) {
|
||||||
|
double cost = amount * HeadDB.getInstance().getCfg().getDouble("economy.cost." + costCfg);
|
||||||
|
if (cost > 0) {
|
||||||
|
if (economy.has(player, cost)) {
|
||||||
|
economy.withdrawPlayer(player, cost);
|
||||||
|
player.sendMessage(String.format("You purchased %d x %s for %.2f %s!", amount, description, cost, economy.currencyNamePlural()));
|
||||||
|
} else {
|
||||||
|
player.sendMessage(String.format("You do not have enough %s to purchase %d x %s.", economy.currencyNamePlural(), amount, description));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
player.sendMessage(String.format("You purchased %d x %s for free!", amount, description));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
item.setAmount(amount);
|
||||||
|
player.getInventory().addItem(item);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,5 +7,21 @@ asyncStartup: false
|
|||||||
# If the cached heads are older than these amount of seconds, the plugin will refresh the database
|
# If the cached heads are older than these amount of seconds, the plugin will refresh the database
|
||||||
refresh: 3600
|
refresh: 3600
|
||||||
|
|
||||||
|
# Economy options
|
||||||
|
economy:
|
||||||
|
enable: false
|
||||||
|
cost:
|
||||||
|
alphabet: 100
|
||||||
|
animals: 100
|
||||||
|
blocks: 100
|
||||||
|
decoration: 100
|
||||||
|
food-drinks: 100
|
||||||
|
humans: 100
|
||||||
|
humanoid: 100
|
||||||
|
miscellaneous: 100
|
||||||
|
monsters: 100
|
||||||
|
plants: 100
|
||||||
|
local: 1000
|
||||||
|
|
||||||
# Debug Mode
|
# Debug Mode
|
||||||
debug: false
|
debug: false
|
@ -3,6 +3,7 @@ description: ${project.description}
|
|||||||
|
|
||||||
main: tsp.headdb.HeadDB
|
main: tsp.headdb.HeadDB
|
||||||
version: ${project.version}
|
version: ${project.version}
|
||||||
|
softdepend: [Vault]
|
||||||
api-version: 1.16
|
api-version: 1.16
|
||||||
author: Silent
|
author: Silent
|
||||||
|
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren