Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- try {
- String name = playerCommand.split(" ")[2];
- int points Integer.parseInt(playerCommand.split(" ")[1])
- Client c2 = PlayerHandler.getPlayerByName(name);
- if (c2 != null) {
- c2.slayerPoints += points;
- c.sendMessage(Added + points + " Slayer Points to " + Misc.formatPlayerName(c2.playerName));
- return;
- }
- c.sendMessage("Player is offline, modifying offline player.");
- FileInputStream fstream = new FileInputStream("./Data/characters/" + name + ".txt");
- BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
- String strLine;
- StringBuilder fileContent = new StringBuilder();
- //Read File Line By Line
- while ((strLine = br.readLine()) != null) {
- // Print the content on the console
- System.out.println(strLine);
- String tokens[] = strLine.split(" = ");
- if (tokens.length > 0) {
- // Here tokens[0] will have value of ID
- if (tokens[0].equals("slayerPoints")) {
- tokens[1] = (Integer.parseInt(tokens[1]) + points);
- String newLine = tokens[0] + " = " + tokens[1];
- fileContent.append(newLine);
- fileContent.append("\n");
- } else {
- // update content as it is
- fileContent.append(strLine);
- fileContent.append("\n");
- }
- }
- }
- // Now fileContent will have updated content , which you can override into file
- FileWriter fstreamWrite = new FileWriter("./Data/characters/" + name + ".txt");
- BufferedWriter out = new BufferedWriter(fstreamWrite);
- out.write(fileContent.toString());
- out.close();
- //Close the input stream
- in.close();
- } catch (Exception e) {//Catch exception if any
- System.err.println("Error: " + e.getMessage());
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement