Package com.comphenix.protocol.events

Examples of com.comphenix.protocol.events.PacketContainer


    // Hide all enchantments
    protocolManager.addPacketListener(new PacketAdapter(plugin, ConnectionSide.SERVER_SIDE, 0x67, 0x68, 0x3E) {
      @Override
      public void onPacketSending(PacketEvent event) {
        PacketContainer packet = event.getPacket();
       
        try {
          // Item packets
          switch (event.getPacketID()) {
          case 0x67: // Set slot
            removeEnchantments(packet.getItemModifier().read(0));
            break;
           
          case 0x68: // Set Window Items
            ItemStack[] elements = packet.getItemArrayModifier().read(0);
 
            for (int i = 0; i < elements.length; i++) {
              if (elements[i] != null) {
                removeEnchantments(elements[i]);
              }
View Full Code Here


    if (sender instanceof Player) {
   
      Player player = (Player) sender;
     
      if (label.equalsIgnoreCase("explosion")) {
        PacketContainer fakeExplosion = protocolManager.createPacket(0x3C);
       
        // Set the coordinates
        try {
          fakeExplosion.getSpecificModifier(double.class).
              write(0, player.getLocation().getX()).
              write(1, player.getLocation().getY()).
              write(2, player.getLocation().getZ());
          fakeExplosion.getSpecificModifier(float.class).
            write(0, 3.0F);
         
          protocolManager.sendServerPacket(player, fakeExplosion);
         
        } catch (Exception e) {
View Full Code Here

        distSq = dist * dist;
    }

    @Override
    public void onPacketSending(final PacketEvent event) {
        final PacketContainer packetContainer = event.getPacket();

        // Compare sound effect name.
        if (!contains(packetContainer.getStrings().read(0))) {
            return;
        }

        final Player player = event.getPlayer();
        final Location loc = player.getLocation(); // TODO: Use getLocation(useLoc) [synced if async].

        // Compare distance of player to the weather location.
        final StructureModifier<Integer> ints = packetContainer.getIntegers();
        if (TrigUtil.distanceSquared(ints.read(0) / 8, ints.read(2) / 8, loc.getX(), loc.getZ()) > distSq) {
            // TODO: Get from a NetConfig (optimized).
            if (ConfigManager.getConfigFile(player.getWorld().getName()).getBoolean(ConfPaths.NET_SOUNDDISTANCE_ACTIVE)) {
                event.setCancelled(true);
            }
View Full Code Here

  /**
   * Retrieve the parent update attributes packet.
   * @return The parent packet.
   */
  public PacketContainer getParentPacket() {
    return new PacketContainer(
      PacketType.Play.Server.UPDATE_ATTRIBUTES,
      modifier.withType(MinecraftReflection.getPacketClass()).read(0)
    );
  }
View Full Code Here

      try {
        byte[] buffer = bufferStream != null ? bufferStream.toByteArray() : null;
       
        // Let the people know
        PacketType type = PacketType.findLegacy(packetID, Sender.CLIENT);
        PacketContainer container = new PacketContainer(type, thisObj);
        PacketEvent event = packetInjector.packetRecieved(container, input, buffer);
       
        // Handle override
        if (event != null) {
          Object result = event.getPacket().getHandle();
View Full Code Here

      if (id != null && hasListener(id)) {
        NetworkMarker marker = queuedMarkers.remove(packet);
       
        // A packet has been sent guys!
        PacketType type = PacketType.findLegacy(id, Sender.SERVER);
        PacketContainer container = new PacketContainer(type, packet);
        PacketEvent event = PacketEvent.fromServer(invoker, container, marker, currentPlayer);
        invoker.invokePacketSending(event);
       
        // Cancelling is pretty simple. Just ignore the packet.
        if (event.isCancelled())
View Full Code Here

  public PacketContainer createPacket(int id, boolean forceDefaults) {
    if (delegate != null) {
      return delegate.createPacket(id);
    } else {
      // Fallback implementation
      PacketContainer packet = new PacketContainer(id);
     
      // Use any default values if possible
      if (forceDefaults) {
        try {
          packet.getModifier().writeDefaults();
        } catch (FieldAccessException e) {
          throw new RuntimeException("Security exception.", e);
        }
      }
      return packet;
View Full Code Here

      Object javaProxy = enhancer.create(
        new Class<?>[] { ByteBuf.class },
        new Object[]   { UnpooledByteBufAllocator.DEFAULT.buffer() }
      );
     
      Object lookPacket = new PacketContainer(PacketType.Play.Client.BLOCK_PLACE).getHandle();
      List<Method> candidates = FuzzyReflection.fromClass(MinecraftReflection.getPacketClass()).
        getMethodListByParameters(Void.TYPE, new Class<?>[] { MinecraftReflection.getPacketDataSerializerClass() });
     
      // Look through all the methods
      for (Method method : candidates) {
View Full Code Here

          values[i] = paramUnwrapper[i].unwrapItem(values[i]);
        }
      }
     
      Object nmsPacket = constructorMethod.newInstance(values);
      return new PacketContainer(type, nmsPacket);
     
    } catch (IllegalArgumentException e) {
      throw e;
    } catch (InstantiationException e) {
      throw new FieldAccessException("Cannot construct an abstract packet.", e);
View Full Code Here

        return packet;
      }
     
      Player sender = getInjector(networkManager, connection).getUpdatedPlayer();
      PacketType type = PacketType.findLegacy(id, Sender.CLIENT);
      PacketContainer container = new PacketContainer(type, packet);
      PacketEvent event = packetReceived(container, sender, readBufferedPackets.get(packet));
     
      if (!event.isCancelled())
        return event.getPacket().getHandle();
      else
View Full Code Here

TOP

Related Classes of com.comphenix.protocol.events.PacketContainer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.