Start economy
This commit is contained in:
@@ -107,7 +107,7 @@ 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 {
|
||||||
if(EconomyOperations.refundOnDelete(sender)) {
|
if(EconomyOperations.refundOnDelete(sender, number)) {
|
||||||
vm.deleteVault(sender, sender.getName(), number);
|
vm.deleteVault(sender, sender.getName(), number);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import java.io.IOException;
|
|||||||
|
|
||||||
import net.milkbowl.vault.economy.EconomyResponse;
|
import net.milkbowl.vault.economy.EconomyResponse;
|
||||||
|
|
||||||
|
import org.bukkit.ChatColor;
|
||||||
import org.bukkit.configuration.InvalidConfigurationException;
|
import org.bukkit.configuration.InvalidConfigurationException;
|
||||||
import org.bukkit.configuration.file.YamlConfiguration;
|
import org.bukkit.configuration.file.YamlConfiguration;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
@@ -14,13 +15,14 @@ import com.drtshock.playervaults.Main;
|
|||||||
|
|
||||||
public class EconomyOperations {
|
public class EconomyOperations {
|
||||||
|
|
||||||
private static String directory = "plugins" + File.separator + "PlayerVaults" + File.separator;
|
private static File configFile;
|
||||||
private static File configFile = new File(directory + "config.yml");
|
|
||||||
private static YamlConfiguration bukkitConfig = new YamlConfiguration();
|
private static YamlConfiguration bukkitConfig = new YamlConfiguration();
|
||||||
|
|
||||||
public Main plugin;
|
public static Main plugin;
|
||||||
|
|
||||||
public EconomyOperations(Main instance) throws FileNotFoundException, IOException, InvalidConfigurationException {
|
public EconomyOperations(Main instance) throws FileNotFoundException, IOException, InvalidConfigurationException {
|
||||||
this.plugin = instance;
|
plugin = instance;
|
||||||
|
configFile = new File(plugin.getDataFolder(), "config.yml");
|
||||||
bukkitConfig.load(configFile);
|
bukkitConfig.load(configFile);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -30,10 +32,29 @@ public class EconomyOperations {
|
|||||||
* @return transaction success
|
* @return transaction success
|
||||||
*/
|
*/
|
||||||
public static boolean payToOpen(Player player) {
|
public static boolean payToOpen(Player player) {
|
||||||
if(!bukkitConfig.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !Main.useVault)
|
if(!bukkitConfig.getBoolean("economy.enabled") || /*player.hasPermission("playervaults.free") || */!Main.useVault)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
double cost = bukkitConfig.getDouble("economy.cost-to-open");
|
double cost = bukkitConfig.getDouble("economy.cost-to-open", 10);
|
||||||
|
EconomyResponse resp = Main.econ.withdrawPlayer(player.getName(), cost);
|
||||||
|
if(resp.transactionSuccess()) {
|
||||||
|
player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_OPEN.toString().replaceAll("%price", "" + cost));
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Have a player pay to create a vault.
|
||||||
|
* Returns true if successful. Otherwise false.
|
||||||
|
* @param player
|
||||||
|
* @return transaction success
|
||||||
|
*/
|
||||||
|
public static boolean payToCreate(Player player) {
|
||||||
|
if(!bukkitConfig.getBoolean("economy.enabled") || /*player.hasPermission("playervaults.free") || */!Main.useVault)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
double cost = bukkitConfig.getDouble("economy.cost-to-create", 100);
|
||||||
EconomyResponse resp = Main.econ.withdrawPlayer(player.getName(), cost);
|
EconomyResponse resp = Main.econ.withdrawPlayer(player.getName(), cost);
|
||||||
if(resp.transactionSuccess()) {
|
if(resp.transactionSuccess()) {
|
||||||
player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_OPEN.toString().replaceAll("%price", "" + cost));
|
player.sendMessage(Lang.TITLE.toString() + Lang.COST_TO_OPEN.toString().replaceAll("%price", "" + cost));
|
||||||
@@ -49,17 +70,31 @@ public class EconomyOperations {
|
|||||||
* @param player
|
* @param player
|
||||||
* @return transaction success.
|
* @return transaction success.
|
||||||
*/
|
*/
|
||||||
public static boolean refundOnDelete(Player player) {
|
public static boolean refundOnDelete(Player player, int number) {
|
||||||
|
String directory = "plugins" + File.separator + "PlayerVaults" + File.separator + "vaults";
|
||||||
|
|
||||||
if(!bukkitConfig.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !Main.useVault)
|
if(!bukkitConfig.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !Main.useVault)
|
||||||
return true;
|
return true;
|
||||||
|
String name = player.getName().toLowerCase();
|
||||||
|
File file = new File(directory + File.separator + name.toLowerCase() + ".yml");
|
||||||
|
YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file);
|
||||||
|
if(file.exists()) {
|
||||||
|
if(playerFile.getString("vault"+number) == null) {
|
||||||
|
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
double cost = bukkitConfig.getDouble("economy.refund-on-delete");
|
double cost = bukkitConfig.getDouble("economy.refund-on-delete");
|
||||||
EconomyResponse resp = Main.econ.depositPlayer(player.getName(), cost);
|
EconomyResponse resp = Main.econ.depositPlayer(player.getName(), cost);
|
||||||
if(resp.transactionSuccess()) {
|
if(resp.transactionSuccess()) {
|
||||||
player.sendMessage(Lang.TITLE.toString() + Lang.REFUND_AMOUNT.toString().replaceAll("%price", "" + cost));
|
player.sendMessage(Lang.TITLE.toString() + Lang.REFUND_AMOUNT.toString().replaceAll("%price", "" + cost));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.INSUFFICIENT_FUNDS);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user