mirror of
https://github.com/ChestShop-authors/ChestShop-3.git
synced 2024-11-27 04:25:14 +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.CurrencyFormatEvent;
|
||||||
import com.Acrobot.ChestShop.Events.Economy.CurrencySubtractEvent;
|
import com.Acrobot.ChestShop.Events.Economy.CurrencySubtractEvent;
|
||||||
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
import com.Acrobot.ChestShop.Signs.ChestShopSign;
|
||||||
|
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
||||||
import org.bukkit.World;
|
import org.bukkit.World;
|
||||||
import org.bukkit.inventory.Inventory;
|
import org.bukkit.inventory.Inventory;
|
||||||
|
|
||||||
@ -18,12 +19,18 @@ import java.util.UUID;
|
|||||||
* Economy management
|
* Economy management
|
||||||
*/
|
*/
|
||||||
public class Economy {
|
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() {
|
public static String getServerAccountName() {
|
||||||
return Properties.SERVER_ECONOMY_ACCOUNT;
|
return Properties.SERVER_ECONOMY_ACCOUNT;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isOwnerEconomicallyActive(Inventory inventory) {
|
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) {
|
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.math.BigDecimal;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static com.Acrobot.ChestShop.Configuration.Properties.SERVER_ECONOMY_ACCOUNT;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Acrobot
|
* @author Acrobot
|
||||||
*/
|
*/
|
||||||
@ -22,20 +20,12 @@ public class ServerAccountCorrector implements Listener {
|
|||||||
public static void onCurrencyAdd(CurrencyAddEvent event) {
|
public static void onCurrencyAdd(CurrencyAddEvent event) {
|
||||||
UUID target = event.getTarget();
|
UUID target = event.getTarget();
|
||||||
|
|
||||||
if (!NameManager.isAdminShop(target) || SERVER_ECONOMY_ACCOUNT.equals(NameManager.getUsername(target))) {
|
if (!NameManager.isAdminShop(target) || NameManager.isServerEconomyAccount(target)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SERVER_ECONOMY_ACCOUNT.isEmpty()) {
|
Account account = NameManager.getServerEconomyAccount();
|
||||||
event.setAdded(true);
|
target = account != null ? account.getUuid() : null;
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
Account account = NameManager.getAccount(SERVER_ECONOMY_ACCOUNT);
|
|
||||||
if (account == null || account.getUuid() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
target = account.getUuid();
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setAdded(true);
|
event.setAdded(true);
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
@ -50,21 +40,12 @@ public class ServerAccountCorrector implements Listener {
|
|||||||
public static void onCurrencySubtract(CurrencySubtractEvent event) {
|
public static void onCurrencySubtract(CurrencySubtractEvent event) {
|
||||||
UUID target = event.getTarget();
|
UUID target = event.getTarget();
|
||||||
|
|
||||||
if (!NameManager.isAdminShop(target) || SERVER_ECONOMY_ACCOUNT.equals(NameManager.getUsername(target))) {
|
if (!NameManager.isAdminShop(target) || NameManager.isServerEconomyAccount(target)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SERVER_ECONOMY_ACCOUNT.isEmpty()) {
|
Account account = NameManager.getServerEconomyAccount();
|
||||||
event.setSubtracted(true);
|
target = account != null ? account.getUuid() : null;
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
Account account = NameManager.getAccount(SERVER_ECONOMY_ACCOUNT);
|
|
||||||
if (account != null) {
|
|
||||||
target = account.getUuid();
|
|
||||||
} else {
|
|
||||||
target = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
event.setSubtracted(true);
|
event.setSubtracted(true);
|
||||||
if (target == null) {
|
if (target == null) {
|
||||||
@ -78,21 +59,17 @@ public class ServerAccountCorrector implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public static void onCurrencyCheck(CurrencyCheckEvent event) {
|
public static void onCurrencyCheck(CurrencyCheckEvent event) {
|
||||||
UUID target = event.getAccount();
|
UUID target = event.getAccount();
|
||||||
|
|
||||||
if (!NameManager.isAdminShop(target) || SERVER_ECONOMY_ACCOUNT.equals(NameManager.getUsername(target))) {
|
if (!NameManager.isAdminShop(target) || NameManager.isServerEconomyAccount(target)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SERVER_ECONOMY_ACCOUNT.isEmpty()) {
|
Account account = NameManager.getServerEconomyAccount();
|
||||||
|
target = account != null ? account.getUuid() : null;
|
||||||
|
|
||||||
|
if (target == null) {
|
||||||
event.hasEnough(true);
|
event.hasEnough(true);
|
||||||
return;
|
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());
|
CurrencyCheckEvent currencyCheckEvent = new CurrencyCheckEvent(event.getAmount(), target, event.getWorld());
|
||||||
@ -104,8 +81,8 @@ public class ServerAccountCorrector implements Listener {
|
|||||||
@EventHandler(priority = EventPriority.LOWEST)
|
@EventHandler(priority = EventPriority.LOWEST)
|
||||||
public static void onCurrencyHoldCheck(CurrencyHoldEvent event) {
|
public static void onCurrencyHoldCheck(CurrencyHoldEvent event) {
|
||||||
UUID target = event.getAccount();
|
UUID target = event.getAccount();
|
||||||
|
|
||||||
if (!NameManager.isAdminShop(target) || SERVER_ECONOMY_ACCOUNT.equals(NameManager.getUsername(target))) {
|
if (!NameManager.isAdminShop(target) || NameManager.isServerEconomyAccount(target)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,15 +98,12 @@ public class ServerAccountCorrector implements Listener {
|
|||||||
return;
|
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));
|
event.setAmount(BigDecimal.valueOf(Double.MAX_VALUE));
|
||||||
return;
|
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());
|
CurrencyAmountEvent currencyAmountEvent = new CurrencyAmountEvent(target, event.getWorld());
|
||||||
|
@ -33,7 +33,7 @@ public class TaxModule implements Listener {
|
|||||||
|
|
||||||
UUID target = event.getTarget();
|
UUID target = event.getTarget();
|
||||||
|
|
||||||
if (Economy.getServerAccountName().equals(NameManager.getUsername(target))) {
|
if (NameManager.isServerEconomyAccount(target)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,8 +45,11 @@ public class TaxModule implements Listener {
|
|||||||
|
|
||||||
BigDecimal tax = getTax(event.getAmount(), taxAmount);
|
BigDecimal tax = getTax(event.getAmount(), taxAmount);
|
||||||
|
|
||||||
if (!Economy.getServerAccountName().isEmpty()) {
|
if (NameManager.getServerEconomyAccount() != null) {
|
||||||
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(tax, NameManager.getUUID(Economy.getServerAccountName()), event.getWorld());
|
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(
|
||||||
|
tax,
|
||||||
|
NameManager.getServerEconomyAccount().getUuid(),
|
||||||
|
event.getWorld());
|
||||||
ChestShop.callEvent(currencyAddEvent);
|
ChestShop.callEvent(currencyAddEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -45,10 +45,10 @@ public class CreationFeeGetter implements Listener {
|
|||||||
CurrencySubtractEvent subtractionEvent = new CurrencySubtractEvent(BigDecimal.valueOf(shopCreationPrice), player);
|
CurrencySubtractEvent subtractionEvent = new CurrencySubtractEvent(BigDecimal.valueOf(shopCreationPrice), player);
|
||||||
ChestShop.callEvent(subtractionEvent);
|
ChestShop.callEvent(subtractionEvent);
|
||||||
|
|
||||||
if (!Economy.getServerAccountName().isEmpty()) {
|
if (NameManager.getServerEconomyAccount() != null) {
|
||||||
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(
|
CurrencyAddEvent currencyAddEvent = new CurrencyAddEvent(
|
||||||
BigDecimal.valueOf(shopCreationPrice),
|
BigDecimal.valueOf(shopCreationPrice),
|
||||||
NameManager.getUUID(Economy.getServerAccountName()),
|
NameManager.getServerEconomyAccount().getUuid(),
|
||||||
player.getWorld());
|
player.getWorld());
|
||||||
ChestShop.callEvent(currencyAddEvent);
|
ChestShop.callEvent(currencyAddEvent);
|
||||||
}
|
}
|
||||||
|
@ -40,10 +40,10 @@ public class ShopRefundListener implements Listener {
|
|||||||
CurrencyAddEvent currencyEvent = new CurrencyAddEvent(BigDecimal.valueOf(refundPrice), account.getUuid(), event.getSign().getWorld());
|
CurrencyAddEvent currencyEvent = new CurrencyAddEvent(BigDecimal.valueOf(refundPrice), account.getUuid(), event.getSign().getWorld());
|
||||||
ChestShop.callEvent(currencyEvent);
|
ChestShop.callEvent(currencyEvent);
|
||||||
|
|
||||||
if (!Economy.getServerAccountName().isEmpty()) {
|
if (NameManager.getServerEconomyAccount() != null) {
|
||||||
CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(
|
CurrencySubtractEvent currencySubtractEvent = new CurrencySubtractEvent(
|
||||||
BigDecimal.valueOf(refundPrice),
|
BigDecimal.valueOf(refundPrice),
|
||||||
NameManager.getUUID(Economy.getServerAccountName()),
|
NameManager.getServerEconomyAccount().getUuid(),
|
||||||
event.getSign().getWorld());
|
event.getSign().getWorld());
|
||||||
ChestShop.callEvent(currencySubtractEvent);
|
ChestShop.callEvent(currencySubtractEvent);
|
||||||
}
|
}
|
||||||
|
@ -285,6 +285,7 @@ public class NameManager {
|
|||||||
if (!Properties.SERVER_ECONOMY_ACCOUNT.isEmpty()) {
|
if (!Properties.SERVER_ECONOMY_ACCOUNT.isEmpty()) {
|
||||||
serverEconomyAccount = getAccount(Properties.SERVER_ECONOMY_ACCOUNT);
|
serverEconomyAccount = getAccount(Properties.SERVER_ECONOMY_ACCOUNT);
|
||||||
if (serverEconomyAccount == null || serverEconomyAccount.getUuid() == null) {
|
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.");
|
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();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Account getServerEconomyAccount() {
|
||||||
|
return serverEconomyAccount;
|
||||||
|
}
|
||||||
|
|
||||||
private static class SimpleLoadingCache<K, V> {
|
private static class SimpleLoadingCache<K, V> {
|
||||||
private final LinkedHashMap<K, V> map;
|
private final LinkedHashMap<K, V> map;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user