feat: add click interaction with favorite item
This commit is contained in:
parent
d7663ab463
commit
18a533667e
4 changed files with 49 additions and 16 deletions
|
@ -5,7 +5,7 @@ plugins {
|
|||
}
|
||||
|
||||
group = "xyz.ineanto"
|
||||
version = "1.2.0"
|
||||
version = "1.3.0"
|
||||
|
||||
val invuiVersion: String = "1.44"
|
||||
|
||||
|
|
|
@ -2,45 +2,78 @@ package xyz.ineanto.nicko.gui.items.favorites;
|
|||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import xyz.ineanto.nicko.Nicko;
|
||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||
import xyz.ineanto.nicko.appearance.Appearance;
|
||||
import xyz.ineanto.nicko.appearance.AppearanceManager;
|
||||
import xyz.ineanto.nicko.gui.items.ItemDefaults;
|
||||
import xyz.ineanto.nicko.language.LanguageKey;
|
||||
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.SkullBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.AsyncItem;
|
||||
import xyz.xenondevs.invui.util.MojangApiUtils;
|
||||
|
||||
import java.io.IOException;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
|
||||
public class FavoriteAppearanceEntryItem {
|
||||
private final PlayerDataStore dataStore = Nicko.getInstance().getDataStore();
|
||||
|
||||
private final AppearanceManager appearanceManager;
|
||||
private final PlayerLanguage playerLanguage;
|
||||
private final Appearance appearance;
|
||||
private final Player player;
|
||||
|
||||
public FavoriteAppearanceEntryItem(Player player, Appearance appearance) {
|
||||
this.player = player;
|
||||
this.appearanceManager = new AppearanceManager(player);
|
||||
this.playerLanguage = new PlayerLanguage(player);
|
||||
this.appearance = appearance;
|
||||
}
|
||||
|
||||
public AsyncItem get() {
|
||||
// TODO (Ineanto, 26/06/2025): handle click
|
||||
final ItemBuilder temporaryItemBuilder = new ItemBuilder(Material.PAINTING);
|
||||
return new AsyncItem(playerLanguage.translateItem(temporaryItemBuilder, LanguageKey.GUI.LOADING),
|
||||
() -> {
|
||||
// what the f is this entanglement of suppliers
|
||||
return new AsyncItem(playerLanguage.translateItem(new ItemBuilder(Material.PAINTING), LanguageKey.GUI.LOADING),
|
||||
() -> new SuppliedItem(() -> {
|
||||
try {
|
||||
// TODO (Ineanto, 08/06/2025): set a default skin if the entry contains only a name
|
||||
final String name = (appearance.name() == null ? "N/A" : appearance.name());
|
||||
final String skin = (appearance.skin() == null ? "N/A" : appearance.skin());
|
||||
final SkullBuilder skull = new SkullBuilder(skin);
|
||||
return playerLanguage.translateItem(skull, LanguageKey.GUI.Favorites.ENTRY, name, skin);
|
||||
} catch (MojangApiUtils.MojangApiException | IOException e) {
|
||||
} catch (Exception e) {
|
||||
Nicko.getInstance().getLogger().warning("Unable to get Head texture for specified UUID (" + appearance.skin() + ")! (GUI/Favorites/Entry)");
|
||||
return ItemDefaults.getErrorSkullItem(playerLanguage, LanguageKey.GUI.Favorites.ENTRY, "N/A", "N/A");
|
||||
}
|
||||
});
|
||||
}, (click) -> {
|
||||
System.out.println("there's a click folks!");
|
||||
final ClickType clickType = click.getClickType();
|
||||
|
||||
if (clickType.isLeftClick() || clickType.isRightClick()) {
|
||||
click.getEvent().getView().close();
|
||||
final NickoProfile profile = dataStore.getData(player.getUniqueId()).orElse(NickoProfile.EMPTY_PROFILE);
|
||||
|
||||
profile.setName(appearance.name());
|
||||
profile.setSkin(appearance.skin());
|
||||
dataStore.updateCache(player.getUniqueId(), profile);
|
||||
|
||||
final ActionResult result = appearanceManager.update(true);
|
||||
if (!result.isError()) {
|
||||
player.sendMessage(playerLanguage.translateWithWhoosh(LanguageKey.Event.Appearance.Set.OK));
|
||||
return true;
|
||||
} else {
|
||||
player.sendMessage(playerLanguage.translateWithOops(
|
||||
LanguageKey.Event.Appearance.Set.ERROR,
|
||||
result.getErrorKey()
|
||||
)
|
||||
);
|
||||
appearanceManager.reset();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}).getItemProvider()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -169,7 +169,7 @@ gui:
|
|||
- "<grey>Clicking on any disguise as this mode is</grey>"
|
||||
- "<grey>active will remove it from your favorites.</grey>"
|
||||
entry:
|
||||
name: "Favorite"
|
||||
name: "<gold>Favorite</gold>"
|
||||
lore:
|
||||
- "<gray>Name:</gray> <green>{0}</green>"
|
||||
- "<gray>Skin:</gray> <green>{1}</green>"
|
||||
- "<gray>Name:</gray> <yellow>{0}</yellow>"
|
||||
- "<gray>Skin:</gray> <yellow>{1}</yellow>"
|
|
@ -171,7 +171,7 @@ gui:
|
|||
- "<grey>Cliquer sur un déguisement lorsque le mode est</grey>"
|
||||
- "<grey>actif le supprimera de vos favoris.</grey>"
|
||||
entry:
|
||||
name: "Favori"
|
||||
name: "<gold>Favori</gold>"
|
||||
lore:
|
||||
- "<gray>Nom:</gray> <green>{0}</green>"
|
||||
- "<gray>Skin:</gray> <green>{1}</green>"
|
||||
- "<gray>Nom:</gray> <yellow>{0}</yellow>"
|
||||
- "<gray>Skin:</gray> <yellow>{1}</yellow>"
|
Loading…
Add table
Add a link
Reference in a new issue