feat: reset skin via admin panel

This commit is contained in:
ineanto 2023-12-07 16:03:43 +01:00
parent 8611ef2604
commit 4eecbf416e
7 changed files with 62 additions and 17 deletions

View file

@ -6,7 +6,7 @@
<groupId>xyz.ineanto</groupId> <groupId>xyz.ineanto</groupId>
<artifactId>nicko</artifactId> <artifactId>nicko</artifactId>
<version>1.0.3-RC1</version> <version>1.0.4-RC1</version>
<name>Nicko</name> <name>Nicko</name>
<properties> <properties>

View file

@ -1,11 +1,11 @@
package xyz.ineanto.nicko.event; package xyz.ineanto.nicko.event;
import xyz.ineanto.nicko.NickoBukkit;
import xyz.ineanto.nicko.appearance.ActionResult;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerQuitEvent; import org.bukkit.event.player.PlayerQuitEvent;
import xyz.ineanto.nicko.NickoBukkit;
import xyz.ineanto.nicko.appearance.ActionResult;
public class PlayerQuitListener implements Listener { public class PlayerQuitListener implements Listener {
@EventHandler @EventHandler

View file

@ -29,7 +29,7 @@ public class PlayerCheckGUI {
final List<Item> items = Bukkit.getOnlinePlayers().stream() final List<Item> items = Bukkit.getOnlinePlayers().stream()
.map(Entity::getUniqueId) .map(Entity::getUniqueId)
.map(uuid -> new PlayerInformationItem(i18n, uuid)) .map(uuid -> new PlayerInformationItem(i18n, Bukkit.getPlayer(uuid)))
.collect(Collectors.toList()); .collect(Collectors.toList());
final AdminGUI parent = new AdminGUI(player); final AdminGUI parent = new AdminGUI(player);

View file

@ -1,14 +1,19 @@
package xyz.ineanto.nicko.gui.items.admin.check; package xyz.ineanto.nicko.gui.items.admin.check;
import org.bukkit.Bukkit;
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.InventoryClickEvent;
import org.jetbrains.annotations.NotNull;
import xyz.ineanto.nicko.NickoBukkit; import xyz.ineanto.nicko.NickoBukkit;
import xyz.ineanto.nicko.appearance.AppearanceManager;
import xyz.ineanto.nicko.gui.ChoiceGUI;
import xyz.ineanto.nicko.gui.PlayerCheckGUI;
import xyz.ineanto.nicko.gui.items.ItemDefaults; import xyz.ineanto.nicko.gui.items.ItemDefaults;
import xyz.ineanto.nicko.gui.items.common.choice.ChoiceCallback;
import xyz.ineanto.nicko.i18n.I18N; import xyz.ineanto.nicko.i18n.I18N;
import xyz.ineanto.nicko.i18n.I18NDict; import xyz.ineanto.nicko.i18n.I18NDict;
import xyz.ineanto.nicko.profile.NickoProfile; 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;
@ -17,35 +22,61 @@ import xyz.xenondevs.invui.util.MojangApiUtils;
import java.io.IOException; import java.io.IOException;
import java.util.Optional; import java.util.Optional;
import java.util.UUID;
public class PlayerInformationItem extends AsyncItem { public class PlayerInformationItem extends AsyncItem {
public PlayerInformationItem(I18N i18n, UUID uuid) { private final Player target;
private final NickoProfile profile;
public PlayerInformationItem(I18N i18n, Player target) {
super(new SuppliedItem(() -> { super(new SuppliedItem(() -> {
final ItemBuilder builder = new ItemBuilder(Material.PAINTING); final ItemBuilder builder = new ItemBuilder(Material.PAINTING);
return i18n.translateItem(builder, I18NDict.GUI.LOADING); return i18n.translateItem(builder, I18NDict.GUI.LOADING);
}, (click -> true)).getItemProvider(), () -> { }, (click -> true)).getItemProvider(), () -> {
final Player player = Bukkit.getPlayer(uuid);
try { try {
final SkullBuilder skull = new SkullBuilder(uuid); final SkullBuilder skull = new SkullBuilder(target.getUniqueId());
final PlayerDataStore dataStore = NickoBukkit.getInstance().getDataStore(); final Optional<NickoProfile> optionalProfile = NickoBukkit.getInstance().getDataStore().getData(target.getUniqueId());
final Optional<NickoProfile> optionalProfile = dataStore.getData(uuid);
if (optionalProfile.isPresent()) { if (optionalProfile.isPresent()) {
final NickoProfile profile = optionalProfile.get(); final NickoProfile profile = optionalProfile.get();
return i18n.translateItem(skull, I18NDict.GUI.Admin.CHECK, return i18n.translateItem(skull, I18NDict.GUI.Admin.CHECK,
player.getName(), target.getName(),
(profile.hasData() ? "§a✔" : "§c❌"), (profile.hasData() ? "§a✔" : "§c❌"),
(profile.getName() == null ? "§7N/A" : profile.getName()), (profile.getName() == null ? "§7N/A" : profile.getName()),
(profile.getSkin() == null ? "§7N/A" : profile.getSkin())); (profile.getSkin() == null ? "§7N/A" : profile.getSkin()));
} }
} catch (MojangApiUtils.MojangApiException | IOException e) { } catch (MojangApiUtils.MojangApiException | IOException e) {
NickoBukkit.getInstance().getLogger().severe("Unable to get head for specified UUID ( " + uuid + ")! (GUI/PlayerCheck)"); NickoBukkit.getInstance().getLogger().severe("Unable to get head for specified UUID ( " + target.getUniqueId() + ")! (GUI/PlayerCheck)");
} }
return ItemDefaults.getErrorSkullItem(i18n, I18NDict.GUI.Admin.CHECK, return ItemDefaults.getErrorSkullItem(i18n, I18NDict.GUI.Admin.CHECK,
"§4???", "§cN/A", "§cN/A", "§cN/A" "§c§l?!?", "§cN/A", "§cN/A", "§cN/A"
); );
}); });
this.target = target;
this.profile = NickoBukkit.getInstance().getDataStore().getData(target.getUniqueId()).orElse(NickoProfile.EMPTY_PROFILE);
} }
@Override
public void handleClick(@NotNull ClickType click, @NotNull Player player, @NotNull InventoryClickEvent event) {
if (click.isLeftClick() || click.isRightClick()) {
if (profile.hasData()) {
event.getView().close();
new ChoiceGUI(player, new ChoiceCallback() {
@Override
public void onConfirm() {
final AppearanceManager appearanceManager = new AppearanceManager(target);
appearanceManager.reset();
final I18N i18n = new I18N(player);
player.sendMessage(i18n.translate(I18NDict.Event.Admin.Check.REMOVE_SKIN, target.getName()));
}
@Override
public void onCancel() {
new PlayerCheckGUI(player).open();
}
}).open();
}
}
}
} }

View file

@ -28,6 +28,12 @@ public class I18NDict {
public static final String INVALIDATE_ENTRY = CACHE_KEY + "invalidate_entry"; public static final String INVALIDATE_ENTRY = CACHE_KEY + "invalidate_entry";
} }
public static class Check {
private static final String CHECK_KEY = ADMIN_KEY + "check.";
public static final String REMOVE_SKIN = CHECK_KEY + "remove_skin";
}
} }
public static class Settings { public static class Settings {

View file

@ -26,6 +26,8 @@ event:
cache: cache:
invalidate_cache: "§fComplete cache invalidated." invalidate_cache: "§fComplete cache invalidated."
invalidate_entry: "§6{0} §fhas been invalidated." invalidate_entry: "§6{0} §fhas been invalidated."
check:
remove_skin: "§fSkin removed from player."
gui: gui:
title: title:
@ -33,7 +35,7 @@ gui:
settings: "Nicko > Settings" settings: "Nicko > Settings"
admin: "Nicko > Administration" admin: "Nicko > Administration"
check: "Nicko > Admin... > Check" check: "Nicko > Admin... > Check"
confirm: "... > Invalidate > Confirm" confirm: "... > Confirm action"
cache: "Nicko > Admin... > Cache" cache: "Nicko > Admin... > Cache"
invalidate_skin: "... > Cache > Invalidate" invalidate_skin: "... > Cache > Invalidate"
@ -101,6 +103,8 @@ gui:
- "§cNicked: §a{1}" - "§cNicked: §a{1}"
- "§cName: §6{2}" - "§cName: §6{2}"
- "§cSkin: §6{3}" - "§cSkin: §6{3}"
- " "
- "§7§oClick to remove skin!"
cache: cache:
statistics: statistics:
name: "Statistics" name: "Statistics"

View file

@ -26,6 +26,8 @@ event:
cache: cache:
invalidate_cache: "§fCache complet invalidé." invalidate_cache: "§fCache complet invalidé."
invalidate_entry: "§6{0} §fa été invalidé." invalidate_entry: "§6{0} §fa été invalidé."
check:
remove_skin: "§fSkin retiré du joueur."
gui: gui:
title: title:
@ -33,7 +35,7 @@ gui:
settings: "Nicko > Paramètres" settings: "Nicko > Paramètres"
admin: "Nicko > Administration" admin: "Nicko > Administration"
check: "Nicko > Admin... > Vérification" check: "Nicko > Admin... > Vérification"
confirm: "... > Invalider > Confirmer" confirm: "... > Confirmer l'action"
cache: "Nicko > Admin... > Cache" cache: "Nicko > Admin... > Cache"
invalidate_skin: "... > Cache > Invalider" invalidate_skin: "... > Cache > Invalider"
@ -96,6 +98,8 @@ gui:
- "§cDéguisé: §a{1}" - "§cDéguisé: §a{1}"
- "§cNom: §6{2}" - "§cNom: §6{2}"
- "§cSkin: §6{3}" - "§cSkin: §6{3}"
- " "
- "§7§oCliquez pour retirer le skin!"
cache: cache:
statistics: statistics:
name: "Statistiques" name: "Statistiques"