@Override public boolean onCommand( final CommandSender sender, final Command cmd, final String label, final String[] args) { if (!plugin.getCommandsManager().hasPermission("autorank.add", sender)) { return true; } if (args.length < 3) { sender.sendMessage(Lang.INVALID_FORMAT.getConfigValue("/ar add <player> <value>")); return true; } final UUID uuid = UUIDManager.getUUIDFromPlayer(args[1]); if (uuid == null) { sender.sendMessage(Lang.UNKNOWN_PLAYER.getConfigValue(args[1])); return true; } int value = -1; if (args.length > 2) { final StringBuilder builder = new StringBuilder(); for (int i = 2; i < args.length; i++) { builder.append(args[i]); } if (!builder.toString().contains("m") && !builder.toString().contains("h") && !builder.toString().contains("d")) { value = AutorankTools.stringtoInt(builder.toString().trim()); value += plugin.getPlaytimes().getLocalTime(uuid); } else { value = AutorankTools.stringToTime(builder.toString(), Time.MINUTES); value += plugin.getPlaytimes().getLocalTime(uuid); } } if (value >= 0) { plugin.getPlaytimes().setLocalTime(uuid, value); AutorankTools.sendColoredMessage( sender, Lang.PLAYTIME_CHANGED.getConfigValue(args[1], value + "")); } else { AutorankTools.sendColoredMessage( sender, Lang.INVALID_FORMAT.getConfigValue("/ar add [player] [value]")); } return true; }
@Override public boolean onCommand( final CommandSender sender, final Command cmd, final String label, final String[] args) { if (args.length < 2) { sender.sendMessage(ChatColor.RED + "No file was given to convert."); return true; } final String targetFile = args[1]; if (targetFile.equalsIgnoreCase("playerdata")) { if (!plugin.getCommandsManager().hasPermission("autorank.convert.playerdata", sender)) { return true; } // Convert playerdata plugin.getPlayerDataHandler().convertNamesToUUIDs(); sender.sendMessage(ChatColor.RED + "Converting playerdata.yml to use new UUID format."); } else if (targetFile.equalsIgnoreCase("data") || targetFile.equalsIgnoreCase("times")) { if (!plugin.getCommandsManager().hasPermission("autorank.convert.data", sender)) { return true; } // Convert data.yml plugin.getPlaytimes().convertToUUIDStorage(); sender.sendMessage(ChatColor.RED + "Converting data.yml to use new UUID format."); } else { sender.sendMessage( ChatColor.RED + "Unknown file. Can convert either 'data' or 'playerdata'."); } return true; }
@Override public boolean onCommand( final CommandSender sender, final Command cmd, final String label, final String[] args) { int value = -1; if (args.length < 3) { sender.sendMessage(Lang.INVALID_FORMAT.getConfigValue("/ar set <player> <value>")); return true; } if (args.length > 2) { final StringBuilder builder = new StringBuilder(); for (int i = 2; i < args.length; i++) { builder.append(args[i]); } if (!builder.toString().contains("m") && !builder.toString().contains("h") && !builder.toString().contains("d") && !builder.toString().contains("s")) { value = AutorankTools.stringtoInt(builder.toString().trim()); } else { if (builder.toString().contains("s")) { sender.sendMessage( ChatColor.RED + Lang.INVALID_FORMAT.getConfigValue("(h)ours, (m)inutes or (d)ays")); return true; } value = AutorankTools.stringToTime(builder.toString(), Time.MINUTES); } } if (value >= 0) { if (args[1].equalsIgnoreCase(sender.getName())) { if (!plugin.getCommandsManager().hasPermission("autorank.set.self", sender)) { return true; } } else { if (!plugin.getCommandsManager().hasPermission("autorank.set.other", sender)) { return true; } } final UUID uuid = UUIDManager.getUUIDFromPlayer(args[1]); // System.out.print("Name of UUID: " + // UUIDManager.getPlayerFromUUID(UUID.fromString("fc914960-7aa1-3ae2-a3ee-70f5ac1e81e5"))); if (uuid == null) { sender.sendMessage(Lang.UNKNOWN_PLAYER.getConfigValue(args[1])); return true; } plugin.getPlaytimes().setLocalTime(uuid, value); AutorankTools.sendColoredMessage( sender, Lang.PLAYTIME_CHANGED.getConfigValue(args[1], value + " minutes")); } else { AutorankTools.sendColoredMessage( sender, Lang.INVALID_FORMAT.getConfigValue("/ar set <player> <value>")); } return true; }
/** * Gets the global play time (playtime across all servers with the same MySQL database linked) of * a player. * * <p> * * @param player Player to check for. * @return play time of a player. -1 if no entry was found. */ public int getGlobalPlayTime(Player player) { return plugin.getPlaytimes().getGlobalTime(player.getUniqueId()); }
/** * Gets the local play time (playtime on this server) of a player. <br> * The time given depends on what plugin is used for keeping track of time. <br> * The time is always given in minutes. * * <p> * * @param UUID uuid to get the time for * @return play time of a player. 0 when has never played before. */ public int getTimeOfPlayer(Player player) { return plugin.getPlaytimes().getTimeOfPlayer(player.getName()); }