Added get_place_url()
This commit is contained in:
parent
c31399155a
commit
ae067c0440
2 changed files with 33 additions and 2 deletions
5
pom.xml
5
pom.xml
|
@ -79,5 +79,10 @@
|
|||
<artifactId>Java-WebSocket</artifactId>
|
||||
<version>Java-WebSocket-1.3.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.github.TBMCPlugins.ButtonCore</groupId>
|
||||
<artifactId>ButtonCore</artifactId>
|
||||
<version>master-SNAPSHOT</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue