feat: add favorites item and gui

This commit is contained in:
ineanto 2025-06-06 19:48:43 +02:00
parent 7eca066cf1
commit 814d7adea7
Signed by: ineanto
GPG key ID: E511F9CAA2F9CE84
6 changed files with 95 additions and 1 deletions

View file

@ -0,0 +1,44 @@
package xyz.ineanto.nicko.gui;
import org.bukkit.entity.Player;
import xyz.ineanto.nicko.gui.items.common.GoBackItem;
import xyz.ineanto.nicko.language.LanguageKey;
import xyz.ineanto.nicko.language.PlayerLanguage;
import xyz.xenondevs.invui.gui.Gui;
import xyz.xenondevs.invui.window.Window;
public class FavoritesGUI {
private final Player player;
private final Gui gui;
private final String title;
public FavoritesGUI(Player player) {
final PlayerLanguage playerLanguage = new PlayerLanguage(player);
this.title = playerLanguage.translate(LanguageKey.GUI.Titles.FAVORITES, false);
final HomeGUI parent = new HomeGUI(player);
final GoBackItem backItem = new GoBackItem(player);
this.gui = Gui.normal()
.setStructure(
"# # # # # # # # #",
"# # # S C E # # #",
"B # # # # # # # #"
)
.addIngredient('B', backItem.get(parent.getGUI(), parent.getTitle()))
.build();
this.player = player;
}
public Gui getGUI() {
return gui;
}
public String getTitle() {
return title;
}
public void open() {
Window.single().setGui(gui).setTitle(title).open(player);
}
}

View file

@ -19,7 +19,7 @@ public class HomeGUI {
final String[] dynamicStructure = new String[]{ final String[] dynamicStructure = new String[]{
"# # # # D # # # #", "# # # # D # # # #",
"A # # N B S # # #", "A # # N B S # # #",
"E P # # # # # # R"}; "E P # # F # # # R"};
if (!player.isOp() || !player.hasPermission("nicko.admin")) { if (!player.isOp() || !player.hasPermission("nicko.admin")) {
dynamicStructure[2] = dynamicStructure[2].replace("A", "#"); dynamicStructure[2] = dynamicStructure[2].replace("A", "#");
@ -36,6 +36,7 @@ public class HomeGUI {
final SettingsAccessItem settingsAccessItem = new SettingsAccessItem(player); final SettingsAccessItem settingsAccessItem = new SettingsAccessItem(player);
final AdminAccessItem adminAccessItem = new AdminAccessItem(player); final AdminAccessItem adminAccessItem = new AdminAccessItem(player);
final RandomSkinItem randomSkinItem = new RandomSkinItem(player); final RandomSkinItem randomSkinItem = new RandomSkinItem(player);
final FavoritesItem favoritesItem = new FavoritesItem(player);
this.gui = Gui.normal() this.gui = Gui.normal()
.setStructure(dynamicStructure) .setStructure(dynamicStructure)
@ -47,6 +48,7 @@ public class HomeGUI {
.addIngredient('P', settingsAccessItem.get()) .addIngredient('P', settingsAccessItem.get())
.addIngredient('A', adminAccessItem.get()) .addIngredient('A', adminAccessItem.get())
.addIngredient('D', randomSkinItem.get()) .addIngredient('D', randomSkinItem.get())
.addIngredient('F', favoritesItem.get())
.build(); .build();
this.player = player; this.player = player;
} }

View file

@ -0,0 +1,36 @@
package xyz.ineanto.nicko.gui.items.home;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType;
import xyz.ineanto.nicko.gui.FavoritesGUI;
import xyz.ineanto.nicko.language.LanguageKey;
import xyz.ineanto.nicko.language.PlayerLanguage;
import xyz.xenondevs.invui.item.builder.ItemBuilder;
import xyz.xenondevs.invui.item.impl.SuppliedItem;
public class FavoritesItem {
private final PlayerLanguage playerLanguage;
public FavoritesItem(Player player) {
this.playerLanguage = new PlayerLanguage(player);
}
public SuppliedItem get() {
return new SuppliedItem(() -> {
final ItemBuilder builder = new ItemBuilder(Material.CHEST);
return playerLanguage.translateItem(builder, LanguageKey.GUI.Home.FAVORITES);
}, click -> {
final Player player = click.getPlayer();
final ClickType clickType = click.getClickType();
if (clickType.isLeftClick() || clickType.isRightClick()) {
click.getEvent().getView().close();
new FavoritesGUI(click.getPlayer()).open();
player.playSound(player.getLocation(), Sound.BLOCK_CHEST_OPEN, 1, 1f);
return true;
}
return false;
});
}
}

View file

@ -92,6 +92,7 @@ public class LanguageKey {
public static final String CONFIRM = TITLE_KEY + "confirm"; public static final String CONFIRM = TITLE_KEY + "confirm";
public static final String CACHE = TITLE_KEY + "cache"; public static final String CACHE = TITLE_KEY + "cache";
public static final String INVALIDATE_SKIN = TITLE_KEY + "invalidate_skin"; public static final String INVALIDATE_SKIN = TITLE_KEY + "invalidate_skin";
public static final String FAVORITES = TITLE_KEY + "favorites";
} }
public static class Choice { public static class Choice {
@ -112,6 +113,7 @@ public class LanguageKey {
public static final String RESET = HOME_KEY + "reset"; public static final String RESET = HOME_KEY + "reset";
public static final String RANDOM_SKIN = HOME_KEY + "random_skin"; public static final String RANDOM_SKIN = HOME_KEY + "random_skin";
public static final String SETTINGS = HOME_KEY + "settings"; public static final String SETTINGS = HOME_KEY + "settings";
public static final String FAVORITES = HOME_KEY + "favorites";
} }
public static class Settings { public static class Settings {

View file

@ -45,6 +45,7 @@ gui:
confirm: "Are you sure?" confirm: "Are you sure?"
cache: "Cache Management" cache: "Cache Management"
invalidate_skin: "Purge cache..." invalidate_skin: "Purge cache..."
favorites: "Favorites"
exit: exit:
name: "Exit" name: "Exit"
@ -100,6 +101,10 @@ gui:
name: "Reset appearance" name: "Reset appearance"
lore: lore:
- "<gray>Completely remove your disguise.</gray>" - "<gray>Completely remove your disguise.</gray>"
favorites:
name: "Favorites"
lore:
- "<gray>List all your favorites appearances.</gray>"
admin: admin:
manage_cache: manage_cache:
name: "Manage the skin cache..." name: "Manage the skin cache..."

View file

@ -45,6 +45,7 @@ gui:
confirm: "Êtes-vous sûr ?" confirm: "Êtes-vous sûr ?"
cache: "Gestion du Cache" cache: "Gestion du Cache"
invalidate_skin: "Purge du cache..." invalidate_skin: "Purge du cache..."
favorites: "Favoris"
exit: exit:
name: "Quitter" name: "Quitter"
@ -101,6 +102,10 @@ gui:
name: "Réinitialiser l'apparence" name: "Réinitialiser l'apparence"
lore: lore:
- "<gray>Supprime complètement votre déguisement.</gray>" - "<gray>Supprime complètement votre déguisement.</gray>"
favorites:
name: "Favoris"
lore:
- "<gray>Listez toutes vos apparences favorites.</gray>"
admin: admin:
manage_cache: manage_cache:
name: "Gérer le cache de skin..." name: "Gérer le cache de skin..."