mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 21:26:46 +01:00
Alternative SQL player loading
This commit is contained in:
parent
fca5f9ec98
commit
fb450671d6
@ -287,81 +287,93 @@ public class PlayerProfile {
|
||||
private boolean loadMySQL() {
|
||||
String tablePrefix = Config.getInstance().getMySQLTablePrefix();
|
||||
|
||||
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 (playerData.size() == 0) {
|
||||
userId = SQLDatabaseManager.getInt("SELECT id FROM " + tablePrefix + "users WHERE user = '" + playerName + "'");
|
||||
|
||||
// Check if user doesn't exist
|
||||
if (userId == 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ArrayList<String> hudValues = SQLDatabaseManager.read("SELECT hudtype, mobhealthbar FROM " + tablePrefix + "huds WHERE user_id = " + userId).get(1);
|
||||
// Write missing table rows
|
||||
SQLDatabaseManager.write("INSERT IGNORE INTO " + tablePrefix + "skills (user_id) VALUES (" + userId + ")");
|
||||
SQLDatabaseManager.write("INSERT IGNORE INTO " + tablePrefix + "experience (user_id) VALUES (" + userId + ")");
|
||||
SQLDatabaseManager.write("INSERT IGNORE INTO " + tablePrefix + "cooldowns (user_id) VALUES (" + userId + ")");
|
||||
SQLDatabaseManager.write("INSERT IGNORE INTO " + tablePrefix + "huds (user_id, mobhealthbar) VALUES (" + userId + ",'" + mobHealthbarType.name() + "')");
|
||||
|
||||
if (hudValues == null) {
|
||||
SQLDatabaseManager.write("INSERT INTO " + tablePrefix + "huds (user_id, mobhealthbar) VALUES (" + userId + ",'" + mobHealthbarType.name() + "')");
|
||||
mcMMO.p.getLogger().warning(playerName + " does not exist in the HUD table. Their HUDs will be reset.");
|
||||
}
|
||||
else {
|
||||
hudType = HudType.valueOf(hudValues.get(0));
|
||||
mobHealthbarType = MobHealthbarType.valueOf(hudValues.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);
|
||||
}
|
||||
|
||||
ArrayList<String> cooldownValues = SQLDatabaseManager.read("SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes, blast_mining FROM " + tablePrefix + "cooldowns WHERE user_id = " + userId).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) {
|
||||
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.");
|
||||
}
|
||||
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_SPLITTER, Integer.valueOf(cooldownValues.get(6)));
|
||||
skillsDATS.put(AbilityType.BLAST_MINING, Integer.valueOf(cooldownValues.get(7)));
|
||||
}
|
||||
userId = Integer.valueOf(playerData.get(0));
|
||||
|
||||
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);
|
||||
// UserName 1 - Already loaded
|
||||
// LastLogin 2 - Doesn't need to be loaded
|
||||
// PartyName 3 - Loaded elsewhere I believe
|
||||
|
||||
if (statValues == null) {
|
||||
SQLDatabaseManager.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)));
|
||||
}
|
||||
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)));
|
||||
|
||||
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);
|
||||
skillsXp.put(SkillType.TAMING, (float) Integer.valueOf(playerData.get(16)));
|
||||
skillsXp.put(SkillType.MINING, (float) Integer.valueOf(playerData.get(17)));
|
||||
skillsXp.put(SkillType.REPAIR, (float) Integer.valueOf(playerData.get(18)));
|
||||
skillsXp.put(SkillType.WOODCUTTING, (float) Integer.valueOf(playerData.get(19)));
|
||||
skillsXp.put(SkillType.UNARMED, (float) Integer.valueOf(playerData.get(20)));
|
||||
skillsXp.put(SkillType.HERBALISM, (float) Integer.valueOf(playerData.get(21)));
|
||||
skillsXp.put(SkillType.EXCAVATION, (float) Integer.valueOf(playerData.get(22)));
|
||||
skillsXp.put(SkillType.ARCHERY, (float) Integer.valueOf(playerData.get(23)));
|
||||
skillsXp.put(SkillType.SWORDS, (float) Integer.valueOf(playerData.get(24)));
|
||||
skillsXp.put(SkillType.AXES, (float) Integer.valueOf(playerData.get(25)));
|
||||
skillsXp.put(SkillType.ACROBATICS, (float) Integer.valueOf(playerData.get(26)));
|
||||
skillsXp.put(SkillType.FISHING, (float) Integer.valueOf(playerData.get(27)));
|
||||
|
||||
if (experienceValues == null) {
|
||||
SQLDatabaseManager.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, (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)));
|
||||
}
|
||||
// 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)));
|
||||
|
||||
hudType = HudType.valueOf(playerData.get(40));
|
||||
mobHealthbarType = MobHealthbarType.valueOf(playerData.get(41));
|
||||
|
||||
loaded = true;
|
||||
return true;
|
||||
|
Loading…
Reference in New Issue
Block a user