Closed Elikill58 closed 1 month ago
Show us your code, and are you up to date?
I was using the latest version, 2.4.0.
The code IS explained in the post. I'm using packet send évent on velocity
I asked you if you are up to date, not if you were up to date. Also, no, your code and usage of the library is not explained at all. You could have missed a crucial step during initialization, thus, I asked for the code...
The latest version is 2.5.0 now.
In the main class:
@Subscribe(order = PostOrder.LATE)
public void onProxyInitialize(ProxyInitializeEvent event) {
PacketEvents.setAPI(VelocityPacketEventsBuilder.build(getServer(), getContainer(), getLogger(), dataDirectory));
PacketEvents.getAPI().load();
PacketEvents.getAPI().getEventManager().registerListener(new MyListener());
}
My listener:
public class MyListener extends PacketListenerAbstract {
@Override
public void onPacketSend(PacketSendEvent e) {
PacketTypeCommon packetType = e.getPacketType();
if (packetType.equals(Server.SPAWN_ENTITY)) {
MyPlugin.getInstance().getLogger().info("Player: " + e.getPlayer());
}
}
}
I always get log: Player: null
.
Also, as there is event.getServerVersion()
, that could be logic if there is event.getServerInfo()
or event.getServerName()
, mostly on proxy side.
Are you on 2.5.0?
Yes, I updated few days ago
You need to call init() after registering your listener. Load does not suffice.
Ok, now the issue is fixed.
It's sad we need so many things to enable the API, why they are not auto-init?
Also, as the original issue is fixed, you will not add server informations to the event?
Because you chose to shade the plugin. If you depend on the plugin externally, you don't need to do any of this initialization.
Is your feature request related to a problem? Please describe. On the
PacketSendEvent
, theevent.getPlayer()
variable can be null (on velocity, for me, it's always null). So, I can't get the server concerned by the packet.Describe the solution you'd like On the
PacketSendEvent
, add a variable for the server that can be:Bukkit.getServer()
Or maybe a custom object that summarize important things (server key, server name, amount of players and others). I just want to identify which server is it.