Add the sender to NetworkEvent.Context for server-side event handlers (#5295)

This commit is contained in:
mezz 2018-12-22 23:24:11 -08:00 committed by GitHub
parent 8a11e3bac4
commit f2f04407a4
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -19,9 +19,15 @@
package net.minecraftforge.fml.network;
import javax.annotation.Nullable;
import com.google.common.util.concurrent.ListenableFuture;
import io.netty.util.Attribute;
import io.netty.util.AttributeKey;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.INetHandler;
import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.network.NetworkManager;
import net.minecraft.network.PacketBuffer;
import net.minecraft.util.IThreadListener;
@ -170,6 +176,21 @@ public class NetworkEvent extends Event
return (ListenableFuture<V>)LogicalSidedProvider.WORKQUEUE.<IThreadListener>get(getDirection().getLogicalSide()).addScheduledTask(runnable);
}
/**
* When available, gets the sender for packets that are sent from a client to the server.
*/
@Nullable
public EntityPlayerMP getSender()
{
INetHandler netHandler = networkManager.getNetHandler();
if (netHandler instanceof NetHandlerPlayServer)
{
NetHandlerPlayServer netHandlerPlayServer = (NetHandlerPlayServer) netHandler;
return netHandlerPlayServer.player;
}
return null;
}
NetworkManager getNetworkManager() {
return networkManager;
}