From 487e59970f06e3b309a40ed962b2e20264349e42 Mon Sep 17 00:00:00 2001 From: Efe Kurban Date: Sat, 20 Jan 2024 15:53:53 +0300 Subject: [PATCH] Some fixes --- .../plugin/api/modules/credit/CreditManager.java | 2 +- .../modules/credit/commands/CreditCommand.java | 13 ++++++++++--- .../net/leaderos/shared/helpers/RequestUtil.java | 2 +- .../shared/modules/credit/CreditHelper.java | 2 +- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/bukkit/src/main/java/net/leaderos/plugin/api/modules/credit/CreditManager.java b/bukkit/src/main/java/net/leaderos/plugin/api/modules/credit/CreditManager.java index 6c155a0df..ffd0e8563 100644 --- a/bukkit/src/main/java/net/leaderos/plugin/api/modules/credit/CreditManager.java +++ b/bukkit/src/main/java/net/leaderos/plugin/api/modules/credit/CreditManager.java @@ -27,7 +27,7 @@ public CreditManager() {} */ public Double get(String player) { Response amount = CreditHelper.getRequest(player); - if (amount == null) return null; + if (amount == null || amount.getResponseMessage() == null) return null; return amount.getResponseMessage().getDouble("raw_credits"); } diff --git a/bukkit/src/main/java/net/leaderos/plugin/modules/credit/commands/CreditCommand.java b/bukkit/src/main/java/net/leaderos/plugin/modules/credit/commands/CreditCommand.java index 8ad5ade31..d99e9b770 100644 --- a/bukkit/src/main/java/net/leaderos/plugin/modules/credit/commands/CreditCommand.java +++ b/bukkit/src/main/java/net/leaderos/plugin/modules/credit/commands/CreditCommand.java @@ -92,7 +92,8 @@ public void sendCommand(Player player, String target, Double a) { if (error == null) { // Calls UpdateCache event for update player's cache - org.bukkit.Bukkit.getPluginManager().callEvent(new UpdateCacheEvent(player.getName(), amount, UpdateType.REMOVE)); + org.bukkit.Bukkit.getScheduler().runTask(Bukkit.getInstance(), () -> org.bukkit.Bukkit.getPluginManager().callEvent(new UpdateCacheEvent(player.getName(), amount, UpdateType.REMOVE))); + ChatUtil.sendMessage(player, ChatUtil.replacePlaceholders( Bukkit.getInstance().getLangFile().getMessages().getCredit().getSuccessfullySentCredit(), new Placeholder("{amount}", MoneyUtil.format(amount)), @@ -109,14 +110,20 @@ public void sendCommand(Player player, String target, Double a) { )); } } else if (error == Error.NOT_ENOUGH_CREDITS || error == Error.USER_NOT_FOUND) { - ChatUtil.sendMessage(player, Bukkit.getInstance().getLangFile().getMessages().getCredit().getCannotSendCreditNotEnough()); + ChatUtil.sendMessage(player, ChatUtil.replacePlaceholders( + Bukkit.getInstance().getLangFile().getMessages().getCredit().getCannotSendCreditNotEnough(), + new Placeholder("{amount}", MoneyUtil.format(amount)) + )); } else if (error == Error.INVALID_TARGET || error == Error.TARGET_USER_NOT_FOUND) { ChatUtil.sendMessage(player, Bukkit.getInstance().getLangFile().getMessages().getCredit().getCannotSendCreditsThisUser()); } else if (error == Error.INVALID_AMOUNT) { ChatUtil.sendMessage(player, Bukkit.getInstance().getLangFile().getMessages().getCredit().getCannotSendCreditNegative()); } else { - ChatUtil.sendMessage(player, Bukkit.getInstance().getLangFile().getMessages().getCredit().getCannotSendCreditNotEnough()); + ChatUtil.sendMessage(player, ChatUtil.replacePlaceholders( + Bukkit.getInstance().getLangFile().getMessages().getCredit().getCannotSendCreditNotEnough(), + new Placeholder("{amount}", MoneyUtil.format(amount)) + )); } RequestUtil.invalidate(player.getUniqueId()); diff --git a/shared/src/main/java/net/leaderos/shared/helpers/RequestUtil.java b/shared/src/main/java/net/leaderos/shared/helpers/RequestUtil.java index b9ab8a6ad..35dd4f041 100644 --- a/shared/src/main/java/net/leaderos/shared/helpers/RequestUtil.java +++ b/shared/src/main/java/net/leaderos/shared/helpers/RequestUtil.java @@ -8,7 +8,7 @@ public class RequestUtil { - private static final Cache CACHE = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.SECONDS).build(); + private static final Cache CACHE = CacheBuilder.newBuilder().expireAfterWrite(20, TimeUnit.SECONDS).build(); public static void addRequest(UUID uuid) { CACHE.put(uuid, (byte) 1); diff --git a/shared/src/main/java/net/leaderos/shared/modules/credit/CreditHelper.java b/shared/src/main/java/net/leaderos/shared/modules/credit/CreditHelper.java index 4bc51609e..9114100b0 100644 --- a/shared/src/main/java/net/leaderos/shared/modules/credit/CreditHelper.java +++ b/shared/src/main/java/net/leaderos/shared/modules/credit/CreditHelper.java @@ -86,7 +86,7 @@ public class CreditHelper { */ public static @Nullable Response setCreditRequest(String target, double amount) { try { - PostRequest postSetCredit = new SetCreditsRequest("credits/" + target + "/set", amount); + PostRequest postSetCredit = new SetCreditsRequest(target, amount); return postSetCredit.getResponse(); } catch (Exception e) {