Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.jnk.SEcReT;
- import java.io.BufferedReader;
- import java.io.DataInputStream;
- import java.io.File;
- import java.io.FileInputStream;
- import java.io.FileWriter;
- import java.io.FilenameFilter;
- import java.io.InputStreamReader;
- import java.util.ArrayList;
- import java.util.Scanner;
- public final class SEcReT {
- /* Server Economy Reset Tool (SEcReT v1.0) By Jnk1296. Copyright © 2013 all rights reserved.
- * This software is subject to the terms and conditions of the GNU GPL V3.0 License.
- * GNU GPL V3.0: http://www.gnu.org/licenses/gpl.html
- * */
- // Information Variables
- public static final String verString = "v1.0_Release";
- public static final String author = "Jnk1296 (Jacob Keep)";
- // Value Changing Variables
- private static double changeAmountPlayer;
- private static double changeAmountTown;
- private static double changeAmountNation;
- private static double moneyLimit = -1;
- // Path Directories
- public static File path = new File(System.getProperty("user.dir") + "/Data");
- public static File Users = new File(System.getProperty("user.dir") +"/regex0.hive");
- public static File Towns = new File(System.getProperty("user.dir") +"/regex1.hive");
- public static File Nations = new File(System.getProperty("user.dir") +"/regex2.hive");
- // Statistic Variables
- public static int finalCount = 0;
- public static double finalTime = 0;
- public static void main(String[] args) {
- boolean hasParameters = false;
- // Check for parameters
- try {
- if (args[0] != null) hasParameters = true;
- } catch (Exception e) {
- hasParameters = false;
- }
- if (hasParameters) {
- // Change Player Economy
- if (args[0].equalsIgnoreCase("-player")) {
- try {
- if (args[1] != null) {
- try {
- changeAmountPlayer = Double.parseDouble(args[1]);
- } catch (NumberFormatException ee) {
- numFormErr(args[0]);
- }
- try {
- if (args[2] != null) {
- try {
- moneyLimit = Double.parseDouble(args[2]);
- } catch (NumberFormatException ee) {
- numFormErr(args[0]);
- }
- commandWarn();
- }
- } catch (Exception e) {
- noSetValWarn();
- }
- waitMsg();
- setPlayerEco(changeAmountPlayer, moneyLimit);
- report(finalCount, finalTime);
- opSuccess();
- }
- } catch (Exception e) {
- argNumErr(args[0]);
- }
- // Change Town Economy
- } else if (args[0].equalsIgnoreCase("-town")) {
- try {
- if (args[1] != null) {
- try {
- changeAmountTown = Double.parseDouble(args[1]);
- } catch (NumberFormatException ee) {
- numFormErr(args[0]);
- }
- try {
- if (args[2] != null) {
- try {
- moneyLimit = Double.parseDouble(args[2]);
- } catch (NumberFormatException ee) {
- numFormErr(args[0]);
- }
- commandWarn();
- }
- } catch (Exception e) {
- noSetValWarn();
- }
- waitMsg();
- setTownEco(changeAmountTown, moneyLimit);
- report(finalCount, finalTime);
- opSuccess();
- }
- } catch (Exception e) {
- argNumErr(args[0]);
- }
- // Change Nation Economy
- } else if (args[0].equalsIgnoreCase("-nation")) {
- try {
- if (args[1] != null) {
- try {
- changeAmountNation = Double.parseDouble(args[1]);
- } catch (NumberFormatException ee) {
- numFormErr(args[0]);
- }
- try {
- if (args[2] != null) {
- try {
- moneyLimit = Double.parseDouble(args[2]);
- } catch (NumberFormatException ee) {
- numFormErr(args[0]);
- }
- commandWarn();
- }
- } catch (Exception e) {
- noSetValWarn();
- }
- waitMsg();
- setNationEco(changeAmountNation, moneyLimit);
- report(finalCount, finalTime);
- opSuccess();
- }
- } catch (Exception e) {
- argNumErr(args[0]);
- }
- // Change Player and Town Economy
- } else if (args[0].equalsIgnoreCase("-low")) {
- try {
- if (args[1] != null) {
- try {
- changeAmountPlayer = Double.parseDouble(args[1]);
- changeAmountTown = Double.parseDouble(args[1]);
- } catch (NumberFormatException ee) {
- numFormErr(args[0]);
- }
- try {
- if (args[2] != null) {
- try {
- moneyLimit = Double.parseDouble(args[2]);
- } catch (NumberFormatException ee) {
- numFormErr(args[0]);
- }
- commandWarn();
- }
- } catch (Exception e) {
- noSetValWarn();
- }
- waitMsg();
- setPlayerEco(changeAmountPlayer, moneyLimit);
- setTownEco(changeAmountTown, moneyLimit);
- report(finalCount, finalTime);
- opSuccess();
- }
- } catch (Exception e) {
- argNumErr(args[0]);
- }
- // Change Town and Nation Economy
- } else if (args[0].equalsIgnoreCase("-high")) {
- try {
- if (args[1] != null) {
- try {
- changeAmountTown = Double.parseDouble(args[1]);
- changeAmountNation = Double.parseDouble(args[1]);
- } catch (NumberFormatException ee) {
- numFormErr(args[0]);
- }
- try {
- if (args[2] != null) {
- try {
- moneyLimit = Double.parseDouble(args[2]);
- } catch (NumberFormatException ee) {
- numFormErr(args[0]);
- }
- commandWarn();
- }
- } catch (Exception e) {
- noSetValWarn();
- }
- waitMsg();
- setTownEco(changeAmountTown, moneyLimit);
- setNationEco(changeAmountNation, moneyLimit);
- report(finalCount, finalTime);
- opSuccess();
- }
- } catch (Exception e) {
- argNumErr(args[0]);
- }
- // Change Entire Economy
- } else if (args[0].equalsIgnoreCase("-all")) {
- try {
- if (args[1] != null) {
- try {
- changeAmountPlayer = Double.parseDouble(args[1]);
- changeAmountTown = Double.parseDouble(args[1]);
- changeAmountNation = Double.parseDouble(args[1]);
- } catch (NumberFormatException ee) {
- numFormErr(args[0]);
- }
- try {
- if (args[2] != null) {
- try {
- moneyLimit = Double.parseDouble(args[2]);
- } catch (NumberFormatException ee) {
- numFormErr(args[0]);
- }
- commandWarn();
- }
- } catch (Exception e) {
- noSetValWarn();
- }
- waitMsg();
- setPlayerEco(changeAmountPlayer, moneyLimit);
- setTownEco(changeAmountTown, moneyLimit);
- setNationEco(changeAmountNation, moneyLimit);
- report(finalCount, finalTime);
- opSuccess();
- }
- } catch (Exception e) {
- argNumErr(args[0]);
- }
- // Display Command Help
- } else if (args[0].equalsIgnoreCase("-help")) {
- displayHelp();
- // Display Program Information
- } else if (args[0].equalsIgnoreCase("-about")) {
- displayInfo();
- // All Else
- } else {
- System.out.println("Improper syntax or invalid command.");
- System.exit(0);
- }
- // If no parameters were specified, tell the user to look at the help command
- } else if (!hasParameters) {
- displayInfo();
- sugHelp();
- }
- }
- public static void genPlayerFiles() {
- // Create Regex0.hive (Hive storage of all player.yml files for program access)
- FileWriter f = null;
- // If regex0.hive exists, delete it
- if (Users.exists()) Users.delete();
- try {
- // Create the file
- Users.createNewFile();
- // Create the file writer
- f = new FileWriter(Users, true);
- // Create a file array which holds all files found in the directory which have the extension *.yml
- File[] files = path.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File pathUsers, String name) {
- if (name.toLowerCase().endsWith(".yml") && !name.toLowerCase().startsWith("nation_") && !name.toLowerCase().startsWith("town_")) {
- return true;
- } else {
- return false;
- }
- }
- });
- // Write each file name to regex0.hive
- for (int i = 0; i < files.length; i++) {
- f.write(files[i].getName() + "\r\n");
- }
- // Close the file writer
- f.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void genTownFiles() {
- // Create Regex1.hive (Hive storage of all town.yml files for program access)
- FileWriter f = null;
- // If regex1.hive exists, delete it
- if (Towns.exists()) Towns.delete();
- try {
- // Create the file
- Towns.createNewFile();
- // Create the file writer
- f = new FileWriter(Towns, true);
- // Create a file array which holds all files found in the directory which have the extension *.yml
- File[] files = path.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File pathTowns, String name) {
- if (name.toLowerCase().endsWith(".yml") && name.toLowerCase().startsWith("town_")) {
- return true;
- } else {
- return false;
- }
- }
- });
- // Write each file name to regex1.hive
- for (int i = 0; i < files.length; i++) {
- f.write(files[i].getName() + "\r\n");
- }
- // Close the file writer
- f.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- public static void genNationFiles() {
- // Create Regex2.hive (Hive storage of all Nation.yml files for program access)
- FileWriter f = null;
- // If regex2.hive exists, delete it
- if (Nations.exists()) Nations.delete();
- try {
- // Create the file
- Nations.createNewFile();
- // Create the file writer
- f = new FileWriter(Nations, true);
- // Create a file array which holds all files found in the directory which have the extension *.yml
- File[] files = path.listFiles(new FilenameFilter() {
- @Override
- public boolean accept(File pathNations, String name) {
- if (name.toLowerCase().endsWith(".yml") && name.toLowerCase().startsWith("nation_")) {
- return true;
- } else {
- return false;
- }
- }
- });
- // Write each file name to regex2.hive
- for (int i = 0; i < files.length; i++) {
- f.write(files[i].getName() + "\r\n");
- }
- // Close the file writer
- f.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- // Change the Player Economy
- public static void setPlayerEco(double value, double limit) {
- // Check starting time
- double startTime = System.currentTimeMillis();
- // Generate regex0.hive
- genPlayerFiles();
- ArrayList<String> fileName = new ArrayList<String>();
- // Create File Reader
- try {
- FileInputStream fstream = new FileInputStream(Users);
- DataInputStream in = new DataInputStream(fstream);
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- String strLine;
- // Load file names from regex0.hive
- while ((strLine = br.readLine()) != null) {
- fileName.add(strLine);
- }
- // Iterate through each file in the hive
- for (String s:fileName) {
- ArrayList<String> lines = new ArrayList<String>();
- File currentFile = new File(path + "/" + s);
- // Create File Reader
- FileInputStream fstream2 = new FileInputStream(currentFile);
- DataInputStream in2 = new DataInputStream(fstream2);
- BufferedReader br2 = new BufferedReader(new InputStreamReader(in2));
- String strLine2;
- // Store contents of file to ArrayList
- while ((strLine2 = br2.readLine()) != null) {
- lines.add(strLine2);
- }
- br2.close();
- // Check for the "money: " line, change it to specified amount if higher than moneyLimit.
- int count = 0;
- for (String ss:lines) {
- if (ss.startsWith("money:")) {
- String strCheck = ss;
- strCheck = strCheck.replace("money: ", "");
- double moneyVal = Double.parseDouble(strCheck);
- if (moneyVal > moneyLimit) {
- lines.set(count, "money: " + changeAmountPlayer);
- }
- // Report to statistics
- finalCount++;
- }
- count++;
- }
- // Create File Writer
- FileWriter f = null;
- // If current file exists, delete it
- if (currentFile.exists()) currentFile.delete();
- try {
- // Create the file
- currentFile.createNewFile();
- // Create the file writer
- f = new FileWriter(currentFile, true);
- // Write current file
- for (String ss:lines) {
- f.write(ss + "\r\n");
- }
- // Close the file writer
- f.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- // Calculate and Report to Statistics
- double endTime = System.currentTimeMillis();
- finalTime += (endTime - startTime) / 1000;
- br.close();
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(0);
- }
- }
- // Change the Town Economy
- public static void setTownEco(double value, double limit) {
- // Check starting time
- double startTime = System.currentTimeMillis();
- // Generate regex1.hive
- genTownFiles();
- ArrayList<String> fileName = new ArrayList<String>();
- // Create File Reader
- try {
- FileInputStream fstream = new FileInputStream(Towns);
- DataInputStream in = new DataInputStream(fstream);
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- String strLine;
- // Load file names from regex1.hive
- while ((strLine = br.readLine()) != null) {
- fileName.add(strLine);
- }
- // Iterate through each file in the hive
- for (String s:fileName) {
- ArrayList<String> lines = new ArrayList<String>();
- File currentFile = new File(path + "/" + s);
- // Create File Reader
- FileInputStream fstream2 = new FileInputStream(currentFile);
- DataInputStream in2 = new DataInputStream(fstream2);
- BufferedReader br2 = new BufferedReader(new InputStreamReader(in2));
- String strLine2;
- // Store contents of file to ArrayList
- while ((strLine2 = br2.readLine()) != null) {
- lines.add(strLine2);
- }
- br2.close();
- // Check for the "money: " line, change it to specified amount if higher than moneyLimit.
- int count = 0;
- for (String ss:lines) {
- if (ss.startsWith("money:")) {
- String strCheck = ss;
- strCheck = strCheck.replace("money: ", "");
- double moneyVal = Double.parseDouble(strCheck);
- if (moneyVal > moneyLimit) {
- lines.set(count, "money: " + changeAmountTown);
- }
- // Report to statistics
- finalCount++;
- }
- count++;
- }
- // Create File Writer
- FileWriter f = null;
- // If current file exists, delete it
- if (currentFile.exists()) currentFile.delete();
- try {
- // Create the file
- currentFile.createNewFile();
- // Create the file writer
- f = new FileWriter(currentFile, true);
- // Write current file
- for (String ss:lines) {
- f.write(ss + "\r\n");
- }
- // Close the file writer
- f.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- // Calculate and Report to Statistics
- double endTime = System.currentTimeMillis();
- finalTime += (endTime - startTime) / 1000;
- br.close();
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(0);
- }
- }
- // Change the Nation Economy
- public static void setNationEco(double value, double limit) {
- // Check starting time
- double startTime = System.currentTimeMillis();
- // Generate regex2.hive
- genNationFiles();
- ArrayList<String> fileName = new ArrayList<String>();
- // Create File Reader
- try {
- FileInputStream fstream = new FileInputStream(Nations);
- DataInputStream in = new DataInputStream(fstream);
- BufferedReader br = new BufferedReader(new InputStreamReader(in));
- String strLine;
- // Load file names from regex2.hive
- while ((strLine = br.readLine()) != null) {
- fileName.add(strLine);
- }
- // Iterate through each file in the hive
- for (String s:fileName) {
- ArrayList<String> lines = new ArrayList<String>();
- File currentFile = new File(path + "/" + s);
- // Create File Reader
- FileInputStream fstream2 = new FileInputStream(currentFile);
- DataInputStream in2 = new DataInputStream(fstream2);
- BufferedReader br2 = new BufferedReader(new InputStreamReader(in2));
- String strLine2;
- // Store contents of file to ArrayList
- while ((strLine2 = br2.readLine()) != null) {
- lines.add(strLine2);
- }
- br2.close();
- // Check for the "money: " line, change it to specified amount if higher than moneyLimit.
- int count = 0;
- for (String ss:lines) {
- if (ss.startsWith("money:")) {
- String strCheck = ss;
- strCheck = strCheck.replace("money: ", "");
- double moneyVal = Double.parseDouble(strCheck);
- if (moneyVal > moneyLimit) {
- lines.set(count, "money: " + changeAmountNation);
- }
- // Report to statistics
- finalCount++;
- }
- count++;
- }
- // Create File Writer
- FileWriter f = null;
- // If current file exists, delete it
- if (currentFile.exists()) currentFile.delete();
- try {
- // Create the file
- currentFile.createNewFile();
- // Create the file writer
- f = new FileWriter(currentFile, true);
- // Write current file
- for (String ss:lines) {
- f.write(ss + "\r\n");
- }
- // Close the file writer
- f.close();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- // Calculate and Report to Statistics
- double endTime = System.currentTimeMillis();
- finalTime += (endTime - startTime) / 1000;
- br.close();
- } catch (Exception e) {
- e.printStackTrace();
- System.exit(0);
- }
- }
- // Report Statistics
- public static void report(int count, double time) {
- System.out.println("\n\nTotal time taken for operation to complete: " + time + " seconds. " + count + " files modified.");
- }
- // Report Invalid Number of Arguments for Command
- public static void argNumErr(String command) {
- System.out.println("Invalid Number of Arguments.\n");
- displaySyntax(command);
- }
- // Report Invalind Argument Format
- public static void numFormErr(String command) {
- System.out.println("Argument must be a valid number (with or without decimals)!\n");
- displaySyntax(command);
- }
- // Display the command for viewing help
- public static void sugHelp() {
- System.out.println("secret.jar -help");
- }
- // Display the Command Syntax for the command entered
- public static void displaySyntax(String command) {
- System.out.println("Usage: secret.jar " + command + " <AMOUNT_TO_SET> <MONEY_LIMIT>(Optional)");
- System.exit(0);
- }
- // Report Operation Success
- public static void opSuccess() {
- System.out.println("\nOperation completed successfully!");
- System.exit(0);
- }
- // Report Working Status of Operation
- public static void waitMsg() {
- System.out.println("\nPlease wait while operation completes...");
- }
- // Prompt for user approval (if Money_limit not set)
- public static void noSetValWarn() {
- System.out.println("\nWARNING. No value was given for <MONEY_LIMIT>. Proceeding with this action will affect ALL PLAYER FILES. There is NO UNDO. Do you wish to proceed? <Y/N>");
- Scanner in = new Scanner(System.in);
- String response = in.next();
- if (response.equalsIgnoreCase("y")) {
- return;
- } else if (response.equalsIgnoreCase("n")) {
- System.out.println("\nOperation Aborted.");
- System.exit(0);
- } else {
- System.out.println("\nOperation Aborted. Bad Input Received.");
- System.exit(0);
- }
- }
- // Prompt for user approval
- public static void commandWarn() {
- System.out.println("\nWARNING. Proceeding with this action will affect player data files. There is NO UNDO. Do you wish to proceed? <Y/N>");
- Scanner in = new Scanner(System.in);
- String response = in.next();
- if (response.equalsIgnoreCase("y")) {
- return;
- } else if (response.equalsIgnoreCase("n")) {
- System.out.println("\nOperation Aborted.");
- System.exit(0);
- } else {
- System.out.println("\nOperation Aborted. Bad Input Received.");
- System.exit(0);
- }
- }
- // Display Program Information
- public static void displayInfo() {
- System.out.println("\nSEcReT (Server Economy Reset Tool) " + verString + " by: " + author + "\n" +
- "Build date: 31/03/2013 | JVM Build Version: Java 1.7_17\n" +
- "Copyright (C) 2013. Released under GNU GPL v3.0.\n");
- }
- // Display Help Information
- public static void displayHelp() {
- System.out.println( "\n<--()***________SEcReT v1.0 by Jnk1296________***()-->\n" +
- "======================================================\n" +
- "Command | Description\n" +
- "======================================================\n" +
- "-player Resets the economy of players.\n" +
- "-town Resets the economy of towns.\n" +
- "-nation Resets the economy of nations.\n" +
- "-low Resets the economy of both players and towns.\n" +
- "-high Resets the economy of both towns and nations.\n" +
- "-all Resets entire economy.\n\n" +
- "For additional help, type the command with no parameters."
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement