Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/main/java/codechicken/lib/config/ConfigTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ default ConfigTag setComment(String... lines) {

int getInt();

long getLong();

int getHex();

double getDouble();
Expand All @@ -217,6 +219,8 @@ default ConfigTag setComment(String... lines) {

ConfigTag setDefaultInt(int value);

ConfigTag setDefaultLong(long value);

ConfigTag setDefaultHex(int value);

ConfigTag setDefaultDouble(double value);
Expand All @@ -228,6 +232,8 @@ default ConfigTag setComment(String... lines) {

ConfigTag setInt(int value);

ConfigTag setLong(long value);

ConfigTag setHex(int value);

ConfigTag setDouble(double value);
Expand All @@ -239,6 +245,8 @@ default ConfigTag setComment(String... lines) {

List<Integer> getIntList();

List<Long> getLongList();

List<Integer> getHexList();

List<Double> getDoubleList();
Expand All @@ -250,6 +258,8 @@ default ConfigTag setComment(String... lines) {

ConfigTag setDefaultIntList(List<Integer> value);

ConfigTag setDefaultLongList(List<Long> value);

ConfigTag setDefaultHexList(List<Integer> value);

ConfigTag setDefaultDoubleList(List<Double> value);
Expand All @@ -261,6 +271,8 @@ default ConfigTag setComment(String... lines) {

ConfigTag setIntList(List<Integer> value);

ConfigTag setLongList(List<Long> value);

ConfigTag setHexList(List<Integer> value);

ConfigTag setDoubleList(List<Double> value);
Expand Down Expand Up @@ -395,6 +407,17 @@ public void write(MCDataOutput out, TagType listType, Object value) {
out.writeSignedVarInt((Integer) value);
}
},
LONG('L') {
@Override
public Object read(MCDataInput in, TagType listType) {
return in.readSignedVarLong();
}

@Override
public void write(MCDataOutput out, TagType listType, Object value) {
out.writeSignedVarLong((Long) value);
}
},
HEX('H') {
@Override
public String processLine(Object obj) {
Expand Down
69 changes: 69 additions & 0 deletions src/main/java/codechicken/lib/config/ConfigTagImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,19 @@ public int getInt() {
return (Integer) value;
}

@Override
public long getLong() {
if (value == null) {
throw new IllegalStateException("Tag in a weird state, value is null, did you set a default?");
} else if (type != TagType.LONG) {
throw new UnsupportedOperationException("ConfigTag is not of a Integer type, Actual: " + type);
} else if (!(value instanceof Long)) {
throw new IllegalStateException(String.format("Tag appears to be in an invalid state.. Requested: %s, Current %s.", type, value.getClass()));
}

return (Long) value;
}

@Override
public int getHex() {
if (value == null) {
Expand Down Expand Up @@ -323,6 +336,18 @@ public ConfigTagImpl setDefaultInt(int value) {
return this;
}

@Override
public ConfigTag setDefaultLong(long value) {
setDefaultCheck();

defaultValue = value;
if (this.value == null) {
setLong(value);
}

return this;
}

@Override
public ConfigTagImpl setDefaultHex(int value) {
setDefaultCheck();
Expand Down Expand Up @@ -374,6 +399,15 @@ public ConfigTagImpl setInt(int value) {
return this;
}

@Override
public ConfigTag setLong(long value) {
setValueCheck();
type = TagType.LONG;
this.value = value;
markDirty();
return this;
}

@Override
public ConfigTagImpl setHex(int value) {
setValueCheck();
Expand Down Expand Up @@ -442,6 +476,22 @@ public List<Integer> getIntList() {
return (List) value;
}

@Override
@SuppressWarnings ("unchecked")
public List<Long> getLongList() {
if (value == null) {
throw new IllegalStateException("Tag in a weird state, value is null, did you set a default?");
} else if (type != TagType.LIST) {
throw new UnsupportedOperationException("ConfigTag is not of a List type, Actual: " + type);
} else if (listType != TagType.LONG) {
throw new UnsupportedOperationException("List is not of a Long type, Actual: " + type);
} else if (!(value instanceof List)) {
throw new IllegalStateException(String.format("Tag appears to be in an invalid state.. Requested: %s, Current %s.", type, value.getClass()));
}

return (List) value;
}

@Override
@SuppressWarnings ("unchecked")
public List<Integer> getHexList() {
Expand Down Expand Up @@ -510,6 +560,18 @@ public ConfigTagImpl setDefaultIntList(List<Integer> value) {
return this;
}

@Override
public ConfigTagImpl setDefaultLongList(List<Long> value) {
setDefaultCheck();

defaultValue = value;
if (this.value == null) {
setLongList(value);
}

return this;
}

@Override
public ConfigTagImpl setDefaultHexList(List<Integer> value) {
setDefaultCheck();
Expand Down Expand Up @@ -562,6 +624,13 @@ public ConfigTagImpl setIntList(List<Integer> value) {
return this;
}

@Override
public ConfigTagImpl setLongList(List<Long> value) {
setList(value);
listType = TagType.LONG;
return this;
}

@Override
public ConfigTagImpl setHexList(List<Integer> value) {
setList(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ private void parse(ConfigTagImpl thisTag, ConfigReader reader) throws IOExceptio
}
continue;
}
case LONG: {
try {
tag.setLong(Long.parseLong(value));
} catch (NumberFormatException e) {
throw new ConfigParseException(e, "Malformed line!, @%s, '%s'", reader.getCurrLine(), line);
}
continue;
}
case HEX: {
try {
tag.setHex((int) Long.parseLong(value.replace("0x", ""), 16));
Expand Down Expand Up @@ -162,6 +170,10 @@ private void parse(ConfigTagImpl thisTag, ConfigReader reader) throws IOExceptio
list.add(Integer.parseInt(listLine));
break;
}
case LONG: {
list.add(Long.parseLong(listLine));
break;
}
case HEX: {
list.add((int) Long.parseLong(listLine.replace("0x", ""), 16));
break;
Expand All @@ -186,6 +198,9 @@ private void parse(ConfigTagImpl thisTag, ConfigReader reader) throws IOExceptio
case INT:
tag.setIntList(list);
break;
case LONG:
tag.setLongList(list);
break;
case HEX: {
tag.setHexList(list);
break;
Expand Down Expand Up @@ -262,6 +277,7 @@ private void writeTag(ConfigTagImpl tag, PrintWriter writer, int depth) {
break;
case BOOLEAN:
case INT:
case LONG:
case HEX:
case DOUBLE:
writeLine(writer, depth, "%s:\"%s\"=%s", tag.type.getChar(), tag.name, tag.type.processLine(tag.value));
Expand Down