diff --git a/pom.xml b/pom.xml index 2dd251f..cdd760c 100644 --- a/pom.xml +++ b/pom.xml @@ -79,5 +79,10 @@ Java-WebSocket Java-WebSocket-1.3.1 + + com.github.TBMCPlugins.ButtonCore + ButtonCore + master-SNAPSHOT + diff --git a/src/main/java/buttondevteam/PlaceMinecraft2/App.java b/src/main/java/buttondevteam/PlaceMinecraft2/App.java index 619d7f5..b2b56c3 100644 --- a/src/main/java/buttondevteam/PlaceMinecraft2/App.java +++ b/src/main/java/buttondevteam/PlaceMinecraft2/App.java @@ -1,18 +1,23 @@ package buttondevteam.PlaceMinecraft2; +import java.io.IOException; +import java.net.MalformedURLException; import java.net.URISyntaxException; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocketFactory; +import buttondevteam.lib.TBMCCoreAPI; + /** * Hello world! * */ public class App { public static void main(String[] args) throws URISyntaxException { - PlaceWebSocket placews = new PlaceWebSocket( - "wss://..."); + PlaceWebSocket placews = new PlaceWebSocket(get_place_url()); SSLContext sslContext = null; try { sslContext = SSLContext.getInstance("TLS"); @@ -26,4 +31,25 @@ public class App { } System.out.println("Finished"); } + + public static String get_place_url() { + String match = null; + + while (match == null) { + String content; + try { + content = TBMCCoreAPI.DownloadString("https://reddit.com/r/place"); + } catch (Exception e) { + e.printStackTrace(); + return null; + } + Pattern url_re = Pattern.compile("\"place_websocket_url\": \"([^,]+)\""); // Forgive me, for I am a sinner + Matcher matcher = url_re.matcher(content); + + if (matcher.find()) + match = content.substring(matcher.start() + "\"place_websocket_url\": \"".length(), matcher.end() - 1); + } + return match; + } + }