fix(favorite/item): i had forgor how to use library
This commit is contained in:
parent
9b6e7e0f8e
commit
b7ac5862eb
3 changed files with 37 additions and 41 deletions
1
TODO
Normal file
1
TODO
Normal file
|
@ -0,0 +1 @@
|
||||||
|
nom non mis à jour lors de la connection du joueur
|
|
@ -47,7 +47,7 @@ public class FavoritesGUI {
|
||||||
items = Collections.emptyList();
|
items = Collections.emptyList();
|
||||||
} else {
|
} else {
|
||||||
items = favorites.stream()
|
items = favorites.stream()
|
||||||
.map((appearance) -> new FavoriteAppearanceEntryItem(player, appearance).get())
|
.map((appearance) -> new FavoriteAppearanceEntryItem(playerLanguage, appearance))
|
||||||
.collect(Collectors.toList());
|
.collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,8 @@ 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 org.bukkit.event.inventory.ClickType;
|
||||||
|
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import xyz.ineanto.nicko.Nicko;
|
import xyz.ineanto.nicko.Nicko;
|
||||||
import xyz.ineanto.nicko.appearance.ActionResult;
|
import xyz.ineanto.nicko.appearance.ActionResult;
|
||||||
import xyz.ineanto.nicko.appearance.Appearance;
|
import xyz.ineanto.nicko.appearance.Appearance;
|
||||||
|
@ -17,25 +19,18 @@ 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.item.impl.SuppliedItem;
|
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||||
|
|
||||||
public class FavoriteAppearanceEntryItem {
|
public class FavoriteAppearanceEntryItem extends AsyncItem {
|
||||||
private final PlayerDataStore dataStore = Nicko.getInstance().getDataStore();
|
private final PlayerDataStore dataStore = Nicko.getInstance().getDataStore();
|
||||||
|
|
||||||
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(PlayerLanguage playerLanguage, Appearance appearance) {
|
||||||
this.player = player;
|
super(new SuppliedItem(() -> {
|
||||||
this.appearanceManager = new AppearanceManager(player);
|
final ItemBuilder builder = new ItemBuilder(Material.PAINTING);
|
||||||
this.playerLanguage = new PlayerLanguage(player);
|
return playerLanguage.translateItem(builder, LanguageKey.GUI.LOADING);
|
||||||
this.appearance = appearance;
|
}, (_ -> true)).getItemProvider(),
|
||||||
}
|
() -> {
|
||||||
|
|
||||||
public AsyncItem get() {
|
|
||||||
// what the f is this entanglement of suppliers
|
|
||||||
return new AsyncItem(playerLanguage.translateItem(new ItemBuilder(Material.PAINTING), 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());
|
||||||
|
@ -46,13 +41,17 @@ public class FavoriteAppearanceEntryItem {
|
||||||
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) -> {
|
});
|
||||||
// TODO (Ineanto, 30/06/2025): Doesn't work for some obscure reason.
|
this.playerLanguage = playerLanguage;
|
||||||
final ClickType clickType = click.getClickType();
|
this.appearance = appearance;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||||
if (clickType.isLeftClick() || clickType.isRightClick()) {
|
if (clickType.isLeftClick() || clickType.isRightClick()) {
|
||||||
click.getEvent().getView().close();
|
event.getView().close();
|
||||||
final NickoProfile profile = dataStore.getData(player.getUniqueId()).orElse(NickoProfile.EMPTY_PROFILE);
|
final NickoProfile profile = dataStore.getData(player.getUniqueId()).orElse(NickoProfile.EMPTY_PROFILE);
|
||||||
|
final AppearanceManager appearanceManager = new AppearanceManager(player);
|
||||||
|
|
||||||
profile.setName(appearance.name());
|
profile.setName(appearance.name());
|
||||||
profile.setSkin(appearance.skin());
|
profile.setSkin(appearance.skin());
|
||||||
|
@ -61,7 +60,7 @@ public class FavoriteAppearanceEntryItem {
|
||||||
final ActionResult result = appearanceManager.update(true);
|
final ActionResult result = appearanceManager.update(true);
|
||||||
if (!result.isError()) {
|
if (!result.isError()) {
|
||||||
player.sendMessage(playerLanguage.translateWithWhoosh(LanguageKey.Event.Appearance.Set.OK));
|
player.sendMessage(playerLanguage.translateWithWhoosh(LanguageKey.Event.Appearance.Set.OK));
|
||||||
return true;
|
|
||||||
} else {
|
} else {
|
||||||
player.sendMessage(playerLanguage.translateWithOops(
|
player.sendMessage(playerLanguage.translateWithOops(
|
||||||
LanguageKey.Event.Appearance.Set.ERROR,
|
LanguageKey.Event.Appearance.Set.ERROR,
|
||||||
|
@ -69,11 +68,7 @@ public class FavoriteAppearanceEntryItem {
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
appearanceManager.reset();
|
appearanceManager.reset();
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}).getItemProvider()
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue