Java Code Examples for us.myles.ViaVersion.api.PacketWrapper#write()
The following examples show how to use
us.myles.ViaVersion.api.PacketWrapper#write() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ArmorListener.java From ViaVersion with MIT License | 6 votes |
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(); } }
Example 2
Source File: Windows.java From ViaRewind with MIT License | 6 votes |
public static void updateBrewingStand(UserConnection user, Item blazePowder, short windowId) { if (blazePowder != null && blazePowder.getIdentifier() != 377) return; int amount = blazePowder == null ? 0 : blazePowder.getAmount(); PacketWrapper openWindow = new PacketWrapper(0x2D, null, user); openWindow.write(Type.UNSIGNED_BYTE, windowId); openWindow.write(Type.STRING, "minecraft:brewing_stand"); openWindow.write(Type.STRING, "[{\"translate\":\"container.brewing\"},{\"text\":\": \",\"color\":\"dark_gray\"},{\"text\":\"ยง4" + amount + " \",\"color\":\"dark_red\"},{\"translate\":\"item.blazePowder.name\",\"color\":\"dark_red\"}]"); openWindow.write(Type.UNSIGNED_BYTE, (short) 420); PacketUtil.sendPacket(openWindow, Protocol1_8TO1_9.class); Item[] items = user.get(Windows.class).getBrewingItems(windowId); for (int i = 0; i < items.length; i++) { PacketWrapper setSlot = new PacketWrapper(0x2F, null, user); setSlot.write(Type.BYTE, (byte) windowId); setSlot.write(Type.SHORT, (short) i); setSlot.write(Type.ITEM, items[i]); PacketUtil.sendPacket(setSlot, Protocol1_8TO1_9.class); } }
Example 3
Source File: EndermiteReplacement.java From ViaRewind with MIT License | 6 votes |
public void updateLocation() { PacketWrapper teleport = new PacketWrapper(0x18, null, user); teleport.write(Type.INT, entityId); teleport.write(Type.INT, (int) (locX * 32.0)); teleport.write(Type.INT, (int) (locY * 32.0)); teleport.write(Type.INT, (int) (locZ * 32.0)); teleport.write(Type.BYTE, (byte)((yaw / 360f) * 256)); teleport.write(Type.BYTE, (byte)((pitch / 360f) * 256)); PacketWrapper head = new PacketWrapper(0x19, null, user); head.write(Type.INT, entityId); head.write(Type.BYTE, (byte)((headYaw / 360f) * 256)); PacketUtil.sendPacket(teleport, Protocol1_7_6_10TO1_8.class, true, true); PacketUtil.sendPacket(head, Protocol1_7_6_10TO1_8.class, true, true); }
Example 4
Source File: Cooldown.java From ViaRewind with MIT License | 6 votes |
private void sendBossBar(float cooldown) { PacketWrapper wrapper = new PacketWrapper(0x0C, null, getUser()); if (bossUUID==null) { bossUUID = UUID.randomUUID(); wrapper.write(Type.UUID, bossUUID); wrapper.write(Type.VAR_INT, 0); wrapper.write(Type.STRING, "{\"text\":\" \"}"); wrapper.write(Type.FLOAT, cooldown); wrapper.write(Type.VAR_INT, 0); wrapper.write(Type.VAR_INT, 0); wrapper.write(Type.UNSIGNED_BYTE, (short) 0); } else { wrapper.write(Type.UUID, bossUUID); wrapper.write(Type.VAR_INT, 2); wrapper.write(Type.FLOAT, cooldown); } PacketUtil.sendPacket(wrapper, Protocol1_8TO1_9.class, false, true); }
Example 5
Source File: ElytraPatch.java From ViaVersion with MIT License | 6 votes |
@EventHandler(priority = EventPriority.HIGH) public void onServerConnected(ServerConnectedEvent event) { UserConnection user = Via.getManager().getConnection(event.getPlayer().getUniqueId()); if (user == null) return; try { if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) { int entityId = user.get(EntityTracker1_9.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(); } }
Example 6
Source File: ConnectionData.java From ViaVersion with MIT License | 6 votes |
public static void update(UserConnection user, Position position) { for (BlockFace face : BlockFace.values()) { Position pos = position.getRelative(face); int blockState = blockConnectionProvider.getBlockData(user, pos.getX(), pos.getY(), pos.getZ()); ConnectionHandler handler = connectionHandlerMap.get(blockState); if (handler == null) continue; int newBlockState = handler.connect(user, pos, blockState); 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, true); } catch (Exception ex) { ex.printStackTrace(); } } }
Example 7
Source File: WitherBossBar.java From ViaRewind with MIT License | 6 votes |
private void spawnWither() { PacketWrapper packetWrapper = new PacketWrapper(0x0F, null, this.connection); packetWrapper.write(Type.VAR_INT, entityId); packetWrapper.write(Type.UNSIGNED_BYTE, (short)64); packetWrapper.write(Type.INT, (int) (locX * 32d)); packetWrapper.write(Type.INT, (int) (locY * 32d)); packetWrapper.write(Type.INT, (int) (locZ * 32d)); packetWrapper.write(Type.BYTE, (byte)0); packetWrapper.write(Type.BYTE, (byte)0); packetWrapper.write(Type.BYTE, (byte)0); packetWrapper.write(Type.SHORT, (short)0); packetWrapper.write(Type.SHORT, (short)0); packetWrapper.write(Type.SHORT, (short)0); List<Metadata> metadata = new ArrayList<>(); metadata.add(new Metadata(0, MetaType1_8.Byte, (byte) 0x20)); metadata.add(new Metadata(2, MetaType1_8.String, title)); metadata.add(new Metadata(3, MetaType1_8.Byte, (byte) 1)); metadata.add(new Metadata(6, MetaType1_8.Float, health * 300f)); packetWrapper.write(Types1_8.METADATA_LIST, metadata); PacketUtil.sendPacket(packetWrapper, Protocol1_8TO1_9.class, true, true); }
Example 8
Source File: TagRewriter.java From ViaVersion with MIT License | 6 votes |
private void handle(PacketWrapper wrapper, IdRewriteFunction rewriteFunction, List<TagData> newTags) throws Exception { int tagsSize = wrapper.read(Type.VAR_INT); wrapper.write(Type.VAR_INT, newTags != null ? tagsSize + newTags.size() : tagsSize); // add new tags count for (int i = 0; i < tagsSize; i++) { wrapper.passthrough(Type.STRING); int[] ids = wrapper.passthrough(Type.VAR_INT_ARRAY_PRIMITIVE); if (rewriteFunction != null) { for (int j = 0; j < ids.length; j++) { ids[j] = rewriteFunction.rewrite(ids[j]); } } } // Send new tags if present if (newTags != null) { for (TagData tag : newTags) { wrapper.write(Type.STRING, tag.identifier); wrapper.write(Type.VAR_INT_ARRAY_PRIMITIVE, tag.entries); } } }
Example 9
Source File: Cooldown.java From ViaRewind with MIT License | 6 votes |
private void sendTitle(String title, String subTitle, int fadeIn, int stay, int fadeOut) { PacketWrapper timePacket = new PacketWrapper(0x45, null, getUser()); timePacket.write(Type.VAR_INT, 2); timePacket.write(Type.INT, fadeIn); timePacket.write(Type.INT, stay); timePacket.write(Type.INT, fadeOut); PacketWrapper titlePacket = new PacketWrapper(0x45, null, getUser()); titlePacket.write(Type.VAR_INT, 0); titlePacket.write(Type.STRING, title); PacketWrapper subtitlePacket = new PacketWrapper(0x45, null, getUser()); subtitlePacket.write(Type.VAR_INT, 1); subtitlePacket.write(Type.STRING, subTitle); PacketUtil.sendPacket(titlePacket, Protocol1_8TO1_9.class); PacketUtil.sendPacket(subtitlePacket, Protocol1_8TO1_9.class); PacketUtil.sendPacket(timePacket, Protocol1_8TO1_9.class); }
Example 10
Source File: EntityTracker1_9.java From ViaVersion with MIT License | 5 votes |
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(); } }
Example 11
Source File: Cooldown.java From ViaRewind with MIT License | 5 votes |
private void hideBossBar() { if (bossUUID==null) return; PacketWrapper wrapper = new PacketWrapper(0x0C, null, getUser()); wrapper.write(Type.UUID, bossUUID); wrapper.write(Type.VAR_INT, 1); PacketUtil.sendPacket(wrapper, Protocol1_8TO1_9.class, false, true); bossUUID = null; }
Example 12
Source File: Sponge5ArmorListener.java From ViaVersion with MIT License | 5 votes |
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(); } }
Example 13
Source File: Levitation.java From ViaRewind with MIT License | 5 votes |
@Override public void tick() { if (!active) { return; } int vY = (amplifier+1) * 360; PacketWrapper packet = new PacketWrapper(0x12, null, Levitation.this.getUser()); packet.write(Type.VAR_INT, getUser().get(EntityTracker.class).getPlayerId()); packet.write(Type.SHORT, (short)0); packet.write(Type.SHORT, (short)vY); packet.write(Type.SHORT, (short)0); PacketUtil.sendPacket(packet, Protocol1_8TO1_9.class); }
Example 14
Source File: Scoreboard.java From ViaRewind with MIT License | 5 votes |
public String removeTeamForScore(String score) { ScoreTeam scoreTeam = scoreTeams.remove(score); if (scoreTeam==null) return score; scoreTeamNames.remove(scoreTeam.name); PacketWrapper teamPacket = new PacketWrapper(0x3E, null, getUser()); teamPacket.write(Type.STRING, scoreTeam.name); teamPacket.write(Type.BYTE, (byte) 1); PacketUtil.sendPacket(teamPacket, Protocol1_7_6_10TO1_8.class, true, true); return scoreTeam.name; }
Example 15
Source File: VelocityMovementTransmitter.java From ViaVersion with MIT License | 5 votes |
public void sendPlayer(UserConnection userConnection) { if (userConnection.getProtocolInfo().getState() == State.PLAY) { PacketWrapper wrapper = new PacketWrapper(0x03, null, userConnection); wrapper.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround()); try { wrapper.sendToServer(Protocol1_9To1_8.class); } catch (Exception e) { e.printStackTrace(); } // PlayerPackets will increment idle } }
Example 16
Source File: EntityTracker1_9.java From ViaVersion with MIT License | 5 votes |
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().getProtocolInfo().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(); } }
Example 17
Source File: BungeeMovementTransmitter.java From ViaVersion with MIT License | 5 votes |
public void sendPlayer(UserConnection userConnection) { if (userConnection.getProtocolInfo().getState() == State.PLAY) { PacketWrapper wrapper = new PacketWrapper(0x03, null, userConnection); wrapper.write(Type.BOOLEAN, userConnection.get(MovementTracker.class).isGround()); try { wrapper.sendToServer(Protocol1_9To1_8.class); } catch (Exception e) { e.printStackTrace(); } // PlayerPackets will increment idle } }
Example 18
Source File: EndermiteReplacement.java From ViaRewind with MIT License | 5 votes |
public void updateMetadata() { PacketWrapper metadataPacket = new PacketWrapper(0x1C, null, user); metadataPacket.write(Type.INT, entityId); List<Metadata> metadataList = new ArrayList<>(); for (Metadata metadata : datawatcher) { metadataList.add(new Metadata(metadata.getId(), metadata.getMetaType(), metadata.getValue())); } MetadataRewriter.transform(Entity1_10Types.EntityType.SQUID, metadataList); metadataPacket.write(Types1_7_6_10.METADATA_LIST, metadataList); PacketUtil.sendPacket(metadataPacket, Protocol1_7_6_10TO1_8.class); }
Example 19
Source File: EntityToggleGlideListener.java From ViaVersion with MIT License | 4 votes |
@EventHandler(priority = EventPriority.MONITOR) public void entityToggleGlide(EntityToggleGlideEvent event) { if (!(event.getEntity() instanceof Player)) return; Player player = (Player) event.getEntity(); if (!isOnPipe(player)) return; // Cancelling can only be done by updating the player's metadata if (event.isGliding() && event.isCancelled()) { PacketWrapper packet = new PacketWrapper(0x44, null, getUserConnection(player)); try { packet.write(Type.VAR_INT, player.getEntityId()); byte bitmask = 0; // Collect other metadata for the mitmask if (player.getFireTicks() > 0) { bitmask |= 0x01; } if (player.isSneaking()) { bitmask |= 0x02; } // 0x04 is unused if (player.isSprinting()) { bitmask |= 0x08; } if (swimmingMethodExists && player.isSwimming()) { bitmask |= 0x10; } if (player.hasPotionEffect(PotionEffectType.INVISIBILITY)) { bitmask |= 0x20; } if (player.isGlowing()) { bitmask |= 0x40; } // leave 0x80 as 0 to stop gliding packet.write(Types1_14.METADATA_LIST, Arrays.asList(new Metadata(0, MetaType1_14.Byte, bitmask))); packet.send(Protocol1_15To1_14_4.class); } catch (Exception e) { e.printStackTrace(); } } }
Example 20
Source File: ConnectionData.java From ViaVersion with MIT License | 4 votes |
public static void updateChunkSectionNeighbours(UserConnection user, int chunkX, int chunkZ, int chunkSectionY) { for (int chunkDeltaX = -1; chunkDeltaX <= 1; chunkDeltaX++) { for (int chunkDeltaZ = -1; chunkDeltaZ <= 1; chunkDeltaZ++) { if (Math.abs(chunkDeltaX) + Math.abs(chunkDeltaZ) == 0) continue; List<BlockChangeRecord> updates = new ArrayList<>(); if (Math.abs(chunkDeltaX) + Math.abs(chunkDeltaZ) == 2) { // Corner for (int blockY = chunkSectionY * 16; blockY < chunkSectionY * 16 + 16; blockY++) { int blockPosX = chunkDeltaX == 1 ? 0 : 15; int blockPosZ = chunkDeltaZ == 1 ? 0 : 15; updateBlock(user, new Position( ((chunkX + chunkDeltaX) << 4) + blockPosX, (short) blockY, ((chunkZ + chunkDeltaZ) << 4) + blockPosZ ), updates ); } } else { for (int blockY = chunkSectionY * 16; blockY < chunkSectionY * 16 + 16; blockY++) { int xStart; int xEnd; int zStart; int zEnd; if (chunkDeltaX == 1) { xStart = 0; xEnd = 2; zStart = 0; zEnd = 16; } else if (chunkDeltaX == -1) { xStart = 14; xEnd = 16; zStart = 0; zEnd = 16; } else if (chunkDeltaZ == 1) { xStart = 0; xEnd = 16; zStart = 0; zEnd = 2; } else { xStart = 0; xEnd = 16; zStart = 14; zEnd = 16; } for (int blockX = xStart; blockX < xEnd; blockX++) { for (int blockZ = zStart; blockZ < zEnd; blockZ++) { updateBlock(user, new Position( ((chunkX + chunkDeltaX) << 4) + blockX, (short) blockY, ((chunkZ + chunkDeltaZ) << 4) + blockZ), updates ); } } } } if (!updates.isEmpty()) { PacketWrapper wrapper = new PacketWrapper(0x0F, null, user); wrapper.write(Type.INT, chunkX + chunkDeltaX); wrapper.write(Type.INT, chunkZ + chunkDeltaZ); wrapper.write(Type.BLOCK_CHANGE_RECORD_ARRAY, updates.toArray(EMPTY_RECORDS)); try { wrapper.send(Protocol1_13To1_12_2.class, true, true); } catch (Exception e) { e.printStackTrace(); } } } } }