ScriptCraft

ScriptCraft

14.6k Downloads

How to use an enumeration?

Opened this issue ยท 4 comments

commented

Hello,

Sorry, if this post is not appropriate for this place, I didn't know where to send it.
So my question is simple, I would like to use the setGameMode method but this method takes as a parameter an enumeration, out when I try to write it as a string or without a string I have an error. So after that, I asked myself this probably silly question, how to use the enumerations?

Thank you in advance for your help.

commented

All right I found this: var GameMode = Packages.org.bukkit.GameMode;. If anyone knows any other way to do it, please share it with me.

commented

I do it like this in Magikcraft:

const GameMode = Java.type("org.bukkit.GameMode");
const modes = {
    c: GameMode.CREATIVE,
    s: GameMode.SURVIVAL,
    x: GameMode.SPECTATOR
}

Magikcraft uses TypeScript, but it should work in vanilla ScriptCraft if you replace const with var.

See here: https://github.com/jwulf/magikcraft-spells--jwulf/blob/master/GM.js

commented

Maybe it's better if I create another topic.
I put this one as resolved.

commented

Thanks for sharing it works, by searching a little more on Magikcraft, I didn't find a tutorial or page laying the basics to get started, but I still found the API documentation, if you know of a useful link in that sense I would like to. :) . By doing a little research I understood that Java.type() was part of the Nashorn engine out I thought ScriptCraft was using Rhino, I'm a little lost, would you explain it to me please? In addition, I did not find many documents on Rhino except for the few pages on MDN, which I find very poor. However as far as Nashorn is concerned I was able to find the Oracle documentation, but if you know of any interesting resources to read to learn more about Nashorn I would ask you to let me know.