Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- importClass(java.net.URL)
- importClass(java.io.BufferedReader)
- importClass(java.io.InputStreamReader)
- importClass(java.io.FileNotFoundException)
- importClass(java.util.logging.Level)
- // In the javascript engine we can implement Java interfaces such as Runnable,
- // this makes it possible to use some of the bukkit scheduler API, which
- // is required for doing http requests without hanging your server.
- // To send messages to players we really should be on the main thread.
- var sendResponse = function(s) {
- server.getScheduler().runTask(plugin, new java.lang.Runnable({
- run : function() {
- sender.sendMessage(s);
- }
- }));
- }
- // To do http or anything slow we must not be on the main thread.
- server.getScheduler().runTaskAsynchronously(plugin, new java.lang.Runnable({
- run : function () {
- try {
- var url = new URL("http://cyberiantiger.org/EasyScript/http.txt");
- var content = new BufferedReader(new InputStreamReader(url.openConnection().getContent()));
- // We only read the first line here.
- var message = content.readLine();
- content.close();
- sendResponse(message);
- } catch (e) {
- if (e.javaException instanceof FileNotFoundException) {
- sendResponse("Error: not found");
- } else {
- sendResponse("An error occured, check logs.");
- throw e
- }
- }
- }
- }));
Advertisement
Add Comment
Please, Sign In to add comment