Search in sources :

Example 1 with PyrPlugin

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

the class CommandReload method perform.

@Override
public void perform(CallInfo call) {
    CommandSender sender = call.getSender();
    String pl = call.getArgAsString(1).toUpperCase();
    if (!Core.instance().isPluginRegistered(pl)) {
        Core.instance().getLocale().getMessage("admin_plugin_not_found").send(sender);
        return;
    }
    PyrPlugin plugin = Core.instance().getRegisteredPlugin(pl);
    plugin.reload();
    Messenger.send(sender, Level.NORMAL_SUCCESS, plugin.getName(), "Reloaded plugin !");
}
Also used : CommandSender(org.bukkit.command.CommandSender) PyrPlugin(be.pyrrh4.core.PyrPlugin)

Example 2 with PyrPlugin

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

the class Utils method unzipGZ.

// ------------------------------------------------------------
// File
// ------------------------------------------------------------
public static File unzipGZ(File gzFile, PyrPlugin pl) {
    if (gzFile == null) {
        return null;
    }
    try {
        File output = File.createTempFile(pl.getDescription().getName().toLowerCase() + "_" + "log_", ".log");
        Logger.log(Level.INFO, pl, "Unzipped file to " + output.getAbsolutePath());
        byte[] buffer = new byte[1024];
        GZIPInputStream in = new GZIPInputStream(new FileInputStream(gzFile));
        FileOutputStream out = new FileOutputStream(output);
        int len;
        while ((len = in.read(buffer)) > 0) {
            out.write(buffer, 0, len);
        }
        in.close();
        out.close();
        return output;
    } catch (IOException ex) {
        ex.printStackTrace();
        return null;
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) AdapterFile(be.pyrrh4.core.x.lib.com.google.gson.adapter.AdapterFile) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 3 with PyrPlugin

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

the class CommandPlugins method perform.

@Override
public void perform(CallInfo call) {
    CommandSender sender = call.getSender();
    Core.instance().getLocale().getMessage("admin_plugins_amount").send(sender, "$AMOUNT", Core.instance().getRegisteredPlugins().size(), "$PLURAL", Utils.getPlural("s", Core.instance().getRegisteredPlugins().size()));
    ArrayList<String> list = new ArrayList<String>();
    String listElementText = Core.instance().getLocale().getMessage("admin_plugins_list_element").getLines().get(0);
    for (PyrPlugin pl : Core.instance().getRegisteredPlugins()) {
        list.add(listElementText.replace("$NAME", pl.getName()).replace("$VERSION", pl.getDescription().getVersion()));
    }
    Messenger.send(sender, list);
}
Also used : ArrayList(java.util.ArrayList) CommandSender(org.bukkit.command.CommandSender) PyrPlugin(be.pyrrh4.core.PyrPlugin)

Example 4 with PyrPlugin

use of be.pyrrh4.core.PyrPlugin 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

PyrPlugin (be.pyrrh4.core.PyrPlugin)2 CommandSender (org.bukkit.command.CommandSender)2 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 AdapterFile (be.pyrrh4.core.x.lib.com.google.gson.adapter.AdapterFile)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 GZIPInputStream (java.util.zip.GZIPInputStream)1 Player (org.bukkit.entity.Player)1 EventHandler (org.bukkit.event.EventHandler)1 BukkitRunnable (org.bukkit.scheduler.BukkitRunnable)1