ScriptCraft
ScriptCraft lets you create your own mods using Javascript. ScriptCraft uses the CommonJS module system (the same module loading system used by Node.js) so managing your code will be easier. You can also run Javascript code on the in-game command prompt or extend the game by writing plugins that use the Bukkit API in javascript.
Examples:
At the command prompt type:
/js 1 + 1
> 2
... Any javascript code can be evaluated at the in-game command prompt.
/js alert( 'Hello ' + self.name )
> Hello walterh
... Special bukkit variables are available via javascript , for example the server
object is the instance of org.bukkit.Server . Writing event handlers in ScriptCraft is relatively easy...
events.blockBreak( function( event ) {
echo(event.player, 'You broke a block!' );
});
events.playerJoin( function( event ) {
echo( event.player, 'Welcome to the server!' );
});
... Any bukkit event can be handled. The above code prints the name of any player who breaks a block in the game. ScriptCraft comes with some built-in functions to make building easier...
/js box( blocks.wool.black, 4, 9 , 1)
... creates a 2001 Monolith 4 blocks wide by 9 blocks high by 1 block long.
The full bukkit API can be used via javascript to write new mods. Yes - you can write bukkit plugins in javascript! See ScriptCraft on GitHub for more information. Full documentation is available on the github docs page.
A Youtube Video demonstrating Exploding Arrows in ScriptCraft A Youtube video demonstrating a mini-game (SnowBall Fight)
It's work. thx
<<reply 1972341="">>
You can get the permissionsEx (or any other plugin) like this...
Generally if you want to use another plugin's API, then get the plugin object by name and then call its methods. Hope this helps.
Walter
How to use other bukkit plugins API?
Like PermissionEX API.
I can check permission group by java code:
ru.tehkode.permissions.bukkit.PermissionsEx.getUser(player).inGroup("moderator");
But I can't run this code in JavaScript.
<<reply 1864460="">>
The new 'commando' function / plugin lets you create custom commands so that you don't need to prefix your command with 'jsp' . The 'commando()' function is called exactly the same way as command(). Example:
At the in-game prompt type...
And it will display...
You can get the very latest release at http://scriptcraftjs.org/downloads
@ray73864
Short answer: the feature isn't planned. See https://github.com/walterhiggins/ScriptCraft/issues/83
Long answer: you can hack up a workaround, either with a separate alias plugin, or by writing some event handlers.
You will have to create a module for it that grabs the PlayerCommandPreprocessEvent and just manipulate it like that.
Read up on
http://jd.bukkit.org/dev/apidocs/org/bukkit/event/player/PlayerCommandPreprocessEvent.html
for more info
(note that if you want to do the same for Console commands, you'll have to look into the event.server.ServerCommandEvent)
Will it eventually be possible to expose a command using the command() function through the standard bukkit/minecraft command handler?
That way, instead of having to type something like '/jsp home <home to tp to>' the player can just type '/home <home to tp to>'?
We currently use CommandHelper, and i'm liking the idea of what you have going here, that's just one feature i would find extremely handy.
@vivredraco
Yes. Scriptcraft can use the API provided by BKCommonLib or any other craftbukkit plugin which is installed.
Is it possible to access the BKCommonLib API through JS using ScriptCraft?
<<reply 1738288="">>
No. Javascript cannot access private members, what the JS interpreter does is provide a handy shortcut for JavaBeans - that's all. So for example if you have a Java class with 2 methods,
getPropX()
andgetPropY()
, the js interepreter embedded in java will let you access the propX and propY bean properties like this....It's a shorthand for JavaBeans provided by the JS interpreter - that's all . See http://download.java.net/jdk8/docs/technotes/guides/scripting/programmer_guide/index.html for more information.
So in javascript,
event.getPlayer().getName()
becomes the more succinctevent.player.name
(because both the Event and Player objects follow the JavaBean spec for naming accessor methods).js bukkit.on("block.BlockBreakEvent", function(lstnr, evt){ echo( evt.player.name + " broke a block!") ; });
Also why is this code working? In java plugin you cant access player Object directly. Does it mean that I can access private fields from javascript?
player.AsyncPlayerChatEcent and player.PlayerChatEvent do not work for some reason. Tried to simply echo or server.broadcastMessage() (Which may be used async even though undocumented). Nothing happens.
Also I finished modifying that teleporter plugin but for some reason it fails at getting entrySet() from a hashmap. I think I will write it as a normal plugin in java, but it is interesting why doesn't it work. Here is what I have. Check it out if it is interesting for you.
http://pastebin.com/6DUFpnd2
<<reply 1735250="">>
You can access
__plugin
,server
and other globals from a javascript .js file . The only variable that isn't safe to access (outside of the in-game command prompt) isself
..... will disable and then re-enable the ScriptCraft plugin (and only the scriptcraft plugin).
This is what you want to call.
@walterhiggins
I wanted to save a bukkit Object. At first I thought that you save "store" using java and binary streams. But then I saw .txt store files in js folder. ;D Well, its fine this way too. I can just serialize and desirialize everything. Only 1 thing left. Is there any way to reload your plugin? Sometimes I may mess up with a script and after loading it on the server I need to somehow reset everything. /reload command is not an option for me.
Also can I access such vars as server or plugin from a javascript file?
@blackalegator
I'm 95% sure you can't (The stored object is stored in JSON format so the object must be one which can be stringified using the 3rd party json2 library). What Java object type do you want to store? Is there a good Javascript equivalent?
Can I store java objects inside store?
I dont think I can, but I just have to make sure
@blackalegator
OK. A couple of things...
You should declare 'test' like this...
var test = {};
... that way it's declared as an object. 2. Player.getEyeLocation() returns a Location object so you can't set that as a key for a javascript object (javascript objects are not like Java Map objects in that sense - only a javascript number or string can be a property in a javascript object).
I'd recommend you declare 'test' as a java.util.HashMap instead since that seems to be how you want to use it.
var test = new java.util.HashMap();
var player = server.onlinePlayers[0];
test.put(player.eyeLocation, player.targetBlock(null, 10) );
the 'for (var a in test)' loop construct won't as far as I know work for java.util.HashMap so you'll have to use a java-type iterator loop instead.
Hmmm I wrote a plugin: http://pastebin.com/r65Z42F6
For some reason after adding any entries and restarting server I get this in my log
http://pastebin.com/d3jGfD5x
After server is back up I loose everything that was aved iside plugin.store.
Also it is very strange, but I cant use Bukkit objects as a map keys. eg: var test; var test[server.getOnlinePlayers()[0].getEyeLocation()] = server.getOnlinePlayers()[0].getTargetBlock(null,10); for(var a in test){ if((a instanceof org.bukkit.Location) === false) echo("False") }
This will print out false
@blackalegator
This plugin is just amazing. Seriously, I can masturbate on it.
Thanks. Please don't. :-)
something like myBean.getMyProp() can be simplified to just myBean.myProp in javascript so...
if(e.getAction() === e.getAction().LEFT_CLICK_BLOCK){ do smth }
... can be shortened to ...
importClass("org.bukkit.event.block.Action");
if(e.action === LEFT_CLICK_BLOCK){ do smth }
... I *think* this should work but haven't tried it out yet.
See http://download.java.net/jdk8/docs/technotes/guides/scripting/programmer_guide/index.html#jsimport for information on importing packages and classes in Javascript.
This plugin is just amazing. Seriously, I can masturbate on it. Just one thing though... how do I access enums? Or at least some classes; objects? right noww I have to do smth like
if(e.getAction() === e.getAction().LEFT_CLICK_BLOCK){ do smth }
Is there a better solution? It would be great if I could acess all the packages and classes.
Nevermind again I am starting to get it :)