BukkitDev API

Discussion in 'BukkitDev Information and Feedback' started by iKeirNez, Feb 13, 2012.

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

    iKeirNez

    I am aware that there is an API called BukGet but how do I use this in PHP?

    Can someone please post the code they have used to implement this to their website?

    Keir
     
  2. Offline

    Bertware

    Check out their github. There are a few examples.
    I've implemented it using .NET, and it works really nice.
    SteveMcGrath
    what do you want that PHP script to do?
     
  3. Offline

    iKeirNez

    So would that work on a website? I am trying to get the download link (done) and below it, it would say Version and then get the from BukkitDev and CB Version and get that from BukkitDev too.

    Thanks
    Keir
     
  4. Offline

    Bertware

    So like this:

    Download
    Current Version
    Supported CB version

    The flow of my implementation is like this:
    Request to API --> Get result --> Result to own class --> get data from class
    That self-made class contains the plugin information, and a list of the Versions. The versions are also a custom class
    This structure allows you to easily expand or add functionality later on.

    However, if you need that information only from you plugin, you could just use
    strpos($haystack,$needle), mb_substr($haystack,$startpos) and explode($haystack,$startpos) to get the correct parts out of the result.
     
  5. Offline

    iKeirNez

    Yeah exactly like that, I am rubbish at PHP so is there any chance you could post the code to use?

    Keir
     
  6. Offline

    Bertware

    could you give me the plugin name?

    Edit: working on something, almost done...
     
  7. Offline

    iKeirNez

    There a quite a few, would you be able to make this configurable?

    But if this isn't possible could you use locked-chest-commands

    I am presuming it wouldn't be too hard to change this? Simply URL change right?

    Thanks for all your help
    Keir
     
  8. Offline

    Bertware

    Here's your 50-line solution:
    example: http://automation.bertware.net/plugin.php?plugin=UselessTNT
    as you can see, you insert the plugin name using the "plugin" parameter
    I made it using functions, so it's quite modular. You'll probably be able to onderstand how the functions are working, so you could change them to get other values as well


    PHP:
    <?php
    $plugin_name 
    $_GET['plugin']; //Get plugin name from URL
    $plugin_name strtolower($plugin_name); //to lower for valid URL
    $base "http://bukget.org/api/plugin/"// Base path for bukget API plugin search
    $url=$base $plugin_name;
    $content file_get_contents($base $plugin_name); //Get content
    echo Getname($content); //get plugin name
    echo "<br>";
    echo 
    GetVersion($content); //get plugin version
    echo "<br>";
    echo 
    GetLink($content);//get plugin DL link
    echo "<br>";
    echo 
    GetCB($content); //get compatible CB version
     
    function Getname($cont) {
    //example: "name": "locked-chest-surprise",
    $start strpos($cont,'"plugin_name": "');
    $cont mb_substr($cont,$start+16); //+16, because strpos get start of string, we need the end
    $split explode('"',$cont); //get first element of this array, to get the value
    $cont $split[0];
    return 
    $cont;
    }
    function 
    GetVersion($cont) {
    //example: "name": "UselessTNT ver.2.8",
    $versions_start strpos($cont,'"md5":'); //make sure it detects the version name, not hte plugin name. so remove first part of result
    $cont mb_substr($cont,$versions_start);
    $start strpos($cont,'"name": "');
    $cont mb_substr($cont,$start+9,$versions_start);
    $split explode('"',$cont);
    $cont $split[0];
    return 
    $cont;
    }
    function 
    GetLink($cont) {
    //example: "dl_link": "http://dev.bukkit.org/media/files/562/989/UselessTNT.jar",
    $start strpos($cont,'"dl_link": "');
    $cont mb_substr($cont,$start+12);
    $split explode('"',$cont);
    $cont $split[0];
    return 
    $cont;
    }
    function 
    GetCB($cont) {
    //example: "game_builds": [ "CB 1.0.1-R1" ], //spaces in this comment might be incorrect
    $start strpos($cont,'"CB ');
    $cont mb_substr($cont,$start+1);
    $split explode('"',$cont);
    $cont $split[0];
    return 
    $cont;
    }
     
    ?>
     
  9. Offline

    iKeirNez

    Wow!!!! Thanks for this, I cant try it just now but I will when I'm back at my pc. Do you mind if I post this on my blog? All credit will be given to you plus a link to this topic.

    Thanks
    Keir
     
  10. Offline

    Bertware

    no problem, feel free to use/share it :)

    Hint:
    use this line:
    PHP:
    echo '<a href="' GetLink($content) . '"><img src="http://mag.racked.eu/mcimage/i327/' GetName($content) . '/' GetVersion($content) . '/mca.png"</a>';
    to generate an image + hyperlink as shown at:
    http://automation.bertware.net/plugin.php?plugin=UselessTNT

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

    iKeirNez

    Wow! You are completely awesome! Does the URL have to have the ?plugin=UselessTNT bit or can I have it without that.

    Keir
     
  12. Offline

    Bertware

  13. Offline

    iKeirNez

    Ok it's just that now my URL will look like this

    keir-nellyer.co.uk/main-projects/generalcommands?plugin=generalcommands

    Also I don't think the Plugin bit in the URL would work with WordPress too well.

    Keir
     
  14. Offline

    Bertware

    that ?plugin part should work in wordpress.
    However, if you want to use this for only one plugin:
    replace
    PHP:
    $plugin_name $_GET['plugin'];
    with
    PHP:
    $plugin_name "generalcommands";
    or you could also use this code (Default value, but can be overwritten using ?plugin)
    PHP:
    $plugin_name $_GET['plugin']; //get name from url
    if ($plugin_name =""){ //if no name provided
    $plugin_name "generalcommands"// set default
    }
     

    I tried your link but it doesn't work, as wordpress thinks its a wordpress page.
    I am currently using this method:
    subdomain, with 2 directory's:
    -site (wordpress site)
    -tools (php scripts and such stuff)

    maybe you could add such a 'tools' directory even in your wordpress main directory.

    then I am using this code:
    HTML:
    <html><object data="URL HERE"  width="300" height="125"><embed src="URL HERE" width="300" height="125"> </embed>Error</object></html>
    you can change the width and height.
    This is a code snippet I found on the internet, but it works nicely with wordpress.
     
  15. Offline

    iKeirNez

    Bertware Thanks soooo much for your help! I found the time today to add this to my wordpress site and it works! I had to use a plugin to get PHP working and modify a little bit of the code to make it work with wordpress and it is amazing. This will help loads of plugin developers who have a website and use BukkitDev.

    Keir
     
  16. Offline

    chaseoes Retired Staff

    Hey, thanks for this! I never knew such an API existed for BukkitDev.
    Trying out your script, one thing I've noticed is that the plugin version format varies with different plugins, it seems to simply grab the title of the uploaded file. Is there any way to strip this down to a simple, numerical number?

    Also, how would you go about displaying the information for multiple plugins on one page?

    Thanks! :D
     
  17. Offline

    Bertware

    the PHP script should contain the functions.

    you need to get the API result to a variable, in this example i use the $content variable
    PHP:
    $plugin_name "plugin name"//enter name, or enter code to retrieve from URL. Must be lowercase!
    $base "http://bukget.org/api/plugin/"// Base path for bukget API plugin search
    $url=$base $plugin_name;
    $content file_get_contents($base $plugin_name); //Get content
    then you can use the functions to retrieve the information, as the 2 examples below are showing
    PHP:
    echo Getname($content); //get plugin name
    echo "<br>";
    echo 
    GetVersion($content); //get plugin version
    echo "<br>";
    echo 
    GetLink($content);//get plugin DL link
    echo "<br>";
    echo 
    GetCB($content); //get compatible CB version
    PHP:
    echo '<a href="' GetLink($content) . '"><img src="http://mag.racked.eu/mcimage/i327/' GetName($content) . '/' GetVersion($content) . '/mca.png"</a>';
     
  18. Offline

    chaseoes Retired Staff

    Yeah, I got that part.. but I need to display multiple of those per page. E.g. if I supplied the link:
    http://yousite.com/whatever.php?plugin=mcmmo&plugin2=vanish

    Because the current script only allows for one plugin name (in your example the $plugin_name variable) but I need it to handle multiple plugin names.
     
  19. Offline

    iKeirNez

    It should be possible to easily define 2 variables in the URL.
     
  20. Offline

    chaseoes Retired Staff

    You can. But I need the script to then process *both* of those variables and return the necessary information for both of them on the same page.
     
  21. Offline

    Bertware

    I would just embed the script on every page you need it, for every plug-in you want to show, and provide the plugin name in the URL.
     
  22. Offline

    chaseoes Retired Staff

    Except I need it on the same page. :/
     
  23. Offline

    Bertware

    embed it twice?

    Or modificate it, so you can add
    ?plugin1="plugin"&plugin2="pluginname"
     
  24. Offline

    chaseoes Retired Staff

    Exactly what I want to do! -.-
     
  25. Offline

    iKeirNez

    Send me a PM please so that I'll remember to code this for you when I get to my coding pc.

    Keir
     
Thread Status:
Not open for further replies.

Share This Page