First thing: Don’t want to offend anyone with the title - the title is a working title and has nothing to do with an official Sponge Powered plugin.
I wanted to make it possible to write plugins, scripts, commands etc. using multiple languages and not only Java.
Other plugins (Skript, ScriptCraft and more) offer scripting but all of the creates there own custom language. I really people to be able to use the languages they already knew and to use the API that the Sponge team already spend alot of time designing. Why reinvent something that other people has already perfected, when we could just combine those things?
So I started to play around with Java’s build in scripting engine (JSR-223), and found that to give a lot of possibilities in writing scripts in alot of scripting languages. And the JSR-223 design provides access the to full Java API, which then also includes the Sponge API.
My initial version of this includes scripts in JavaScript and Groovy, where I playing around with event listeners and changing blocks. I created a small script what changes a block into a dirt block when the player hits the block, just to prove that it worked. And it did!!!
Plans for this plugin:
- Core script engine (kinda done)
- Possible to write scripting-plugin (work in progress)
- JavaScript support (kinda working out-of-the-box with Java needs more finetuning and testing)
- Groovy support (kinda working out-of-the-box with Java needs more finetuning and testing)
- Sandboxing of scripts (limit what the scripts are allowed to do)
Future ideas:
- Blockly IDE to make it possible to build plugins using the visual programming of Google’s Blockly (May be created as a seperate project)
- Lua support (there are multiple implementations of JSR-223)
- Python support (there are multiple implementations of JSR-223)
- Ruby support (there are multiple implementations of JSR-223)
- Scala support (there are multiple implementations of JSR-223)
- Simplified Sponge API (shortcut API for common used tasks (like change block etc.), to make it easier for people to write a simple plugin)
- Support other languages that already has a JSR-223 implementation.
I will add a link to source and a first early-alpha release very soon.
Suggestions are very welcome, also for a title for the project.
Example of a plugin written in JavaScript
var EventListener = Java.type("org.spongepowered.api.event.EventListener");
var BlockTypes = Java.type("org.spongepowered.api.block.BlockTypes");
var Player = Java.type("org.spongepowered.api.entity.living.player.Player");
var InteractBlockEvent = Java.type("org.spongepowered.api.event.block.InteractBlockEvent");
var ItemTypes = Java.type("org.spongepowered.api.item.ItemTypes");
sponge.getLogger().debug("*** Dirt Punch loading");
var myEventListener = new EventListener({
handle: function(event) {
sponge.getLogger().debug("*** Block punched");
var player = event.getCause().first(Player.class).get();
var itemInHand = player.getItemInHand().get();
if (itemInHand.getItem().equals(ItemTypes.STICK)) {
var punchedBlock = event.getTargetBlock();
punchedBlock.getLocation().get().setBlockType(BlockTypes.DIRT);
}
}
});
sponge.registerEventListener(InteractBlockEvent.Secondary.class, myEventListener);
sponge.getLogger().debug("*** Dirt Punch loaded");