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"
|
group = "xyz.ineanto"
|
||||||
version = "1.2.0"
|
version = "1.3.0"
|
||||||
|
|
||||||
val invuiVersion: String = "1.44"
|
val invuiVersion: String = "1.44"
|
||||||
|
|
||||||
|
|
|
@ -2,45 +2,78 @@ package xyz.ineanto.nicko.gui.items.favorites;
|
||||||
|
|
||||||
import org.bukkit.Material;
|
import org.bukkit.Material;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
import org.bukkit.event.inventory.ClickType;
|
||||||
import xyz.ineanto.nicko.Nicko;
|
import xyz.ineanto.nicko.Nicko;
|
||||||
|
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||||
import xyz.ineanto.nicko.appearance.Appearance;
|
import xyz.ineanto.nicko.appearance.Appearance;
|
||||||
import xyz.ineanto.nicko.appearance.AppearanceManager;
|
import xyz.ineanto.nicko.appearance.AppearanceManager;
|
||||||
import xyz.ineanto.nicko.gui.items.ItemDefaults;
|
import xyz.ineanto.nicko.gui.items.ItemDefaults;
|
||||||
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.builder.SkullBuilder;
|
import xyz.xenondevs.invui.item.builder.SkullBuilder;
|
||||||
import xyz.xenondevs.invui.item.impl.AsyncItem;
|
import xyz.xenondevs.invui.item.impl.AsyncItem;
|
||||||
import xyz.xenondevs.invui.util.MojangApiUtils;
|
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class FavoriteAppearanceEntryItem {
|
public class FavoriteAppearanceEntryItem {
|
||||||
|
private final PlayerDataStore dataStore = Nicko.getInstance().getDataStore();
|
||||||
|
|
||||||
private final AppearanceManager appearanceManager;
|
private final AppearanceManager appearanceManager;
|
||||||
private final PlayerLanguage playerLanguage;
|
private final PlayerLanguage playerLanguage;
|
||||||
private final Appearance appearance;
|
private final Appearance appearance;
|
||||||
|
private final Player player;
|
||||||
|
|
||||||
public FavoriteAppearanceEntryItem(Player player, Appearance appearance) {
|
public FavoriteAppearanceEntryItem(Player player, Appearance appearance) {
|
||||||
|
this.player = player;
|
||||||
this.appearanceManager = new AppearanceManager(player);
|
this.appearanceManager = new AppearanceManager(player);
|
||||||
this.playerLanguage = new PlayerLanguage(player);
|
this.playerLanguage = new PlayerLanguage(player);
|
||||||
this.appearance = appearance;
|
this.appearance = appearance;
|
||||||
}
|
}
|
||||||
|
|
||||||
public AsyncItem get() {
|
public AsyncItem get() {
|
||||||
// TODO (Ineanto, 26/06/2025): handle click
|
// what the f is this entanglement of suppliers
|
||||||
final ItemBuilder temporaryItemBuilder = new ItemBuilder(Material.PAINTING);
|
return new AsyncItem(playerLanguage.translateItem(new ItemBuilder(Material.PAINTING), LanguageKey.GUI.LOADING),
|
||||||
return new AsyncItem(playerLanguage.translateItem(temporaryItemBuilder, LanguageKey.GUI.LOADING),
|
() -> new SuppliedItem(() -> {
|
||||||
() -> {
|
|
||||||
try {
|
try {
|
||||||
// TODO (Ineanto, 08/06/2025): set a default skin if the entry contains only a name
|
// 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 name = (appearance.name() == null ? "N/A" : appearance.name());
|
||||||
final String skin = (appearance.skin() == null ? "N/A" : appearance.skin());
|
final String skin = (appearance.skin() == null ? "N/A" : appearance.skin());
|
||||||
final SkullBuilder skull = new SkullBuilder(skin);
|
final SkullBuilder skull = new SkullBuilder(skin);
|
||||||
return playerLanguage.translateItem(skull, LanguageKey.GUI.Favorites.ENTRY, name, 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)");
|
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");
|
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>Clicking on any disguise as this mode is</grey>"
|
||||||
- "<grey>active will remove it from your favorites.</grey>"
|
- "<grey>active will remove it from your favorites.</grey>"
|
||||||
entry:
|
entry:
|
||||||
name: "Favorite"
|
name: "<gold>Favorite</gold>"
|
||||||
lore:
|
lore:
|
||||||
- "<gray>Name:</gray> <green>{0}</green>"
|
- "<gray>Name:</gray> <yellow>{0}</yellow>"
|
||||||
- "<gray>Skin:</gray> <green>{1}</green>"
|
- "<gray>Skin:</gray> <yellow>{1}</yellow>"
|
|
@ -171,7 +171,7 @@ gui:
|
||||||
- "<grey>Cliquer sur un déguisement lorsque le mode est</grey>"
|
- "<grey>Cliquer sur un déguisement lorsque le mode est</grey>"
|
||||||
- "<grey>actif le supprimera de vos favoris.</grey>"
|
- "<grey>actif le supprimera de vos favoris.</grey>"
|
||||||
entry:
|
entry:
|
||||||
name: "Favori"
|
name: "<gold>Favori</gold>"
|
||||||
lore:
|
lore:
|
||||||
- "<gray>Nom:</gray> <green>{0}</green>"
|
- "<gray>Nom:</gray> <yellow>{0}</yellow>"
|
||||||
- "<gray>Skin:</gray> <green>{1}</green>"
|
- "<gray>Skin:</gray> <yellow>{1}</yellow>"
|
Loading…
Add table
Add a link
Reference in a new issue