feat(i18n): cache admin
This commit is contained in:
parent
b24202e8ab
commit
597ed23dbc
10 changed files with 131 additions and 39 deletions
|
@ -3,30 +3,39 @@ package xyz.atnrch.nicko.gui;
|
|||
import org.bukkit.entity.Player;
|
||||
import xyz.atnrch.nicko.gui.items.admin.cache.CacheStatisticsItem;
|
||||
import xyz.atnrch.nicko.gui.items.admin.cache.InvalidateCacheItem;
|
||||
import xyz.atnrch.nicko.gui.items.admin.cache.InvalidateEntryItem;
|
||||
import xyz.atnrch.nicko.gui.items.admin.cache.InvalidateSkinItem;
|
||||
import xyz.atnrch.nicko.gui.items.common.GoBackItem;
|
||||
import xyz.atnrch.nicko.i18n.I18N;
|
||||
import xyz.atnrch.nicko.i18n.I18NDict;
|
||||
import xyz.xenondevs.invui.gui.Gui;
|
||||
import xyz.xenondevs.invui.window.Window;
|
||||
|
||||
public class CacheManagementGUI {
|
||||
private final String title = "Nicko > Admin... > Cache";
|
||||
private final Player player;
|
||||
private final Gui gui;
|
||||
private final String title;
|
||||
|
||||
public CacheManagementGUI(Player player) {
|
||||
final I18N i18n = new I18N(player);
|
||||
this.title = i18n.translatePrefixless(I18NDict.GUI.Admin.Cache.TITLE);
|
||||
|
||||
final AdminGUI parent = new AdminGUI(player);
|
||||
final GoBackItem backItem = new GoBackItem(player);
|
||||
|
||||
final CacheStatisticsItem cacheStatisticsItem = new CacheStatisticsItem(player);
|
||||
final InvalidateCacheItem invalidateCacheItem = new InvalidateCacheItem(player);
|
||||
final InvalidateSkinItem invalidateSkinItem = new InvalidateSkinItem(player);
|
||||
|
||||
this.gui = Gui.normal()
|
||||
.setStructure(
|
||||
"# # # # # # # # #",
|
||||
"# # # S A D # # #",
|
||||
"# # # S C E # # #",
|
||||
"B # # # # # # # #"
|
||||
)
|
||||
.addIngredient('B', backItem.get(parent.getGUI(), parent.getTitle()))
|
||||
.addIngredient('S', new CacheStatisticsItem())
|
||||
.addIngredient('A', new InvalidateCacheItem())
|
||||
.addIngredient('D', new InvalidateEntryItem())
|
||||
.addIngredient('S', cacheStatisticsItem.get())
|
||||
.addIngredient('C', invalidateCacheItem.get())
|
||||
.addIngredient('E', invalidateSkinItem.get())
|
||||
.build();
|
||||
this.player = player;
|
||||
}
|
||||
|
|
|
@ -2,7 +2,11 @@ package xyz.atnrch.nicko.gui.items.admin.cache;
|
|||
|
||||
import com.google.common.cache.CacheStats;
|
||||
import com.google.common.cache.LoadingCache;
|
||||
import org.bukkit.entity.Player;
|
||||
import xyz.atnrch.nicko.NickoBukkit;
|
||||
import xyz.atnrch.nicko.i18n.I18N;
|
||||
import xyz.atnrch.nicko.i18n.I18NDict;
|
||||
import xyz.atnrch.nicko.i18n.ItemTranslation;
|
||||
import xyz.atnrch.nicko.mojang.MojangSkin;
|
||||
import org.bukkit.Material;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
|
@ -10,17 +14,27 @@ import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
|||
|
||||
import java.util.Optional;
|
||||
|
||||
public class CacheStatisticsItem extends SuppliedItem {
|
||||
public CacheStatisticsItem() {
|
||||
super(() -> {
|
||||
public class CacheStatisticsItem {
|
||||
private final I18N i18n;
|
||||
|
||||
public CacheStatisticsItem(Player player) {
|
||||
this.i18n = new I18N(player);
|
||||
}
|
||||
|
||||
public SuppliedItem get() {
|
||||
return new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.BOOK);
|
||||
final LoadingCache<String, Optional<MojangSkin>> cache = NickoBukkit.getInstance().getMojangAPI().getSkinCache();
|
||||
final CacheStats stats = cache.stats();
|
||||
builder.setDisplayName("Statistics");
|
||||
builder.addLoreLines(
|
||||
"Request Count: §b" + stats.requestCount(),
|
||||
"Skin Cached: §b" + Math.round(cache.size()),
|
||||
"§8§oCache is cleared every 24 hours.");
|
||||
|
||||
final ItemTranslation translation = i18n.translateItem(I18NDict.GUI.Admin.Cache.STATISTICS,
|
||||
stats.requestCount(),
|
||||
Math.round(cache.size())
|
||||
);
|
||||
translation.getLore().forEach(System.out::println);
|
||||
// TODO (Ineanto, 9/11/23): This doesn't work.
|
||||
builder.setDisplayName(translation.getName());
|
||||
translation.getLore().forEach(builder::addLoreLines);
|
||||
return builder;
|
||||
}, (event) -> true);
|
||||
}
|
||||
|
|
|
@ -6,18 +6,23 @@ import xyz.atnrch.nicko.i18n.I18NDict;
|
|||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import xyz.atnrch.nicko.i18n.ItemTranslation;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
|
||||
public class InvalidateCacheItem extends SuppliedItem {
|
||||
public InvalidateCacheItem() {
|
||||
super(() -> {
|
||||
public class InvalidateCacheItem {
|
||||
private final I18N i18n;
|
||||
|
||||
public InvalidateCacheItem(Player player) {
|
||||
this.i18n = new I18N(player);
|
||||
}
|
||||
|
||||
public SuppliedItem get() {
|
||||
return new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.TNT);
|
||||
builder.setDisplayName("Invalidate cache");
|
||||
builder.addLoreLines(
|
||||
"§c§oNOT RECOMMENDED",
|
||||
"§7Invalidates every skin entry present in the cache.",
|
||||
"§7Does not reset player disguises.");
|
||||
final ItemTranslation translation = i18n.translateItem(I18NDict.GUI.Admin.Cache.INVALIDATE_CACHE);
|
||||
builder.setDisplayName(translation.getName());
|
||||
translation.getLore().forEach(builder::addLoreLines);
|
||||
return builder;
|
||||
}, (click) -> {
|
||||
final ClickType clickType = click.getClickType();
|
||||
|
|
|
@ -1,19 +1,28 @@
|
|||
package xyz.atnrch.nicko.gui.items.admin.cache;
|
||||
|
||||
import xyz.atnrch.nicko.gui.CacheDetailedGUI;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import xyz.atnrch.nicko.gui.CacheDetailedGUI;
|
||||
import xyz.atnrch.nicko.i18n.I18N;
|
||||
import xyz.atnrch.nicko.i18n.I18NDict;
|
||||
import xyz.atnrch.nicko.i18n.ItemTranslation;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
|
||||
public class InvalidateEntryItem extends SuppliedItem {
|
||||
public InvalidateEntryItem() {
|
||||
super(() -> {
|
||||
public class InvalidateSkinItem {
|
||||
private final I18N i18n;
|
||||
|
||||
public InvalidateSkinItem(Player player) {
|
||||
this.i18n = new I18N(player);
|
||||
}
|
||||
|
||||
public SuppliedItem get() {
|
||||
return new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.PAPER);
|
||||
builder.setDisplayName("Invalidate specific entry");
|
||||
builder.addLoreLines("§7Select a specific skin to invalidate.",
|
||||
"§7Useful if a skin has been updated",
|
||||
"§7recently and the cache no longer up-to-date.");
|
||||
final ItemTranslation translation = i18n.translateItem(I18NDict.GUI.Admin.Cache.INVALIDATE_SKIN);
|
||||
builder.setDisplayName(translation.getName());
|
||||
translation.getLore().forEach(builder::addLoreLines);
|
||||
return builder;
|
||||
}, (click) -> {
|
||||
final ClickType clickType = click.getClickType();
|
|
@ -35,7 +35,7 @@ public class I18N {
|
|||
this.yamlConfig = getYamlConfig();
|
||||
}
|
||||
|
||||
public ItemTranslation translateItem(String key, String... args) {
|
||||
public ItemTranslation translateItem(String key, Object... args) {
|
||||
final String nameKey = key + ".name";
|
||||
final String loreKey = key + ".lore";
|
||||
final String name = readString(nameKey);
|
||||
|
@ -74,8 +74,9 @@ public class I18N {
|
|||
|
||||
// If it does, replace the content with the args at position replacementIndex
|
||||
if (replacementIndex < args.length && args[replacementIndex] != null) {
|
||||
System.out.println("replacing...");
|
||||
// Replace with the corresponding varargs index
|
||||
toTranslate.set(lineIndex, currentLine.replace("{" + replacementIndex + "}", args[replacementIndex]));
|
||||
toTranslate.set(lineIndex, currentLine.replace("{" + replacementIndex + "}", args[replacementIndex].toString()));
|
||||
replacementIndex++;
|
||||
}
|
||||
|
||||
|
|
|
@ -104,6 +104,15 @@ public class I18NDict {
|
|||
public static final String TITLE = ADMIN_KEY + "title";
|
||||
public static final String MANAGE_CACHE = ADMIN_KEY + "manage_cache";
|
||||
public static final String MANAGE_PLAYER = ADMIN_KEY + "manage_player";
|
||||
|
||||
public static class Cache {
|
||||
private static final String CACHE_KEY = ADMIN_KEY + "cache.";
|
||||
|
||||
public static final String TITLE = CACHE_KEY + "title";
|
||||
public static final String STATISTICS = CACHE_KEY + "statistics";
|
||||
public static final String INVALIDATE_CACHE = CACHE_KEY + "invalidate_cache";
|
||||
public static final String INVALIDATE_SKIN = CACHE_KEY + "invalidate_skin";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -51,10 +51,15 @@ public class NickoExpansion extends PlaceholderExpansion {
|
|||
final Optional<NickoProfile> optionalProfile = instance.getDataStore().getData(player.getUniqueId());
|
||||
if (optionalProfile.isPresent()) {
|
||||
final NickoProfile profile = optionalProfile.get();
|
||||
if (!profile.hasData()) {
|
||||
if (profile.hasData()) {
|
||||
if (profile.getName() != null) {
|
||||
name = profile.getName();
|
||||
}
|
||||
|
||||
if (profile.getSkin() != null) {
|
||||
skin = profile.getSkin();
|
||||
}
|
||||
}
|
||||
locale = profile.getLocale().getName();
|
||||
bungeecord = profile.isBungeecordTransfer();
|
||||
}
|
||||
|
|
|
@ -73,6 +73,25 @@ gui:
|
|||
name: "Check a player..."
|
||||
lore:
|
||||
- "§7See players' disguise information."
|
||||
cache:
|
||||
title: "Nicko > Admin... > Cache"
|
||||
statistics:
|
||||
name: "Statistics"
|
||||
lore:
|
||||
- "§fRequest count: §b{0}"
|
||||
- "§fNumber of skin cached: §b{1}"
|
||||
- "§8§oCache is cleared every 24 hours."
|
||||
invalidate_cache:
|
||||
name: "Invalidate cache"
|
||||
lore:
|
||||
- "§c§oNOT RECOMMENDED"
|
||||
- "§7Invalidate the entirety of the skin cache."
|
||||
- "§7This doesn't reset player's disguises."
|
||||
invalidate_skin:
|
||||
name: "Invalidate a skin..."
|
||||
lore:
|
||||
- "§7Select a specific skin to invalidate."
|
||||
- "§7Useful if a skin has been recently updated."
|
||||
settings:
|
||||
title: "Nicko > Settings"
|
||||
language:
|
||||
|
|
|
@ -66,13 +66,34 @@ gui:
|
|||
admin:
|
||||
title: "Nicko > Administration"
|
||||
manage_cache:
|
||||
name: "Gérer le cache d'§6apparences..."
|
||||
name: "Gérer le cache d'§6skin..."
|
||||
lore:
|
||||
- "§7Accédez à la gestion du cache d'apparences."
|
||||
- "§7Accédez à la gestion du cache de skin."
|
||||
manage_player:
|
||||
name: "Vérifier un joueur..."
|
||||
lore:
|
||||
- "§7Vérifiez les informations de déguisement d'un joueur."
|
||||
cache:
|
||||
title: "Nicko > Admin... > Cache"
|
||||
statistics:
|
||||
name: "Statistiques"
|
||||
lore:
|
||||
- "§fNombre de requêtes: §b{0}"
|
||||
- "§fNb. de skin dans le cache: §b{1}"
|
||||
- "§8§oLe cache est vidé toutes les 24 heures."
|
||||
invalidate_cache:
|
||||
name: "Invalider le cache"
|
||||
lore:
|
||||
- "§c§oDÉCONSEILLÉ"
|
||||
- "§7Invalide l'entièreté du cache des skin."
|
||||
- "§7Ne retire pas les déguisements"
|
||||
- "§7pour les joueurs en disposant."
|
||||
invalidate_skin:
|
||||
name: "Invalider un skin..."
|
||||
lore:
|
||||
- "§7Sélectionnez une apparence spécifique à"
|
||||
- "§7invalider. Utile dans le cas où un skin"
|
||||
- "§7a récemment été mis à jour."
|
||||
settings:
|
||||
title: "Nicko > Paramètres"
|
||||
language:
|
||||
|
|
|
@ -44,8 +44,8 @@ public class I18NItemTranslationTest {
|
|||
@DisplayName("Translate Item")
|
||||
public void translateItemLore() {
|
||||
final I18N i18n = new I18N(Locale.FRENCH);
|
||||
final ItemTranslation translation = i18n.translateItem(I18NDict.GUI.Settings.BUNGEECORD, "Test");
|
||||
assertEquals("§7§oParcourez les valeurs", translation.getLore().get(0));
|
||||
final String translation = i18n.translatePrefixless(I18NDict.Event.Settings.ERROR, "Test!");
|
||||
assertEquals("§cImpossible de mettre à jour vos paramètres. §7§o(Test!)", translation);
|
||||
}
|
||||
|
||||
@AfterAll
|
||||
|
|
Loading…
Reference in a new issue