Working with Rhino

MineHacker is a powerful tool for creating full-blown Bukkit mods using the power of the Rhino JavaScript runtime. If you already know Rhino JavaScript, MineHacker should be a breeze to pick up. If not, here are a few tips to get you started. If you already know how to use Rhino, you can skip to the API docs on the next page.

 

Java getter/setters are mapped to property names.

So e.g. instead of player.getUniqueId() you can just write player.uniqueId

 

String passed from Java are not JavaScript strings

The following code will fail since Java strings are unequal to each other:

if (server.getPlayer("John_Clarkson").world.name == "world_nether") { }

 Instead, we must cast the Java string to a JavaScript string and then compare:

if (server.getPlayer("John_Clarkson").world.name + "" == "world_nether") { }

 

Classes and Interfaces can be extended by using a JavaAdapter

So e.g. to create a conversation Prompt you could do:

var prompt = new JavaAdapter(org.bukkit.conversations.Prompt, {
 acceptInput: function ​(context, input) { }
 blocksForInput: function ​​(context) { }
 getPromptText​: function ​(context) { }
})

 

That's the gist of scripting with Rhino. Next up you should have a look at the MineHacker API docs to get a list of useful shortcut APIs for scripting Bukkit.


Comments

Posts Quoted:
Reply
Clear All Quotes