mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-01-19 16:59:37 +01:00
Cleanup
This commit is contained in:
parent
3732db2226
commit
dfff0efc0b
@ -84,6 +84,7 @@ public class PlayerProfile {
|
|||||||
if (Config.getInstance().getUseMySQL()) {
|
if (Config.getInstance().getUseMySQL()) {
|
||||||
if (!loadMySQL() && addNew) {
|
if (!loadMySQL() && addNew) {
|
||||||
addMySQLPlayer();
|
addMySQLPlayer();
|
||||||
|
loaded = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!load() && addNew) {
|
else if (!load() && addNew) {
|
||||||
@ -94,7 +95,7 @@ public class PlayerProfile {
|
|||||||
lastlogin = ((Long) (System.currentTimeMillis() / 1000)).intValue();
|
lastlogin = ((Long) (System.currentTimeMillis() / 1000)).intValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Player getPlayer() {
|
public Player getlayer() {
|
||||||
return player;
|
return player;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -107,44 +108,43 @@ public class PlayerProfile {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean loadMySQL() {
|
public boolean loadMySQL() {
|
||||||
int id = 0;
|
userid = mcMMO.database.getInt("SELECT id FROM " + Config.getInstance().getMySQLTablePrefix() + "users WHERE user = '" + playerName + "'");
|
||||||
id = mcMMO.database.getInt("SELECT id FROM "+Config.getInstance().getMySQLTablePrefix()+"users WHERE user = '" + playerName + "'");
|
|
||||||
|
|
||||||
userid = id;
|
if (userid <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
HashMap<Integer, ArrayList<String>> huds = mcMMO.database.read("SELECT hudtype FROM " + Config.getInstance().getMySQLTablePrefix() + "huds WHERE user_id = " + userid);
|
||||||
|
|
||||||
if (id > 0) {
|
if (huds.get(1) == null) {
|
||||||
HashMap<Integer, ArrayList<String>> huds = mcMMO.database.read("SELECT hudtype FROM "+Config.getInstance().getMySQLTablePrefix()+"huds WHERE user_id = " + id);
|
mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "huds (user_id) VALUES (" + userid + ")");
|
||||||
if(huds.get(1) == null)
|
}
|
||||||
{
|
else {
|
||||||
mcMMO.database.write("INSERT INTO "+Config.getInstance().getMySQLTablePrefix()+"huds (user_id) VALUES ("+id+")");
|
if (huds.get(1).get(0) != null) {
|
||||||
} else {
|
for (HUDType x : HUDType.values()) {
|
||||||
if(huds.get(1).get(0) != null)
|
if (x.toString().equals(huds.get(1).get(0))) {
|
||||||
{
|
|
||||||
for(HUDType x : HUDType.values())
|
|
||||||
{
|
|
||||||
if(x.toString().equals(huds.get(1).get(0)))
|
|
||||||
{
|
|
||||||
hud = x;
|
hud = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
hud = SpoutConfig.getInstance().defaulthud;
|
hud = SpoutConfig.getInstance().defaulthud;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
HashMap<Integer, ArrayList<String>> users = mcMMO.database.read("SELECT lastlogin, party FROM "+Config.getInstance().getMySQLTablePrefix()+"users WHERE id = " + id);
|
|
||||||
|
HashMap<Integer, ArrayList<String>> users = mcMMO.database.read("SELECT lastlogin, party FROM " + Config.getInstance().getMySQLTablePrefix() + "users WHERE id = " + userid);
|
||||||
//lastlogin = Integer.parseInt(users.get(1).get(0));
|
//lastlogin = Integer.parseInt(users.get(1).get(0));
|
||||||
party = PartyManager.getInstance().getParty(users.get(1).get(1));
|
party = PartyManager.getInstance().getParty(users.get(1).get(1));
|
||||||
HashMap<Integer, ArrayList<String>> cooldowns = mcMMO.database.read("SELECT mining, woodcutting, unarmed, herbalism, excavation, swords, axes, blast_mining FROM "+Config.getInstance().getMySQLTablePrefix()+"cooldowns WHERE user_id = " + id);
|
HashMap<Integer, ArrayList<String>> 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
|
* I'm still learning MySQL, this is a fix for adding a new table
|
||||||
* its not pretty but it works
|
* its not pretty but it works
|
||||||
*/
|
*/
|
||||||
if(cooldowns.get(1) == null)
|
if(cooldowns.get(1) == null) {
|
||||||
{
|
mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "cooldowns (user_id) VALUES (" + userid + ")");
|
||||||
mcMMO.database.write("INSERT INTO "+Config.getInstance().getMySQLTablePrefix()+"cooldowns (user_id) VALUES ("+id+")");
|
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(cooldowns.get(1).get(0)));
|
skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(cooldowns.get(1).get(0)));
|
||||||
skillsDATS.put(AbilityType.TREE_FELLER, Integer.valueOf(cooldowns.get(1).get(1)));
|
skillsDATS.put(AbilityType.TREE_FELLER, Integer.valueOf(cooldowns.get(1).get(1)));
|
||||||
skillsDATS.put(AbilityType.BERSERK, Integer.valueOf(cooldowns.get(1).get(2)));
|
skillsDATS.put(AbilityType.BERSERK, Integer.valueOf(cooldowns.get(1).get(2)));
|
||||||
@ -154,7 +154,8 @@ public class PlayerProfile {
|
|||||||
skillsDATS.put(AbilityType.SKULL_SPLIITER, Integer.valueOf(cooldowns.get(1).get(6)));
|
skillsDATS.put(AbilityType.SKULL_SPLIITER, Integer.valueOf(cooldowns.get(1).get(6)));
|
||||||
skillsDATS.put(AbilityType.BLAST_MINING, Integer.valueOf(cooldowns.get(1).get(7)));
|
skillsDATS.put(AbilityType.BLAST_MINING, Integer.valueOf(cooldowns.get(1).get(7)));
|
||||||
}
|
}
|
||||||
HashMap<Integer, ArrayList<String>> stats = mcMMO.database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM "+Config.getInstance().getMySQLTablePrefix()+"skills WHERE user_id = " + id);
|
|
||||||
|
HashMap<Integer, ArrayList<String>> stats = mcMMO.database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM "+Config.getInstance().getMySQLTablePrefix()+"skills WHERE user_id = " + userid);
|
||||||
skills.put(SkillType.TAMING, Integer.valueOf(stats.get(1).get(0)));
|
skills.put(SkillType.TAMING, Integer.valueOf(stats.get(1).get(0)));
|
||||||
skills.put(SkillType.MINING, Integer.valueOf(stats.get(1).get(1)));
|
skills.put(SkillType.MINING, Integer.valueOf(stats.get(1).get(1)));
|
||||||
skills.put(SkillType.REPAIR, Integer.valueOf(stats.get(1).get(2)));
|
skills.put(SkillType.REPAIR, Integer.valueOf(stats.get(1).get(2)));
|
||||||
@ -167,7 +168,7 @@ public class PlayerProfile {
|
|||||||
skills.put(SkillType.AXES, Integer.valueOf(stats.get(1).get(9)));
|
skills.put(SkillType.AXES, Integer.valueOf(stats.get(1).get(9)));
|
||||||
skills.put(SkillType.ACROBATICS, Integer.valueOf(stats.get(1).get(10)));
|
skills.put(SkillType.ACROBATICS, Integer.valueOf(stats.get(1).get(10)));
|
||||||
skills.put(SkillType.FISHING, Integer.valueOf(stats.get(1).get(11)));
|
skills.put(SkillType.FISHING, Integer.valueOf(stats.get(1).get(11)));
|
||||||
HashMap<Integer, ArrayList<String>> experience = mcMMO.database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM "+Config.getInstance().getMySQLTablePrefix()+"experience WHERE user_id = " + id);
|
HashMap<Integer, ArrayList<String>> experience = mcMMO.database.read("SELECT taming, mining, repair, woodcutting, unarmed, herbalism, excavation, archery, swords, axes, acrobatics, fishing FROM "+Config.getInstance().getMySQLTablePrefix()+"experience WHERE user_id = " + userid);
|
||||||
skillsXp.put(SkillType.TAMING, Integer.valueOf(experience.get(1).get(0)));
|
skillsXp.put(SkillType.TAMING, Integer.valueOf(experience.get(1).get(0)));
|
||||||
skillsXp.put(SkillType.MINING, Integer.valueOf(experience.get(1).get(1)));
|
skillsXp.put(SkillType.MINING, Integer.valueOf(experience.get(1).get(1)));
|
||||||
skillsXp.put(SkillType.REPAIR, Integer.valueOf(experience.get(1).get(2)));
|
skillsXp.put(SkillType.REPAIR, Integer.valueOf(experience.get(1).get(2)));
|
||||||
@ -183,34 +184,30 @@ public class PlayerProfile {
|
|||||||
loaded = true;
|
loaded = true;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addMySQLPlayer() {
|
public void addMySQLPlayer() {
|
||||||
int id = 0;
|
|
||||||
mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "users (user, lastlogin) VALUES ('" + playerName + "'," + System.currentTimeMillis() / 1000 + ")");
|
mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "users (user, lastlogin) VALUES ('" + playerName + "'," + System.currentTimeMillis() / 1000 + ")");
|
||||||
id = mcMMO.database.getInt("SELECT id FROM "+Config.getInstance().getMySQLTablePrefix()+"users WHERE user = '" + playerName + "'");
|
userid = mcMMO.database.getInt("SELECT id FROM "+Config.getInstance().getMySQLTablePrefix() + "users WHERE user = '" + playerName + "'");
|
||||||
mcMMO.database.write("INSERT INTO "+Config.getInstance().getMySQLTablePrefix()+"cooldowns (user_id) VALUES ("+id+")");
|
mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "cooldowns (user_id) VALUES (" + userid + ")");
|
||||||
mcMMO.database.write("INSERT INTO "+Config.getInstance().getMySQLTablePrefix()+"skills (user_id) VALUES ("+id+")");
|
mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "skills (user_id) VALUES (" + userid + ")");
|
||||||
mcMMO.database.write("INSERT INTO "+Config.getInstance().getMySQLTablePrefix()+"experience (user_id) VALUES ("+id+")");
|
mcMMO.database.write("INSERT INTO " + Config.getInstance().getMySQLTablePrefix() + "experience (user_id) VALUES (" + userid + ")");
|
||||||
this.userid = id;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean load()
|
public boolean load() {
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
//Open the user file
|
//Open the user file
|
||||||
FileReader file = new FileReader(location);
|
FileReader file = new FileReader(location);
|
||||||
BufferedReader in = new BufferedReader(file);
|
BufferedReader in = new BufferedReader(file);
|
||||||
String line = "";
|
String line = "";
|
||||||
while((line = in.readLine()) != null)
|
|
||||||
{
|
while ((line = in.readLine()) != null) {
|
||||||
//Find if the line contains the player we want.
|
//Find if the line contains the player we want.
|
||||||
String[] character = line.split(":");
|
String[] character = line.split(":");
|
||||||
|
|
||||||
if(!character[0].equals(playerName)){continue;}
|
if (!character[0].equals(playerName)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
//Get Mining
|
//Get Mining
|
||||||
if (character.length > 1 && Misc.isInt(character[1]))
|
if (character.length > 1 && Misc.isInt(character[1]))
|
||||||
@ -275,12 +272,9 @@ public class PlayerProfile {
|
|||||||
skillsDATS.put(AbilityType.SKULL_SPLIITER, Integer.valueOf(character[31]));
|
skillsDATS.put(AbilityType.SKULL_SPLIITER, Integer.valueOf(character[31]));
|
||||||
if (character.length > 32)
|
if (character.length > 32)
|
||||||
skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(character[32]));
|
skillsDATS.put(AbilityType.SUPER_BREAKER, Integer.valueOf(character[32]));
|
||||||
if(character.length > 33)
|
if (character.length > 33) {
|
||||||
{
|
for (HUDType x : HUDType.values()) {
|
||||||
for(HUDType x : HUDType.values())
|
if (x.toString().equalsIgnoreCase(character[33])) {
|
||||||
{
|
|
||||||
if(x.toString().equalsIgnoreCase(character[33]))
|
|
||||||
{
|
|
||||||
hud = x;
|
hud = x;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -291,10 +285,13 @@ public class PlayerProfile {
|
|||||||
skillsXp.put(SkillType.FISHING, Integer.valueOf(character[35]));
|
skillsXp.put(SkillType.FISHING, Integer.valueOf(character[35]));
|
||||||
if (character.length > 36)
|
if (character.length > 36)
|
||||||
skillsDATS.put(AbilityType.BLAST_MINING, Integer.valueOf(character[36]));
|
skillsDATS.put(AbilityType.BLAST_MINING, Integer.valueOf(character[36]));
|
||||||
in.close();
|
|
||||||
loaded = true;
|
loaded = true;
|
||||||
|
|
||||||
|
in.close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
in.close();
|
in.close();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
mcMMO.p.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString());
|
mcMMO.p.getLogger().severe("Exception while reading " + location + " (Are you sure you formatted it correctly?)" + e.toString());
|
||||||
@ -436,27 +433,7 @@ public class PlayerProfile {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetAllData() {
|
public void addPlayer() {
|
||||||
//This will reset everything to default values and then save the information to FlatFile/MySQL
|
|
||||||
for (SkillType skillType : SkillType.values()) {
|
|
||||||
if (skillType != SkillType.ALL) {
|
|
||||||
skills.put(skillType, 0);
|
|
||||||
skillsXp.put(skillType, 0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (AbilityType abilityType : AbilityType.values()) {
|
|
||||||
skillsDATS.put(abilityType, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
//Misc stuff
|
|
||||||
party = null;
|
|
||||||
|
|
||||||
save();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addPlayer()
|
|
||||||
{
|
|
||||||
try {
|
try {
|
||||||
//Open the file to write the player
|
//Open the file to write the player
|
||||||
FileWriter file = new FileWriter(location, true);
|
FileWriter file = new FileWriter(location, true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user