ModsJava
Slingswap
Java mod listed for Minecraft 1.13–1.15. Downloads from the MC Java Mods app on Android.
⬇ Download on Spigot
Extend your plugin accessability with a neat JSON-based Web API!
General Information
Slingswap serves as a provider for REST API implementation within Bukkit or Spigot plugins. It runs a local web server on a configurable port (25560 by default, can be changed in config.yml) and listens to all requests performed on that web server. Any response will be returned in a JSON-format, so it's easily integratable into any web application you need it in.
A plugin needs to register any kind of request to Slingswap using "Hooks". A hook is basically a class registered by Slingswap along with its URL and method. Once called, hooks get passed the request URL, form data, query data and even header data to achieve a very flexible usage of the API.
Commands & Permissions
Because this plugin serves as an API provider and web server, there are no such things as commands and permissions needed. Concider this as an additional library that other plugins can make use of.
Implementation
Using the Slingswap-API is pretty easy. At first, add the Slingswap.jar to your build path / dependencies like usual.
Then you need to create a Hook:
Code (Java):
// Implement the SlingHook Interface
public class MyHook implements SlingHook {
@Override
public void ProcessRequest ( SlingRequest request, SlingResponse response ) {
/*
** YOUR REQUEST HANDLING HERE
*/
}
}
public class MyHook implements SlingHook {
@Override
public void ProcessRequest ( SlingRequest request, SlingResponse response ) {
/*
** YOUR REQUEST HANDLING HERE
*/
}
}
Code (Java):
@Override
public void onEnable ( ) {
Slingswap. RegisterHook ( "my/hook" , new MyHook ( ) ) ;
}
public void onEnable ( ) {
Slingswap. RegisterHook ( "my/hook" , new MyHook ( ) ) ;
}
SlingRequest usage
Code (Java):
request.
Header
(
"User-Agent"
)
;
// Retrieve a header value.
// This case: User Agent.
// NULL if unset
request. Query ( "data" ) ; // Retrieve Data from Query.
// This case, if the URL is
// "/my/api?data=12345", the
// method will return "12345"
request. Body ( "username" ) ; // Returns body data from a
// possible x-www-form-urlencoded
// POST or similar body
// This case: User Agent.
// NULL if unset
request. Query ( "data" ) ; // Retrieve Data from Query.
// This case, if the URL is
// "/my/api?data=12345", the
// method will return "12345"
request. Body ( "username" ) ; // Returns body data from a
// possible x-www-form-urlencoded
// POST or similar body
SlingResponse usage
Code (Java):
response.
Code
=
404
;
// Set the HTTP/1.1 Response Code
// to a specific value, this case
// 404 Not Found
response. Data . Add ( "key" , "Value" ) ; // Adds "key" : "value" to the final
// JSON response. You can use nearly
// any base type for this - Strings,
// Integers, Floats, Boolean, as well
// as Arrays of those.
// to a specific value, this case
// 404 Not Found
response. Data . Add ( "key" , "Value" ) ; // Adds "key" : "value" to the final
// JSON response. You can use nearly
// any base type for this - Strings,
// Integers, Floats, Boolean, as well
// as Arrays of those.
Nesting JSON response
In case you want to return nested JSON objects, take a look at the Storager object. Basically. response.Data already is a predefined Storager object in which you can put other Storager objects.
Be careful though : Don't mess around with any kinds of circular structure due to possible overall-fuckups of your server! My current JSON-parser will try to print this circular structure and - of course - will never end. I plan to implement a safety mechanism for preventing this in the future.
Code (Java):
Storager nest
=
new Storager
(
)
;
nest. Add ( "name" , "Parter Peker" ) ;
nest. Add ( "age" , 12 ) ;
nest. Add ( "height" , 1.48 ) ;
nest. Add ( "imposter" , true ) ;
response. Data . Add ( "personal_details" , nest ) ;
nest. Add ( "name" , "Parter Peker" ) ;
nest. Add ( "age" , 12 ) ;
nest. Add ( "height" , 1.48 ) ;
nest. Add ( "imposter" , true ) ;
response. Data . Add ( "personal_details" , nest ) ;
Quick facts
- Edition: Minecraft Java
- File type: .jar
- Minecraft versions listed: 1.13, 1.14, 1.15
- How to install: Install the matching mod loader (Forge, Fabric or NeoForge) for your Minecraft version. → Download the .jar. → Put it in the .minecraft/mods folder and launch that loader profile.
- Where to get it: Opens on Spigot — not every file is mirrored on our own servers.
Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.
Slingswap is a free Minecraft Java mod. Compatible with Minecraft 1.13, 1.14, 1.15. Downloaded 224 times (via Spigot). Download it and open it directly in the game.