Add the sender to NetworkEvent.Context for server-side event handlers (#5295)
This commit is contained in:
parent
8a11e3bac4
commit
f2f04407a4
1 changed files with 21 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue