Sending Respawn Packet On Sync PlayerDeath
DontActLikeMe opened this issue ยท 16 comments
Hi im thinking of trying to send a respawn packet on the player death event. I want to do this synchronously,but i already have a playerdeathevent trigger that is async and i want to keep it out of the server thread. Is there a way to have an async event trigger so it doesnt stress the server, and a sync trigger of the same event that executes just a small snippet of code such as sending a respawn packet? Idk the possible ramifications of doing it this way but im just curious.
Thank you so much i know i ask so much of you lately XD but im just soaking all this in and learning. Thanks for dealing with me lol
No worries :) glad to see you enjoying it though.
Good luck with whatever you are doing now
Yeah triggerreactor was saying that it cant translate string into enum.
Error WARN Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Enum
WARN ... 47 more
09.11 18:43:02 [Server] WARN at com.comphenix.protocol.reflect.StructureModifier.write(StructureModifier.java:328)
09.11 18:43:02 [Server] WARN at com.comphenix.protocol.reflect.StructureModifier.writeInternal(StructureModifier.java:355)
09.11 18:43:02 [Server] WARN at com.comphenix.protocol.wrappers.EnumWrappers$EnumConverter.getGeneric(EnumWrappers.java:654)
09.11 18:43:02 [Server] WARN Caused by: java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Enum
09.11 18:43:02 [Server] WARN ... 40 more
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.callFunction(Interpreter.java:691)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.tools.ReflectionUtil.invokeMethod(ReflectionUtil.java:256)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.tools.ReflectionUtil.invokeMethod(ReflectionUtil.java:206)
09.11 18:43:02 [Server] WARN at java.lang.reflect.Method.invoke(Unknown Source)
09.11 18:43:02 [Server] WARN at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
09.11 18:43:02 [Server] WARN at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
09.11 18:43:02 [Server] WARN at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
09.11 18:43:02 [Server] WARN Caused by: java.lang.reflect.InvocationTargetException
09.11 18:43:02 [Server] WARN ... 39 more
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.interpret(Interpreter.java:543)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.callFunction(Interpreter.java:695)
09.11 18:43:02 [Server] WARN Caused by: io.github.wysohn.triggerreactor.core.script.interpreter.InterpreterException: Error executing fuction StructureModifier[fieldType=class net.minecraft.server.v1_12_R1.PacketPlayInClientCommand$EnumClientCommand, data=[private net.minecraft.server.v1_12_R1.PacketPlayInClientCommand$EnumClientCommand net.minecraft.server.v1_12_R1.PacketPlayInClientCommand.a]].write!
09.11 18:43:02 [Server] WARN ... 29 more
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.startWithContextAndInterrupter(Interpreter.java:136)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:166)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:292)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:185)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:292)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:166)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:292)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:185)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:292)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.start(Interpreter.java:296)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.interpret(Interpreter.java:651)
09.11 18:43:02 [Server] WARN Caused by: io.github.wysohn.triggerreactor.core.script.interpreter.InterpreterException: Error occured while processing Node [type: OPERATOR, value: '.'] at row[-1], col[-1]
09.11 18:43:02 [Server] WARN ... 28 more
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager$Trigger.start(AbstractTriggerManager.java:274)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.script.interpreter.Interpreter.startWithContextAndInterrupter(Interpreter.java:138)
09.11 18:43:02 [Server] WARN Caused by: io.github.wysohn.triggerreactor.core.script.interpreter.InterpreterException: While interpreting [type: ID, value: 'IF'] at row[3], col[2]
09.11 18:43:02 [Server] WARN at java.lang.Thread.run(Unknown Source)
09.11 18:43:02 [Server] WARN at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:577)
09.11 18:43:02 [Server] WARN at net.minecraft.server.v1_12_R1.MinecraftServer.C(MinecraftServer.java:679)
09.11 18:43:02 [Server] WARN at net.minecraft.server.v1_12_R1.DedicatedServer.D(DedicatedServer.java:406)
09.11 18:43:02 [Server] WARN at net.minecraft.server.v1_12_R1.MinecraftServer.D(MinecraftServer.java:748)
09.11 18:43:02 [Server] WARN at net.minecraft.server.v1_12_R1.SystemUtils.a(SourceFile:46)
09.11 18:43:02 [Server] WARN at java.util.concurrent.FutureTask.run(Unknown Source)
09.11 18:43:02 [Server] WARN at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
09.11 18:43:02 [Server] WARN at net.minecraft.server.v1_12_R1.PlayerConnectionUtils$1.run(SourceFile:13)
09.11 18:43:02 [Server] WARN at net.minecraft.server.v1_12_R1.PacketPlayInUseEntity.a(SourceFile:13)
09.11 18:43:02 [Server] WARN at net.minecraft.server.v1_12_R1.PacketPlayInUseEntity.a(SourceFile:69)
09.11 18:43:02 [Server] WARN at net.minecraft.server.v1_12_R1.PlayerConnection.a(PlayerConnection.java:1610)
09.11 18:43:02 [Server] WARN at net.minecraft.server.v1_12_R1.EntityPlayer.attack(EntityPlayer.java:1302)
09.11 18:43:02 [Server] WARN at net.minecraft.server.v1_12_R1.EntityHuman.attack(EntityHuman.java:1005)
09.11 18:43:02 [Server] WARN at net.minecraft.server.v1_12_R1.EntityPlayer.damageEntity(EntityPlayer.java:577)
09.11 18:43:02 [Server] WARN at net.minecraft.server.v1_12_R1.EntityHuman.damageEntity(EntityHuman.java:759)
09.11 18:43:02 [Server] WARN at net.minecraft.server.v1_12_R1.EntityLiving.damageEntity(EntityLiving.java:951)
09.11 18:43:02 [Server] WARN at net.minecraft.server.v1_12_R1.EntityPlayer.die(EntityPlayer.java:423)
09.11 18:43:02 [Server] WARN at org.bukkit.craftbukkit.v1_12_R1.event.CraftEventFactory.callPlayerDeathEvent(CraftEventFactory.java:412)
09.11 18:43:02 [Server] WARN at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:484)
09.11 18:43:02 [Server] WARN at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:499)
09.11 18:43:02 [Server] WARN at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.bukkit.manager.trigger.CustomTriggerManager$4.execute(CustomTriggerManager.java:187)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.bukkit.manager.trigger.CustomTriggerManager.handleEvent(CustomTriggerManager.java:260)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager$Trigger.activate(AbstractTriggerManager.java:172)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager$Trigger.startInterpretation(AbstractTriggerManager.java:237)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager$Trigger$1.call(AbstractTriggerManager.java:227)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager$Trigger$1.call(AbstractTriggerManager.java:230)
09.11 18:43:02 [Server] WARN at io.github.wysohn.triggerreactor.core.manager.trigger.AbstractTriggerManager$Trigger.start(AbstractTriggerManager.java:277)
09.11 18:43:02 [Server] WARN java.lang.Exception: Error occurred while processing Trigger [playerRespawn]!
check out #40
Ok so im gonna leave this closed because this is totally unrelated but i dont want to make a new thread to ask lol. So anyway im trying to skip the respawn screen on a playerdeathevent. I switched the trigger to sync mode and now im trying to send a respawn packet with protocollib. ill type out what i have so far.
player = event.getEntity()
world = player.getLocation().getWorld().getName().toString()
IF world.contains("world")
killer = player.getKiller()
IF killer
IF killer.getType().name() == "PLAYER"
IF protocollib
respawn = protocollib.createPacket("RESPAWN")
protocollib.sendPacket(player,respawn)
ENDIF
ENDIF
ENDIF
ENDIF
I get an error on this that looks like this when i die.
https://imgur.com/a/MLq7F
Ok adding on to this i see part of the problem. I have to specify the respawn packet is client side so i tried using "PacketType.Play.Client.RESPAWN" instead of respawn.
The packet your are modifying: PacketPlayInClientCommand, Client Status
Enum: EnumClientCommand
Method to use: getClientCommands()
So there are some (quite a lot) information you have to consider when you are modifying the packet.
First, you have to identify which packet you are sending. In your case, probably the ClientStatus packet is what you are looking for.
And then, you have to find the NMS class that is responsible for the packet. That is PacketPlayInClientCommand.
Inside the PacketPlayInClientCommand, you will see a enum field named 'a' which has type of EnumClientCommand.
However, because we are using ProtocolLib instead of directly dealing with the NMS, you have pre-defined wrapper classes to use.
You see Here, you can find PacketType.Play.Client.CLIENT_COMMAND which is exactly what you are looking for
respawn = protocollib.createPacket("CLIENT_COMMAND")
Then, now you have created your packet, you have to put the value you want. As you already saw in the NMS packet class, you have a field 'a' with enum type EnumClientCommand; similarly, ProtocolLib has a ClientCommand enum in its wrapper: https://github.com/aadnk/ProtocolLib/blob/master/modules/API/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java
So,
respawn = protocollib.createPacket("CLIENT_COMMAND")
respawn.getClientCommands().write(0, "PERFORM_RESPAWN")
protocollib.sendPacket(player, respawn)
This should work fine.
Hopefully, TriggerReactor can translate String into Enum automatically even the write() method is Generic type.
Hi so i see your enhancement and again this might have to do with my inexperience but, tried your new parse enum commonfunction and the class that ive been using to try to parse the enum is not recognized as an enum class. Is this perhaps because of it being an abstract class? I will link you where i was getting the class from and how i typed it.
https://github.com/aadnk/ProtocolLib/blob/master/modules/API/src/main/java/com/comphenix/protocol/wrappers/EnumWrappers.java
i was typing:
respawn = protocollib.createPacket("CLIENT_COMMAND")
respawn.getClientCommands().write(0,parseEnum("com.comphenix.protocol.wrappers.EnumWrappers","PERFORM_RESPAWN"))
protocollib.sendPacket(player,respawn)
I also updated to your latest version through jenkins.
Hey again so thank you so much yes that got rid of the class error. With that said triggerreactor is now erroring saying that im trying to send a client packet to a client.
WARN Caused by: java.lang.IllegalArgumentException: Packet of sender CLIENT cannot be sent to a client.
I was wondering even though you have support methods established for these plugins would i be able to access some methods of their own through 3rd party access? I saw this post in the bukkit threads that might help.
They put this(this is a direct paste from the forums):
PacketContainer packet = new PacketContainer(Packets.Client.CLIENT_COMMAND);
packet.getIntegers().write(0, 1);
ProtocolLibrary.getProtocolManager().recieveClientPacket(player, packet);
I understand their code is more in the form of traditional Java Rather than scripting but their solution closed the thread.
The link to the thread(the solution was the last reply): https://bukkit.org/threads/force-respawn-a-player-with-protocollib.162346/
I was also thinking of writing an executor of this if i cant get it to work in the scripts and just have the executor run in the sync script.
PS i really appreciate your patience to work with me and figure this out. I can only imagine the amount of long sighs you must be giving over this thread XD. Your awesome don't let anyone else tell you otherwise.
public void sendPacket(Player p, PacketContainer container) throws InvocationTargetException{
ValidationUtil.notNull(p);
ValidationUtil.notNull(container);
ProtocolLibrary.getProtocolManager().sendServerPacket(p, container);
}
This is the code in the protocollib support
This uses sendServerPacket() not recieveClientPacket
In that case, use the protocollib directly
IMPORT com.comphenix.protocol.wrappers.EnumWrappers
respawn = protocollib.createPacket("CLIENT_COMMAND")
respawn.getClientCommands().write(0,EnumWrappers.PERFORM_RESPAWN))
protocollib.protocolManager.recieveClientPacket(player, respawn)
Wysohn i would like to say we did it but this was like 90 percent you! Thank you so much this thread can finally go to sleep it works beautifully thank you thank you thank you!
No worries; it was pretty advanced stuff, and you managed to follow through all the obstacles.
Be proud of yourself!