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