Wrong values in AsyncPlayerPreLoginEvent.Result
PilgrimViis opened this issue ยท 2 comments
Hi. I'm trying to use this method in event handler https://hub.spigotmc.org/javadocs/spigot/org/bukkit/event/player/AsyncPlayerPreLoginEvent.html#disallow-org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result-java.lang.String-
My js code is something like this
function onPlayerPreLogin(evt, cancel){
evt.disallow(org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result.KICK_OTHER, "Sorry for inconvinience, maintenance in progress");
}
events.asyncPlayerPreLogin( onPlayerPreLogin);
I'm getting exception like this enum doesn't exist at all. And when I write in console
/js org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result. and press Tab I'm getting values (DEFAULT, ALLOW, DENY) but in docs there are no such values at all
[18:20:40] [User Authenticator #32/ERROR]: Could not pass event AsyncPlayerPreLoginEvent to scriptcraft v3.2.1-2017-09-23 java.lang.RuntimeException: java.lang.NoSuchMethodException: None of the fixed arity signatures [(org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result, java.lang.String), (org.bukkit.event.player.PlayerPreLoginEvent.Result, java.lang.String)] of method org.bukkit.event.player.AsyncPlayerPreLoginEvent.disallow match the argument types [jdk.nashorn.internal.runtime.Undefined, java.lang.String] at org.bukkit.plugin.EventExecutor$$NashornJavaAdapter.execute(Unknown Source) ~[?:?] at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[spigot2.jar:git-Spigot-642f6d2-6103339] at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) [spigot2.jar:git-Spigot-642f6d2-6103339] at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:482) [spigot2.jar:git-Spigot-642f6d2-6103339] at net.minecraft.server.v1_12_R1.LoginListener$LoginHandler.fireEvents(LoginListener.java:271) [spigot2.jar:git-Spigot-642f6d2-6103339] at net.minecraft.server.v1_12_R1.LoginListener$2.run(LoginListener.java:187) [spigot2.jar:git-Spigot-642f6d2-6103339] Caused by: java.lang.NoSuchMethodException: None of the fixed arity signatures [(org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result, java.lang.String), (org.bukkit.event.player.PlayerPreLoginEvent.Result, java.lang.String)] of method org.bukkit.event.player.AsyncPlayerPreLoginEvent.disallow match the argument types [jdk.nashorn.internal.runtime.Undefined, java.lang.String] at jdk.internal.dynalink.beans.OverloadedMethod.throwNoSuchMethod(OverloadedMethod.java:202) ~[nashorn.jar:?] at jdk.nashorn.internal.scripts.Script$Recompilation$4712$183AA$\^eval\_.L:1#onPlayerPreLogin(<eval>:12) ~[?:?] at jdk.nashorn.internal.scripts.Script$Recompilation$4505$1377AA$\^eval\_.L:1#on#execute(<eval>:61) ~[?:?] ... 6 more
Any suggestions?
@Gloorf, thanks a lot. It works.
I had the same exact issue ! I haven't dig deep to understand the real problem, but as a quick fix you can use Java.type to get the Result Enum (& the kick reason) :
var kickReason = Java.type("org.bukkit.event.player.AsyncPlayerPreLoginEvent.Result").valueOf("KICK_OTHER");
event.disallow(kickReason, "Sorry, maintenance");