Skip to content

Commit

Permalink
Some fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
efekurbann committed Jan 20, 2024
1 parent 3c62524 commit 487e599
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

public class RequestUtil {

private static final Cache<UUID, Byte> CACHE = CacheBuilder.newBuilder().expireAfterWrite(5, TimeUnit.SECONDS).build();
private static final Cache<UUID, Byte> CACHE = CacheBuilder.newBuilder().expireAfterWrite(20, TimeUnit.SECONDS).build();

public static void addRequest(UUID uuid) {
CACHE.put(uuid, (byte) 1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 487e599

Please sign in to comment.