Add economy support. Update to 2.1.1
Not tested at all!
This commit is contained in:
@@ -6,7 +6,10 @@ import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
|
||||
import com.drtshock.playervaults.commands.Commands;
|
||||
@@ -22,6 +25,7 @@ public class Main extends JavaPlugin {
|
||||
public static boolean update = false;
|
||||
public static String name = "";
|
||||
Commands commands;
|
||||
public static Economy econ = null;
|
||||
|
||||
@Override
|
||||
public void onEnable() {
|
||||
@@ -44,6 +48,7 @@ public class Main extends JavaPlugin {
|
||||
commands = new Commands();
|
||||
getCommand("pv").setExecutor(commands);
|
||||
getCommand("pvdel").setExecutor(commands);
|
||||
setupEconomy();
|
||||
}
|
||||
|
||||
public void startMetrics() {
|
||||
@@ -55,6 +60,18 @@ public class Main extends JavaPlugin {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean setupEconomy() {
|
||||
if (getServer().getPluginManager().getPlugin("Vault") == null) {
|
||||
return false;
|
||||
}
|
||||
RegisteredServiceProvider<Economy> rsp = getServer().getServicesManager().getRegistration(Economy.class);
|
||||
if (rsp == null) {
|
||||
return false;
|
||||
}
|
||||
econ = rsp.getProvider();
|
||||
return econ != null;
|
||||
}
|
||||
|
||||
public void loadConfig() {
|
||||
File config = new File(getDataFolder() + File.separator + "config.yml");
|
||||
if(!config.exists()) {
|
||||
|
||||
@@ -7,6 +7,7 @@ import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.drtshock.playervaults.Main;
|
||||
import com.drtshock.playervaults.util.EconomyOperations;
|
||||
import com.drtshock.playervaults.util.Lang;
|
||||
import com.drtshock.playervaults.util.VaultManager;
|
||||
|
||||
@@ -23,6 +24,7 @@ public class VaultOperations {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
* TODO: Change how permissions are checked here.
|
||||
*/
|
||||
@@ -37,9 +39,14 @@ public class VaultOperations {
|
||||
return false;
|
||||
}
|
||||
if(checkPerms(sender, number)) {
|
||||
vm.loadVault(sender, sender.getName(), number);
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.OPEN_VAULT.toString().replace("%v", arg));
|
||||
return true;
|
||||
if(EconomyOperations.payToOpen(sender)) {
|
||||
vm.loadVault(sender, sender.getName(), number);
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.OPEN_VAULT.toString().replace("%v", arg));
|
||||
return true;
|
||||
} else {
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.INSUFFICIENT_FUNDS);
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
Feedback.noPerms(sender);
|
||||
}
|
||||
@@ -49,7 +56,6 @@ public class VaultOperations {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public static boolean openOtherVault(Player sender, String user, String arg) {
|
||||
if(sender.hasPermission("playervaults.admin")) {
|
||||
if(arg.matches("^[0-9]{1,2}$")) {
|
||||
@@ -72,6 +78,7 @@ public class VaultOperations {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void deleteOwnVault(Player sender, String arg) {
|
||||
if(arg.matches("^[0-9]{1,2}$")) {
|
||||
int number = 0;
|
||||
@@ -82,7 +89,10 @@ public class VaultOperations {
|
||||
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
||||
}
|
||||
try {
|
||||
vm.deleteVault(sender, sender.getName(), number);
|
||||
if(EconomyOperations.refundOnDelete(sender)) {
|
||||
vm.deleteVault(sender, sender.getName(), number);
|
||||
return;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT_ERROR);
|
||||
}
|
||||
@@ -90,6 +100,7 @@ public class VaultOperations {
|
||||
sender.sendMessage(Lang.TITLE.toString()+ Lang.MUST_BE_NUMBER);
|
||||
}
|
||||
}
|
||||
|
||||
public static void deleteOtherVault(CommandSender sender, String user, String arg) {
|
||||
if(sender.hasPermission("playervaults.delete")) {
|
||||
if(arg.matches("^[0-9]{1,2}$")) {
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package com.drtshock.playervaults.util;
|
||||
|
||||
import net.milkbowl.vault.economy.EconomyResponse;
|
||||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import com.drtshock.playervaults.Main;
|
||||
|
||||
public class EconomyOperations {
|
||||
|
||||
public Main plugin;
|
||||
private static FileConfiguration config;
|
||||
|
||||
public EconomyOperations(Main instance) {
|
||||
this.plugin = instance;
|
||||
EconomyOperations.config = plugin.getConfig();
|
||||
}
|
||||
|
||||
|
||||
public static boolean payToOpen(Player player) {
|
||||
if(!config.getBoolean("economy.enabled") || player.hasPermission("playervaults.free"))
|
||||
return true;
|
||||
|
||||
double cost = config.getDouble("economy.cost-to-open");
|
||||
EconomyResponse resp = Main.econ.withdrawPlayer(player.getName(), cost);
|
||||
if(resp.transactionSuccess()) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_OPEN.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean payToMake(Player player) {
|
||||
if(!config.getBoolean("economy.enabled") || player.hasPermission("playervaults.free"))
|
||||
return true;
|
||||
|
||||
double cost = config.getDouble("economy.cost-to-create");
|
||||
EconomyResponse resp = Main.econ.withdrawPlayer(player.getName(), cost);
|
||||
if(resp.transactionSuccess()) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_CREATE.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean refundOnDelete(Player player) {
|
||||
if(!config.getBoolean("economy.enabled") || player.hasPermission("playervaults.free"))
|
||||
return true;
|
||||
|
||||
double cost = config.getDouble("economy.refund-on-delete");
|
||||
EconomyResponse resp = Main.econ.depositPlayer(player.getName(), cost);
|
||||
if(resp.transactionSuccess()) {
|
||||
player.sendMessage(Lang.TITLE.toString() + Lang.REFUND_AMOUNT.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,11 @@ public enum Lang {
|
||||
PLAYER_ONLY("player-only"),
|
||||
MUST_BE_NUMBER("must-be-number"),
|
||||
DELETE_VAULT_ERROR("delete-vault-error"),
|
||||
NO_PERMS("no-permissions");
|
||||
NO_PERMS("no-permissions"),
|
||||
INSUFFICIENT_FUNDS("insufficient-funds"),
|
||||
REFUND_AMOUNT("refund-amount"),
|
||||
COST_TO_CREATE("cost-to-create"),
|
||||
COST_TO_OPEN("cost-to-open");
|
||||
|
||||
private String path = "";
|
||||
private static YamlConfiguration lang;
|
||||
|
||||
Reference in New Issue
Block a user