Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.BufferedReader;
- import java.io.BufferedWriter;
- import java.io.File;
- import java.io.FileReader;
- import java.io.FileWriter;
- import java.io.IOException;
- import org.osbot.rs07.script.Script;
- /**
- *
- * @author Jimmy
- *
- * In order for this to work you need to have -norandoms enabled
- *
- * The only way to remove a line from a file is to delete the file entirely and only
- * write in the lines from the old file that you wanted to keep.
- *
- *
- */
- public class MainScript extends Script {
- private String username, password;
- private boolean accountBanned;
- @Override
- public void onStart() {
- readInAccount();
- }
- @Override
- public int onLoop() throws InterruptedException {
- if(!getClient().isLoggedIn() && !accountBanned) {
- login();
- } else {
- readInAccount();
- }
- return 0;
- }
- /**
- * Logins into the account
- */
- private void login() {
- LoginEvent loginEvent = new LoginEvent(username, password);
- execute(loginEvent);
- }
- /**
- * This will read in a new username/password to be used
- */
- public void readInAccount() {
- File originalAccounts = new File("File Location here");
- if(originalAccounts.exists()) {
- try {
- FileReader fr = new FileReader(originalAccounts);
- BufferedReader br = new BufferedReader(fr);
- String line = br.readLine();
- br.close();
- if(line != null && line != "") {
- username = line.substring(0, line.indexOf(':'));
- password = line.substring(line.indexOf(':') + 1, line.length());
- accountBanned = false;
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
- /**
- * Deleted the account that is currently being used from the file
- *
- * - Makes a temp file and then copies all the accounts that are not going to be delted into the temporary file
- * - Deletes the old file
- * - Renames the temporary file to the regular file name
- */
- public void deleteAccountFromFile() {
- File originalAccounts = new File("File Location");
- File originalAccountsTemp = new File("File Locaition" + "Temp.txt");
- BufferedReader reader;
- BufferedWriter writer;
- try {
- reader = new BufferedReader(new FileReader(originalAccounts));
- writer = new BufferedWriter(new FileWriter(originalAccountsTemp));
- String lineToRemove = username + ":" + password;
- String currentLine;
- while((currentLine = reader.readLine()) != null) {
- // trim newline when comparing with lineToRemove
- String trimmedLine = currentLine.trim();
- if(trimmedLine.equals(lineToRemove)) continue;
- writer.write(currentLine);
- writer.newLine();
- }
- writer.close();
- reader.close();
- originalAccounts.delete();
- originalAccountsTemp.renameTo(originalAccounts);
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement