Tabnine Logo
PacketWrapper.send
Code IndexAdd Tabnine to your IDE (free)

How to use
send
method
in
us.myles.ViaVersion.api.PacketWrapper

Best Java code snippets using us.myles.ViaVersion.api.PacketWrapper.send (Showing top 20 results out of 315)

origin: MylesIsCool/ViaVersion

/**
 * Send this packet to the associated user.
 * Be careful not to send packets twice.
 * (Sends it after current)
 *
 * @param packetProtocol      - The protocol version of the packet.
 * @param skipCurrentPipeline - Skip the current pipeline
 * @throws Exception if it fails to write
 */
public void send(Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline) throws Exception {
  send(packetProtocol, skipCurrentPipeline, false);
}
origin: MylesIsCool/ViaVersion

/**
 * Send this packet to the associated user.
 * Be careful not to send packets twice.
 * (Sends it after current)
 *
 * @param packetProtocol - The protocol version of the packet.
 * @throws Exception if it fails to write
 */
public void send(Class<? extends Protocol> packetProtocol) throws Exception {
  send(packetProtocol, true);
}
origin: Gerrygames/ViaRewind

  public static boolean sendPacket(PacketWrapper packet, Class<? extends Protocol> packetProtocol, boolean skipCurrentPipeline, boolean currentThread) {
    try {
      packet.send(packetProtocol, skipCurrentPipeline, currentThread);
      return true;
    } catch (CancelException ignored) {
      ;
    } catch (Exception ex) {
      ex.printStackTrace();
    }
    return false;
  }
}
origin: Gerrygames/ViaRewind

  public void sendMetadataBuffer(int entityId) {
    if (!this.metadataBuffer.containsKey(entityId)) return;
    if (entityReplacements.containsKey(entityId)) {
      entityReplacements.get(entityId).updateMetadata(this.metadataBuffer.remove(entityId));
    } else {
      PacketWrapper wrapper = new PacketWrapper(0x1C, null, this.getUser());
      wrapper.write(Type.VAR_INT, entityId);
      wrapper.write(Types1_8.METADATA_LIST, this.metadataBuffer.get(entityId));
      MetadataRewriter.transform(this.getClientEntityTypes().get(entityId), this.metadataBuffer.get(entityId));
      if (!this.metadataBuffer.get(entityId).isEmpty()) {
        try {
          wrapper.send(Protocol1_8TO1_9.class);
        } catch (Exception ex) {
          ex.printStackTrace();
        }
      }

      this.metadataBuffer.remove(entityId);
    }
  }
}
origin: MylesIsCool/ViaVersion

private void sendPacket(UUID uuid, PacketWrapper wrapper) {
  if (!Via.getAPI().isPorted(uuid) || !(Via.getAPI().getPlayerVersion(uuid) >= ProtocolVersion.v1_9.getId())) {
    players.remove(uuid);
    return;
  }
  try {
    wrapper.send(Protocol1_9TO1_8.class);
  } catch (Exception e) {
    e.printStackTrace();
  }
}
origin: MylesIsCool/ViaVersion

private void sendBlockChange(UserConnection user, Position position, int blockId) throws Exception {
  PacketWrapper wrapper = new PacketWrapper(0x0B, null, user);
  wrapper.write(Type.POSITION, position);
  wrapper.write(Type.VAR_INT, blockId);
  wrapper.send(Protocol1_13To1_12_2.class, true, true);
}
origin: MylesIsCool/ViaVersion

public void sendMetadataBuffer(int entityID) {
  List<Metadata> metadataList = metadataBuffer.get(entityID);
  if (metadataList != null) {
    PacketWrapper wrapper = new PacketWrapper(0x39, null, getUser());
    wrapper.write(Type.VAR_INT, entityID);
    wrapper.write(Types1_9.METADATA_LIST, metadataList);
    MetadataRewriter.transform(getClientEntityTypes().get(entityID), metadataList);
    handleMetadata(entityID, metadataList);
    if (metadataList.size() > 0) {
      try {
        wrapper.send(Protocol1_9TO1_8.class);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
    metadataBuffer.remove(entityID);
  }
}
origin: MylesIsCool/ViaVersion

public void setSecondHand(int entityID, Item item) {
  PacketWrapper wrapper = new PacketWrapper(0x3C, null, getUser());
  wrapper.write(Type.VAR_INT, entityID);
  wrapper.write(Type.VAR_INT, 1); // slot
  wrapper.write(Type.ITEM, item);
  try {
    wrapper.send(Protocol1_9TO1_8.class);
  } catch (Exception e) {
    e.printStackTrace();
  }
}
origin: MylesIsCool/ViaVersion

  private static void updateBlockEntity(Position pos, short id, CompoundTag tag, UserConnection connection) throws Exception {
    PacketWrapper wrapper = new PacketWrapper(0x09, null, connection);
    wrapper.write(Type.POSITION, pos);
    wrapper.write(Type.UNSIGNED_BYTE, id);
    wrapper.write(Type.NBT, tag);
    wrapper.send(Protocol1_9_1_2TO1_9_3_4.class, false);
  }
}
origin: Matsv/ViaBackwards

public void update() {
  PacketWrapper wrapper = new PacketWrapper(0x0F, null, getUser());
  wrapper.write(Type.STRING, Protocol1_9TO1_8.fixJson(generateString()));
  wrapper.write(Type.BYTE, (byte) 2);
  try {
    wrapper.send(Protocol1_12To1_11_1.class);
  } catch (Exception e) {
    ViaBackwards.getPlatform().getLogger().severe("Failed to send the shoulder indication");
    e.printStackTrace();
  }
}
origin: MylesIsCool/ViaVersion

  @Override
  public void run() {
    PacketWrapper wrapper = new PacketWrapper(0x2C, null, getUserConnection(p.getUniqueId()));
    try {
      int entityId = getEntityId(p);
      wrapper.write(Type.VAR_INT, 2); // Event - Entity dead
      wrapper.write(Type.VAR_INT, entityId); // Player ID
      wrapper.write(Type.INT, entityId); // Entity ID
      Protocol1_9TO1_8.FIX_JSON.write(wrapper, msg); // Message
      wrapper.send(Protocol1_9TO1_8.class);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
});
origin: MylesIsCool/ViaVersion

  @Override
  public void run() {
    // If online
    if (getUserConnection(p) != null) {
      PacketWrapper wrapper = new PacketWrapper(0x2C, null, getUserConnection(p));
      try {
        wrapper.write(Type.VAR_INT, 2); // Event - Entity dead
        wrapper.write(Type.VAR_INT, p.getEntityId()); // Player ID
        wrapper.write(Type.INT, p.getEntityId()); // Entity ID
        Protocol1_9TO1_8.FIX_JSON.write(wrapper, msg); // Message
        wrapper.send(Protocol1_9TO1_8.class);
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
  }
});
origin: MylesIsCool/ViaVersion

public static void update(UserConnection user, Position position) {
  for (int x = -1; x <= 1; x++) {
    for (int z = -1; z <= 1; z++) {
      for (int y = -1; y <= 1; y++) {
        if (Math.abs(x) + Math.abs(y) + Math.abs(z) != 1) continue;
        Position pos = new Position(position.getX() + x, position.getY() + y, position.getZ() + z);
        int blockState = Via.getManager().getProviders().get(BlockConnectionProvider.class).getBlockdata(user, pos);
        if (!connects(blockState)) continue;
        int newBlockState = connect(user, pos, blockState);
        if (newBlockState == blockState) continue;
        PacketWrapper blockUpdatePacket = new PacketWrapper(0x0B, null, user);
        blockUpdatePacket.write(Type.POSITION, pos);
        blockUpdatePacket.write(Type.VAR_INT, newBlockState);
        try {
          blockUpdatePacket.send(Protocol1_13To1_12_2.class, true, false);
        } catch (Exception ex) {
          ex.printStackTrace();
        }
      }
    }
  }
}
origin: MylesIsCool/ViaVersion

public void sendPermission(UserConnection user) throws Exception {
  if (!isEnabled())
    return;
  PacketWrapper wrapper = new PacketWrapper(0x1B, null, user); // Entity status
  wrapper.write(Type.INT, user.get(EntityTracker.class).getProvidedEntityId()); // Entity ID
  wrapper.write(Type.BYTE, (byte) 26); // Hardcoded op permission level
  wrapper.send(Protocol1_9TO1_8.class);
  user.get(CommandBlockStorage.class).setPermissions(true);
}
origin: MylesIsCool/ViaVersion

  @Subscribe(order = PostOrder.LAST)
  public void onServerConnected(ServerConnectedEvent event) {
    UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId());
    if (user == null) return;

    try {
      if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) {
        int entityId = user.get(EntityTracker.class).getProvidedEntityId();

        PacketWrapper wrapper = new PacketWrapper(0x39, null, user);

        wrapper.write(Type.VAR_INT, entityId);
        wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0)));

        wrapper.send(Protocol1_9TO1_8.class);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
origin: MylesIsCool/ViaVersion

  @EventHandler(priority = EventPriority.HIGH)
  public void onServerConnected(ServerConnectedEvent event) {
    UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId());
    if (user == null) return;

    try {
      if (user.get(ProtocolInfo.class).getPipeline().contains(Protocol1_9TO1_8.class)) {
        int entityId = user.get(EntityTracker.class).getProvidedEntityId();

        PacketWrapper wrapper = new PacketWrapper(0x39, null, user);

        wrapper.write(Type.VAR_INT, entityId);
        wrapper.write(Types1_9.METADATA_LIST, Collections.singletonList(new Metadata(0, MetaType1_9.Byte, (byte) 0)));

        wrapper.send(Protocol1_9TO1_8.class);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
}
origin: MylesIsCool/ViaVersion

public void sendArmorUpdate(Player player) {
  // Ensure that the player is on our pipe
  if (!isOnPipe(player)) return;
  int armor = 0;
  for (ItemStack stack : player.getInventory().getArmorContents()) {
    armor += ArmorType.findById(stack.getTypeId()).getArmorPoints();
  }
  PacketWrapper wrapper = new PacketWrapper(0x4B, null, getUserConnection(player));
  try {
    wrapper.write(Type.VAR_INT, player.getEntityId()); // Player ID
    wrapper.write(Type.INT, 1); // only 1 property
    wrapper.write(Type.STRING, "generic.armor");
    wrapper.write(Type.DOUBLE, 0D); //default 0 armor
    wrapper.write(Type.VAR_INT, 1); // 1 modifier
    wrapper.write(Type.UUID, ARMOR_ATTRIBUTE); // armor modifier uuid
    wrapper.write(Type.DOUBLE, (double) armor); // the modifier value
    wrapper.write(Type.BYTE, (byte) 0);// the modifier operation, 0 is add number
    wrapper.send(Protocol1_9TO1_8.class);
  } catch (Exception e) {
    e.printStackTrace();
  }
}
origin: MylesIsCool/ViaVersion

public void sendTeamPacket(boolean add, boolean now) {
  PacketWrapper wrapper = new PacketWrapper(0x41, null, getUser());
  wrapper.write(Type.STRING, "viaversion"); // Use viaversion as name
  if (add) {
    // add
    if (!teamExists) {
      wrapper.write(Type.BYTE, (byte) 0); // make team
      wrapper.write(Type.STRING, "viaversion");
      wrapper.write(Type.STRING, ""); // prefix
      wrapper.write(Type.STRING, ""); // suffix
      wrapper.write(Type.BYTE, (byte) 0); // friendly fire
      wrapper.write(Type.STRING, ""); // nametags
      wrapper.write(Type.STRING, "never"); // collision rule :)
      wrapper.write(Type.BYTE, (byte) 0); // color
    } else {
      wrapper.write(Type.BYTE, (byte) 3);
    }
    wrapper.write(Type.STRING_ARRAY, new String[]{getUser().get(ProtocolInfo.class).getUsername()});
  } else {
    wrapper.write(Type.BYTE, (byte) 1); // remove team
  }
  teamExists = add;
  try {
    wrapper.send(Protocol1_9TO1_8.class, true, now);
  } catch (Exception e) {
    e.printStackTrace();
  }
}
origin: MylesIsCool/ViaVersion

public void sendArmorUpdate(Player player) {
  // Ensure that the player is on our pipe
  if (!isOnPipe(player.getUniqueId())) return;
  int armor = 0;
  armor += calculate(player.getHelmet());
  armor += calculate(player.getChestplate());
  armor += calculate(player.getLeggings());
  armor += calculate(player.getBoots());
  PacketWrapper wrapper = new PacketWrapper(0x4B, null, getUserConnection(player.getUniqueId()));
  try {
    wrapper.write(Type.VAR_INT, getEntityId(player)); // Player ID
    wrapper.write(Type.INT, 1); // only 1 property
    wrapper.write(Type.STRING, "generic.armor");
    wrapper.write(Type.DOUBLE, 0D); //default 0 armor
    wrapper.write(Type.VAR_INT, 1); // 1 modifier
    wrapper.write(Type.UUID, ARMOR_ATTRIBUTE); // armor modifier uuid
    wrapper.write(Type.DOUBLE, (double) armor); // the modifier value
    wrapper.write(Type.BYTE, (byte) 0);// the modifier operation, 0 is add number
    wrapper.send(Protocol1_9TO1_8.class);
  } catch (Exception e) {
    e.printStackTrace();
  }
}
origin: MylesIsCool/ViaVersion

public void sendArmorUpdate(Player player) {
  // Ensure that the player is on our pipe
  if (!isOnPipe(player.getUniqueId())) return;
  int armor = 0;
  armor += calculate(player.getHelmet());
  armor += calculate(player.getChestplate());
  armor += calculate(player.getLeggings());
  armor += calculate(player.getBoots());
  PacketWrapper wrapper = new PacketWrapper(0x4B, null, getUserConnection(player.getUniqueId()));
  try {
    wrapper.write(Type.VAR_INT, getEntityId(player)); // Player ID
    wrapper.write(Type.INT, 1); // only 1 property
    wrapper.write(Type.STRING, "generic.armor");
    wrapper.write(Type.DOUBLE, 0D); //default 0 armor
    wrapper.write(Type.VAR_INT, 1); // 1 modifier
    wrapper.write(Type.UUID, ARMOR_ATTRIBUTE); // armor modifier uuid
    wrapper.write(Type.DOUBLE, (double) armor); // the modifier value
    wrapper.write(Type.BYTE, (byte) 0);// the modifier operation, 0 is add number
    wrapper.send(Protocol1_9TO1_8.class);
  } catch (Exception e) {
    e.printStackTrace();
  }
}
us.myles.ViaVersion.apiPacketWrappersend

Popular methods of PacketWrapper

    Popular in Java

    • Parsing JSON documents to java classes using gson
    • getContentResolver (Context)
    • getSupportFragmentManager (FragmentActivity)
    • onRequestPermissionsResult (Fragment)
    • Path (java.nio.file)
    • NumberFormat (java.text)
      The abstract base class for all number formats. This class provides the interface for formatting and
    • Dictionary (java.util)
      Note: Do not use this class since it is obsolete. Please use the Map interface for new implementatio
    • ReentrantLock (java.util.concurrent.locks)
      A reentrant mutual exclusion Lock with the same basic behavior and semantics as the implicit monitor
    • Manifest (java.util.jar)
      The Manifest class is used to obtain attribute information for a JarFile and its entries.
    • Project (org.apache.tools.ant)
      Central representation of an Ant project. This class defines an Ant project with all of its targets,
    • Top Vim plugins
    Tabnine Logo
    • Products

      Search for Java codeSearch for JavaScript code
    • IDE Plugins

      IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
    • Company

      About UsContact UsCareers
    • Resources

      FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
    Get Tabnine for your IDE now