feat: add apparence to gui
This commit is contained in:
parent
02fd88d9c9
commit
bf1d360bd5
5 changed files with 36 additions and 15 deletions
|
@ -28,22 +28,16 @@ public class AppearanceManager {
|
|||
|
||||
public ActionResult reset() {
|
||||
final NickoProfile profile = getNickoProfile();
|
||||
final String defaultName = nameStore.getStoredName(player);
|
||||
|
||||
// Call the event.
|
||||
final PlayerResetDisguiseEvent event = new PlayerResetDisguiseEvent(player);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
|
||||
profile.setName(defaultName);
|
||||
profile.setSkin(defaultName);
|
||||
|
||||
final ActionResult result = update(true);
|
||||
|
||||
profile.setName(null);
|
||||
profile.setSkin(null);
|
||||
dataStore.getCache().cache(player.getUniqueId(), profile);
|
||||
|
||||
return result;
|
||||
return ActionResult.error();
|
||||
}
|
||||
|
||||
public ActionResult update(boolean skinChange) {
|
||||
|
|
|
@ -36,7 +36,7 @@ public class FavoritesGUI {
|
|||
final ScrollUpItem scrollUpItem = new ScrollUpItem(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 NickoProfile profile = Nicko.getInstance().getDataStore().getData(player.getUniqueId()).orElse(NickoProfile.EMPTY_PROFILE);
|
||||
|
|
|
@ -6,20 +6,34 @@ import org.bukkit.DyeColor;
|
|||
import org.bukkit.Material;
|
||||
import org.bukkit.block.banner.Pattern;
|
||||
import org.bukkit.block.banner.PatternType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.inventory.ItemFlag;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
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.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.impl.SuppliedItem;
|
||||
|
||||
public class FavoriteAddItem {
|
||||
private final PlayerLanguage playerLanguage;
|
||||
import java.util.List;
|
||||
|
||||
public FavoriteAddItem(PlayerLanguage playerLanguage) {
|
||||
this.playerLanguage = playerLanguage;
|
||||
public class FavoriteAddItem {
|
||||
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() {
|
||||
|
@ -50,8 +64,17 @@ public class FavoriteAddItem {
|
|||
return playerLanguage.translateItem(builder, LanguageKey.GUI.Favorites.ADD);
|
||||
}, click -> {
|
||||
final ClickType clickType = click.getClickType();
|
||||
if (clickType.isLeftClick() || clickType.isRightClick()) {
|
||||
if (clickType.isShiftClick() && clickType.isLeftClick()) {
|
||||
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 false;
|
||||
|
|
|
@ -46,7 +46,7 @@ public class RandomSkinItem {
|
|||
} else {
|
||||
player.sendMessage(playerLanguage.translateWithOops(
|
||||
LanguageKey.Event.Appearance.Set.ERROR,
|
||||
playerLanguage.translate(result.getErrorKey(), false)
|
||||
result.getErrorKey()
|
||||
)
|
||||
);
|
||||
appearanceManager.reset();
|
||||
|
|
|
@ -42,6 +42,10 @@ public class NickoProfile implements Cloneable {
|
|||
return dataStore.getData(uuid);
|
||||
}
|
||||
|
||||
public Appearance getAppearance() {
|
||||
return appearance;
|
||||
}
|
||||
|
||||
public boolean hasData() {
|
||||
return appearance.name() != null || appearance.skin() != null;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue