Search in sources :

Example 1 with CommandSupport

use of be.pyrrh4.core.core.CommandSupport in project PyrCore by PYRRH4.

the class Core method enable.

// ------------------------------------------------------------
// On enable
// ------------------------------------------------------------
@Override
protected void enable() {
    // Auto update
    allowAutoUpdate = getConfiguration().getBoolean("auto_update");
    if (allowAutoUpdate) {
        autoUpdateTaskId = new AutoUpdateTask().runTaskTimerAsynchronously(this, 100L, 18000L).getTaskId();
    }
    Logger.log(Level.INFO, this, "Allowing AutoUpdate : " + allowAutoUpdate);
    // MySQL
    if (getConfiguration() != null && (allowMySql = getConfiguration().getBoolean("mysql.enable"))) {
        String host = getConfiguration().getString("mysql.host");
        String name = getConfiguration().getString("mysql.name");
        String usr = getConfiguration().getString("mysql.user");
        String pwd = getConfiguration().getString("mysql.pass");
        String url = "jdbc:mysql://" + host + "/" + name + "?allowMultiQueries=true";
        mySQL = new MySQL(url, usr, pwd);
        try {
            mySQL.connect();
            allowMySqlStats = getConfiguration().getBoolean("mysql_stats");
            if (allowMySqlStats) {
                new Handler() {

                    @Override
                    public void execute() {
                        mySQL.executeQuery("CREATE TABLE IF NOT EXISTS pyrcore_stats(uid INT NOT NULL AUTO_INCREMENT,uuid TINYTEXT NOT NULL,stats TEXT NOT NULL,PRIMARY KEY(uid))ENGINE=MYISAM DEFAULT CHARSET='utf8';");
                    }
                }.runAsync();
            }
            Logger.log(Level.INFO, this, "Using mysql : yes");
            Logger.log(Level.INFO, this, "Using mysql stats : " + (allowMySqlStats ? "yes" : "no"));
        } catch (Exception exception) {
            exception.printStackTrace();
            mySQL = null;
            Logger.log(Level.INFO, this, "Using mysql : no (unknown error)");
        }
    } else {
        mySQL = null;
        Logger.log(Level.INFO, this, "Using mysql : no");
    }
    // Load online users
    for (Player player : Utils.getOnlinePlayers()) {
        User.from(player);
    }
    // Core events
    Bukkit.getPluginManager().registerEvents(this, this);
    // Core commands
    Command command = new Command(this, "pyr", "pyr", null);
    command.addArguments(new Arguments("plugins|pl", "plugins", "list PyrCore dependant plugins", "pyr.core.admin", false, new CommandPlugins()));
    command.addArguments(new Arguments("reload|rl [string]", "reload", "reload a plugin", "pyr.core.reload", false, new CommandReload()));
    command.addArguments(new Arguments("support|bug|bugreport|report [string]", "support", "get support for a plugin", "pyr.core.admin", false, new CommandSupport()));
    command.addArguments(new Arguments("mat", null, null, "pyr.core.admin", true, new CommandMat()));
    // Task
    long delay = Utils.getMinutesInTicks(30);
    coreTaskId = new BukkitRunnable() {

        @Override
        public void run() {
            // plugin data
            for (PyrPlugin plugin : registeredPlugins) {
                try {
                    plugin.savePluginData();
                } catch (Exception ignored) {
                }
            }
        }
    }.runTaskTimerAsynchronously(this, delay, delay).getTaskId();
    // Enable log
    Logger.log(Level.SUCCESS, this, getDescription().getName() + " v" + getDescription().getVersion() + " has been enabled !");
}
Also used : CommandReload(be.pyrrh4.core.core.CommandReload) Player(org.bukkit.entity.Player) Arguments(be.pyrrh4.core.command.Arguments) EventHandler(org.bukkit.event.EventHandler) Handler(be.pyrrh4.core.util.Handler) BukkitRunnable(org.bukkit.scheduler.BukkitRunnable) Command(be.pyrrh4.core.command.Command) CommandPlugins(be.pyrrh4.core.core.CommandPlugins) CommandMat(be.pyrrh4.core.core.CommandMat) CommandSupport(be.pyrrh4.core.core.CommandSupport)

Aggregations

Arguments (be.pyrrh4.core.command.Arguments)1 Command (be.pyrrh4.core.command.Command)1 CommandMat (be.pyrrh4.core.core.CommandMat)1 CommandPlugins (be.pyrrh4.core.core.CommandPlugins)1 CommandReload (be.pyrrh4.core.core.CommandReload)1 CommandSupport (be.pyrrh4.core.core.CommandSupport)1 Handler (be.pyrrh4.core.util.Handler)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1