From 24575aba88e487669854b193a2c362806d4516be Mon Sep 17 00:00:00 2001 From: speedxx <43330808+speedxx@users.noreply.github.com> Date: Mon, 17 Aug 2020 18:17:45 -0400 Subject: [PATCH] index httpd module --- .../totalfreedommod/config/ConfigEntry.java | 3 +- .../httpd/HTMLGenerationTools.java | 5 -- .../httpd/HTTPDPageBuilder.java | 14 ++-- .../totalfreedommod/httpd/HTTPDaemon.java | 8 +-- .../httpd/module/Module_index.java | 64 +++++++++++++++++++ .../httpd/module/Module_logfile.java | 26 +++++--- .../httpd/module/Module_schematic.java | 25 +++++--- src/main/resources/config.yml | 7 +- 8 files changed, 111 insertions(+), 41 deletions(-) create mode 100644 src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_index.java diff --git a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java index 6c6657b7..de9b8acb 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/config/ConfigEntry.java @@ -45,6 +45,7 @@ public enum ConfigEntry MOB_LIMITER_DISABLE_SLIME(Boolean.class, "moblimiter.disable.slime"), // HTTPD_ENABLED(Boolean.class, "httpd.enabled"), + HTTPD_HOST(String.class, "httpd.host"), HTTPD_PORT(Integer.class, "httpd.port"), HTTPD_PUBLIC_FOLDER(String.class, "httpd.public_folder"), // @@ -172,7 +173,7 @@ public enum ConfigEntry FAMOUS_PLAYERS(List.class, "famous_players"), STAFF_ONLY_MODE(Boolean.class, "staff_only_mode"), STAFF_INFO(List.class, "staffinfo"), - VOTING_INFO(List.class, "votinginfo"), + VOTING_INFO(List.class, "votinginfo"), MASTER_BUILDER_INFO(List.class, "masterbuilderinfo"), AUTO_ENTITY_WIPE(Boolean.class, "auto_wipe"), TOGGLE_CHAT(Boolean.class, "toggle_chat"), diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java index 4570f14d..23bc066c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTMLGenerationTools.java @@ -7,11 +7,6 @@ import static org.apache.commons.lang3.StringEscapeUtils.escapeHtml4; public class HTMLGenerationTools { - - private HTMLGenerationTools() - { - } - public static String paragraph(String data) { return "
" + escapeHtml4(data) + "
\r\n"; diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDPageBuilder.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDPageBuilder.java index 5a9b5d54..b4027a0d 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDPageBuilder.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDPageBuilder.java @@ -20,14 +20,10 @@ public class HTTPDPageBuilder + "\r\n" + "\r\n"; // - private String body = null; - private String title = null; - private String style = null; - private String script = null; - - public HTTPDPageBuilder() - { - } + private String body; + private String title; + private String style; + private String script; public HTTPDPageBuilder(String body, String title, String style, String script) { @@ -71,4 +67,4 @@ public class HTTPDPageBuilder .replace("{$STYLE}", this.style == null ? "" : STYLE.replace("{$STYLE}", this.style)) .replace("{$SCRIPT}", this.script == null ? "" : SCRIPT.replace("{$SCRIPT}", this.script)); } -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java index cd334bfd..a18d0375 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/HTTPDaemon.java @@ -16,6 +16,7 @@ import me.totalfreedom.totalfreedommod.httpd.module.Module_bans; import me.totalfreedom.totalfreedommod.httpd.module.Module_file; import me.totalfreedom.totalfreedommod.httpd.module.Module_help; import me.totalfreedom.totalfreedommod.httpd.module.Module_indefbans; +import me.totalfreedom.totalfreedommod.httpd.module.Module_index; import me.totalfreedom.totalfreedommod.httpd.module.Module_list; import me.totalfreedom.totalfreedommod.httpd.module.Module_logfile; import me.totalfreedom.totalfreedommod.httpd.module.Module_logs; @@ -47,7 +48,6 @@ public class HTTPDaemon extends FreedomService } port = ConfigEntry.HTTPD_PORT.getInteger(); - ; httpd = new HTTPD(port); // Modules @@ -63,6 +63,7 @@ public class HTTPDaemon extends FreedomService module("players", Module_players.class, false); module("punishments", Module_punishments.class, true); module("schematic", Module_schematic.class, true); + module("index", Module_index.class, false); try { @@ -103,7 +104,6 @@ public class HTTPDaemon extends FreedomService private class HTTPD extends NanoHTTPD { - private HTTPD(int port) { super(port); @@ -177,8 +177,6 @@ public class HTTPDaemon extends FreedomService FLog.severe(ex); } } - return response; } - -} +} \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_index.java b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_index.java new file mode 100644 index 00000000..8b3fb66b --- /dev/null +++ b/src/main/java/me/totalfreedom/totalfreedommod/httpd/module/Module_index.java @@ -0,0 +1,64 @@ +package me.totalfreedom.totalfreedommod.httpd.module; + +import java.util.Set; +import me.totalfreedom.totalfreedommod.TotalFreedomMod; +import me.totalfreedom.totalfreedommod.config.ConfigEntry; +import me.totalfreedom.totalfreedommod.httpd.HTMLGenerationTools; +import me.totalfreedom.totalfreedommod.httpd.HTTPDPageBuilder; +import me.totalfreedom.totalfreedommod.httpd.NanoHTTPD; +import org.reflections.Reflections; + +public class Module_index extends HTTPDModule +{ + + public Module_index(TotalFreedomMod plugin, NanoHTTPD.HTTPSession session) + { + super(plugin, session); + } + + @Override + public NanoHTTPD.Response getResponse() + { + return new HTTPDPageBuilder(body(), title(), null, null).getResponse(); + } + + public String body() + { + final StringBuilder sb = new StringBuilder(); + + sb.append(HTMLGenerationTools.heading("TotalFreedom HTTPd Module List", 1)); + + Reflections r = new Reflections("me.totalfreedom.totalfreedommod.httpd.module"); + + Set