Search in sources :

Example 1 with ParserNotSupportedException

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

the class ArcadePlugin method loadEnvironment.

private void loadEnvironment() throws DOMException {
    Node node = this.getSettings().getData().child("environment");
    Parser<Environment> parser;
    try {
        parser = this.parsers.forType(Environment.class);
    } catch (ParserNotSupportedException ex) {
        throw new RuntimeException("No " + Environment.class.getSimpleName() + " parser installed");
    }
    this.environment = parser.parse(node).orFail();
    this.environment.initialize(this);
}
Also used : Node(pl.themolka.arcade.dom.Node) Environment(pl.themolka.arcade.environment.Environment) ParserNotSupportedException(pl.themolka.arcade.parser.ParserNotSupportedException)

Example 2 with ParserNotSupportedException

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

the class ArcadeCommands method reload.

// 
// '/arcade reload' command
// 
private void reload(Sender sender) {
    if (!sender.hasPermission("arcade.command.reload")) {
        throw new CommandPermissionException("arcade.command.reload");
    }
    Settings settings = this.plugin.getSettings();
    sender.sendInfo("Reloading settings file...");
    try {
        settings.setDocument(settings.readSettingsFile());
        this.plugin.getEventBus().publish(new SettingsReloadEvent(this.plugin, settings));
        sender.sendSuccess("Successfully reloaded settings file. Well done!");
    } catch (DOMException | IOException | ParserNotSupportedException ex) {
        ex.printStackTrace();
        throw new CommandException("Could not reload settings file: " + ex.getMessage());
    }
}
Also used : DOMException(pl.themolka.arcade.dom.DOMException) SettingsReloadEvent(pl.themolka.arcade.settings.SettingsReloadEvent) IOException(java.io.IOException) Settings(pl.themolka.arcade.settings.Settings) ParserNotSupportedException(pl.themolka.arcade.parser.ParserNotSupportedException)

Example 3 with ParserNotSupportedException

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

the class MapLoaderModule method readMapDirectory.

private OfflineMap readMapDirectory(File worldDirectory) throws DOMException, IOException {
    File file = new File(worldDirectory, MapManifest.FILENAME);
    if (!file.exists()) {
        throw new FileNotFoundException("Missing " + file.getName());
    }
    DOMEngine engine = this.getPlugin().getDomEngines().forFile(file);
    Parser<OfflineMap> parser;
    try {
        parser = this.getPlugin().getParsers().forType(OfflineMap.class);
    } catch (ParserNotSupportedException ex) {
        throw new RuntimeException("No " + OfflineMap.class.getSimpleName() + " parser installed");
    }
    Document document = engine.read(file);
    this.getPlugin().getDomPreprocessor().preprocess(document);
    OfflineMap map = parser.parse(document).orFail();
    map.setDirectory(worldDirectory);
    map.setSettings(file);
    return map;
}
Also used : DOMEngine(pl.themolka.arcade.dom.engine.DOMEngine) FileNotFoundException(java.io.FileNotFoundException) Document(pl.themolka.arcade.dom.Document) File(java.io.File) ParserNotSupportedException(pl.themolka.arcade.parser.ParserNotSupportedException)

Example 4 with ParserNotSupportedException

use of pl.themolka.arcade.parser.ParserNotSupportedException 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 5 with ParserNotSupportedException

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

the class ArcadePlugin method loadParsers.

private void loadParsers() {
    this.domEngines = new EngineManager();
    this.domEngines.registerDefault();
    this.domPreprocessor = new Preprocessor();
    this.domPreprocessor.install(new Import(this.domEngines, this.domPreprocessor));
    this.parsers = new ParserManager(this);
    this.parsers.setContextFactory(new ParserContext.Factory());
    try (InputStream input = this.getClass().getClassLoader().getResourceAsStream(ParsersFile.DEFAULT_FILENAME)) {
        ParsersFile file = new ParsersFile(this, input);
        int done = 0;
        int doneSilent = 0;
        ParserContainer container = new ParserContainer();
        for (Class<? extends Parser<?>> parser : file.getParsers()) {
            try {
                container.register(parser.newInstance());
                done++;
                Silent silent = parser.getAnnotation(Silent.class);
                Produces produces = parser.getAnnotation(Produces.class);
                if (produces == null) {
                    throw new ReflectiveOperationException(parser.getName() + " is not @Produces decorated!");
                } else if (silent == null) {
                    Class<?> producesType = produces.value();
                    if (producesType != null) {
                        this.parsers.registerType(producesType, parser);
                    }
                } else {
                    doneSilent++;
                }
            } catch (ReflectiveOperationException ex) {
                ex.printStackTrace();
            }
        }
        this.parsers.getContainer().register(container);
        String silentString = "";
        if (doneSilent > 0) {
            silentString = " (" + doneSilent + " of them " + (doneSilent == 1 ? "was" : "were") + " silent)";
        }
        this.getLogger().info("Registered " + done + " parsers" + silentString + ".");
    } catch (DOMException | IOException ex) {
        ex.printStackTrace();
    }
    // Install parser dependencies
    int done = 0;
    try {
        done = this.parsers.install();
    } catch (ParserNotSupportedException ex) {
        this.getLogger().log(Level.SEVERE, "Given parser is not supported", ex);
    }
    this.getLogger().info("Installed " + done + " parser dependencies.");
}
Also used : ParserContainer(pl.themolka.arcade.parser.ParserContainer) EngineManager(pl.themolka.arcade.dom.engine.EngineManager) Import(pl.themolka.arcade.dom.preprocess.Import) InputStream(java.io.InputStream) Silent(pl.themolka.arcade.parser.Silent) IOException(java.io.IOException) ParserManager(pl.themolka.arcade.parser.ParserManager) ParsersFile(pl.themolka.arcade.parser.ParsersFile) DOMException(pl.themolka.arcade.dom.DOMException) Produces(pl.themolka.arcade.parser.Produces) Preprocessor(pl.themolka.arcade.dom.preprocess.Preprocessor) ParserContext(pl.themolka.arcade.parser.ParserContext) ParserNotSupportedException(pl.themolka.arcade.parser.ParserNotSupportedException)

Aggregations

ParserNotSupportedException (pl.themolka.arcade.parser.ParserNotSupportedException)7 IOException (java.io.IOException)3 DOMException (pl.themolka.arcade.dom.DOMException)3 File (java.io.File)2 Document (pl.themolka.arcade.dom.Document)2 Node (pl.themolka.arcade.dom.Node)2 DOMEngine (pl.themolka.arcade.dom.engine.DOMEngine)2 ParserContext (pl.themolka.arcade.parser.ParserContext)2 SettingsReloadEvent (pl.themolka.arcade.settings.SettingsReloadEvent)2 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 EngineManager (pl.themolka.arcade.dom.engine.EngineManager)1 Import (pl.themolka.arcade.dom.preprocess.Import)1 Preprocessor (pl.themolka.arcade.dom.preprocess.Preprocessor)1 Environment (pl.themolka.arcade.environment.Environment)1 ArcadeMap (pl.themolka.arcade.map.ArcadeMap)1 MapManifest (pl.themolka.arcade.map.MapManifest)1 WorldNameGenerator (pl.themolka.arcade.map.WorldNameGenerator)1 ParserContainer (pl.themolka.arcade.parser.ParserContainer)1 ParserException (pl.themolka.arcade.parser.ParserException)1