Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package backend;
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import java.io.InputStreamReader;
- import java.io.RandomAccessFile;
- import java.nio.channels.FileChannel;
- import java.nio.channels.FileLock;
- import java.util.ArrayList;
- import ui.Error_Screen;
- public class Methods {
- static String path = System.getProperty("user.home") + File.separator
- + "OSBot" + File.separator + "data" + File.separator + "btm.txt";
- public static String[] getAccountNames() throws Throwable {
- if (statsAreValid()) {
- return readBotStats((path), 1).toArray(new String[0]);
- }
- return null;
- }
- public static String[] getScriptNames() throws Throwable {
- if (statsAreValid()) {
- return readBotStats((path), 0).toArray(new String[0]);
- }
- return null;
- }
- public static String[] getXpph() throws Throwable {
- if (statsAreValid()) {
- return readBotStats((path), 3).toArray(new String[0]);
- }
- return null;
- }
- public static String[] getXp() throws Throwable {
- if (statsAreValid()) {
- return readBotStats((path), 2).toArray(new String[0]);
- }
- return null;
- }
- /*
- * The path can be found in the writing method but also you need to add ","
- * after String so name+","+time+","+xpgained;
- */
- public static ArrayList<String> readBotStats(String Path, int index)
- throws Throwable {
- if (new File(Path).exists()) {
- BufferedReader br = new BufferedReader(new FileReader(
- new File(Path)));
- ArrayList<String> settings = new ArrayList<String>();
- String line;
- while ((line = br.readLine()) != null) {
- String tokens[] = (line.split(",", 4));
- settings.add(tokens[index].trim());
- }
- br.close();
- return settings;
- }
- Error_Screen.showScreen();
- return null;
- }
- /*
- * Method needs to be used like so Account name,Timerunning,Xp-Gained
- */
- public static void addAccount(String... settings)
- throws IOException {
- File file = new File(path);
- FileWriter f = new FileWriter(file, true);
- RandomAccessFile randomAccessFile = new RandomAccessFile(file, "rw");
- FileChannel channel = randomAccessFile.getChannel();
- FileLock lock = channel.lock();
- for (String setting : settings) {
- f.write(setting + System.getProperty("line.separator"));
- }
- lock.release();
- channel.close();
- randomAccessFile.close();
- f.close();
- }
- public static boolean statsAreValid() {
- return (new File((path)).exists());
- }
- public static File getFile() {
- if (statsAreValid())
- return (new File((path)));
- return null;
- }
- public static void removeAccount(String acc) throws IOException {
- if (statsAreValid()) {
- FileInputStream fstream = new FileInputStream(path);
- BufferedReader br = new BufferedReader(new InputStreamReader(
- fstream));
- String strLine;
- StringBuilder fileContent = new StringBuilder();
- while ((strLine = br.readLine()) != null) {
- String lines[] = strLine.split(",");
- if (lines[1].equalsIgnoreCase(acc)) {
- fileContent.append("");
- } else {
- fileContent.append(strLine + System.lineSeparator());
- }
- }
- FileWriter fstreamWrite = new FileWriter((path));
- BufferedWriter out = new BufferedWriter(fstreamWrite);
- out.write(fileContent.toString());
- out.close();
- br.close();
- }
- }
- public static void updateAccount(String account_name, String settings)
- throws IOException {
- FileInputStream fstream = new FileInputStream(path);
- BufferedReader br = new BufferedReader(new InputStreamReader(fstream));
- String strLine;
- StringBuilder fileContent = new StringBuilder();
- while ((strLine = br.readLine()) != null) {
- String lines[] = strLine.split(",");
- if (lines[1].equalsIgnoreCase(account_name)) {
- String newLine = settings;
- fileContent.append(newLine + System.lineSeparator());
- } else {
- fileContent.append(strLine + System.lineSeparator());
- }
- }
- FileWriter fstreamWrite = new FileWriter((path));
- BufferedWriter out = new BufferedWriter(fstreamWrite);
- out.write(fileContent.toString());
- out.close();
- br.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement