use of pl.themolka.arcade.dom.DOMException 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.dom.DOMException in project Arcade2 by ShootGame.
the class ArcadePlugin method start.
public final void start() throws Throwable {
if (this.isRunning()) {
throw new IllegalStateException("Already running!");
} else if (this.getStartTime() != null) {
throw new IllegalStateException("Outdated class!");
}
this.running = true;
this.startTime = Time.now();
this.loadParsers();
try (InputStream input = this.getClass().getClassLoader().getResourceAsStream(ManifestFile.DEFAULT_FILE)) {
this.manifest = new ManifestFile(this.domEngines.forFile(ManifestFile.DEFAULT_FILE).read(input));
}
this.eventBus = new EventBus(this);
this.console = new ConsoleSender(this);
this.commands = new BukkitCommands(this, this.getName());
this.commands.setPrefix(BukkitCommands.BUKKIT_COMMAND_PREFIX);
this.settings = new Settings(this);
this.reloadConfig();
if (!this.getSettings().isEnabled()) {
this.getLogger().log(Level.INFO, this.getName() + " isn't enabled in the settings file, skipped enabling...");
return;
}
this.domPreprocessor.install(new Include(this.domEngines, this.domPreprocessor, this.settings.getIncludeRepository()));
this.getEventBus().publish(new PluginStartEvent(this));
this.loadServer();
try {
this.loadEnvironment();
this.getEnvironment().onEnable();
} catch (DOMException ex) {
this.getLogger().log(Level.SEVERE, "Could not enable the environment: " + ex.toString());
return;
}
this.loadCommands();
this.loadModules();
this.loadMaps();
this.loadTasks();
this.loadWindows();
this.loadGames();
this.tickableTask = this.getServer().getScheduler().runTaskTimer(this, this, 1L, 1L);
this.getEventBus().publish(new PluginReadyEvent(this));
// begin the plugin logic
this.getServer().getScheduler().runTaskLater(this, () -> {
World defaultWorld = this.getServer().getWorlds().get(0);
Vector spawn = this.getSettings().getSpawn();
defaultWorld.setSpawnLocation(spawn.getBlockX(), spawn.getBlockY(), spawn.getBlockZ());
if (this.beginLogic()) {
this.getEventBus().publish(new PluginFreshEvent(this));
this.getLogger().info(getName() + " is fresh and ready to use.");
} else {
this.getLogger().severe("Could not start - see logs above. Shutting down the server...");
this.getServer().shutdown();
}
}, Time.ZERO.toTicks());
}
use of pl.themolka.arcade.dom.DOMException 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.");
}
use of pl.themolka.arcade.dom.DOMException in project Arcade2 by ShootGame.
the class ArcadePlugin method loadModules.
private void loadModules() {
Node ignoredModules = this.getSettings().getData().child("ignored-modules");
if (ignoredModules == null) {
ignoredModules = Node.empty();
}
List<String> ignoredModuleList = new ArrayList<>();
for (Node ignoredModule : ignoredModules.children("module")) {
String id = ignoredModule.getValue();
if (id != null && !id.isEmpty()) {
ignoredModuleList.add(id);
}
}
List<Module<?>> moduleList = new ArrayList<>();
try (InputStream input = this.getClass().getClassLoader().getResourceAsStream(ModulesFile.DEFAULT_FILENAME)) {
ModulesFile file = new ModulesFile(this, input);
for (Module<?> module : file.getModules()) {
ModuleInfo infoAnnotation = module.getClass().getAnnotation(ModuleInfo.class);
if (infoAnnotation == null) {
continue;
}
if (!ignoredModuleList.contains(infoAnnotation.id().toLowerCase())) {
moduleList.add(module);
}
}
} catch (DOMException | IOException ex) {
ex.printStackTrace();
}
ModulesLoadEvent loadEvent = new ModulesLoadEvent(this, moduleList);
this.getEventBus().publish(loadEvent);
List<Module<?>> success = new ArrayList<>();
for (Module<?> module : loadEvent.getModules()) {
try {
module.initialize(this);
module.registerCommandObject(module);
success.add(module);
} catch (Throwable th) {
this.getLogger().log(Level.SEVERE, "Could not load module '" + module.getId() + "': " + th.getMessage(), th);
}
}
this.getLogger().info("Successfully loaded " + success.size() + " of " + loadEvent.getModules().size() + " available modules.");
this.getModules().register(success.toArray(new Module<?>[success.size()]));
Node globalModules = this.getSettings().getData().child("modules");
if (globalModules == null) {
globalModules = Node.empty();
}
for (Module<?> module : this.getModules().getModules()) {
try {
Node moduleNode = globalModules.child(module.getId());
module.setGlobal(moduleNode != null);
module.registerListeners();
module.onEnable(moduleNode);
} catch (Throwable th) {
this.getLogger().log(Level.SEVERE, "Could not enable module '" + module.getId() + "': " + th.getMessage(), th);
}
}
}
use of pl.themolka.arcade.dom.DOMException in project Arcade2 by ShootGame.
the class ArcadePlugin method reloadConfig.
@Override
public void reloadConfig() {
try {
this.settings.setDocument(this.settings.readSettingsFile());
this.getEventBus().publish(new SettingsReloadEvent(this, this.settings));
} catch (DOMException | IOException | ParserNotSupportedException ex) {
throw new RuntimeException(ex);
}
}
Aggregations