From 81eadc14181b9af82188bd45005d07568e7ac3b3 Mon Sep 17 00:00:00 2001 From: bm01 Date: Sat, 9 Jun 2012 19:48:18 +0200 Subject: [PATCH] No longer use/save party name in database and users flat file --- .../nossr50/datatypes/PlayerProfile.java | 40 +++---------------- .../com/gmail/nossr50/party/PartyManager.java | 16 ++++++++ .../java/com/gmail/nossr50/util/Database.java | 1 - .../java/com/gmail/nossr50/util/Users.java | 2 +- 4 files changed, 23 insertions(+), 36 deletions(-) diff --git a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java index 7873bb4e9..737dea3cf 100644 --- a/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java +++ b/src/main/java/com/gmail/nossr50/datatypes/PlayerProfile.java @@ -70,6 +70,8 @@ public class PlayerProfile { this.player = player; this.playerName = player.getName(); + party = PartyManager.getInstance().getPlayerParty(playerName); + for (AbilityType abilityType : AbilityType.values()) { skillsDATS.put(abilityType, 0); } @@ -132,15 +134,12 @@ public class PlayerProfile { } } - HashMap> users = mcMMO.database.read("SELECT lastlogin, party FROM " + Config.getInstance().getMySQLTablePrefix() + "users WHERE id = " + userid); - //lastlogin = Integer.parseInt(users.get(1).get(0)); - party = PartyManager.getInstance().getParty(users.get(1).get(1)); - HashMap> cooldowns = mcMMO.database.read("SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes, blast_mining FROM " + Config.getInstance().getMySQLTablePrefix() + "cooldowns WHERE user_id = " + userid); - /* * I'm still learning MySQL, this is a fix for adding a new table * its not pretty but it works */ + HashMap> cooldowns = mcMMO.database.read("SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes, blast_mining FROM " + Config.getInstance().getMySQLTablePrefix() + "cooldowns WHERE user_id = " + userid); + if(cooldowns.get(1) == null) { mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "cooldowns (user_id) VALUES (" + userid + ")"); } @@ -209,13 +208,8 @@ public class PlayerProfile { continue; } - //Get Mining if (character.length > 1 && Misc.isInt(character[1])) skills.put(SkillType.MINING, Integer.valueOf(character[1])); - //Party - if (character.length > 3) - party = PartyManager.getInstance().getParty(character[3]); - //Mining XP if (character.length > 4 && Misc.isInt(character[4])) skillsXp.put(SkillType.MINING, Integer.valueOf(character[4])); if (character.length > 5 && Misc.isInt(character[5])) @@ -306,14 +300,6 @@ public class PlayerProfile { mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "huds SET hudtype = '" + hud.toString() + "' WHERE user_id = " + userid); mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "users SET lastlogin = " + timestamp.intValue() + " WHERE id = " + userid); - - String partyName = ""; - - if (party != null) { - partyName = party.getName(); - } - - mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "users SET party = '" + partyName + "' WHERE id = " + userid); mcMMO.database.write("UPDATE " + Config.getInstance().getMySQLTablePrefix() + "cooldowns SET " + " mining = " + skillsDATS.get(AbilityType.SUPER_BREAKER) + ", woodcutting = " + skillsDATS.get(AbilityType.TREE_FELLER) @@ -374,14 +360,7 @@ public class PlayerProfile { writer.append(playerName + ":"); writer.append(skills.get(SkillType.MINING) + ":"); writer.append("" + ":"); - - String partyName = ""; - - if (party != null) { - partyName = party.getName(); - } - - writer.append(partyName + ":"); + writer.append("" + ":"); writer.append(skillsXp.get(SkillType.MINING) + ":"); writer.append(skills.get(SkillType.WOODCUTTING) + ":"); writer.append(skillsXp.get(SkillType.WOODCUTTING) + ":"); @@ -443,14 +422,7 @@ public class PlayerProfile { out.append(playerName + ":"); out.append(0 + ":"); //mining out.append("" + ":"); - - String partyName = ""; - - if (party != null) { - partyName = party.getName(); - } - - out.append(partyName + ":"); + out.append("" + ":"); out.append(0 + ":"); //XP out.append(0 + ":"); //woodcutting out.append(0 + ":"); //woodCuttingXP diff --git a/src/main/java/com/gmail/nossr50/party/PartyManager.java b/src/main/java/com/gmail/nossr50/party/PartyManager.java index da32b3d4f..7aaa30f0b 100644 --- a/src/main/java/com/gmail/nossr50/party/PartyManager.java +++ b/src/main/java/com/gmail/nossr50/party/PartyManager.java @@ -166,6 +166,22 @@ public class PartyManager { return null; } + /** + * Retrieve a party by a member name + * + * @param playerName The member name + * @return the existing party, null otherwise + */ + public Party getPlayerParty(String playerName) { + for (Party party : parties) { + if (party.getMembers().contains(playerName)) { + return party; + } + } + + return null; + } + /** * Get a list of all current party names. * diff --git a/src/main/java/com/gmail/nossr50/util/Database.java b/src/main/java/com/gmail/nossr50/util/Database.java index bcbf978f0..1cb0aef75 100644 --- a/src/main/java/com/gmail/nossr50/util/Database.java +++ b/src/main/java/com/gmail/nossr50/util/Database.java @@ -69,7 +69,6 @@ public class Database { write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "users` (`id` int(10) unsigned NOT NULL AUTO_INCREMENT," + "`user` varchar(40) NOT NULL," + "`lastlogin` int(32) unsigned NOT NULL," - + "`party` varchar(100) NOT NULL DEFAULT ''," + "PRIMARY KEY (`id`)," + "UNIQUE KEY `user` (`user`)) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=1;"); write("CREATE TABLE IF NOT EXISTS `" + tablePrefix + "cooldowns` (`user_id` int(10) unsigned NOT NULL," diff --git a/src/main/java/com/gmail/nossr50/util/Users.java b/src/main/java/com/gmail/nossr50/util/Users.java index f3164ee95..3aba3a6b7 100644 --- a/src/main/java/com/gmail/nossr50/util/Users.java +++ b/src/main/java/com/gmail/nossr50/util/Users.java @@ -90,7 +90,7 @@ public class Users { */ public static void removeUser(String playerName) { for (Iterator it = profiles.iterator() ; it.hasNext() ; ) { - if (it.next().getPlayer().getName().equals(playerName)) { + if (it.next().getPlayerName().equals(playerName)) { it.remove(); return; }