Thread: [PI] Updating Character files while they are offline

Results 1 to 5 of 5
  1. #1 [PI] Updating Character files while they are offline 
    arrowzftw
    Guest
    Add in PlayerSave.java

    Code:
        public static void updateCharString(String charName, String lineContains, String replaceWith) {
            String filePath = "./data/characters/"+charName+".txt";
            try {
    
                FileReader charFile = new FileReader(filePath);
                BufferedReader br = new BufferedReader(charFile);
                String line1 = br.readLine();
                while (line1 != null) {
                    if (line1.trim().contains(lineContains)) {
    
                        line1 = replaceWith;
                    }
                    BufferedWriter out = new BufferedWriter(new FileWriter(filePath + ".tmp", true));
                    out.write(line1);
                    out.newLine();
                    out.close();
    
                    line1 = br.readLine();
                }
                br.close();
                charFile.close();
            } catch (Exception e) {
                e.printStackTrace();
            }
            File file = new File(filePath);
            file.delete();
            File file2 = new File(filePath + ".tmp");
            file2.renameTo(file);
        }
    Usage:
    PlayerSave.updateCharString("arrowzftw, "special-amount", "special-amount = 100");

    What this will do is replace all lines that contain special-amount with special-amount = 100

    So if i had in my file:
    special-amount = 10000;

    It'll be replaced with:
    special-amount = 100

    Useful for something like an automated lottery.
    Reply With Quote  
     

  2. Thankful users:


  3. #2  
    GANGNAM STYLE!

    Ohad's Avatar
    Join Date
    Aug 2011
    Posts
    3,182
    Thanks given
    152
    Thanks received
    352
    Rep Power
    1671
    Nice, thanks
    [Only registered and activated users can see links. ]
    Reply With Quote  
     

  4. #3  
    The One And Only

    KaiserCo's Avatar
    Join Date
    Dec 2010
    Posts
    2,420
    Thanks given
    509
    Thanks received
    445
    Rep Power
    209
    Thanks, used.
    Reply With Quote  
     

  5. #4  
    Registered Member
    Freezia's Avatar
    Join Date
    Feb 2011
    Posts
    5,869
    Thanks given
    1,145
    Thanks received
    757
    Rep Power
    1309
    Thanks going to use this


    Click above to get the cheapest WEB HOSTING options! We also provide VIRTUAL PRIVATE SERVERS (VPS)! Now equipped with DDOS Protection.


    Reply With Quote  
     

  6. #5  
    Registered Member
    Wale's Avatar
    Join Date
    Jul 2011
    Posts
    921
    Thanks given
    279
    Thanks received
    149
    Rep Power
    238
    nice work
    [CENTER][Only registered and activated users can see links. ]
    Reply With Quote  
     


Thread Information
Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)


User Tag List

Similar Threads

  1. PI Character Files
    By TehOne in forum Help
    Replies: 4
    Last Post: 12-31-2010, 01:19 AM
  2. Replies: 32
    Last Post: 09-01-2010, 01:17 AM
  3. Updating Files
    By King in forum Help
    Replies: 5
    Last Post: 10-12-2009, 12:59 AM
  4. Updating Files
    By King in forum Requests
    Replies: 0
    Last Post: 10-12-2009, 12:33 AM
  5. Help With My Character Files...
    By Alwaysstuck1 in forum Configuration
    Replies: 9
    Last Post: 01-02-2009, 02:04 AM
Posting Permissions
  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •