Need MAJOR help.

Discussion in 'Plugin Development' started by Joey Clover, Mar 19, 2011.

Thread Status:
Not open for further replies.
  1. Offline

    Joey Clover

  2. Offline

    Sammy

    Make a flat file were you store the values and grab them, look at this example of my currency plugin:
    Code:
        private static final Logger log = Logger.getLogger("Minecraft");
        private static final File accounts = new File("plugins/RPGmod/currency/accounts.txt");
    
        public boolean hasAccount(Player p) {
            Properties prop = new Properties();
            String Key = p.getName();
            try {
                FileInputStream in = new FileInputStream(accounts);
                prop.load(in);
                if (prop.containsKey(Key)) {
                    return true;
                }
            } catch (IOException ex) {
                log.log(Level.INFO, ex.getMessage());
            }
            return false;
        }
    
        public void MakeAccount(Player p, ArrayList<Integer> initialvalues) {
            Properties prop = new Properties();
            String Key = p.getName();
            try {
                FileInputStream in = new FileInputStream(accounts);
                prop.load(in);
                prop.put(Key, initialvalues.get(0).toString() + ";" + initialvalues.get(1).toString() + ";" + initialvalues.get(2).toString());
                prop.store(new FileOutputStream(accounts), "[Name]=Money;Bones;Slimes");
            } catch (Exception ex) {
                log.log(Level.INFO, ex.getMessage());
            }
        }
    
        public int GetMoney(Player p) {
            Properties prop = new Properties();
            String Key = p.getName();
            try {
                FileInputStream in = new FileInputStream(accounts);
                prop.load(in);
                String values = prop.getProperty(Key);
                String[] money = values.split(";");
                return Integer.parseInt(money[0]);
            } catch (Exception ex) {
                log.log(Level.INFO, ex.getMessage());
            }
            return 0;
    
    
     
  3. Offline

    Joey Clover

    Hmm. Could try that I suppose. Thanks!
     
  4. Offline

    Sammy

    If you don't like my solution go suck a lemon ihihi jkd
    I think this is the way everyone uses ;)
    If you are thinking of databases forget it, you don't need it for that ^^
     
Thread Status:
Not open for further replies.

Share This Page