TriggerReactor / TriggerReactor

Simple script parser with infinite possibility
GNU General Public License v3.0
50 stars 18 forks source link

inconsistent notation for importing inner classes #256

Open 305pence opened 4 years ago

305pence commented 4 years ago

Basically, i'm having trouble with importing org.bukkit.entity.EnderDragon.Phase

i tried this code to summon an ender dragon and set it's phase so it doesn't just float there

IMPORT org.bukkit.entity.EntityType
IMPORT java.lang.Math
IMPORT org.bukkit.entity.EnderDragon.Phase
FOR player = getPlayers()
 world = $world
ENDFOR
pu = {"location.shrine"} 
locS = pu.clone()
pu = {"location.mobspawn"} 
locM = pu.clone()
x = locM.getX() - locS.getX()
z = locM.getZ() - locS.getZ()
rAngle = Math.atan(x/z)
IF z < 0
 angle = Math.toRadians(180) + rAngle
ELSE
 angle = rAngle
ENDIF
loc = locS.add(64*Math.sin(angle), 15, 64*Math.cos(angle))
dragon = world.spawnEntity(loc, EntityType.ENDER_DRAGON)
dragon.setPhase(EnderDragon.Phase.CHARGE_PLAYER)

and i got the error below

[20:31:34] [Server thread/WARN]: java.lang.Exception: Could not finish interpretation for [bug]!
[20:31:34] [Server thread/WARN]:        at io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager$Trigger.start(AbstractTriggerManager.java:409)
[20:31:34] [Server thread/WARN]:        at io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager$Trigger$1.call(AbstractTriggerManager.java:359)
[20:31:34] [Server thread/WARN]:        at io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager$Trigger$1.call(AbstractTriggerManager.java:355)
[20:31:34] [Server thread/WARN]:        at org.bukkit.craftbukkit.v1_14_R1.scheduler.CraftFuture.run(CraftFuture.java:88)
[20:31:34] [Server thread/WARN]:        at org.bukkit.craftbukkit.v1_14_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:394)
[20:31:34] [Server thread/WARN]:        at net.minecraft.server.v1_14_R1.MinecraftServer.b(MinecraftServer.java:1022)
[20:31:34] [Server thread/WARN]:        at net.minecraft.server.v1_14_R1.DedicatedServer.b(DedicatedServer.java:393)
[20:31:34] [Server thread/WARN]:        at net.minecraft.server.v1_14_R1.MinecraftServer.a(MinecraftServer.java:970)
[20:31:34] [Server thread/WARN]:        at net.minecraft.server.v1_14_R1.MinecraftServer.run(MinecraftServer.java:815)
[20:31:34] [Server thread/WARN]:        at java.lang.Thread.run(Unknown Source)
[20:31:34] [Server thread/WARN]: Caused by: io.github.wysohn.triggerreactor.core.script.interpreter.InterpreterException: Error at row[3], col[43]
[20:31:34] [Server thread/WARN]:        at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.interpret(Interpreter.java:921)
[20:31:34] [Server thread/WARN]:        at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:483)
[20:31:34] [Server thread/WARN]:        at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.startWithContextAndInterrupter(Interpreter.java:199)
[20:31:34] [Server thread/WARN]:        at io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager$Trigger.start(AbstractTriggerManager.java:404)
[20:31:34] [Server thread/WARN]:        ... 9 more
[20:31:34] [Server thread/WARN]: Caused by: java.lang.ClassNotFoundException: org.bukkit.entity.EnderDragon.Phase
[20:31:34] [Server thread/WARN]:        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:86)
[20:31:34] [Server thread/WARN]:        at org.bukkit.plugin.java.PluginClassLoader.findClass(PluginClassLoader.java:81)
[20:31:34] [Server thread/WARN]:        at java.lang.ClassLoader.loadClass(Unknown Source)
[20:31:34] [Server thread/WARN]:        at java.lang.ClassLoader.loadClass(Unknown Source)
[20:31:34] [Server thread/WARN]:        at java.lang.Class.forName0(Native Method)
[20:31:34] [Server thread/WARN]:        at java.lang.Class.forName(Unknown Source)
[20:31:34] [Server thread/WARN]:        at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.interpret(Interpreter.java:915)
[20:31:34] [Server thread/WARN]:        ... 12 more
[20:31:34] [Server thread/INFO]: Could not execute this trigger.
[20:31:34] [Server thread/INFO]:  >> Caused by:
[20:31:34] [Server thread/INFO]: Could not finish interpretation for [bug]!
[20:31:34] [Server thread/INFO]:  >> Caused by:
[20:31:34] [Server thread/INFO]: Error at row[3], col[43]
[20:31:34] [Server thread/INFO]:  >> Caused by:
[20:31:34] [Server thread/INFO]: org.bukkit.entity.EnderDragon.Phase
[20:31:34] [Server thread/INFO]: If you are administrator, see console for details.
wysohn commented 4 years ago

@305pence Hello,

The problem seems to be related to the inner class.

Java denote the inner class with $ sign instead of .(dot), so all you have to do is

IMPORT org.bukkit.entity.EnderDragon$Phase

Let us know if it doesn't work.

gerzytet commented 4 years ago

@wysohn In that case, would the class be called Phase or EnderDragon$Phase in your code?

wysohn commented 4 years ago

@gerzytet I believe it is just Phase

305pence commented 4 years ago

yeah, that seems to work

gerzytet commented 4 years ago

I'm reopening this as a low priority bug because requiring this internal notation for importing is inconsistent with java and the javadocs.

gerzytet commented 4 years ago

I'm especially suprised that no-one who uses sponge has complained yet. Sponge has inner classes everywhere