Skip to content

Commit

Permalink
Add Version support to YAMLConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
ME1312 committed Jan 17, 2019
1 parent c288aa3 commit a47af68
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 3 deletions.
45 changes: 45 additions & 0 deletions GalaxiAPI/src/net/ME1312/Galaxi/Library/Config/YAMLSection.java
@@ -1,6 +1,7 @@
package net.ME1312.Galaxi.Library.Config;

import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import org.json.JSONObject;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.error.YAMLException;
Expand Down Expand Up @@ -164,6 +165,8 @@ private Object convert(Object value) {
return list;
} else if (value instanceof UUID) {
return value.toString();
} else if (value instanceof Version) {
return ((Version) value).toFullString();
} else {
return value;
}
Expand Down Expand Up @@ -866,6 +869,48 @@ public List<UUID> getUUIDList(String handle, List<UUID> def) {
return get(handle, def).asUUIDList();
}

/**
* Get a Version by Handle
*
* @param handle Handle
* @return Version
*/
public Version getVersion(String handle) {
return get(handle).asVersion();
}

/**
* Get a Version by Handle
*
* @param handle Handle
* @param def Default
* @return Version
*/
public Version getVersion(String handle, Version def) {
return get(handle, def).asVersion();
}

/**
* Get a Version List by Handle
*
* @param handle Handle
* @return Version List
*/
public List<Version> getVersionList(String handle) {
return get(handle).asVersionList();
}

/**
* Get a Version List by Handle
*
* @param handle Handle
* @param def Default
* @return Version List
*/
public List<Version> getVersionList(String handle, List<Version> def) {
return get(handle, def).asVersionList();
}

/**
* Check if object is Null by Handle
*
Expand Down
29 changes: 27 additions & 2 deletions GalaxiAPI/src/net/ME1312/Galaxi/Library/Config/YAMLValue.java
@@ -1,6 +1,7 @@
package net.ME1312.Galaxi.Library.Config;

import net.ME1312.Galaxi.Library.Util;
import net.ME1312.Galaxi.Library.Version.Version;
import org.yaml.snakeyaml.Yaml;

import java.util.ArrayList;
Expand Down Expand Up @@ -241,7 +242,7 @@ public List<String> asStringList() {
* @return UUID
*/
public UUID asUUID() {
if (obj != null) return UUID.fromString((String) obj);
if (obj != null) return UUID.fromString(asRawString());
else return null;
}

Expand All @@ -260,6 +261,30 @@ public List<UUID> asUUIDList() {
} else return null;
}

/**
* Get Object as Version
*
* @return Version
*/
public Version asVersion() {
if (obj != null) return Version.fromString(asRawString());
else return null;
}

/**
* Get Object as Version List
*
* @return Version List
*/
public List<Version> asVersionList() {
if (obj != null) {
List<Version> values = new ArrayList<Version>();
for (String value : (List<String>) obj) {
values.add(Version.fromString(value));
}
return values;
} else return null;
}

/**
* Check if object is Null
Expand Down Expand Up @@ -321,7 +346,7 @@ public boolean isString() {
* @return UUID Status
*/
public boolean isUUID() {
return (obj instanceof String && !Util.isException(() -> UUID.fromString((String) obj)));
return (obj instanceof String && !Util.isException(() -> UUID.fromString(asRawString())));
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion GalaxiEngine/pom.xml
Expand Up @@ -11,10 +11,11 @@

<dependencies>
<dependency>
<systemPath>${basedir}/UI/jansi.jar</systemPath>
<groupId>org.fusesource.jansi</groupId>
<artifactId>jansi</artifactId>
<version>1.17.1</version>
<scope>compile</scope>
<scope>system</scope>
<optional>true</optional>
</dependency>
<dependency>
Expand Down

0 comments on commit a47af68

Please sign in to comment.