radic / bukkit-swift-api
SwiftApi PHP API wrapped in a laravel package for remote calls to a minecraft bukkit server.
Requires
- php: >=5.3.0
- illuminate/support: 4.*
This package is not auto-updated.
Last update: 2024-12-17 03:00:42 UTC
README
Wraps the Apache Thrift generated PHP library for SwiftAPI in a Laravel Package and provides easy access trough a Facade.
SwiftAPI is a Bukkit plugin that allows you to use the generated API to make simple calls to the Bukkit server over the webz. Or if wanted, you can generate it yourself using Apache Thrift. This makes SwiftAPI usable in almost any programming language.
Version 1.0.0
Overview
Requirements
- PHP >= 5.3
- Laravel >= 4.0
Installation
Require with composer:
composer require radic/bukkit-swift-api
Or add to composer.json:
{ "radic/bukkit-swift-api": "dev-master" }
Register service provder and facade in app/config/app.php
'providers' => array( // .. 'Radic\BukkitSwiftApi\BukkitSwiftApiServiceProvider', ), 'aliases' => array( // .. 'SwiftApi' => 'Radic\BukkitSwiftApi\Facades\SwiftApi', )
Configuration
Use php artisan config:publish radic/bukkit-swift-api
to edit the default configuration.
array( 'global' => array( 'host' => 'localhost', 'port' => 21111, 'username' => 'admin', 'password' => 'test', 'salt' => 'saltines' ), 'my-other-server' => array( 'host' => '11.11.11.11', 'username' => 'admin', 'password' => 'test' // If you left out config settings, it will use the global for that setting ) );
Connecting
There are several ways to connect:
// Uses global config settings $api = SwiftAPI::connect(); // Define all connection parameters inline $api = SwiftAPI::connect('ip-or-host', 4444, 'username', 'password', 'crypt-salt'); // null or left out parameters will default back to the global config $api = SwiftAPI::connect('ip-or-host', null, 'username', 'password'); // Uses 'my-other-server' from conffig. $api = SwiftAPI::connectTo('my-other-server');
Example connection:
$api = SwiftApi::connect(); if($api->isConnected()) { var_dump('Connected'); $serverInfo = $api->getServer(); $api->disconnect(); var_dump($serverInfo); } else { var_dump( $api->getConnectionException()->getMessage() ); }
API Methods
$api->addToWhitelist($name); $api->announce($message); $api->ban($name); $api->banIp($ip); $api->deOp($name, $notifyPlayer); $api->getBannedIps(); $api->getBannedPlayers(); $api->getBukkitVersion(); $api->getConsoleMessages($since); $api->getFileContents($fileName); $api->getOfflinePlayer($name); $api->getOfflinePlayers(); $api->getOps(); $api->getPlayer($name); $api->getPlayers(); $api->getPlugin($name); $api->getPlugins(); $api->getServer(); $api->getServerVersion(); $api->getWhitelist(); $api->getWorld($worldName); $api->getWorlds(); $api->installPlugin($downloadUrl, $md5); $api->kick($name, $message); $api->op($name, $notifyPlayer); $api->ping(); $api->reloadServer(); $api->removeFromWhitelist($name); $api->replacePlugin($pluginName, $downloadUrl, $md5); $api->runConsoleCommand($command); $api->saveWorld($worldName); $api->setFileContents($fileName, $fileContents); $api->setGameMode($name, $mode); $api->setPvp($worldName, $isPvp); $api->setStorm($worldName, $hasStorm); $api->setThundering($worldName, $isThundering); $api->setWorldTime($worldName, $time); $api->unBan($name); $api->unBanIp($ip);
See here which methods return data, and how that data is structured. A quick example:
$api = SwiftApi::connect(); $calls[] = $api->getServer(); $calls[] = $api->getPlugins(); $calls[] = $api->getOfflinePlayers(); $calls[] = $api->ping(); $calls[] = $api->getOps(); $api->disconnect(); var_dump($calls);
You'll get something like this in return
Further reading
- Bukkit SwiftAPI. The SwiftAPI Website.
- SwiftAPI Thrift Documentation. The docs for SwiftAPI generated Thrift code.
- Bukkit SwiftAPI Reposiotry. Repository for the SwiftApi Bukkit Java plugin.
Examples and goodies
Check my Laravel Bukkit Console. A web based console to directly interact with your Bukkit Server.
Credits
- Robin Radic created Laravel Bukkit SwiftApi
- Phybros created Bukkit SwiftAPI
License
GNU General Public License version 3 (GPLv3)