[Discontinued] ✏ Create a plugin in JavaScript [v2.0.2]

Update v2.0

Tested on SpongeAPI: 4.1.0
Require SpongeForge

Links

1 Like

What else :sunglasses:

You even took time to update the documentation, thank you sir !

1 Like

put it into my mods folder, and it looked for Djxycore on launch. should toss that into the wiki. looks handy though!

Added the dependency to the wiki.

1 Like

is this still building on the forge and sponge versions listed on this page? i’m having some trouble during server startup. thanks for any replies :slight_smile:

Yeah I forgot to add that, it only works with SpongeForge

Spongeforge-1.8.9-1694-3.1.0-BETA-1090 still? or a newer version?

Tested on SpongeAPI 4.1.0

1 Like

i figured out my issue, it came down to the 2.0 release not including nashorn.jar

after copying nashorn.jar from a 1.0 download, it works like a charm. :smiley:

Sorry my bad. I will add it to the release.

I think “/js reload” is not a good way to live test :frowning:
In your example script, everything is loaded “onGameInitializationEvent” and it removes everything from memory.

Basically, I created a folder “example” with a file “main.js” containing all of your plugin example. When using “/js reload example” it simply removes the command /job

So I had a simple try with a folder “log” containing “main.js” containing “console.log(“hello world”);” and when using /reload log I get :

Right now, my test environment is :

forge-1.8.9-11.15.1.1855-universal.jar
minecraft_server.1.8.9.jar
-/mods
–spongeforge-1.8.9-1855-4.1.0-BETA-1312.jar
–SpongeJavaScript.jar
–nashorn.jar
–DjxyCore-1.0.jar

Under debian jessie with openjdk-8-jdk

Actually, your example plugin throws this unsatisfaying thing :

[quote]
[16:32:51] [Server thread/ERROR] [Sponge/]: Error occurred while executing command ‘job 1 10’ for source EntityPlayerMP[‘Keuterio’/279, l=‘world’, x=-179.87, y=64.00, z=335.34]: ReferenceError: “Player” is not defined
jdk.nashorn.internal.runtime.ECMAException: ReferenceError: “Player” is not defined
at jdk.nashorn.internal.runtime.ECMAErrors.error(ECMAErrors.java:57) ~[ECMAErrors.class:?]
at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:319) ~[ECMAErrors.class:?]
at jdk.nashorn.internal.runtime.ECMAErrors.referenceError(ECMAErrors.java:291) ~[ECMAErrors.class:?]
at jdk.nashorn.internal.objects.Global.noSuchProperty(Global.java:1432) ~[Global.class:?]
at jdk.nashorn.internal.scripts.Script$Recompilation$9$1545AA$^eval_.createCommand$executor(:44) ~[?:?]
at jdk.nashorn.internal.runtime.ScriptFunctionData.invoke(ScriptFunctionData.java:644) ~[ScriptFunctionData.class:?]
at jdk.nashorn.internal.runtime.ScriptFunction.invoke(ScriptFunction.java:228) ~[ScriptFunction.class:?]
at jdk.nashorn.internal.runtime.ScriptRuntime.apply(ScriptRuntime.java:393) ~[ScriptRuntime.class:?]
at jdk.nashorn.api.scripting.ScriptObjectMirror.call(ScriptObjectMirror.java:117) ~[ScriptObjectMirror.class:?]
at io.github.djxy.spongejavascript.script.util.CommandManager$CommandExecutor.execute(CommandManager.java:171) ~[CommandManager$CommandExecutor.class:?]
at org.spongepowered.api.command.spec.CommandSpec.process(CommandSpec.java:331) ~[CommandSpec.class:1.8.9-1855-4.1.0-BETA-1312]
at org.spongepowered.api.command.dispatcher.SimpleDispatcher.process(SimpleDispatcher.java:331) ~[SimpleDispatcher.class:1.8.9-1855-4.1.0-BETA-1312]
at org.spongepowered.common.command.SpongeCommandManager.process(SpongeCommandManager.java:268) [SpongeCommandManager.class:1.8.9-1855-4.1.0-BETA-1312]
at net.minecraft.command.ServerCommandManager.func_71556_a(SourceFile:80) [bd.class:?]
at net.minecraft.network.NetHandlerPlayServer.func_147361_d(NetHandlerPlayServer.java:815) [lm.class:?]
at net.minecraft.network.NetHandlerPlayServer.func_147354_a(NetHandlerPlayServer.java:794) [lm.class:?]
at net.minecraft.network.play.client.C01PacketChatMessage.func_148833_a(SourceFile:37) [ie.class:?]
at net.minecraft.network.play.client.C01PacketChatMessage.func_148833_a(SourceFile:9) [ie.class:?]
at org.spongepowered.common.network.PacketUtil.onProcessPacket(PacketUtil.java:107) [PacketUtil.class:1.8.9-1855-4.1.0-BETA-1312]
at net.minecraft.network.PacketThreadUtil$1.redirect$onProcessPacket$0(SourceFile:39) [fh$1.class:?]
at net.minecraft.network.PacketThreadUtil$1.run(SourceFile:13) [fh$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [?:1.8.0_72-internal]
at java.util.concurrent.FutureTask.run(FutureTask.java:266) [?:1.8.0_72-internal]
at net.minecraft.util.Util.func_181617_a(SourceFile:44) [g.class:?]
at net.minecraft.server.MinecraftServer.func_71190_q(MinecraftServer.java:660) [MinecraftServer.class:?]
at net.minecraft.server.dedicated.DedicatedServer.func_71190_q(DedicatedServer.java:344) [ko.class:?]
at net.minecraft.server.MinecraftServer.func_71217_p(MinecraftServer.java:605) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:481) [MinecraftServer.class:?]
at java.lang.Thread.run(Thread.java:745) [?:1.8.0_72-internal][/quote]

Any idea of what I did wrong ?

Yeah, there is two new events. onStart and onStop. onStart is when the script has reloaded and onStop is just before the reload.

These events should be used only in development.

I forgot to add them to the wiki.

EDIT: Reload events

Hail master \o/
I will only use for development purposes of course, it is so much convenient.

Edit : working like charm now but I still cannot type “/job 1 10” as I get the error “Player is not defined”.

I will look closely later, thanks for support !

Can I see you code?

Update v2.0

  • New translation
  • fr_FR. Thanks to @Advancid for the translation.

Links

Sure, I had a bad ratio inspiration/time so I took this one :
https://github.com/djxy/SpongeJavaScript/wiki/Plugin-example

:stuck_out_tongue:

Edit :
Looks line “if(typeof commandSource == typeof Player.class)” is the problem in function createCommand()

Code here : http://pastebin.com/ckex6AyR
I use latest build of SpongeJavascript

Thanks to report the error. I found the problem and I will try to upload a patch tonight.

My pleasure, do you want me to create tickets on github or better here ?

Here, I’ll respond faster.

Update v2.0.1

  • Fix a bug with instanceof.
  • Example: commandSource instanceof Player.class to check if it is a player.
  • Player class is now by default in the scripts.

Links