-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1.1.6: added leaderos-cache update <player> command
- Loading branch information
1 parent
69ea2b6
commit 61dfe11
Showing
5 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
bukkit/src/main/java/net/leaderos/plugin/modules/cache/commands/CacheCommand.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
)); | ||
}); | ||
} | ||
} |