Search in sources :

Example 1 with DOMException

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());
    }
}
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 2 with DOMException

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());
}
Also used : InputStream(java.io.InputStream) Include(pl.themolka.arcade.dom.preprocess.Include) EventBus(pl.themolka.arcade.event.EventBus) PluginReadyEvent(pl.themolka.arcade.event.PluginReadyEvent) World(org.bukkit.World) ManifestFile(pl.themolka.arcade.util.ManifestFile) DOMException(pl.themolka.arcade.dom.DOMException) ConsoleSender(pl.themolka.arcade.command.ConsoleSender) PluginFreshEvent(pl.themolka.arcade.event.PluginFreshEvent) PluginStartEvent(pl.themolka.arcade.event.PluginStartEvent) Vector(org.bukkit.util.Vector) BukkitCommands(pl.themolka.arcade.command.BukkitCommands) Settings(pl.themolka.arcade.settings.Settings)

Example 3 with DOMException

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

Example 4 with DOMException

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);
        }
    }
}
Also used : ModulesLoadEvent(pl.themolka.arcade.module.ModulesLoadEvent) InputStream(java.io.InputStream) Node(pl.themolka.arcade.dom.Node) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) ArrayList(java.util.ArrayList) IOException(java.io.IOException) DOMException(pl.themolka.arcade.dom.DOMException) ModulesFile(pl.themolka.arcade.module.ModulesFile) ModuleInfo(pl.themolka.arcade.module.ModuleInfo) Module(pl.themolka.arcade.module.Module)

Example 5 with DOMException

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);
    }
}
Also used : DOMException(pl.themolka.arcade.dom.DOMException) SettingsReloadEvent(pl.themolka.arcade.settings.SettingsReloadEvent) IOException(java.io.IOException) ParserNotSupportedException(pl.themolka.arcade.parser.ParserNotSupportedException)

Aggregations

DOMException (pl.themolka.arcade.dom.DOMException)7 IOException (java.io.IOException)4 InputStream (java.io.InputStream)3 ParserNotSupportedException (pl.themolka.arcade.parser.ParserNotSupportedException)3 ArrayList (java.util.ArrayList)2 Settings (pl.themolka.arcade.settings.Settings)2 SettingsReloadEvent (pl.themolka.arcade.settings.SettingsReloadEvent)2 File (java.io.File)1 Instant (java.time.Instant)1 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)1 World (org.bukkit.World)1 Vector (org.bukkit.util.Vector)1 BukkitCommands (pl.themolka.arcade.command.BukkitCommands)1 ConsoleSender (pl.themolka.arcade.command.ConsoleSender)1 ServerCycleEvent (pl.themolka.arcade.cycle.ServerCycleEvent)1 Node (pl.themolka.arcade.dom.Node)1 EngineManager (pl.themolka.arcade.dom.engine.EngineManager)1 Import (pl.themolka.arcade.dom.preprocess.Import)1 Include (pl.themolka.arcade.dom.preprocess.Include)1 Preprocessor (pl.themolka.arcade.dom.preprocess.Preprocessor)1