mirror of
https://github.com/EpicEricEE/ShopChest.git
synced 2024-11-08 11:50:14 +01:00
Fixed support for multi-world economy plugins
This commit is contained in:
parent
57e57dc71e
commit
48eda92079
@ -440,7 +440,7 @@ class ShopCommand implements CommandExecutor {
|
|||||||
|
|
||||||
double creationPrice = (shopType == ShopType.NORMAL) ? plugin.getShopChestConfig().shop_creation_price_normal : plugin.getShopChestConfig().shop_creation_price_admin;
|
double creationPrice = (shopType == ShopType.NORMAL) ? plugin.getShopChestConfig().shop_creation_price_normal : plugin.getShopChestConfig().shop_creation_price_admin;
|
||||||
if (creationPrice > 0) {
|
if (creationPrice > 0) {
|
||||||
if (plugin.getEconomy().getBalance(p) < creationPrice) {
|
if (plugin.getEconomy().getBalance(p, p.getWorld().getName()) < creationPrice) {
|
||||||
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_CREATE_NOT_ENOUGH_MONEY, new LocalizedMessage.ReplacedPlaceholder(Placeholder.CREATION_PRICE, String.valueOf(creationPrice))));
|
p.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.SHOP_CREATE_NOT_ENOUGH_MONEY, new LocalizedMessage.ReplacedPlaceholder(Placeholder.CREATION_PRICE, String.valueOf(creationPrice))));
|
||||||
plugin.debug(p.getName() + " can not pay the creation price");
|
plugin.debug(p.getName() + " can not pay the creation price");
|
||||||
return;
|
return;
|
||||||
|
@ -824,12 +824,14 @@ public class ShopInteractListener implements Listener {
|
|||||||
int amount = shop.getProduct().getAmount();
|
int amount = shop.getProduct().getAmount();
|
||||||
if (stack) amount = shop.getProduct().getMaxStackSize();
|
if (stack) amount = shop.getProduct().getMaxStackSize();
|
||||||
|
|
||||||
|
String worldName = shop.getLocation().getWorld().getName();
|
||||||
|
|
||||||
double price = shop.getBuyPrice();
|
double price = shop.getBuyPrice();
|
||||||
if (stack) price = (price / shop.getProduct().getAmount()) * amount;
|
if (stack) price = (price / shop.getProduct().getAmount()) * amount;
|
||||||
|
|
||||||
if (econ.getBalance(executor) >= price || config.auto_calculate_item_amount) {
|
if (econ.getBalance(executor, worldName) >= price || config.auto_calculate_item_amount) {
|
||||||
|
|
||||||
int amountForMoney = (int) (amount / price * econ.getBalance(executor));
|
int amountForMoney = (int) (amount / price * econ.getBalance(executor, worldName));
|
||||||
|
|
||||||
if (amountForMoney == 0 && config.auto_calculate_item_amount) {
|
if (amountForMoney == 0 && config.auto_calculate_item_amount) {
|
||||||
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NOT_ENOUGH_MONEY));
|
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.NOT_ENOUGH_MONEY));
|
||||||
@ -879,8 +881,6 @@ public class ShopInteractListener implements Listener {
|
|||||||
ItemStack newProduct = new ItemStack(product);
|
ItemStack newProduct = new ItemStack(product);
|
||||||
newProduct.setAmount(newAmount);
|
newProduct.setAmount(newAmount);
|
||||||
|
|
||||||
String worldName = shop.getLocation().getWorld().getName();
|
|
||||||
|
|
||||||
EconomyResponse r = econ.withdrawPlayer(executor, worldName, newPrice);
|
EconomyResponse r = econ.withdrawPlayer(executor, worldName, newPrice);
|
||||||
|
|
||||||
if (r.transactionSuccess()) {
|
if (r.transactionSuccess()) {
|
||||||
@ -892,8 +892,8 @@ public class ShopInteractListener implements Listener {
|
|||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
econ.depositPlayer(executor, newPrice);
|
econ.depositPlayer(executor, worldName, newPrice);
|
||||||
econ.withdrawPlayer(shop.getVendor(), newPrice);
|
econ.withdrawPlayer(shop.getVendor(), worldName, newPrice);
|
||||||
plugin.debug("Buy event cancelled (#" + shop.getID() + ")");
|
plugin.debug("Buy event cancelled (#" + shop.getID() + ")");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -920,14 +920,14 @@ public class ShopInteractListener implements Listener {
|
|||||||
} else {
|
} else {
|
||||||
plugin.debug("Economy transaction failed (r2): " + r2.errorMessage + " (#" + shop.getID() + ")");
|
plugin.debug("Economy transaction failed (r2): " + r2.errorMessage + " (#" + shop.getID() + ")");
|
||||||
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedPlaceholder(Placeholder.ERROR, r2.errorMessage)));
|
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedPlaceholder(Placeholder.ERROR, r2.errorMessage)));
|
||||||
econ.depositPlayer(executor, newPrice);
|
econ.depositPlayer(executor, worldName, newPrice);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ShopBuySellEvent event = new ShopBuySellEvent(executor, shop, ShopBuySellEvent.Type.BUY, newAmount, newPrice);
|
ShopBuySellEvent event = new ShopBuySellEvent(executor, shop, ShopBuySellEvent.Type.BUY, newAmount, newPrice);
|
||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
econ.depositPlayer(executor, newPrice);
|
econ.depositPlayer(executor, worldName, newPrice);
|
||||||
plugin.debug("Buy event cancelled (#" + shop.getID() + ")");
|
plugin.debug("Buy event cancelled (#" + shop.getID() + ")");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -967,8 +967,10 @@ public class ShopInteractListener implements Listener {
|
|||||||
double price = shop.getSellPrice();
|
double price = shop.getSellPrice();
|
||||||
if (stack) price = (price / shop.getProduct().getAmount()) * amount;
|
if (stack) price = (price / shop.getProduct().getAmount()) * amount;
|
||||||
|
|
||||||
if (econ.getBalance(shop.getVendor()) >= price || shop.getShopType() == ShopType.ADMIN || config.auto_calculate_item_amount) {
|
String worldName = shop.getLocation().getWorld().getName();
|
||||||
int amountForMoney = (int) (amount / price * econ.getBalance(shop.getVendor()));
|
|
||||||
|
if (econ.getBalance(shop.getVendor(), worldName) >= price || shop.getShopType() == ShopType.ADMIN || config.auto_calculate_item_amount) {
|
||||||
|
int amountForMoney = (int) (amount / price * econ.getBalance(shop.getVendor(), worldName));
|
||||||
|
|
||||||
plugin.debug("Vendor has enough money for " + amountForMoney + " item(s) (#" + shop.getID() + ")");
|
plugin.debug("Vendor has enough money for " + amountForMoney + " item(s) (#" + shop.getID() + ")");
|
||||||
|
|
||||||
@ -1018,8 +1020,6 @@ public class ShopInteractListener implements Listener {
|
|||||||
ItemStack newProduct = new ItemStack(product);
|
ItemStack newProduct = new ItemStack(product);
|
||||||
newProduct.setAmount(newAmount);
|
newProduct.setAmount(newAmount);
|
||||||
|
|
||||||
String worldName = shop.getLocation().getWorld().getName();
|
|
||||||
|
|
||||||
EconomyResponse r = econ.depositPlayer(executor, worldName, newPrice);
|
EconomyResponse r = econ.depositPlayer(executor, worldName, newPrice);
|
||||||
|
|
||||||
if (r.transactionSuccess()) {
|
if (r.transactionSuccess()) {
|
||||||
@ -1031,8 +1031,8 @@ public class ShopInteractListener implements Listener {
|
|||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
econ.withdrawPlayer(executor, newPrice);
|
econ.withdrawPlayer(executor, worldName, newPrice);
|
||||||
econ.depositPlayer(shop.getVendor(), newPrice);
|
econ.depositPlayer(shop.getVendor(), worldName, newPrice);
|
||||||
plugin.debug("Sell event cancelled (#" + shop.getID() + ")");
|
plugin.debug("Sell event cancelled (#" + shop.getID() + ")");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1059,7 +1059,7 @@ public class ShopInteractListener implements Listener {
|
|||||||
} else {
|
} else {
|
||||||
plugin.debug("Economy transaction failed (r2): " + r2.errorMessage + " (#" + shop.getID() + ")");
|
plugin.debug("Economy transaction failed (r2): " + r2.errorMessage + " (#" + shop.getID() + ")");
|
||||||
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedPlaceholder(Placeholder.ERROR, r2.errorMessage)));
|
executor.sendMessage(LanguageUtils.getMessage(LocalizedMessage.Message.ERROR_OCCURRED, new LocalizedMessage.ReplacedPlaceholder(Placeholder.ERROR, r2.errorMessage)));
|
||||||
econ.withdrawPlayer(executor, newPrice);
|
econ.withdrawPlayer(executor, worldName, newPrice);
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
@ -1067,7 +1067,7 @@ public class ShopInteractListener implements Listener {
|
|||||||
Bukkit.getPluginManager().callEvent(event);
|
Bukkit.getPluginManager().callEvent(event);
|
||||||
|
|
||||||
if (event.isCancelled()) {
|
if (event.isCancelled()) {
|
||||||
econ.withdrawPlayer(executor, newPrice);
|
econ.withdrawPlayer(executor, worldName, newPrice);
|
||||||
plugin.debug("Sell event cancelled (#" + shop.getID() + ")");
|
plugin.debug("Sell event cancelled (#" + shop.getID() + ")");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user