mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-23 10:35:15 +01:00
Fix errors when server economy account is not defined or invalid
This commit is contained in:
parent
4075b2e38a
commit
29ef7f25aa
@ -7,6 +7,7 @@ import com.Acrobot.ChestShop.Events.Economy.CurrencyCheckEvent;
|
||||
import com.Acrobot.ChestShop.Events.Economy.CurrencyFormatEvent;
|
||||
import com.Acrobot.ChestShop.Events.Economy.CurrencySubtractEvent;
|
||||
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
||||
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
|
||||
@ -18,12 +19,18 @@ import java.util.UUID;
|
||||
* Economy management
|
||||
*/
|
||||
public class Economy {
|
||||
/**
|
||||
* Get the name of the server conomy account
|
||||
* @return The username of te server economy account
|
||||
* @deprecated Use {@link NameManager#getServerEconomyAccount()} or {@link Properties#SERVER_ECONOMY_ACCOUNT}
|
||||
*/
|
||||
@Deprecated
|
||||
public static String getServerAccountName() {
|
||||
return Properties.SERVER_ECONOMY_ACCOUNT;
|
||||
}
|
||||
|
||||
public static boolean isOwnerEconomicallyActive(Inventory inventory) {
|
||||
return !ChestShopSign.isAdminShop(inventory) || !getServerAccountName().isEmpty();
|
||||
return !ChestShopSign.isAdminShop(inventory) || NameManager.getServerEconomyAccount() != null;
|
||||
}
|
||||
|
||||
public static boolean add(UUID name, World world, double amount) {
|
||||
|
@ -11,8 +11,6 @@ import org.bukkit.event.Listener;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.UUID;
|
||||
|
||||
import static com.Acrobot.ChestShop.Configuration.Properties.SERVER_ECONOMY_ACCOUNT;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
@ -22,20 +20,12 @@ public class ServerAccountCorrector implements Listener {
|
||||
public static void onCurrencyAdd(CurrencyAddEvent event) {
|
||||
UUID target = event.getTarget();
|
||||
|
||||
if (!NameManager.isAdminShop(target) || SERVER_ECONOMY_ACCOUNT.equals(NameManager.getUsername(target))) {
|
||||
if (!NameManager.isAdminShop(target) || NameManager.isServerEconomyAccount(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SERVER_ECONOMY_ACCOUNT.isEmpty()) {
|
||||
event.setAdded(true);
|
||||
return;
|
||||
} else {
|
||||
Account account = NameManager.getAccount(SERVER_ECONOMY_ACCOUNT);
|
||||
if (account == null || account.getUuid() == null) {
|
||||
return;
|
||||
}
|
||||
target = account.getUuid();
|
||||
}
|
||||
Account account = NameManager.getServerEconomyAccount();
|
||||
target = account != null ? account.getUuid() : null;
|
||||
|
||||
event.setAdded(true);
|
||||
if (target == null) {
|
||||
@ -50,21 +40,12 @@ public class ServerAccountCorrector implements Listener {
|
||||
public static void onCurrencySubtract(CurrencySubtractEvent event) {
|
||||
UUID target = event.getTarget();
|
||||
|
||||
if (!NameManager.isAdminShop(target) || SERVER_ECONOMY_ACCOUNT.equals(NameManager.getUsername(target))) {
|
||||
if (!NameManager.isAdminShop(target) || NameManager.isServerEconomyAccount(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SERVER_ECONOMY_ACCOUNT.isEmpty()) {
|
||||
event.setSubtracted(true);
|
||||
return;
|
||||
} else {
|
||||
Account account = NameManager.getAccount(SERVER_ECONOMY_ACCOUNT);
|
||||
if (account != null) {
|
||||
target = account.getUuid();
|
||||
} else {
|
||||
target = null;
|
||||
}
|
||||
}
|
||||
|
||||
Account account = NameManager.getServerEconomyAccount();
|
||||
target = account != null ? account.getUuid() : null;
|
||||
|
||||
event.setSubtracted(true);
|
||||
if (target == null) {
|
||||
@ -78,21 +59,17 @@ public class ServerAccountCorrector implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public static void onCurrencyCheck(CurrencyCheckEvent event) {
|
||||
UUID target = event.getAccount();
|
||||
|
||||
if (!NameManager.isAdminShop(target) || SERVER_ECONOMY_ACCOUNT.equals(NameManager.getUsername(target))) {
|
||||
|
||||
if (!NameManager.isAdminShop(target) || NameManager.isServerEconomyAccount(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SERVER_ECONOMY_ACCOUNT.isEmpty()) {
|
||||
Account account = NameManager.getServerEconomyAccount();
|
||||
target = account != null ? account.getUuid() : null;
|
||||
|
||||
if (target == null) {
|
||||
event.hasEnough(true);
|
||||
return;
|
||||
} else {
|
||||
Account account = NameManager.getAccount(SERVER_ECONOMY_ACCOUNT);
|
||||
if (account == null || account.getUuid() == null) {
|
||||
event.hasEnough(true);
|
||||
return;
|
||||
}
|
||||
target = account.getUuid();
|
||||
}
|
||||
|
||||
CurrencyCheckEvent currencyCheckEvent = new CurrencyCheckEvent(event.getAmount(), target, event.getWorld());
|
||||
@ -104,8 +81,8 @@ public class ServerAccountCorrector implements Listener {
|
||||
@EventHandler(priority = EventPriority.LOWEST)
|
||||
public static void onCurrencyHoldCheck(CurrencyHoldEvent event) {
|
||||
UUID target = event.getAccount();
|
||||
|
||||
if (!NameManager.isAdminShop(target) || SERVER_ECONOMY_ACCOUNT.equals(NameManager.getUsername(target))) {
|
||||
|
||||
if (!NameManager.isAdminShop(target) || NameManager.isServerEconomyAccount(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -121,15 +98,12 @@ public class ServerAccountCorrector implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (SERVER_ECONOMY_ACCOUNT.isEmpty()) {
|
||||
Account account = NameManager.getServerEconomyAccount();
|
||||
target = account != null ? account.getUuid() : null;
|
||||
|
||||
if (target == null) {
|
||||
event.setAmount(BigDecimal.valueOf(Double.MAX_VALUE));
|
||||
return;
|
||||
} else {
|
||||
Account account = NameManager.getAccount(SERVER_ECONOMY_ACCOUNT);
|
||||
if (account == null || account.getUuid() == null) {
|
||||
return;
|
||||
}
|
||||
target = account.getUuid();
|
||||
}
|
||||
|
||||
CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(target, event.getWorld());
|
||||
|
@ -33,7 +33,7 @@ public class TaxModule implements Listener {
|
||||
|
||||
UUID target = event.getTarget();
|
||||
|
||||
if (Economy.getServerAccountName().equals(NameManager.getUsername(target))) {
|
||||
if (NameManager.isServerEconomyAccount(target)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@ -45,8 +45,11 @@ public class TaxModule implements Listener {
|
||||
|
||||
BigDecimal tax = getTax(event.getAmount(), taxAmount);
|
||||
|
||||
if (!Economy.getServerAccountName().isEmpty()) {
|
||||
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(tax, NameManager.getUUID(Economy.getServerAccountName()), event.getWorld());
|
||||
if (NameManager.getServerEconomyAccount() != null) {
|
||||
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(
|
||||
tax,
|
||||
NameManager.getServerEconomyAccount().getUuid(),
|
||||
event.getWorld());
|
||||
ChestShop.callEvent(currencyAddEvent);
|
||||
}
|
||||
|
||||
|
@ -45,10 +45,10 @@ public class CreationFeeGetter implements Listener {
|
||||
CurrencySubtractEvent subtractionEvent = new CurrencySubtractEvent(BigDecimal.valueOf(shopCreationPrice), player);
|
||||
ChestShop.callEvent(subtractionEvent);
|
||||
|
||||
if (!Economy.getServerAccountName().isEmpty()) {
|
||||
if (NameManager.getServerEconomyAccount() != null) {
|
||||
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(
|
||||
BigDecimal.valueOf(shopCreationPrice),
|
||||
NameManager.getUUID(Economy.getServerAccountName()),
|
||||
NameManager.getServerEconomyAccount().getUuid(),
|
||||
player.getWorld());
|
||||
ChestShop.callEvent(currencyAddEvent);
|
||||
}
|
||||
|
@ -40,10 +40,10 @@ public class ShopRefundListener implements Listener {
|
||||
CurrencyAddEvent currencyEvent = new CurrencyAddEvent(BigDecimal.valueOf(refundPrice), account.getUuid(), event.getSign().getWorld());
|
||||
ChestShop.callEvent(currencyEvent);
|
||||
|
||||
if (!Economy.getServerAccountName().isEmpty()) {
|
||||
if (NameManager.getServerEconomyAccount() != null) {
|
||||
CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(
|
||||
BigDecimal.valueOf(refundPrice),
|
||||
NameManager.getUUID(Economy.getServerAccountName()),
|
||||
NameManager.getServerEconomyAccount().getUuid(),
|
||||
event.getSign().getWorld());
|
||||
ChestShop.callEvent(currencySubtractEvent);
|
||||
}
|
||||
|
@ -285,6 +285,7 @@ public class NameManager {
|
||||
if (!Properties.SERVER_ECONOMY_ACCOUNT.isEmpty()) {
|
||||
serverEconomyAccount = getAccount(Properties.SERVER_ECONOMY_ACCOUNT);
|
||||
if (serverEconomyAccount == null || serverEconomyAccount.getUuid() == null) {
|
||||
serverEconomyAccount = null;
|
||||
ChestShop.getBukkitLogger().log(Level.WARNING, "Server economy account setting '" + Properties.SERVER_ECONOMY_ACCOUNT + "' doesn't seem to be the name of a known player! Please log in at least once in order for the server economy account to work.");
|
||||
}
|
||||
}
|
||||
@ -292,7 +293,11 @@ public class NameManager {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static Account getServerEconomyAccount() {
|
||||
return serverEconomyAccount;
|
||||
}
|
||||
|
||||
private static class SimpleLoadingCache<K, V> {
|
||||
private final LinkedHashMap<K, V> map;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user