use of com.viaversion.viaversion.api.minecraft.metadata.Metadata in project ViaVersion by ViaVersion.
the class EntityToggleGlideListener method entityToggleGlide.
@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 = PacketWrapper.create(ClientboundPackets1_15.ENTITY_METADATA, 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, Types1_14.META_TYPES.byteType, bitmask)));
packet.scheduleSend(Protocol1_15To1_14_4.class);
} catch (Exception e) {
e.printStackTrace();
}
}
}
use of com.viaversion.viaversion.api.minecraft.metadata.Metadata in project ViaVersion by ViaVersion.
the class ElytraPatch method onServerConnected.
@EventHandler(priority = EventPriority.HIGH)
public void onServerConnected(ServerConnectedEvent event) {
UserConnection user = Via.getManager().getConnectionManager().getConnectedClient(event.getPlayer().getUniqueId());
if (user == null)
return;
try {
if (user.getProtocolInfo().getPipeline().contains(Protocol1_9To1_8.class)) {
EntityTracker1_9 tracker = user.getEntityTracker(Protocol1_9To1_8.class);
int entityId = tracker.getProvidedEntityId();
PacketWrapper wrapper = PacketWrapper.create(ClientboundPackets1_9.ENTITY_METADATA, 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.scheduleSend(Protocol1_9To1_8.class);
}
} catch (Exception e) {
e.printStackTrace();
}
}
Aggregations