Add economy support. Update to 2.1.1
Not tested at all!
This commit is contained in:
@@ -4,3 +4,12 @@
|
|||||||
# Whether or not you want to check for updates.
|
# Whether or not you want to check for updates.
|
||||||
# Will not download an update, that is your job :)
|
# Will not download an update, that is your job :)
|
||||||
check-update: true
|
check-update: true
|
||||||
|
|
||||||
|
# Settings here are for economy integration.
|
||||||
|
economy:
|
||||||
|
enabled: false
|
||||||
|
|
||||||
|
# Cost to create a vault. You can give players playervaults.free to bypass this.
|
||||||
|
cost-to-create: 100
|
||||||
|
cost-to-open: 10
|
||||||
|
refund-on-delete: 50
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
# Use & for color codes.
|
# Use & for color codes.
|
||||||
# %p is where the player name will get inserted.
|
# %p is where the player name will get inserted.
|
||||||
# %v is where the vault number will get inserted.
|
# %v is where the vault number will get inserted.
|
||||||
|
# %price is the price.
|
||||||
# Made with love :)
|
# Made with love :)
|
||||||
title-name: "&4[&fPlayerVaults&4]: "
|
title-name: "&4[&fPlayerVaults&4]: "
|
||||||
open-vault: "&fOpening vault &a%v"
|
open-vault: "&fOpening vault &a%v"
|
||||||
@@ -12,3 +13,7 @@ must-be-number: "&cYou need to specify a number between 1-99"
|
|||||||
invalid-args: "&cInvalid args!"
|
invalid-args: "&cInvalid args!"
|
||||||
delete-vault-error: "&cError deleting vault :("
|
delete-vault-error: "&cError deleting vault :("
|
||||||
no-permissions: "&cYou don't have permission for that!"
|
no-permissions: "&cYou don't have permission for that!"
|
||||||
|
insufficient-funds: "&cYou don't have enough money for that!"
|
||||||
|
refund-amount: "&fYou were refunded &a%price &ffor deleting that vault."
|
||||||
|
cost-to-create: "&fYou were charged &c%price &ffor creating that vault."
|
||||||
|
cost-to-open: "&fYou were charged &c%price &ffor opening that vault."
|
||||||
|
|||||||
+2
-1
@@ -1,8 +1,9 @@
|
|||||||
name: PlayerVaults
|
name: PlayerVaults
|
||||||
main: com.drtshock.playervaults.Main
|
main: com.drtshock.playervaults.Main
|
||||||
authors: [drtshock, gomeow, chester]
|
authors: [drtshock, gomeow, chester]
|
||||||
version: 2.1.0
|
version: 2.1.1
|
||||||
website: http://dev.bukkit.org/server-mods/PlayerVaults
|
website: http://dev.bukkit.org/server-mods/PlayerVaults
|
||||||
|
softdepend: Vault
|
||||||
commands:
|
commands:
|
||||||
pv:
|
pv:
|
||||||
description: Open a vault with /vault <number>
|
description: Open a vault with /vault <number>
|
||||||
|
|||||||
@@ -6,7 +6,10 @@ import java.io.IOException;
|
|||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
|
|
||||||
|
import net.milkbowl.vault.economy.Economy;
|
||||||
|
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
|
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
|
||||||
import com.drtshock.playervaults.commands.Commands;
|
import com.drtshock.playervaults.commands.Commands;
|
||||||
@@ -22,6 +25,7 @@ public class Main extends JavaPlugin {
|
|||||||
public static boolean update = false;
|
public static boolean update = false;
|
||||||
public static String name = "";
|
public static String name = "";
|
||||||
Commands commands;
|
Commands commands;
|
||||||
|
public static Economy econ = null;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
@@ -44,6 +48,7 @@ public class Main extends JavaPlugin {
|
|||||||
commands = new Commands();
|
commands = new Commands();
|
||||||
getCommand("pv").setExecutor(commands);
|
getCommand("pv").setExecutor(commands);
|
||||||
getCommand("pvdel").setExecutor(commands);
|
getCommand("pvdel").setExecutor(commands);
|
||||||
|
setupEconomy();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startMetrics() {
|
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() {
|
public void loadConfig() {
|
||||||
File config = new File(getDataFolder() + File.separator + "config.yml");
|
File config = new File(getDataFolder() + File.separator + "config.yml");
|
||||||
if(!config.exists()) {
|
if(!config.exists()) {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import org.bukkit.command.CommandSender;
|
|||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import com.drtshock.playervaults.Main;
|
import com.drtshock.playervaults.Main;
|
||||||
|
import com.drtshock.playervaults.util.EconomyOperations;
|
||||||
import com.drtshock.playervaults.util.Lang;
|
import com.drtshock.playervaults.util.Lang;
|
||||||
import com.drtshock.playervaults.util.VaultManager;
|
import com.drtshock.playervaults.util.VaultManager;
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ public class VaultOperations {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* TODO: Change how permissions are checked here.
|
* TODO: Change how permissions are checked here.
|
||||||
*/
|
*/
|
||||||
@@ -37,9 +39,14 @@ public class VaultOperations {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if(checkPerms(sender, number)) {
|
if(checkPerms(sender, number)) {
|
||||||
vm.loadVault(sender, sender.getName(), number);
|
if(EconomyOperations.payToOpen(sender)) {
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.OPEN_VAULT.toString().replace("%v", arg));
|
vm.loadVault(sender, sender.getName(), number);
|
||||||
return true;
|
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 {
|
} else {
|
||||||
Feedback.noPerms(sender);
|
Feedback.noPerms(sender);
|
||||||
}
|
}
|
||||||
@@ -49,7 +56,6 @@ public class VaultOperations {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static boolean openOtherVault(Player sender, String user, String arg) {
|
public static boolean openOtherVault(Player sender, String user, String arg) {
|
||||||
if(sender.hasPermission("playervaults.admin")) {
|
if(sender.hasPermission("playervaults.admin")) {
|
||||||
if(arg.matches("^[0-9]{1,2}$")) {
|
if(arg.matches("^[0-9]{1,2}$")) {
|
||||||
@@ -72,6 +78,7 @@ public class VaultOperations {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteOwnVault(Player sender, String arg) {
|
public static void deleteOwnVault(Player sender, String arg) {
|
||||||
if(arg.matches("^[0-9]{1,2}$")) {
|
if(arg.matches("^[0-9]{1,2}$")) {
|
||||||
int number = 0;
|
int number = 0;
|
||||||
@@ -82,7 +89,10 @@ public class VaultOperations {
|
|||||||
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER);
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
vm.deleteVault(sender, sender.getName(), number);
|
if(EconomyOperations.refundOnDelete(sender)) {
|
||||||
|
vm.deleteVault(sender, sender.getName(), number);
|
||||||
|
return;
|
||||||
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT_ERROR);
|
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);
|
sender.sendMessage(Lang.TITLE.toString()+ Lang.MUST_BE_NUMBER);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void deleteOtherVault(CommandSender sender, String user, String arg) {
|
public static void deleteOtherVault(CommandSender sender, String user, String arg) {
|
||||||
if(sender.hasPermission("playervaults.delete")) {
|
if(sender.hasPermission("playervaults.delete")) {
|
||||||
if(arg.matches("^[0-9]{1,2}$")) {
|
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"),
|
PLAYER_ONLY("player-only"),
|
||||||
MUST_BE_NUMBER("must-be-number"),
|
MUST_BE_NUMBER("must-be-number"),
|
||||||
DELETE_VAULT_ERROR("delete-vault-error"),
|
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 String path = "";
|
||||||
private static YamlConfiguration lang;
|
private static YamlConfiguration lang;
|
||||||
|
|||||||
Reference in New Issue
Block a user