-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #20 from Bram1903/feat/SpoofLogicRewrite
[Feat] Spoofer Logic Rewrite
- Loading branch information
Showing
38 changed files
with
1,176 additions
and
1,135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
98 changes: 98 additions & 0 deletions
98
common/src/main/java/com/deathmotion/antihealthindicator/cache/EntityCache.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
/* | ||
* This file is part of AntiHealthIndicator - https://github.com/Bram1903/AntiHealthIndicator | ||
* Copyright (C) 2025 Bram and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.deathmotion.antihealthindicator.cache; | ||
|
||
import com.deathmotion.antihealthindicator.cache.entities.CachedEntity; | ||
import com.deathmotion.antihealthindicator.cache.entities.RidableEntity; | ||
import com.deathmotion.antihealthindicator.cache.trackers.EntityTracker; | ||
import com.deathmotion.antihealthindicator.cache.trackers.VehicleTracker; | ||
import com.deathmotion.antihealthindicator.data.AHIPlayer; | ||
import com.github.retrooper.packetevents.event.PacketSendEvent; | ||
import lombok.Getter; | ||
import lombok.NonNull; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
|
||
@Getter | ||
public class EntityCache { | ||
private final AHIPlayer player; | ||
private final ConcurrentHashMap<Integer, CachedEntity> cache; | ||
private final EntityTracker entityTracker; | ||
private final VehicleTracker vehicleTracker; | ||
|
||
public EntityCache(AHIPlayer player) { | ||
this.player = player; | ||
this.cache = new ConcurrentHashMap<>(); | ||
this.entityTracker = new EntityTracker(player, this); | ||
this.vehicleTracker = new VehicleTracker(player, this); | ||
} | ||
|
||
public void onPacketSend(PacketSendEvent event) { | ||
entityTracker.onPacketSend(event); | ||
vehicleTracker.onPacketSend(event); | ||
} | ||
|
||
public Optional<CachedEntity> getCachedEntity(int entityId) { | ||
return Optional.ofNullable(cache.get(entityId)); | ||
} | ||
|
||
public Optional<RidableEntity> getVehicleData(int entityId) { | ||
return getCachedEntity(entityId) | ||
.filter(entityData -> entityData instanceof RidableEntity) | ||
.map(entityData -> (RidableEntity) entityData); | ||
} | ||
|
||
public void addLivingEntity(int entityId, @NonNull CachedEntity cachedEntity) { | ||
cache.put(entityId, cachedEntity); | ||
} | ||
|
||
public void removeEntity(int entityId) { | ||
cache.remove(entityId); | ||
} | ||
|
||
public void resetUserCache() { | ||
cache.clear(); | ||
} | ||
|
||
public void updateVehiclePassenger(int entityId, int passengerId) { | ||
getVehicleData(entityId).ifPresent(ridableEntityData -> ridableEntityData.setPassengerId(passengerId)); | ||
} | ||
|
||
public float getVehicleHealth(int entityId) { | ||
return getVehicleData(entityId).map(RidableEntity::getHealth).orElse(0.5f); | ||
} | ||
|
||
public boolean isUserPassenger(int entityId) { | ||
return getVehicleData(entityId).map(ridableEntityData -> ridableEntityData.getPassengerId() == player.user.getEntityId()).orElse(false); | ||
} | ||
|
||
public int getPassengerId(int entityId) { | ||
return getVehicleData(entityId).map(RidableEntity::getPassengerId).orElse(0); | ||
} | ||
|
||
public int getEntityIdByPassengerId(int passengerId) { | ||
return cache.entrySet().stream() | ||
.filter(entry -> entry.getValue() instanceof RidableEntity && ((RidableEntity) entry.getValue()).getPassengerId() == passengerId) | ||
.map(Map.Entry::getKey) | ||
.findFirst() | ||
.orElse(0); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
common/src/main/java/com/deathmotion/antihealthindicator/cache/entities/CachedEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* This file is part of AntiHealthIndicator - https://github.com/Bram1903/AntiHealthIndicator | ||
* Copyright (C) 2025 Bram and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.deathmotion.antihealthindicator.cache.entities; | ||
|
||
import com.deathmotion.antihealthindicator.data.AHIPlayer; | ||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData; | ||
import com.github.retrooper.packetevents.protocol.entity.type.EntityType; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class CachedEntity { | ||
private EntityType entityType; | ||
|
||
public void processMetaData(EntityData metaData, AHIPlayer player) { | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
common/src/main/java/com/deathmotion/antihealthindicator/cache/entities/RidableEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* This file is part of AntiHealthIndicator - https://github.com/Bram1903/AntiHealthIndicator | ||
* Copyright (C) 2025 Bram and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.deathmotion.antihealthindicator.cache.entities; | ||
|
||
import com.deathmotion.antihealthindicator.data.AHIPlayer; | ||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
public class RidableEntity extends CachedEntity { | ||
private float health; | ||
private int passengerId; | ||
|
||
@Override | ||
public void processMetaData(EntityData metaData, AHIPlayer player) { | ||
if (metaData.getIndex() == player.metadataIndex.HEALTH) { | ||
setHealth((float) metaData.getValue()); | ||
} | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
common/src/main/java/com/deathmotion/antihealthindicator/cache/entities/WolfEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/* | ||
* This file is part of AntiHealthIndicator - https://github.com/Bram1903/AntiHealthIndicator | ||
* Copyright (C) 2025 Bram and contributors | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package com.deathmotion.antihealthindicator.cache.entities; | ||
|
||
import com.deathmotion.antihealthindicator.data.AHIPlayer; | ||
import com.github.retrooper.packetevents.protocol.entity.data.EntityData; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
@Getter | ||
@Setter | ||
public class WolfEntity extends CachedEntity { | ||
private boolean isTamed; | ||
private UUID ownerUUID; | ||
|
||
public boolean isOwnerPresent() { | ||
return ownerUUID != null; | ||
} | ||
|
||
public UUID getOwnerUUID() { | ||
if (!isOwnerPresent()) { | ||
throw new IllegalStateException("Owner UUID not present"); | ||
} | ||
return ownerUUID; | ||
} | ||
|
||
@Override | ||
public void processMetaData(EntityData metaData, AHIPlayer player) { | ||
int index = metaData.getIndex(); | ||
|
||
if (index == player.metadataIndex.TAMABLE_TAMED) { | ||
setTamed(((Byte) metaData.getValue() & 0x04) != 0); | ||
} else if (index == player.metadataIndex.TAMABLE_OWNER) { | ||
Object value = metaData.getValue(); | ||
|
||
UUID ownerUUID = value instanceof String | ||
? Optional.of((String) value) | ||
.filter(player.uuid.toString()::equals) | ||
.map(UUID::fromString) | ||
.orElse(null) | ||
: ((Optional<UUID>) value) | ||
.filter(player.uuid::equals) | ||
.orElse(null); | ||
|
||
setOwnerUUID(ownerUUID); | ||
} | ||
} | ||
} |
Oops, something went wrong.