+ * Example: *
* YamlConfig config = new YamlConfig(this, "config.yml", true); * config.load(); @@ -41,7 +43,8 @@ public class FConfig extends YamlConfiguration // BukkitLib @ https://github.com /** * Creates a new YamlConfig instance. * - *Example: + *
+ * Example: *
* YamlConfig config = new YamlConfig(this, new File(plugin.getDataFolder() + "/players", "Prozza.yml"), false); * config.load(); @@ -89,7 +92,8 @@ public class FConfig extends YamlConfiguration // BukkitLib @ https://github.com /** * Loads the configuration from the predefined file. * - *Optionally, if loadDefaults has been set to true, the file will be copied over from the default inside the jar-file of the owning plugin.
+ *+ * Optionally, if loadDefaults has been set to true, the file will be copied over from the default inside the jar-file of the owning plugin.
* * @see #YamlConfig(Plugin, String, boolean) */ @@ -142,6 +146,7 @@ public class FConfig extends YamlConfiguration // BukkitLib @ https://github.com /** * Returns the default configuration as been stored in the jar-file of the owning plugin. + * * @return The default configuration. */ public YamlConfiguration getDefaultConfig() diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/MainConfig.java b/src/main/java/me/totalfreedom/totalfreedommod/config/MainConfig.java index 3693af39..e0e5423e 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/config/MainConfig.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/MainConfig.java @@ -15,6 +15,7 @@ import org.bukkit.configuration.file.YamlConfiguration; public class MainConfig { + public static final File CONFIG_FILE = new File(TotalFreedomMod.plugin.getDataFolder(), TotalFreedomMod.CONFIG_FILENAME); // private static final EnumMapENTRY_MAP; @@ -79,7 +80,8 @@ public class MainConfig } else { - FLog.warning("Value for " + entry.getConfigName() + " is of type " + value.getClass().getSimpleName() + ". Needs to be " + entry.getType().getSimpleName() + ". Using default value."); + FLog.warning("Value for " + entry.getConfigName() + " is of type " + + value.getClass().getSimpleName() + ". Needs to be " + entry.getType().getSimpleName() + ". Using default value."); } } else @@ -274,6 +276,7 @@ public class MainConfig public static class TFM_Defaults { + private YamlConfiguration defaults = null; private TFM_Defaults(InputStream defaultConfig) @@ -300,4 +303,5 @@ public class MainConfig return defaults.get(path); } } + } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/freeze/FreezeData.java b/src/main/java/me/totalfreedom/totalfreedommod/freeze/FreezeData.java index 2c42d66a..7c3fff22 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/freeze/FreezeData.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/freeze/FreezeData.java @@ -14,6 +14,7 @@ import org.bukkit.scheduler.BukkitTask; public class FreezeData { + private final FPlayer fPlayer; // @Getter diff --git a/src/main/java/me/totalfreedom/totalfreedommod/freeze/Freezer.java b/src/main/java/me/totalfreedom/totalfreedommod/freeze/Freezer.java index ddb5d097..c81e81eb 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/freeze/Freezer.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/freeze/Freezer.java @@ -11,6 +11,7 @@ import org.bukkit.event.player.PlayerMoveEvent; public class Freezer extends AbstractService { + @Getter private boolean globalFreeze = false; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/Jumppads.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/Jumppads.java index fbe23712..46c84abc 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/Jumppads.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/Jumppads.java @@ -15,6 +15,7 @@ import org.bukkit.util.Vector; public class Jumppads extends AbstractService { + public static final Material BLOCK_ID = Material.WOOL; public static final double DAMPING_COEFFICIENT = 0.8; // @@ -117,6 +118,7 @@ public class Jumppads extends AbstractService public static enum JumpPadMode { + OFF(false), NORMAL(true), NORMAL_AND_SIDEWAYS(true), MADGEEK(true); private final boolean on; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/fun/Landminer.java b/src/main/java/me/totalfreedom/totalfreedommod/fun/Landminer.java index 57f944be..f2e7e0a7 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/fun/Landminer.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/fun/Landminer.java @@ -19,6 +19,7 @@ import org.bukkit.util.Vector; public class Landminer extends AbstractService { + @Getter private final List landmines = new ArrayList (); @@ -102,6 +103,7 @@ public class Landminer extends AbstractService public static class Landmine { + @Getter private final Location location; @Getter diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java index 293f31eb..0bccaf4f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java @@ -7,6 +7,7 @@ import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4; public class HTMLGenerationTools { + private HTMLGenerationTools() { throw new AssertionError(); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDModule.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDModule.java index 8318c747..8ec888d1 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDModule.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDModule.java @@ -10,6 +10,7 @@ import me.totalfreedom.totalfreedommod.util.FLog; public abstract class HTTPDModule { + protected final String uri; protected final Method method; protected final Map headers; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDPageBuilder.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDPageBuilder.java index 9ca7310e..5a9b5d54 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDPageBuilder.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDPageBuilder.java @@ -4,6 +4,7 @@ import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD.Response; public class HTTPDPageBuilder { + private static final String TEMPLATE = "\r\n" + "\r\n" + "\r\n" diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_dump.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_dump.java index 6b1e3955..927f5d8a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_dump.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_dump.java @@ -12,6 +12,7 @@ import org.apache.commons.lang3.StringUtils; public class Module_dump extends HTTPDModule { + private File echoFile = null; private final String body; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_file.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_file.java index 2cdb8f2d..6b440a92 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_file.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_file.java @@ -21,6 +21,7 @@ import org.apache.commons.lang3.StringUtils; */ public class Module_file extends HTTPDModule { + private final File rootDir = new File(ConfigEntry.HTTPD_PUBLIC_FOLDER.getString()); public static final Map MIME_TYPES = new HashMap (); @@ -302,7 +303,7 @@ public class Module_file extends HTTPDModule } } - List _files = Arrays.asList(f.list(new FilenameFilter() + List files = Arrays.asList(f.list(new FilenameFilter() { @Override public boolean accept(File dir, String name) @@ -310,7 +311,7 @@ public class Module_file extends HTTPDModule return new File(dir, name).isFile(); } })); - Collections.sort(_files); + Collections.sort(files); List directories = Arrays.asList(f.list(new FilenameFilter() { @Override @@ -320,7 +321,7 @@ public class Module_file extends HTTPDModule } })); Collections.sort(directories); - if (up != null || directories.size() + _files.size() > 0) + if (up != null || directories.size() + files.size() > 0) { msg += " "; if (up != null || directories.size() > 0) @@ -337,12 +338,12 @@ public class Module_file extends HTTPDModule } msg += ""; } - if (_files.size() > 0) + if (files.size() > 0) { msg += "
"; - for (int i = 0; i < _files.size(); i++) + for (int i = 0; i < files.size(); i++) { - String file = _files.get(i); + String file = files.get(i); msg += " - " + file + ""; File curFile = new File(f, file); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_help.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_help.java index a6519927..0b0efdab 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_help.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_help.java @@ -8,11 +8,11 @@ import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; import me.totalfreedom.totalfreedommod.commands.FreedomCommand; import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.heading; import static me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools.paragraph; import me.totalfreedom.totalfreedommod.rank.PlayerRank; -import me.totalfreedom.totalfreedommod.TotalFreedomMod; import net.pravian.aero.command.CommandReflection; import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4; import org.apache.commons.lang3.StringUtils; @@ -23,6 +23,7 @@ import org.bukkit.command.SimpleCommandMap; public class Module_help extends HTTPDModule { + public Module_help(NanoHTTPD.HTTPSession session) { super(session); @@ -136,6 +137,7 @@ public class Module_help extends HTTPDModule public static class CommandComparator implements Comparator
{ + @Override public int compare(Command a, Command b) { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_list.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_list.java index 007fd9c7..a7c65300 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_list.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_list.java @@ -7,6 +7,7 @@ import org.bukkit.entity.Player; public class Module_list extends HTTPDModule { + public Module_list(NanoHTTPD.HTTPSession session) { super(session); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_permbans.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_permbans.java index 026169f2..b580be32 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_permbans.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_permbans.java @@ -5,6 +5,7 @@ import me.totalfreedom.totalfreedommod.TotalFreedomMod; public class Module_permbans extends HTTPDModule { + public Module_permbans(NanoHTTPD.HTTPSession session) { super(session); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_players.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_players.java index 68f954b6..585dd27f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_players.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_players.java @@ -10,6 +10,7 @@ import org.json.simple.JSONObject; public class Module_players extends HTTPDModule { + public Module_players(NanoHTTPD.HTTPSession session) { super(session); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_schematic.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_schematic.java index 013291c3..496b266a 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_schematic.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/Module_schematic.java @@ -20,6 +20,7 @@ import org.apache.commons.lang3.StringUtils; public class Module_schematic extends HTTPDModule { + private static final File SCHEMATIC_FOLDER = new File("./plugins/WorldEdit/schematics/"); private static final String REQUEST_FORM_FILE_ELEMENT_NAME = "schematicFile"; private static final Pattern SCHEMATIC_FILENAME_LC = Pattern.compile("^[a-z0-9_'!,\\-]{1,30}\\.schematic$"); @@ -236,6 +237,7 @@ public class Module_schematic extends HTTPDModule private static class SchematicTransferException extends Exception { + public SchematicTransferException() { } @@ -248,6 +250,7 @@ public class Module_schematic extends HTTPDModule private static class ResponseOverrideException extends Exception { + private final Response response; public ResponseOverrideException(Response response) @@ -269,6 +272,7 @@ public class Module_schematic extends HTTPDModule private static enum ModuleMode { + LIST("list"), UPLOAD("upload"), DOWNLOAD("download"), @@ -300,4 +304,5 @@ public class Module_schematic extends HTTPDModule return INVALID; } } + } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/NanoHTTPD.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/NanoHTTPD.java index 114911c5..aefb0adf 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/NanoHTTPD.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/NanoHTTPD.java @@ -79,7 +79,8 @@ import me.totalfreedom.totalfreedommod.util.FLog; * * See the separate "LICENSE.md" file for the distribution license (Modified BSD licence) */ -public abstract class NanoHTTPD { +public abstract class NanoHTTPD +{ /** * Common mime type for dynamic content: plain text @@ -115,43 +116,60 @@ public abstract class NanoHTTPD { /** * Constructs an HTTP server on given port. */ - public NanoHTTPD(int port) { + public NanoHTTPD(int port) + { this(null, port); } /** * Constructs an HTTP server on given hostname and port. */ - public NanoHTTPD(String hostname, int port) { + public NanoHTTPD(String hostname, int port) + { this.hostname = hostname; this.myPort = port; setTempFileManagerFactory(new DefaultTempFileManagerFactory()); setAsyncRunner(new DefaultAsyncRunner()); } - private static final void safeClose(ServerSocket serverSocket) { - if (serverSocket != null) { - try { + private static final void safeClose(ServerSocket serverSocket) + { + if (serverSocket != null) + { + try + { serverSocket.close(); - } catch (IOException e) { + } + catch (IOException e) + { } } } - private static final void safeClose(Socket socket) { - if (socket != null) { - try { + private static final void safeClose(Socket socket) + { + if (socket != null) + { + try + { socket.close(); - } catch (IOException e) { + } + catch (IOException e) + { } } } - private static final void safeClose(Closeable closeable) { - if (closeable != null) { - try { + private static final void safeClose(Closeable closeable) + { + if (closeable != null) + { + try + { closeable.close(); - } catch (IOException e) { + } + catch (IOException e) + { } } } @@ -161,38 +179,55 @@ public abstract class NanoHTTPD { * * @throws IOException if the socket is in use. */ - public void start() throws IOException { + public void start() throws IOException + { myServerSocket = new ServerSocket(); myServerSocket.bind((hostname != null) ? new InetSocketAddress(hostname, myPort) : new InetSocketAddress(myPort)); - myThread = new Thread(new Runnable() { + myThread = new Thread(new Runnable() + { @Override - public void run() { - do { - try { + public void run() + { + do + { + try + { final Socket finalAccept = myServerSocket.accept(); final InputStream inputStream = finalAccept.getInputStream(); - if (inputStream == null) { + if (inputStream == null) + { safeClose(finalAccept); - } else { - asyncRunner.exec(new Runnable() { + } + else + { + asyncRunner.exec(new Runnable() + { @Override - public void run() { + public void run() + { OutputStream outputStream = null; - try { + try + { outputStream = finalAccept.getOutputStream(); TempFileManager tempFileManager = tempFileManagerFactory.create(); HTTPSession session = new HTTPSession(tempFileManager, inputStream, outputStream, finalAccept); - while (!finalAccept.isClosed()) { + while (!finalAccept.isClosed()) + { session.execute(); } - } catch (Exception e) { + } + catch (Exception e) + { // When the socket is closed by the client, we throw our own SocketException // to break the "keep alive" loop above. - if (!(e instanceof SocketException && "NanoHttpd Shutdown".equals(e.getMessage()))) { + if (!(e instanceof SocketException && "NanoHttpd Shutdown".equals(e.getMessage()))) + { FLog.severe(e); } - } finally { + } + finally + { safeClose(outputStream); safeClose(inputStream); safeClose(finalAccept); @@ -200,7 +235,9 @@ public abstract class NanoHTTPD { } }); } - } catch (IOException e) { + } + catch (IOException e) + { } } while (!myServerSocket.isClosed()); } @@ -213,24 +250,31 @@ public abstract class NanoHTTPD { /** * Stop the server. */ - public void stop() { - try { + public void stop() + { + try + { safeClose(myServerSocket); myThread.join(); - } catch (Exception e) { + } + catch (Exception e) + { FLog.severe(e); } } - public final int getListeningPort() { + public final int getListeningPort() + { return myServerSocket == null ? -1 : myServerSocket.getLocalPort(); } - public final boolean wasStarted() { + public final boolean wasStarted() + { return myServerSocket != null && myThread != null; } - public final boolean isAlive() { + public final boolean isAlive() + { return wasStarted() && !myServerSocket.isClosed() && myThread.isAlive(); } @@ -248,7 +292,8 @@ public abstract class NanoHTTPD { */ @Deprecated public Response serve(String uri, Method method, Map headers, Map parms, - Map files) { + Map files) + { return new Response(Response.Status.NOT_FOUND, MIME_PLAINTEXT, "Not Found"); } @@ -261,15 +306,22 @@ public abstract class NanoHTTPD { * @param session The HTTP session * @return HTTP response, see class Response for details */ - public Response serve(HTTPSession session) { + public Response serve(HTTPSession session) + { Map files = new HashMap (); Method method = session.getMethod(); - if (Method.PUT.equals(method) || Method.POST.equals(method)) { - try { + if (Method.PUT.equals(method) || Method.POST.equals(method)) + { + try + { session.parseBody(files); - } catch (IOException ioe) { + } + catch (IOException ioe) + { return new Response(Response.Status.INTERNAL_ERROR, MIME_PLAINTEXT, "SERVER INTERNAL ERROR: IOException: " + ioe.getMessage()); - } catch (ResponseException re) { + } + catch (ResponseException re) + { return new Response(re.getStatus(), MIME_PLAINTEXT, re.getMessage()); } } @@ -283,48 +335,56 @@ public abstract class NanoHTTPD { * @param str the percent encoded String
* @return expanded form of the input, for example "foo%20bar" becomes "foo bar" */ - protected String decodePercent(String str) { + protected String decodePercent(String str) + { String decoded = null; - try { + try + { decoded = URLDecoder.decode(str, "UTF8"); - } catch (UnsupportedEncodingException ignored) { + } + catch (UnsupportedEncodingException ignored) + { } return decoded; } /** - * Decode parameters from a URL, handing the case where a single parameter name might have been - * supplied several times, by return lists of values. In general these lists will contain a single + * Decode parameters from a URL, handing the case where a single parameter name might have been supplied several times, by return lists of values. In general these lists will contain a single * element. * * @param parms original NanoHttpd parameters values, as passed to theserve()
method. * @return a map ofString
(parameter name) toList<String>
(a list of the values supplied). */ - protected Map> decodeParameters(Map parms) { + protected Map > decodeParameters(Map parms) + { return this.decodeParameters(parms.get(QUERY_STRING_PARAMETER)); } /** - * Decode parameters from a URL, handing the case where a single parameter name might have been - * supplied several times, by return lists of values. In general these lists will contain a single + * Decode parameters from a URL, handing the case where a single parameter name might have been supplied several times, by return lists of values. In general these lists will contain a single * element. * * @param queryString a query string pulled from the URL. * @return a map of String
(parameter name) toList<String>
(a list of the values supplied). */ - protected Map> decodeParameters(String queryString) { + protected Map > decodeParameters(String queryString) + { Map