@@ -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}
0 commit comments