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

Good news ! Thanks for updating

1 Like

This is still a nope :frowning:

Code : http://pastebin.com/ExbnECF3
Using latest version 2.0.1 of SpongeJavascript

Ingame I have the same message “Error occured while executing command : Reference Error : “Player” is not defined”

Update v2.0.2

  • Fix a bug with Player class.

Links

No more bugs !

Nonetheless, your example plugin is still not working as you register blockId in command and you get blockName in event, I figured out with this code http://pastebin.com/35ELGacu

I am a total beginner with spongeApi so I was not able to get blockId from event.transactions[0] :flushed:
(Thus I tried to stringify the event object, I got no result)

1 Like

Wow! I was already looking into making a plugin that did this exact same thing about a month ago. I had already researched how to use Java’s ScriptEngine too.

Well good luck with developing this, I’ll keep an eye on this and give any suggestions or help I can.

1 Like

Cool, if you want to contribute, sent a commit and I will look. I’m open to all suggestions and new ideas.

You don’t have the link to your dependencie in first post.

Also, how is it possible to have blockId in breakBlockEvent ?

Try this event.transactions[0].original.state.type.name

Thanks, i’ll give it a try.

Also, did you try your mod with sponge vanilla ? I had many errors so I went back to sponge forge and it was ok.

It doesn’t work with SpongeVanilla because Nashorn isn’t loaded. So my plugin doesn’t had his dependency.

There is no way to have nashorn loaded or included in your plugin ? So we can use it with SpongeVanilla, not everyone wants SpongeForge.

event.transactions[0].original.state.type.name

Is already in your example and it returns “minecraft:stone” not “1” :frowning:

1 Like

When I log the event, I got this :

So, can I get blockId from minecraft:stone or in the other way when registering the broken block, getting minecraft:stone from 1 ?

I think this item id thinking doesn’t exist anymore in Minecraft. You can’t do /give kitcrafty 137, instead /give kitcrafty minecraft:command_block. Maybe there is a legacy support from sponge (like formatting colors). Why would you want to know the old id?

Oh, that’s a new thing popping out. I didn’t know, it would explain why I couldn’t give me stone with /give 1
In fact, I am used to numbers, easier to type :stuck_out_tongue:

In this case, the example plugins aims to pay people when they break a block.
You configure how much you want per block with
/job [block] [amount to pay]

So I did
/job 1 10

But I should change to
/job minecraft:stone 10

2 Likes

Sorry for double posting :blush:

I am having hard time with object player.

When breaking a block, in my event I can do player.sendMessage() but player.getName() nor player.getItemInHand() are working.

I am still testing with sample plugin and I want to getItemInHand from commandSource to avoid writing full name of item (i.e minecraft:stone)

Any help would be greatly appreciated :slight_smile:

They return an error??

Yup, it does with getItemInHand but not with getName :

listener: function(event, player){
[…]
player.sendMessage(Text.of("Your name is "+player.getName()));
[…]
}
Returns :
Your name is null

The functions who starts with get or set are converted like this: player.getName() is now player.name and player.setName("Djxy") is now player.name = "name"

1 Like

So I should type without set or get. I was using your example :

player.name is working like a charm, thanks ! I am going to try to get itemInHand now and I suppose I will need to use item.class to get its name !

I thought like .set...(...) and .value are the same, .get...(...) and .value = ... are the same. And why not?