Skip to content

Commit f088ace

Browse files
committed
address comments
1 parent d425948 commit f088ace

20 files changed

Lines changed: 273 additions & 352 deletions

File tree

src/main/java/dev/noah/perplayerkit/ConfigMigrator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ private Map<String, Object> extractCustomizedStrings(FileConfiguration userConfi
126126

127127
if (userConfig.contains("disabled-command-message")) {
128128
String current = userConfig.getString("disabled-command-message");
129-
String defaultValue = "<red>Kits are disabled here!</red>";
129+
String defaultValue = defaults.getString("error.disabled-in-world");
130130
if (current != null && !current.equals(defaultValue)) {
131131
diffs.put("error.disabled-in-world", current);
132132
}
@@ -151,7 +151,7 @@ private Map<String, Object> extractCustomizedStrings(FileConfiguration userConfi
151151
continue;
152152
}
153153
String current = userConfig.getString(oldPath);
154-
String defaultValue = defaults.getString(oldPath);
154+
String defaultValue = defaults.getString(newKey);
155155
if (current != null && !current.equals(defaultValue)) {
156156
diffs.put(newKey, current);
157157
}

src/main/java/dev/noah/perplayerkit/KitManager.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -370,6 +370,9 @@ private boolean loadKitInternal(Player player, String kitId, Runnable notFoundMe
370370
}
371371

372372
public boolean loadKit(Player player, int slot) {
373+
if (player == null) {
374+
return false;
375+
}
373376
return loadKitInternal(player, IDUtil.getPlayerKitId(player.getUniqueId(), slot),
374377
() -> Lang.get().send(player, "error.kit-slot-not-found", "slot", String.valueOf(slot)),
375378
false, () -> {
@@ -380,6 +383,9 @@ public boolean loadKit(Player player, int slot) {
380383
}
381384

382385
public boolean loadKitSilent(Player player, int slot) {
386+
if (player == null) {
387+
return false;
388+
}
383389
return loadKitInternal(player, IDUtil.getPlayerKitId(player.getUniqueId(), slot), null, false, null);
384390
}
385391

@@ -403,6 +409,9 @@ public boolean loadPublicKitSilent(Player player, String id) {
403409
}
404410

405411
public boolean loadEnderchest(Player player, int slot) {
412+
if (player == null) {
413+
return false;
414+
}
406415
return loadKitInternal(player, IDUtil.getECId(player.getUniqueId(), slot),
407416
() -> Lang.get().send(player, "error.kit-slot-not-found", "slot", String.valueOf(slot)),
408417
true, () -> {
@@ -412,10 +421,16 @@ public boolean loadEnderchest(Player player, int slot) {
412421
}
413422

414423
public boolean loadEnderchestSilent(Player player, int slot) {
424+
if (player == null) {
425+
return false;
426+
}
415427
return loadKitInternal(player, IDUtil.getECId(player.getUniqueId(), slot), null, true, null);
416428
}
417429

418430
public boolean loadLastKit(Player player) {
431+
if (player == null) {
432+
return false;
433+
}
419434
if (lastKitUsedByPlayer.containsKey(player.getUniqueId())) {
420435
return loadKit(player, lastKitUsedByPlayer.get(player.getUniqueId()));
421436
}

src/main/java/dev/noah/perplayerkit/commands/features/RegearCommand.java

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,19 +248,30 @@ private Inventory createRegearInventory(RegearInventoryHolder holder) {
248248
Inventory inventory = Bukkit.createInventory(holder, 27,
249249
StyleManager.get().getPrimaryColor() + Lang.get().legacy("gui.regear-shulker-title"));
250250
inventory.setItem(13, regearShellItem);
251+
holder.setInventory(inventory);
251252
return inventory;
252253
}
253254

254255

255-
public record RegearInventoryHolder(
256-
Player player) implements InventoryHolder {
256+
public static class RegearInventoryHolder implements InventoryHolder {
257+
private final Player player;
258+
private Inventory inventory;
259+
260+
public RegearInventoryHolder(Player player) {
261+
this.player = player;
262+
}
263+
264+
public Player player() {
265+
return player;
266+
}
267+
268+
private void setInventory(Inventory inventory) {
269+
this.inventory = inventory;
270+
}
257271

258272
@Override
259273
public @NotNull Inventory getInventory() {
260-
// Inventory is created externally via RegearCommand#createRegearInventory.
261-
// This method is required by InventoryHolder but not used at runtime — the
262-
// inventory is opened through createRegearInventory which assigns the holder.
263-
throw new UnsupportedOperationException("Use RegearCommand#createRegearInventory");
274+
return inventory;
264275
}
265276
}
266277
}

src/main/java/dev/noah/perplayerkit/gui/GUI.java

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,25 @@ public class GUI {
4949
private final Plugin plugin;
5050
private final boolean filterItemsOnImport;
5151
private static final Set<UUID> kitDeletionFlag = new HashSet<>();
52-
private static final Map<UUID, UUID> inspectTargets = new HashMap<>();
52+
private static final Map<UUID, EditorContext> editorContexts = new HashMap<>();
5353

54-
public static void setInspectTarget(UUID inspector, UUID target) {
55-
inspectTargets.put(inspector, target);
54+
public enum EditorType {
55+
KIT,
56+
PUBLIC_KIT,
57+
ENDERCHEST,
58+
INSPECT_KIT,
59+
INSPECT_ENDERCHEST
5660
}
5761

58-
public static UUID getAndRemoveInspectTarget(UUID inspector) {
59-
return inspectTargets.remove(inspector);
62+
public record EditorContext(EditorType type, int slot, String id, UUID target, String playerName) {
63+
}
64+
65+
public static EditorContext getAndRemoveEditorContext(UUID viewer) {
66+
return editorContexts.remove(viewer);
67+
}
68+
69+
private static void setEditorContext(Player viewer, EditorContext context) {
70+
editorContexts.put(viewer.getUniqueId(), context);
6071
}
6172

6273
public GUI(Plugin plugin) {
@@ -106,6 +117,7 @@ public void OpenKitMenu(Player p, int slot) {
106117
menu.setCursorDropHandler(Menu.ALLOW_CURSOR_DROPPING);
107118

108119
menu.open(p);
120+
setEditorContext(p, new EditorContext(EditorType.KIT, slot, null, null, null));
109121
}
110122

111123
public void OpenPublicKitEditor(Player p, String kitId) {
@@ -130,6 +142,7 @@ public void OpenPublicKitEditor(Player p, String kitId) {
130142
menu.setCursorDropHandler(Menu.ALLOW_CURSOR_DROPPING);
131143

132144
menu.open(p);
145+
setEditorContext(p, new EditorContext(EditorType.PUBLIC_KIT, 0, kitId, null, null));
133146
}
134147

135148
public void OpenECKitKenu(Player p, int slot) {
@@ -153,11 +166,14 @@ public void OpenECKitKenu(Player p, int slot) {
153166
addImportEC(menu.getSlot(IMPORT_SLOT));
154167
menu.setCursorDropHandler(Menu.ALLOW_CURSOR_DROPPING);
155168
menu.open(p);
169+
setEditorContext(p, new EditorContext(EditorType.ENDERCHEST, slot, null, null, null));
156170
}
157171

158172
public void InspectKit(Player p, UUID target, int slot) {
159-
setInspectTarget(p.getUniqueId(), target);
160173
String playerName = getPlayerName(target);
174+
if (playerName == null) {
175+
playerName = target.toString();
176+
}
161177
Menu menu = GuiMenuFactory.createInspectMenu(slot, playerName);
162178

163179
if (KitManager.get().hasKit(target, slot)) {
@@ -184,11 +200,11 @@ public void InspectKit(Player p, UUID target, int slot) {
184200

185201
menu.setCursorDropHandler(Menu.ALLOW_CURSOR_DROPPING);
186202
menu.open(p);
203+
setEditorContext(p, new EditorContext(EditorType.INSPECT_KIT, slot, null, target, playerName));
187204
SoundManager.playOpenGui(p);
188205
}
189206

190207
public void InspectEc(Player p, UUID target, int slot) {
191-
setInspectTarget(p.getUniqueId(), target);
192208
String playerName = getPlayerName(target);
193209
if (playerName == null) {
194210
playerName = target.toString();
@@ -220,6 +236,7 @@ public void InspectEc(Player p, UUID target, int slot) {
220236

221237
menu.setCursorDropHandler(Menu.ALLOW_CURSOR_DROPPING);
222238
menu.open(p);
239+
setEditorContext(p, new EditorContext(EditorType.INSPECT_ENDERCHEST, slot, null, target, playerName));
223240
SoundManager.playOpenGui(p);
224241
}
225242

0 commit comments

Comments
 (0)