Search in sources :

Example 1 with Metrics

use of me.botsko.prism.measurement.Metrics in project Prism-Bukkit by prism.

the class Prism method onEnable.

/**
     * Enables the plugin and activates our player listeners
     */
@SuppressWarnings("rawtypes")
@Override
public void onEnable() {
    plugin_name = this.getDescription().getName();
    plugin_version = this.getDescription().getVersion();
    prism = this;
    log("Initializing Prism " + plugin_version + ". By Viveleroi.");
    // Load configuration, or install if new
    loadConfig();
    if (getConfig().getBoolean("prism.allow-metrics")) {
        try {
            final Metrics metrics = new Metrics(this);
            metrics.start();
        } catch (final IOException e) {
            log("MCStats submission failed.");
        }
    }
    // init db
    pool = initDbPool();
    final Connection test_conn = dbc();
    if (pool == null || test_conn == null) {
        final String[] dbDisabled = new String[3];
        dbDisabled[0] = "Prism will disable itself because it couldn't connect to a database.";
        dbDisabled[1] = "If you're using MySQL, check your config. Be sure MySQL is running.";
        dbDisabled[2] = "For help - try http://discover-prism.com/wiki/view/troubleshooting/";
        logSection(dbDisabled);
        disablePlugin();
    }
    if (test_conn != null) {
        try {
            test_conn.close();
        } catch (final SQLException e) {
            handleDatabaseException(e);
        }
    }
    if (isEnabled()) {
        // Info needed for setup, init these here
        handlerRegistry = new HandlerRegistry();
        actionRegistry = new ActionRegistry();
        // Setup databases
        setupDatabase();
        // Cache world IDs
        cacheWorldPrimaryKeys();
        PlayerIdentification.cacheOnlinePlayerPrimaryKeys();
        // ensure current worlds are added
        for (final World w : getServer().getWorlds()) {
            if (!Prism.prismWorlds.containsKey(w.getName())) {
                Prism.addWorldName(w.getName());
            }
        }
        // Apply any updates
        final Updater up = new Updater(this);
        up.apply_updates();
        eventTimer = new TimeTaken(this);
        queueStats = new QueueStats();
        ignore = new Ignore(this);
        // Plugins we use
        checkPluginDependancies();
        // Assign event listeners
        getServer().getPluginManager().registerEvents(new PrismBlockEvents(this), this);
        getServer().getPluginManager().registerEvents(new PrismEntityEvents(this), this);
        getServer().getPluginManager().registerEvents(new PrismWorldEvents(), this);
        getServer().getPluginManager().registerEvents(new PrismPlayerEvents(this), this);
        getServer().getPluginManager().registerEvents(new PrismInventoryEvents(this), this);
        getServer().getPluginManager().registerEvents(new PrismVehicleEvents(this), this);
        // InventoryMoveItem
        if (getConfig().getBoolean("prism.track-hopper-item-events") && Prism.getIgnore().event("item-insert")) {
            getServer().getPluginManager().registerEvents(new PrismInventoryMoveItemEvent(), this);
        }
        if (getConfig().getBoolean("prism.tracking.api.enabled")) {
            getServer().getPluginManager().registerEvents(new PrismCustomEvents(this), this);
        }
        // Assign listeners to our own events
        // getServer().getPluginManager().registerEvents(new
        // PrismRollbackEvents(), this);
        getServer().getPluginManager().registerEvents(new PrismMiscEvents(), this);
        // Add commands
        getCommand("prism").setExecutor(new PrismCommands(this));
        getCommand("prism").setTabCompleter(new PrismCommands(this));
        getCommand("what").setExecutor(new WhatCommand(this));
        // Register official parameters
        registerParameter(new ActionParameter());
        registerParameter(new BeforeParameter());
        registerParameter(new BlockParameter());
        registerParameter(new EntityParameter());
        registerParameter(new FlagParameter());
        registerParameter(new IdParameter());
        registerParameter(new KeywordParameter());
        registerParameter(new PlayerParameter());
        registerParameter(new RadiusParameter());
        registerParameter(new SinceParameter());
        registerParameter(new WorldParameter());
        // Init re-used classes
        messenger = new Messenger(plugin_name);
        actionsQuery = new ActionsQuery(this);
        oreMonitor = new OreMonitor(this);
        useMonitor = new UseMonitor(this);
        // Init async tasks
        actionRecorderTask();
        // Init scheduled events
        endExpiredQueryCaches();
        endExpiredPreviews();
        removeExpiredLocations();
        // Delete old data based on config
        launchScheduledPurgeManager();
        // Keep watch on db connections, other sanity
        launchInternalAffairs();
    }
}
Also used : World(org.bukkit.World) Metrics(me.botsko.prism.measurement.Metrics) UseMonitor(me.botsko.prism.monitors.UseMonitor) QueueStats(me.botsko.prism.measurement.QueueStats) OreMonitor(me.botsko.prism.monitors.OreMonitor) PrismMiscEvents(me.botsko.prism.listeners.self.PrismMiscEvents) WhatCommand(me.botsko.prism.commands.WhatCommand) PrismCommands(me.botsko.prism.commands.PrismCommands) TimeTaken(me.botsko.prism.measurement.TimeTaken) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 PrismCommands (me.botsko.prism.commands.PrismCommands)1 WhatCommand (me.botsko.prism.commands.WhatCommand)1 PrismMiscEvents (me.botsko.prism.listeners.self.PrismMiscEvents)1 Metrics (me.botsko.prism.measurement.Metrics)1 QueueStats (me.botsko.prism.measurement.QueueStats)1 TimeTaken (me.botsko.prism.measurement.TimeTaken)1 OreMonitor (me.botsko.prism.monitors.OreMonitor)1 UseMonitor (me.botsko.prism.monitors.UseMonitor)1 World (org.bukkit.World)1