Check if pastebin file equals something

Discussion in 'Plugin Development' started by HaitherecreeperMC, Oct 5, 2013.

Thread Status:
Not open for further replies.
  1. So basically I want so that if the pastebin file I specify equals something, It will do something. So basically I want it so that if the pastebin file says "true" in it, it will notify the user that it is equal to true. If this is really complicated/not explained enough, tell me.
     
  2. Offline

    Polaris29

    HaitherecreeperMC
    You could use an Html parser like Jsoup.

    With Jsoup, you can use this code to get the text from a pastebin file:
    Code:java
    1.  
    2. Document doc = Jsoup.parse(url.openStream(), "UTF-8", url.toString()); // Get Document object ('url' is a java.net.URL object)
    3. Element e = doc.getElementById("paste_code"); // paste_code is the id of the textarea containing the raw paste code
    4. if (e.text().contains("true")) { // Use element.text() to get the text of the element as a String
    5. // pastebin text contains true
    6. }
    7.  


    But Html parsers don't execute Javascript (which some sites rely on to show their content), so if you need javascript to run, you could try out HtmlUnit
     
  3. thanks, will try this!

    I tried that with the code
    Code:java
    1. public void onEnable(){
    2. getLogger().info("OpMeFX started successfully!");
    3. getServer().getPluginManager().registerEvents(this, this);
    4. this.getConfig().options().copyDefaults(true);
    5. saveDefaultConfig();
    6. URL url = new URL ("pastebin.com/raw.php?i=EVk48aWV");
    7. org.jsoup.nodes.Document doc = Jsoup.parse(url.openStream(), "UTF-8", url.toString()); // Get Document object ('url' is a java.net.URL object)
    8. org.jsoup.nodes.Element e = doc.getElementById("paste_code"); // paste_code is the id of the textarea containing the raw paste code
    9. if (e.text().contains("true")) { // Use element.text() to get the text of the element as a String
    10. // pastebin text contains true
    11. getLogger().info("test successful!");
    12. }
    13. try {
    14. Metrics metrics = new Metrics(this);
    15. metrics.start();
    16. getLogger().info("OpMeFX Metrics started successfully!");
    17. } catch (IOException e) {
    18. // Failed to submit the stats :-(
    19. }
    20. }

    but, (You can see I have pluginmetrics) this part
    Code:java
    1. try {
    2.  
    3. Metrics metrics = new Metrics(this);
    4.  
    5. metrics.start();
    6.  
    7. getLogger().info("OpMeFX Metrics started successfully!");
    8.  
    9. } catch (IOException e) {
    10.  
    11. // Failed to submit the stats :-(
    12.  
    13. }

    Interferes with it, and says e is a duplicate variable. So that's all and well, but when I rename the e in either of them, it tells me to but try/catch around a few of the lines of code D: any idea what's happening?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  4. Offline

    tommycake50

Thread Status:
Not open for further replies.

Share This Page