Skip to content

Commit

Permalink
Fix getting disconnected upon entering a boat
Browse files Browse the repository at this point in the history
  • Loading branch information
Bram1903 committed Jul 13, 2024
1 parent 5213cb3 commit dc21cbd
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,16 @@
package com.deathmotion.antihealthindicator.packetlisteners;

import com.deathmotion.antihealthindicator.AHIPlatform;
import com.deathmotion.antihealthindicator.data.RidableEntities;
import com.deathmotion.antihealthindicator.data.Settings;
import com.deathmotion.antihealthindicator.data.cache.CachedEntity;
import com.deathmotion.antihealthindicator.managers.CacheManager;
import com.deathmotion.antihealthindicator.util.MetadataIndex;
import com.github.retrooper.packetevents.event.PacketListenerAbstract;
import com.github.retrooper.packetevents.event.PacketSendEvent;
import com.github.retrooper.packetevents.protocol.entity.data.EntityData;
import com.github.retrooper.packetevents.protocol.entity.data.EntityDataTypes;
import com.github.retrooper.packetevents.protocol.entity.type.EntityType;
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
import com.github.retrooper.packetevents.protocol.packettype.PacketTypeCommon;
import com.github.retrooper.packetevents.protocol.player.User;
Expand All @@ -35,6 +38,7 @@

import java.util.Collections;
import java.util.List;
import java.util.UUID;

/**
* Listens for VehicleState events and manages the caching of various entity state details.
Expand Down Expand Up @@ -79,6 +83,7 @@ public void onPacketSend(PacketSendEvent event) {
private void handleSetPassengers(WrapperPlayServerSetPassengers packet, User user) {
int entityId = packet.getEntityId();
if (entityId == user.getEntityId()) return;
if (!validVehicle(user.getUUID(), entityId)) return;

int[] passengers = packet.getPassengers();

Expand All @@ -98,6 +103,7 @@ private void handleSetPassengers(WrapperPlayServerSetPassengers packet, User use
private void handleAttachEntity(WrapperPlayServerAttachEntity packet, User user) {
int entityId = packet.getHoldingId();
if (entityId == user.getEntityId()) return;
if (!validVehicle(user.getUUID(), entityId)) return;

int passengerId = packet.getAttachedId();

Expand All @@ -116,6 +122,14 @@ private void handleAttachEntity(WrapperPlayServerAttachEntity packet, User user)
}
}

private boolean validVehicle(UUID user, int entityId) {
CachedEntity cachedEntity = cacheManager.getCachedEntity(user, entityId).orElse(null);
if (cachedEntity == null) return false;

EntityType entityType = cachedEntity.getEntityType();
return RidableEntities.isRideable(entityType);
}

private void handlePassengerEvent(User user, int vehicleId, float healthValue, boolean entering) {
platform.getScheduler().runAsyncTask((o) -> {
if (!entering && settings.isAllowBypass()) {
Expand Down

0 comments on commit dc21cbd

Please sign in to comment.