Search in sources :

Example 1 with PluginFreshEvent

use of pl.themolka.arcade.event.PluginFreshEvent 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)

Aggregations

InputStream (java.io.InputStream)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 DOMException (pl.themolka.arcade.dom.DOMException)1 Include (pl.themolka.arcade.dom.preprocess.Include)1 EventBus (pl.themolka.arcade.event.EventBus)1 PluginFreshEvent (pl.themolka.arcade.event.PluginFreshEvent)1 PluginReadyEvent (pl.themolka.arcade.event.PluginReadyEvent)1 PluginStartEvent (pl.themolka.arcade.event.PluginStartEvent)1 Settings (pl.themolka.arcade.settings.Settings)1 ManifestFile (pl.themolka.arcade.util.ManifestFile)1