diff --git a/src/main/java/dev/plex/HTTPDModule.java b/src/main/java/dev/plex/HTTPDModule.java index 2cdb9bb..07a3b47 100644 --- a/src/main/java/dev/plex/HTTPDModule.java +++ b/src/main/java/dev/plex/HTTPDModule.java @@ -7,6 +7,7 @@ import dev.plex.request.impl.IndefBansEndpoint; import dev.plex.request.impl.IndexEndpoint; import dev.plex.request.impl.ListEndpoint; import dev.plex.request.impl.PunishmentsEndpoint; +import dev.plex.request.impl.SchematicDownloadEndpoint; import dev.plex.util.PlexLog; import java.util.concurrent.atomic.AtomicReference; import lombok.Getter; @@ -67,6 +68,7 @@ public class HTTPDModule extends PlexModule new IndexEndpoint(); new ListEndpoint(); new PunishmentsEndpoint(); + new SchematicDownloadEndpoint(); server.setConnectors(new Connector[]{connector}); server.setHandler(context); diff --git a/src/main/java/dev/plex/request/impl/SchematicDownloadEndpoint.java b/src/main/java/dev/plex/request/impl/SchematicDownloadEndpoint.java new file mode 100644 index 0000000..81b3074 --- /dev/null +++ b/src/main/java/dev/plex/request/impl/SchematicDownloadEndpoint.java @@ -0,0 +1,50 @@ +package dev.plex.request.impl; + +import dev.plex.request.AbstractServlet; +import dev.plex.request.GetMapping; +import jakarta.servlet.http.HttpServletRequest; +import java.io.File; +import java.util.Arrays; +import org.bukkit.Bukkit; + +public class SchematicDownloadEndpoint extends AbstractServlet +{ + @GetMapping(endpoint = "/api/schematics/download/") + public String downloadSchematics(HttpServletRequest request) + { + return schematicHTML(); + } + + private String schematicHTML() + { + String file = readFile(this.getClass().getResourceAsStream("/httpd/schematic_list.html")); + File worldeditFolder; + if (Bukkit.getPluginManager().isPluginEnabled("WorldEdit")) + { + worldeditFolder = new File(Bukkit.getPluginManager().getPlugin("WorldEdit").getDataFolder() + "/schematics/"); + } + else if (Bukkit.getPluginManager().isPluginEnabled("FastAsyncWorldEdit")) + { + worldeditFolder = new File(Bukkit.getPluginManager().getPlugin("FastAsyncWorldEdit").getDataFolder() + "/schematics/"); + } + else + { + return null; + } + StringBuilder sb = new StringBuilder(); + File[] alphabetical = worldeditFolder.listFiles(); + if (alphabetical != null) + { + Arrays.sort(alphabetical); + } + for (File worldeditFile : alphabetical) + { + sb.append("" + + "" + worldeditFile.getName() + "" + + "" + worldeditFile.length() + "B" + "" + + ""); + } + file = file.replace("${schematics}", sb.toString()); + return file; + } +} diff --git a/src/main/java/dev/plex/request/impl/SchematicIndexEndpoint.java b/src/main/java/dev/plex/request/impl/SchematicIndexEndpoint.java new file mode 100644 index 0000000..df1c2d6 --- /dev/null +++ b/src/main/java/dev/plex/request/impl/SchematicIndexEndpoint.java @@ -0,0 +1,16 @@ +package dev.plex.request.impl; + +import com.google.gson.GsonBuilder; +import dev.plex.request.AbstractServlet; +import dev.plex.request.GetMapping; +import jakarta.servlet.http.HttpServletRequest; +import org.bukkit.Bukkit; +import org.bukkit.entity.Player; + +public class SchematicIndexEndpoint extends AbstractServlet +{ + @GetMapping(endpoint = "/api/list/") + public String schematicIndex(HttpServletRequest request) + { + } +} diff --git a/src/main/resources/httpd/admins.html b/src/main/resources/httpd/admins.html index 3024658..52e1ab6 100644 --- a/src/main/resources/httpd/admins.html +++ b/src/main/resources/httpd/admins.html @@ -32,7 +32,10 @@ List + diff --git a/src/main/resources/httpd/indefbans.html b/src/main/resources/httpd/indefbans.html index 9fa0d9a..aa00f5c 100644 --- a/src/main/resources/httpd/indefbans.html +++ b/src/main/resources/httpd/indefbans.html @@ -32,7 +32,10 @@ List + diff --git a/src/main/resources/httpd/index.html b/src/main/resources/httpd/index.html index b7bbe97..7bde1cf 100644 --- a/src/main/resources/httpd/index.html +++ b/src/main/resources/httpd/index.html @@ -32,7 +32,10 @@ List + diff --git a/src/main/resources/httpd/punishments.html b/src/main/resources/httpd/punishments.html index 1c4ea77..7689efd 100644 --- a/src/main/resources/httpd/punishments.html +++ b/src/main/resources/httpd/punishments.html @@ -34,6 +34,9 @@ + diff --git a/src/main/resources/httpd/punishments_error.html b/src/main/resources/httpd/punishments_error.html index f1ea1ee..2f315c6 100644 --- a/src/main/resources/httpd/punishments_error.html +++ b/src/main/resources/httpd/punishments_error.html @@ -34,6 +34,9 @@ + diff --git a/src/main/resources/httpd/punishments_good.html b/src/main/resources/httpd/punishments_good.html index 6fdc342..4a5aaab 100644 --- a/src/main/resources/httpd/punishments_good.html +++ b/src/main/resources/httpd/punishments_good.html @@ -34,6 +34,9 @@ + diff --git a/src/main/resources/httpd/schematic_index.html b/src/main/resources/httpd/schematic_index.html new file mode 100644 index 0000000..40f3cc7 --- /dev/null +++ b/src/main/resources/httpd/schematic_index.html @@ -0,0 +1,60 @@ + + + + + + + Schematics - Plex HTTPD + + + +
+

Plex HTTPD

+
A list of schematics is below. You can click on the schematic name to download it.
+ + + + + + + + + ${schematics} + +
NameSize
+
+ + \ No newline at end of file diff --git a/src/main/resources/httpd/schematic_list.html b/src/main/resources/httpd/schematic_list.html new file mode 100644 index 0000000..d524643 --- /dev/null +++ b/src/main/resources/httpd/schematic_list.html @@ -0,0 +1,53 @@ + + + + + + + Schematic Download - Plex HTTPD + + + +
+

Plex HTTPD

+
Welcome to the schematic page. Please select if you would like to download or upload a schematic.
+
+ + +
+
+ + \ No newline at end of file