Skip to content

Commit 937d11c

Browse files
committed
patch: replace direct config access with a type-safe method for detection items
this is probably extra asl but i hate the little yellow numbers
1 parent 408aca1 commit 937d11c

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

src/main/java/top/modpotato/commands/AntiNetheriteCommand.java

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,8 +250,7 @@ public boolean onCommand(CommandSender sender, Command command, String label, St
250250
String action = args[2].toLowerCase();
251251
String item = args[3].toUpperCase();
252252

253-
@SuppressWarnings("unchecked")
254-
List<String> items = (List<String>) plugin.getConfigValue("anti-netherite.detection.items");
253+
List<String> items = getDetectionItems();
255254

256255
if (action.equals("add")) {
257256
if (!items.contains(item)) {
@@ -485,7 +484,7 @@ private boolean handleGetCommand(CommandSender sender, String[] args) {
485484

486485
// Handle special case for detection.items
487486
if (setting.equals("detection.items")) {
488-
List<String> items = (List<String>) plugin.getConfigValue("anti-netherite.detection.items");
487+
List<String> items = getDetectionItems();
489488
sender.sendMessage(Component.text("Netherite items list:").color(NamedTextColor.GREEN));
490489
for (String item : items) {
491490
sender.sendMessage(Component.text("- " + item).color(NamedTextColor.YELLOW));
@@ -621,4 +620,26 @@ private List<String> filterCompletions(List<String> completions, String input) {
621620
}
622621
return filtered;
623622
}
623+
624+
/**
625+
* Safely retrieves the detection.items list from the config, ensuring type safety.
626+
* Filters out any non-string entries and logs warnings if the data type is unexpected.
627+
* @return a mutable List<String> of detection items (never null)
628+
*/
629+
private List<String> getDetectionItems() {
630+
Object value = plugin.getConfigValue("anti-netherite.detection.items");
631+
List<String> result = new ArrayList<>();
632+
if (value instanceof List<?>) {
633+
for (Object o : (List<?>) value) {
634+
if (o instanceof String s) {
635+
result.add(s);
636+
} else if (o != null) {
637+
plugin.getLogger().warning("Non-string entry in detection.items: " + o);
638+
}
639+
}
640+
} else if (value != null) {
641+
plugin.getLogger().warning("detection.items config value is not a list: " + value.getClass().getName());
642+
}
643+
return result;
644+
}
624645
}

src/main/java/top/modpotato/listeners/InventoryMoveListener.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public InventoryMoveListener(NetheriteDetector netheriteDetector, Config config)
3232
this.config = config;
3333
}
3434

35+
@SuppressWarnings("removal")
3536
@EventHandler
3637
public void onInventoryClick(InventoryClickEvent event) {
3738
if (!(event.getWhoClicked() instanceof Player)) {

0 commit comments

Comments
 (0)