Java Code Examples for us.myles.ViaVersion.api.PacketWrapper

The following examples show how to use us.myles.ViaVersion.api.PacketWrapper. These examples are extracted from open source projects. 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 Project: ViaRewind   Author: ViaVersion   File: GuardianReplacement.java    License: MIT License 6 votes vote down vote up
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 #2
Source Project: ViaRewind   Author: ViaVersion   File: GuardianReplacement.java    License: MIT License 6 votes vote down vote up
public void updateMetadata() {
	PacketWrapper metadataPacket = new PacketWrapper(0x1C, null, user);
	metadataPacket.write(Type.INT, entityId);

	List<Metadata> metadataList = new ArrayList<>();
	for (Metadata metadata : datawatcher) {
		if (metadata.getId()==16 || metadata.getId()==17) continue;
		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 #3
Source Project: ViaRewind   Author: ViaVersion   File: EndermiteReplacement.java    License: MIT License 6 votes vote down vote up
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 Project: ViaRewind   Author: ViaVersion   File: EntityTracker.java    License: MIT License 6 votes vote down vote up
public void sendMetadataBuffer(int entityId) {
	if (!this.metadataBuffer.containsKey(entityId)) return;
	if (entityReplacements.containsKey(entityId)) {
		entityReplacements.get(entityId).updateMetadata(this.metadataBuffer.remove(entityId));
	} else {
		Entity1_10Types.EntityType type = this.getClientEntityTypes().get(entityId);
		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(type, this.metadataBuffer.get(entityId));
		if (!this.metadataBuffer.get(entityId).isEmpty()) {
			PacketUtil.sendPacket(wrapper, Protocol1_7_6_10TO1_8.class);
		}

		this.metadataBuffer.remove(entityId);
	}
}
 
Example #5
Source Project: ViaRewind   Author: ViaVersion   File: WitherBossBar.java    License: MIT License 6 votes vote down vote up
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 #6
Source Project: ViaVersion   Author: ViaVersion   File: EntityTracker1_9.java    License: MIT License 6 votes vote down vote up
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);
        getUser().getProtocolInfo().getPipeline().getProtocol(Protocol1_9To1_8.class).get(MetadataRewriter1_9To1_8.class)
                .handleMetadata(entityId, metadataList, getUser());
        handleMetadata(entityId, metadataList);
        if (!metadataList.isEmpty()) {
            try {
                wrapper.send(Protocol1_9To1_8.class);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        metadataBuffer.remove(entityId);
    }
}
 
Example #7
Source Project: ViaRewind   Author: ViaVersion   File: EntityTracker.java    License: MIT License 6 votes vote down vote up
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);
	}
}
 
Example #8
Source Project: ViaRewind   Author: ViaVersion   File: Windows.java    License: MIT License 6 votes vote down vote up
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 #9
Source Project: ViaBackwards   Author: ViaVersion   File: RecipeRewriter1_15.java    License: MIT License 6 votes vote down vote up
@Override
public void handle(PacketWrapper wrapper, String type) throws Exception {
    switch (type) {
        case "crafting_shapeless":
            handleCraftingShapeless(wrapper);
            break;
        case "crafting_shaped":
            handleCraftingShaped(wrapper);
            break;
        case "blasting": // new
        case "smoking": // new
        case "campfire_cooking": // new
        case "smelting":
            handleSmelting(wrapper);
            break;
        case "stonecutting": // new
            handleStonecutting(wrapper);
            break;
    }
}
 
Example #10
Source Project: ViaVersion   Author: ViaVersion   File: ElytraPatch.java    License: MIT License 6 votes vote down vote up
@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 #11
Source Project: ViaVersion   Author: ViaVersion   File: DeathListener.java    License: MIT License 6 votes vote down vote up
private void sendPacket(final Player p, final String msg) {
    Via.getPlatform().runSync(new Runnable() {
        @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();
            }
        }
    });
}
 
Example #12
Source Project: ViaVersion   Author: ViaVersion   File: DeathListener.java    License: MIT License 6 votes vote down vote up
private void sendPacket(final Player p, final String msg) {
    Via.getPlatform().runSync(new Runnable() {
        @Override
        public void run() {
            // If online
            UserConnection userConnection = getUserConnection(p);
            if (userConnection != null) {
                PacketWrapper wrapper = new PacketWrapper(0x2C, null, userConnection);
                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();
                }
            }
        }
    });
}
 
Example #13
Source Project: ViaVersion   Author: ViaVersion   File: ArmorListener.java    License: MIT License 6 votes vote down vote up
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 #14
Source Project: ViaVersion   Author: ViaVersion   File: ElytraPatch.java    License: MIT License 6 votes vote down vote up
@Subscribe(order = PostOrder.LAST)
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 #15
Source Project: ViaVersion   Author: ViaVersion   File: ConnectionData.java    License: MIT License 6 votes vote down vote up
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 #16
Source Project: ViaBackwards   Author: ViaVersion   File: EntityPositionHandler.java    License: MIT License 6 votes vote down vote up
public void cacheEntityPosition(PacketWrapper wrapper, double x, double y, double z, boolean create, boolean relative) throws Exception {
    int entityId = wrapper.get(Type.VAR_INT, 0);
    EntityTracker.StoredEntity storedEntity = entityRewriter.getEntityTracker(wrapper.user()).getEntity(entityId);
    if (storedEntity == null) {
        if (Via.getManager().isDebug()) { // There is too many plugins violating this out there, and reading seems to be hard! :>
            ViaBackwards.getPlatform().getLogger().warning("Stored entity with id " + entityId + " missing at position: " + x + " - " + y + " - " + z + " in " + storageClass.getSimpleName());
            if (entityId == -1 && x == 0 && y == 0 && z == 0) {
                ViaBackwards.getPlatform().getLogger().warning("DO NOT REPORT THIS TO VIA, THIS IS A PLUGIN ISSUE");
            } else if (!warnedForMissingEntity) {
                warnedForMissingEntity = true;
                ViaBackwards.getPlatform().getLogger().warning("This is very likely caused by a plugin sending a teleport packet for an entity outside of the player's range.");
            }
        }
        return;
    }

    EntityPositionStorage positionStorage = create ? storageSupplier.get() : storedEntity.get(storageClass);
    if (positionStorage == null) {
        ViaBackwards.getPlatform().getLogger().warning("Stored entity with id " + entityId + " missing " + storageClass.getSimpleName());
        return;
    }

    positionStorage.setCoordinates(x, y, z, relative);
    storedEntity.put(positionStorage);
}
 
Example #17
Source Project: ViaVersion   Author: ViaVersion   File: WorldPackets.java    License: MIT License 6 votes vote down vote up
public static void register(Protocol protocol) {
    protocol.registerOutgoing(ClientboundPackets1_13.SPAWN_PARTICLE, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(Type.INT); // 0 - Particle ID
            map(Type.BOOLEAN); // 1 - Long Distance
            map(Type.FLOAT); // 2 - X
            map(Type.FLOAT); // 3 - Y
            map(Type.FLOAT); // 4 - Z
            map(Type.FLOAT); // 5 - Offset X
            map(Type.FLOAT); // 6 - Offset Y
            map(Type.FLOAT); // 7 - Offset Z
            map(Type.FLOAT); // 8 - Particle Data
            map(Type.INT); // 9 - Particle Count
            handler(new PacketHandler() {
                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int id = wrapper.get(Type.INT, 0);
                    if (id == 27) {
                        wrapper.write(Type.FLAT_VAR_INT_ITEM, wrapper.read(Type.FLAT_ITEM));
                    }
                }
            });
        }
    });
}
 
Example #18
Source Project: ViaVersion   Author: ViaVersion   File: EntityTracker1_9.java    License: MIT License 5 votes vote down vote up
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 #19
Source Project: ViaRewind   Author: ViaVersion   File: EntityTracker.java    License: MIT License 5 votes vote down vote up
public void setPassenger(int vehicleId, int passengerId) {
	if (vehicleId==this.spectating && this.spectating!=this.playerId) {
		try {
			PacketWrapper sneakPacket = new PacketWrapper(0x0B, null, getUser());
			sneakPacket.write(Type.VAR_INT, playerId);
			sneakPacket.write(Type.VAR_INT, 0);  //Start sneaking
			sneakPacket.write(Type.VAR_INT, 0);  //Action Parameter

			PacketWrapper unsneakPacket = new PacketWrapper(0x0B, null, getUser());
			unsneakPacket.write(Type.VAR_INT, playerId);
			unsneakPacket.write(Type.VAR_INT, 1);  //Stop sneaking
			unsneakPacket.write(Type.VAR_INT, 0);  //Action Parameter

			PacketUtil.sendToServer(sneakPacket, Protocol1_7_6_10TO1_8.class, true, true);

			setSpectating(playerId);
		} catch (Exception ex) {ex.printStackTrace();}
	}
	if (vehicleId==-1) {
		int oldVehicleId = getVehicle(passengerId);
		vehicles.remove(oldVehicleId);
	} else if (passengerId==-1) {
		vehicles.remove(vehicleId);
	} else {
		vehicles.put(vehicleId, passengerId);
	}
}
 
Example #20
Source Project: ViaBackwards   Author: ViaVersion   File: EntityPositionHandler.java    License: MIT License 5 votes vote down vote up
public static void writeFacingAngles(PacketWrapper wrapper, double x, double y, double z, double targetX, double targetY, double targetZ) {
    double dX = targetX - x;
    double dY = targetY - y;
    double dZ = targetZ - z;
    double r = Math.sqrt(dX * dX + dY * dY + dZ * dZ);
    double yaw = -Math.atan2(dX, dZ) / Math.PI * 180;
    if (yaw < 0) {
        yaw = 360 + yaw;
    }
    double pitch = -Math.asin(dY / r) / Math.PI * 180;

    wrapper.write(Type.BYTE, (byte) (yaw * 256f / 360f));
    wrapper.write(Type.BYTE, (byte) (pitch * 256f / 360f));
}
 
Example #21
Source Project: ViaRewind   Author: ViaVersion   File: ShulkerReplacement.java    License: MIT License 5 votes vote down vote up
public void updateLocation() {
	PacketWrapper teleport = new PacketWrapper(0x18, null, user);
	teleport.write(Type.VAR_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) 0);
	teleport.write(Type.BYTE, (byte) 0);
	teleport.write(Type.BOOLEAN, true);

	PacketUtil.sendPacket(teleport, Protocol1_8TO1_9.class, true, true);
}
 
Example #22
Source Project: ViaRewind   Author: ViaVersion   File: ScoreboardPackets.java    License: MIT License 5 votes vote down vote up
public static void register(Protocol protocol) {
	/*  OUTGOING  */

	//Display Scoreboard
	protocol.registerOutgoing(State.PLAY, 0x38, 0x3D);

	//Scoreboard Objective
	protocol.registerOutgoing(State.PLAY, 0x3F, 0x3B);

	//Scoreboard Team
	protocol.registerOutgoing(State.PLAY, 0x41, 0x3E, new PacketRemapper() {
		@Override
		public void registerMap() {
			map(Type.STRING);
			map(Type.BYTE);
			handler(new PacketHandler() {
				@Override
				public void handle(PacketWrapper packetWrapper) throws Exception {
					byte mode = packetWrapper.get(Type.BYTE, 0);
					if (mode == 0 || mode == 2) {
						packetWrapper.passthrough(Type.STRING);  //Display Name
						packetWrapper.passthrough(Type.STRING);  //Prefix
						packetWrapper.passthrough(Type.STRING);  //Suffix
						packetWrapper.passthrough(Type.BYTE);  //Friendly Flags
						packetWrapper.passthrough(Type.STRING);  //Name Tag Visibility
						packetWrapper.read(Type.STRING);  //Skip Collision Rule
						packetWrapper.passthrough(Type.BYTE);  //Friendly Flags
					}

					if (mode == 0 || mode == 3 || mode == 4) {
						packetWrapper.passthrough(Type.STRING_ARRAY);
					}
				}
			});
		}
	});

	//Update Score
	protocol.registerOutgoing(State.PLAY, 0x42, 0x3C);
}
 
Example #23
Source Project: ViaRewind   Author: ViaVersion   File: WitherBossBar.java    License: MIT License 5 votes vote down vote up
private void updateLocation() {
	PacketWrapper packetWrapper = new PacketWrapper(0x18, null, this.connection);
	packetWrapper.write(Type.VAR_INT, entityId);
	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.BOOLEAN, false);

	PacketUtil.sendPacket(packetWrapper, Protocol1_8TO1_9.class, true, true);
}
 
Example #24
Source Project: ViaRewind   Author: ViaVersion   File: Cooldown.java    License: MIT License 5 votes vote down vote up
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 #25
Source Project: ViaBackwards   Author: ViaVersion   File: EntityPackets1_16.java    License: MIT License 5 votes vote down vote up
@Override
public Integer transform(PacketWrapper wrapper, String input) throws Exception {
    switch (input) {
        case "minecraft:the_nether":
            return -1;
        default:
        case "minecraft:overworld":
            return 0;
        case "minecraft:the_end":
            return 1;
    }
}
 
Example #26
Source Project: ViaVersion   Author: ViaVersion   File: BlockEntityProvider.java    License: MIT License 5 votes vote down vote up
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);
}
 
Example #27
Source Project: ViaBackwards   Author: ViaVersion   File: ShoulderTracker.java    License: MIT License 5 votes vote down vote up
public void update() {
    PacketWrapper wrapper = new PacketWrapper(0x0F, null, getUser());

    wrapper.write(Type.COMPONENT, Protocol1_9To1_8.fixJson(generateString()));
    wrapper.write(Type.BYTE, (byte) 2);

    try {
        wrapper.send(Protocol1_11_1To1_12.class);
    } catch (Exception e) {
        ViaBackwards.getPlatform().getLogger().severe("Failed to send the shoulder indication");
        e.printStackTrace();
    }
}
 
Example #28
Source Project: ViaRewind   Author: ViaVersion   File: Cooldown.java    License: MIT License 5 votes vote down vote up
private void sendActionBar(String bar) {
	PacketWrapper actionBarPacket = new PacketWrapper(0x02, null, getUser());
	actionBarPacket.write(Type.STRING, bar);
	actionBarPacket.write(Type.BYTE, (byte) 2);

	PacketUtil.sendPacket(actionBarPacket, Protocol1_8TO1_9.class);
}
 
Example #29
Source Project: ViaVersion   Author: ViaVersion   File: Protocol1_9_1To1_9.java    License: MIT License 5 votes vote down vote up
@Override
protected void registerPackets() {
    // Currently supports 1.9.1 and 1.9.2

    registerOutgoing(ClientboundPackets1_9.JOIN_GAME, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(Type.INT); // 0 - Player ID
            map(Type.UNSIGNED_BYTE); // 1 - Player Gamemode
            // 1.9.1 PRE 2 Changed this
            map(Type.BYTE, Type.INT); // 2 - Player Dimension
            map(Type.UNSIGNED_BYTE); // 3 - World Difficulty
            map(Type.UNSIGNED_BYTE); // 4 - Max Players (Tab)
            map(Type.STRING); // 5 - Level Type
            map(Type.BOOLEAN); // 6 - Reduced Debug info
        }
    });

    registerOutgoing(ClientboundPackets1_9.SOUND, new PacketRemapper() {
        @Override
        public void registerMap() {
            map(Type.VAR_INT); // 0 - Sound ID

            handler(new PacketHandler() {
                @Override
                public void handle(PacketWrapper wrapper) throws Exception {
                    int sound = wrapper.get(Type.VAR_INT, 0);

                    if (sound >= 415) // Add 1 to every sound id since there is no Elytra sound on a 1.9 server
                        wrapper.set(Type.VAR_INT, 0, sound + 1);
                }
            });
        }
    });
}
 
Example #30
Source Project: ViaBackwards   Author: ViaVersion   File: RecipeRewriter1_14.java    License: MIT License 5 votes vote down vote up
public void handleSmelting(PacketWrapper wrapper) throws Exception {
    wrapper.passthrough(Type.STRING); // Group
    Item[] items = wrapper.passthrough(Type.FLAT_VAR_INT_ITEM_ARRAY_VAR_INT); // Ingredients
    for (Item item : items) {
        rewriter.handleItemToClient(item);
    }

    rewriter.handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); // Result

    wrapper.passthrough(Type.FLOAT); // EXP
    wrapper.passthrough(Type.VAR_INT); // Cooking time
}