Dreamliner Posted November 3, 2013 Share Posted November 3, 2013 (edited) User.java public class User { private int atkxp = 0; private int strxp = 0; private int defxp = 0; private int hpxp = 0; private int time = 0; private String name = null; public User(String name, int time, int atk, int str, int def, int hp) { this.setName(name); this.setTime(time); this.setAtkxp(atk); this.setStrxp(str); this.setDefxp(def); this.setHpxp(hp); } public int getAtkxp() { return atkxp; } public void setAtkxp(int atkxp) { this.atkxp = atkxp; } public int getStrxp() { return strxp; } public void setStrxp(int strxp) { this.strxp = strxp; } public int getDefxp() { return defxp; } public void setDefxp(int defxp) { this.defxp = defxp; } public int getHpxp() { return hpxp; } public void setHpxp(int hpxp) { this.hpxp = hpxp; } public int getTime() { return time; } public void setTime(int time) { this.time = time; } public String getName() { return name; } public void setName(String name) { this.name = name; } } UserManager.java import java.io.File; import java.io.IOException; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.OutputKeys; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerConfigurationException; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.xml.sax.SAXException; public class UserManager { public UserManager() { } public void saveUser(User u, int time, int atkxp, int strxp, int hpxp, int defxp) { File dir = new File("C:/Users/" + System.getProperty("user.name") + "/OSBot/Scripts/Dreamliner/MonsterKiller"); if (!dir.exists()) { dir.mkdirs(); } File file = new File("C:/Users/" + System.getProperty("user.name") + "/OSBot/Scripts/Dreamliner/MonsterKiller/" + u.getName() + ".xml"); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = null; try { db = dbf.newDocumentBuilder(); Document d = db.newDocument(); Element root = d.createElement("user"); d.appendChild(root); Element e_atk = d.createElement("atkxp"); e_atk.setTextContent(Integer.toString(u.getAtkxp() + atkxp)); root.appendChild(e_atk); Element e_str = d.createElement("strxp"); e_str.setTextContent(Integer.toString(u.getStrxp() + strxp)); root.appendChild(e_str); Element e_def = d.createElement("defxp"); e_def.setTextContent(Integer.toString(u.getDefxp() + defxp)); root.appendChild(e_def); Element e_hp = d.createElement("hpxp"); e_hp.setTextContent(Integer.toString(u.getHpxp() + hpxp)); root.appendChild(e_hp); Element e_time = d.createElement("time"); e_time.setTextContent(Integer.toString(u.getTime() + time)); root.appendChild(e_time); prettyPrint(d, file); } catch (TransformerConfigurationException e) { System.out.println("1"); } catch (TransformerException e) { System.out.println("2"); } catch (ParserConfigurationException e) { System.out.println("3"); } catch (Exception e) { } } public User loadUser(String user) { File file = new File("C:/Users/" + System.getProperty("user.name") + "/OSBot/Scripts/Dreamliner/MonsterKiller/" + user + ".xml"); int atkxp = 0; int strxp = 0; int defxp = 0; int hpxp = 0; int time = 0; if (file.exists()) { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db; try { db = dbf.newDocumentBuilder(); Document d; try { d = db.parse(file); atkxp = Integer.parseInt(d.getElementsByTagName("atkxp").item(0).getTextContent()); strxp = Integer.parseInt(d.getElementsByTagName("strxp").item(0).getTextContent()); defxp = Integer.parseInt(d.getElementsByTagName("defxp").item(0).getTextContent()); hpxp = Integer.parseInt(d.getElementsByTagName("hpxp").item(0).getTextContent()); time = Integer.parseInt(d.getElementsByTagName("time").item(0).getTextContent()); } catch (SAXException e) { } catch (IOException e) { } } catch (ParserConfigurationException e) { } } User u = new User(user, time, atkxp, strxp, defxp, hpxp); return u; } public static final void prettyPrint(Document xml, File file) throws Exception { Transformer tf = TransformerFactory.newInstance().newTransformer(); tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); tf.setOutputProperty(OutputKeys.INDENT, "yes"); StreamResult sr = new StreamResult(file); tf.transform(new DOMSource(xml), sr); } } How to use public UserManager um = new UserManager(); public User user = null; String un = this.client.instance.getUsername(); if (un != null) { this.user = um.loadUser(this.client.instance.getUsername()); this.loaded = true; } um.saveUser(this.user, t3, this.pu.getAtkGained(), this.pu.getStrGained(), this.pu.getHPGained(), this.pu.getDefGained()); you get this<?xml version="1.0" encoding="UTF-8" standalone="no"?> <user> <atkxp>102560</atkxp> <strxp>125268</strxp> <defxp>102561</defxp> <hpxp>110114</hpxp> <time>18778</time> </user> Edited November 3, 2013 by dreamliner Link to comment Share on other sites More sharing options...
Assume Posted November 4, 2013 Share Posted November 4, 2013 (edited) This is a bad system as it only works with Windows. Also just use ObjectOutput/Input Streams to serialize and deserialze the object you store all the information in. If you insist on plain text, you can all use the Properties class. It generate more readable text than XML. Edited November 4, 2013 by Assume Link to comment Share on other sites More sharing options...
GoldenGates Posted November 4, 2013 Share Posted November 4, 2013 I use XML but in a different/more efficient manner. Good release though, better than nothing. Link to comment Share on other sites More sharing options...
LifezHatred Posted November 4, 2013 Share Posted November 4, 2013 This is a bad system as it only works with Windows. Also just use ObjectOutput/Input Streams to serialize and deserialze the object you store all the information in. If you insist on plain text, you can all use the Properties class. It generate more readable text than XML. System isn't bad... Link to comment Share on other sites More sharing options...
Assume Posted November 4, 2013 Share Posted November 4, 2013 This is a bad system as it only works with Windows. Also just use ObjectOutput/Input Streams to serialize and deserialze the object you store all the information in. If you insist on plain text, you can all use the Properties class. It generate more readable text than XML. System isn't bad... A platform dependent system running inside of a platform independent system is bad. Link to comment Share on other sites More sharing options...
LifezHatred Posted November 4, 2013 Share Posted November 4, 2013 This is a bad system as it only works with Windows. Also just use ObjectOutput/Input Streams to serialize and deserialze the object you store all the information in. If you insist on plain text, you can all use the Properties class. It generate more readable text than XML. System isn't bad... A platform dependent system running inside of a platform independent system is bad. Wait im confused what makes this only work on Windows? please clarify your statement Link to comment Share on other sites More sharing options...
Assume Posted November 4, 2013 Share Posted November 4, 2013 This is a bad system as it only works with Windows. Also just use ObjectOutput/Input Streams to serialize and deserialze the object you store all the information in. If you insist on plain text, you can all use the Properties class. It generate more readable text than XML. System isn't bad... A platform dependent system running inside of a platform independent system is bad. Wait im confused what makes this only work on Windows? please clarify your statement It saves to C:/Users/USER_NAME Linux and Unix(Mac OSX) do not use this file scheme. Link to comment Share on other sites More sharing options...
LifezHatred Posted November 4, 2013 Share Posted November 4, 2013 (edited) This is a bad system as it only works with Windows. Also just use ObjectOutput/Input Streams to serialize and deserialze the object you store all the information in. If you insist on plain text, you can all use the Properties class. It generate more readable text than XML. System isn't bad... A platform dependent system running inside of a platform independent system is bad. Wait im confused what makes this only work on Windows? please clarify your statement It saves to C:/Users/USER_NAME Linux and Unix(Mac OSX) do not use this file scheme. LMFAO your joking right? You simply change the directory location (the string) honestly haha thats funny infact that has nothing to do with the function of the code itself, thats just telling the jvm where to put the file (Which your suppose to enter manually anyways) Edited November 4, 2013 by LifezHatred Link to comment Share on other sites More sharing options...
Assume Posted November 4, 2013 Share Posted November 4, 2013 This is a bad system as it only works with Windows. Also just use ObjectOutput/Input Streams to serialize and deserialze the object you store all the information in. If you insist on plain text, you can all use the Properties class. It generate more readable text than XML. System isn't bad... A platform dependent system running inside of a platform independent system is bad. Wait im confused what makes this only work on Windows? please clarify your statement It saves to C:/Users/USER_NAME Linux and Unix(Mac OSX) do not use this file scheme. LMFAO your joking right? You simply change the directory location (the string) honestly haha thats funny infact that has nothing to do with the function of the code itself, thats just telling the jvm where to put the file (Which your suppose to enter manually anyways) No, it should dynamically figure it out itself. It should not rely on user input. I was purely commenting on what was posted, not what was possible to be added. He should of used System.getProperty("os.name") and used a switch statement to convert the file location to the correct one. He did not do this so it is not compatible with any OS other than Windows in it's current form. Link to comment Share on other sites More sharing options...
LifezHatred Posted November 4, 2013 Share Posted November 4, 2013 (edited) This is a bad system as it only works with Windows. Also just use ObjectOutput/Input Streams to serialize and deserialze the object you store all the information in. If you insist on plain text, you can all use the Properties class. It generate more readable text than XML. System isn't bad... A platform dependent system running inside of a platform independent system is bad. Wait im confused what makes this only work on Windows? please clarify your statement It saves to C:/Users/USER_NAME Linux and Unix(Mac OSX) do not use this file scheme. LMFAO your joking right? You simply change the directory location (the string) honestly haha thats funny infact that has nothing to do with the function of the code itself, thats just telling the jvm where to put the file (Which your suppose to enter manually anyways) No, it should dynamically figure it out itself. It should not rely on user input. I was purely commenting on what was posted, not what was possible to be added. He should of used System.getProperty("os.name") and used a switch statement to convert the file location to the correct one. He did not do this so it is not compatible with any OS other than Windows in it's current form. Honestly because it is not your way, doesn't make it wrong/bad. It is perfectly fine and functional and can work on other machines with minimal editing (One string) You over complicated this more than it should If you want it to work on other machines all you do is change ("C:/Users/") in the locations to work with your machine Edited November 4, 2013 by LifezHatred Link to comment Share on other sites More sharing options...
Assume Posted November 4, 2013 Share Posted November 4, 2013 This is a bad system as it only works with Windows. Also just use ObjectOutput/Input Streams to serialize and deserialze the object you store all the information in. If you insist on plain text, you can all use the Properties class. It generate more readable text than XML.System isn't bad... A platform dependent system running inside of a platform independent system is bad. Wait im confused what makes this only work on Windows?please clarify your statement It saves to C:/Users/USER_NAMELinux and Unix(Mac OSX) do not use this file scheme. LMFAO your joking right?You simply change the directory location (the string) honestly haha thats funny infact that has nothing to do with the function of the code itself, thats just telling the jvm where to put the file (Which your suppose to enter manually anyways) No, it should dynamically figure it out itself. It should not rely on user input. I was purely commenting on what was posted, not what was possible to be added. He should of used System.getProperty("os.name") and used a switch statement to convert the file location to the correct one. He did not do this so it is not compatible with any OS other than Windows in it's current form. Honestly because it is not your way, doesn't make it wrong/bad.It is perfectly fine and functional and can work on other machines with minimal editing (One string) You over complicated this more than it should If you want it to work on other machines all you do is change ("C:/Users/") in the locations to work with your machine getProperty("os.name") allows you to do this without the user selecting their OS. Obviously it is better. Link to comment Share on other sites More sharing options...
LifezHatred Posted November 4, 2013 Share Posted November 4, 2013 This is a bad system as it only works with Windows. Also just use ObjectOutput/Input Streams to serialize and deserialze the object you store all the information in. If you insist on plain text, you can all use the Properties class. It generate more readable text than XML.System isn't bad... A platform dependent system running inside of a platform independent system is bad. Wait im confused what makes this only work on Windows?please clarify your statement It saves to C:/Users/USER_NAMELinux and Unix(Mac OSX) do not use this file scheme. LMFAO your joking right?You simply change the directory location (the string) honestly haha thats funny infact that has nothing to do with the function of the code itself, thats just telling the jvm where to put the file (Which your suppose to enter manually anyways) No, it should dynamically figure it out itself. It should not rely on user input. I was purely commenting on what was posted, not what was possible to be added. He should of used System.getProperty("os.name") and used a switch statement to convert the file location to the correct one. He did not do this so it is not compatible with any OS other than Windows in it's current form. Honestly because it is not your way, doesn't make it wrong/bad.It is perfectly fine and functional and can work on other machines with minimal editing (One string) You over complicated this more than it should If you want it to work on other machines all you do is change ("C:/Users/") in the locations to work with your machine getProperty("os.name") allows you to do this without the user selecting their OS. Obviously it is better. So let me get this right? your coming in here bitching about one line of code or wait infact, not even a line but a simple part of a line. whateve its not bad in my eyes, nothing wrong with it in my eyes Link to comment Share on other sites More sharing options...
Assume Posted November 4, 2013 Share Posted November 4, 2013 This is a bad system as it only works with Windows. Also just use ObjectOutput/Input Streams to serialize and deserialze the object you store all the information in. If you insist on plain text, you can all use the Properties class. It generate more readable text than XML.System isn't bad... A platform dependent system running inside of a platform independent system is bad. Wait im confused what makes this only work on Windows?please clarify your statement It saves to C:/Users/USER_NAMELinux and Unix(Mac OSX) do not use this file scheme. LMFAO your joking right?You simply change the directory location (the string) honestly haha thats funny infact that has nothing to do with the function of the code itself, thats just telling the jvm where to put the file (Which your suppose to enter manually anyways) No, it should dynamically figure it out itself. It should not rely on user input. I was purely commenting on what was posted, not what was possible to be added. He should of used System.getProperty("os.name") and used a switch statement to convert the file location to the correct one. He did not do this so it is not compatible with any OS other than Windows in it's current form. Honestly because it is not your way, doesn't make it wrong/bad.It is perfectly fine and functional and can work on other machines with minimal editing (One string) You over complicated this more than it should If you want it to work on other machines all you do is change ("C:/Users/") in the locations to work with your machine getProperty("os.name") allows you to do this without the user selecting their OS. Obviously it is better. So let me get this right? your coming in here bitching about one line of code or wait infact, not even a line but a simple part of a line.whateve its not bad in my eyes, nothing wrong with it in my eyes Anything that requires user input when it can be done without user input is bad. Link to comment Share on other sites More sharing options...
Dreamliner Posted November 4, 2013 Author Share Posted November 4, 2013 This is a bad system as it only works with Windows. Also just use ObjectOutput/Input Streams to serialize and deserialze the object you store all the information in. If you insist on plain text, you can all use the Properties class. It generate more readable text than XML.System isn't bad... A platform dependent system running inside of a platform independent system is bad. Wait im confused what makes this only work on Windows? please clarify your statement It saves to C:/Users/USER_NAME Linux and Unix(Mac OSX) do not use this file scheme. LMFAO your joking right? You simply change the directory location (the string) honestly haha thats funny infact that has nothing to do with the function of the code itself, thats just telling the jvm where to put the file (Which your suppose to enter manually anyways) No, it should dynamically figure it out itself. It should not rely on user input. I was purely commenting on what was posted, not what was possible to be added. He should of used System.getProperty("os.name") and used a switch statement to convert the file location to the correct one. He did not do this so it is not compatible with any OS other than Windows in it's current form. Honestly because it is not your way, doesn't make it wrong/bad. It is perfectly fine and functional and can work on other machines with minimal editing (One string) You over complicated this more than it should If you want it to work on other machines all you do is change ("C:/Users/") in the locations to work with your machine getProperty("os.name") allows you to do this without the user selecting their OS. Obviously it is better. I don't use linux or mac. I have no need to check an extra line for something I never use. Anyone who scripts here, especially on mac or linux can figure out how to save files them selves. And last time I checked, OSBot has compatibility issues on mac. Link to comment Share on other sites More sharing options...
Dreamliner Posted November 4, 2013 Author Share Posted November 4, 2013 I use XML but in a different/more efficient manner. Good release though, better than nothing. Care to share? Link to comment Share on other sites More sharing options...