Exemple #1
0
  public void setGlobalTime(String name, int time) throws SQLException {
    // Check for MySQL
    if (!plugin.getMySQLWrapper().isMySQLEnabled()) {
      throw new SQLException("MySQL database is not enabled so you can't set items to it!");
    }

    plugin.getMySQLWrapper().setGlobalTime(name, time);
  }
 /**
  * Add a player to group
  *
  * @param player Player to add
  * @param world On a specific world
  * @param group Group to add the player to
  * @return true if done, false if failed
  */
 public boolean addGroup(final Player player, final String world, final String group) {
   // No known way to set via API, hence we do it the ugly route (via commands).
   plugin
       .getServer()
       .dispatchCommand(
           plugin.getServer().getConsoleSender(),
           "pp user " + player.getName() + " setrank " + group);
   return true;
   // There is no way to check if the command was successful.
 }
Exemple #3
0
  @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 isEnabled() {
    if (statsApi == null) {
      plugin.getLogger().info("Statistics (by bitWolfy) api library was not found!");
      return false;
    }

    if (!statsApi.isAvailable()) {
      plugin.getLogger().info("Statistics (by bitWolfy) is not enabled!");
      return false;
    }

    return true;
  }
Exemple #5
0
  public void modifyGlobalTime(String name, int timeDifference) throws IllegalArgumentException {
    // Check for MySQL
    if (!plugin.getMySQLWrapper().isMySQLEnabled()) {
      try {
        throw new SQLException("MySQL database is not enabled so you can't modify database!");
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return;
      }
    }

    int time = getGlobalTime(name);

    if (time >= 0) {
      try {
        setGlobalTime(name, time + timeDifference);
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return;
      }
    } else {
      // First entry.
      try {
        setGlobalTime(name, timeDifference);
      } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
Exemple #6
0
  public Playtimes(Autorank plugin) {
    this.plugin = plugin;

    INTERVAL_MINUTES = plugin.getAdvancedConfig().getInt("interval check", 5);
    plugin.getLogger().info("Interval check every " + INTERVAL_MINUTES + " minutes.");

    this.data = new SimpleYamlConfiguration(plugin, "Data.yml", null, "Data");
    this.save = new PlaytimesSave(this);
    this.update = new PlaytimesUpdate(this, plugin);

    plugin.getServer().getScheduler().runTaskTimer(plugin, save, 12000, 12000);
    plugin.getServer().getScheduler().runTaskTimer(plugin, save, 600, 600);
    plugin
        .getServer()
        .getScheduler()
        .runTaskTimer(plugin, update, INTERVAL_MINUTES * 20 * 60, INTERVAL_MINUTES * 20 * 60);
  }
  private void sqlSetup(SimpleYamlConfiguration config) {
    ConfigurationSection s = config.getConfigurationSection("sql");

    Boolean enabled = s.getBoolean("enabled");
    if (enabled != null && enabled) {

      String hostname = s.getString("hostname");
      String username = s.getString("username");
      String password = s.getString("password");
      String database = s.getString("database");
      this.table = s.getString("table");

      this.sql = new SQLDataStorage(hostname, username, password, database);
      if (!sql.connect()) {
        this.sql = null;
        plugin.getLogger().severe("Could not connect to " + hostname);
      } else {
        plugin.getLogger().info("Successfully established connection to " + hostname);
      }
    }
  }
Exemple #8
0
  /**
   * Gets the permission groups a player is part of.
   *
   * @param player Player to get the groups of
   * @return A list of permission groups
   */
  public List<String> getPermissionGroups(Player player) {
    String[] groups = plugin.getPermPlugHandler().getPermissionPlugin().getPlayerGroups(player);

    List<String> permGroups = new ArrayList<String>();

    // Convert array into list
    for (String group : groups) {
      permGroups.add(group);
    }

    return permGroups;
  }
Exemple #9
0
  /**
   * Gets all requirements for a player at the exact moment. This does not consider already finished
   * requirement but just mirrors the config file.
   *
   * @param player Player to get the requirements from.
   * @return a list of requirements; An empty list when none are found.
   */
  public List<Requirement> getAllRequirements(final Player player) {
    final Map<RankChange, List<Requirement>> failed =
        plugin.getPlayerChecker().getAllRequirements(player);

    final Set<RankChange> keySet = failed.keySet();
    List<Requirement> reqs = new ArrayList<Requirement>();

    for (final RankChange rank : keySet) {
      reqs = failed.get(rank);
    }

    return reqs;
  }
  private boolean setup() {
    final PluginManager pluginManager = plugin.getServer().getPluginManager();
    final Plugin permPlugin = pluginManager.getPlugin("PowerfulPerms");

    System.out.println("PowerfulPerms: " + permPlugin);
    System.out.println("PowerfulPerms enabled: " + permPlugin.isEnabled());

    if (permPlugin != null && permPlugin.isEnabled()) {
      powerfulPerms = (PowerfulPermsPlugin) permPlugin;
    }

    return powerfulPerms != null;
  }
  public Playtimes(Autorank plugin) {
    this.plugin = plugin;
    this.scheduler = plugin.getServer().getScheduler();
    this.data = new SimpleYamlConfiguration(plugin, "Data.yml", null, "Data");
    this.save = new PlaytimesSave(this);
    this.update = new PlaytimesUpdate(this, plugin);

    sqlSetup(plugin.getAdvancedConfig());
    if (sql != null) {
      setupTable();
    }

    plugin.getServer().getScheduler().runTaskTimer(plugin, save, 12000, 12000);
    plugin.getServer().getScheduler().runTaskTimer(plugin, save, 600, 600);
    plugin
        .getServer()
        .getScheduler()
        .runTaskTimer(plugin, update, INTERVAL_MINUTES * 20 * 60, INTERVAL_MINUTES * 20 * 60);
    // plugin.getServer().getScheduler().scheduleSyncRepeatingTask(plugin, update, INTERVAL_MINUTES
    // * 20 * 4, INTERVAL_MINUTES * 20 * 4);

  }
  @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;
  }
Exemple #13
0
  @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;
  }
Exemple #14
0
 /**
  * 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());
 }
Exemple #15
0
 /**
  * Gets the database name Autorank stores its global times in.
  *
  * @return name of database
  */
 public String getMySQLDatabase() {
   return plugin.getMySQLWrapper().getDatabaseName();
 }
Exemple #16
0
 /**
  * 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());
 }
Exemple #17
0
 /**
  * Get the addon manager of Autorank.
  *
  * <p>This class stores information about the loaded addons
  *
  * @return {@link me.armar.plugins.autorank.addons.AddOnManager} class
  */
 public AddOnManager getAddonManager() {
   return plugin.getAddonManager();
 }
Exemple #18
0
  /**
   * Register a result that can be used in the advanced config. The name should be unique as that is
   * the way Autorank will identify the result.
   *
   * <p>The name will be the name that is used in the config.
   *
   * @param uniqueName Unique name identifier for the result
   * @param clazz Result class that does all the logic
   */
  public void registerResult(String uniqueName, Class<? extends Result> clazz) {
    plugin.getLogger().info("Loaded custom result: " + uniqueName);

    plugin.registerResult(uniqueName, clazz);
  }
Exemple #19
0
 /**
  * Gets the permission group that the player will be ranked up to after he completes all
  * requirements.
  *
  * <p><b>NOTE:</b> This does not mean the player will always be ranked up to this group. If a
  * requirement has its own <i>'rank change'</i> result, the player will be ranked up to that group
  * and not the 'global results' group.
  *
  * @param player Player to get the next rank up for.
  * @return The name of the group the player will be ranked to; null when no rank up.
  */
 public String getNextRankupGroup(Player player) {
   return plugin.getPlayerChecker().getNextRankupGroup(player);
 }
Exemple #20
0
 public boolean isMySQLEnabled() {
   return plugin.getMySQLWrapper().isMySQLEnabled();
 }
Exemple #21
0
 /**
  * Returns total playtime across all servers (Multiple servers write to 1 database and get the
  * total playtime from there)
  *
  * @param name Player to check for
  * @return Global playtime across all servers or -1 if no time was found
  */
 public int getGlobalTime(String name) {
   return plugin.getMySQLWrapper().getDatabaseTime(name);
 }