Java 类net.minecraft.network.NetHandlerPlayServer 实例源码

项目:Factorization    文件:FlatNet.java   
@SubscribeEvent
public void packetToServer(FMLNetworkEvent.ServerCustomPacketEvent event) {
    ByteBuf buf = event.packet.payload();
    byte kind = buf.readByte();
    NetHandlerPlayServer handler = (NetHandlerPlayServer) event.handler;
    EntityPlayerMP player = handler.playerEntity;
    if (kind == INTERACT_HIT || kind == INTERACT_USE) {
        Coord at = readCoord(buf, player);
        EnumFacing side = readSide(buf);
        if (!at.blockExists()) return;
        double reachSq = 6 * 6; // FIXME: There's no way to get this properly on the server?
        if (at.distanceSq(player) > reachSq) {
            log("Ignoring distant interaction packet for " + at + " from " + player);
            return;
        }
        FlatFace face = Flat.get(at, side);
        if (kind == INTERACT_HIT) {
            face.onHit(at, side, player);
        } else {
            face.onActivate(at, side, player);
        }
    } else {
        log("Invalid packet ID " + kind + " from " + player);
    }
}
项目:CreeperHostGui    文件:CreeperHostServer.java   
@SubscribeEvent
public void clientConnectedtoServer(FMLNetworkEvent.ServerConnectionFromClientEvent event)
{
    if (!CreeperHost.instance.active)
        return;
    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
    if (server == null || server.isSinglePlayer() || discoverMode != Discoverability.PUBLIC)
        return;

    INetHandlerPlayServer handler = event.handler;
    if (handler instanceof NetHandlerPlayServer)
    {
        EntityPlayerMP entity = ((NetHandlerPlayServer) handler).playerEntity;
        playersJoined.add(entity.getUniqueID());
    }
}
项目:CreeperHostGui    文件:CreeperHostServer.java   
@SubscribeEvent
public void clientConnectedtoServer(FMLNetworkEvent.ServerConnectionFromClientEvent event)
{
    if (!CreeperHost.instance.active)
        return;
    MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
    if (server == null || server.isSinglePlayer() || discoverMode != Discoverability.PUBLIC)
        return;

    INetHandlerPlayServer handler = event.getHandler();
    if (handler instanceof NetHandlerPlayServer)
    {
        EntityPlayerMP entity = ((NetHandlerPlayServer)handler).playerEntity;
        playersJoined.add(entity.getUniqueID());
    }
}
项目:CustomWorldGen    文件:FMLEventChannel.java   
@Override
FMLNetworkEvent.CustomPacketEvent<?> make(FMLProxyPacket msg)
{
    FMLNetworkEvent.CustomPacketEvent<?> event = null;
    if (msg.handler() instanceof NetHandlerPlayClient)
    {
        NetHandlerPlayClient client = (NetHandlerPlayClient) msg.handler();
        event = new FMLNetworkEvent.ClientCustomPacketEvent(client.getNetworkManager(), msg);
    }
    else if (msg.handler() instanceof NetHandlerPlayServer)
    {
        NetHandlerPlayServer server = (NetHandlerPlayServer) msg.handler();
        event = new FMLNetworkEvent.ServerCustomPacketEvent(server.getNetworkManager(), msg);
    }
    return event;
}
项目:Simple-Dimensions    文件:HandlerCreateDimension.java   
@Override
public IMessage onMessage(final MessageCreateDimension message, final MessageContext ctx)
{
    FMLCommonHandler.instance().getMinecraftServerInstance().addScheduledTask(new Runnable()
    {
        @Override
        public void run()
        {
            NetHandlerPlayServer netHandler = (NetHandlerPlayServer) ctx.netHandler;

            if (netHandler.player.canUseCommand(3, "simpledimensions"))
            {
                DimensionHandler.getInstance().createDimension(((NetHandlerPlayServer) ctx.netHandler).player, message.getWorldInfo());
            }
        }
    });

    return null;
}
项目:CrystalMod    文件:PacketEnhancementTable.java   
@Override
public void handleServerSafe(NetHandlerPlayServer netHandler) {
    EntityPlayer player = netHandler.playerEntity;
    World world = netHandler.playerEntity.getEntityWorld();
    if(world == null){
        return;
    }
    IEnhancement enhancement = EnhancementManager.getEnhancement(new ResourceLocation(id));

    TileEntity tile = world.getTileEntity(new BlockPos(x, y, z));
    if(tile !=null){
        if(tile instanceof TileEnhancementTable){
            TileEnhancementTable table = (TileEnhancementTable)tile;
            if(type == 0){
                table.applyEnhancement(player, enhancement);
            } else if(type == 1){
                table.removeEnhancement(player, enhancement);
            }
        }
    }
}
项目:TRHS_Club_Mod_2016    文件:FMLEventChannel.java   
@Override
FMLNetworkEvent.CustomPacketEvent<?> make(FMLProxyPacket msg)
{
    FMLNetworkEvent.CustomPacketEvent<?> event = null;
    if (msg.handler() instanceof NetHandlerPlayClient)
    {
        NetHandlerPlayClient client = (NetHandlerPlayClient) msg.handler();
        event = new FMLNetworkEvent.ClientCustomPacketEvent(client.func_147298_b(), msg);
    }
    else if (msg.handler() instanceof NetHandlerPlayServer)
    {
        NetHandlerPlayServer server = (NetHandlerPlayServer) msg.handler();
        event = new FMLNetworkEvent.ServerCustomPacketEvent(server.func_147362_b(), msg);
    }
    return event;
}
项目:TRHS_Club_Mod_2016    文件:NetworkDispatcher.java   
int serverInitiateHandshake()
{
    // Send mod salutation to the client
    // This will be ignored by vanilla clients
    this.state = ConnectionState.AWAITING_HANDSHAKE;
    this.manager.channel().pipeline().addFirst("fml:vanilla_detector", new VanillaTimeoutWaiter());
    // Need to start the handler here, so we can send custompayload packets
    serverHandler = new NetHandlerPlayServer(scm.func_72365_p(), manager, player);
    this.netHandler = serverHandler;
    // NULL the play server here - we restore it further on. If not, there are packets sent before the login
    player.field_71135_a = null;
    // manually for the manager into the PLAY state, so we can send packets later
    this.manager.func_150723_a(EnumConnectionState.PLAY);

    // Return the dimension the player is in, so it can be pre-sent to the client in the ServerHello v2 packet
    // Requires some hackery to the serverconfigmanager and stuff for this to work
    NBTTagCompound playerNBT = scm.getPlayerNBT(player);
    if (playerNBT!=null)
    {
        return playerNBT.func_74762_e("Dimension");
    }
    else
    {
        return 0;
    }
}
项目:Alchemy    文件:ExItemElytra.java   
@Hook("net.minecraft.network.NetHandlerPlayServer#func_147357_a")
public static Hook.Result processEntityAction(NetHandlerPlayServer handler, CPacketEntityAction action) {
    if (action.getAction() == Action.START_FALL_FLYING) {
        PacketThreadUtil.checkThreadAndEnqueue(action, handler, handler.player.getServerWorld());
        handler.player.markPlayerActive();
        if (!handler.player.onGround && handler.player.motionY < 0.0D &&
                !handler.player.isElytraFlying() && !handler.player.isInWater()) {
            ItemStack item = getFormLiving0(handler.player);
            if (item.getItem() == Items.ELYTRA && ItemElytra.isUsable(item))
                handler.player.setElytraFlying();
        } else
            handler.player.clearElytraFlying();
        return Hook.Result.NULL;
    }
    return Hook.Result.VOID;
}
项目:FairyFactions    文件:PacketSetFairyName.java   
@Override
public void handle(NetworkManager origin) {
    FairyFactions.LOGGER.info("PacketSetFairyName.handle");

    final EntityPlayerMP player = ((NetHandlerPlayServer)origin.getNetHandler()).playerEntity;
    if( player != null ) {
        final EntityFairy fairy = FairyFactions.getFairy(this.fairyID);
        if( fairy == null ) {
            FairyFactions.LOGGER.warn("Unable to find fairy "+this.fairyID+" to rename.");
            return;
        }

        final String username = player.getGameProfile().getName();
        final String rulername = fairy.rulerName();
        if( fairy.nameEnabled() && rulername.equals(username) ) {
            fairy.setCustomName(this.name);
        } else {
            FairyFactions.LOGGER.warn("Attempt by '"+username+"' to rename fairy owned by '"+rulername+"'");
        }
        fairy.setNameEnabled(false);
    }
}
项目:Ambidextrous    文件:NetworkRouter.java   
@SubscribeEvent
public void serverPacket(
        final ServerCustomPacketEvent ev )
{
    // find player
    final NetHandlerPlayServer srv = (NetHandlerPlayServer) ev.getPacket().handler();

    try
    {
        if ( serverPacketHandler != null )
        {
            serverPacketHandler.onPacketData( ev.getPacket(), ev.getHandler(), srv.playerEntity );
        }
    }
    catch ( final ThreadQuickExitException ext )
    {
        ;
    }
}
项目:EnderBook    文件:PacketWarpButton.java   
@Override
public IMessage onMessage(PacketWarpButton message, MessageContext ctx)
{
    EntityPlayer player = ((NetHandlerPlayServer)ctx.netHandler).playerEntity;


    int cost = (int)ConfigSettings.expCostPerTeleport;


    if(cost != 0 && UtilExperience.getExpTotal(player) < cost )
    {
        player.addChatMessage(new TextComponentTranslation(I18n.translateToLocal("gui.chatexp")));
    }
    else
    { 
        ItemEnderBook.teleport(player, message.slot);
    }

    return null;
}
项目:EnderBook    文件:PacketNewButton.java   
@Override
public IMessage onMessage(PacketNewButton message, MessageContext ctx)
{
    //since we are on the server right now:
    EntityPlayer player = ((NetHandlerPlayServer)ctx.netHandler).playerEntity;
    //otherwise, on the client we would use  Minecraft.getMinecraft().thePlayer;
/*
    //this shouldnt happen anyway but just in case
    if(player.getHeldItem() == null || 
            !(player.getHeldItem().getItem() instanceof ItemEnderBook))
    {
        //then cancel
        return null;
    }
    */
    //it now passes the stack, in case the players hand becomes null/empty at some point during process


    ItemEnderBook.saveCurrentLocation(player,message.name);


    return null;
}
项目:CauldronGit    文件:FMLEventChannel.java   
@Override
FMLNetworkEvent.CustomPacketEvent<?> make(FMLProxyPacket msg)
{
    FMLNetworkEvent.CustomPacketEvent<?> event = null;
    if (msg.handler() instanceof NetHandlerPlayClient)
    {
        NetHandlerPlayClient client = (NetHandlerPlayClient) msg.handler();
        event = new FMLNetworkEvent.ClientCustomPacketEvent(client.getNetworkManager(), msg);
    }
    else if (msg.handler() instanceof NetHandlerPlayServer)
    {
        NetHandlerPlayServer server = (NetHandlerPlayServer) msg.handler();
        event = new FMLNetworkEvent.ServerCustomPacketEvent(server.func_147362_b(), msg);
    }
    return event;
}
项目:morecommands    文件:PacketDispatcher.java   
/**
 * Invoked when the server receives a packet from the client
 */
@SubscribeEvent
public void onClientPacket(final ServerCustomPacketEvent event) {
    if (!event.getPacket().channel().equals(Reference.CHANNEL)) return;

    ((NetHandlerPlayServer) event.getHandler()).player.getServerWorld().addScheduledTask(new Runnable() {
        @Override
        public void run() {
            try {handleClientPacket(event.getPacket(), ((NetHandlerPlayServer) event.getHandler()).player);}
            catch (Exception ex) {
                ex.printStackTrace(); 
                MoreCommands.INSTANCE.getLogger().warn("Error handling Packet");
            }
        }
    });
}
项目:morecommands    文件:CommonHandler.java   
/**
 * Invoked when a client connects to the server. Loads player settings
 * and sends a handshake to the client.
 */
@SubscribeEvent
public void clientConnect(ServerConnectionFromClientEvent event) {
    EntityPlayerMP player = ((NetHandlerPlayServer) event.getHandler()).player;
    ServerPlayerSettings settings = player.getCapability(PlayerSettings.SETTINGS_CAP_SERVER, null);

    if (settings != null)  //Should never be null
        settings.init(player, new ServerPlayerSettings(player));

    //Packets are not intended to be sent at this point but is required here
    //To prevent a NPE in OutboundTarget.selectNetworks(), we have to set the NetHandlerPlayServer
    player.connection = (NetHandlerPlayServer) event.getHandler();

    MoreCommands.INSTANCE.getLogger().info("Requesting Client Handshake for Player '" + player.getName() + "'");
    MoreCommands.INSTANCE.getPacketDispatcher().sendS00Handshake(player);
    MoreCommands.INSTANCE.getPacketDispatcher().sendS14RemoteWorld(player, player.world.getSaveHandler().getWorldDirectory().getName());

    //To prevent a NPE because Minecraft.thePlayer is not set at this point, reset connection to null
    player.connection = null;

    if (MoreCommandsConfig.retryHandshake)
        PacketHandlerServer.addPlayerToRetries(player);

}
项目:NOVA-Core    文件:MCPacketHandler.java   
@Override
protected void channelRead0(ChannelHandlerContext ctx, PacketAbstract packet) throws Exception {
    INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();

    switch (FMLCommonHandler.instance().getEffectiveSide()) {
        case CLIENT:
            FMLClientHandler.instance().getClient().addScheduledTask(() -> packet.handleClientSide(NovaMinecraft.proxy.getClientPlayer()));
            break;
        case SERVER:
            FMLCommonHandler.instance().getMinecraftServerInstance().addScheduledTask(() -> packet.handleServerSide(((NetHandlerPlayServer) netHandler).playerEntity));
            break;
        default:
            break;
    }

}
项目:NOVA-Core    文件:MCPacketHandler.java   
@Override
protected void channelRead0(ChannelHandlerContext ctx, PacketAbstract packet) throws Exception {
    INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();

    switch (FMLCommonHandler.instance().getEffectiveSide()) {
        case CLIENT:
            packet.handleClientSide(NovaMinecraft.proxy.getClientPlayer());
            break;
        case SERVER:
            packet.handleServerSide(((NetHandlerPlayServer) netHandler).playerEntity);
            break;
        default:
            break;
    }

}
项目:Cyclic    文件:UtilFakePlayer.java   
public static WeakReference<FakePlayer> initFakePlayer(WorldServer ws, UUID uname, String blockName) {
  GameProfile breakerProfile = new GameProfile(uname, Const.MODID + ".fake_player." + blockName);
  WeakReference<FakePlayer> fakePlayer;
  try {
    fakePlayer = new WeakReference<FakePlayer>(FakePlayerFactory.get(ws, breakerProfile));
  }
  catch (Exception e) {
    ModCyclic.logger.error("Exception thrown trying to create fake player : " + e.getMessage());
    fakePlayer = null;
  }
  if (fakePlayer == null || fakePlayer.get() == null) {
    fakePlayer = null;
    return null; // trying to get around https://github.com/PrinceOfAmber/Cyclic/issues/113
  }
  fakePlayer.get().onGround = true;
  fakePlayer.get().connection = new NetHandlerPlayServer(FMLCommonHandler.instance().getMinecraftServerInstance(), new NetworkManager(EnumPacketDirection.SERVERBOUND), fakePlayer.get()) {
    @SuppressWarnings("rawtypes")
    @Override
    public void sendPacket(Packet packetIn) {}
  };
  fakePlayer.get().setSilent(true);
  return fakePlayer;
}
项目:Cyclic    文件:PacketWarpButton.java   
@Override
public IMessage onMessage(PacketWarpButton message, MessageContext ctx) {
  EntityPlayer player = ((NetHandlerPlayServer) ctx.netHandler).player;
  int cost = (int) ItemEnderBook.getExpCostPerTeleport(player, ItemEnderBook.getPlayersBook(player), message.slot);
  if (player.isCreative()) {
    ItemEnderBook.teleport(player, message.slot);
  }
  else if (cost > 0 && UtilExperience.getExpTotal(player) < cost) {
    UtilChat.addChatMessage(player, "gui.chatexp");
  }
  else if (ItemEnderBook.teleport(player, message.slot)) {
    //if the teleport worked in non creative, drain it
    UtilExperience.drainExp(player, cost);
  }
  return null;
}
项目:KeyCraft    文件:RewriteNetwork.java   
/** ������������� */
@SubscribeEvent
public void onServerPacket(ServerCustomPacketEvent event) {
    EntityPlayerMP player = ((NetHandlerPlayServer)event.handler).playerEntity;

    ByteBufInputStream stream = new ByteBufInputStream(event.packet.payload());
    try {
        switch (stream.readInt()) {
        case LEARN_SKILL_CODE:
            RewriteHelper.learnSkill(player, stream.readInt());
            break;

        case USE_SKILL_CODE:
            RewriteHelper.useSkill(player);
            break;
        }

        stream.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:SasaLib    文件:PacketDispatcher.java   
@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception
{
    ByteBuf buf = msg.payload();
    int packetId = buf.readByte();
    Class pktCls = packets.get(packetId);
    SasaPacketBase pkt = (SasaPacketBase)pktCls.newInstance();
    pkt.fromByteBuf(ctx, buf);
    if(FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
    {
        pkt.receiveClient(getClientPlayer());
    }
    else if(FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
    {
        INetHandler localINetHandler = (INetHandler)ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
        EntityPlayer ep = ((NetHandlerPlayServer)localINetHandler).playerEntity;
        pkt.receiveServer(ep);
    }
}
项目:SpaceCore    文件:PacketProcesser.java   
@Override
public void channelRead( ChannelHandlerContext context, Object message )
{
    if ( !( message instanceof Packet ) ) return;
    Packet packet = ( Packet ) message;

    // Kinda from here: http://www.minecraftforge.net/wiki/Netty_Packet_Handling
    if ( FMLCommonHandler.instance().getEffectiveSide().equals( Side.SERVER ) )
    {
        INetHandler handler = context.channel().attr( NetworkRegistry.NET_HANDLER ).get();
        packet.processServer( ( ( NetHandlerPlayServer ) handler ).playerEntity );
    }
    else
    {
        packet.processClient( getClientPlayer() );
    }
}
项目:UsefulPets    文件:JumpPacketMonitor.java   
@Override
public void monitorIncoming( INetHandler net, net.minecraft.network.Packet packet )
{
    if ( !( net instanceof NetHandlerPlayServer ) || !( packet instanceof C0BPacketEntityAction ) )
    {
        return;
    }

    NetHandlerPlayServer server = ( NetHandlerPlayServer ) net;
    C0BPacketEntityAction action = ( C0BPacketEntityAction ) packet;

    if ( action.func_149513_d() != 6 || !( server.playerEntity.ridingEntity instanceof PetEntity ) )
    {
        return;
    }
    PetEntity pet = ( PetEntity ) server.playerEntity.ridingEntity;

    pet.setJumpingState( action.func_149512_e() );
}
项目:MiscUtils    文件:ChannelHandler.java   
@Override
protected void channelRead0(ChannelHandlerContext ctx, AbstractPacket msg) throws Exception
{
    Side side = ctx.channel().attr(NetworkRegistry.CHANNEL_SOURCE).get();
    EntityPlayer player = null;
    if(side.isServer())
    {
        INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
        player = ((NetHandlerPlayServer) netHandler).playerEntity;
    }
    else
    {
        player = this.getClientPlayer();
    }

    msg.onMessage(side, player);
}
项目:Cauldron    文件:FMLEventChannel.java   
@Override
FMLNetworkEvent.CustomPacketEvent<?> make(FMLProxyPacket msg)
{
    FMLNetworkEvent.CustomPacketEvent<?> event = null;
    if (msg.handler() instanceof NetHandlerPlayClient)
    {
        NetHandlerPlayClient client = (NetHandlerPlayClient) msg.handler();
        event = new FMLNetworkEvent.ClientCustomPacketEvent(client.getNetworkManager(), msg);
    }
    else if (msg.handler() instanceof NetHandlerPlayServer)
    {
        NetHandlerPlayServer server = (NetHandlerPlayServer) msg.handler();
        event = new FMLNetworkEvent.ServerCustomPacketEvent(server.func_147362_b(), msg);
    }
    return event;
}
项目:Cauldron    文件:FMLEventChannel.java   
@Override
FMLNetworkEvent.CustomPacketEvent<?> make(FMLProxyPacket msg)
{
    FMLNetworkEvent.CustomPacketEvent<?> event = null;
    if (msg.handler() instanceof NetHandlerPlayClient)
    {
        NetHandlerPlayClient client = (NetHandlerPlayClient) msg.handler();
        event = new FMLNetworkEvent.ClientCustomPacketEvent(client.getNetworkManager(), msg);
    }
    else if (msg.handler() instanceof NetHandlerPlayServer)
    {
        NetHandlerPlayServer server = (NetHandlerPlayServer) msg.handler();
        event = new FMLNetworkEvent.ServerCustomPacketEvent(server.func_147362_b(), msg);
    }
    return event;
}
项目:Cauldron    文件:FMLEventChannel.java   
@Override
FMLNetworkEvent.CustomPacketEvent<?> make(FMLProxyPacket msg)
{
    FMLNetworkEvent.CustomPacketEvent<?> event = null;
    if (msg.handler() instanceof NetHandlerPlayClient)
    {
        NetHandlerPlayClient client = (NetHandlerPlayClient) msg.handler();
        event = new FMLNetworkEvent.ClientCustomPacketEvent(client.getNetworkManager(), msg);
    }
    else if (msg.handler() instanceof NetHandlerPlayServer)
    {
        NetHandlerPlayServer server = (NetHandlerPlayServer) msg.handler();
        event = new FMLNetworkEvent.ServerCustomPacketEvent(server.func_147362_b(), msg);
    }
    return event;
}
项目:NBTEdit    文件:PacketPipeline.java   
@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception {
    ByteBuf payload = msg.payload();
    byte discriminator = payload.readByte();
    Class<? extends AbstractPacket> clazz = this.packets.get(discriminator);

    AbstractPacket pkt = clazz.newInstance();
    pkt.decodeInto(ctx, payload.slice());

    switch (FMLCommonHandler.instance().getEffectiveSide()) {
        case CLIENT:
            pkt.handleClientSide(this.getClientPlayer());
            break;
        case SERVER:
            INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
            pkt.handleServerSide(((NetHandlerPlayServer) netHandler).playerEntity);
            break;
        default:
            break;
    }

    out.add(pkt);
}
项目:EnderAmmunition    文件:EAChannelHandler.java   
@Override
public void decodeInto(ChannelHandlerContext ctx, ByteBuf source,
                       IPacket msg) {
    byte[] arr = new byte[source.readableBytes()];
    source.readBytes(arr);
    ByteArrayInputStream bais = new ByteArrayInputStream(arr);
    try {
        msg.read(new DataInputStream(bais));
    } catch (Throwable e) {
        e.printStackTrace();
        return;
    }
    if (!FMLCommonHandler.instance().getEffectiveSide().isClient()) {
        INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
        EntityPlayer player = ((NetHandlerPlayServer) netHandler).playerEntity;
        msg.execute(player);
    } else {
        msg.execute(getClientPlayer());
    }
}
项目:carpentersblocks    文件:PacketHandler.java   
@SubscribeEvent
public void onServerPacket(ServerCustomPacketEvent event) throws IOException
{
    ByteBufInputStream bbis = new ByteBufInputStream(event.packet.payload());
    EntityPlayer entityPlayer = ((NetHandlerPlayServer) event.handler).playerEntity;
    int packetId = bbis.readInt();
    if (packetId < packetCarrier.size()) {
        try {
            ICarpentersPacket packetClass = (ICarpentersPacket) packetCarrier.get(packetId).newInstance();
            packetClass.processData(entityPlayer, bbis);
        } catch (Exception e) {
            e.printStackTrace();
        }
    } else {
        ModLogger.log(Level.WARN, "Encountered out of range packet Id: " + packetId);
    }
    bbis.close();
}
项目:Pay2Spawn    文件:ConnectionHandler.java   
@SubscribeEvent
public void connectionReceived(FMLNetworkEvent.ServerConnectionFromClientEvent event)
{
    if (!event.isLocal && Pay2Spawn.getConfig().forceP2S)
    {
        final String username = ((NetHandlerPlayServer) event.handler).playerEntity.getCommandSenderName();
        new Timer().schedule(new TimerTask()
        {
            @Override
            public void run()
            {
                if (!StatusMessage.doesPlayerHaveValidConfig(username)) MinecraftServer.getServer().getConfigurationManager().getPlayerForUsername(username).playerNetServerHandler.kickPlayerFromServer("Pay2Spawn is required on this server.\nIt needs to be configured properly.");
            }
        }, 5 * 1000);
    }
}
项目:McMod-CubicVillager    文件:SyncSlotHandler.java   
@Override
public IMessage onMessage(SyncSlotMessage message, MessageContext ctx)
{
    if(message.guiId == 1)
    {
        // ContainerMerchantEditorを開いているはず
        NetHandlerPlayServer handler = ctx.getServerHandler();
        EntityPlayerMP player = handler.player;
        if(player.openContainer instanceof ContainerMerchantEditor)
        {
            // GUIがContainerMerchantEditor
            ContainerMerchantEditor container = (ContainerMerchantEditor)player.openContainer;
            if(container.getCurrentTradeIndex() != message.index)
            {
                container.loadTradeAt(message.index);
            }
        }
    }
    return null;
}
项目:Combustible-Lemon-Launcher    文件:CLLPacketHandler.java   
@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception {
    ByteBuf packetPayload = msg.payload();
    byte indexOfClass = packetPayload.readByte();
    ByteBufInputStream bbis = new ByteBufInputStream(packetPayload.slice());
    Class<? extends CLLPacket> packetClass = registeredPackets.get(indexOfClass);
    if(packetClass != null){
        CLLPacket packetCLL = packetClass.newInstance();
        packetCLL.readDataFrom(bbis);
        switch(FMLCommonHandler.instance().getEffectiveSide()){
        case CLIENT:
            handleClient(packetCLL);
            break;
        case SERVER:
            packetCLL.handleServerSide(((NetHandlerPlayServer)ctx.channel().attr(NetworkRegistry.NET_HANDLER).get()).player);
            break;          
        }
        bbis.close();
        out.add(packetCLL);
    }
}
项目:MinecraftScripting    文件:PacketPipeline.java   
@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception {
    ScriptPacket pkt = ScriptPacket.readPacket(ctx, msg.payload());

    switch (FMLCommonHandler.instance().getEffectiveSide()) {
        case CLIENT:
            ScriptingMod.proxy.getClientHandler().handlePacket(pkt, getClientPlayer());
            break;
        case SERVER:
            INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
            ScriptingMod.proxy.getServerHandler().handlePacket(pkt, ((NetHandlerPlayServer) netHandler).playerEntity);
            break;
        default:
            break;
    }

    out.add(pkt);
}
项目:PaintingSelectionGui    文件:PacketPipeline.java   
@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws IllegalArgumentException, IllegalAccessException, InstantiationException {
    ByteBuf payload = msg.payload();
    byte discriminator = payload.readByte();
    Class<? extends IPacket> clazz = packets.get(discriminator);
    if (clazz == null)
        throw new IllegalArgumentException("No packet registered for discriminator: " + discriminator);

    IPacket pkt = clazz.newInstance();
    pkt.decodeInto(ctx, payload.slice());

    switch (FMLCommonHandler.instance().getEffectiveSide()) {
        case CLIENT:
            pkt.handleClientSide(PaintingSelectionMod.proxy.getClientPlayer());
            break;
        case SERVER:
            INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
            pkt.handleServerSide(((NetHandlerPlayServer) netHandler).playerEntity);
            break;
        default:
            break;
    }

    out.add(pkt);
}
项目:MobSpawnControls2    文件:PacketPipeline.java   
@Override
protected void decode(ChannelHandlerContext ctx, FMLProxyPacket msg, List<Object> out) throws Exception {
    MSCPacket pkt = MSCPacket.readPacket(ctx, msg.payload());

    switch (FMLCommonHandler.instance().getEffectiveSide()) {
        case CLIENT:
            MobSpawnControls.proxy.getClientHandler().handlePacket(pkt, getClientPlayer());
            break;
        case SERVER:
            INetHandler netHandler = ctx.channel().attr(NetworkRegistry.NET_HANDLER).get();
            MobSpawnControls.proxy.getServerHandler().handlePacket(pkt, ((NetHandlerPlayServer) netHandler).playerEntity);
            break;
        default:
            break;
    }

    out.add(pkt);
}
项目:pnc-repressurized    文件:EntityDrone.java   
private void initializeFakePlayer() {
    fakePlayer = new DroneFakePlayer(
            (WorldServer) world,
            new GameProfile(UUID.fromString(getOwnerUUID()), playerName),
            this);
    fakePlayer.connection = new NetHandlerPlayServer(FMLCommonHandler.instance().getMinecraftServerInstance(), new NetworkManager(EnumPacketDirection.SERVERBOUND), fakePlayer);
    fakePlayer.inventory = new InventoryFakePlayer(fakePlayer);
}
项目:pnc-repressurized    文件:TileEntityProgrammableController.java   
private void initializeFakePlayer() {
    String playerName = "Drone";
    fakePlayer = new DroneFakePlayer((WorldServer) getWorld(), new GameProfile(null, playerName), this);
    fakePlayer.connection = new NetHandlerPlayServer(FMLCommonHandler.instance().getMinecraftServerInstance(), new NetworkManager(EnumPacketDirection.SERVERBOUND), fakePlayer);
    fakePlayer.inventory = new InventoryPlayer(fakePlayer) {
        private ItemStack oldStack;

        @Override
        public int getSizeInventory() {
            return getDroneSlots();
        }

        @Override
        public void setInventorySlotContents(int slot, ItemStack stack) {
            super.setInventorySlotContents(slot, stack);
            if (slot == 0) {
                for (EntityEquipmentSlot ee : EntityEquipmentSlot.values()) {
                    if (!oldStack.isEmpty()) {
                        getFakePlayer().getAttributeMap().removeAttributeModifiers(oldStack.getAttributeModifiers(ee));
                    }
                    if (!stack.isEmpty()) {
                        getFakePlayer().getAttributeMap().applyAttributeModifiers(stack.getAttributeModifiers(ee));
                    }
                }
                oldStack = stack;
            }
        }
    };
}
项目:PacketControl    文件:PacketControlService.java   
@Override
public void sendPacket(Packet packet, PlayerConnection connection) {
    if(connection instanceof NetworkManager) {
        ((NetworkManager)connection).sendPacket((net.minecraft.network.Packet)packet);
    } else if(connection instanceof NetHandlerPlayServer) {
        ((NetHandlerPlayServer)connection).sendPacket((net.minecraft.network.Packet)packet);
    } else {
        sendPacket(packet, connection.getPlayer());
    }
}