SwiftApi

SwiftApi Logo

What is SwiftApi?

SwiftApi is an Apache Thrift based API for CraftBukkit Minecraft servers. This API allows simple calls to Bukkit methods over the internet using your favorite programming language. This plugin acts as the server component, allowing you to write client programs/websites/apps that can talk to your CraftBukkit server in almost any programming language!

What can you do with it?

Basically, SwiftApi allows you write awesome code and apps that can talk to and control your Minecraft server.

An example of such an app is MineCenter. Check it out at http://minecenter.org

Configuration Options

Edit the plugins/SwiftApi/config.yml file to your liking.

The most important options are:

# Authentication Information (CHANGE THESE)
username: admin
password: password
salt: saltines

Leaving these at default would make it easy for an attacker to use this API on your server.

Creating a Client App

Once you have downloaded the Apache Thrift compiler, you can create a client app in a few lines of code.

Check out the example PHP project here: https://github.com/phybros/swiftapi-example-php

Try the C#.NET/VB.NET tutorial here: http://dev.bukkit.org/server-mods/swiftapi/pages/examples/c-net-vb-net/

Generate the Client Library

You can generate the client library (example is in C#) by typing

thrift -r --gen csharp SwiftApi.thrift

The -r option tells the compiler to generate code for all files (including ones that are referenced in SwiftApi.thrift with the include directive. The gen csharp option tells the compiler to generate C# code. This command will leave you with a gen-csharp directory with all the code you need to connect to a server running the SwiftApi plugin.

Include the Code in your App

If you're using C#, you can just drag all the source files right into your client app to use them, or alternatively you could create a new project with the generated files to keep your code and the generated code seperate.

Examples

Visit the Examples page for examples of how to use the code.

Here's an example in C#:


//open a connection to a server running SwiftApi
TSocket socket = new TSocket("your.bukkitserver.org", 21111);
socket.Open();

//create a new SwiftApi client object
TBinaryProtocol protocol = new TBinaryProtocol(new TFramedTransport(socket));
SwiftApi.Client client = new SwiftApi.Client(protocol);

//get the server version and output it
Console.WriteLine("Server Version: " + client.getServerVersion(authString));

//close the connection
socket.Close();

Because the code is based on Apache thrift, you have access to all the complex types in the CraftBukkit API, such as the Player object.

This example is in C#, but the thrift compiler is able to create libraries for almost ANY programming language.

Visit the Examples page for examples in some other languages

Available Programming Languages

As of version 0.9.0 of Apache Thrift, the following languages are available:

  • Actionscript 3 (AS3)
  • C (using GLib)
  • C
  • C#
  • Cocoa (Objective-C on Mac OS and iOS)
  • Delphi
  • Erlang
  • Go
  • Haskell
  • Java
  • Javascript
  • OCaml
  • Perl
  • PHP
  • Python (including Twisted async support)
  • Ruby
  • Smalltalk

Documentation

Full API documentation (generated by the Thrift compiler!) is available at http://willwarren.com/docs/swiftapi/latest.

Code

Think you can improve SwiftApi? Fork the repo on GitHub and submit a pull request!

Repo URL: https://github.com/phybros/swiftapi

Notes

This plugin sends anonymous usage statistics to https://mcstats.org/

To opt out, set opt-out to true in plugins/PluginMetrics/config.yml

You must login to post a comment. Don't have an account? Register to get one!

  • Avatar of phybros phybros Mar 31, 2013 at 18:13 UTC - 0 likes

    @HammyHavoc: Go

    Sorry, I moved the C# page and didn't update the Examples page.

    The C#/VB.NET examples + demo can now be found here: http://dev.bukkit.org/server-mods/swiftapi/pages/examples/c-net-vb-net/

  • Avatar of HammyHavoc HammyHavoc Mar 28, 2013 at 15:18 UTC - 1 like

    I tried to take a look at your C# example for listing players, but I get this error when trying to access the page:

    "You don't have the permission to access the requested resource. It is either read-protected or not readable by the server.

    If you find this to be in error, please notify the administrators."

    http://www.splitanatom.com/SmallSplitAnAtom.png IP: minecraft.splitanatom.com or visit our website http://gaming.splitanatom.com

  • Avatar of Vincent1468 Vincent1468 Mar 17, 2013 at 14:55 UTC - 0 likes

    It would be nice if we could use color codes in the announce :)

  • Avatar of Vincent1468 Vincent1468 Feb 13, 2013 at 17:22 UTC - 0 likes

    @phybros: Go

    Indeed, I never used PHP. That was a mistake, thanks for you awnser!

  • Avatar of phybros phybros Feb 13, 2013 at 16:13 UTC - 1 like

    @Vincent1468: Go

    It sounds like you have never used PHP and don't really have a good idea as to what it is and what it can and can not do.

    PHP is a server-side scripting language, and as such, the browser never sees the PHP code. All it sees is the generated HTML.

    Not sure what this discussion has to do with this plugin though.

  • Avatar of Vincent1468 Vincent1468 Feb 13, 2013 at 06:27 UTC - 1 like

    I wanted to say that I'm really enjoying this plugin. But isn't PHP a bit insecure? People can use ctrl+s to save the webpage and see the code/edit it.

  • Avatar of phybros phybros Feb 03, 2013 at 01:03 UTC - 1 like

    Version 1.2 is on the way - fixed for compatibility with Recommended Build 1.4.7-R1.0

  • Avatar of phybros phybros Feb 01, 2013 at 00:31 UTC - 1 like

    @Vincent1468: Go

    MineCenter is made by me yes

  • Avatar of Vincent1468 Vincent1468 Jan 30, 2013 at 09:45 UTC - 1 like

    @phybros: Go

    Thanks, I get it now :) I already did some pretty cool stuff with it, for example if a player says '!day" to me on skype, the time on the server will change to day :) But could you add color codes for the announce? That would be great :) And is the Minecenter program made by you?

    Last edited Jan 30, 2013 by Vincent1468
  • Avatar of phybros phybros Jan 30, 2013 at 02:05 UTC - 1 like

    @Vincent1468: Go

    Glad to hear it.

    FYI, any of the data types in SwiftApi can be used like that. If you look at the definition of the World type (http://willwarren.com/docs/swiftapi/latest/SwiftApi.html#Struct_World), you can get any of its properties just by using their names like so:

    Dim worldName As String = world.Name
    Dim worldTime As Long = world.Time
    Dim worldRaining As Boolean = world.hasStorm
    

    And so on... Another example, to get a player's X coordinate, you can do

    Dim playersXCoordinate As Double = player.Location.X
    

    So it's all pretty simple to use.

Facts

Date created
Sep 03, 2012
Categories
Last update
Apr 12, 2013
Development stage
Release
Language
  • enUS
License
GNU General Public License version 3 (GPLv3)
Curse link
SwiftApi
Downloads
1,659
Recent files

Authors