public void addMySQLPlayer() { Database database = mcMMO.getPlayerDatabase(); String tablePrefix = Config.getInstance().getMySQLTablePrefix(); database.write( "INSERT INTO " + tablePrefix + "users (user, lastlogin) VALUES ('" + playerName + "'," + System.currentTimeMillis() / 1000 + ")"); userId = database.getInt( "SELECT id FROM " + tablePrefix + "users WHERE user = '******'"); database.write("INSERT INTO " + tablePrefix + "cooldowns (user_id) VALUES (" + userId + ")"); database.write("INSERT INTO " + tablePrefix + "skills (user_id) VALUES (" + userId + ")"); database.write("INSERT INTO " + tablePrefix + "experience (user_id) VALUES (" + userId + ")"); }
public void save() { Long timestamp = System.currentTimeMillis() / 1000; // if we are using mysql save to database if (Config.getInstance().getUseMySQL()) { Database database = mcMMO.getPlayerDatabase(); String tablePrefix = Config.getInstance().getMySQLTablePrefix(); database.write( "UPDATE " + tablePrefix + "huds SET hudtype = '" + hudType.toString() + "' WHERE user_id = " + userId); database.write( "UPDATE " + tablePrefix + "users SET lastlogin = "******" WHERE id = " + userId); database.write( "UPDATE " + tablePrefix + "cooldowns SET " + " mining = " + skillsDATS.get(AbilityType.SUPER_BREAKER) + ", woodcutting = " + skillsDATS.get(AbilityType.TREE_FELLER) + ", unarmed = " + skillsDATS.get(AbilityType.BERSERK) + ", herbalism = " + skillsDATS.get(AbilityType.GREEN_TERRA) + ", excavation = " + skillsDATS.get(AbilityType.GIGA_DRILL_BREAKER) + ", swords = " + skillsDATS.get(AbilityType.SERRATED_STRIKES) + ", axes = " + skillsDATS.get(AbilityType.SKULL_SPLIITER) + ", blast_mining = " + skillsDATS.get(AbilityType.BLAST_MINING) + " WHERE user_id = " + userId); database.write( "UPDATE " + tablePrefix + "skills SET " + " taming = " + skills.get(SkillType.TAMING) + ", mining = " + skills.get(SkillType.MINING) + ", repair = " + skills.get(SkillType.REPAIR) + ", woodcutting = " + skills.get(SkillType.WOODCUTTING) + ", unarmed = " + skills.get(SkillType.UNARMED) + ", herbalism = " + skills.get(SkillType.HERBALISM) + ", excavation = " + skills.get(SkillType.EXCAVATION) + ", archery = " + skills.get(SkillType.ARCHERY) + ", swords = " + skills.get(SkillType.SWORDS) + ", axes = " + skills.get(SkillType.AXES) + ", acrobatics = " + skills.get(SkillType.ACROBATICS) + ", fishing = " + skills.get(SkillType.FISHING) + " WHERE user_id = " + userId); database.write( "UPDATE " + tablePrefix + "experience SET " + " taming = " + skillsXp.get(SkillType.TAMING) + ", mining = " + skillsXp.get(SkillType.MINING) + ", repair = " + skillsXp.get(SkillType.REPAIR) + ", woodcutting = " + skillsXp.get(SkillType.WOODCUTTING) + ", unarmed = " + skillsXp.get(SkillType.UNARMED) + ", herbalism = " + skillsXp.get(SkillType.HERBALISM) + ", excavation = " + skillsXp.get(SkillType.EXCAVATION) + ", archery = " + skillsXp.get(SkillType.ARCHERY) + ", swords = " + skillsXp.get(SkillType.SWORDS) + ", axes = " + skillsXp.get(SkillType.AXES) + ", acrobatics = " + skillsXp.get(SkillType.ACROBATICS) + ", fishing = " + skillsXp.get(SkillType.FISHING) + " WHERE user_id = " + userId); } else { // otherwise save to flatfile try { // Open the file FileReader file = new FileReader(location); BufferedReader in = new BufferedReader(file); StringBuilder writer = new StringBuilder(); String line = ""; // While not at the end of the file while ((line = in.readLine()) != null) { // Read the line in and copy it to the output it's not the player // we want to edit if (!line.split(":")[0].equals(playerName)) { writer.append(line).append("\r\n"); } else { // Otherwise write the new player information writer.append(playerName + ":"); writer.append(skills.get(SkillType.MINING) + ":"); writer.append("" + ":"); writer.append("" + ":"); writer.append(skillsXp.get(SkillType.MINING) + ":"); writer.append(skills.get(SkillType.WOODCUTTING) + ":"); writer.append(skillsXp.get(SkillType.WOODCUTTING) + ":"); writer.append(skills.get(SkillType.REPAIR) + ":"); writer.append(skills.get(SkillType.UNARMED) + ":"); writer.append(skills.get(SkillType.HERBALISM) + ":"); writer.append(skills.get(SkillType.EXCAVATION) + ":"); writer.append(skills.get(SkillType.ARCHERY) + ":"); writer.append(skills.get(SkillType.SWORDS) + ":"); writer.append(skills.get(SkillType.AXES) + ":"); writer.append(skills.get(SkillType.ACROBATICS) + ":"); writer.append(skillsXp.get(SkillType.REPAIR) + ":"); writer.append(skillsXp.get(SkillType.UNARMED) + ":"); writer.append(skillsXp.get(SkillType.HERBALISM) + ":"); writer.append(skillsXp.get(SkillType.EXCAVATION) + ":"); writer.append(skillsXp.get(SkillType.ARCHERY) + ":"); writer.append(skillsXp.get(SkillType.SWORDS) + ":"); writer.append(skillsXp.get(SkillType.AXES) + ":"); writer.append(skillsXp.get(SkillType.ACROBATICS) + ":"); writer.append("" + ":"); writer.append(skills.get(SkillType.TAMING) + ":"); writer.append(skillsXp.get(SkillType.TAMING) + ":"); // Need to store the DATS of abilities nao // Berserk, Gigadrillbreaker, Tree Feller, Green Terra, Serrated Strikes, Skull // Splitter, Super Breaker writer.append(String.valueOf(skillsDATS.get(AbilityType.BERSERK)) + ":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.GIGA_DRILL_BREAKER)) + ":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.TREE_FELLER)) + ":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.GREEN_TERRA)) + ":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.SERRATED_STRIKES)) + ":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.SKULL_SPLIITER)) + ":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.SUPER_BREAKER)) + ":"); writer.append(hudType.toString() + ":"); writer.append(skills.get(SkillType.FISHING) + ":"); writer.append(skillsXp.get(SkillType.FISHING) + ":"); writer.append(String.valueOf(skillsDATS.get(AbilityType.BLAST_MINING)) + ":"); writer.append("\r\n"); } } in.close(); // Write the new file FileWriter out = new FileWriter(location); out.write(writer.toString()); out.close(); } catch (Exception e) { e.printStackTrace(); } } }
public boolean loadMySQL() { Database database = mcMMO.getPlayerDatabase(); String tablePrefix = Config.getInstance().getMySQLTablePrefix(); userId = database.getInt( "SELECT id FROM " + tablePrefix + "users WHERE user = '******'"); if (userId == 0) { return false; } else { HashMap<Integer, ArrayList<String>> huds = database.read("SELECT hudtype FROM " + tablePrefix + "huds WHERE user_id = " + userId); if (huds.get(1) == null) { database.write("INSERT INTO " + tablePrefix + "huds (user_id) VALUES (" + userId + ")"); } else { for (HudType type : HudType.values()) { if (type.toString().equals(huds.get(1).get(0))) { hudType = type; } } } /* * I'm still learning MySQL, this is a fix for adding a new table * its not pretty but it works */ HashMap<Integer, ArrayList<String>> cooldowns = database.read( "SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes, blast_mining FROM " + tablePrefix + "cooldowns WHERE user_id = " + userId); ArrayList<String> cooldownValues = cooldowns.get(1); if (cooldownValues == null) { database.write( "INSERT INTO " + tablePrefix + "cooldowns (user_id) VALUES (" + userId + ")"); mcMMO .p .getLogger() .warning( playerName + "does not exist in the cooldown table. Their cooldowns will be reset."); } else { skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(cooldownValues.get(0))); skillsDATS.put(AbilityType.TREE_FELLER, Integer.valueOf(cooldownValues.get(1))); skillsDATS.put(AbilityType.BERSERK, Integer.valueOf(cooldownValues.get(2))); skillsDATS.put(AbilityType.GREEN_TERRA, Integer.valueOf(cooldownValues.get(3))); skillsDATS.put(AbilityType.GIGA_DRILL_BREAKER, Integer.valueOf(cooldownValues.get(4))); skillsDATS.put(AbilityType.SERRATED_STRIKES, Integer.valueOf(cooldownValues.get(5))); skillsDATS.put(AbilityType.SKULL_SPLIITER, Integer.valueOf(cooldownValues.get(6))); skillsDATS.put(AbilityType.BLAST_MINING, Integer.valueOf(cooldownValues.get(7))); } HashMap<Integer, ArrayList<String>> stats = database.read( "SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM " + tablePrefix + "skills WHERE user_id = " + userId); ArrayList<String> statValues = stats.get(1); if (statValues == null) { database.write("INSERT INTO " + tablePrefix + "skills (user_id) VALUES (" + userId + ")"); mcMMO .p .getLogger() .warning(playerName + "does not exist in the skills table. Their stats will be reset."); } else { skills.put(SkillType.TAMING, Integer.valueOf(statValues.get(0))); skills.put(SkillType.MINING, Integer.valueOf(statValues.get(1))); skills.put(SkillType.REPAIR, Integer.valueOf(statValues.get(2))); skills.put(SkillType.WOODCUTTING, Integer.valueOf(statValues.get(3))); skills.put(SkillType.UNARMED, Integer.valueOf(statValues.get(4))); skills.put(SkillType.HERBALISM, Integer.valueOf(statValues.get(5))); skills.put(SkillType.EXCAVATION, Integer.valueOf(statValues.get(6))); skills.put(SkillType.ARCHERY, Integer.valueOf(statValues.get(7))); skills.put(SkillType.SWORDS, Integer.valueOf(statValues.get(8))); skills.put(SkillType.AXES, Integer.valueOf(statValues.get(9))); skills.put(SkillType.ACROBATICS, Integer.valueOf(statValues.get(10))); skills.put(SkillType.FISHING, Integer.valueOf(statValues.get(11))); } HashMap<Integer, ArrayList<String>> experience = database.read( "SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM " + tablePrefix + "experience WHERE user_id = " + userId); ArrayList<String> experienceValues = experience.get(1); if (experienceValues == null) { database.write( "INSERT INTO " + tablePrefix + "experience (user_id) VALUES (" + userId + ")"); mcMMO .p .getLogger() .warning( playerName + "does not exist in the experience table. Their experience will be reset."); } else { skillsXp.put(SkillType.TAMING, Integer.valueOf(experienceValues.get(0))); skillsXp.put(SkillType.MINING, Integer.valueOf(experienceValues.get(1))); skillsXp.put(SkillType.REPAIR, Integer.valueOf(experienceValues.get(2))); skillsXp.put(SkillType.WOODCUTTING, Integer.valueOf(experienceValues.get(3))); skillsXp.put(SkillType.UNARMED, Integer.valueOf(experienceValues.get(4))); skillsXp.put(SkillType.HERBALISM, Integer.valueOf(experienceValues.get(5))); skillsXp.put(SkillType.EXCAVATION, Integer.valueOf(experienceValues.get(6))); skillsXp.put(SkillType.ARCHERY, Integer.valueOf(experienceValues.get(7))); skillsXp.put(SkillType.SWORDS, Integer.valueOf(experienceValues.get(8))); skillsXp.put(SkillType.AXES, Integer.valueOf(experienceValues.get(9))); skillsXp.put(SkillType.ACROBATICS, Integer.valueOf(experienceValues.get(10))); skillsXp.put(SkillType.FISHING, Integer.valueOf(experienceValues.get(11))); } loaded = true; return true; } }