Skip to content

Commit

Permalink
Fix economy
Browse files Browse the repository at this point in the history
  • Loading branch information
PBoki committed Dec 29, 2023
1 parent 282a711 commit d279c76
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 38 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ target/
src/test/

dependency-reduced-pom.xml
build.properties
build/

.classpath
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>tsp.headdb</groupId>
<artifactId>HeadDB</artifactId>
<version>5.0.0-rc.8</version>
<version>5.0.0-rc.9</version>
<packaging>jar</packaging>

<name>HeadDB</name>
Expand Down
1 change: 1 addition & 0 deletions src/main/java/tsp/headdb/core/command/CommandInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public CommandInfo() {
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)");
Expand Down
62 changes: 26 additions & 36 deletions src/main/java/tsp/headdb/core/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,48 +213,38 @@ private static Promise<Boolean> processPayment(Player player, Head head, int amo
.replace("%cost%", HeadDB.getInstance().getDecimalFormat().format(cost))
);

try (Promise<Boolean> 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<Boolean> 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<String> getTexture(ItemStack head) {
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/build.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=${project.version}

0 comments on commit d279c76

Please sign in to comment.