Permalink
Browse files

Code reorganization part 1

handling null pointer in updating player's time in group
added auto updater
changed version to 1.3.beta5
  • Loading branch information...
1 parent ec059df commit 6659e4ff72efb3b52d35d7585b2479bd47888675 @Rutr committed May 11, 2013
View
36 src/pl/azpal/azpermissions/system/AZGroup.java
@@ -1,36 +0,0 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
-package pl.azpal.azrank.groupManager;
-
-import java.util.Calendar;
-
-/**
- *
- * @author Rutr <artuczapl at gmail.com>
- */
-public class AZGroup {
- private String name;
- public long date;
- public long endTime;
-
- public AZGroup(String groupName, long start, long end) {
- name=groupName;
- date=start;
- endTime=end;
- }
-
- public long getDateDiff() {
- return endTime-date;
- }
-
- public long getRemainingTime(){
- return endTime - Calendar.getInstance().getTimeInMillis();
- }
-
- public String getName() {
- return name;
- }
-
-}
View
21 src/pl/azpal/azpermissions/system/AZPermissionsSysIf.java
@@ -1,21 +0,0 @@
-/*
- * Group Manager
- *
- */
-package pl.azpal.azrank.groupManager;
-
-
-import org.bukkit.entity.Player;
-/**
- *
- * @author Rutr
- */
-public interface AZPermissionsSysIf {
-
- public abstract AZGroup[] getPlayersGroups(Player player);
-
- public abstract void setPlayersGroups(Player player, AZGroup[] groups);
-
- //public
-
-}
View
141 src/pl/azpal/azrank/TimeRankChecker.java
@@ -1,141 +0,0 @@
-package pl.azpal.azrank;
-
-import java.util.Calendar;
-import java.util.List;
-import java.util.Set;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import org.bukkit.configuration.ConfigurationSection;
-
-
-
-
-class TimeRankChecker implements Runnable {
- private AZRank plugin;
-
- public TimeRankChecker(AZRank origin) {
- this.plugin = origin;
- }
- @Override
- public void run() {
- try {
- plugin.debugmsg("Checking Time Ranks");
- long now = Calendar.getInstance().getTimeInMillis();
- //GregorianCalendar
- ConfigurationSection usersSection = plugin.database.getConfigurationSection("users");
-
- if (usersSection != null) {
- Set<String> usersNames = usersSection.getKeys(false);
- //plugin.tempranks=usersNames.size();
- int tempranks=0;
- for (String userName : usersNames)
- {
- plugin.debugmsg("Checking user: " + userName);
- long to = plugin.database.getLong("users." + userName + ".to");
- if(to == 0)
- { //version >= 1.3.0
- //TODO: usuwanie jak nie ma .to
- ConfigurationSection userSection = plugin.database.getConfigurationSection("users."+userName);
- Set<String> groups = userSection.getKeys(false);
-
- if(groups.size()>0){
- for(String group:groups)
- {
- tempranks++;
- to = plugin.database.getLong("users." + userName + "."+group+".to");
- if(to < now)
- {
- List<String> restoreGroups = userSection.getStringList(group+".restoreGroups");
- String world = userSection.getString(group+".world");
- if((world == null) || (world.equalsIgnoreCase("")))
- {
- world = plugin.getServer().getWorlds().get(0).getName();
- }
-
- if(restoreGroups!=null)
- {
- plugin.permBridge.playerAddGroups(userName,restoreGroups.toArray(new String[]{}), true, world);
- for(String rGroup:restoreGroups)//usuwanie danych o grupach które mają zostać przywrócone.
- {
- userSection.set(rGroup,null);
- }
- }
- plugin.permBridge.playerRemoveGroups(userName,new String[]{group}, true, world);
- plugin.database.set("users." + userName + "."+group,null);
- plugin.save();
- }
- }
- } else {
- plugin.debugmsg(userName + " dont have any groups - deleting!");
- usersSection.set(userName, null);
- }
-
- }
- else {//capability with 1.2.5 and older versions
- String world = plugin.getServer().getWorlds().get(0).getName();
- if(to < now) {
- List<String> oldGroups = plugin.database.getStringList("users." + userName + ".oldRanks");
-
- plugin.debugmsg("groups count: " + oldGroups.size());
- if(oldGroups.size() > 0) {
- String[] groups= new String[oldGroups.size()];
- for(int i=0;i<oldGroups.size();i++) {
- groups[i] = oldGroups.get(i);
- plugin.debugmsg("Was in group: " + oldGroups.get(i) );
- }
- try{
- if(plugin.setGroups(userName, groups, true, world)){
- plugin.log.info("[AZRank] unranked user " + userName + " to group(s) " + oldGroups);
- plugin.database.set("users." + userName, null);
- plugin.save();
- } else {
- String oldGroupsS="[";
- if (oldGroups.size() > 0) {
- oldGroupsS += oldGroups.get(0); // start with the first element
- for (int i=1; i<oldGroups.size(); i++) {
- oldGroupsS += ", " + oldGroups.get(i);
- }
- }
- oldGroupsS+="]";
- plugin.log.severe("[AZRank][ERROR]F " + "Failed to restore group for "+userName+" to "+oldGroupsS+".\nYou should manualy retore player groups in permissions manager, and later in database.yml");
- }
- } catch (Exception e) {
- plugin.log.severe("[AZRank][ERROR]E " + e.getMessage());
- e.printStackTrace();
- }
-
- } else {
- plugin.log.severe("[AZRank] Failed to unrank user " + userName + "! He haven't 'oldGroups'");
- plugin.database.set("users." + userName, null);
- plugin.save();
- }
- } else {
- plugin.debugmsg("Checked " + userName + " - converting to new system...");
- String[] crGroups = plugin.permBridge.getPlayersGroups(userName, true, world);
- ConfigurationSection userSection = plugin.database.getConfigurationSection("users."+userName);
- for(String crGroup:crGroups)
- {
- userSection.set(crGroup+".from",userSection.getLong("from"));
- userSection.set(crGroup+".to",to);
- userSection.set(crGroup+".restoreGroups",userSection.getStringList("oldRanks"));
- userSection.set("from",null);
- userSection.set("to",null);
- userSection.set("oldRankss",null);
- plugin.debugmsg("Is in: " + crGroup);
- }
- plugin.save();
- plugin.debugmsg("Converted!");
- }
- }
- }
- plugin.tempranks=tempranks;
- plugin.debugmsg("temporary ranks: "+tempranks);
- }
-
- } catch(Exception e) {
- plugin.log.info("[AZRank]ERROR - " + e.getMessage());
- e.printStackTrace();
- }
- }
-
-}
View
8 src/pl/azpal/azrank/manager/AZPlayersGroup.java
@@ -1,13 +1,13 @@
-/*
- * To change this template, choose Tools | Templates
- * and open the template in the editor.
- */
+
package pl.azpal.azrank.manager;
/**
*
* @author Rutr <artuczapl at gmail.com>
*/
+
+
+
public class AZPlayersGroup {
public String playerName;
public String groupName;
View
1 src/pl/azpal/azrank/manager/ComparatorByPlayerAndTimeEnd.java
@@ -7,6 +7,7 @@
*/
public class ComparatorByPlayerAndTimeEnd implements Comparator<AZPlayersGroup>{
+ @Override
public int compare(AZPlayersGroup o1, AZPlayersGroup o2) {
int wynik = o1.playerName.compareTo(o2.playerName);
if(wynik==0)
View
809 src/pl/azpal/azrank/AZRank.java → src/pl/rutr/minecraft/azrank/AZRank.java
@@ -1,14 +1,18 @@
-package pl.azpal.azrank;
-/**
+
+package pl.rutr.minecraft.azrank;
+
+/** AZRank
*
* @author Rutr <artuczapl at gmail.com>
*/
-import pl.azpal.azrank.permissions.*;
+import java.util.logging.Logger;
+import java.util.logging.Level;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
+import java.lang.annotation.Target;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
@@ -17,13 +21,10 @@
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
-import java.util.TimeZone;
-import java.util.logging.Logger;
import net.milkbowl.vault.permission.Permission;
import org.anjocaido.groupmanager.GroupManager;
import org.bukkit.ChatColor;
-import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -33,89 +34,128 @@
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.java.JavaPlugin;
-import pl.azpal.azrank.manager.AZPlayersGroup;
-import pl.azpal.azrank.manager.ComparatorByPlayerAndTimeEnd;
+
+import org.bukkit.scheduler.BukkitTask;
+import pl.azpal.azrank.manager.*;
+import pl.rutr.minecraft.azrank.commands.*;
+import pl.rutr.minecraft.azrank.permissions.*;
+
public class AZRank extends JavaPlugin {
- protected final YamlConfiguration database = new YamlConfiguration();
- protected Cfg cfg = new Cfg(this);
+ public final YamlConfiguration database = new YamlConfiguration();
+ public final Cfg cfg = new Cfg(this);
//public static String permPlg;
//public static byte permtype=0;
- public static AZPermissionsHandler permBridge=null;
+ public /*static*/ PermissionsSysHandler permsSys;
+ private AZRankCommandExecutor commandExecutor = new AZRankCommandExecutor(this);
+
+ public final static Logger log = Logger.getLogger("Minecraft");
+ public final File dir = new File("plugins/AZRank");//location of files of plugin
+ public final File cfgFile = new File(dir, "config.yml"); //config file
+ public final File yamlDataBaseFile = new File(dir, "database.yml"); //database file
+ public final File updateFile = new File(dir, "update.jar");
- public static final Logger log = Logger.getLogger("Minecraft");
- public final File dir = new File("plugins/AZRank");
- public final File yml = new File(dir, "config.yml");
- public final File yamlDataBaseFile = new File(dir, "database.yml");
public boolean cancelE;
- protected int taskID;
- private TimeRankChecker checker;
- private int checkDelay=10*20;
+
+ //public int checkerTaskID=0;
+ private BukkitTask checkerTask;
+ public TimeRankChecker checker=new TimeRankChecker(this);
+ private BukkitTask updaterTask;
+ UpdateChecker updater;
+ //public int checkDelay=10*20;
+ // protected Thread checkerThread = new Thread(checker);
+
+ //protected CheckerCaller checkerCaller = new CheckerCaller(this);
public int tempranks=0;
//private int checkInterval=10*20;
- private static final String INFO_NODE = "azrank.info";
- private static final String RESTORE_NODE = "azrank.restore";
- private static final String LIST_NODE = "azrank.list";
- private static final String ALL_NODE = "azrank.*";
- Metrics metrics;
+
+
+ public Metrics metrics;
public List<String> dependies = new ArrayList<String>();
public boolean dloaded = false;
+
@Override
public void onEnable() {
- setupPermissions();
- if (cancelE == true) {
- return;
- }
- if (!yml.exists() || !yamlDataBaseFile.exists()) {
- firstRunSettings();
- }
- dLoad();
- checker = new TimeRankChecker(this);
- checker.run();
- taskID = getServer().getScheduler().scheduleAsyncRepeatingTask(this, checker, checkDelay, cfg.checkInterval);
-
- PluginDescriptionFile pdffile = this.getDescription();
+ if(updater==null)
+ {
+ updater=new UpdateChecker(this);
+ }
+ try {
+ getCommand("azrank").setExecutor(commandExecutor);
+ getCommand("azplayer").setExecutor(commandExecutor);
+ getCommand("azsetgroup").setExecutor(commandExecutor);
+ getCommand("azaddgroup").setExecutor(commandExecutor);
+ getCommand("azremovegroup").setExecutor(commandExecutor);
+ getCommand("azrankreload").setExecutor(commandExecutor);
+ getCommand("azranks").setExecutor(commandExecutor);
+ getCommand("azextend").setExecutor(commandExecutor);
- log.info("[AZRank] "+ pdffile.getFullName() + " is now enabled.");
- try {
- metrics = new Metrics(this);
- Metrics.Graph pp = metrics.createGraph("Permissions plugins");
- pp.addPlotter(new Metrics.Plotter(permBridge.getName()){
- public int getValue(){
- return 1;
- }
- });
- Metrics.Graph ranks = metrics.createGraph("Temporiary ranks count");
- ranks.addPlotter(new Metrics.Plotter(){
- public int getValue(){
- return tempranks;
- }
- });
- Metrics.Graph versions = metrics.createGraph("AZRank version");
- versions.addPlotter(new Metrics.Plotter(getDescription().getVersion()){
- public int getValue(){
- return 1;
- }
- });
- metrics.start();
- } catch (IOException e) {
- // Failed to submit the stats :-(
- e.printStackTrace();
- log.severe("[AZRank] unable to start metrics!");
+ } catch(NullPointerException e)
+ {
+ log.log(Level.SEVERE, "[AZRank] Error when enabling! Some commands may not work.");
+ }
+
+
+ setupPermissions();
+ if (cancelE == true) {
+ return;
+ }
+ if (!cfgFile.exists() || !yamlDataBaseFile.exists()) {
+ firstRunSettings();
+ }
+ dLoad(null);
+
+ startCheckerTask(false);
+ startUpdaterTask(false);
+
+ PluginDescriptionFile pdffile = this.getDescription();
+
+ log.log(Level.INFO, "[AZRank] {0} is now enabled.", pdffile.getFullName());
+ try {
+ metrics = new Metrics(this);
+ Metrics.Graph pp = metrics.createGraph("Permissions plugins");
+ pp.addPlotter( new Metrics.Plotter(permsSys.getName()) {
+ @Override
+ public int getValue(){
+ return 1;
+ }
+ });
+ Metrics.Graph ranks = metrics.createGraph("Temporiary ranks count");
+ ranks.addPlotter(new Metrics.Plotter() {
+ @Override
+ public int getValue(){
+ return tempranks;
+ }
+ });
+ Metrics.Graph versions = metrics.createGraph("AZRank version");
+ versions.addPlotter(new Metrics.Plotter(getDescription().getVersion()) {
+ @Override
+ public int getValue(){
+ return 1;
+ }
+ });
+ metrics.start();
+ } catch (IOException e) {
+ log.log(Level.WARNING, "[AZRank] unable to start metrics!");
+ StackTraceElement[] stackTrace = e.getStackTrace();
+ for(StackTraceElement element : stackTrace)
+ {
+ log.log(Level.SEVERE, " {0}", element.toString());
}
+ }
}
@Override
public void onDisable() {
- getServer().getScheduler().cancelTask(taskID);
+ stopCheckerTask();
PluginDescriptionFile pdffile = this.getDescription();
- log.info("[AZRank] " + pdffile.getName() + " is now disabled.");
+ log.log(Level.INFO, "[AZRank] {0} is now disabled.", pdffile.getName());
}
@@ -126,18 +166,18 @@ private void setupPermissions() {
final Plugin GMplugin = pluginManager.getPlugin("GroupManager");
if(GMplugin != null && GMplugin.isEnabled()) {
- permBridge = new AZGroupManagerAdapter(this, ((GroupManager)GMplugin).getWorldsHolder());
- log.info("[AZRank] Found " + ((GroupManager)GMplugin).getDescription().getFullName() + " (directly) and is good to go");
+ permsSys = new AZGroupManagerAdapter(this, ((GroupManager)GMplugin).getWorldsHolder());
+ log.log(Level.INFO, "[AZRank] Found {0} (directly) and is good to go", ((GroupManager)GMplugin).getDescription().getFullName());
}
else if (permissionProvider != null)
{
- permBridge = new AZVaultAdapter(this, permissionProvider.getProvider());
- log.info("[AZRank] Found Vault and " + permBridge.getName() + " and is good to go");
+ permsSys = new AZVaultAdapter(this, permissionProvider.getProvider());
+ log.log(Level.INFO, "[AZRank] Found Vault and {0} and is good to go", permsSys.getName());
}
else
{
- log.severe("[AZRank] Don't found Vault and/or Permission Plugin - Disabling!");
+ log.log(Level.INFO,"[AZRank] Don't found Vault and/or Permission Plugin - Disabling!");
this.setEnabled(false);
cancelE = true;
return;
@@ -151,7 +191,7 @@ private void firstRunSettings() {
if (!dir.exists()) {
dir.mkdir();
}
- if (!yml.exists()) {
+ if (!cfgFile.exists()) {
cfg.defaultConfig();
}
if (!yamlDataBaseFile.exists()) {
@@ -162,368 +202,26 @@ private void firstRunSettings() {
}
}
catch (Exception e) {
- log.severe("[AZRank] Failed to create config file!");
+ log.log(Level.SEVERE, "[AZRank] Failed to create config file!");
}
}
- @Override
- public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args) {
-
-
- if (cmd.getName().equalsIgnoreCase("azplayer")) {
- if(args.length > 0){
- if(args.length > 1)
- sayTooManyArgs(cs,1);
- if(hasPerm(cs, INFO_NODE))
- return infoCMD(cs,args[0]);
- else {
- sayNoPerm(cs);
- return true;
- }
- } else
- sayTooFewArgs(cs,1);
-
-
- }else if (cmd.getName().equalsIgnoreCase("azrankreload")) {
- if (args.length > 0) {
- sayTooManyArgs(cs, 0);
- }
- PluginDescriptionFile pdffile = this.getDescription();
- if (cs instanceof Player) {
- Player player = (Player)cs;
- if (hasReload(player) || (cfg.allowOpsChanges && player.isOp())) {
- if(dLoad()) { // jeżeli dobrze przeładowano
- cs.sendMessage(ChatColor.GREEN + "[AZRank] " + pdffile.getFullName() + " was succesfully reloaded");
- getServer().getScheduler().cancelTask(taskID);
- taskID = getServer().getScheduler().scheduleAsyncRepeatingTask(this, checker, checkDelay, cfg.checkInterval);
- log.info("[AZRank] " + pdffile.getFullName() + " was succesfully reloaded");
- } else { //jeżeli błąd podczas przeładowywania
- cs.sendMessage(ChatColor.GREEN + "[AZRank] " + pdffile.getFullName() + " - Error when reloading");
- }
- } else {
- cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.RED + "You do not have permission to do this!" );
- }
- } else {
- if(dLoad()) { // jeżeli dobrze przeładowano
- getServer().getScheduler().cancelTask(taskID);
- taskID = getServer().getScheduler().scheduleAsyncRepeatingTask(this, checker, checkDelay, cfg.checkInterval);
- log.info("[AZRank] " + pdffile.getFullName() + " was succesfully reloaded");
- } else { //jeżeli błąd podczas przeładowywania
- cs.sendMessage(ChatColor.GREEN + "[AZRank] " + pdffile.getFullName() + " - Error when reloading");
- }
- }
- return true;
-
-
-
- } else if (cmd.getName().equalsIgnoreCase("azsetgroup")) {
- if(args.length < 2) {
- sayTooFewArgs(cs, 2);
- return false;
- }
- long czas = -1;
- if (args.length > 2) {
- if(args.length > 4)
- sayTooManyArgs(cs, 4);
- try {
- //czas = Util.parseDateDiff(args[args.length-1], true);
- czas = Util.parseTimeDiffInMillis(args[args.length-1]);
- }
- catch (Exception e) {
- cs.sendMessage(ChatColor.RED + "[AZRank] Error - " + e.getMessage());
- e.printStackTrace();
- return false;
- }
- }
- if(canSetRank(cs, args[0],args[1])) {
- String world;
- if(cs instanceof Player) {
- world=((Player)cs).getLocation().getWorld().getName();
- } else {
- world=getServer().getWorlds().get(0).getName();
- }
-
- if(!SetRank(cs, args[0], new String[]{ args[1]}, czas,args[args.length-2].equalsIgnoreCase("-s"),true, world))
- {
- cs.sendMessage(ChatColor.GREEN + "[AZRank]"+ChatColor.RED +"An error occurred when tried to set group!");
- debugmsg("Error when tried to set group "+args[0] + " to " + args[1] + " time: "+czas/1000+"seconds");
- }
- else
- return true;
- } //else
- // sayNoPerm(cs);
-
- }else if (cmd.getName().equalsIgnoreCase("azaddgroup"))
- {
- if(args.length<2)
- {
- sayTooFewArgs(cs,2);
- return false;
- }
- long czas=-1;
- if(args.length>2)
- {
- if(args.length > 4)
- sayTooManyArgs(cs, 4);
- try {
- czas = Util.parseTimeDiffInMillis(args[args.length-1]);
- }
- catch (Exception e) {
- cs.sendMessage(ChatColor.RED + "[AZRank] Error - " + e.getMessage());
- e.printStackTrace();
- return false;
- }
- }
- if(canSetRank(cs, args[0],args[1]))
- {
- String world;
- if(cs instanceof Player) {
- world=((Player)cs).getLocation().getWorld().getName();
- } else {
- world=getServer().getWorlds().get(0).getName();
- }
-
- if(!playerAddTmpGroup(cs, args[0], new String[]{ args[1]}, czas,args[args.length-2].equalsIgnoreCase("-s"), true, world))
- {
- cs.sendMessage(ChatColor.GREEN + "[AZRank]"+ChatColor.RED +"An error occurred when tried to add group!");
- debugmsg("Error when tried to add group "+args[0] + " to " + args[1] + " time: "+czas);
- }
- else
- return true;
- }
-
-
- }
- else if (cmd.getName().equalsIgnoreCase("azremovegroup"))
- {
- if(args.length==2){
- if(canSetRank(cs, args[0], args[1]))
- {
- String world;
- if(cs instanceof Player) {
- world=((Player)cs).getLocation().getWorld().getName();
- } else {
- world=getServer().getWorlds().get(0).getName();
- }
- if(permBridge.playerRemoveGroups(args[0],new String[] {args[1]} , true, world))
- {
- if(database.getConfigurationSection("users."+args[0]+"."+args[1])!=null)
- {
- database.set("users."+args[0]+"."+args[1],null);
- }
- cs.sendMessage(ChatColor.GREEN + "[AZRank]"+ChatColor.AQUA +" Successful removed "+args[0] + " from " + args[1] + "!");
- debugmsg("successful removed group "+args[0] + " from " + args[1]);
- return true;
- } else
- {
- cs.sendMessage(ChatColor.GREEN + "[AZRank]"+ChatColor.RED +"An error occurred when tried to remove group!");
- debugmsg("Error when tried to remove group "+args[0] + " from " + args[1]);
- return false;
- }
-
- }else
- {
- sayNoPerm(cs);
- return false;
- }
- }
- else if(args.length<2){
- sayTooFewArgs(cs,2);
- return false;
- }
- else if(args.length>2){
- sayTooManyArgs(cs,2);
- return false;
- }
-
-
-
- }
- else if (cmd.getName().equalsIgnoreCase("azranks"))
- {
- if(cs instanceof Player)
- {
- if(! hasPerm(cs, LIST_NODE))
- {
- sayNoPerm(cs);
- return false;
- }
- //wypisywanie jezeli gracz
- if(args.length>0)
- {
- try {
- int page = Integer.parseInt(args[0]);
- if(page<1) throw new NumberFormatException("Number must be positive!");
- wypiszGraczy(cs,10,page);
- return true;
- } catch(NumberFormatException e) {
- cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.RED + "Error! Invalid page number!" + e.getMessage());
- return false;
- }
- } else {
- wypiszGraczy(cs,10,1);
- return true;
- }
- } else
- { //wypisywanie jeżeli konsola
- wypiszGraczy(cs,0,0);
- return true;
- }
-
- }else if (cmd.getName().equalsIgnoreCase("azextend"))
- {
- //TODO: extension all temp groups time
- if(args.length != 3)
- {
- if(args.length < 3)
- sayTooFewArgs(cs, 3);
- else
- sayTooManyArgs(cs, 3);
- return false;
- }
- long interval;
- try {
- interval = Util.parseTimeDiffInMillis(args[args.length-1]);
- }
- catch (Exception e) {
- cs.sendMessage(ChatColor.RED + "[AZRank] Invalid time format - " + e.getMessage());
- e.printStackTrace();
- return false;
- }
- if(canSetRank(cs, args[0], args[1]))
- {
- ConfigurationSection groupSection = database.getConfigurationSection("users."+args[0]+"."+args[1]);
- if(groupSection==null)
- {
- cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.RED + "Player isnt in that group temporary");
- return false;
- }
- long to=groupSection.getLong("to");
- if(to>0)
- {
- groupSection.set("to",to + interval);
- save(cs);
- cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.AQUA + "Successful prolonged duration "+args[0]+ " in "+args[1]);
- debugmsg("Successful prolonged duration "+args[0]+ " in "+args[1]);
- return true;
- } else
- {
- cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.RED + "Invalid end time for "+args[0]+ " in "+args[1]+"! Deleting!");
- database.set("users."+args[0]+"."+args[1], null);
- save(cs);
- debugmsg("Invalid end time for "+args[0]+ " in "+args[1]+"! Deleted!");
- return false;
- }
-
-
- }
- }
-
-
- /*
-
- } else if (cmd.getName().equalsIgnoreCase("restoregroup")) {
- if(cs instanceof Player) {
- if(!((Player)cs).hasPermission(RESTORE_NODE)) {
- sayNoPerm(cs);
- return true;
- }
- }
- if(args.length!=1)
- return false;
- ConfigurationSection userSection= database.getConfigurationSection("users."+args[0]);
- if(userSection==null) {
- cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.RED + "Error! User arent having temporiary group!" );
- return true;
- } else {
- List<String> oldGroups = database.getStringList("users." + args[0] + ".oldRanks");
- debugmsg("groups count: " + oldGroups.size());
- if(oldGroups.size() > 0) {
- String[] groups= new String[oldGroups.size()];
- for(int i=0;i<oldGroups.size();i++) {
- groups[i] = oldGroups.get(i);
- debugmsg("Was in group: " + oldGroups.get(i) );
- }
- try{
- setGroups(args[0], groups);
- } catch (Exception e) {
- log.severe("[AZRank][ERROR]" + e.getMessage());
- }
- log.info("[AZRank] unranked user " + args[0] + " to group(s): " + oldGroups);
- cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.AQUA + "Unranked user " + args[0] + " to group(s): " + oldGroups);
- database.set("users." + args[0], null);
- save();
- } else {
- log.severe("[AZRank] Failed to unrank user " + args[0] + "! He haven't 'oldGroups'");
- cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.AQUA + "Failed to unrank user " + args[0] + "! He haven't 'oldGroups'");
- database.set("users." + args[0], null);
- save();
- }
- }
-
- return true;
- } else if (cmd.getName().equalsIgnoreCase("azranks")) {
- if(cs instanceof Player) {
- if(! ((Player)cs).hasPermission(LIST_NODE) && !((Player)cs).hasPermission("azrank.*")) {
- sayNoPerm(cs);
- return true;
- }
- //wypisywanie jezlie gracz
- if(args.length>0) {
- try {
- int page = Integer.parseInt(args[0]);
- wypiszGraczy(cs,10,page);
- } catch(NumberFormatException e) {
- cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.RED + "Error! Invalid page number!");
- return false;
- }
- } else {
- wypiszGraczy(cs,10,1);
- }
- } else {
- //wypisywanie jeżeli konsola
- ConfigurationSection usersSection = database.getConfigurationSection("users");
- if(usersSection!=null){
- Iterator<String> users = usersSection.getKeys(false).iterator();
- cs.sendMessage("Temporiary ranks: <user>[<currentGroup>] to: <to>, next will by: <group>");
-
- for(int i=0;users.hasNext();i++){
- String user = users.next();
- String groups=permBridge.getPlayersGroupsAsString(user);
- long to = database.getLong("users." + user + ".to");
- SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
- java.util.Date toDate = new java.util.Date(to);
- List<String> oldGroups = database.getStringList("users." + user + ".oldRanks");
- cs.sendMessage(user + groups + " to: " + dateformat.format(toDate) + ", next will by: " + oldGroups);
-
- }
- } else {
- cs.sendMessage("no users" );
-
- }
-
- }
- return true;
- } else if (cmd.getName().equalsIgnoreCase("azranks")) {
- cs.sendMessage("This command is not jet implemented!");
- }*/
- return false;
- }
+
/**
* Say "You do not have permission to do this!"
* @param cs CommandSender to which is send message
*/
public void sayNoPerm(CommandSender cs){
cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.RED + "You do not have permission to do this!" );
}
- @Deprecated
- public void sayBadArgs(CommandSender cs){
- cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.RED + "Bad amount of args!" );
- }
- @Deprecated
- public void sayBadArgs(CommandSender cs,int a){
- cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.RED + "Bad amount of args! Expected "+ a );
- }
+ @Deprecated
+ public void sayBadArgs(CommandSender cs){
+ cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.RED + "Bad amount of args!" );
+ }
+ @Deprecated
+ public void sayBadArgs(CommandSender cs,int a){
+ cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.RED + "Bad amount of args! Expected "+ a );
+ }
/**
* Say "Too many arguments!"
* @param cs CommandSender to which is send message
@@ -532,18 +230,28 @@ public void sayTooManyArgs(CommandSender cs){
cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.RED + "Too many arguments!");
}
/**
- * Say "Too many arguments!"
+ * Say "Too many arguments! Expected maximum <tt>a</tt>"
* @param cs CommandSender to which is send message
- * @param a maximum amount of parameters thad expected
+ * @param a maximum amount of parameters that expected
*/
public void sayTooManyArgs(CommandSender cs,int a){
cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.RED + "Too many arguments! Expected maximum " + a );
}
+ /**
+ * Say "Too few arguments!"
+ * @param cs CommandSender to which is send message
+ */
public void sayTooFewArgs(CommandSender cs){
cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.RED + "Too few arguments!");
}
+ /**
+ * Say "Too few arguments! Expected minimum <tt>a</tt>"
+ * @param cs CommandSender to which is send message
+ * @param a minimum amount of parameters that expected
+ */
public void sayTooFewArgs(CommandSender cs,int a){
cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.RED + "Too few arguments! Expected minimum " + a );
+
}
//TODO: przenieść do API / move to API
@@ -552,8 +260,12 @@ public void sayTooFewArgs(CommandSender cs,int a){
* @param cs Messages output
* @param Player player to change his groups
* @param groups new groups to set to the player
- * @param timeDiff the duration of give groups
+ * @param timeDiff the duration of give groups in milliseconds
* @param set if true, time will be set, else if already player is in only give groups, time will be prolonged
+ * @param globaly if true, plugin try set rank globaly
+ * @param worldName the world name, in witch rank have to be seted if not globaly, when Permissions plugin not support globaly changes or <s>in config globaly changes are disabled.
+ * @return true if rank has been seted
+ * @deprecated this will be moved to API
*/
@Deprecated
public boolean SetRank(CommandSender cs, String Player, String[] groups, long timeDiff ,boolean set, boolean globaly, String worldName){
@@ -565,7 +277,7 @@ public boolean SetRank(CommandSender cs, String Player, String[] groups, long ti
save(cs);
}
- if(permBridge.setPlayersGroups(Player, groups, globaly, worldName))
+ if(permsSys.setPlayersGroups(Player, groups, worldName, globaly))
{
debugmsg("Seted group "+ Player + " to "+Util.tableToString(groups) + " permanently.");
cs.sendMessage(ChatColor.AQUA + "[AZRank]"+ChatColor.AQUA + " Successful moved "+ Player + " to " + Util.tableToString(groups) + " forever!");
@@ -574,17 +286,18 @@ public boolean SetRank(CommandSender cs, String Player, String[] groups, long ti
debugmsg("Permissions plugin dont Set group "+ Player + " to "+Util.tableToString(groups) + " (permanently)");
return false;
}
- else //tymczasowa
+ else //temporary
{
- String[] oldGroups = permBridge.getPlayersGroups(Player, globaly, worldName);
+ String[] oldGroups = permsSys.getPlayersGroups(Player, worldName, globaly);
if(Arrays.equals(groups, oldGroups)) //jeżeli jest już w tych grupach
{
//TODO: multi check
// debugmsg
int i=0;
java.util.Date now = new java.util.Date();
ConfigurationSection groupSection = database.getConfigurationSection("users."+Player+"."+groups[i]);
- long timeTo=groupSection.getLong("to");
+
+ long timeTo = (groupSection!=null ? groupSection.getLong("to") : 0);
if(groupSection!=null && !set && timeTo>0) { //has temporiary and without -s flag (adding time)
//TODO: add adding time
timeTo += timeDiff;
@@ -628,7 +341,7 @@ public boolean SetRank(CommandSender cs, String Player, String[] groups, long ti
restoreGroups.add(oldGroup);
}
debugmsg("Generated list of groups to restore: "+ Util.tableToString(restoreGroups.toArray(new String[]{})));
- if(permBridge.setPlayersGroups(Player, groups, globaly, worldName))
+ if(permsSys.setPlayersGroups(Player, groups, worldName, globaly))
{ //jeżeli pomyślnie ustawiono nowe grupy
//TODO: obsługe wyjątków
database.set("users." + Player , null);
@@ -653,42 +366,9 @@ public boolean SetRank(CommandSender cs, String Player, String[] groups, long ti
}
}
}
- //return false;
+
}
- /*public void SetRank(CommandSender cs, String Name, String Group, long time) {
- ConfigurationSection usersSection = database.getConfigurationSection("users."+Name);
- if(time <= 0L) {
- if(usersSection!=null){
- database.set("users." + Name, null);
- }
- } else {
- java.util.Date now = new java.util.Date();
- if(usersSection==null)
- database.set("users." + Name + ".oldRanks", getGroups(Name));
- database.set("users." + Name + ".from", now.getTime());
- database.set("users." + Name + ".to", time );
- save(cs);
-
- }
- if(setGroup(Name,Group)){
- String message = cfg.message;
- message = message.replace("+player", Name);
- message = message.replace("+group", Group);
- if(time>0) {
- message = message.replace("+time", cfg.aWhile);
- } else {
- message = message.replace("+time", cfg.ever);
- }
- message = message.replace("&", "�");
- if (cfg.broadcastRankChange) {
- getServer().broadcastMessage(ChatColor.YELLOW + "[AZRank] " + ChatColor.BLUE + message);
- } else {
- cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.BLUE + message);
- }
- } else {
- cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.RED + "Error when setting group!");
- }
- }*/
+
public boolean playerAddTmpGroup(CommandSender cs, String Player, String[] groups, long timeDiff, boolean set, boolean globaly, String worldName) {
ConfigurationSection usersSection = database.getConfigurationSection("users."+Player);
if(timeDiff <= 0L) {
@@ -697,7 +377,7 @@ public boolean playerAddTmpGroup(CommandSender cs, String Player, String[] group
usersSection.set(group,null);
}
save(cs);
- if(permBridge.playerAddGroups(Player, groups, globaly, worldName))
+ if(permsSys.playerAddGroups(Player, groups, worldName, globaly))
{
debugmsg("Added "+ Player + " to "+Util.tableToString(groups) + " permanently.");
cs.sendMessage(ChatColor.AQUA + "[AZRank]"+ChatColor.AQUA + " Successful add "+ Player + " to " + Util.tableToString(groups) + " forever!");
@@ -708,7 +388,7 @@ public boolean playerAddTmpGroup(CommandSender cs, String Player, String[] group
}
else //tymczasowa
{
- String[] oldGroups = permBridge.getPlayersGroups(Player, globaly, worldName);
+ String[] oldGroups = permsSys.getPlayersGroups(Player, worldName, globaly);
boolean czy=false;
boolean znaleziono;
if(groups.length>0)
@@ -735,8 +415,9 @@ public boolean playerAddTmpGroup(CommandSender cs, String Player, String[] group
ConfigurationSection groupSection = database.getConfigurationSection("users."+Player+"."+groups[i]);
java.util.Date now = new java.util.Date();
long timeTo=groupSection.getLong("to");
-
- if(groupSection!=null && !set && timeTo>0) { //has temporiary and without -s flag (adding time)
+
+
+ if(!set && timeTo>0) { //has temporiary and without -s flag (adding time)
//TODO: add adding time
timeTo += timeDiff;
//time = Util parse time + database.get
@@ -759,7 +440,7 @@ public boolean playerAddTmpGroup(CommandSender cs, String Player, String[] group
{
//TODO: debug msgs to this:
//TODO: dla każdej grupy osobno sprawdzanie czy w niej już jest!
- if(permBridge.playerAddGroups(Player, groups, globaly, worldName))
+ if(permsSys.playerAddGroups(Player, groups, worldName, globaly))
{ //jeżeli pomyślnie ustawiono nowe grupy
//TODO: obsługe wyjątków
java.util.Date now = new java.util.Date();
@@ -790,24 +471,40 @@ public void save() {
database.save(yamlDataBaseFile);
database.load(yamlDataBaseFile);
} catch (IOException e) {
- log.info(ChatColor.RED + "[AZRank] I/O ERROR - unable to save database");
- e.printStackTrace();
+ log.log(Level.SEVERE, "[AZRank] I/O ERROR - unable to save database");
+ StackTraceElement[] stackTrace = e.getStackTrace();
+ for(StackTraceElement element : stackTrace)
+ {
+ log.log(Level.SEVERE, " {0}", element.toString());
+ }
} catch (Exception e) {
- log.info(ChatColor.RED + "[AZRank] OTHER ERROR - unable to save database");
- e.printStackTrace();
+ log.log(Level.SEVERE, "[AZRank] OTHER ERROR - unable to save database");
+ StackTraceElement[] stackTrace = e.getStackTrace();
+ for(StackTraceElement element : stackTrace)
+ {
+ log.log(Level.SEVERE, " {0}", element.toString());
+ }
}
}
public void save(CommandSender cs) {
try {
database.save(yamlDataBaseFile);
database.load(yamlDataBaseFile);
} catch (IOException e) {
- log.info(ChatColor.RED + "[AZRank] I/O ERROR - unable to save database");
+ log.log(Level.SEVERE, "[AZRank] I/O ERROR - unable to save database");
cs.sendMessage(ChatColor.RED + "[AZRank] I/O ERROR - unable to save database");
- e.printStackTrace();
+ StackTraceElement[] stackTrace = e.getStackTrace();
+ for(StackTraceElement element : stackTrace)
+ {
+ log.log(Level.SEVERE, " {0}", element.toString());
+ }
} catch (Exception e) {
- log.info(ChatColor.RED + "[AZRank] OTHER ERROR - unable to save database");
- e.printStackTrace();
+ log.log(Level.SEVERE, "[AZRank] OTHER ERROR - unable to save database");
+ StackTraceElement[] stackTrace = e.getStackTrace();
+ for(StackTraceElement element : stackTrace)
+ {
+ log.log(Level.SEVERE, " {0}", element.toString());
+ }
}
}
@@ -835,7 +532,7 @@ public boolean hasSetRank(CommandSender cs, String group) {
} else return true;
} catch(Exception e) {
- log.severe("[AZRank][ERROR]" + e.getMessage());
+ log.log(Level.SEVERE, "[AZRank][ERROR]{0}", e.getMessage());
return false;
}
}
@@ -846,7 +543,7 @@ public boolean hasReload(Player player) {
return player.hasPermission(node);
} catch(Exception e) {
- log.severe("[AZRank][ERROR]" + e.getMessage());
+ log.log(Level.SEVERE, "[AZRank][ERROR]{0}", e.getMessage());
return false;
}
@@ -855,10 +552,14 @@ public boolean hasReload(Player player) {
@Deprecated
public boolean setGroups(String name, String[] oldGroups, boolean globaly, String worldName) {
try {
- return permBridge.setPlayersGroups(name, oldGroups, globaly, worldName);
+ return permsSys.setPlayersGroups(name, oldGroups, worldName, globaly);
} catch(Exception e) {
- log.severe("[AZRank][Exception]when setting group|" + e.getMessage());
- e.printStackTrace();
+ log.log(Level.SEVERE, "[AZRank][Exception]when setting group|{0}", e.getMessage());
+ StackTraceElement[] stackTrace = e.getStackTrace();
+ for(StackTraceElement element : stackTrace)
+ {
+ log.log(Level.SEVERE, " {0}", element.toString());
+ }
return false;
}
}
@@ -871,29 +572,99 @@ public boolean setGroup(String name, String group, boolean globaly, String world
@Deprecated
public String[] getGroups(String name, boolean globaly, String worldName){
try {
- return permBridge.getPlayersGroups(name, globaly, worldName);
+ return permsSys.getPlayersGroups(name, worldName, globaly);
} catch(Exception e) {
- log.severe("[AZRank][ERROR]" + e.getMessage());
+ log.log(Level.SEVERE, "[AZRank][ERROR]{0}", e.getMessage());
return null;
}
}
+ @Deprecated
public boolean dLoad() {
try {
- cfg.checkConfig();
- cfg.loadConfig();
- database.load(yamlDataBaseFile);
- return true;
+ cfg.checkConfig();
+ cfg.loadConfig();
+ /* if(checker.working)
+ {
+ checker.setToDataReload(null);
+ return true;
+ }*/
+ if(checkerTask!=null && getServer().getScheduler().isCurrentlyRunning(checkerTask.getTaskId()))
+ {
+ checker.setToDataReload(null);
+ return true;
+ }
+ else
+ {
+ database.load(yamlDataBaseFile);
+ return true;
+ }
+ }
+ catch (Exception e)
+ {
+ log.log(Level.SEVERE, "[AZRank][ERROR]{0}", new Object[]{ e.getMessage()});
+ StackTraceElement[] stackTrace = e.getStackTrace();
+ for(StackTraceElement element : stackTrace)
+ {
+ log.log(Level.SEVERE, " {0}", element.toString());
+ }
+ return false;
+ }
+ }
+
+ public boolean dLoad(CommandSender cs) {
+ try {
+ cfg.checkConfig();
+ cfg.loadConfig();
+ /*if(checker.working)
+ {
+ checker.setToDataReload(cs);
+ return true;
+ }*/
+ if(checkerTask!=null && getServer().getScheduler().isCurrentlyRunning(checkerTask.getTaskId()))
+ {
+ checker.setToDataReload(null);
+ return true;
+ }
+ else
+ {
+ database.load(yamlDataBaseFile);
+ return true;
+ }
} catch (Exception e) {
- log.info(ChatColor.RED + "[AZRank][ERROR]" + e.getMessage());
- e.printStackTrace();
- return false;
+ log.log(Level.SEVERE, "[AZRank][ERROR]{0}", new Object[]{ e.getMessage()});
+ StackTraceElement[] stackTrace = e.getStackTrace();
+ for(StackTraceElement element : stackTrace)
+ {
+ log.log(Level.SEVERE, " {0}", element.toString());
+ }
+ return false;
+ }
+ }
+ public boolean dataReload(CommandSender cs) {
+ try {
+ database.load(yamlDataBaseFile);
+ if(cs!=null)
+ {
+ cs.sendMessage("[AZRank] Successful reloaded data!");
+ }
+ return true;
+ } catch (Exception e) {
+ log.log(Level.SEVERE, "[AZRank][ERROR]{0}", new Object[]{e.getMessage()});
+ StackTraceElement[] stackTrace = e.getStackTrace();
+ for(StackTraceElement element : stackTrace)
+ {
+ log.log(Level.SEVERE, " {0}", element.toString());
+ }
+ return false;
}
}
public void debugmsg(String msg){
- if(cfg.logEverything)
- log.info(ChatColor.RED + "[AZRank][DEBUG]" + msg);
+ if(cfg.logEverything)
+ {
+ log.log(Level.INFO, "[AZRank][DEBUG]{0}", new Object[]{ msg});
+ }
}
@@ -988,10 +759,10 @@ public void wypiszGraczy(CommandSender cs, int count, int page) {
return user + ChatColor.RED +groups + ChatColor.WHITE + " to: " + ChatColor.YELLOW + dateformat.format(toDate) + ChatColor.WHITE + ", next " + ChatColor.BLUE + oldGroups;
}*/
- private boolean hasPerm(CommandSender cs, String node) {
+ public boolean hasPerm(CommandSender cs, String node) {
if(cs instanceof Player){
Player player = (Player)cs;
- if(player.hasPermission(node) || player.hasPermission(ALL_NODE) || (player.isOp() && cfg.allowOpsChanges))
+ if(player.hasPermission(node) || player.hasPermission(AZRankPermissions.ALL_NODE) || (player.isOp() && cfg.allowOpsChanges))
return true;
else return false;
} else
@@ -1007,11 +778,11 @@ public boolean infoCMD(CommandSender cs, String playername) {
}
ConfigurationSection userSection = database.getConfigurationSection("users."+playername);
- String[] groups = permBridge.getPlayersGroups(playername, true, world);
+ String[] groups = permsSys.getPlayersGroups(playername, world, true);
if(userSection==null) {
cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.AQUA + "User "+playername+ " is in " + Util.tableToString(groups) + " forever");
} else {
- String msg="";//=ChatColor.GREEN + "[AZRank] " + ChatColor.AQUA + "User "+playername+ " is in: ";
+ String msg="";
long to;
SimpleDateFormat dateformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
java.util.Date toDate;
@@ -1057,8 +828,48 @@ public boolean infoCMD(CommandSender cs, String playername) {
}
return true;
}
+ /**
+ * Run task repeatively to check rank.
+ * @return true if task has'n be yet runed, but now.
+ */
+ private boolean startCheckerTask(boolean delayed) {
+ if(checkerTask==null || !getServer().getScheduler().isQueued(checkerTask.getTaskId()))
+ {
+ checkerTask = getServer().getScheduler().runTaskTimerAsynchronously(this, checker, delayed ? cfg.checkInterval : 0, cfg.checkInterval);
+ return true;
+ }
+ return false;
+ }
+ /**
+ * Stop task checking rank.
+ * @return true if task has be already runed and stoped now.
+ */
+ private boolean stopCheckerTask() {
+ if(checkerTask!=null && getServer().getScheduler().isQueued(checkerTask.getTaskId()))
+ {
+ checkerTask.cancel();
+ return true;
+ }
+ return false;
+ }
-
+ private boolean startUpdaterTask(boolean delayed) {
+ if(updaterTask==null || !getServer().getScheduler().isQueued(updaterTask.getTaskId()))
+ {
+ updaterTask = getServer().getScheduler().runTaskTimerAsynchronously(this, updater, delayed ? cfg.updateInterval : 0, cfg.updateInterval);
+ return true;
+ }
+ return false;
+ }
+
+ private boolean stopUpdaterTask() {
+ if(updaterTask!=null && getServer().getScheduler().isQueued(updaterTask.getTaskId()))
+ {
+ updaterTask.cancel();
+ return true;
+ }
+ return false;
+ }
}
View
22 src/pl/azpal/azrank/Cfg.java → src/pl/rutr/minecraft/azrank/Cfg.java
@@ -1,4 +1,4 @@
-package pl.azpal.azrank;
+package pl.rutr.minecraft.azrank;
import java.io.FileNotFoundException;
import java.io.IOException;
@@ -8,26 +8,30 @@
import org.bukkit.configuration.file.YamlConfiguration;
public class Cfg {
+ public static final long MAX_CHECKING_INTERVAL=345600000L;//4 Days
+
private AZRank plugin;
protected final YamlConfiguration config = new YamlConfiguration();
- public String message = "+player is now a(n) +group for+time";
- public String aWhile = " a while";
- public String ever = "ever";
+ public String message = "+player is now a(n) +group +time";
+ public String aWhile = "for a while";
+ public String ever = "forever";
public boolean broadcastRankChange = true;
public boolean allowOpsChanges = true;
public boolean logEverything = false;
public int checkInterval=10*20;
+ public int updateInterval=12*60*60*20;
+
public TimeZone timeZone = TimeZone.getDefault();
- protected Cfg(AZRank plugin) {
+ protected Cfg(AZRank plugin) {
this.plugin = plugin;
}
@SuppressWarnings("CallToThreadDumpStack")
protected boolean loadConfig() {
try {
- config.load(plugin.yml);
+ config.load(plugin.cfgFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
return false;
@@ -67,7 +71,7 @@ protected void defaultConfig() {
config.set("checkInterval", checkInterval/20);
try {
- config.save(plugin.yml);
+ config.save(plugin.cfgFile);
} catch (IOException e) {
e.printStackTrace();
}
@@ -76,7 +80,7 @@ protected void defaultConfig() {
protected void checkConfig() {
plugin.debugmsg("Checking CFG");
try {
- config.load(plugin.yml);
+ config.load(plugin.cfgFile);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
@@ -122,7 +126,7 @@ else if (config.getInt("checkInterval")<1) {
if (hasChanged) {
//plugin.logIt("the config has been updated :D");
try {
- config.save(plugin.yml);
+ config.save(plugin.cfgFile);
} catch (IOException e) {
e.printStackTrace();
}
View
2 src/pl/azpal/azrank/Metrics.java → src/pl/rutr/minecraft/azrank/Metrics.java
@@ -1,4 +1,4 @@
-package pl.azpal.azrank;
+package pl.rutr.minecraft.azrank;
/*
* Copyright 2011 Tyler Blair. All rights reserved.
*
View
194 src/pl/rutr/minecraft/azrank/TimeRankChecker.java
@@ -0,0 +1,194 @@
+package pl.rutr.minecraft.azrank;
+
+import java.util.logging.Level;
+import java.util.Calendar;
+import java.util.List;
+import java.util.Set;
+import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.ConfigurationSection;
+
+
+
+
+public class TimeRankChecker implements Runnable {
+ private AZRank plugin;
+ public boolean working=false;
+ private boolean toReload=false;
+
+ private CommandSender cs;
+
+ public TimeRankChecker(AZRank origin) {
+ this.plugin = origin;
+ }
+ @Override
+ public void run()
+ {
+ if(!working)
+ {
+ working=true;
+
+ try {
+ plugin.debugmsg("Checking Time Ranks");
+ long now = Calendar.getInstance().getTimeInMillis();
+ //GregorianCalendar
+ ConfigurationSection usersSection = plugin.database.getConfigurationSection("users");
+
+ if (usersSection != null) {
+ Set<String> usersNames = usersSection.getKeys(false);
+
+ int tempranks=0;
+ for (String userName : usersNames)
+ {
+ plugin.debugmsg("Checking user: " + userName);
+
+ long to = plugin.database.getLong("users." + userName + ".to");
+ if(to == 0)
+ { //version >= 1.3.0
+ //TODO: usuwanie jak nie ma .to
+ ConfigurationSection userSection = plugin.database.getConfigurationSection("users."+userName);
+ Set<String> groups = userSection.getKeys(false);
+
+ if(groups.size()>0){
+ for(String group:groups)
+ {
+ tempranks++;
+ to = plugin.database.getLong("users." + userName + "."+group+".to");
+ if(to < now)
+ {
+ List<String> restoreGroups = userSection.getStringList(group+".restoreGroups");
+ String world = userSection.getString(group+".world");
+ if((world == null) || (world.equalsIgnoreCase("")))
+ {
+ world = plugin.getServer().getWorlds().get(0).getName();
+ }
+
+ if(restoreGroups!=null)
+ {
+ plugin.permsSys.playerAddGroups(userName,restoreGroups.toArray(new String[]{}), world, true);
+ for(String rGroup:restoreGroups)//usuwanie danych o grupach które mają zostać przywrócone.
+ {
+ userSection.set(rGroup,null);
+ }
+ }
+ plugin.permsSys.playerRemoveGroups(userName,new String[]{group}, world, true);
+ plugin.database.set("users." + userName + "."+group,null);
+ plugin.save();
+ }
+ }
+ } else {
+
+ plugin.debugmsg(userName + " dont have any groups - deleting!");
+
+ usersSection.set(userName, null);
+ }
+
+ }
+ else {//capability with 1.2.5 and older versions
+ String world = plugin.getServer().getWorlds().get(0).getName();
+ if(to < now) {
+ List<String> oldGroups = plugin.database.getStringList("users." + userName + ".oldRanks");
+
+ plugin.debugmsg("groups count: " + oldGroups.size());
+
+ if(oldGroups.size() > 0) {
+ String[] groups= new String[oldGroups.size()];
+ for(int i=0;i<oldGroups.size();i++) {
+ groups[i] = oldGroups.get(i);
+
+ plugin.debugmsg("Was in group: " + oldGroups.get(i) );
+
+ }
+ try{
+ if(plugin.setGroups(userName, groups, true, world)){
+ AZRank.log.log(Level.INFO, "[AZRank] unranked user {0} to group(s) {1}", new Object[]{userName, oldGroups});
+ plugin.database.set("users." + userName, null);
+ plugin.save();
+ } else {
+ String oldGroupsS="[";
+ if (oldGroups.size() > 0) {
+ oldGroupsS += oldGroups.get(0); // start with the first element
+ for (int i=1; i<oldGroups.size(); i++) {
+ oldGroupsS += ", " + oldGroups.get(i);
+ }
+ }
+ oldGroupsS+="]";
+ plugin.log.severe("[AZRank][ERROR]F " + "Failed to restore group for "+userName+" to "+oldGroupsS+".\nYou should manualy retore player groups in permissions manager, and later in database.yml");
+ }
+ } catch (Exception e) {
+ plugin.log.severe("[AZRank][ERROR]E " + e.getMessage());
+ e.printStackTrace();
+ }
+
+ } else {
+ plugin.log.severe("[AZRank] Failed to unrank user " + userName + "! He haven't 'oldGroups'");
+ plugin.database.set("users." + userName, null);
+ plugin.save();
+ }
+ } else {
+ plugin.debugmsg("Checked " + userName + " - converting to new system...");
+ String[] crGroups = plugin.permsSys.getPlayersGroups(userName, world, true);
+ ConfigurationSection userSection = plugin.database.getConfigurationSection("users."+userName);
+ for(String crGroup:crGroups)
+ {
+ userSection.set(crGroup+".from",userSection.getLong("from"));
+ userSection.set(crGroup+".to",to);
+ userSection.set(crGroup+".restoreGroups",userSection.getStringList("oldRanks"));
+ userSection.set("from",null);
+ userSection.set("to",null);
+ userSection.set("oldRankss",null);
+ plugin.debugmsg("Is in: " + crGroup);
+ }
+ plugin.save();
+ plugin.debugmsg("Converted!");
+ }
+ }
+ }
+ if(usersNames.size()<=0)
+ {
+ plugin.debugmsg("no users!");
+ }
+ else
+ {
+ plugin.debugmsg("checked user: " + usersNames.size() + "!");
+ }
+ plugin.tempranks=tempranks;
+
+ plugin.debugmsg("temporary ranks: "+tempranks);
+
+
+ }
+
+ } catch(Exception e) {
+ plugin.log.severe("[AZRank]ERROR - " + e.getMessage());
+ e.printStackTrace();
+
+ }
+ if(toReload)
+ {
+ if(plugin.dataReload(cs))
+ {
+ toReload=false;
+ }
+ }
+ working=false;
+
+ }
+ else
+ {
+ plugin.debugmsg("[TmpRankChecker] Still checking! new check canceled!");
+ }
+
+ }
+
+ public void setToDataReload(CommandSender cs)
+ {
+ this.toReload=true;
+ this.cs=cs;
+ }
+
+ public boolean isToDataReload()
+ {
+ return toReload;
+ }
+
+}
View
287 src/pl/rutr/minecraft/azrank/UpdateChecker.java
@@ -0,0 +1,287 @@
+/*
+ * To change this template, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package pl.rutr.minecraft.azrank;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.OutputStream;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.net.URLConnection;
+import java.net.URLEncoder;
+import java.util.Calendar;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.bukkit.Server;
+import pl.rutr.minecraft.azrank.AZRank;
+
+/**
+ *
+ * @author Rutr <artuczapl at gmail.com>
+ */
+public class UpdateChecker implements Runnable {
+ private AZRank azrank;
+ private boolean working=false;
+ private boolean updating=false;
+ private static String userAgent;
+
+ UpdateChecker(AZRank plugin)
+ {
+ azrank=plugin;
+ Server server = azrank.getServer();
+ if(server!=null){
+ userAgent="CraftBukkit/" +
+ azrank.getServer().getBukkitVersion() +
+ " AZRank/"+azrank.getDescription().getVersion() +
+ " (;;"+System.getProperty("os.name") +
+ "/" + System.getProperty("os.version") +
+ "/" + System.getProperty("os.arch") +
+ ") Java/"+System.getProperty("java.version");
+ } else
+ {
+ AZRank.log.severe("[AZRank] Error 102");
+ userAgent = "Java"+System.getProperty("java.version");
+ }
+
+ }
+
+ @Override
+ public void run() {
+ if(!working)
+ {
+ working=true;
+
+ String verStr = azrank.getDescription().getVersion();
+ azrank.debugmsg("Checkign updates... for version: " + verStr);
+ String[] ver = verStr.split("\\.");
+ if(ver.length>0)
+ {
+ String[] letters = {"a","b","c","d"};
+ try {
+ String version2="";
+ for(int i = 0; i < (ver.length>3 ? 4 : ver.length); i++)
+ {
+ version2 += "&" + letters[i] + "="+URLEncoder.encode(ver[i],"UTF-8");
+ }
+
+ URL address = new URL("http://updater.azrank.minecraft.rutr.pl/?protocol=1"+version2);
+ URLConnection con = address.openConnection();
+ con.setRequestProperty("User-Agent", userAgent);
+
+ BufferedReader in = new BufferedReader(
+ new InputStreamReader(con.getInputStream()));
+ String inputLine;
+ String[] lines= {"", "", "", ""};
+ int i=0;
+ while ((inputLine = in.readLine()) != null && i<4)
+ {
+ lines[i] = inputLine;
+ //System.out.println("" + i + ": " + inputLine);
+ i++;
+ }
+ in.close();
+
+ if(lines[0].equals("ok") )
+ {
+ if(lines[1].equals("-2"))
+ {
+ azrank.debugmsg("Error when parsing version of AZRank");
+ }
+ else if(lines[1].equals("-1"))
+ {
+ azrank.debugmsg("Checked update! You have newer version than the last!(Error ?)");
+ }
+ else if(lines[1].equals("0"))
+ {
+ azrank.debugmsg("Checked update! You have latest version!");
+ }
+ else if(lines[1].equals("1"))
+ {
+ azrank.debugmsg("Checked update! Your version is out of date! UPDATING...!");
+ update(lines[2]);
+
+ }
+ else if(lines[1].equals("2"))
+ {
+ azrank.debugmsg("Checked update! Your version is out of date! but you have turned off auto updating");
+ }
+ else
+ {
+ azrank.debugmsg("Error when parsing !");
+ }
+ }
+ else
+ {
+ azrank.debugmsg("Error when parsing !");
+ }
+
+ } catch (IOException ex) {
+ AZRank.log.log(Level.SEVERE, null, ex);
+ }
+
+ }
+ else
+ {
+ azrank.debugmsg("[ERROR] Invalid version!");
+ }
+
+
+ working=false;
+ }
+ else
+ {
+ azrank.debugmsg("[TmpRankChecker] Still checking! new check canceled!");
+ }
+ }
+
+ public boolean isUpdating()
+ {
+ return updating;
+ }
+
+ private boolean update(String url)
+ {
+
+ if(downloadUpdate(url, azrank.updateFile, userAgent))
+ {
+ if(copyUpdate(azrank.updateFile))
+ {
+ AZRank.log.info("[AZRank] Please restart server to finish update!");
+ return true;
+ }
+ else
+ return false;
+ }
+ else
+ return false;
+
+ }
+
+ private static boolean downloadUpdate(String url, File file, String userAgent)
+ {
+ URL address;
+ try {
+ String message="";
+ address = new URL(url);
+ message="[UPDATER]connecting...";
+
+ URLConnection conn = address.openConnection();
+ conn.setRequestProperty("User-Agent", userAgent);
+ InputStream inStream = conn.getInputStream();
+
+ AZRank.log.log(Level.INFO, "{0}[OK]", message);
+
+ AZRank.log.log(Level.INFO, "Downloading...");
+ FileOutputStream fileOutStream= new FileOutputStream( file );
+ int oneChar;
+ long count=0;
+ int length = conn.getContentLength();
+ float p,lastp=0;
+ long started = Calendar.getInstance().getTimeInMillis();
+ long last=started;
+ long now;
+ long timeDiff;
+ int czas = 2000,czas2 = 10000;
+ int avaliable;
+ byte[] b;
+ int ile;
+
+ //ONE test byte
+ oneChar=inStream.read();
+ fileOutStream.write(oneChar);
+ count++;
+ now = Calendar.getInstance().getTimeInMillis();
+ p = count*100/length;
+ AZRank.log.log(Level.INFO, "[AZRank][UPDATER]{0}% {1}/{2}KiB in: {3}/{4}", new Object[]{p, count/1024, length/1024, now - last, now - started});
+
+ while ((oneChar=inStream.read()) != -1)
+ {
+
+ fileOutStream.write(oneChar);
+ count++;
+
+ avaliable=inStream.available();
+ b = new byte[avaliable];
+ ile = inStream.read(b);
+ fileOutStream.write(b);
+ count+=ile;
+
+ now = Calendar.getInstance().getTimeInMillis();
+ timeDiff = now - last;
+
+ p = count*100/length;
+ if((timeDiff>czas && p-lastp>=4) || timeDiff>czas2 )
+ {
+ AZRank.log.log(Level.INFO, "[AZRank][UPDATER]{0}% {1}/{2}KiB in: {3}/{4}", new Object[]{p, count/1024, length/1024, now - last, now - started});
+
+ lastp=p;
+ last=now;
+ }
+
+ }
+ inStream.close();
+ fileOutStream.close();
+
+ now = Calendar.getInstance().getTimeInMillis();
+ p = count*100/length;
+ AZRank.log.log(Level.INFO, "[AZRank][UPDATER]{0}% {1}/{2}KiB in: {3}/{4}", new Object[]{p, count/1024, length/1024, now - last, now - started});
+
+
+ return true;
+ } catch (IOException ex) {
+ System.out.println( ex);
+ return false;
+ }
+
+
+
+
+ }
+
+ private static boolean copyUpdate(File updateFile) {
+ try {
+ File target = new File(AZRank.class.getProtectionDomain().getCodeSource().getLocation().toURI());
+ AZRank.log.log(Level.INFO, "[AZRank]file URI: "+target.getCanonicalPath());
+
+ InputStream in = new FileInputStream(updateFile);
+ OutputStream out = new FileOutputStream(target);
+ // Transfer bytes from in to out
+ AZRank.log.log(Level.INFO, "[AZRank] Coping update....");
+ try {
+ int oc, count=0;
+ while ((oc=in.read()) != -1)
+ {
+ out.write(oc);
+ count++;
+ }
+ in.close();
+ out.close();
+ AZRank.log.log(Level.INFO, "[AZRank]Update Successful copied! Bytes:{0}!", count);
+ return true;
+ } catch (IOException ex) {
+ AZRank.log.log(Level.SEVERE, null, ex);
+ return false;
+ }
+
+
+ } catch (FileNotFoundException ex) {
+ AZRank.log.log(Level.SEVERE, null, ex);
+ } catch (IOException ex) {
+ AZRank.log.log(Level.SEVERE, null, ex);
+ } catch (URISyntaxException ex) {
+ AZRank.log.log(Level.SEVERE, null, ex);
+ }
+
+ return false;
+ }
+
+}
View
5 src/pl/azpal/azrank/Util.java → src/pl/rutr/minecraft/azrank/Util.java
@@ -1,12 +1,13 @@
-package pl.azpal.azrank;
+package pl.rutr.minecraft.azrank;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public abstract class Util {
- //This is code from essentials plugin.
+
+ //This is code from essentials plugin.
public static long parseTimeDiffInMillis(String time) throws Exception
{
Pattern timePattern = Pattern.compile(
View
293 src/pl/rutr/minecraft/azrank/commands/AZRankCommandExecutor.java
@@ -0,0 +1,293 @@
+
+package pl.rutr.minecraft.azrank.commands;
+
+/**
+ *
+ * @author Rutr <artuczapl at gmail.com>
+ */
+
+import java.util.logging.Level;
+import org.bukkit.ChatColor;
+import org.bukkit.command.Command;
+import org.bukkit.command.CommandExecutor;
+import org.bukkit.command.CommandSender;
+import org.bukkit.configuration.ConfigurationSection;
+import org.bukkit.entity.Player;
+import org.bukkit.plugin.PluginDescriptionFile;
+import pl.rutr.minecraft.azrank.AZRank;
+import pl.rutr.minecraft.azrank.Util;
+import pl.rutr.minecraft.azrank.permissions.AZRankPermissions;
+
+
+
+public class AZRankCommandExecutor implements CommandExecutor {
+ AZRank plugin;
+
+
+ public AZRankCommandExecutor (AZRank plugin)
+ {
+ this.plugin = plugin;
+ }
+
+
+ @Override
+ public boolean onCommand(CommandSender cs, Command cmd, String alias, String[] args)
+ {
+
+ if (cmd.getName().equalsIgnoreCase("azplayer")) {
+ if(args.length > 0){
+ if(args.length > 1)
+ plugin.sayTooManyArgs(cs,1);
+ if(plugin.hasPerm(cs, AZRankPermissions.INFO_NODE))
+ return plugin.infoCMD(cs,args[0]);
+ else {
+ plugin.sayNoPerm(cs);
+ return true;
+ }
+ } else
+ plugin.sayTooFewArgs(cs,1);
+
+
+ }else if (cmd.getName().equalsIgnoreCase("azrankreload")) {
+ if (args.length > 0) {
+ plugin.sayTooManyArgs(cs, 0);
+ }
+ PluginDescriptionFile pdffile = plugin.getDescription();
+ if (cs instanceof Player) {
+ Player player = (Player)cs;
+ if (plugin.hasReload(player) || (plugin.cfg.allowOpsChanges && player.isOp())) {
+ if(plugin.dLoad()) { // jeżeli dobrze przeładowano
+ cs.sendMessage(ChatColor.GREEN + "[AZRank] " + pdffile.getFullName() + " was succesfully reloaded");
+
+ AZRank.log.log(Level.INFO, "[AZRank] {0} was succesfully reloaded", pdffile.getFullName());
+ } else { //jeżeli błąd podczas przeładowywania
+ cs.sendMessage(ChatColor.GREEN + "[AZRank] " + pdffile.getFullName() + " - Error when reloading");
+ }
+ } else {
+ cs.sendMessage(ChatColor.GREEN + "[AZRank] " + ChatColor.RED + "You do not have permission to do this!" );
+ }
+ } else {
+ if(plugin.dLoad()) { // jeżeli dobrze przeładowano
+ AZRank.log.log(Level.INFO, "[AZRank] {0} was succesfully reloaded", pdffile.getFullName());
+ } else { //jeżeli błąd podczas przeładowywania
+ cs.sendMessage(ChatColor.GREEN + "[AZRank] " + pdffile.getFullName() + " - Error when reloading");
+ }
+ }
+ return true;
+
+
+
+ } else if (cmd.getName().equalsIgnoreCase("azsetgroup")) {
+ if(args.length < 2) {
+ plugin.sayTooFewArgs(cs, 2);
+ return false;
+ }
+ long czas = -1;
+ if (args.length > 2) {
+ if(args.length > 4)
+ plugin.sayTooManyArgs(cs, 4);
+ try {
+ //czas = Util.parseDateDiff(args[args.length-1], true);
+ czas = Util.parseTimeDiffInMillis(args[args.length-1]);
+ }
+ catch (Exception e) {
+ cs.sendMessage(ChatColor.RED + "[AZRank] Error - " + e.getMessage());
+ StackTraceElement[] stackTrace = e.getStackTrace();
+ AZRank.log.log(Level.SEVERE, " [AZRank] Error - {0}", e.getMessage());
+ for(StackTraceElement element : stackTrace)
+ {
+ AZRank.log.log(Level.SEVERE, " {0}", element.toString());
+ }
+ return false;
+ }
+ }
+ if(plugin.canSetRank(cs, args[0],args[1])) {
+ String world;
+ if(cs instanceof Player) {
+ world=((Player)cs).getLocation().getWorld().getName();
+ } else {
+ world=plugin.getServer().getWorlds().get(0).getName();
+ }
+
+ if(!plugin.SetRank(cs, args[0], new String[]{ args[1]}, czas,args[args.length-2].equalsIgnoreCase("-s"),true, world))
+ {
+ cs.sendMessage(ChatColor.GREEN + "[AZRank]"+ChatColor.RED +"An error occurred when tried to set group!");
+ plugin.debugmsg("Error when tried to set group "+args[0] + " to " + args[1] + " time: "+czas/1000+"seconds");
+ }
+ else
+ return true;
+ } //else
+ // sayNoPerm(cs);
+
+ }else if (cmd.getName().equalsIgnoreCase("azaddgroup"))
+ {
+ cs.sendMessage(ChatColor.RED + "[AZRank] Dodawanie... ");
+ if(args.length<2)
+ {
+ plugin.sayTooFewArgs(cs,2);
+ return false;
+ }
+ long czas=-1;
+ if(args.length>2)
+ {
+ if(args.length > 4)
+ plugin.sayTooManyArgs(cs, 4);
+ try {
+ czas = Util.parseTimeDiffInMillis(args[args.length-1]);
+ }
+ catch (Exception e) {
+ cs.sendMessage(ChatColor.RED + "[AZRank] Error - " + e.getMessage());
+ e.printStackTrace();
+ return false;
+ }
+ }
+ if(plugin.canSetRank(cs, args[0],args[1]))
+ {
+ String world;
+ if(cs instanceof Player) {
+ world=((Player)cs).getLocation().getWorld().getName();
+ } else {
+ world=plugin.getServer().getWorlds().get(0).getName();
+ }
+
+ if(!plugin.playerAddTmpGroup(cs, args[0], new String[]{ args[1]}, czas,args[args.length-2].equalsIgnoreCase("-s"), true, world))
+ {
+ cs.sendMessage(ChatColor.GREEN + "[AZRank]"+ChatColor.RED +"An error occurred when tried to add group!");
+ plugin.debugmsg("Error when tried to add group "+args[0] + " to " + args[1] + " time: "+czas);
+ }
+ else
+ return true;
+ }
+
+
+ }
+ else if (cmd.getName().equalsIgnoreCase("azremovegroup"))
+ {
+ if(args.length==2){
+ if(plugin.canSetRank(cs, args[0], args[1]))
+ {
+ String world;
+ if(cs instanceof Player) {
+ world=((Player)cs).getLocation().getWorld().getName();
+ } else {
+ world=plugin.getServer().getWorlds().get(0).getName();
+ }
+ if(plugin.permsSys.playerRemoveGroups(args[0],new String[] {args[1]} , world, true))
+ {
+ if(plugin.database.getConfigurationSection("users."+args[0]+"."+args[1])!=null)
+ {
+ plugin.database.set("users."+args[0]+"."+args[1],null);
+ }
+ cs.sendMessage(ChatColor.GREEN + "[AZRank]"+ChatColor.AQUA +" Successful removed "+args[0] + " from " + args[1] + "!");
+ plugin.debugmsg("successful removed group "+args[0] + " from " + args[1]);
+ return true;
+ } else
+ {
+ cs.sendMessage(ChatColor.GREEN + "[AZRank]"+ChatColor.RED +"An error occurred when tried to remove group!");
+ plugin.debugmsg("Error when tried to remove group "+args[0] + " from " + args[1]);
+ return false;
+ }
+
+ }else
+ {
+ plugin.sayNoPerm(cs);
+ return false;
+ }
+ }
+ else if(args.length<2){
+ plugin.sayTooFewArgs(cs,2);
+ return false;
+ }
+ else if(args.length>2){
+ plugin.sayTooManyArgs(cs,2);
+ return false;
+ }
+
+
+
+ }
+ else if (cmd.getName().equalsIgnoreCase("azranks"))
+ {
+ if(cs instanceof Player)
+ {
+ if(! plugin.hasPerm(cs, AZRankPermissions.LIST_NODE))
+ {
+ plugin.sayNoPerm(cs);
+ return false;
+ }
+ //wypisywanie jezeli gracz
+ if(args.length>0)
+ {
+ try {
+ int page = Integer.parseInt(args[0]);
+ if(page<1) throw new NumberFormatException("Number must be positive!");
+ plugin.wypiszGraczy(cs,10,page);