mirror of
https://github.com/Flowsqy/ShopChest.git
synced 2024-11-14 23:15:10 +01:00
For god's sake call economy methods async, they can run db calls
This commit is contained in:
parent
794a0400ca
commit
1a8d48954d
@ -1,6 +1,7 @@
|
||||
package de.epiceric.shopchest.listeners;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
@ -64,22 +65,24 @@ public class ChestProtectListener implements Listener {
|
||||
}
|
||||
});
|
||||
} else {
|
||||
double creationPrice = shop.getShopType() == ShopType.ADMIN ? Config.shopCreationPriceAdmin : Config.shopCreationPriceNormal;
|
||||
if (creationPrice > 0 && Config.refundShopCreation && p.getUniqueId().equals(shop.getVendor().getUniqueId())) {
|
||||
EconomyResponse r = plugin.getEconomy().depositPlayer(p, shop.getLocation().getWorld().getName(), creationPrice);
|
||||
if (!r.transactionSuccess()) {
|
||||
plugin.debug("Economy transaction failed: " + r.errorMessage);
|
||||
p.sendMessage(LanguageUtils.getMessage(Message.ERROR_OCCURRED,
|
||||
new Replacement(Placeholder.ERROR, r.errorMessage)));
|
||||
p.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED_REFUND,
|
||||
new Replacement(Placeholder.CREATION_PRICE, 0)));
|
||||
CompletableFuture.runAsync(() -> {
|
||||
double creationPrice = shop.getShopType() == ShopType.ADMIN ? Config.shopCreationPriceAdmin : Config.shopCreationPriceNormal;
|
||||
if (creationPrice > 0 && Config.refundShopCreation && p.getUniqueId().equals(shop.getVendor().getUniqueId())) {
|
||||
EconomyResponse r = plugin.getEconomy().depositPlayer(p, shop.getLocation().getWorld().getName(), creationPrice);
|
||||
if (!r.transactionSuccess()) {
|
||||
plugin.debug("Economy transaction failed: " + r.errorMessage);
|
||||
p.sendMessage(LanguageUtils.getMessage(Message.ERROR_OCCURRED,
|
||||
new Replacement(Placeholder.ERROR, r.errorMessage)));
|
||||
p.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED_REFUND,
|
||||
new Replacement(Placeholder.CREATION_PRICE, 0)));
|
||||
} else {
|
||||
p.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED_REFUND,
|
||||
new Replacement(Placeholder.CREATION_PRICE, creationPrice)));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED_REFUND,
|
||||
new Replacement(Placeholder.CREATION_PRICE, creationPrice)));
|
||||
p.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED));
|
||||
}
|
||||
} else {
|
||||
p.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED));
|
||||
}
|
||||
});
|
||||
|
||||
shopUtils.removeShop(shop, true);
|
||||
plugin.debug(String.format("%s broke %s's shop (#%d)", p.getName(), shop.getVendor().getName(), shop.getID()));
|
||||
|
@ -506,22 +506,28 @@ public class ShopInteractListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
if (creationPrice > 0) {
|
||||
EconomyResponse r = plugin.getEconomy().withdrawPlayer(executor, location.getWorld().getName(), creationPrice);
|
||||
if (!r.transactionSuccess()) {
|
||||
plugin.debug("Economy transaction failed: " + r.errorMessage);
|
||||
executor.sendMessage(LanguageUtils.getMessage(Message.ERROR_OCCURRED, new Replacement(Placeholder.ERROR, r.errorMessage)));
|
||||
return;
|
||||
CompletableFuture.runAsync(() -> {
|
||||
|
||||
if (creationPrice > 0) {
|
||||
EconomyResponse r = econ.withdrawPlayer(executor, location.getWorld().getName(), creationPrice);
|
||||
if (!r.transactionSuccess()) {
|
||||
plugin.debug("Economy transaction failed: " + r.errorMessage);
|
||||
executor.sendMessage(LanguageUtils.getMessage(Message.ERROR_OCCURRED, new Replacement(Placeholder.ERROR, r.errorMessage)));
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
shop.create(true);
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
|
||||
plugin.debug("Shop created");
|
||||
shopUtils.addShop(shop, true);
|
||||
shop.create(true);
|
||||
|
||||
Message message = shopType == ShopType.ADMIN ? Message.ADMIN_SHOP_CREATED : Message.SHOP_CREATED;
|
||||
executor.sendMessage(LanguageUtils.getMessage(message, new Replacement(Placeholder.CREATION_PRICE, creationPrice)));
|
||||
plugin.debug("Shop created");
|
||||
shopUtils.addShop(shop, true);
|
||||
|
||||
Message message = shopType == ShopType.ADMIN ? Message.ADMIN_SHOP_CREATED : Message.SHOP_CREATED;
|
||||
executor.sendMessage(LanguageUtils.getMessage(message, new Replacement(Placeholder.CREATION_PRICE, creationPrice)));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -549,25 +555,31 @@ public class ShopInteractListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
double creationPrice = shop.getShopType() == ShopType.ADMIN ? Config.shopCreationPriceAdmin : Config.shopCreationPriceNormal;
|
||||
if (creationPrice > 0 && Config.refundShopCreation && executor.getUniqueId().equals(shop.getVendor().getUniqueId())) {
|
||||
EconomyResponse r = plugin.getEconomy().depositPlayer(executor, shop.getLocation().getWorld().getName(), creationPrice);
|
||||
if (!r.transactionSuccess()) {
|
||||
plugin.debug("Economy transaction failed: " + r.errorMessage);
|
||||
executor.sendMessage(LanguageUtils.getMessage(Message.ERROR_OCCURRED,
|
||||
new Replacement(Placeholder.ERROR, r.errorMessage)));
|
||||
executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED_REFUND,
|
||||
new Replacement(Placeholder.CREATION_PRICE, 0)));
|
||||
} else {
|
||||
executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED_REFUND,
|
||||
new Replacement(Placeholder.CREATION_PRICE, creationPrice)));
|
||||
}
|
||||
} else {
|
||||
executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED));
|
||||
}
|
||||
CompletableFuture.runAsync(() -> {
|
||||
|
||||
shopUtils.removeShop(shop, true);
|
||||
plugin.debug("Removed shop (#" + shop.getID() + ")");
|
||||
double creationPrice = shop.getShopType() == ShopType.ADMIN ? Config.shopCreationPriceAdmin : Config.shopCreationPriceNormal;
|
||||
if (creationPrice > 0 && Config.refundShopCreation && executor.getUniqueId().equals(shop.getVendor().getUniqueId())) {
|
||||
EconomyResponse r = econ.depositPlayer(executor, shop.getLocation().getWorld().getName(), creationPrice);
|
||||
if (!r.transactionSuccess()) {
|
||||
plugin.debug("Economy transaction failed: " + r.errorMessage);
|
||||
executor.sendMessage(LanguageUtils.getMessage(Message.ERROR_OCCURRED,
|
||||
new Replacement(Placeholder.ERROR, r.errorMessage)));
|
||||
executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED_REFUND,
|
||||
new Replacement(Placeholder.CREATION_PRICE, 0)));
|
||||
} else {
|
||||
executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED_REFUND,
|
||||
new Replacement(Placeholder.CREATION_PRICE, creationPrice)));
|
||||
}
|
||||
} else {
|
||||
executor.sendMessage(LanguageUtils.getMessage(Message.SHOP_REMOVED));
|
||||
}
|
||||
|
||||
Bukkit.getScheduler().runTask(plugin, () -> {
|
||||
|
||||
shopUtils.removeShop(shop, true);
|
||||
plugin.debug("Removed shop (#" + shop.getID() + ")");
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user