fix: persistence, i18n
This commit is contained in:
parent
618af08024
commit
8d87cddbea
8 changed files with 44 additions and 25 deletions
|
@ -44,7 +44,7 @@ public class AnvilManager {
|
|||
getNameAnvil().open(player);
|
||||
}
|
||||
|
||||
public AnvilGUI.Builder getNameThenSkinAnvil() {
|
||||
private AnvilGUI.Builder getNameThenSkinAnvil() {
|
||||
return new AnvilGUI.Builder()
|
||||
.plugin(NickoBukkit.getInstance())
|
||||
.itemLeft(getLeftItem(false))
|
||||
|
@ -65,7 +65,7 @@ public class AnvilManager {
|
|||
.text("New name...");
|
||||
}
|
||||
|
||||
public AnvilGUI.Builder getNameAnvil() {
|
||||
private AnvilGUI.Builder getNameAnvil() {
|
||||
return new AnvilGUI.Builder()
|
||||
.plugin(NickoBukkit.getInstance())
|
||||
.itemLeft(getLeftItem(false))
|
||||
|
|
|
@ -21,7 +21,6 @@ import xyz.atnrch.nicko.wrapper.*;
|
|||
import java.io.IOException;
|
||||
import java.util.EnumSet;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class AppearanceManager {
|
||||
|
@ -29,35 +28,29 @@ public class AppearanceManager {
|
|||
private final PlayerDataStore dataStore = instance.getDataStore();
|
||||
private final PlayerNameStore nameStore = instance.getNameStore();
|
||||
|
||||
private final NickoProfile profile;
|
||||
private final Player player;
|
||||
private final UUID uuid;
|
||||
|
||||
public AppearanceManager(Player player) {
|
||||
this.uuid = player.getUniqueId();
|
||||
this.player = player;
|
||||
|
||||
final Optional<NickoProfile> optionalProfile = dataStore.getData(player.getUniqueId());
|
||||
this.profile = optionalProfile.orElse(NickoProfile.EMPTY_PROFILE.clone());
|
||||
if (!optionalProfile.isPresent()) {
|
||||
instance.getLogger().warning("Unable to appearance data for: " + player.getUniqueId() + ".");
|
||||
}
|
||||
}
|
||||
|
||||
public ActionResult reset() {
|
||||
final NickoProfile profile = getNickoProfile();
|
||||
final String defaultName = nameStore.getStoredName(player);
|
||||
profile.setName(defaultName);
|
||||
profile.setSkin(defaultName);
|
||||
dataStore.getCache().cache(player.getUniqueId(), profile);
|
||||
final ActionResult actionResult = updatePlayer(true, true);
|
||||
if (!actionResult.isError()) {
|
||||
profile.setSkin(null);
|
||||
profile.setName(null);
|
||||
dataStore.getCache().cache(uuid, profile);
|
||||
dataStore.getCache().cache(player.getUniqueId(), profile);
|
||||
}
|
||||
return actionResult;
|
||||
}
|
||||
|
||||
public ActionResult updatePlayer(boolean skinChange, boolean reset) {
|
||||
final NickoProfile profile = getNickoProfile();
|
||||
final String displayName = profile.getName() == null ? player.getName() : profile.getName();
|
||||
final WrappedGameProfile gameProfile = WrappedGameProfile.fromPlayer(player).withName(displayName);
|
||||
final ActionResult result = updateGameProfileSkin(gameProfile, skinChange, reset);
|
||||
|
@ -70,6 +63,11 @@ public class AppearanceManager {
|
|||
return result;
|
||||
}
|
||||
|
||||
private NickoProfile getNickoProfile() {
|
||||
final Optional<NickoProfile> optionalProfile = dataStore.getData(player.getUniqueId());
|
||||
return optionalProfile.orElse(NickoProfile.EMPTY_PROFILE.clone());
|
||||
}
|
||||
|
||||
public void updateOthers() {
|
||||
final WrapperPlayServerEntityDestroy destroy = new WrapperPlayServerEntityDestroy();
|
||||
final WrapperPlayServerNamedEntitySpawn spawn = new WrapperPlayServerNamedEntitySpawn();
|
||||
|
@ -85,9 +83,10 @@ public class AppearanceManager {
|
|||
|
||||
|
||||
private ActionResult updateGameProfileSkin(WrappedGameProfile gameProfile, boolean skinChange, boolean reset) {
|
||||
final boolean changeOnlyName = profile.getSkin() != null && !profile.getSkin().equalsIgnoreCase(player.getName());
|
||||
final NickoProfile profile = getNickoProfile();
|
||||
final boolean changeOnlyName = profile.getSkin() != null && profile.getSkin().equals(player.getName());
|
||||
|
||||
if (skinChange || changeOnlyName) {
|
||||
if (skinChange || !changeOnlyName) {
|
||||
Optional<MojangSkin> skin;
|
||||
try {
|
||||
final MojangAPI mojangAPI = NickoBukkit.getInstance().getMojangAPI();
|
||||
|
|
|
@ -9,7 +9,6 @@ import xyz.atnrch.nicko.appearance.ActionResult;
|
|||
import xyz.atnrch.nicko.appearance.AppearanceManager;
|
||||
import xyz.atnrch.nicko.i18n.I18N;
|
||||
import xyz.atnrch.nicko.mojang.MojangUtils;
|
||||
import xyz.atnrch.nicko.profile.AppearanceData;
|
||||
import xyz.atnrch.nicko.profile.NickoProfile;
|
||||
import xyz.atnrch.nicko.storage.PlayerDataStore;
|
||||
|
||||
|
@ -57,10 +56,10 @@ public class NickoDebugCmd {
|
|||
if (optionalProfile.isPresent()) {
|
||||
final NickoProfile profile = optionalProfile.get();
|
||||
final PlayerDataStore dataStore = NickoBukkit.getInstance().getDataStore();
|
||||
final AppearanceManager appearanceManager = new AppearanceManager(target);
|
||||
profile.setName(name);
|
||||
profile.setSkin(skin);
|
||||
dataStore.updateCache(target.getUniqueId(), profile);
|
||||
final AppearanceManager appearanceManager = new AppearanceManager(target);
|
||||
final ActionResult result = appearanceManager.updatePlayer(true, false);
|
||||
if (!result.isError()) {
|
||||
target.sendMessage(prefix + "§aWhoosh!");
|
||||
|
|
|
@ -26,9 +26,11 @@ public class HomeGUI {
|
|||
dynamicStructure[2] = dynamicStructure[2].replace("A", "#");
|
||||
}
|
||||
|
||||
final ExitItem exitItem = new ExitItem(player);
|
||||
|
||||
this.gui = Gui.normal()
|
||||
.setStructure(dynamicStructure)
|
||||
.addIngredient('E', new ExitItem())
|
||||
.addIngredient('E', exitItem.get())
|
||||
.addIngredient('R', new ResetItem())
|
||||
.addIngredient('N', new ChangeNameItem())
|
||||
.addIngredient('B', new ChangeBothItem())
|
||||
|
|
|
@ -22,7 +22,7 @@ public class PlayerInformationItem extends AsyncItem {
|
|||
final Optional<NickoProfile> optionalProfile = dataStore.getData(uuid);
|
||||
|
||||
optionalProfile.ifPresent(profile -> {
|
||||
if (!profile.hasData()) {
|
||||
if (profile.hasData()) {
|
||||
skull.addLoreLines(
|
||||
"§cNicked: §a✔",
|
||||
"§cName: §6" + profile.getName(),
|
||||
|
|
|
@ -1,17 +1,34 @@
|
|||
package xyz.atnrch.nicko.gui.items.home;
|
||||
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import xyz.atnrch.nicko.i18n.I18N;
|
||||
import xyz.atnrch.nicko.i18n.I18NDict;
|
||||
import xyz.atnrch.nicko.i18n.ItemTranslation;
|
||||
import xyz.xenondevs.invui.item.builder.ItemBuilder;
|
||||
import xyz.xenondevs.invui.item.impl.SimpleItem;
|
||||
import xyz.xenondevs.invui.item.impl.SuppliedItem;
|
||||
|
||||
public class ExitItem extends SimpleItem {
|
||||
public ExitItem() {
|
||||
super(new ItemBuilder(Material.OAK_DOOR).setDisplayName("Exit"), click -> {
|
||||
public class ExitItem {
|
||||
private final I18N i18n;
|
||||
|
||||
public ExitItem(Player player) {
|
||||
this.i18n = new I18N(player);
|
||||
}
|
||||
|
||||
public SuppliedItem get() {
|
||||
return new SuppliedItem(() -> {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.OAK_DOOR);
|
||||
final ItemTranslation translation = i18n.translateItem(I18NDict.GUI.EXIT);
|
||||
builder.setDisplayName(translation.getName());
|
||||
return builder;
|
||||
}, click -> {
|
||||
click.getEvent().getView().close();
|
||||
final ClickType clickType = click.getClickType();
|
||||
if (clickType.isLeftClick() || clickType.isRightClick()) {
|
||||
click.getEvent().getView().close();
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,7 +28,8 @@ event:
|
|||
invalidate_entry: "§6{0} §fhas been invalidated."
|
||||
|
||||
gui:
|
||||
exit: "Exit"
|
||||
exit:
|
||||
name: "Exit"
|
||||
go_back:
|
||||
name: "Back"
|
||||
home:
|
||||
|
|
|
@ -28,7 +28,8 @@ event:
|
|||
invalidate_entry: "§6{0} §fa été invalidé."
|
||||
|
||||
gui:
|
||||
exit: "Quitter"
|
||||
exit:
|
||||
name: "Quitter"
|
||||
go_back:
|
||||
name: "Retour"
|
||||
home:
|
||||
|
|
Loading…
Reference in a new issue