Skip to content

Commit

Permalink
1.1.6: added leaderos-cache update <player> command
Browse files Browse the repository at this point in the history
  • Loading branch information
benfiratkaya committed Sep 8, 2024
1 parent 69ea2b6 commit 61dfe11
Show file tree
Hide file tree
Showing 5 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ public static class Credit extends OkaeriConfig {
private String successfullyRemovedCredit = "{prefix} &aSuccessfully removed &e{amount} credit &afrom &b{target}&a.";

private String receivedCredit = "{prefix} &aYou just received &e{amount} credit(s) &afrom &b{player}&a.";

private String cacheUpdated = "{prefix} &aSuccessfully updated cache for &b{target}&a.";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ public static class Credit extends Language.Messages.Credit {
private String successfullyRemovedCredit = "{prefix} &aSuccessfully removed &e{amount} credit &afrom &b{target}&a.";

private String receivedCredit = "{prefix} &aYou just received &e{amount} credit(s) &afrom &b{player}&a.";

private String cacheUpdated = "{prefix} &aSuccessfully updated cache for &b{target}&a.";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ public static class Credit extends Language.Messages.Credit {
private String successfullyRemovedCredit = "{prefix} &b{target} &aadlı oyuncunun &e{amount} kredisi &abaşarıyla silindi.";

private String receivedCredit = "{prefix} &b{player} &aadlı oyuncudan &e{amount} kredi &aaldın.";

private String cacheUpdated = "{prefix} &b{target} &aadlı oyuncunun önbelleğe alınmış verisi güncellendi.";
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package net.leaderos.plugin.modules.cache;

import net.leaderos.plugin.Bukkit;
import net.leaderos.plugin.modules.cache.commands.CacheCommand;
import net.leaderos.plugin.modules.cache.listeners.CacheUpdateEvent;
import net.leaderos.plugin.modules.cache.listeners.LoginListener;
import net.leaderos.plugin.modules.cache.listeners.QuitListener;
Expand Down Expand Up @@ -43,6 +44,8 @@ public void onEnable() {
org.bukkit.Bukkit.getPluginManager().registerEvents(cacheUpdateEvent, Bukkit.getInstance());
// Loads all player data
User.loadAllPlayers();
// Register Command
Bukkit.getCommandManager().registerCommand(new CacheCommand());
// Placeholder loader
if (org.bukkit.Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI"))
new Placeholders().register();
Expand All @@ -57,6 +60,8 @@ public void onDisable() {
HandlerList.unregisterAll(cacheUpdateEvent);
// Removes cache
User.getUserList().clear();
// Unregister Command
Bukkit.getCommandManager().unregisterCommand(new CacheCommand());
// Placeholder unloader
if( org.bukkit.Bukkit.getPluginManager().isPluginEnabled("PlaceholderAPI"))
new Placeholders().unregister();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package net.leaderos.plugin.modules.cache.commands;

import dev.triumphteam.cmd.core.BaseCommand;
import dev.triumphteam.cmd.core.annotation.Command;
import dev.triumphteam.cmd.core.annotation.SubCommand;
import lombok.RequiredArgsConstructor;
import net.leaderos.plugin.Bukkit;
import net.leaderos.plugin.api.LeaderOSAPI;
import net.leaderos.plugin.api.handlers.UpdateCacheEvent;
import net.leaderos.plugin.helpers.ChatUtil;
import net.leaderos.shared.helpers.MoneyUtil;
import net.leaderos.shared.helpers.Placeholder;
import net.leaderos.shared.modules.credit.enums.UpdateType;
import org.bukkit.command.CommandSender;

@RequiredArgsConstructor
@Command(value = "leaderos-cache")
public class CacheCommand extends BaseCommand {
/**
* Update player cache
* @param sender executor
* @param target player to update
*/
@SubCommand(value = "update", alias = {"reset"})
public void updateCommand(CommandSender sender, String target) {
org.bukkit.Bukkit.getScheduler().runTaskAsynchronously(Bukkit.getInstance(), () -> {

// Check if the player is online
if (org.bukkit.Bukkit.getPlayer(target) == null) {
ChatUtil.sendMessage(sender, ChatUtil.replacePlaceholders(
Bukkit.getInstance().getLangFile().getMessages().getPlayerNotOnline()
));
return;
}

Double amount = LeaderOSAPI.getCreditManager().get(target);

if (amount != null) {
org.bukkit.Bukkit.getScheduler().runTask(Bukkit.getInstance(), () -> org.bukkit.Bukkit.getPluginManager().callEvent(new UpdateCacheEvent(target, amount, UpdateType.SET)));

ChatUtil.sendMessage(sender, ChatUtil.replacePlaceholders(
Bukkit.getInstance().getLangFile().getMessages().getCredit().getCacheUpdated(),
new Placeholder("{amount}", MoneyUtil.format(amount)),
new Placeholder("{target}", target)
));
}
else
ChatUtil.sendMessage(sender, ChatUtil.replacePlaceholders(
Bukkit.getInstance().getLangFile().getMessages().getPlayerNotAvailable()
));
});
}
}

0 comments on commit 61dfe11

Please sign in to comment.