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);
}
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());
}
}
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;
}
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();
}
}
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.");
}
Aggregations