feat(i18n): move to adventure

This commit is contained in:
ineanto 2023-12-22 17:23:36 +01:00
parent 3377dcf2bf
commit 84e792880f
13 changed files with 175 additions and 110 deletions

View file

@ -49,6 +49,7 @@ dependencies {
implementation("com.comphenix.protocol:ProtocolLib:5.1.1-SNAPSHOT")
shadowImplementation("me.clip:placeholderapi:2.11.4")
shadowImplementation("net.kyori:adventure-api:4.14.0")
shadowImplementation("xyz.xenondevs.invui:invui:1.23")
shadowImplementation("net.wesjd:anvilgui:1.9.0-SNAPSHOT")
shadowImplementation("com.github.jsixface:yamlconfig:1.2")

View file

@ -40,13 +40,7 @@ public class AppearanceManager {
profile.setName(defaultName);
profile.setSkin(defaultName);
dataStore.getCache().cache(player.getUniqueId(), profile);
final ActionResult actionResult = updatePlayer(true, true);
if (!actionResult.isError()) {
profile.setSkin(null);
profile.setName(null);
dataStore.getCache().cache(player.getUniqueId(), profile);
}
return actionResult;
return updatePlayer(true, true);
}
public ActionResult updatePlayer(boolean skinChange, boolean reset) {

View file

@ -4,10 +4,7 @@ import org.bukkit.entity.Player;
import xyz.ineanto.nicko.gui.items.appearance.ChangeBothItem;
import xyz.ineanto.nicko.gui.items.appearance.ChangeNameItem;
import xyz.ineanto.nicko.gui.items.appearance.ChangeSkinItem;
import xyz.ineanto.nicko.gui.items.home.AdminAccessItem;
import xyz.ineanto.nicko.gui.items.home.ExitItem;
import xyz.ineanto.nicko.gui.items.home.ResetItem;
import xyz.ineanto.nicko.gui.items.home.SettingsAccessItem;
import xyz.ineanto.nicko.gui.items.home.*;
import xyz.ineanto.nicko.i18n.I18N;
import xyz.ineanto.nicko.i18n.I18NDict;
import xyz.xenondevs.invui.gui.Gui;
@ -20,7 +17,7 @@ public class HomeGUI {
public HomeGUI(Player player) {
final String[] dynamicStructure = new String[]{
"# # # # # # # # #",
"# # # # D # # # #",
"A # # N B S # # #",
"E P # # # # # # R"};
@ -38,6 +35,7 @@ public class HomeGUI {
final ChangeSkinItem changeSkinItem = new ChangeSkinItem(player);
final SettingsAccessItem settingsAccessItem = new SettingsAccessItem(player);
final AdminAccessItem adminAccessItem = new AdminAccessItem(player);
final RandomSkinItem randomSkinItem = new RandomSkinItem(player);
this.gui = Gui.normal()
.setStructure(dynamicStructure)
@ -48,6 +46,7 @@ public class HomeGUI {
.addIngredient('S', changeSkinItem.get())
.addIngredient('P', settingsAccessItem.get())
.addIngredient('A', adminAccessItem.get())
.addIngredient('D', randomSkinItem.get())
.build();
this.player = player;
}

View file

@ -1,5 +1,6 @@
package xyz.ineanto.nicko.gui.items.admin.cache;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
@ -27,7 +28,9 @@ public class CacheEntryItem extends AsyncItem {
private final MojangAPI mojangAPI = NickoBukkit.getInstance().getMojangAPI();
public CacheEntryItem(I18N i18n, String uuid) {
super(new ItemBuilder(Material.PAINTING).setDisplayName("§7§oLoading..."), () -> {
super(new ItemBuilder(Material.PAINTING)
.setDisplayName(Component.text(i18n.translateStringWithoutPrefix(I18NDict.GUI.LOADING)).content()),
() -> {
final String dashedUuid = uuid.replaceAll("(.{8})(.{4})(.{4})(.{4})(.+)", "$1-$2-$3-$4-$5");
final UUID uuidObject = UUID.fromString(dashedUuid);
try {

View file

@ -1,5 +1,6 @@
package xyz.ineanto.nicko.gui.items.common;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import xyz.ineanto.nicko.i18n.I18N;
import xyz.ineanto.nicko.i18n.I18NDict;
@ -21,7 +22,7 @@ public class ScrollDownItem extends ScrollItem {
public ItemProvider getItemProvider(ScrollGui gui) {
final ItemBuilder builder = new ItemBuilder(Material.GREEN_STAINED_GLASS_PANE);
final Translation translation = i18n.translate(I18NDict.GUI.SCROLL_DOWN);
builder.setDisplayName(translation.name());
builder.setDisplayName(Component.text(translation.name()).content());
if (!gui.canScroll(1)) translation.lore().forEach(builder::addLoreLines);
return builder;
}

View file

@ -1,5 +1,6 @@
package xyz.ineanto.nicko.gui.items.common;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import xyz.ineanto.nicko.i18n.I18N;
import xyz.ineanto.nicko.i18n.I18NDict;
@ -21,7 +22,7 @@ public class ScrollUpItem extends ScrollItem {
public ItemProvider getItemProvider(ScrollGui gui) {
final ItemBuilder builder = new ItemBuilder(Material.RED_STAINED_GLASS_PANE);
final Translation translation = i18n.translate(I18NDict.GUI.SCROLL_UP);
builder.setDisplayName(translation.name());
builder.setDisplayName(Component.text(translation.name()).content());
if (!gui.canScroll(-1)) translation.lore().forEach(builder::addLoreLines);
return builder;
}

View file

@ -0,0 +1,53 @@
package xyz.ineanto.nicko.gui.items.home;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import xyz.ineanto.nicko.NickoBukkit;
import xyz.ineanto.nicko.appearance.AppearanceManager;
import xyz.ineanto.nicko.i18n.I18N;
import xyz.ineanto.nicko.i18n.I18NDict;
import xyz.ineanto.nicko.profile.NickoProfile;
import xyz.xenondevs.invui.item.builder.SkullBuilder;
import xyz.xenondevs.invui.item.impl.SuppliedItem;
import java.util.Optional;
public class RandomSkinItem {
private final I18N i18n;
private final NickoBukkit instance;
public RandomSkinItem(Player player) {
this.instance = NickoBukkit.getInstance();
this.i18n = new I18N(player);
}
public SuppliedItem get() {
return new SuppliedItem(() -> {
final SkullBuilder.HeadTexture texture = new SkullBuilder.HeadTexture("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzgzMTEzOGMyMDYxMWQzMDJjNDIzZmEzMjM3MWE3NDNkMTc0MzdhMTg5NzNjMzUxOTczNDQ3MGE3YWJiNCJ9fX0=");
final SkullBuilder builder = new SkullBuilder(texture);
return i18n.translateItem(builder, I18NDict.GUI.Home.RANDOM_SKIN);
}, (event) -> {
final Player player = event.getPlayer();
final ClickType clickType = event.getClickType();
if (clickType.isLeftClick() || clickType.isRightClick()) {
final Optional<NickoProfile> optionalProfile = NickoProfile.get(player);
optionalProfile.ifPresent(profile -> {
final String name = instance.getNameFetcher().getRandomUsername();
final String skin = instance.getNameFetcher().getRandomUsername();
profile.setName(name);
profile.setSkin(skin);
instance.getDataStore().updateCache(player.getUniqueId(), profile);
final AppearanceManager appearanceManager = new AppearanceManager(player);
if (!appearanceManager.updatePlayer(true, false).isError()) {
player.sendMessage(i18n.translateString(I18NDict.Event.Appearance.Set.OK));
} else {
player.sendMessage(i18n.translateString(I18NDict.Event.Appearance.Set.ERROR));
}
});
return true;
}
return false;
});
}
}

View file

@ -40,8 +40,6 @@ public class ResetItem {
player.sendMessage(i18n.translateString(I18NDict.Event.Appearance.Remove.OK));
} else {
player.sendMessage(i18n.translateString(I18NDict.Event.Appearance.Remove.ERROR));
profile.setSkin(null);
profile.setName(null);
}
});
return true;

View file

@ -1,5 +1,6 @@
package xyz.ineanto.nicko.gui.items.settings;
import net.kyori.adventure.text.Component;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
@ -59,7 +60,7 @@ public class LanguageCyclingItem {
final Translation translation = i18n.translate(I18NDict.GUI.Settings.LANGUAGE);
final Translation cyclingChoicesTranslation = i18n.translate(I18NDict.GUI.Settings.CYCLING_CHOICES);
builder.setDisplayName(translation.name());
builder.setDisplayName(Component.text(translation.name()).content());
for (Locale value : locales) {
if (locale != value) {
builder.addLoreLines("§7> " + value.getName());

View file

@ -1,6 +1,9 @@
package xyz.ineanto.nicko.i18n;
import com.github.jsixface.YamlConfig;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import org.bukkit.entity.Player;
import xyz.ineanto.nicko.NickoBukkit;
import xyz.ineanto.nicko.profile.NickoProfile;
@ -36,7 +39,18 @@ public class I18N {
public AbstractItemBuilder<?> translateItem(AbstractItemBuilder<?> item, String key, Object... args) {
final Translation translation = translate(key, args);
item.setDisplayName(translation.name());
// Name serialization
final Component deserializedName = MiniMessage.miniMessage().deserialize(translation.name());
final String serializedName = LegacyComponentSerializer.legacySection().serialize(deserializedName);
// Lore serialization
translation.lore().replaceAll(s -> {
final Component deserializedLoreLine = MiniMessage.miniMessage().deserialize(s);
return LegacyComponentSerializer.legacySection().serialize(deserializedLoreLine);
});
item.setDisplayName(serializedName);
translation.lore().forEach(item::addLoreLines);
return item;
}

View file

@ -105,6 +105,7 @@ public class I18NDict {
public static final String CHANGE_SKIN = HOME_KEY + "change_skin";
public static final String CHANGE_BOTH = HOME_KEY + "change_both";
public static final String RESET = HOME_KEY + "reset";
public static final String RANDOM_SKIN = HOME_KEY + "random_skin";
public static final String SETTINGS = HOME_KEY + "settings";
}

View file

@ -39,11 +39,6 @@ gui:
cache: "Nicko > Admin... > Cache"
invalidate_skin: "... > Cache > Invalidate"
cycling_choices:
name: "IGNOREME"
lore:
- "§7§oGet through the values"
- "§7§oby left or right clicking."
exit:
name: "Exit"
go_back:
@ -51,99 +46,97 @@ gui:
unavailable:
name: "Unavailable"
lore:
- "§7§oThis button is disabled."
- "<gray><i>This button is disabled.</i></gray>"
error:
name: "Error!"
lore:
- "§7"
- "§7The item texture failed to load, but it might still work."
- "<gray>The item texture failed to load, but it might still work.</gray>"
loading:
name: "§7§oLoading..."
name: "<gray><i>Loading...</i></gray>"
choice:
confirm:
name: "§aConfirm"
name: "<green>Confirm</green>"
choose:
name: "§6§oChoose an option..."
name: "<gold><i>Choose an option...</i></gold>"
cancel:
name: "§cCancel"
name: "<red>Cancel</red>"
scroll_up:
name: "Scroll up"
lore:
- "§8§o(You can't scroll any higher.)"
- "<dark_gray><i>(You can't scroll any higher.)</i></dark_gray>"
scroll_down:
name: "Scroll down"
lore:
- "§8§o(You can't scroll any further down.)"
- "<dark_gray><i>(You can't scroll any further down.)</i></dark_gray>"
home:
admin:
name: "Administration panel"
lore:
- "§7Configure and manage Nicko."
- "<gray>Configure and manage Nicko.</gray>"
settings:
name: "Settings"
lore:
- "§7Fine tune your experience with Nicko."
- "<gray>Fine tune your experience with Nicko.</gray>"
change_name:
name: "§6Nickname §fchange"
name: "Change your <gold>nickname</gold>"
change_skin:
name: "§6Skin §fchange"
name: "Change your <gold>skin</gold>"
change_both:
name: "Change §6both"
name: "Change <gold>both</gold>"
random_skin:
name: "<rainbow>Get a random appearance!</rainbow>"
reset:
name: "Reset appearance"
lore:
- "§7Completely remove your disguise."
- "<gray>Completely remove your disguise.</gray>"
admin:
manage_cache:
name: "Manage §6skin §fcache..."
name: "Manage the <gold>skin</gold> cache..."
lore:
- "§7View and manage the skin cache."
- "<gray>View and manage the skin cache.</gray>"
manage_player:
name: "Check a player..."
name: "Inspect a player..."
lore:
- "§7See players' disguise information."
- "<gray>See players' disguise information.</gray>"
check:
name: "§6{0}"
name: "<gold>{0}</gold>"
lore:
- "§cNicked: §a{1}"
- "§cName: §6{2}"
- "§cSkin: §6{3}"
- "<red>Nicked:</red> {1}"
- "<red>Name:</red> <gold>{2}</gold>"
- "<red>Skin:</red> <gold>{3}</gold>"
- " "
- "§7§oClick to remove skin!"
- "<gray><i>Click to remove skin!</i></gray>"
cache:
statistics:
name: "Statistics"
lore:
- "§fRequest count: §b{0}"
- "§fNumber of skin cached: §b{1}"
- "§8§oCache is cleared every 24 hours."
- "Request count: <aqua>{0}</aqua>"
- "Number of skin cached: <aqua>{1}</aqua>"
- "<dark_gray><i>Cache is cleared every 24 hours.</i></dark_gray>"
invalidate_cache:
name: "Invalidate cache"
lore:
- "§c§oNOT RECOMMENDED"
- "§7Invalidate the entirety of the skin cache."
- "§7This doesn't reset player's disguises."
- "<red><i>NOT RECOMMENDED</i></red>"
- "<gray>Invalidate the entirety of the skin cache.</gray>"
- "<gray>This doesn't reset player's disguises.</gray>"
invalidate_skin:
name: "Invalidate a skin..."
lore:
- "§7Select a specific skin to invalidate."
- "§7Useful if a skin has been recently updated."
- "<gray>Select a specific skin to invalidate.</gray>"
- "<gray>Useful if a skin has been recently updated.</gray>"
entry:
name: "§6{0}"
name: "<gold>{0}</gold>"
lore:
- "§7Click to invalidate..."
- "<gray>Click to invalidate...</gray>"
settings:
toggleable_button:
name: "IGNORE_ME"
lore:
# {0}/{1} represents the carets that shows the current selected option.
- "§b{0} Disabled"
- "§b{1} Enabled"
- "{0} Disabled"
- "{1} Enabled"
cycling_choices:
name: "IGNORE_ME"
lore:
- "§7§oCycle through the values"
- "§7§oby left or right clicking."
- "<gray><i>Cycle through the values</i></gray>"
- "<gray><i>by left or right clicking.</i></gray>"
language:
name: "Language"
random_skin:

View file

@ -46,84 +46,90 @@ gui:
unavailable:
name: "Indisponible"
lore:
- "§7§oCe boutton est désactivé."
- "<gray><i>Ce boutton est désactivé.</i></gray>"
error:
name: "Erreur!"
lore:
- "<gray>La texture de l'objet n'a pas chargé</gray>"
- "<gray>correctement mais il fonctionne encore.</gray>"
loading:
name: "§7§oChargement..."
name: "<gray><i>Chargement...</i></gray>"
choice:
confirm:
name: "§aConfirmer"
name: "<green>Confirmer</green>"
choose:
name: "§6§oChoisissez une option..."
name: "<gold><i>Choisissez une option...</i></gold>"
cancel:
name: "§cAnnuler"
name: "<red>Annuler</red>"
scroll_up:
name: "Défiler vers le haut"
lore:
- "§8§o(Impossible de défiler plus haut.)"
- "<dark_gray><i>(Impossible de défiler plus haut.)</i></dark_gray>"
scroll_down:
name: "Défiler vers le bas"
lore:
- "§8§o(Impossible de défiler plus bas.)"
- "<dark_gray><i>(Impossible de défiler plus bas.)</i></dark_gray>"
home:
admin:
name: "Panel d'administration"
lore:
- "§7Configurez et gérez Nicko."
- "<gray>Configurez et gérez Nicko.</gray>"
settings:
name: "Paramètres"
lore:
- "§7Gérez votre expérience avec Nicko."
- "<gray>Gérez votre expérience avec Nicko.</gray>"
change_name:
name: "Changer le §6pseudo"
name: "Changer le <gold>pseudo</gold>"
change_skin:
name: "Changer le §6skin"
name: "Changer le <gold>skin</gold>"
change_both:
name: "Changer les §6deux"
name: "Changer les <gold>deux</gold>"
random_skin:
name: "<rainbow>Obtenir une apparence aléatoire !</rainbow>"
reset:
name: "Réinitialiser l'apparence"
lore:
- "§7Supprime complètement votre déguisement."
- "<gray>Supprime complètement votre déguisement.</gray>"
admin:
manage_cache:
name: "Gérer le cache de §6skin..."
name: "Gérer le cache de <gold>skin...</gold>"
lore:
- "§7Consultez et gérez le cache de skin."
- "<gray>Consultez et gérez le cache de skin.</gray>"
manage_player:
name: "Vérifier un joueur..."
lore:
- "§7Vérifiez les informations de déguisement d'un joueur."
- "<gray>Vérifiez les informations de déguisement d'un joueur.</gray>"
check:
name: "§6{0}"
name: "<gold>{0}</gold>"
lore:
- "§cDéguisé: §a{1}"
- "§cNom: §6{2}"
- "§cSkin: §6{3}"
- "<red>Déguisé:</red> {1}"
- "<red>Nom:</red> <gold>{2}</gold>"
- "<red>Skin:</red> <gold>{3}</gold>"
- " "
- "§7§oCliquez pour retirer le skin!"
- "<gray><i>Cliquez pour retirer le skin !</i></gray>"
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."
- "Nombre de requêtes: <aqua>{0}</aqua>"
- "Nb. de skin dans le cache: <aqua>{1}</aqua>"
- "<dark_gray><i>Le cache est vidé toutes les 24 heures.</i></dark_gray>"
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."
- "<red><i>DÉCONSEILLÉ</i></red>"
- "<gray>Invalide l'entièreté du cache des skin.</gray>"
- "<gray>Ne retire pas les déguisements des joueurs.</gray>"
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."
- "<gray>Sélectionnez une apparence spécifique à</gray>"
- "<gray>invalider. Utile dans le cas où un skin</gray>"
- "<gray>a récemment été mis à jour.</gray>"
entry:
name: "§6{0}"
name: "<gold>{0}</gold>"
lore:
- "§7Cliquez pour invalider..."
- "<gray>Cliquez pour invalider...</gray>"
settings:
toggleable_button:
lore:
@ -131,8 +137,8 @@ gui:
- "{1} Activé"
cycling_choices:
lore:
- "§7§oParcourez les valeurs"
- "§7§oavec un clique gauche/droit."
- "<gray><i>Parcourez les valeurs</i></gray>"
- "<gray><i>avec un clique gauche/droit.</i></gray>"
language:
name: "Langage"
random_skin: