mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-24 02:56:02 +01:00
Added support for bank accounts
This commit is contained in:
parent
4363198cbb
commit
6f12dd8464
@ -48,9 +48,15 @@ public class Properties {
|
||||
@ConfigurationComment("The economy account which Admin Shops should use and to which all taxes will go")
|
||||
public static String SERVER_ECONOMY_ACCOUNT = "";
|
||||
|
||||
@ConfigurationComment("Whether bank account members (if available) can create shops on its behalf")
|
||||
public static boolean BANK_MEMBERS_ALLOWED = true;
|
||||
|
||||
@ConfigurationComment("Percent of the price that should go to the server's account. (100 = 100 percent)")
|
||||
public static int TAX_AMOUNT = 0;
|
||||
|
||||
@ConfigurationComment("Percent of the price that should go to the server's account when buying from a Bank.")
|
||||
public static int BANK_TAX_AMOUNT = 0;
|
||||
|
||||
@ConfigurationComment("Percent of the price that should go to the server's account when buying from an Admin Shop.")
|
||||
public static int SERVER_TAX_AMOUNT = 0;
|
||||
|
||||
|
@ -35,6 +35,18 @@ public class Economy {
|
||||
return ChestShopSign.isAdminShop(acc);
|
||||
}
|
||||
|
||||
public static boolean isBank(String name) {
|
||||
return name.startsWith(uName.BANK_PREFIX);
|
||||
}
|
||||
|
||||
public static boolean hasBankSupport() {
|
||||
return manager.hasBankSupport();
|
||||
}
|
||||
|
||||
public static boolean bankExists(String name) {
|
||||
return manager.bankExists(name);
|
||||
}
|
||||
|
||||
public static boolean add(String name, double amount) {
|
||||
if (isServerAccount(name)) {
|
||||
if (!getServerAccountName().isEmpty()) {
|
||||
@ -44,7 +56,7 @@ public class Economy {
|
||||
}
|
||||
}
|
||||
|
||||
float taxAmount = isServerAccount(name) ? Properties.SERVER_TAX_AMOUNT : Properties.TAX_AMOUNT;
|
||||
float taxAmount = isServerAccount(name) ? Properties.SERVER_TAX_AMOUNT : isBank(name) ? Properties.BANK_TAX_AMOUNT : Properties.TAX_AMOUNT;
|
||||
|
||||
double tax = getTax(taxAmount, amount);
|
||||
if (tax != 0) {
|
||||
@ -54,7 +66,17 @@ public class Economy {
|
||||
amount -= tax;
|
||||
}
|
||||
|
||||
return manager.add(uName.getName(name), amount);
|
||||
name = uName.getName(name);
|
||||
amount = roundUp(amount);
|
||||
if (isBank(name)) {
|
||||
if (hasBankSupport()) {
|
||||
return manager.bankAdd(uName.stripBankPrefix(name), amount);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return manager.add(name, amount);
|
||||
}
|
||||
}
|
||||
|
||||
public static double getTax(float tax, double price) {
|
||||
@ -70,7 +92,17 @@ public class Economy {
|
||||
}
|
||||
}
|
||||
|
||||
return manager.subtract(uName.getName(name), roundUp(amount));
|
||||
name = uName.getName(name);
|
||||
amount = roundUp(amount);
|
||||
if (isBank(name)) {
|
||||
if (hasBankSupport()) {
|
||||
return manager.bankSubtract(uName.stripBankPrefix(name), amount);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return manager.subtract(name, amount);
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean canHold(String name, double amount) {
|
||||
@ -87,11 +119,23 @@ public class Economy {
|
||||
}
|
||||
|
||||
name = uName.getName(name);
|
||||
|
||||
if (!manager.add(name, amount)) {
|
||||
return false;
|
||||
amount = roundUp(amount);
|
||||
if (isBank(name)) {
|
||||
if (hasBankSupport()) {
|
||||
if (!manager.bankAdd(name, amount)) {
|
||||
return false;
|
||||
} else {
|
||||
manager.bankSubtract(name, amount);
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
manager.subtract(name, amount);
|
||||
if (!manager.add(name, amount)) {
|
||||
return false;
|
||||
} else {
|
||||
manager.subtract(name, amount);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -110,7 +154,17 @@ public class Economy {
|
||||
}
|
||||
}
|
||||
|
||||
return manager.hasEnough(uName.getName(name), roundUp(amount));
|
||||
name = uName.getName(name);
|
||||
amount = roundUp(amount);
|
||||
if (isBank(name)) {
|
||||
if (hasBankSupport()) {
|
||||
return manager.bankHasEnough(uName.stripBankPrefix(name), amount);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return manager.hasEnough(name, amount);
|
||||
}
|
||||
}
|
||||
|
||||
public static double getBalance(String name) {
|
||||
@ -122,13 +176,38 @@ public class Economy {
|
||||
}
|
||||
}
|
||||
|
||||
return manager.balance(uName.getName(name));
|
||||
name = uName.getName(name);
|
||||
if (isBank(name)) {
|
||||
if (hasBankSupport()) {
|
||||
return manager.bankBalance(uName.stripBankPrefix(name));
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
} else {
|
||||
return manager.balance(name);
|
||||
}
|
||||
}
|
||||
|
||||
public static String formatBalance(double amount) {
|
||||
return manager.format(roundUp(amount));
|
||||
}
|
||||
|
||||
public static boolean isBankOwner(String player, String bank) {
|
||||
if (hasBankSupport()) {
|
||||
return manager.isBankOwner(player, bank);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isBankMember(String player, String bank) {
|
||||
if (hasBankSupport()) {
|
||||
return manager.isBankMember(player, bank);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static void setPlugin(EconomyManager plugin) {
|
||||
manager = plugin;
|
||||
}
|
||||
|
@ -35,6 +35,46 @@ public class EconomyManager {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean hasBankSupport() {
|
||||
printError();
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean bankExists(String bank) {
|
||||
printError();
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean bankAdd(String bank, double amount) {
|
||||
printError();
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean bankSubtract(String bank, double amount) {
|
||||
printError();
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean bankHasEnough(String bank, double amount) {
|
||||
printError();
|
||||
return false;
|
||||
}
|
||||
|
||||
public double bankBalance(String bank) {
|
||||
printError();
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isBankOwner(String player, String bank) {
|
||||
printError();
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isBankMember(String player, String bank) {
|
||||
printError();
|
||||
return false;
|
||||
}
|
||||
|
||||
public String format(double amount) {
|
||||
printError();
|
||||
return null;
|
||||
|
@ -36,6 +36,38 @@ public class Register extends EconomyManager {
|
||||
return method.getAccount(player).balance();
|
||||
}
|
||||
|
||||
public boolean hasBankSupport() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean bankExists(String bank) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean bankAdd(String bank, double amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean bankSubtract(String bank, double amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean bankHasEnough(String bank, double amount) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public double bankBalance(String bank) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public boolean isBankOwner(String player, String bank) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isBankMember(String player, String bank) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public String format(double amount) {
|
||||
return method.format(amount);
|
||||
}
|
||||
|
@ -3,6 +3,8 @@ package com.Acrobot.ChestShop.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.RegisteredServiceProvider;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
@ -33,6 +35,43 @@ public class Vault extends EconomyManager {
|
||||
return vaultPlugin.getBalance(player);
|
||||
}
|
||||
|
||||
public boolean hasBankSupport() {
|
||||
return vaultPlugin.hasBankSupport() && !getPluginName().startsWith("iConomy");
|
||||
}
|
||||
|
||||
public boolean bankExists(String bank) {
|
||||
bank = bank.toLowerCase();
|
||||
List<String> banks = vaultPlugin.getBanks();
|
||||
for (String entry : banks) {
|
||||
if (bank.equals(entry.toLowerCase())) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean bankAdd(String bank, double amount) {
|
||||
return vaultPlugin.bankDeposit(bank, amount).transactionSuccess();
|
||||
}
|
||||
|
||||
public boolean bankSubtract(String bank, double amount) {
|
||||
return vaultPlugin.bankWithdraw(bank, amount).transactionSuccess();
|
||||
}
|
||||
|
||||
public boolean bankHasEnough(String bank, double amount) {
|
||||
return vaultPlugin.bankHas(bank, amount).transactionSuccess();
|
||||
}
|
||||
|
||||
public double bankBalance(String bank) {
|
||||
return vaultPlugin.bankBalance(bank).amount;
|
||||
}
|
||||
|
||||
public boolean isBankOwner(String player, String bank) {
|
||||
return vaultPlugin.isBankOwner(bank, player).transactionSuccess();
|
||||
}
|
||||
|
||||
public boolean isBankMember(String player, String bank) {
|
||||
return vaultPlugin.isBankMember(bank, player).transactionSuccess();
|
||||
}
|
||||
|
||||
public String format(double amount) {
|
||||
return vaultPlugin.format(amount);
|
||||
}
|
||||
|
@ -1,5 +1,7 @@
|
||||
package com.Acrobot.ChestShop.Listeners.PreShopCreation;
|
||||
|
||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
import com.Acrobot.ChestShop.Economy.Economy;
|
||||
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
|
||||
import com.Acrobot.ChestShop.Permission;
|
||||
import com.Acrobot.ChestShop.Utils.uName;
|
||||
@ -19,8 +21,24 @@ public class NameChecker implements Listener {
|
||||
public static void onPreShopCreation(PreShopCreationEvent event) {
|
||||
String name = event.getSignLine(NAME_LINE);
|
||||
Player player = event.getPlayer();
|
||||
boolean isBank = name.startsWith(uName.BANK_PREFIX);
|
||||
boolean noAccess;
|
||||
boolean exists;
|
||||
if (isBank) {
|
||||
name = uName.stripBankPrefix(name);
|
||||
exists = Economy.bankExists(name);
|
||||
noAccess = !Economy.hasBankSupport() || !Permission.has(player, Permission.BANK);
|
||||
if (Properties.BANK_MEMBERS_ALLOWED) {
|
||||
noAccess = noAccess || !Economy.isBankMember(player.getName(), name);
|
||||
} else {
|
||||
noAccess = noAccess || !Economy.isBankOwner(player.getName(), name);
|
||||
}
|
||||
} else {
|
||||
noAccess = !uName.canUseName(player, name);
|
||||
exists = Economy.hasAccount(name);
|
||||
}
|
||||
|
||||
if (name.isEmpty() || (!uName.canUseName(player, name) && !Permission.has(player, Permission.ADMIN))) {
|
||||
if (name.isEmpty() || !exists || (noAccess && !Permission.has(player, Permission.ADMIN))) {
|
||||
String shortName = uName.shortenName(player);
|
||||
event.setSignLine(NAME_LINE, shortName);
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ public enum Permission {
|
||||
MOD("ChestShop.mod"),
|
||||
OTHER_NAME("ChestShop.name."),
|
||||
GROUP("ChestShop.group."),
|
||||
BANK("ChestShop.bank"),
|
||||
|
||||
NOFEE("ChestShop.nofee"),
|
||||
DISCOUNT("ChestShop.discount.");
|
||||
|
@ -23,7 +23,7 @@ public class ChestShopSign {
|
||||
public static final byte ITEM_LINE = 3;
|
||||
|
||||
public static final Pattern[] SHOP_SIGN_PATTERN = {
|
||||
Pattern.compile("^[\\w -.]*$"),
|
||||
Pattern.compile("^(" + uName.BANK_PREFIX_QUOTED + ")?[\\w -.]*$"),
|
||||
Pattern.compile("^[1-9][0-9]*$"),
|
||||
Pattern.compile("(?i)^[\\d.bs(free) :]+$"),
|
||||
Pattern.compile("^[\\w #:-]+$")
|
||||
|
@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
@ -14,6 +15,10 @@ public class uName {
|
||||
public static YamlConfiguration config;
|
||||
public static File file;
|
||||
|
||||
public static final String BANK_PREFIX = "$";
|
||||
public static final String BANK_PREFIX_QUOTED = Pattern.quote(BANK_PREFIX);
|
||||
public static final String BANK_PREFIX_REPLACE = "^" + BANK_PREFIX_QUOTED;
|
||||
|
||||
public static String getName(String shortName) {
|
||||
return config.getString(shortName, shortName);
|
||||
}
|
||||
@ -43,6 +48,10 @@ public class uName {
|
||||
return shortenName(player).equals(name) || Permission.otherName(player, name);
|
||||
}
|
||||
|
||||
public static String stripBankPrefix(String name) {
|
||||
return name.replaceFirst(BANK_PREFIX_REPLACE, "");
|
||||
}
|
||||
|
||||
public static void load() {
|
||||
config = YamlConfiguration.loadConfiguration(file);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user