stats.Stats issue with methods really need help

Discussion in 'Spigot Plugin Development' started by PCPSells, May 30, 2016.

  1. Okay so this is my stats.Stats class and I use this for the balance of eTokens for every player
    Code (Text):
    package stats;
    import java.io.File;
    import java.io.IOException;
    import java.util.UUID;
    import org.bukkit.Bukkit;
    import org.bukkit.Statistic;
    import org.bukkit.configuration.file.FileConfiguration;
    import org.bukkit.configuration.file.YamlConfiguration;
    import org.bukkit.entity.Player;
    import org.bukkit.plugin.java.JavaPlugin;

    import me.PCPSells.MaineT;
    public class Stats
      extends JavaPlugin {
        static MaineT main;
      public static File file = new File("plugins/eTokens", "eTokens.yml");
      public static FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
      public static void addPoints(Player p, int i) {
        if (cfg.get("eTokens." + p.getUniqueId() + ".Tokens") != null) {
          int o = cfg.getInt("eTokens." + p.getUniqueId() + ".Tokens");
          cfg.set("eTokens." + p.getUniqueId() + ".Tokens", Integer.valueOf(o + i));
        } else {
          cfg.set("eTokens." + p.getUniqueId() + ".Tokens", Integer.valueOf(i));
        }
        saveFile();
      } public static int getBrokenBlocks(UUID uuid) {
          return Bukkit.getPlayer(uuid).getStatistic(Statistic.MINE_BLOCK);
      } public static void resetBrokenBlocks(UUID uuid) {
       Bukkit.getPlayer(uuid).setStatistic(Statistic.MINE_BLOCK, 0);
      } public static void setPoints(Player p, int i) {
        cfg.set("eTokens." + p.getUniqueId() + ".Tokens", Integer.valueOf(i));
        saveFile();
      } public static void removePoints(Player p, int i) {
        int o = cfg.getInt("eTokens." + p.getUniqueId() + ".Tokens");
        cfg.set("eTokens." + p.getUniqueId() + ".Tokens", Integer.valueOf(o - i));
        saveFile();
      } public static int getPoints(Player p) {
        return cfg.get("eTokens." + p.getUniqueId() + ".Tokens") != null ? cfg.getInt("eTokens." + p.getUniqueId() + ".Tokens") : 0;
      } public static UUID getUUID(Player p) {
        return p.getUniqueId();
      } public static void resetPoints(Player p) {
        cfg.set("eTokens." + p.getUniqueId() + ".Tokens", Integer.valueOf(0));
        saveFile();
      } public static void saveFile() { try {
          cfg.save(file);
        } catch (IOException e) {
          Bukkit.getConsoleSender().sendMessage("§fError occured when trying to save eTokens balance.");
          e.printStackTrace();
        }}}
    My issue is for when I use the methods such as
    Stats.getPoints(p);
    etc, well whatever code is after it doesn't seem to go through. Here's an example..

    Code (Text):
          ActionBarAPI bar = new ActionBarAPI(p, plugin.getConfig().getString("ActionBarMsgs.Profit").replace("&", "§").replace("%prefix%", plugin.getConfig().getString("messages.Prefix").replace("&", "§")).replace("%amount%", "" + e.getPlayer().getItemInHand().getAmount()));
          bar.sendPlayerAnnouncement();
          p.setItemInHand(air);
          p.updateInventory();
          Stats.addPoints(p, p.getItemInHand().getAmount());
    That's a very simple method of just adding some points with replacing the item to air, which all used to work fine until I updated to the stats.Stats I have now. I have the Stats.addPoints at the bottom assuming that, that would fix it.. but now everything else works other than adding the points, and no matter where I place it (Above the p.setItemInHand(air); or anywhere then anything below that no longer works and the points being added works.)
    I seriously have no idea why this occurs. Any help would be AMAZING.
     
  2. What's MaineT? Do you have more than one JavaPlugin class?
     
  3. MaineT is my the main class, and yes both MaineT & Stats extend JavaPlugin
     
  4. Then you are designing them incorrectly. You don't have two plugins, so you shouldn't have two JavaPlugin classes. Additionally there's a horrendous amount of static misuse in your code, there's not really any reason for a lot of it and it's just making your plugin more and more unnecessarily complicated.

    As for the issue itself, have you verified it actually reaches that point in the code? Use try/catch blocks and debug statements to determine what's going on in your code.