[SNIPPET] PastebinReporter

Discussion in 'Resources' started by CaptainBern, Feb 3, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    CaptainBern Retired Staff

    Hello, everyone!

    Some of you may have noticed that some "bigger" plugins have a fancy feature that when there's an unknown error, they post a log on Pastebin, and then print the URL and tell the server owner to send you, the plugin author, the URL. So, I thought to myself, why not make such a tool? And, voilĂ : it is finished.

    The usage is fairly simple:
    1. public class MyPlugin extends JavaPlugin
    3. public PastebinReporter REPORTER;
    5. @Override
    6. public void onEnable() {
    8. this.REPORTER = new PastebinReporter(<Your pastebin API-Key>);
    10. }
    12. public PastebinReporter getReporter() {
    13. return this.REPORTER;
    14. }

    The API-Key is your personal API key for Pastebin. (to retrieve one, go to pastebin.com, create an account, and click "API")

    Then, if you want to make a report:
    1. Paste mySexyPaste = new Paste("This is the Header.\nThis header looks extremely sexy.");

    Then you can add as many lines as you want:
    1. mySexyPaste.appendLine("1. This is line 1!")
    2. .appendLine("2. Line 2!")
    3. .appendLine("Do you like it already?");

    And then finally, to post your report on Pastebin do:
    1. MyPluginInstance.getReporter().post(<name of the paste, if null then no name will be given>, mySexyPaste, ReportFormat.YAML, ExpireDate.ONE_MONTH);

    My code supports all possible Pastebin syntaxes, so you can pick whichever you like. The "post(report, format);" returns the URL where the paste got posted.

    glen3b, Phasesaber, Chinwe and 15 others like this.
  2. Offline


    [​IMG]Have this cookie.
    I also like your definition of "a little class".
    glen3b, Phasesaber, DSH105 and 3 others like this.
  3. Offline

    CaptainBern Retired Staff

    UnrealPowerz Yeah but keep in mind that the reportformat are over 200 diffrent formats so the "usefull" code is like 120 lines or so :p

    Added an "ExpireDate", you can pick between never, 10 minutes, 1 hour, 1 day, 1 week, 2 weeks and 1 month.

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


    Nice, but is this running in the main server thread? Could bring a lot of servers to a grinding halt if pastebin is slow/down...
    CaptainBern likes this.
  5. Offline


    CaptainBern likes this.
  6. Offline

    CaptainBern Retired Staff

    desht Thank you :) , Yes it runs on the main thread, but nothing stops you from running it async. :p
  7. Offline


    It's not working for me :/ It doesn't show any error, but it doesn't send to my pastebin :l
  8. Offline


    CaptainBern likes this.
  9. Offline

    CaptainBern Retired Staff

    The_Doctor_123 Thank you :) LCastr0 Hmm, do this: System.out.print(reporter.post(<stuff here>)); and take a look at the url in the console.
  10. Offline


    Sounds great, here's a cake [cake]
    CaptainBern likes this.
  11. Offline


  12. Offline

    lol768 Retired Staff

    Please ensure you document this appropriately if you use it in a BukkitDev plugin :)
Thread Status:
Not open for further replies.

Share This Page