From 2386ea44a2dc29e2462dcd975f79c24efa56550e Mon Sep 17 00:00:00 2001 From: biglyderv Date: Fri, 7 Feb 2025 11:20:44 -0500 Subject: [PATCH] cool stuff --- README.md | 16 +----- app/build.gradle.kts | 1 + app/src/main/java/net/xuyezo/main/Main.java | 20 +++++++- .../java/net/xuyezo/main/ServHandler.java | 50 +++++++++++++++++++ 4 files changed, 71 insertions(+), 16 deletions(-) create mode 100644 app/src/main/java/net/xuyezo/main/ServHandler.java diff --git a/README.md b/README.md index 64c92fe..361b667 100644 --- a/README.md +++ b/README.md @@ -1,15 +1 @@ -# Skystone -A PaperMC plugin that turns the whole world into stone platforms. A few extra recipes and things are added for playability. - -Vague inspiration: https://www.curseforge.com/minecraft/mc-mods/dirt-platform - -## Using -Download this plugin into the ``plugins`` folder of your PaperMC installation directory. Afterwards, edit bukkit.yml to look something like this: - -``` -(...) -worlds: - world: - generator: MinzeoPlugin - biome-provider: MinzeoPlugin -``` +# TODO: update this \ No newline at end of file diff --git a/app/build.gradle.kts b/app/build.gradle.kts index cffda5b..0e9b0bb 100644 --- a/app/build.gradle.kts +++ b/app/build.gradle.kts @@ -27,6 +27,7 @@ dependencies { // This dependency is used by the application. implementation(libs.guava) + implementation("org.json:json:20090211") compileOnly("io.papermc.paper:paper-api:1.21.4-R0.1-SNAPSHOT") } diff --git a/app/src/main/java/net/xuyezo/main/Main.java b/app/src/main/java/net/xuyezo/main/Main.java index fb7da3f..2e1fbdf 100644 --- a/app/src/main/java/net/xuyezo/main/Main.java +++ b/app/src/main/java/net/xuyezo/main/Main.java @@ -1,5 +1,10 @@ package net.xuyezo.main; +import com.sun.net.httpserver.HttpServer; +import com.sun.net.httpserver.HttpHandler; +import com.sun.net.httpserver.HttpExchange; +import java.io.IOException; +import java.net.InetSocketAddress; import java.sql.Connection; import java.sql.DriverManager; import org.bukkit.Bukkit; @@ -13,6 +18,7 @@ public class Main extends JavaPlugin { String host = this.getConfig().getString("dbhost"); String pass = this.getConfig().getString("dbpass"); String user = this.getConfig().getString("dbuser"); + Connection c = null; try { c = DriverManager @@ -26,6 +32,18 @@ public class Main extends JavaPlugin { Bukkit.getPluginManager().registerEvents(new Handler(c), this); - Server server = getServer(); + Server serverS = getServer(); + + try { + HttpServer server = HttpServer.create(new InetSocketAddress(8787), 0); + server.createContext("/messages", new ServHandler(c)); + + // Start the server + server.setExecutor(null); // Use the default executor + server.start(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } } } \ No newline at end of file diff --git a/app/src/main/java/net/xuyezo/main/ServHandler.java b/app/src/main/java/net/xuyezo/main/ServHandler.java new file mode 100644 index 0000000..4bbf433 --- /dev/null +++ b/app/src/main/java/net/xuyezo/main/ServHandler.java @@ -0,0 +1,50 @@ +package net.xuyezo.main; + +import java.io.IOException; +import java.io.OutputStream; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; + +import net.kyori.adventure.text.TextComponent; + +import org.json.simple.JSONArray; +import org.json.simple.JSONObject; +public class ServHandler implements HttpHandler { + Connection cc; + public ServHandler(Connection c) { + this.cc = c; + } + + @Override + public void handle(HttpExchange exchange) throws IOException + { + PreparedStatement stmt; + JSONArray outObject = new JSONArray(); + try { + stmt = cc.prepareStatement("SELECT * FROM main.text ORDER BY date DESC"); + ResultSet rs = stmt.executeQuery(); + while (rs.next()) { + JSONObject mainObject = new JSONObject(); + mainObject.put("username", rs.getString("username")); + mainObject.put("date", rs.getLong("date")); + mainObject.put("content", rs.getString("content")); + outObject.add(mainObject); + } + } catch (SQLException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + // handle the request + String response = outObject.toString(); + exchange.sendResponseHeaders(200, response.length()); + OutputStream os = exchange.getResponseBody(); + os.write(response.getBytes()); + os.close(); + } +} \ No newline at end of file