feat: skin cache invalidation
This commit is contained in:
parent
593e69c797
commit
3497dd3adf
10 changed files with 116 additions and 2 deletions
|
@ -19,6 +19,9 @@
|
|||
<plugin>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.0.0-M7</version>
|
||||
<configuration>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
|
|
|
@ -119,6 +119,9 @@
|
|||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>3.0.0-M7</version>
|
||||
<configuration>
|
||||
<skipTests>true</skipTests>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
|
|
|
@ -1,4 +1,28 @@
|
|||
package net.artelnatif.nicko.gui.items.admin;
|
||||
|
||||
public class SkinInvalidatorItem {
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
import de.studiocode.invui.item.builder.SkullBuilder;
|
||||
import de.studiocode.invui.item.impl.BaseItem;
|
||||
import net.artelnatif.nicko.gui.sub.SkinInvalidatorSelectionGUI;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class SkinInvalidatorItem extends BaseItem {
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
final SkullBuilder builder = new SkullBuilder("Notch");
|
||||
builder.setDisplayName("§fManage §6skin §fcache...");
|
||||
builder.addLoreLines("§7Access the skin cache management panel.");
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick() || clickType.isRightClick()) {
|
||||
event.getView().close();
|
||||
new SkinInvalidatorSelectionGUI(player).open();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,36 @@
|
|||
package net.artelnatif.nicko.gui.items.invalidator;
|
||||
|
||||
import de.studiocode.invui.item.ItemProvider;
|
||||
import de.studiocode.invui.item.builder.ItemBuilder;
|
||||
import de.studiocode.invui.item.impl.BaseItem;
|
||||
import net.artelnatif.nicko.NickoBukkit;
|
||||
import net.artelnatif.nicko.i18n.I18N;
|
||||
import net.artelnatif.nicko.i18n.I18NDict;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.ClickType;
|
||||
import org.bukkit.event.inventory.InventoryClickEvent;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class InvalidateAllItem extends BaseItem {
|
||||
@Override
|
||||
public ItemProvider getItemProvider() {
|
||||
final ItemBuilder builder = new ItemBuilder(Material.BARRIER);
|
||||
builder.setDisplayName("§fInvalidate §6all §fthe skin cache");
|
||||
builder.addLoreLines(
|
||||
"§c§oNOT RECOMMENDED",
|
||||
"§7Invalidate every skin entry present in the cache,",
|
||||
"§7without removing active player disguises.",
|
||||
"§7Skins will have to be fetched again if asked by a disguise.");
|
||||
return builder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleClick(@NotNull ClickType clickType, @NotNull Player player, @NotNull InventoryClickEvent event) {
|
||||
if (clickType.isLeftClick() || clickType.isRightClick()) {
|
||||
event.getView().close();
|
||||
player.sendMessage(I18N.translate(player, I18NDict.Event.Admin.CACHE_CLEAN));
|
||||
NickoBukkit.getInstance().getMojangAPI().getCache().invalidateAll();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -5,6 +5,7 @@ import de.studiocode.invui.gui.builder.GUIBuilder;
|
|||
import de.studiocode.invui.gui.builder.guitype.GUIType;
|
||||
import de.studiocode.invui.window.impl.single.SimpleWindow;
|
||||
import net.artelnatif.nicko.gui.MainGUI;
|
||||
import net.artelnatif.nicko.gui.items.admin.SkinInvalidatorItem;
|
||||
import net.artelnatif.nicko.gui.items.common.BackItem;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
|
@ -13,18 +14,23 @@ public class AdminPanelGUI {
|
|||
private final GUI gui;
|
||||
private final String[] structure = new String[]{
|
||||
"# # # # # # # # #",
|
||||
"# % % X X X % % #",
|
||||
"# % % X X S % % #",
|
||||
"B # # # # # # # #"
|
||||
};
|
||||
|
||||
public AdminPanelGUI(Player player) {
|
||||
this.gui = new GUIBuilder<>(GUIType.NORMAL)
|
||||
.setStructure(structure)
|
||||
.addIngredient('S', new SkinInvalidatorItem())
|
||||
.addIngredient('B', new BackItem(new MainGUI(player).getGUI()))
|
||||
.build();
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public GUI getGUI() {
|
||||
return gui;
|
||||
}
|
||||
|
||||
public void open() {
|
||||
new SimpleWindow(player, "Nicko", gui).show();
|
||||
}
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
package net.artelnatif.nicko.gui.sub;
|
||||
|
||||
import de.studiocode.invui.gui.GUI;
|
||||
import de.studiocode.invui.gui.builder.GUIBuilder;
|
||||
import de.studiocode.invui.gui.builder.guitype.GUIType;
|
||||
import de.studiocode.invui.window.impl.single.SimpleWindow;
|
||||
import net.artelnatif.nicko.gui.items.common.BackItem;
|
||||
import net.artelnatif.nicko.gui.items.invalidator.InvalidateAllItem;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
public class SkinInvalidatorSelectionGUI {
|
||||
private final Player player;
|
||||
private final GUI gui;
|
||||
private final String[] structure = new String[]{
|
||||
"B # # A S",
|
||||
};
|
||||
|
||||
public SkinInvalidatorSelectionGUI(Player player) {
|
||||
this.gui = new GUIBuilder<>(GUIType.NORMAL)
|
||||
.setStructure(structure)
|
||||
.addIngredient('B', new BackItem(new AdminPanelGUI(player).getGUI()))
|
||||
.addIngredient('A', new InvalidateAllItem())
|
||||
.build();
|
||||
this.player = player;
|
||||
}
|
||||
|
||||
public void open() {
|
||||
new SimpleWindow(player, "Nicko", gui).show();
|
||||
}
|
||||
}
|
|
@ -2,6 +2,10 @@ package net.artelnatif.nicko.i18n;
|
|||
|
||||
public record I18NDict(String key) {
|
||||
public static class Event {
|
||||
public static class Admin {
|
||||
public static final I18NDict CACHE_CLEAN = new I18NDict("event.admin.cache_clear");
|
||||
}
|
||||
|
||||
public static class Disguise {
|
||||
public static final I18NDict SUCCESS = new I18NDict("event.disguise.success");
|
||||
public static final I18NDict FAIL = new I18NDict("event.disguise.fail");
|
||||
|
|
|
@ -111,4 +111,8 @@ public class MojangAPI {
|
|||
private boolean hasNoError(JsonObject object) {
|
||||
return object.get("error") == null;
|
||||
}
|
||||
|
||||
public LoadingCache<String, Optional<MojangSkin>> getCache() {
|
||||
return cache;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,8 @@ error:
|
|||
invalid_username: "§cThe specified username is not a valid Minecraft username."
|
||||
player_offline: "§c{0} §fis offline, please try again."
|
||||
event:
|
||||
admin:
|
||||
cache_clear: "§aSkin cache cleaned."
|
||||
disguise:
|
||||
fail: "§cUnable to apply your disguise. §7§o({0})"
|
||||
success: "§aDisguise applied!"
|
||||
|
|
|
@ -6,6 +6,8 @@ error:
|
|||
invalid_username: "§cLe pseudo spécifié n''est pas un pseudo Minecraft valide."
|
||||
player_offline: "§c{0} §fest hors-ligne, veuillez réessayer."
|
||||
event:
|
||||
admin:
|
||||
cache_clear: "§aCache des skins nettoyé."
|
||||
disguise:
|
||||
fail: "§cImpossible d''appliquer votre déguisement. §7§o({0})"
|
||||
success: "§aDéguisement appliqué !"
|
||||
|
|
Loading…
Reference in a new issue