How to use parsePrimitiveValue method of be.seeseemelk.mockbukkit.tags.TagParser class

Best MockBukkit code snippet using be.seeseemelk.mockbukkit.tags.TagParser.parsePrimitiveValue

Source:TagParser.java Github

copy

Full Screen

...100 {101 if (element instanceof JsonPrimitive && ((JsonPrimitive) element).isString())102 {103 // Strings will be parsed directly104 parsePrimitiveValue(element.getAsString(), materials, tags);105 }106 else if (element instanceof JsonObject)107 {108 // JSONObjects can have a "required" property which can make109 // it optional to resolve the underlying value110 parseComplexValue(element.getAsJsonObject(), materials, tags);111 }112 else113 {114 throw new TagMisconfigurationException(key, "Unexpected value format: "115 + element.getClass().getSimpleName() + " - " + element.toString());116 }117 }118 // Run the callback with the filled-in materials and tags119 callback.accept(materials, tags);120 }121 else122 {123 // The JSON seems to be empty yet valid124 throw new TagMisconfigurationException(key, "No values array specified");125 }126 }127 catch (IllegalStateException | JsonParseException x)128 {129 throw new TagMisconfigurationException(key, x.getMessage());130 }131 }132 private void parsePrimitiveValue(@NotNull String value, @NotNull Set<Material> materials,133 @NotNull Set<TagWrapperMock> tags) throws TagMisconfigurationException134 {135 if (MINECRAFT_MATERIAL.matcher(value).matches())136 {137 // Match the NamespacedKey against Materials138 Material material = Material.matchMaterial(value);139 if (material != null)140 {141 // If the Material could be matched, simply add it to our Set142 materials.add(material);143 }144 else145 {146 throw new TagMisconfigurationException(key, "Minecraft Material '" + value + "' seems to not exist!");147 }148 }149 else if (MINECRAFT_TAG.matcher(value).matches())150 {151 NamespacedKey tagKey = NamespacedKey.minecraft(COLON.split(value)[1]);152 TagWrapperMock tag = registry.getTags().get(tagKey);153 if (tag != null)154 {155 tags.add(tag);156 }157 else158 {159 throw new TagMisconfigurationException(key,160 "There is no '" + value + "' tag in Minecraft:" + registry.getRegistry());161 }162 }163 else164 {165 // If no RegEx pattern matched, it's malformed.166 throw new TagMisconfigurationException(key, "Could not recognize value '" + value + "'");167 }168 }169 private void parseComplexValue(@NotNull JsonObject entry, @NotNull Set<Material> materials,170 @NotNull Set<TagWrapperMock> tags) throws TagMisconfigurationException171 {172 JsonElement id = entry.get("id");173 JsonElement required = entry.get("required");174 // Check if the entry contains elements of the correct type175 if (id instanceof JsonPrimitive && ((JsonPrimitive) id).isString() && required instanceof JsonPrimitive176 && ((JsonPrimitive) required).isBoolean())177 {178 if (required.getAsBoolean())179 {180 // If this entry is required, parse it like normal181 parsePrimitiveValue(id.getAsString(), materials, tags);182 }183 else184 {185 // If the entry is not required, validation will be optional186 try187 {188 parsePrimitiveValue(id.getAsString(), materials, tags);189 }190 catch (TagMisconfigurationException x)191 {192 // This is an optional entry, so we will ignore the validation here193 }194 }195 }196 else197 {198 throw new TagMisconfigurationException(key, "Found a JSON Object value without an id!");199 }200 }201 @NotNull202 @Override...

Full Screen

Full Screen

parsePrimitiveValue

Using AI Code Generation

copy

Full Screen

1public void parsePrimitiveValue ( String input ) throws Exception 2 { 3 TagParser parser = new TagParser ( "test" ); 4 Object actual = parser . parsePrimitiveValue ( input ); 5 assertEquals ( expected , actual ); 6 }7public void parsePrimitiveValue ( String input ) throws Exception 8 { 9 TagParser parser = new TagParser ( "test" ); 10 Object actual = parser . parsePrimitiveValue ( input ); 11 assertEquals ( expected , actual ); 12 }13public void parsePrimitiveValue ( String input ) throws Exception 14 { 15 TagParser parser = new TagParser ( "test" ); 16 Object actual = parser . parsePrimitiveValue ( input ); 17 assertEquals ( expected , actual ); 18 }19public void parsePrimitiveValue ( String input ) throws Exception 20 { 21 TagParser parser = new TagParser ( "test" ); 22 Object actual = parser . parsePrimitiveValue ( input ); 23 assertEquals ( expected , actual ); 24 }25public void parsePrimitiveValue ( String input ) throws Exception 26 { 27 TagParser parser = new TagParser ( "test" ); 28 Object actual = parser . parsePrimitiveValue ( input ); 29 assertEquals ( expected , actual ); 30 }31public void parsePrimitiveValue (

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run MockBukkit automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful