Start work on schematics

This commit is contained in:
2022-04-17 17:27:30 -05:00
parent 2ce0a1e698
commit ef5ff6b540
11 changed files with 202 additions and 3 deletions

View File

@ -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("<tr>" +
"<th scope=\"row\">" + worldeditFile.getName() + "</th>" +
"<td>" + worldeditFile.length() + "B" + "</td>" +
"</tr>");
}
file = file.replace("${schematics}", sb.toString());
return file;
}
}