MCPcopy Create free account
hub / github.com/DGVPSH/SlackOpen / Primitive

Class Primitive

src/main/java/net/minecraft/nbt/JsonToNBT.java:437–552  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

435 }
436
437 static class Primitive extends JsonToNBT.Any
438 {
439 private static final Pattern DOUBLE = Pattern.compile("[-+]?[0-9]*\\.?[0-9]+[d|D]");
440 private static final Pattern FLOAT = Pattern.compile("[-+]?[0-9]*\\.?[0-9]+[f|F]");
441 private static final Pattern BYTE = Pattern.compile("[-+]?[0-9]+[b|B]");
442 private static final Pattern LONG = Pattern.compile("[-+]?[0-9]+[l|L]");
443 private static final Pattern SHORT = Pattern.compile("[-+]?[0-9]+[s|S]");
444 private static final Pattern INTEGER = Pattern.compile("[-+]?[0-9]+");
445 private static final Pattern DOUBLE_UNTYPED = Pattern.compile("[-+]?[0-9]*\\.?[0-9]+");
446 private static final Splitter SPLITTER = Splitter.on(',').omitEmptyStrings();
447 protected String jsonValue;
448
449 public Primitive(String p_i45139_1_, String p_i45139_2_)
450 {
451 this.json = p_i45139_1_;
452 this.jsonValue = p_i45139_2_;
453 }
454
455 public NBTBase parse() throws NBTException
456 {
457 try
458 {
459 if (DOUBLE.matcher(this.jsonValue).matches())
460 {
461 return new NBTTagDouble(Double.parseDouble(this.jsonValue.substring(0, this.jsonValue.length() - 1)));
462 }
463
464 if (FLOAT.matcher(this.jsonValue).matches())
465 {
466 return new NBTTagFloat(Float.parseFloat(this.jsonValue.substring(0, this.jsonValue.length() - 1)));
467 }
468
469 if (BYTE.matcher(this.jsonValue).matches())
470 {
471 return new NBTTagByte(Byte.parseByte(this.jsonValue.substring(0, this.jsonValue.length() - 1)));
472 }
473
474 if (LONG.matcher(this.jsonValue).matches())
475 {
476 return new NBTTagLong(Long.parseLong(this.jsonValue.substring(0, this.jsonValue.length() - 1)));
477 }
478
479 if (SHORT.matcher(this.jsonValue).matches())
480 {
481 return new NBTTagShort(Short.parseShort(this.jsonValue.substring(0, this.jsonValue.length() - 1)));
482 }
483
484 if (INTEGER.matcher(this.jsonValue).matches())
485 {
486 return new NBTTagInt(Integer.parseInt(this.jsonValue));
487 }
488
489 if (DOUBLE_UNTYPED.matcher(this.jsonValue).matches())
490 {
491 return new NBTTagDouble(Double.parseDouble(this.jsonValue));
492 }
493
494 if (this.jsonValue.equalsIgnoreCase("true") || this.jsonValue.equalsIgnoreCase("false"))

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected