Search in sources :

Example 1 with ParserException

use of pl.themolka.arcade.parser.ParserException in project Arcade2 by ShootGame.

the class SimpleGameManager method setDefaultMaxGameId.

@Override
public void setDefaultMaxGameId() {
    Node node = this.plugin.getSettings().getData().child("queue");
    if (node == null) {
        return;
    }
    try {
        ParserContext context = this.plugin.getParsers().createContext();
        this.setMaxGameId(context.type(Integer.class).parse(node.property("restart-after")).orFail());
    } catch (ParserNotSupportedException | ParserException ex) {
        ex.printStackTrace();
    }
}
Also used : ParserException(pl.themolka.arcade.parser.ParserException) Node(pl.themolka.arcade.dom.Node) ParserContext(pl.themolka.arcade.parser.ParserContext) ParserNotSupportedException(pl.themolka.arcade.parser.ParserNotSupportedException)

Example 2 with ParserException

use of pl.themolka.arcade.parser.ParserException in project Arcade2 by ShootGame.

the class OfflineMapParser method parseTree.

@Override
protected ParserResult<OfflineMap> parseTree(Node node, String name) throws ParserException {
    Property fileVersionProperty = node.property("fileversion", "file-version", "ver", "version", "proto", "manifest");
    MapFileVersion fileVersion = this.fileVersionParser.parse(fileVersionProperty).orDefault(MapFileVersions.NEWEST);
    Node nameNode = node.firstChild("name");
    Node versionNode = node.firstChild("version", "ver");
    if (nameNode == null || versionNode == null) {
        throw new ParserException(node, MISSING_NAME_VERSION);
    }
    String mapName = this.nameParser.parse(nameNode).orFail();
    MapVersion version = this.versionParser.parse(versionNode).orFail();
    String description = this.descriptionParser.parse(node.firstChild("description", "objective", "goal", "about")).orNull();
    int mapNameLength = mapName.length();
    if (mapNameLength < OfflineMap.NAME_MIN_LENGTH) {
        throw this.fail(nameNode, nameNode.getName(), nameNode.getValue(), "Map name is shorter than " + OfflineMap.NAME_MIN_LENGTH + " characters");
    } else if (mapNameLength > OfflineMap.NAME_MAX_LENGTH) {
        throw this.fail(nameNode, nameNode.getName(), nameNode.getValue(), "Map name is longer than " + OfflineMap.NAME_MAX_LENGTH + " characters");
    }
    List<Author> authors = this.parseAuthors(node);
    Node authorsNode = node.firstChild("authors", "contributors", "teams");
    if (authorsNode != null) {
        authors.addAll(this.parseAuthors(authorsNode));
    }
    List<Changelog> changelogs = new ArrayList<>();
    Node changelogsNode = node.firstChild("changelog", "change-log", "changes");
    if (changelogsNode != null) {
        changelogs.addAll(this.parseChangelogs(changelogsNode));
    }
    return ParserResult.fine(node, name, new OfflineMap(fileVersion, mapName, version, description, authors, changelogs));
}
Also used : ParserException(pl.themolka.arcade.parser.ParserException) Node(pl.themolka.arcade.dom.Node) ArrayList(java.util.ArrayList) Property(pl.themolka.arcade.dom.Property)

Aggregations

Node (pl.themolka.arcade.dom.Node)2 ParserException (pl.themolka.arcade.parser.ParserException)2 ArrayList (java.util.ArrayList)1 Property (pl.themolka.arcade.dom.Property)1 ParserContext (pl.themolka.arcade.parser.ParserContext)1 ParserNotSupportedException (pl.themolka.arcade.parser.ParserNotSupportedException)1