Beispiel #1
0
  @Override
  public void run() {
    String location = mcMMO.usersFile;

    try {
      FileReader file = new FileReader(location);
      BufferedReader in = new BufferedReader(file);
      String line = "";
      String playerName = null;
      String party = null;
      String mining = null;
      String woodcutting = null;
      String repair = null;
      String unarmed = null;
      String herbalism = null;
      String excavation = null;
      String archery = null;
      String swords = null;
      String axes = null;
      String acrobatics = null;
      String taming = null;
      String fishing = null;
      String miningXP = null;
      String woodCuttingXP = null;
      String repairXP = null;
      String unarmedXP = null;
      String herbalismXP = null;
      String excavationXP = null;
      String archeryXP = null;
      String swordsXP = null;
      String axesXP = null;
      String acrobaticsXP = null;
      String tamingXP = null;
      String fishingXP = null;
      int id = 0;
      int theCount = 0;

      while ((line = in.readLine()) != null) {

        // Find if the line contains the player we want.
        String[] character = line.split(":");
        playerName = character[0];

        // Check for things we don't want put in the DB
        if (playerName == null
            || playerName.equals("null")
            || playerName.equals("#Storage place for user information")) {
          continue;
        }

        if (character.length > 1) {
          mining = character[1];
        }

        if (character.length > 3) {
          party = character[3];
        }

        if (character.length > 4) {
          miningXP = character[4];
        }

        if (character.length > 5) {
          woodcutting = character[5];
        }

        if (character.length > 6) {
          woodCuttingXP = character[6];
        }

        if (character.length > 7) {
          repair = character[7];
        }

        if (character.length > 8) {
          unarmed = character[8];
        }

        if (character.length > 9) {
          herbalism = character[9];
        }

        if (character.length > 10) {
          excavation = character[10];
        }

        if (character.length > 11) {
          archery = character[11];
        }

        if (character.length > 12) {
          swords = character[12];
        }

        if (character.length > 13) {
          axes = character[13];
        }

        if (character.length > 14) {
          acrobatics = character[14];
        }

        if (character.length > 15) {
          repairXP = character[15];
        }

        if (character.length > 16) {
          unarmedXP = character[16];
        }

        if (character.length > 17) {
          herbalismXP = character[17];
        }

        if (character.length > 18) {
          excavationXP = character[18];
        }

        if (character.length > 19) {
          archeryXP = character[19];
        }

        if (character.length > 20) {
          swordsXP = character[20];
        }

        if (character.length > 21) {
          axesXP = character[21];
        }

        if (character.length > 22) {
          acrobaticsXP = character[22];
        }

        if (character.length > 24) {
          taming = character[24];
        }

        if (character.length > 25) {
          tamingXP = character[25];
        }

        if (character.length > 34) {
          fishing = character[34];
        }

        if (character.length > 35) {
          fishingXP = character[35];
        }

        // Check to see if the user is in the DB
        id =
            mcMMO.database.getInt(
                "SELECT id FROM " + tablePrefix + "users WHERE user = '******'");

        if (id > 0) {
          theCount++;

          // Update the skill values
          mcMMO.database.write(
              "UPDATE " + tablePrefix + "users SET lastlogin = "******" WHERE id = " + id);
          mcMMO.database.write(
              "UPDATE "
                  + tablePrefix
                  + "skills SET "
                  + "  taming = taming+"
                  + Misc.getInt(taming)
                  + ", mining = mining+"
                  + Misc.getInt(mining)
                  + ", repair = repair+"
                  + Misc.getInt(repair)
                  + ", woodcutting = woodcutting+"
                  + Misc.getInt(woodcutting)
                  + ", unarmed = unarmed+"
                  + Misc.getInt(unarmed)
                  + ", herbalism = herbalism+"
                  + Misc.getInt(herbalism)
                  + ", excavation = excavation+"
                  + Misc.getInt(excavation)
                  + ", archery = archery+"
                  + Misc.getInt(archery)
                  + ", swords = swords+"
                  + Misc.getInt(swords)
                  + ", axes = axes+"
                  + Misc.getInt(axes)
                  + ", acrobatics = acrobatics+"
                  + Misc.getInt(acrobatics)
                  + ", fishing = fishing+"
                  + Misc.getInt(fishing)
                  + " WHERE user_id = "
                  + id);
          mcMMO.database.write(
              "UPDATE "
                  + tablePrefix
                  + "experience SET "
                  + "  taming = "
                  + Misc.getInt(tamingXP)
                  + ", mining = "
                  + Misc.getInt(miningXP)
                  + ", repair = "
                  + Misc.getInt(repairXP)
                  + ", woodcutting = "
                  + Misc.getInt(woodCuttingXP)
                  + ", unarmed = "
                  + Misc.getInt(unarmedXP)
                  + ", herbalism = "
                  + Misc.getInt(herbalismXP)
                  + ", excavation = "
                  + Misc.getInt(excavationXP)
                  + ", archery = "
                  + Misc.getInt(archeryXP)
                  + ", swords = "
                  + Misc.getInt(swordsXP)
                  + ", axes = "
                  + Misc.getInt(axesXP)
                  + ", acrobatics = "
                  + Misc.getInt(acrobaticsXP)
                  + ", fishing = "
                  + Misc.getInt(fishingXP)
                  + " WHERE user_id = "
                  + id);
        } else {
          theCount++;

          // Create the user in the DB
          mcMMO.database.write(
              "INSERT INTO "
                  + tablePrefix
                  + "users (user, lastlogin) VALUES ('"
                  + playerName
                  + "',"
                  + System.currentTimeMillis() / 1000
                  + ")");
          id =
              mcMMO.database.getInt(
                  "SELECT id FROM " + tablePrefix + "users WHERE user = '******'");
          mcMMO.database.write(
              "INSERT INTO " + tablePrefix + "skills (user_id) VALUES (" + id + ")");
          mcMMO.database.write(
              "INSERT INTO " + tablePrefix + "experience (user_id) VALUES (" + id + ")");
          // Update the skill values
          mcMMO.database.write(
              "UPDATE " + tablePrefix + "users SET lastlogin = "******" WHERE id = " + id);
          mcMMO.database.write(
              "UPDATE " + tablePrefix + "users SET party = '" + party + "' WHERE id = " + id);
          mcMMO.database.write(
              "UPDATE "
                  + tablePrefix
                  + "skills SET "
                  + "  taming = taming+"
                  + Misc.getInt(taming)
                  + ", mining = mining+"
                  + Misc.getInt(mining)
                  + ", repair = repair+"
                  + Misc.getInt(repair)
                  + ", woodcutting = woodcutting+"
                  + Misc.getInt(woodcutting)
                  + ", unarmed = unarmed+"
                  + Misc.getInt(unarmed)
                  + ", herbalism = herbalism+"
                  + Misc.getInt(herbalism)
                  + ", excavation = excavation+"
                  + Misc.getInt(excavation)
                  + ", archery = archery+"
                  + Misc.getInt(archery)
                  + ", swords = swords+"
                  + Misc.getInt(swords)
                  + ", axes = axes+"
                  + Misc.getInt(axes)
                  + ", acrobatics = acrobatics+"
                  + Misc.getInt(acrobatics)
                  + ", fishing = fishing+"
                  + Misc.getInt(fishing)
                  + " WHERE user_id = "
                  + id);
          mcMMO.database.write(
              "UPDATE "
                  + tablePrefix
                  + "experience SET "
                  + "  taming = "
                  + Misc.getInt(tamingXP)
                  + ", mining = "
                  + Misc.getInt(miningXP)
                  + ", repair = "
                  + Misc.getInt(repairXP)
                  + ", woodcutting = "
                  + Misc.getInt(woodCuttingXP)
                  + ", unarmed = "
                  + Misc.getInt(unarmedXP)
                  + ", herbalism = "
                  + Misc.getInt(herbalismXP)
                  + ", excavation = "
                  + Misc.getInt(excavationXP)
                  + ", archery = "
                  + Misc.getInt(archeryXP)
                  + ", swords = "
                  + Misc.getInt(swordsXP)
                  + ", axes = "
                  + Misc.getInt(axesXP)
                  + ", acrobatics = "
                  + Misc.getInt(acrobaticsXP)
                  + ", fishing = "
                  + Misc.getInt(fishingXP)
                  + " WHERE user_id = "
                  + id);
        }
      }

      System.out.println(
          "[mcMMO] MySQL Updated from users file, "
              + theCount
              + " items added/updated to MySQL DB"); // TODO: Locale
      in.close();
    } catch (Exception e) {
      plugin
          .getLogger()
          .severe(
              "Exception while reading "
                  + location
                  + " (Are you sure you formatted it correctly?)"
                  + e.toString());
    }
  }
Beispiel #2
0
  @Override
  public boolean onCommand(CommandSender sender, Command command, String label, String[] args) {
    String usage1 = LocaleLoader.getString("Commands.xprate.proper.0");
    String usage2 = LocaleLoader.getString("Commands.xprate.proper.1");
    String usage3 = LocaleLoader.getString("Commands.xprate.proper.2");

    if (CommandHelper.noCommandPermissions(sender, "mcmmo.admin")) {
      return true;
    }

    switch (args.length) {
      case 1:
        if (args[0].equalsIgnoreCase("reset")) {
          if (xpEvent) {
            for (Player x : plugin.getServer().getOnlinePlayers()) {
              x.sendMessage(LocaleLoader.getString("Commands.xprate.over"));
            }

            xpEvent = !xpEvent;
            Config.getInstance().xpGainMultiplier = oldRate;
          } else {
            Config.getInstance().xpGainMultiplier = oldRate;
          }
        } else if (Misc.isInt(args[0])) {
          sender.sendMessage(usage3);
        } else {
          sender.sendMessage(usage2);
        }

        return true;

      case 2:
        if (Misc.isInt(args[0])) {
          oldRate = Config.getInstance().xpGainMultiplier;

          if (args[1].equalsIgnoreCase("true") || args[1].equalsIgnoreCase("false")) {
            xpEvent = Boolean.valueOf(args[1]);
          } else {
            sender.sendMessage(usage3);
          }

          Config.getInstance().xpGainMultiplier = Misc.getInt(args[0]);

          if (xpEvent) {
            for (Player x : plugin.getServer().getOnlinePlayers()) {
              x.sendMessage(LocaleLoader.getString("Commands.xprate.started.0"));
              x.sendMessage(
                  LocaleLoader.getString(
                      "Commands.xprate.started.1",
                      new Object[] {Config.getInstance().xpGainMultiplier}));
            }
          } else {
            sender.sendMessage(
                "The XP RATE was modified to "
                    + Config.getInstance().xpGainMultiplier); // TODO: Locale
          }
        } else {
          sender.sendMessage(usage1);
          sender.sendMessage(usage2);
        }

        return true;

      default:
        sender.sendMessage(usage1);
        sender.sendMessage(usage2);
        return true;
    }
  }