Alternative SQL player loading

This commit is contained in:
T00thpick1 2013-05-15 22:33:57 -04:00
parent fca5f9ec98
commit fb450671d6

View File

@ -287,81 +287,93 @@ public class PlayerProfile {
private boolean loadMySQL() { private boolean loadMySQL() {
String tablePrefix = Config.getInstance().getMySQLTablePrefix(); String tablePrefix = Config.getInstance().getMySQLTablePrefix();
userId = SQLDatabaseManager.getInt("SELECT id FROM " + tablePrefix + "users WHERE user = '" + playerName + "'"); ArrayList<String> playerData = SQLDatabaseManager.read(
"SELECT * FROM " + tablePrefix + "users u " +
"JOIN " + tablePrefix + "skills s ON (u.id = s.user_id) " +
"JOIN " + tablePrefix + "experience e ON (u.id = e.user_id) " +
"JOIN " + tablePrefix + "cooldowns c ON (u.id = c.user_id) " +
"JOIN " + tablePrefix + "huds h ON (u.id = h.user_id) " +
"WHERE u.user = '" + playerName + "'"
).get(1);
if (userId == 0) { if (playerData.size() == 0) {
return false; userId = SQLDatabaseManager.getInt("SELECT id FROM " + tablePrefix + "users WHERE user = '" + playerName + "'");
}
ArrayList<String> hudValues = SQLDatabaseManager.read("SELECT hudtype, mobhealthbar FROM " + tablePrefix + "huds WHERE user_id = " + userId).get(1); // Check if user doesn't exist
if (userId == 0) {
return false;
}
if (hudValues == null) { // Write missing table rows
SQLDatabaseManager.write("INSERT INTO " + tablePrefix + "huds (user_id, mobhealthbar) VALUES (" + userId + ",'" + mobHealthbarType.name() + "')"); SQLDatabaseManager.write("INSERT IGNORE INTO " + tablePrefix + "skills (user_id) VALUES (" + userId + ")");
mcMMO.p.getLogger().warning(playerName + " does not exist in the HUD table. Their HUDs will be reset."); SQLDatabaseManager.write("INSERT IGNORE INTO " + tablePrefix + "experience (user_id) VALUES (" + userId + ")");
} SQLDatabaseManager.write("INSERT IGNORE INTO " + tablePrefix + "cooldowns (user_id) VALUES (" + userId + ")");
else { SQLDatabaseManager.write("INSERT IGNORE INTO " + tablePrefix + "huds (user_id, mobhealthbar) VALUES (" + userId + ",'" + mobHealthbarType.name() + "')");
hudType = HudType.valueOf(hudValues.get(0));
mobHealthbarType = MobHealthbarType.valueOf(hudValues.get(1));
}
ArrayList<String> cooldownValues = SQLDatabaseManager.read("SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes, blast_mining FROM " + tablePrefix + "cooldowns WHERE user_id = " + userId).get(1); // Re-read data
playerData = SQLDatabaseManager.read(
"SELECT * FROM " + tablePrefix + "users u " +
"JOIN " + tablePrefix + "skills s ON (u.id = s.user_id) " +
"JOIN " + tablePrefix + "experience e ON (u.id = e.user_id) " +
"JOIN " + tablePrefix + "cooldowns c ON (u.id = c.user_id) " +
"JOIN " + tablePrefix + "huds h ON (u.id = h.user_id) " +
"WHERE u.user = '" + playerName + "'"
).get(1);
}
// Remove from list the user_id's from various tables
playerData.remove(43);
playerData.remove(30);
playerData.remove(17);
playerData.remove(4);
if (cooldownValues == null) { userId = Integer.valueOf(playerData.get(0));
SQLDatabaseManager.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."); // UserName 1 - Already loaded
} // LastLogin 2 - Doesn't need to be loaded
else { // PartyName 3 - Loaded elsewhere I believe
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_SPLITTER, Integer.valueOf(cooldownValues.get(6)));
skillsDATS.put(AbilityType.BLAST_MINING, Integer.valueOf(cooldownValues.get(7)));
}
ArrayList<String> statValues = SQLDatabaseManager.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM " + tablePrefix + "skills WHERE user_id = " + userId).get(1); skills.put(SkillType.TAMING, Integer.valueOf(playerData.get(4)));
skills.put(SkillType.MINING, Integer.valueOf(playerData.get(5)));
skills.put(SkillType.REPAIR, Integer.valueOf(playerData.get(6)));
skills.put(SkillType.WOODCUTTING, Integer.valueOf(playerData.get(7)));
skills.put(SkillType.UNARMED, Integer.valueOf(playerData.get(8)));
skills.put(SkillType.HERBALISM, Integer.valueOf(playerData.get(9)));
skills.put(SkillType.EXCAVATION, Integer.valueOf(playerData.get(10)));
skills.put(SkillType.ARCHERY, Integer.valueOf(playerData.get(11)));
skills.put(SkillType.SWORDS, Integer.valueOf(playerData.get(12)));
skills.put(SkillType.AXES, Integer.valueOf(playerData.get(13)));
skills.put(SkillType.ACROBATICS, Integer.valueOf(playerData.get(14)));
skills.put(SkillType.FISHING, Integer.valueOf(playerData.get(15)));
if (statValues == null) { skillsXp.put(SkillType.TAMING, (float) Integer.valueOf(playerData.get(16)));
SQLDatabaseManager.write("INSERT INTO " + tablePrefix + "skills (user_id) VALUES (" + userId + ")"); skillsXp.put(SkillType.MINING, (float) Integer.valueOf(playerData.get(17)));
mcMMO.p.getLogger().warning(playerName + "does not exist in the skills table. Their stats will be reset."); skillsXp.put(SkillType.REPAIR, (float) Integer.valueOf(playerData.get(18)));
} skillsXp.put(SkillType.WOODCUTTING, (float) Integer.valueOf(playerData.get(19)));
else { skillsXp.put(SkillType.UNARMED, (float) Integer.valueOf(playerData.get(20)));
skills.put(SkillType.TAMING, Integer.valueOf(statValues.get(0))); skillsXp.put(SkillType.HERBALISM, (float) Integer.valueOf(playerData.get(21)));
skills.put(SkillType.MINING, Integer.valueOf(statValues.get(1))); skillsXp.put(SkillType.EXCAVATION, (float) Integer.valueOf(playerData.get(22)));
skills.put(SkillType.REPAIR, Integer.valueOf(statValues.get(2))); skillsXp.put(SkillType.ARCHERY, (float) Integer.valueOf(playerData.get(23)));
skills.put(SkillType.WOODCUTTING, Integer.valueOf(statValues.get(3))); skillsXp.put(SkillType.SWORDS, (float) Integer.valueOf(playerData.get(24)));
skills.put(SkillType.UNARMED, Integer.valueOf(statValues.get(4))); skillsXp.put(SkillType.AXES, (float) Integer.valueOf(playerData.get(25)));
skills.put(SkillType.HERBALISM, Integer.valueOf(statValues.get(5))); skillsXp.put(SkillType.ACROBATICS, (float) Integer.valueOf(playerData.get(26)));
skills.put(SkillType.EXCAVATION, Integer.valueOf(statValues.get(6))); skillsXp.put(SkillType.FISHING, (float) Integer.valueOf(playerData.get(27)));
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)));
}
ArrayList<String> experienceValues = SQLDatabaseManager.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM " + tablePrefix + "experience WHERE user_id = " + userId).get(1); // Taming 28 - Unused
skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(playerData.get(29)));
skillsDATS.put(AbilityType.TREE_FELLER, Integer.valueOf(playerData.get(30)));
// Repair 31 - Unused
skillsDATS.put(AbilityType.BERSERK, Integer.valueOf(playerData.get(32)));
skillsDATS.put(AbilityType.GREEN_TERRA, Integer.valueOf(playerData.get(33)));
skillsDATS.put(AbilityType.GIGA_DRILL_BREAKER, Integer.valueOf(playerData.get(34)));
// Archery 35 - Unused
skillsDATS.put(AbilityType.SERRATED_STRIKES, Integer.valueOf(playerData.get(36)));
skillsDATS.put(AbilityType.SKULL_SPLITTER, Integer.valueOf(playerData.get(37)));
// Acrobatics 38 - Unused
skillsDATS.put(AbilityType.BLAST_MINING, Integer.valueOf(playerData.get(39)));
if (experienceValues == null) { hudType = HudType.valueOf(playerData.get(40));
SQLDatabaseManager.write("INSERT INTO " + tablePrefix + "experience (user_id) VALUES (" + userId + ")"); mobHealthbarType = MobHealthbarType.valueOf(playerData.get(41));
mcMMO.p.getLogger().warning(playerName + "does not exist in the experience table. Their experience will be reset.");
}
else {
skillsXp.put(SkillType.TAMING, (float) Integer.valueOf(experienceValues.get(0)));
skillsXp.put(SkillType.MINING, (float) Integer.valueOf(experienceValues.get(1)));
skillsXp.put(SkillType.REPAIR, (float) Integer.valueOf(experienceValues.get(2)));
skillsXp.put(SkillType.WOODCUTTING, (float) Integer.valueOf(experienceValues.get(3)));
skillsXp.put(SkillType.UNARMED, (float) Integer.valueOf(experienceValues.get(4)));
skillsXp.put(SkillType.HERBALISM, (float) Integer.valueOf(experienceValues.get(5)));
skillsXp.put(SkillType.EXCAVATION, (float) Integer.valueOf(experienceValues.get(6)));
skillsXp.put(SkillType.ARCHERY, (float) Integer.valueOf(experienceValues.get(7)));
skillsXp.put(SkillType.SWORDS, (float) Integer.valueOf(experienceValues.get(8)));
skillsXp.put(SkillType.AXES, (float) Integer.valueOf(experienceValues.get(9)));
skillsXp.put(SkillType.ACROBATICS, (float) Integer.valueOf(experienceValues.get(10)));
skillsXp.put(SkillType.FISHING, (float) Integer.valueOf(experienceValues.get(11)));
}
loaded = true; loaded = true;
return true; return true;