|
| 1 | +package org.mvplugins.multiverse.inventories.commands; |
| 2 | + |
| 3 | +import com.google.common.cache.CacheStats; |
| 4 | +import org.bukkit.entity.Player; |
| 5 | +import org.jvnet.hk2.annotations.Service; |
| 6 | +import org.mvplugins.multiverse.core.commandtools.MVCommandIssuer; |
| 7 | +import org.mvplugins.multiverse.core.commandtools.MVCommandManager; |
| 8 | +import org.mvplugins.multiverse.external.acf.commands.annotation.CommandAlias; |
| 9 | +import org.mvplugins.multiverse.external.acf.commands.annotation.CommandCompletion; |
| 10 | +import org.mvplugins.multiverse.external.acf.commands.annotation.CommandPermission; |
| 11 | +import org.mvplugins.multiverse.external.acf.commands.annotation.Flags; |
| 12 | +import org.mvplugins.multiverse.external.acf.commands.annotation.Subcommand; |
| 13 | +import org.mvplugins.multiverse.external.acf.commands.annotation.Syntax; |
| 14 | +import org.mvplugins.multiverse.external.jakarta.inject.Inject; |
| 15 | +import org.mvplugins.multiverse.external.jetbrains.annotations.NotNull; |
| 16 | +import org.mvplugins.multiverse.inventories.profile.ProfileDataSource; |
| 17 | + |
| 18 | +import java.util.Map; |
| 19 | + |
| 20 | +@Service |
| 21 | +@CommandAlias("mvinv") |
| 22 | +final class CacheCommand extends InventoriesCommand { |
| 23 | + |
| 24 | + private final ProfileDataSource profileDataSource; |
| 25 | + |
| 26 | + @Inject |
| 27 | + CacheCommand(@NotNull MVCommandManager commandManager, @NotNull ProfileDataSource profileDataSource) { |
| 28 | + super(commandManager); |
| 29 | + this.profileDataSource = profileDataSource; |
| 30 | + } |
| 31 | + |
| 32 | + @Subcommand("cache stats") |
| 33 | + @CommandPermission("multiverse.inventories.cache.stats") |
| 34 | + void onCacheStatsCommand(MVCommandIssuer issuer) { |
| 35 | + Map<String, CacheStats> stats = this.profileDataSource.getCacheStats(); |
| 36 | + for (Map.Entry<String, CacheStats> entry : stats.entrySet()) { |
| 37 | + issuer.sendInfo("Cache: " + entry.getKey()); |
| 38 | + issuer.sendInfo(" hits count: " + entry.getValue().hitCount()); |
| 39 | + issuer.sendInfo(" misses count: " + entry.getValue().missCount()); |
| 40 | + issuer.sendInfo(" loads count: " + entry.getValue().loadCount()); |
| 41 | + issuer.sendInfo(" avg load time: " + entry.getValue().averageLoadPenalty()); |
| 42 | + issuer.sendInfo(" exceptions: " + entry.getValue().loadExceptionCount()); |
| 43 | + issuer.sendInfo(" evictions: " + entry.getValue().evictionCount()); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + @Subcommand("cache invalidate all") |
| 48 | + @CommandPermission("multiverse.inventories.cache.invalidate") |
| 49 | + void onCacheClearAllCommand(MVCommandIssuer issuer) { |
| 50 | + this.profileDataSource.clearAllCache(); |
| 51 | + } |
| 52 | + |
| 53 | + @Subcommand("cache invalidate player") |
| 54 | + @CommandPermission("multiverse.inventories.cache.invalidate") |
| 55 | + @CommandCompletion("@players") |
| 56 | + @Syntax("<player>") |
| 57 | + void onCacheClearProfileCommand( |
| 58 | + MVCommandIssuer issuer, |
| 59 | + |
| 60 | + @Flags("resolve=issuerAware") |
| 61 | + Player player) { |
| 62 | + this.profileDataSource.clearProfileCache(key -> key.getPlayerUUID().equals(player.getUniqueId())); |
| 63 | + } |
| 64 | +} |
0 commit comments