Proper code style for core package

TODO: environment package
This commit is contained in:
Clisprail
2014-02-19 00:04:57 +01:00
parent 376714a07d
commit 8181a36800
29 changed files with 113 additions and 104 deletions
+3 -4
View File
@@ -11,10 +11,9 @@ import java.io.IOException;
* @author Everel * @author Everel
*/ */
public class Core { public class Core {
private static boolean debug;
private static boolean debug = false; private static boolean verbose;
private static boolean verbose = false; private static boolean loadLocal; //Loads both local and public scripts/servers
private static boolean loadLocal = false; //Loads both local and public scripts/servers
/** /**
* Enabled loadLocal mode * Enabled loadLocal mode
@@ -13,11 +13,10 @@ import java.util.*;
* @author Matt * @author Matt
*/ */
public class Directories { public class Directories {
private static Map<String, File> cached;
private static Map<String, File> cached = new HashMap<String, File>();
static { static {
cached = new HashMap<String, File>();
switch (OperatingSystem.getOS()) { switch (OperatingSystem.getOS()) {
case WINDOWS: case WINDOWS:
cached.put("Root", new JFileChooser().getFileSystemView().getDefaultDirectory()); cached.put("Root", new JFileChooser().getFileSystemView().getDefaultDirectory());
@@ -34,21 +34,23 @@ import org.parabot.core.ui.components.VerboseLoader;
* @author Matt * @author Matt
*/ */
public class ClassPath { public class ClassPath {
public final HashMap<String, ClassNode> classes = new HashMap<String, ClassNode>(); public final HashMap<String, ClassNode> classes;
public final Map<String, URL> resources = new HashMap<String, URL>(); public final Map<String, URL> resources;
private boolean isJar;
private boolean isJar = false; private boolean parseJar;
private boolean parseJar = true; private ArrayList<URL> jarFiles;
private ArrayList<URL> jarFiles = new ArrayList<URL>();
public URL lastParsed = null; public URL lastParsed = null;
public ClassPath() { public ClassPath() {
this(false);
} }
public ClassPath(final boolean isJar) { public ClassPath(final boolean isJar) {
this.isJar = isJar; this.isJar = isJar;
this.classes = new HashMap<String, ClassNode>();
this.resources = new HashMap<String, URL>();
this.jarFiles = new ArrayList<URL>();
} }
public void addJar(final File file) { public void addJar(final File file) {
@@ -7,16 +7,16 @@ package org.parabot.core.desc;
* *
*/ */
public class ScriptDescription { public class ScriptDescription {
public String scriptName = null; public String scriptName;
public String author = null; public String author;
public String category = null; public String category;
public double version = 0; public double version;
public String description = null; public String description;
public String[] servers = null; public String[] servers;
public String isVip = null; public String isVip;
public String isPremium = null; public String isPremium;
public int sdnId = -1; public int sdnId = -1;
public String jarName = null; public String jarName;
/** /**
* The ScriptManifest * The ScriptManifest
@@ -8,9 +8,9 @@ package org.parabot.core.desc;
* *
*/ */
public class ServerDescription { public class ServerDescription {
private String serverName = null; private String serverName;
private String author = null; private String author;
private double revision = 0; private double revision;
public ServerDescription(final String serverName, final String author, public ServerDescription(final String serverName, final String author,
final double revision) { final double revision) {
@@ -10,8 +10,8 @@ package org.parabot.core.forum;
* *
*/ */
public class Account { public class Account {
private String username = null; private String username;
private String password = null; private String password;
/** /**
* *
@@ -17,8 +17,8 @@ import java.util.ArrayList;
* *
*/ */
public final class AccountManager { public final class AccountManager {
private static boolean validated = false; private static boolean validated;
private static AccountManager instance = null; private static AccountManager instance;
private Account account = null; private Account account = null;
@@ -3,16 +3,17 @@ package org.parabot.core.io;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
/**
*
* @author Everel
*
*/
public class SizeInputStream extends InputStream { public class SizeInputStream extends InputStream {
private InputStream in = null; public int bytesRead;
private double size = 0;
public int bytesRead = 0;
private ProgressListener l; private ProgressListener l;
private InputStream in;
private long startTime = 0L; private long startTime;
private double size;
public SizeInputStream(InputStream in, int size, ProgressListener l) { public SizeInputStream(InputStream in, int size, ProgressListener l) {
this.in = in; this.in = in;
@@ -15,7 +15,7 @@ import org.parabot.core.build.BuildPath;
* *
*/ */
public class Jython { public class Jython {
private static boolean valid = false; private static boolean valid;
/** /**
* Determines if jython jar has been downloaded. * Determines if jython jar has been downloaded.
@@ -8,12 +8,12 @@ import java.util.logging.LogRecord;
import javax.swing.JLabel; import javax.swing.JLabel;
public class LabelLogHandler extends Handler { public class LabelLogHandler extends Handler {
public final JLabel label = new JLabel(); public final JLabel label;
private final Color defaultColor; private final Color defaultColor;
public LabelLogHandler() { public LabelLogHandler() {
super(); this.label = new JLabel();
defaultColor = label.getForeground(); this.defaultColor = label.getForeground();
} }
@Override @Override
@@ -7,25 +7,27 @@ import java.util.Date;
import java.util.logging.Formatter; import java.util.logging.Formatter;
import java.util.logging.LogRecord; import java.util.logging.LogRecord;
public class LogFormatter extends Formatter public class LogFormatter extends Formatter {
{ private static final String LINE_SEPARATOR = System
private static final String LINE_SEPARATOR = System.getProperty("line.separator"); .getProperty("line.separator");
private final boolean appendNewLine; private final boolean appendNewLine;
public LogFormatter() public LogFormatter() {
{
this(true); this(true);
} }
public LogFormatter(final boolean appendNewLine) public LogFormatter(final boolean appendNewLine) {
{
this.appendNewLine = appendNewLine; this.appendNewLine = appendNewLine;
} }
@Override @Override
public String format(final LogRecord record) { public String format(final LogRecord record) {
final StringBuilder result = new StringBuilder().append("[").append(record.getLevel().getName()).append("] ").append(new Date(record.getMillis())).append(": ").append(record.getLoggerName()).append(": ").append(record.getMessage()).append(throwableToString(record.getThrown())); final StringBuilder result = new StringBuilder().append("[")
.append(record.getLevel().getName()).append("] ")
.append(new Date(record.getMillis())).append(": ")
.append(record.getLoggerName()).append(": ")
.append(record.getMessage())
.append(throwableToString(record.getThrown()));
if (appendNewLine) { if (appendNewLine) {
result.append(LogFormatter.LINE_SEPARATOR); result.append(LogFormatter.LINE_SEPARATOR);
} }
@@ -9,7 +9,7 @@ import java.util.logging.Logger;
* @author Paris * @author Paris
*/ */
public class LogOutputStream extends OutputStream { public class LogOutputStream extends OutputStream {
protected boolean hasBeenClosed = false; protected boolean hasBeenClosed;
protected Logger category; protected Logger category;
protected Level priority; protected Level priority;
protected StringBuilder buffer; protected StringBuilder buffer;
@@ -16,8 +16,13 @@ import org.parabot.core.Context;
* *
*/ */
public class PaintDebugger { public class PaintDebugger {
private final HashMap<String, AbstractDebugger> debuggers = new HashMap<String, AbstractDebugger>(); private final HashMap<String, AbstractDebugger> debuggers;
private final Queue<String> stringDebug = new LinkedList<String>(); private final Queue<String> stringDebug;
public PaintDebugger() {
this.debuggers = new HashMap<String, AbstractDebugger>();
this.stringDebug = new LinkedList<String>();
}
public final void addDebugger(final String name, final AbstractDebugger debugger) { public final void addDebugger(final String name, final AbstractDebugger debugger) {
debuggers.put(name, debugger); debuggers.put(name, debugger);
@@ -20,11 +20,8 @@ import org.parabot.core.asm.wrappers.Super;
* *
* @author Dane * @author Dane
* *
*
*
*/ */
public class JSONHookParser extends HookParser { public class JSONHookParser extends HookParser {
private JSONObject root; private JSONObject root;
private Map<String, String> interfaces; private Map<String, String> interfaces;
private HashMap<String, String> constants; private HashMap<String, String> constants;
@@ -18,9 +18,7 @@ import java.io.FilenameFilter;
* @author Everel * @author Everel
*/ */
public class LocalPythonScripts extends ScriptParser { public class LocalPythonScripts extends ScriptParser {
private PythonInterpreter interpreter = new PythonInterpreter(); private static final FilenameFilter PYTHON_SCRIPT_FILTER = new FilenameFilter() {
private static final FilenameFilter PYTHON_SCRIPT_FILTER = new FilenameFilter() {
@Override @Override
public boolean accept(File dir, String name) { public boolean accept(File dir, String name) {
@@ -29,6 +27,12 @@ public class LocalPythonScripts extends ScriptParser {
}; };
private PythonInterpreter interpreter;
public LocalPythonScripts() {
this.interpreter = new PythonInterpreter();
}
/** /**
* @param name - local var name * @param name - local var name
* @return script instance * @return script instance
@@ -16,7 +16,7 @@ import java.net.URL;
* @author Everel * @author Everel
*/ */
public class SDNScripts extends ScriptParser { public class SDNScripts extends ScriptParser {
private static AccountManager manager = null; private static AccountManager manager;
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() { public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
@@ -5,11 +5,8 @@ import java.net.SocketException;
import java.util.Enumeration; import java.util.Enumeration;
public class MacAddress { public class MacAddress {
public static byte[] mac = new byte[] { 11, 11, 11, 11, 11, 11 }; public static byte[] mac = new byte[] { 11, 11, 11, 11, 11, 11 };
private static byte[] realMac; private static byte[] realMac;
private static MacAddress cached; private static MacAddress cached;
static { static {
+1 -1
View File
@@ -23,7 +23,7 @@ import java.awt.event.ActionListener;
public class BotUI extends JFrame implements ActionListener { public class BotUI extends JFrame implements ActionListener {
private static final long serialVersionUID = -2126184292879805519L; private static final long serialVersionUID = -2126184292879805519L;
private static BotUI instance = null; private static BotUI instance;
public static BotUI getInstance() { public static BotUI getInstance() {
return instance == null ? instance = new BotUI() : instance; return instance == null ? instance = new BotUI() : instance;
@@ -34,12 +34,12 @@ import org.parabot.core.ui.utils.SwingUtil;
public class LoginUI extends JFrame { public class LoginUI extends JFrame {
private static final long serialVersionUID = 2032832552863466297L; private static final long serialVersionUID = 2032832552863466297L;
private static LoginUI instance = null; private static LoginUI instance;
private JTextField txtUsername; private JTextField txtUsername;
private JPasswordField txtPassword; private JPasswordField txtPassword;
private JButton cmdLogin; private JButton cmdLogin;
private JButton cmdRegister; private JButton cmdRegister;
private static AccountManager manager = null; private static AccountManager manager;
public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() { public static final AccountManagerAccess MANAGER_FETCHER = new AccountManagerAccess() {
@@ -7,15 +7,15 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.util.HashMap; import java.util.HashMap;
public class NetworkUI { public class NetworkUI {
public JFrame frame; public JFrame frame;
private JTextField proxyHostField; private JTextField proxyHostField;
private JTextField proxyPortField; private JTextField proxyPortField;
private HashMap<String, Integer> socksVersions = new HashMap<>(); private HashMap<String, Integer> socksVersions;
public NetworkUI() { public NetworkUI() {
this.socksVersions = new HashMap<String, Integer>();
initialize(); initialize();
} }
@@ -25,18 +25,19 @@ import java.util.HashMap;
* @author Everel * @author Everel
*/ */
public final class ScriptSelector extends JFrame { public final class ScriptSelector extends JFrame {
public static ScriptParser parser;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private HashMap<String, DefaultMutableTreeNode> categories = new HashMap<String, DefaultMutableTreeNode>(); private HashMap<String, DefaultMutableTreeNode> categories = new HashMap<String, DefaultMutableTreeNode>();
private HashMap<String, ScriptDescription> format = new HashMap<String, ScriptDescription>(); private HashMap<String, ScriptDescription> format = new HashMap<String, ScriptDescription>();
private DefaultMutableTreeNode root = new DefaultMutableTreeNode("Scripts"); private DefaultMutableTreeNode root = new DefaultMutableTreeNode("Scripts");
private DefaultTreeModel model = null; private DefaultTreeModel model;
private final int WIDTH = 640; private final int WIDTH;
private final int HEIGHT = 256 + 128; private final int HEIGHT;
public static ScriptParser parser = null;
public ScriptSelector() { public ScriptSelector() {
model = new DefaultTreeModel(root); this.WIDTH = 640;
this.HEIGHT = 256 + 128;
this.model = new DefaultTreeModel(root);
putScripts(); putScripts();
createUI(); createUI();
} }
@@ -25,13 +25,11 @@ import org.parabot.environment.Environment;
*/ */
public class ServerSelector extends JFrame { public class ServerSelector extends JFrame {
public static String initServer;
private static final long serialVersionUID = 5238720307271493899L; private static final long serialVersionUID = 5238720307271493899L;
private static ServerSelector instance = null; private static ServerSelector instance;
private JPanel panel; private JPanel panel;
public static String initServer = null;
public static ServerSelector getInstance() { public static ServerSelector getInstance() {
if (instance == null) { if (instance == null) {
instance = new ServerSelector(); instance = new ServerSelector();
@@ -30,16 +30,18 @@ import org.parabot.environment.scripts.Script;
*/ */
public class BotToolbar extends JToolBar { public class BotToolbar extends JToolBar {
private static final long serialVersionUID = 5373484845104212180L; private static final long serialVersionUID = 5373484845104212180L;
private static BotToolbar instance = null; private static BotToolbar instance;
private JButton tab = null;
private final JButton run = new JButton();
private final JButton stop = new JButton();
private static Map<TabButton, Context> environments = new HashMap<TabButton, Context>(); private static Map<TabButton, Context> environments = new HashMap<TabButton, Context>();
private JButton tab;
private final JButton run;
private final JButton stop;
private boolean runScript = false; private boolean runScript = false;
private boolean pauseScript = false; private boolean pauseScript = false;
public BotToolbar() { public BotToolbar() {
this.run = new JButton();
this.stop = new JButton();
setFloatable(false); setFloatable(false);
tab = new JButton(); tab = new JButton();
tab.addActionListener(new ActionListener() { tab.addActionListener(new ActionListener() {
@@ -18,9 +18,9 @@ import org.parabot.core.Context;
*/ */
public class GamePanel extends JPanel { public class GamePanel extends JPanel {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private static GamePanel instance = null; private static GamePanel instance;
private static VerboseLoader loader = VerboseLoader.get(); private static VerboseLoader loader = VerboseLoader.get();
public Context context = null; public Context context;
private GamePanel() { private GamePanel() {
setFocusable(true); setFocusable(true);
@@ -26,8 +26,8 @@ import org.parabot.core.logging.TextAreaLogHandler;
public class LogArea extends JScrollPane { public class LogArea extends JScrollPane {
private static final long serialVersionUID = 6571141103751675714L; private static final long serialVersionUID = 6571141103751675714L;
private static LogArea instance = null;
private static LogTextArea logArea = new LogTextArea(); private static LogTextArea logArea = new LogTextArea();
private static LogArea instance;
private LogArea() { private LogArea() {
super(TextAreaLogHandler.TEXT_AREA, super(TextAreaLogHandler.TEXT_AREA,
@@ -14,18 +14,21 @@ import java.awt.geom.Rectangle2D;
* *
*/ */
public class ProgressBar { public class ProgressBar {
private double value = 0; private double value;
private int width = 0; private int width;
private int height = 0; private int height;
private double locX = 0; private double locX;
private Color progColor = new Color(255, 0, 0); private Color progColor;
private Color backColor = new Color(74, 74, 72, 100); private Color backColor;
private FontMetrics fontMetrics = null; private FontMetrics fontMetrics;
private String text = ""; private String text;
public ProgressBar(int width, int height) { public ProgressBar(int width, int height) {
this.progColor = new Color(255, 0, 0);
this.backColor = new Color(74, 74, 72, 100);
this.width = width; this.width = width;
this.height = height; this.height = height;
this.text = "";
} }
public void setText(final String text) { public void setText(final String text) {
@@ -21,12 +21,13 @@ public class VerboseLoader extends JPanel implements ProgressListener {
private static final long serialVersionUID = 7412412644921803896L; private static final long serialVersionUID = 7412412644921803896L;
private static VerboseLoader current = null; private static VerboseLoader current = null;
private static String state = "Initializing loader..."; private static String state = "Initializing loader...";
private FontMetrics fontMetrics = null; private FontMetrics fontMetrics;
private BufferedImage bot_image = null; private BufferedImage bot_image;
private ProgressBar p = new ProgressBar(400, 20); private ProgressBar p;
public VerboseLoader() { public VerboseLoader() {
bot_image = Images.getResource("/org/parabot/core/ui/images/para.png"); this.bot_image = Images.getResource("/org/parabot/core/ui/images/para.png");
this.p = new ProgressBar(400, 20);
setSize(775, 510); setSize(775, 510);
setBackground(Color.black); setBackground(Color.black);
setDoubleBuffered(true); setDoubleBuffered(true);
@@ -11,7 +11,6 @@ import java.awt.Toolkit;
* *
*/ */
public class AwtUtil { public class AwtUtil {
private static Toolkit toolkit; private static Toolkit toolkit;
public static Toolkit getToolkit() { public static Toolkit getToolkit() {
@@ -19,11 +19,10 @@ import java.awt.event.MouseMotionListener;
*/ */
public class ServerWidget extends JPanel implements MouseListener, public class ServerWidget extends JPanel implements MouseListener,
MouseMotionListener { MouseMotionListener {
public ServerDescription desc;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private String name = null; private String name;
public ServerDescription desc = null; private boolean hovered;
private boolean hovered = false;
public ServerWidget(final ServerDescription desc) { public ServerWidget(final ServerDescription desc) {
this.desc = desc; this.desc = desc;