further compressed data tree cleanup
This commit is contained in:
parent
b52053f5ea
commit
815c52e5d7
8 changed files with 240 additions and 265 deletions
|
@ -1086,6 +1086,10 @@ public abstract class Dimension extends Nameable implements Comparable<Dimension
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final TagObject dumpTags() {
|
||||||
|
return this.toTags(true, false, true);
|
||||||
|
}
|
||||||
|
|
||||||
public final TagObject toTags(boolean generator) {
|
public final TagObject toTags(boolean generator) {
|
||||||
return this.toTags(generator, !generator, false);
|
return this.toTags(generator, !generator, false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,7 +33,11 @@ class TagByteArray extends Tag {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "[" + this.data.length + " bytes]";
|
StringBuilder sb = new StringBuilder("[0x");
|
||||||
|
for(int z = 0; z < this.data.length; z++) {
|
||||||
|
sb.append(String.format("%02x", this.data[z]));
|
||||||
|
}
|
||||||
|
return sb.append("]").toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag copy() {
|
public Tag copy() {
|
||||||
|
|
|
@ -8,7 +8,8 @@ import common.collect.Lists;
|
||||||
|
|
||||||
class TagInterpreter
|
class TagInterpreter
|
||||||
{
|
{
|
||||||
private static final Pattern PATTERN = Pattern.compile("\\[[-+\\d|,\\s]+\\]");
|
private static final Pattern INT_BYTE_ARRAY = Pattern.compile("\\[[-+\\d|,\\s]+\\]");
|
||||||
|
private static final Pattern BYTE_ARRAY = Pattern.compile("\\[0x[a-fA-F\\d]*\\]");
|
||||||
|
|
||||||
static TagObject parseTag(String tag) throws TagException
|
static TagObject parseTag(String tag) throws TagException
|
||||||
{
|
{
|
||||||
|
@ -16,146 +17,144 @@ class TagInterpreter
|
||||||
{
|
{
|
||||||
throw new TagException("Invalid tag encountered, expected \'{\' as first char.");
|
throw new TagException("Invalid tag encountered, expected \'{\' as first char.");
|
||||||
}
|
}
|
||||||
else if (func_150310_b(tag) != 1)
|
else if (countTags(tag) != 1)
|
||||||
{
|
{
|
||||||
throw new TagException("Encountered multiple top tags, only one expected");
|
throw new TagException("Encountered multiple top tags, only one expected");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return (TagObject)func_150316_a("tag", tag).parse();
|
return (TagObject)parseSection("tag", tag).parse();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int func_150310_b(String p_150310_0_) throws TagException
|
static int countTags(String str) throws TagException
|
||||||
{
|
{
|
||||||
int i = 0;
|
int count = 0;
|
||||||
boolean flag = false;
|
boolean quote = false;
|
||||||
Stack<Character> stack = new Stack();
|
Stack<Character> stack = new Stack();
|
||||||
|
|
||||||
for (int j = 0; j < p_150310_0_.length(); ++j)
|
for (int z = 0; z < str.length(); z++)
|
||||||
{
|
{
|
||||||
char c0 = p_150310_0_.charAt(j);
|
char ch = str.charAt(z);
|
||||||
|
|
||||||
if (c0 == 34)
|
if (ch == '"')
|
||||||
{
|
{
|
||||||
if (func_179271_b(p_150310_0_, j))
|
if (isEscaped(str, z))
|
||||||
{
|
{
|
||||||
if (!flag)
|
if (!quote)
|
||||||
{
|
{
|
||||||
throw new TagException("Illegal use of \\\": " + p_150310_0_);
|
throw new TagException("Illegal use of \\\": " + str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
flag = !flag;
|
quote = !quote;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!flag)
|
else if (!quote)
|
||||||
{
|
{
|
||||||
if (c0 != 123 && c0 != 91)
|
if (ch != '{' && ch != '[')
|
||||||
{
|
{
|
||||||
if (c0 == 125 && (stack.isEmpty() || ((Character)stack.pop()).charValue() != 123))
|
if (ch == '}' && (stack.isEmpty() || ((Character)stack.pop()).charValue() != '{'))
|
||||||
{
|
{
|
||||||
throw new TagException("Unbalanced curly brackets {}: " + p_150310_0_);
|
throw new TagException("Unbalanced curly brackets {}: " + str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c0 == 93 && (stack.isEmpty() || ((Character)stack.pop()).charValue() != 91))
|
if (ch == ']' && (stack.isEmpty() || ((Character)stack.pop()).charValue() != '['))
|
||||||
{
|
{
|
||||||
throw new TagException("Unbalanced square brackets []: " + p_150310_0_);
|
throw new TagException("Unbalanced square brackets []: " + str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (stack.isEmpty())
|
if (stack.isEmpty())
|
||||||
{
|
{
|
||||||
++i;
|
++count;
|
||||||
}
|
}
|
||||||
|
|
||||||
stack.push(Character.valueOf(c0));
|
stack.push(Character.valueOf(ch));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flag)
|
if (quote)
|
||||||
{
|
{
|
||||||
throw new TagException("Unbalanced quotation: " + p_150310_0_);
|
throw new TagException("Unbalanced quotation: " + str);
|
||||||
}
|
}
|
||||||
else if (!stack.isEmpty())
|
else if (!stack.isEmpty())
|
||||||
{
|
{
|
||||||
throw new TagException("Unbalanced brackets: " + p_150310_0_);
|
throw new TagException("Unbalanced brackets: " + str);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (i == 0 && !p_150310_0_.isEmpty())
|
if (count == 0 && !str.isEmpty())
|
||||||
{
|
{
|
||||||
i = 1;
|
count = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return i;
|
return count;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static TagInterpreter.Any func_150316_a(String p_150316_0_, String p_150316_1_) throws TagException
|
static TagInterpreter.Parser parseSection(String id, String str) throws TagException
|
||||||
{
|
{
|
||||||
p_150316_1_ = p_150316_1_.trim();
|
str = str.trim();
|
||||||
|
|
||||||
if (p_150316_1_.startsWith("{"))
|
if (str.startsWith("{"))
|
||||||
{
|
{
|
||||||
p_150316_1_ = p_150316_1_.substring(1, p_150316_1_.length() - 1);
|
str = str.substring(1, str.length() - 1);
|
||||||
TagInterpreter.Compound tag;
|
TagInterpreter.Compound tag;
|
||||||
String s1;
|
String section;
|
||||||
|
|
||||||
for (tag = new TagInterpreter.Compound(p_150316_0_); p_150316_1_.length() > 0; p_150316_1_ = p_150316_1_.substring(s1.length() + 1))
|
for (tag = new TagInterpreter.Compound(id); str.length() > 0; str = str.substring(section.length() + 1))
|
||||||
{
|
{
|
||||||
s1 = func_150314_a(p_150316_1_, true);
|
section = splitSection(str, true);
|
||||||
|
|
||||||
if (s1.length() > 0)
|
if (section.length() > 0)
|
||||||
{
|
{
|
||||||
boolean flag1 = false;
|
tag.parsers.add(parseSubsection(section, false));
|
||||||
tag.field_150491_b.add(func_179270_a(s1, flag1));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_150316_1_.length() < s1.length() + 1)
|
if (str.length() < section.length() + 1)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
char c1 = p_150316_1_.charAt(s1.length());
|
char ch = str.charAt(section.length());
|
||||||
|
|
||||||
if (c1 != 44 && c1 != 123 && c1 != 125 && c1 != 91 && c1 != 93)
|
if (ch != ',' && ch != '{' && ch != '}' && ch != '[' && ch != ']')
|
||||||
{
|
{
|
||||||
throw new TagException("Unexpected token \'" + c1 + "\' at: " + p_150316_1_.substring(s1.length()));
|
throw new TagException("Unexpected token \'" + ch + "\' at: " + str.substring(section.length()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
else if (p_150316_1_.startsWith("[") && !PATTERN.matcher(p_150316_1_).matches())
|
else if (str.startsWith("[") && !INT_BYTE_ARRAY.matcher(str).matches() && !BYTE_ARRAY.matcher(str).matches())
|
||||||
{
|
{
|
||||||
p_150316_1_ = p_150316_1_.substring(1, p_150316_1_.length() - 1);
|
str = str.substring(1, str.length() - 1);
|
||||||
TagInterpreter.List list;
|
TagInterpreter.List list;
|
||||||
String s;
|
String section;
|
||||||
|
|
||||||
for (list = new TagInterpreter.List(p_150316_0_); p_150316_1_.length() > 0; p_150316_1_ = p_150316_1_.substring(s.length() + 1))
|
for (list = new TagInterpreter.List(id); str.length() > 0; str = str.substring(section.length() + 1))
|
||||||
{
|
{
|
||||||
s = func_150314_a(p_150316_1_, false);
|
section = splitSection(str, false);
|
||||||
|
|
||||||
if (s.length() > 0)
|
if (section.length() > 0)
|
||||||
{
|
{
|
||||||
boolean flag = true;
|
list.parsers.add(parseSubsection(section, true));
|
||||||
list.data.add(func_179270_a(s, flag));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (p_150316_1_.length() < s.length() + 1)
|
if (str.length() < section.length() + 1)
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
char c0 = p_150316_1_.charAt(s.length());
|
char ch = str.charAt(section.length());
|
||||||
|
|
||||||
if (c0 != 44 && c0 != 123 && c0 != 125 && c0 != 91 && c0 != 93)
|
if (ch != ',' && ch != '{' && ch != '}' && ch != '[' && ch != ']')
|
||||||
{
|
{
|
||||||
throw new TagException("Unexpected token \'" + c0 + "\' at: " + p_150316_1_.substring(s.length()));
|
throw new TagException("Unexpected token \'" + ch + "\' at: " + str.substring(section.length()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -163,202 +162,202 @@ class TagInterpreter
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new TagInterpreter.Primitive(p_150316_0_, p_150316_1_);
|
return new TagInterpreter.Primitive(id, str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static TagInterpreter.Any func_179270_a(String p_179270_0_, boolean p_179270_1_) throws TagException
|
private static TagInterpreter.Parser parseSubsection(String str, boolean list) throws TagException
|
||||||
{
|
{
|
||||||
String s = func_150313_b(p_179270_0_, p_179270_1_);
|
String key = getKey(str, list);
|
||||||
String s1 = func_150311_c(p_179270_0_, p_179270_1_);
|
String value = getValue(str, list);
|
||||||
return func_150316_a(s, s1);
|
return parseSection(key, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String func_150314_a(String p_150314_0_, boolean p_150314_1_) throws TagException
|
private static String splitSection(String str, boolean noList) throws TagException
|
||||||
{
|
{
|
||||||
int i = func_150312_a(p_150314_0_, ':');
|
int colon = findSeparator(str, ':');
|
||||||
int j = func_150312_a(p_150314_0_, ',');
|
int comma = findSeparator(str, ',');
|
||||||
|
|
||||||
if (p_150314_1_)
|
if (noList)
|
||||||
{
|
{
|
||||||
if (i == -1)
|
if (colon == -1)
|
||||||
{
|
{
|
||||||
throw new TagException("Unable to locate name/value separator for string: " + p_150314_0_);
|
throw new TagException("Unable to locate name/value separator for string: " + str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (j != -1 && j < i)
|
if (comma != -1 && comma < colon)
|
||||||
{
|
{
|
||||||
throw new TagException("Name error at: " + p_150314_0_);
|
throw new TagException("Name error at: " + str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (i == -1 || i > j)
|
else if (colon == -1 || colon > comma)
|
||||||
{
|
{
|
||||||
i = -1;
|
colon = -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return func_179269_a(p_150314_0_, i);
|
return split(str, colon);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String func_179269_a(String p_179269_0_, int p_179269_1_) throws TagException
|
private static String split(String str, int index) throws TagException
|
||||||
{
|
{
|
||||||
Stack<Character> stack = new Stack();
|
Stack<Character> stack = new Stack();
|
||||||
int i = p_179269_1_ + 1;
|
int idx = index + 1;
|
||||||
boolean flag = false;
|
boolean quote = false;
|
||||||
boolean flag1 = false;
|
boolean quoteFirst = false;
|
||||||
boolean flag2 = false;
|
boolean printable = false;
|
||||||
|
|
||||||
for (int j = 0; i < p_179269_0_.length(); ++i)
|
for (int quoteEnd = 0; idx < str.length(); ++idx)
|
||||||
{
|
{
|
||||||
char c0 = p_179269_0_.charAt(i);
|
char ch = str.charAt(idx);
|
||||||
|
|
||||||
if (c0 == 34)
|
if (ch == '"')
|
||||||
{
|
{
|
||||||
if (func_179271_b(p_179269_0_, i))
|
if (isEscaped(str, idx))
|
||||||
{
|
{
|
||||||
if (!flag)
|
if (!quote)
|
||||||
{
|
{
|
||||||
throw new TagException("Illegal use of \\\": " + p_179269_0_);
|
throw new TagException("Illegal use of \\\": " + str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
flag = !flag;
|
quote = !quote;
|
||||||
|
|
||||||
if (flag && !flag2)
|
if (quote && !printable)
|
||||||
{
|
{
|
||||||
flag1 = true;
|
quoteFirst = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!flag)
|
if (!quote)
|
||||||
{
|
{
|
||||||
j = i;
|
quoteEnd = idx;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!flag)
|
else if (!quote)
|
||||||
{
|
{
|
||||||
if (c0 != 123 && c0 != 91)
|
if (ch != '{' && ch != '[')
|
||||||
{
|
{
|
||||||
if (c0 == 125 && (stack.isEmpty() || ((Character)stack.pop()).charValue() != 123))
|
if (ch == '}' && (stack.isEmpty() || ((Character)stack.pop()).charValue() != '{'))
|
||||||
{
|
{
|
||||||
throw new TagException("Unbalanced curly brackets {}: " + p_179269_0_);
|
throw new TagException("Unbalanced curly brackets {}: " + str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c0 == 93 && (stack.isEmpty() || ((Character)stack.pop()).charValue() != 91))
|
if (ch == ']' && (stack.isEmpty() || ((Character)stack.pop()).charValue() != '['))
|
||||||
{
|
{
|
||||||
throw new TagException("Unbalanced square brackets []: " + p_179269_0_);
|
throw new TagException("Unbalanced square brackets []: " + str);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c0 == 44 && stack.isEmpty())
|
if (ch == ',' && stack.isEmpty())
|
||||||
{
|
{
|
||||||
return p_179269_0_.substring(0, i);
|
return str.substring(0, idx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stack.push(Character.valueOf(c0));
|
stack.push(Character.valueOf(ch));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Character.isWhitespace(c0))
|
if (!Character.isWhitespace(ch))
|
||||||
{
|
{
|
||||||
if (!flag && flag1 && j != i)
|
if (!quote && quoteFirst && quoteEnd != idx)
|
||||||
{
|
{
|
||||||
return p_179269_0_.substring(0, j + 1);
|
return str.substring(0, quoteEnd + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
flag2 = true;
|
printable = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return p_179269_0_.substring(0, i);
|
return str.substring(0, idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String func_150313_b(String p_150313_0_, boolean p_150313_1_) throws TagException
|
private static String getKey(String str, boolean list) throws TagException
|
||||||
{
|
{
|
||||||
if (p_150313_1_)
|
if (list)
|
||||||
{
|
{
|
||||||
p_150313_0_ = p_150313_0_.trim();
|
str = str.trim();
|
||||||
|
|
||||||
if (p_150313_0_.startsWith("{") || p_150313_0_.startsWith("["))
|
if (str.startsWith("{") || str.startsWith("["))
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = func_150312_a(p_150313_0_, ':');
|
int colon = findSeparator(str, ':');
|
||||||
|
|
||||||
if (i == -1)
|
if (colon == -1)
|
||||||
{
|
{
|
||||||
if (p_150313_1_)
|
if (list)
|
||||||
{
|
{
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new TagException("Unable to locate name/value separator for string: " + p_150313_0_);
|
throw new TagException("Unable to locate name/value separator for string: " + str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return p_150313_0_.substring(0, i).trim();
|
return str.substring(0, colon).trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String func_150311_c(String p_150311_0_, boolean p_150311_1_) throws TagException
|
private static String getValue(String str, boolean list) throws TagException
|
||||||
{
|
{
|
||||||
if (p_150311_1_)
|
if (list)
|
||||||
{
|
{
|
||||||
p_150311_0_ = p_150311_0_.trim();
|
str = str.trim();
|
||||||
|
|
||||||
if (p_150311_0_.startsWith("{") || p_150311_0_.startsWith("["))
|
if (str.startsWith("{") || str.startsWith("["))
|
||||||
{
|
{
|
||||||
return p_150311_0_;
|
return str;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int i = func_150312_a(p_150311_0_, ':');
|
int colon = findSeparator(str, ':');
|
||||||
|
|
||||||
if (i == -1)
|
if (colon == -1)
|
||||||
{
|
{
|
||||||
if (p_150311_1_)
|
if (list)
|
||||||
{
|
{
|
||||||
return p_150311_0_;
|
return str;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
throw new TagException("Unable to locate name/value separator for string: " + p_150311_0_);
|
throw new TagException("Unable to locate name/value separator for string: " + str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return p_150311_0_.substring(i + 1).trim();
|
return str.substring(colon + 1).trim();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int func_150312_a(String p_150312_0_, char p_150312_1_)
|
private static int findSeparator(String str, char separator)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int idx = 0;
|
||||||
|
|
||||||
for (boolean flag = true; i < p_150312_0_.length(); ++i)
|
for (boolean noQuote = true; idx < str.length(); idx++)
|
||||||
{
|
{
|
||||||
char c0 = p_150312_0_.charAt(i);
|
char ch = str.charAt(idx);
|
||||||
|
|
||||||
if (c0 == 34)
|
if (ch == '"')
|
||||||
{
|
{
|
||||||
if (!func_179271_b(p_150312_0_, i))
|
if (!isEscaped(str, idx))
|
||||||
{
|
{
|
||||||
flag = !flag;
|
noQuote = !noQuote;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (flag)
|
else if (noQuote)
|
||||||
{
|
{
|
||||||
if (c0 == p_150312_1_)
|
if (ch == separator)
|
||||||
{
|
{
|
||||||
return i;
|
return idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (c0 == 123 || c0 == 91)
|
if (ch == '{' || ch == '[')
|
||||||
{
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -368,47 +367,47 @@ class TagInterpreter
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean func_179271_b(String p_179271_0_, int p_179271_1_)
|
private static boolean isEscaped(String str, int index)
|
||||||
{
|
{
|
||||||
return p_179271_1_ > 0 && p_179271_0_.charAt(p_179271_1_ - 1) == 92 && !func_179271_b(p_179271_0_, p_179271_1_ - 1);
|
return index > 0 && str.charAt(index - 1) == '\\' && !isEscaped(str, index - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract static class Any
|
abstract static class Parser
|
||||||
{
|
{
|
||||||
protected String json;
|
protected String section;
|
||||||
|
|
||||||
public abstract Tag parse() throws TagException;
|
public abstract Tag parse() throws TagException;
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Compound extends TagInterpreter.Any
|
static class Compound extends TagInterpreter.Parser
|
||||||
{
|
{
|
||||||
protected java.util.List<TagInterpreter.Any> field_150491_b = Lists.<TagInterpreter.Any>newArrayList();
|
protected java.util.List<TagInterpreter.Parser> parsers = Lists.<TagInterpreter.Parser>newArrayList();
|
||||||
|
|
||||||
public Compound(String p_i45137_1_)
|
public Compound(String section)
|
||||||
{
|
{
|
||||||
this.json = p_i45137_1_;
|
this.section = section;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag parse() throws TagException
|
public Tag parse() throws TagException
|
||||||
{
|
{
|
||||||
TagObject tag = new TagObject();
|
TagObject tag = new TagObject();
|
||||||
|
|
||||||
for (TagInterpreter.Any any : this.field_150491_b)
|
for (TagInterpreter.Parser any : this.parsers)
|
||||||
{
|
{
|
||||||
tag.set(any.json, any.parse());
|
tag.set(any.section, any.parse());
|
||||||
}
|
}
|
||||||
|
|
||||||
return tag;
|
return tag;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class List extends TagInterpreter.Any
|
static class List extends TagInterpreter.Parser
|
||||||
{
|
{
|
||||||
protected java.util.List<TagInterpreter.Any> data = Lists.<TagInterpreter.Any>newArrayList();
|
protected java.util.List<TagInterpreter.Parser> parsers = Lists.<TagInterpreter.Parser>newArrayList();
|
||||||
|
|
||||||
public List(String json)
|
public List(String section)
|
||||||
{
|
{
|
||||||
this.json = json;
|
this.section = section;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag parse() throws TagException
|
public Tag parse() throws TagException
|
||||||
|
@ -416,25 +415,25 @@ class TagInterpreter
|
||||||
TagList list = null;
|
TagList list = null;
|
||||||
java.util.List<String> strs = null;
|
java.util.List<String> strs = null;
|
||||||
|
|
||||||
for (TagInterpreter.Any any : this.data)
|
for (TagInterpreter.Parser any : this.parsers)
|
||||||
{
|
{
|
||||||
Tag tag = any.parse();
|
Tag tag = any.parse();
|
||||||
if(tag.getType() == TagType.STRING) {
|
if(tag.getType() == TagType.STRING) {
|
||||||
if(list != null)
|
if(list != null)
|
||||||
throw new TagException("Cannot use mixed types for list: " + any.json);
|
throw new TagException("Cannot use mixed types for list: " + any.section);
|
||||||
if(strs == null)
|
if(strs == null)
|
||||||
strs = new ArrayList<String>(this.data.size());
|
strs = new ArrayList<String>(this.parsers.size());
|
||||||
strs.add(((TagString)tag).getString());
|
strs.add(((TagString)tag).getString());
|
||||||
}
|
}
|
||||||
else if(tag.getType() == TagType.OBJECT) {
|
else if(tag.getType() == TagType.OBJECT) {
|
||||||
if(strs != null)
|
if(strs != null)
|
||||||
throw new TagException("Cannot use mixed types for list: " + any.json);
|
throw new TagException("Cannot use mixed types for list: " + any.section);
|
||||||
if(list == null)
|
if(list == null)
|
||||||
list = new TagList(new ArrayList<TagObject>(this.data.size()));
|
list = new TagList(new ArrayList<TagObject>(this.parsers.size()));
|
||||||
list.getList().add(((TagObject)tag));
|
list.getList().add(((TagObject)tag));
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw new TagException("Type cannot be put in a list: " + any.json);
|
throw new TagException("Type cannot be put in a list: " + any.section);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -442,7 +441,7 @@ class TagInterpreter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class Primitive extends TagInterpreter.Any
|
static class Primitive extends TagInterpreter.Parser
|
||||||
{
|
{
|
||||||
private static final Pattern DOUBLE = Pattern.compile("[-+]?[0-9]*\\.?[0-9]+[d|D]");
|
private static final Pattern DOUBLE = Pattern.compile("[-+]?[0-9]*\\.?[0-9]+[d|D]");
|
||||||
private static final Pattern FLOAT = Pattern.compile("[-+]?[0-9]*\\.?[0-9]+[f|F]");
|
private static final Pattern FLOAT = Pattern.compile("[-+]?[0-9]*\\.?[0-9]+[f|F]");
|
||||||
|
@ -451,133 +450,143 @@ class TagInterpreter
|
||||||
private static final Pattern SHORT = Pattern.compile("[-+]?[0-9]+[s|S]");
|
private static final Pattern SHORT = Pattern.compile("[-+]?[0-9]+[s|S]");
|
||||||
private static final Pattern INTEGER = Pattern.compile("[-+]?[0-9]+");
|
private static final Pattern INTEGER = Pattern.compile("[-+]?[0-9]+");
|
||||||
private static final Pattern DOUBLE_UNTYPED = Pattern.compile("[-+]?[0-9]*\\.?[0-9]+");
|
private static final Pattern DOUBLE_UNTYPED = Pattern.compile("[-+]?[0-9]*\\.?[0-9]+");
|
||||||
// private static final Splitter SPLITTER = Splitter.on(',').omitEmptyStrings();
|
|
||||||
protected String jsonValue;
|
|
||||||
|
|
||||||
public Primitive(String p_i45139_1_, String p_i45139_2_)
|
protected String value;
|
||||||
|
|
||||||
|
public Primitive(String section, String value)
|
||||||
{
|
{
|
||||||
this.json = p_i45139_1_;
|
this.section = section;
|
||||||
this.jsonValue = p_i45139_2_;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Tag parse() throws TagException
|
public Tag parse() throws TagException
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (DOUBLE.matcher(this.jsonValue).matches())
|
if (DOUBLE.matcher(this.value).matches())
|
||||||
{
|
{
|
||||||
return new TagDouble(Double.parseDouble(this.jsonValue.substring(0, this.jsonValue.length() - 1)));
|
return new TagDouble(Double.parseDouble(this.value.substring(0, this.value.length() - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (FLOAT.matcher(this.jsonValue).matches())
|
if (FLOAT.matcher(this.value).matches())
|
||||||
{
|
{
|
||||||
return new TagFloat(Float.parseFloat(this.jsonValue.substring(0, this.jsonValue.length() - 1)));
|
return new TagFloat(Float.parseFloat(this.value.substring(0, this.value.length() - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (BYTE.matcher(this.jsonValue).matches())
|
if (BYTE.matcher(this.value).matches())
|
||||||
{
|
{
|
||||||
return new TagByte(Byte.parseByte(this.jsonValue.substring(0, this.jsonValue.length() - 1)));
|
return new TagByte(Byte.parseByte(this.value.substring(0, this.value.length() - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (LONG.matcher(this.jsonValue).matches())
|
if (LONG.matcher(this.value).matches())
|
||||||
{
|
{
|
||||||
return new TagLong(Long.parseLong(this.jsonValue.substring(0, this.jsonValue.length() - 1)));
|
return new TagLong(Long.parseLong(this.value.substring(0, this.value.length() - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (SHORT.matcher(this.jsonValue).matches())
|
if (SHORT.matcher(this.value).matches())
|
||||||
{
|
{
|
||||||
return new TagShort(Short.parseShort(this.jsonValue.substring(0, this.jsonValue.length() - 1)));
|
return new TagShort(Short.parseShort(this.value.substring(0, this.value.length() - 1)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (INTEGER.matcher(this.jsonValue).matches())
|
if (INTEGER.matcher(this.value).matches())
|
||||||
{
|
{
|
||||||
return new TagInt(Integer.parseInt(this.jsonValue));
|
return new TagInt(Integer.parseInt(this.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (DOUBLE_UNTYPED.matcher(this.jsonValue).matches())
|
if (DOUBLE_UNTYPED.matcher(this.value).matches())
|
||||||
{
|
{
|
||||||
return new TagDouble(Double.parseDouble(this.jsonValue));
|
return new TagDouble(Double.parseDouble(this.value));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.jsonValue.equalsIgnoreCase("true") || this.jsonValue.equalsIgnoreCase("false"))
|
if (this.value.equalsIgnoreCase("true") || this.value.equalsIgnoreCase("false"))
|
||||||
{
|
{
|
||||||
return new TagBool(Boolean.parseBoolean(this.jsonValue));
|
return new TagBool(Boolean.parseBoolean(this.value));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (NumberFormatException var6)
|
catch (NumberFormatException e)
|
||||||
{
|
{
|
||||||
this.jsonValue = this.jsonValue.replaceAll("\\\\\"", "\"");
|
this.value = this.value.replaceAll("\\\\\"", "\"");
|
||||||
return new TagString(this.jsonValue);
|
return new TagString(this.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.jsonValue.startsWith("[") && this.jsonValue.endsWith("]"))
|
if (this.value.startsWith("[") && this.value.endsWith("]"))
|
||||||
{
|
{
|
||||||
String s = this.jsonValue.substring(1, this.jsonValue.length() - 1);
|
String str = this.value.substring(1, this.value.length() - 1);
|
||||||
String[] astring = s.split(",");
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
int[] aint = new int[astring.length];
|
if(str.startsWith("0x")) {
|
||||||
|
str = str.substring(2);
|
||||||
for (int j = 0; j < astring.length; ++j)
|
if((str.length() & 1) == 1)
|
||||||
{
|
str = "0" + str;
|
||||||
aint[j] = Integer.parseInt(astring[j].trim());
|
byte[] bytes = new byte[str.length() / 2];
|
||||||
}
|
for (int z = 0; z < bytes.length; z++)
|
||||||
|
{
|
||||||
return new TagIntArray(aint);
|
bytes[z] = (byte)Integer.parseUnsignedInt(str.substring(z * 2, (z + 1) * 2), 16);
|
||||||
|
}
|
||||||
|
return new TagByteArray(bytes);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
String[] elems = str.split(",");
|
||||||
|
int[] ints = new int[elems.length];
|
||||||
|
for (int z = 0; z < elems.length; z++)
|
||||||
|
{
|
||||||
|
ints[z] = Integer.parseInt(elems[z].trim());
|
||||||
|
}
|
||||||
|
return new TagIntArray(ints);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (NumberFormatException var5)
|
catch (NumberFormatException e)
|
||||||
{
|
{
|
||||||
return new TagString(this.jsonValue);
|
return new TagString(this.value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (this.jsonValue.startsWith("'") && this.jsonValue.endsWith("'"))
|
if (this.value.startsWith("'") && this.value.endsWith("'"))
|
||||||
{
|
{
|
||||||
String s = this.jsonValue.substring(1, this.jsonValue.length() - 1);
|
String str = this.value.substring(1, this.value.length() - 1);
|
||||||
if(s.length() == 1 && s.charAt(0) != '\\') {
|
if(str.length() == 1 && str.charAt(0) != '\\') {
|
||||||
return new TagChar(s.charAt(0));
|
return new TagChar(str.charAt(0));
|
||||||
}
|
}
|
||||||
else if(s.length() == 2 && s.charAt(0) == '\\') {
|
else if(str.length() == 2 && str.charAt(0) == '\\') {
|
||||||
switch(s.charAt(1)) {
|
switch(str.charAt(1)) {
|
||||||
case '\\':
|
case '\\':
|
||||||
return new TagChar('\\');
|
return new TagChar('\\');
|
||||||
case 'n':
|
case 'n':
|
||||||
return new TagChar('\n');
|
return new TagChar('\n');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if((s.length() == 4 && s.startsWith("\\x")) || (s.length() == 6 && s.startsWith("\\u"))) {
|
else if((str.length() == 4 && str.startsWith("\\x")) || (str.length() == 6 && str.startsWith("\\u"))) {
|
||||||
try {
|
try {
|
||||||
return new TagChar((char)Integer.parseUnsignedInt(s.substring(2), 16));
|
return new TagChar((char)Integer.parseUnsignedInt(str.substring(2), 16));
|
||||||
}
|
}
|
||||||
catch(NumberFormatException e) {
|
catch(NumberFormatException e) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.jsonValue.startsWith("\"") && this.jsonValue.endsWith("\""))
|
if (this.value.startsWith("\"") && this.value.endsWith("\""))
|
||||||
{
|
{
|
||||||
this.jsonValue = this.jsonValue.substring(1, this.jsonValue.length() - 1);
|
this.value = this.value.substring(1, this.value.length() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.jsonValue = this.jsonValue.replaceAll("\\\\\"", "\"");
|
this.value = this.value.replaceAll("\\\\\"", "\"");
|
||||||
StringBuilder stringbuilder = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
|
|
||||||
for (int i = 0; i < this.jsonValue.length(); ++i)
|
for (int z = 0; z < this.value.length(); z++)
|
||||||
{
|
{
|
||||||
if (i < this.jsonValue.length() - 1 && this.jsonValue.charAt(i) == 92 && this.jsonValue.charAt(i + 1) == 92)
|
if (z < this.value.length() - 1 && this.value.charAt(z) == '\\' && this.value.charAt(z + 1) == '\\')
|
||||||
{
|
{
|
||||||
stringbuilder.append('\\');
|
sb.append('\\');
|
||||||
++i;
|
++z;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
stringbuilder.append(this.jsonValue.charAt(i));
|
sb.append(this.value.charAt(z));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new TagString(stringbuilder.toString());
|
return new TagString(sb.toString());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,8 +25,8 @@ class TagList extends Tag {
|
||||||
|
|
||||||
void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
|
void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
|
||||||
tracker.read(36);
|
tracker.read(36);
|
||||||
if(depth > 512)
|
if(depth > 256)
|
||||||
throw new RuntimeException("Objekt ist zu komplex, die Tiefe ist größer als 512");
|
throw new IOException("Objekt ist zu komplex, die Tiefe ist größer als 256");
|
||||||
int len = input.readInt();
|
int len = input.readInt();
|
||||||
tracker.read(4 * len);
|
tracker.read(4 * len);
|
||||||
this.list = new ArrayList<TagObject>(len);
|
this.list = new ArrayList<TagObject>(len);
|
||||||
|
|
|
@ -1,26 +0,0 @@
|
||||||
package common.tags;
|
|
||||||
|
|
||||||
import java.io.DataInput;
|
|
||||||
import java.io.DataOutput;
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
class TagNull extends Tag {
|
|
||||||
void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
|
|
||||||
tracker.read(8);
|
|
||||||
}
|
|
||||||
|
|
||||||
void write(DataOutput output) throws IOException {
|
|
||||||
}
|
|
||||||
|
|
||||||
protected TagType getType() {
|
|
||||||
return TagType.NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "END";
|
|
||||||
}
|
|
||||||
|
|
||||||
public Tag copy() {
|
|
||||||
return new TagNull();
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -42,8 +42,8 @@ public class TagObject extends Tag {
|
||||||
|
|
||||||
void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
|
void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
|
||||||
tracker.read(48);
|
tracker.read(48);
|
||||||
if(depth > 512)
|
if(depth > 256)
|
||||||
throw new RuntimeException("Objekt ist zu komplex, die Tiefe ist größer als 512");
|
throw new IOException("Objekt ist zu komplex, die Tiefe ist größer als 256");
|
||||||
this.tags.clear();
|
this.tags.clear();
|
||||||
byte id;
|
byte id;
|
||||||
while((id = input.readByte()) != 0) {
|
while((id = input.readByte()) != 0) {
|
||||||
|
@ -52,7 +52,7 @@ public class TagObject extends Tag {
|
||||||
Tag tag = TagType.create(id);
|
Tag tag = TagType.create(id);
|
||||||
tag.read(input, depth + 1, tracker);
|
tag.read(input, depth + 1, tracker);
|
||||||
if(this.tags.put(key, tag) != null)
|
if(this.tags.put(key, tag) != null)
|
||||||
tracker.read(36);
|
throw new IOException("Objekt ist ungültig, Tag '" + key + "' ist mehrfach vorhanden");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,13 +1,11 @@
|
||||||
package common.tags;
|
package common.tags;
|
||||||
|
|
||||||
import java.io.DataInput;
|
|
||||||
import java.io.DataOutput;
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
enum TagType {
|
enum TagType {
|
||||||
NULL { // 0
|
NULL { // 0
|
||||||
protected Tag createTag() {
|
protected Tag createTag() {
|
||||||
return new TagNull();
|
return null;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
OBJECT { // 1
|
OBJECT { // 1
|
||||||
|
@ -89,28 +87,10 @@ enum TagType {
|
||||||
TYPES = values();
|
TYPES = values();
|
||||||
}
|
}
|
||||||
|
|
||||||
static Tag create(byte id) {
|
static Tag create(byte id) throws IOException {
|
||||||
return id >= 0 && id < TYPES.length ? TYPES[id].createTag() : new Tag() {
|
if(id <= 0 || id >= TYPES.length)
|
||||||
void write(DataOutput output) throws IOException {
|
throw new IOException("Kann keinen gültigen Tag mit ID #" + id + " lesen");
|
||||||
throw new IOException("Kann keinen ungültigen Tag mit ID #" + id + " schreiben");
|
return TYPES[id].createTag();
|
||||||
}
|
|
||||||
|
|
||||||
void read(DataInput input, int depth, SizeTracker tracker) throws IOException {
|
|
||||||
throw new IOException("Kann keinen ungültigen Tag mit ID #" + id + " lesen");
|
|
||||||
}
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return "<invalid>";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected TagType getType() {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Tag copy() {
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private TagType() {
|
private TagType() {
|
||||||
|
|
|
@ -10,9 +10,13 @@ public class CommandSeed extends Command {
|
||||||
super("seed");
|
super("seed");
|
||||||
|
|
||||||
this.addWorld("dim", true);
|
this.addWorld("dim", true);
|
||||||
|
|
||||||
|
this.addFlag("dump", 'd');
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object exec(CommandEnvironment env, Executor exec, WorldServer world) {
|
public Object exec(CommandEnvironment env, Executor exec, WorldServer world, boolean dump) {
|
||||||
|
if(dump)
|
||||||
|
exec.logConsole("Daten: %s", world.dimension.dumpTags().toString());
|
||||||
exec.logConsole("Startwert von %s: %d", world.dimension.getFormattedName(false), world.dimension.getSeed());
|
exec.logConsole("Startwert von %s: %d", world.dimension.getFormattedName(false), world.dimension.getSeed());
|
||||||
return world.dimension.getSeed();
|
return world.dimension.getSeed();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue