From d279c764d91b20113866b52e836c7bce8020dd63 Mon Sep 17 00:00:00 2001 From: Silent Date: Sat, 30 Dec 2023 00:10:47 +0100 Subject: [PATCH] Fix economy --- .gitignore | 1 - pom.xml | 2 +- .../tsp/headdb/core/command/CommandInfo.java | 1 + src/main/java/tsp/headdb/core/util/Utils.java | 62 ++++++++----------- src/main/resources/build.properties | 1 + 5 files changed, 29 insertions(+), 38 deletions(-) create mode 100644 src/main/resources/build.properties diff --git a/.gitignore b/.gitignore index 50c47b2..f902934 100644 --- a/.gitignore +++ b/.gitignore @@ -3,7 +3,6 @@ target/ src/test/ dependency-reduced-pom.xml -build.properties build/ .classpath diff --git a/pom.xml b/pom.xml index 9e62868..8fab64f 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ tsp.headdb HeadDB - 5.0.0-rc.8 + 5.0.0-rc.9 jar HeadDB diff --git a/src/main/java/tsp/headdb/core/command/CommandInfo.java b/src/main/java/tsp/headdb/core/command/CommandInfo.java index 8c22bff..688cf13 100644 --- a/src/main/java/tsp/headdb/core/command/CommandInfo.java +++ b/src/main/java/tsp/headdb/core/command/CommandInfo.java @@ -15,6 +15,7 @@ public class CommandInfo extends SubCommand { public void handle(CommandSender sender, String[] args) { if (HeadDB.getInstance().getConfig().getBoolean("showAdvancedPluginInfo")) { PlayerUtils.sendMessage(sender, "&7Running &6HeadDB - " + Utils.getVersion().orElse(HeadDB.getInstance().getDescription().getVersion() + " &7(&4UNKNOWN SEMVER&7)")); + //PlayerUtils.sendMessage(sender, "&7Build: " + HeadDB.getInstance().getDescription().getVersion()); PlayerUtils.sendMessage(sender, "&7GitHub: &6https://github.com/TheSilentPro/HeadDB"); } else { PlayerUtils.sendMessage(sender, "&7Running &6HeadDB &7by &6TheSilentPro (Silent)"); diff --git a/src/main/java/tsp/headdb/core/util/Utils.java b/src/main/java/tsp/headdb/core/util/Utils.java index 7772d03..8005311 100644 --- a/src/main/java/tsp/headdb/core/util/Utils.java +++ b/src/main/java/tsp/headdb/core/util/Utils.java @@ -213,48 +213,38 @@ public class Utils { .replace("%cost%", HeadDB.getInstance().getDecimalFormat().format(cost)) ); - try (Promise economyPromise = optional.get().purchase(player, cost)) { - // TODO: Might not need to be sync. - return economyPromise.thenApplySync((success) -> { - if (success) { - HeadDB.getInstance().getLocalization().sendMessage(player, "completePayment", msg -> msg - .replace("%name%", head.getName()) - .replace("%cost%", cost.toString())); - } else { - HeadDB.getInstance().getLocalization().sendMessage(player, "invalidFunds", msg -> msg.replace("%name%", head.getName())); - } - return success; - }); - } catch (Exception ex) { - HeadDB.getInstance().getLog().severe("Failed to process payment: " + ex.getMessage()); - return Promise.exceptionally(ex); - } + return optional.get().purchase(player, cost).thenApplyAsync(success -> { + if (success) { + HeadDB.getInstance().getLocalization().sendMessage(player, "completePayment", msg -> msg + .replace("%name%", head.getName()) + .replace("%cost%", cost.toString())); + } else { + HeadDB.getInstance().getLocalization().sendMessage(player, "invalidFunds", msg -> msg.replace("%name%", head.getName())); + } + return success; + }); } } public static void purchase(Player player, Head head, int amount) { // Bukkit API - Has to be sync. - try (Promise paymentPromise = processPayment(player, head, amount)) { - paymentPromise.thenAcceptSync((success) -> { - if (success) { - ItemStack item = head.getItem(player.getUniqueId()); - item.setAmount(amount); - player.getInventory().addItem(item); - HeadDB.getInstance().getConfig().getStringList("commands.purchase").forEach(command -> { - if (command.isEmpty()) { - return; - } - if (Hooks.PAPI.enabled()) { - command = PlaceholderAPI.setPlaceholders(player, command); - } + processPayment(player, head, amount).thenAcceptSync(success -> { + if (success) { + ItemStack item = head.getItem(player.getUniqueId()); + item.setAmount(amount); + player.getInventory().addItem(item); + HeadDB.getInstance().getConfig().getStringList("commands.purchase").forEach(command -> { + if (command.isEmpty()) { + return; + } + if (Hooks.PAPI.enabled()) { + command = PlaceholderAPI.setPlaceholders(player, command); + } - Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); - }); - } - }); - } catch (Exception ex) { - ex.printStackTrace(); - } + Bukkit.dispatchCommand(Bukkit.getConsoleSender(), command); + }); + } + }); } public static Optional getTexture(ItemStack head) { diff --git a/src/main/resources/build.properties b/src/main/resources/build.properties new file mode 100644 index 0000000..e5683df --- /dev/null +++ b/src/main/resources/build.properties @@ -0,0 +1 @@ +version=${project.version} \ No newline at end of file