Fixes some bugs
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	EpicKnarvik97/Blacksmith/pipeline/head This commit looks good
				
			Fixes some config commands not being registered Bumps KnarLib version to include bug-fix Fixes and improves tab-completion for enchantment block-list
This commit is contained in:
		
							
								
								
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								pom.xml
									
									
									
									
									
								
							| @@ -83,7 +83,7 @@ | |||||||
|         <dependency> |         <dependency> | ||||||
|             <groupId>net.knarcraft</groupId> |             <groupId>net.knarcraft</groupId> | ||||||
|             <artifactId>knarlib</artifactId> |             <artifactId>knarlib</artifactId> | ||||||
|             <version>1.2.6</version> |             <version>1.2.7</version> | ||||||
|             <scope>compile</scope> |             <scope>compile</scope> | ||||||
|         </dependency> |         </dependency> | ||||||
|         <dependency> |         <dependency> | ||||||
|   | |||||||
| @@ -3,6 +3,7 @@ package net.knarcraft.blacksmith.command.blacksmith; | |||||||
| import net.knarcraft.blacksmith.config.SettingValueType; | import net.knarcraft.blacksmith.config.SettingValueType; | ||||||
| import net.knarcraft.blacksmith.config.blacksmith.BlacksmithSetting; | import net.knarcraft.blacksmith.config.blacksmith.BlacksmithSetting; | ||||||
| import net.knarcraft.blacksmith.util.InputParsingHelper; | import net.knarcraft.blacksmith.util.InputParsingHelper; | ||||||
|  | import net.knarcraft.knarlib.util.TabCompletionHelper; | ||||||
| import org.bukkit.command.Command; | import org.bukkit.command.Command; | ||||||
| import org.bukkit.command.CommandSender; | import org.bukkit.command.CommandSender; | ||||||
| import org.bukkit.command.TabCompleter; | import org.bukkit.command.TabCompleter; | ||||||
| @@ -53,7 +54,7 @@ public class BlackSmithConfigTabCompleter implements TabCompleter { | |||||||
|                 return new ArrayList<>(); |                 return new ArrayList<>(); | ||||||
|             } |             } | ||||||
|         } |         } | ||||||
|         return null; |         return new ArrayList<>(); | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
| @@ -119,6 +120,11 @@ public class BlackSmithConfigTabCompleter implements TabCompleter { | |||||||
|      */ |      */ | ||||||
|     private List<String> getCompletions(@NotNull BlacksmithSetting blacksmithSetting, |     private List<String> getCompletions(@NotNull BlacksmithSetting blacksmithSetting, | ||||||
|                                         @NotNull String commandValue) { |                                         @NotNull String commandValue) { | ||||||
|  |         if (blacksmithSetting == BlacksmithSetting.ENCHANTMENT_BLOCK_LIST) { | ||||||
|  |             return TabCompletionHelper.getStringList(getTabCompletions(SettingValueType.ENCHANTMENT), | ||||||
|  |                     commandValue, TabCompletionHelper::filterMatchingContains); | ||||||
|  |         } | ||||||
|  |  | ||||||
|         List<String> returnValues = filterMatchingContains( |         List<String> returnValues = filterMatchingContains( | ||||||
|                 getTabCompletions(blacksmithSetting.getValueType()), commandValue); |                 getTabCompletions(blacksmithSetting.getValueType()), commandValue); | ||||||
|         if (blacksmithSetting == BlacksmithSetting.BASE_PRICE || |         if (blacksmithSetting == BlacksmithSetting.BASE_PRICE || | ||||||
|   | |||||||
| @@ -50,4 +50,9 @@ public enum SettingValueType { | |||||||
|      */ |      */ | ||||||
|     REFORGE_ABLE_ITEMS, |     REFORGE_ABLE_ITEMS, | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * A list of enchantments | ||||||
|  |      */ | ||||||
|  |     ENCHANTMENT_LIST, | ||||||
|  |  | ||||||
| } | } | ||||||
|   | |||||||
| @@ -64,7 +64,7 @@ public class BlacksmithNPCSettings implements TraitSettings<BlacksmithSetting> { | |||||||
|  |  | ||||||
|     @Override |     @Override | ||||||
|     public void changeValue(@NotNull BlacksmithSetting setting, @Nullable Object newValue) { |     public void changeValue(@NotNull BlacksmithSetting setting, @Nullable Object newValue) { | ||||||
|         if (setting.getValueType() == SettingValueType.STRING_LIST || |         if (setting.getValueType() == SettingValueType.ENCHANTMENT_LIST || | ||||||
|                 setting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) { |                 setting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) { | ||||||
|             //Workaround to make sure it's treated as the correct type |             //Workaround to make sure it's treated as the correct type | ||||||
|             currentValues.put(setting, newValue == null ? null : ConfigHelper.asStringList(newValue)); |             currentValues.put(setting, newValue == null ? null : ConfigHelper.asStringList(newValue)); | ||||||
|   | |||||||
| @@ -90,7 +90,7 @@ public enum BlacksmithSetting implements Setting { | |||||||
|     /** |     /** | ||||||
|      * The setting for the enchantments a blacksmith cannot apply to items |      * The setting for the enchantments a blacksmith cannot apply to items | ||||||
|      */ |      */ | ||||||
|     ENCHANTMENT_BLOCK_LIST("enchantmentBlockList", SettingValueType.STRING_LIST, List.of("binding_curse", |     ENCHANTMENT_BLOCK_LIST("enchantmentBlockList", SettingValueType.ENCHANTMENT_LIST, List.of("binding_curse", | ||||||
|             "mending", "vanishing_curse"), "The enchantments a " + |             "mending", "vanishing_curse"), "The enchantments a " + | ||||||
|             "blacksmith is denied from applying to an item. Disable anything you find too op or annoying.", |             "blacksmith is denied from applying to an item. Disable anything you find too op or annoying.", | ||||||
|             true, false), |             true, false), | ||||||
| @@ -277,7 +277,7 @@ public enum BlacksmithSetting implements Setting { | |||||||
|         this.valueType = valueType; |         this.valueType = valueType; | ||||||
|         this.childPath = key; |         this.childPath = key; | ||||||
|         if (key.contains(".")) { |         if (key.contains(".")) { | ||||||
|             String[] pathParts = path.split("\\."); |             String[] pathParts = key.split("\\."); | ||||||
|             this.commandName = pathParts[0]; |             this.commandName = pathParts[0]; | ||||||
|         } else { |         } else { | ||||||
|             this.commandName = key; |             this.commandName = key; | ||||||
|   | |||||||
| @@ -73,7 +73,7 @@ public class GlobalBlacksmithSettings implements Settings<BlacksmithSetting> { | |||||||
|      * @param newValue          <p>The new value for the setting</p> |      * @param newValue          <p>The new value for the setting</p> | ||||||
|      */ |      */ | ||||||
|     public void changeValue(@NotNull BlacksmithSetting blacksmithSetting, @Nullable Object newValue) { |     public void changeValue(@NotNull BlacksmithSetting blacksmithSetting, @Nullable Object newValue) { | ||||||
|         if (blacksmithSetting.getValueType() == SettingValueType.STRING_LIST || |         if (blacksmithSetting.getValueType() == SettingValueType.ENCHANTMENT_LIST || | ||||||
|                 blacksmithSetting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) { |                 blacksmithSetting.getValueType() == SettingValueType.REFORGE_ABLE_ITEMS) { | ||||||
|             //Workaround to make sure it's treated as the correct type |             //Workaround to make sure it's treated as the correct type | ||||||
|             this.settings.put(blacksmithSetting, newValue == null ? null : ConfigHelper.asStringList(newValue)); |             this.settings.put(blacksmithSetting, newValue == null ? null : ConfigHelper.asStringList(newValue)); | ||||||
|   | |||||||
| @@ -181,7 +181,7 @@ public enum ScrapperSetting implements Setting { | |||||||
|      * Which items are ignored when calculating salvage for a given material |      * Which items are ignored when calculating salvage for a given material | ||||||
|      */ |      */ | ||||||
|     IGNORED_SALVAGE("ignoredSalvage", SettingValueType.STRING_LIST, |     IGNORED_SALVAGE("ignoredSalvage", SettingValueType.STRING_LIST, | ||||||
|             new ArrayList<>(List.of("*_SHOVEL,*_PICKAXE,*_AXE,*_HOE,*_SWORD:STICK")), |             new ArrayList<>(List.of("*_SHOVEL;*_PICKAXE;*_AXE;*_HOE;*_SWORD:STICK")), | ||||||
|             "Items ignored during salvage calculation. This follows the format: " + |             "Items ignored during salvage calculation. This follows the format: " + | ||||||
|                     "\"MATERIAL[,MATERIAL2][,MATERIAL3]:IGNORED\", so the material or materials listed will ignore " + |                     "\"MATERIAL[,MATERIAL2][,MATERIAL3]:IGNORED\", so the material or materials listed will ignore " + | ||||||
|                     "the material specified after the \":\" when calculating salvage (* matches any character). This " + |                     "the material specified after the \":\" when calculating salvage (* matches any character). This " + | ||||||
| @@ -223,7 +223,7 @@ public enum ScrapperSetting implements Setting { | |||||||
|         this.valueType = valueType; |         this.valueType = valueType; | ||||||
|         this.childPath = key; |         this.childPath = key; | ||||||
|         if (key.contains(".")) { |         if (key.contains(".")) { | ||||||
|             String[] pathParts = path.split("\\."); |             String[] pathParts = key.split("\\."); | ||||||
|             this.commandName = pathParts[0]; |             this.commandName = pathParts[0]; | ||||||
|         } else { |         } else { | ||||||
|             this.commandName = key; |             this.commandName = key; | ||||||
|   | |||||||
| @@ -36,25 +36,11 @@ public final class TabCompleteValuesHelper { | |||||||
|             case PERCENTAGE -> getPercentages(); |             case PERCENTAGE -> getPercentages(); | ||||||
|             case REFORGE_ABLE_ITEMS -> getReforgeAbleMaterials(); |             case REFORGE_ABLE_ITEMS -> getReforgeAbleMaterials(); | ||||||
|             case MATERIAL -> getAllReforgeAbleMaterialNames(); |             case MATERIAL -> getAllReforgeAbleMaterialNames(); | ||||||
|             case ENCHANTMENT -> getAllEnchantments(); |             case ENCHANTMENT, ENCHANTMENT_LIST -> getAllEnchantments(); | ||||||
|             case STRING_LIST -> getExampleEnchantmentBlockLists(); |             case STRING_LIST -> List.of("*_SHOVEL,*_PICKAXE,*_AXE,*_HOE,*_SWORD:STICK,SMITHING_TABLE:*_PLANKS"); | ||||||
|         }; |         }; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /** |  | ||||||
|      * Gets example enchantment block lists |  | ||||||
|      * |  | ||||||
|      * @return <p>Some example enchantment block lists</p> |  | ||||||
|      */ |  | ||||||
|     private static @NotNull List<String> getExampleEnchantmentBlockLists() { |  | ||||||
|         List<String> exampleBlockLists = new ArrayList<>(); |  | ||||||
|         exampleBlockLists.add(Enchantment.VANISHING_CURSE.getKey().getKey() + "," + |  | ||||||
|                 Enchantment.BINDING_CURSE.getKey().getKey() + "," + Enchantment.MENDING.getKey().getKey()); |  | ||||||
|         exampleBlockLists.add(Enchantment.VANISHING_CURSE.getKey().getKey() + "," + |  | ||||||
|                 Enchantment.BINDING_CURSE.getKey().getKey()); |  | ||||||
|         return exampleBlockLists; |  | ||||||
|     } |  | ||||||
|  |  | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Gets a complete list of all reforge-able material names |      * Gets a complete list of all reforge-able material names | ||||||
|   | |||||||
| @@ -37,9 +37,10 @@ public final class TypeValidationHelper { | |||||||
|                 case POSITIVE_INTEGER -> isPositiveInteger(value, sender); |                 case POSITIVE_INTEGER -> isPositiveInteger(value, sender); | ||||||
|                 case PERCENTAGE -> isPercentage(value, sender); |                 case PERCENTAGE -> isPercentage(value, sender); | ||||||
|                 case BOOLEAN -> true; |                 case BOOLEAN -> true; | ||||||
|                 case STRING_LIST, REFORGE_ABLE_ITEMS -> isStringList(value, sender); |                 case REFORGE_ABLE_ITEMS, STRING_LIST -> isStringList(value, sender); | ||||||
|                 case MATERIAL -> isMaterial(value, sender); |                 case MATERIAL -> isMaterial(value, sender); | ||||||
|                 case ENCHANTMENT -> isEnchantment(value, sender); |                 case ENCHANTMENT -> isEnchantment(value, sender); | ||||||
|  |                 case ENCHANTMENT_LIST -> isEnchantmentList(value, sender); | ||||||
|             }; |             }; | ||||||
|         } catch (ClassCastException exception) { |         } catch (ClassCastException exception) { | ||||||
|             //This error signifies that an object is not a string, and of the wrong class |             //This error signifies that an object is not a string, and of the wrong class | ||||||
| @@ -64,6 +65,34 @@ public final class TypeValidationHelper { | |||||||
|         return isMaterial; |         return isMaterial; | ||||||
|     } |     } | ||||||
|  |  | ||||||
|  |     /** | ||||||
|  |      * Checks whether the given value is a list of enchantments | ||||||
|  |      * | ||||||
|  |      * @param value  <p>The value to check</p> | ||||||
|  |      * @param sender <p>The command sender to use for printing error messages</p> | ||||||
|  |      * @return <p>True if the value is an enchantment list</p> | ||||||
|  |      */ | ||||||
|  |     private static boolean isEnchantmentList(@Nullable Object value, @Nullable CommandSender sender) { | ||||||
|  |         // Check whether a string list is given | ||||||
|  |         if (!isStringList(value, sender)) { | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // Make sure the input can be converted to a string list | ||||||
|  |         List<String> strings = ConfigHelper.asStringList(value); | ||||||
|  |         if (strings == null) { | ||||||
|  |             return false; | ||||||
|  |         } | ||||||
|  |  | ||||||
|  |         // Make sure each value is an enchantment | ||||||
|  |         for (String string : strings) { | ||||||
|  |             if (!isEnchantment(string, sender)) { | ||||||
|  |                 return false; | ||||||
|  |             } | ||||||
|  |         } | ||||||
|  |         return true; | ||||||
|  |     } | ||||||
|  |  | ||||||
|     /** |     /** | ||||||
|      * Checks whether the given value is an enchantment |      * Checks whether the given value is an enchantment | ||||||
|      * |      * | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user