added Vault support
This commit is contained in:
parent
ba4ab654b2
commit
db945616f2
BIN
lib/Vault.jar
Normal file
BIN
lib/Vault.jar
Normal file
Binary file not shown.
@ -2,3 +2,4 @@ name: Blacksmith
|
||||
author: aPunch
|
||||
version: 1.0
|
||||
main: net.apunch.blacksmith.Blacksmith
|
||||
depend: [Citizens, Vault]
|
@ -7,13 +7,17 @@ import net.apunch.blacksmith.util.Settings.Setting;
|
||||
|
||||
import net.citizensnpcs.api.CitizensAPI;
|
||||
import net.citizensnpcs.api.util.DataKey;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.bukkit.enchantments.Enchantment;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
public class Blacksmith extends JavaPlugin {
|
||||
private Settings config;
|
||||
private Economy economy;
|
||||
|
||||
@Override
|
||||
public void onDisable() {
|
||||
@ -27,6 +31,12 @@ public class Blacksmith extends JavaPlugin {
|
||||
config = new Settings(this);
|
||||
config.load();
|
||||
|
||||
// Setup Vault
|
||||
RegisteredServiceProvider<Economy> economyProvider = getServer().getServicesManager().getRegistration(
|
||||
Economy.class);
|
||||
if (economyProvider != null)
|
||||
economy = economyProvider.getProvider();
|
||||
|
||||
CitizensAPI.getCharacterManager().register(BlacksmithCharacter.class);
|
||||
|
||||
getLogger().log(Level.INFO, " v" + getDescription().getVersion() + " enabled.");
|
||||
@ -97,7 +107,19 @@ public class Blacksmith extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
public double getCost(ItemStack item) {
|
||||
public boolean doesPlayerHaveEnough(Player player) {
|
||||
return economy.getBalance(player.getName()) - getCost(player.getItemInHand()) >= 0;
|
||||
}
|
||||
|
||||
public String formatCost(Player player) {
|
||||
return economy.format(getCost(player.getItemInHand()));
|
||||
}
|
||||
|
||||
public void withdraw(Player player) {
|
||||
economy.withdrawPlayer(player.getName(), getCost(player.getItemInHand()));
|
||||
}
|
||||
|
||||
private double getCost(ItemStack item) {
|
||||
DataKey root = config.getConfig().getKey("");
|
||||
double price = Setting.BASE_PRICE.asDouble();
|
||||
if (root.keyExists("base-prices." + item.getType().name().toLowerCase().replace('_', '-')))
|
||||
|
@ -119,7 +119,7 @@ public class BlacksmithCharacter extends Character {
|
||||
return;
|
||||
}
|
||||
session = new RepairSession(player, npc);
|
||||
npc.chat(player, costMsg.replace("<price>", String.valueOf(plugin.getCost(hand))).replace("<item>",
|
||||
npc.chat(player, costMsg.replace("<price>", plugin.formatCost(player)).replace("<item>",
|
||||
hand.getType().name().toLowerCase().replace('_', ' ')));
|
||||
}
|
||||
}
|
||||
@ -152,6 +152,7 @@ public class BlacksmithCharacter extends Character {
|
||||
|
||||
private void reforge(NPC npc, Player player) {
|
||||
npc.chat(player, startReforgeMsg);
|
||||
plugin.withdraw(player);
|
||||
session.setTask(plugin.getServer().getScheduler().scheduleAsyncDelayedTask(plugin,
|
||||
new ReforgeTask(npc, player), (new Random().nextInt(maxReforgeDelay) + minReforgeDelay) * 20));
|
||||
if (npc.getBukkitEntity() instanceof Player)
|
||||
|
@ -27,7 +27,7 @@ public class RepairSession {
|
||||
npc.chat(player, "<c>That's not the item you wanted to reforge before!");
|
||||
return true;
|
||||
}
|
||||
if (plugin.getCost(player.getItemInHand()) < 0 /* TODO hasEnough */) {
|
||||
if (!plugin.doesPlayerHaveEnough(player)) {
|
||||
npc.chat(player, ((BlacksmithCharacter) npc.getCharacter()).getInsufficientFundsMessage());
|
||||
return true;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user