feat: add apparence to gui

This commit is contained in:
ineanto 2025-06-12 12:47:52 +02:00
parent 02fd88d9c9
commit bf1d360bd5
Signed by: ineanto
GPG key ID: E511F9CAA2F9CE84
5 changed files with 36 additions and 15 deletions

View file

@ -28,22 +28,16 @@ public class AppearanceManager {
public ActionResult reset() { public ActionResult reset() {
final NickoProfile profile = getNickoProfile(); final NickoProfile profile = getNickoProfile();
final String defaultName = nameStore.getStoredName(player);
// Call the event. // Call the event.
final PlayerResetDisguiseEvent event = new PlayerResetDisguiseEvent(player); final PlayerResetDisguiseEvent event = new PlayerResetDisguiseEvent(player);
Bukkit.getPluginManager().callEvent(event); Bukkit.getPluginManager().callEvent(event);
profile.setName(defaultName);
profile.setSkin(defaultName);
final ActionResult result = update(true);
profile.setName(null); profile.setName(null);
profile.setSkin(null); profile.setSkin(null);
dataStore.getCache().cache(player.getUniqueId(), profile); dataStore.getCache().cache(player.getUniqueId(), profile);
return result; return ActionResult.error();
} }
public ActionResult update(boolean skinChange) { public ActionResult update(boolean skinChange) {

View file

@ -36,7 +36,7 @@ public class FavoritesGUI {
final ScrollUpItem scrollUpItem = new ScrollUpItem(playerLanguage); final ScrollUpItem scrollUpItem = new ScrollUpItem(playerLanguage);
final ScrollDownItem scrollDownItem = new ScrollDownItem(playerLanguage); final ScrollDownItem scrollDownItem = new ScrollDownItem(playerLanguage);
final FavoriteAddItem favoriteAddItem = new FavoriteAddItem(playerLanguage); final FavoriteAddItem favoriteAddItem = new FavoriteAddItem(player);
final FavoriteRemoveItem favoriteRemoveItem = new FavoriteRemoveItem(playerLanguage); final FavoriteRemoveItem favoriteRemoveItem = new FavoriteRemoveItem(playerLanguage);
final NickoProfile profile = Nicko.getInstance().getDataStore().getData(player.getUniqueId()).orElse(NickoProfile.EMPTY_PROFILE); final NickoProfile profile = Nicko.getInstance().getDataStore().getData(player.getUniqueId()).orElse(NickoProfile.EMPTY_PROFILE);

View file

@ -6,20 +6,34 @@ import org.bukkit.DyeColor;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.block.banner.Pattern; import org.bukkit.block.banner.Pattern;
import org.bukkit.block.banner.PatternType; import org.bukkit.block.banner.PatternType;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.ClickType; import org.bukkit.event.inventory.ClickType;
import org.bukkit.inventory.ItemFlag; import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BannerMeta; import org.bukkit.inventory.meta.BannerMeta;
import xyz.ineanto.nicko.Nicko;
import xyz.ineanto.nicko.appearance.Appearance;
import xyz.ineanto.nicko.gui.FavoritesGUI;
import xyz.ineanto.nicko.language.LanguageKey; import xyz.ineanto.nicko.language.LanguageKey;
import xyz.ineanto.nicko.language.PlayerLanguage; import xyz.ineanto.nicko.language.PlayerLanguage;
import xyz.ineanto.nicko.profile.NickoProfile;
import xyz.ineanto.nicko.storage.PlayerDataStore;
import xyz.xenondevs.invui.item.builder.ItemBuilder; import xyz.xenondevs.invui.item.builder.ItemBuilder;
import xyz.xenondevs.invui.item.impl.SuppliedItem; import xyz.xenondevs.invui.item.impl.SuppliedItem;
public class FavoriteAddItem { import java.util.List;
private final PlayerLanguage playerLanguage;
public FavoriteAddItem(PlayerLanguage playerLanguage) { public class FavoriteAddItem {
this.playerLanguage = playerLanguage; private final PlayerDataStore dataStore = Nicko.getInstance().getDataStore();
private final Player player;
private final PlayerLanguage playerLanguage;
private final NickoProfile profile;
public FavoriteAddItem(Player player) {
this.player = player;
this.playerLanguage = new PlayerLanguage(player);
this.profile = dataStore.getData(player.getUniqueId()).orElse(NickoProfile.EMPTY_PROFILE);
} }
public SuppliedItem get() { public SuppliedItem get() {
@ -50,8 +64,17 @@ public class FavoriteAddItem {
return playerLanguage.translateItem(builder, LanguageKey.GUI.Favorites.ADD); return playerLanguage.translateItem(builder, LanguageKey.GUI.Favorites.ADD);
}, click -> { }, click -> {
final ClickType clickType = click.getClickType(); final ClickType clickType = click.getClickType();
if (clickType.isLeftClick() || clickType.isRightClick()) { if (clickType.isShiftClick() && clickType.isLeftClick()) {
click.getEvent().getView().close(); if (!profile.hasData()) {
click.getEvent().getView().close();
return false;
}
final List<Appearance> favorites = profile.getFavorites();
favorites.add(profile.getAppearance());
profile.setFavorites(favorites);
dataStore.updateCache(player.getUniqueId(), profile);
new FavoritesGUI(player).open();
return true; return true;
} }
return false; return false;

View file

@ -46,7 +46,7 @@ public class RandomSkinItem {
} else { } else {
player.sendMessage(playerLanguage.translateWithOops( player.sendMessage(playerLanguage.translateWithOops(
LanguageKey.Event.Appearance.Set.ERROR, LanguageKey.Event.Appearance.Set.ERROR,
playerLanguage.translate(result.getErrorKey(), false) result.getErrorKey()
) )
); );
appearanceManager.reset(); appearanceManager.reset();

View file

@ -42,6 +42,10 @@ public class NickoProfile implements Cloneable {
return dataStore.getData(uuid); return dataStore.getData(uuid);
} }
public Appearance getAppearance() {
return appearance;
}
public boolean hasData() { public boolean hasData() {
return appearance.name() != null || appearance.skin() != null; return appearance.name() != null || appearance.skin() != null;
} }