Skip to content

Commit

Permalink
Merge pull request #20 from Bram1903/feat/SpoofLogicRewrite
Browse files Browse the repository at this point in the history
[Feat] Spoofer Logic Rewrite
  • Loading branch information
Bram1903 authored Feb 18, 2025
2 parents e2ffa50 + 0a86079 commit 2bb68e3
Show file tree
Hide file tree
Showing 38 changed files with 1,176 additions and 1,135 deletions.
10 changes: 8 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,14 @@ tasks {
archiveFileName = "${rootProject.name}-${ext["versionNoHash"]}.jar"
archiveClassifier = null

relocate("net.kyori.adventure.text.serializer.gson", "io.github.retrooper.packetevents.adventure.serializer.gson")
relocate("net.kyori.adventure.text.serializer.legacy", "io.github.retrooper.packetevents.adventure.serializer.legacy")
relocate(
"net.kyori.adventure.text.serializer.gson",
"io.github.retrooper.packetevents.adventure.serializer.gson"
)
relocate(
"net.kyori.adventure.text.serializer.legacy",
"io.github.retrooper.packetevents.adventure.serializer.legacy"
)
}

assemble {
Expand Down
1 change: 1 addition & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies {
compileOnlyApi(libs.bundles.adventure)
compileOnlyApi(libs.snakeyaml)
compileOnlyApi(libs.lombok)
compileOnly(libs.guava)
annotationProcessor(libs.lombok)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@
import com.deathmotion.antihealthindicator.api.AntiHealthIndicator;
import com.deathmotion.antihealthindicator.commands.AntiHealthIndicatorCommand;
import com.deathmotion.antihealthindicator.interfaces.Scheduler;
import com.deathmotion.antihealthindicator.managers.*;
import com.deathmotion.antihealthindicator.managers.ConfigManager;
import com.deathmotion.antihealthindicator.managers.LogManager;
import com.deathmotion.antihealthindicator.managers.PlayerDataManager;
import com.deathmotion.antihealthindicator.packets.PacketPlayerJoinQuit;
import com.deathmotion.antihealthindicator.packets.SpoofManagerPacketListener;
import com.deathmotion.antihealthindicator.util.UpdateChecker;
import com.github.retrooper.packetevents.PacketEvents;
import lombok.Getter;
import net.kyori.adventure.text.Component;
Expand All @@ -31,14 +36,22 @@

@Getter
public abstract class AHIPlatform<P> {

@Getter
private static AHIPlatform<?> instance;

protected ConfigManager<P> configManager;
protected LogManager<P> logManager;

protected Scheduler scheduler;
protected AntiHealthIndicatorCommand<P> command;
private CacheManager<P> cacheManager;
protected PlayerDataManager<P> playerDataManager;

private UpdateChecker<P> updateChecker;

public void commonOnInitialize() {
instance = this;

logManager = new LogManager<>(this);
configManager = new ConfigManager<>(this);
AntiHealthIndicator.setAPI(new AntiHealthIndicatorAPIImpl<>(this));
Expand All @@ -48,11 +61,13 @@ public void commonOnInitialize() {
* Called when the platform is enabled.
*/
public void commonOnEnable() {
cacheManager = new CacheManager<>(this);
command = new AntiHealthIndicatorCommand<>(this);
playerDataManager = new PlayerDataManager<>(this);

PacketEvents.getAPI().getEventManager().registerListener(new PacketPlayerJoinQuit<>(this));
PacketEvents.getAPI().getEventManager().registerListener(new SpoofManagerPacketListener<>(this));

new UpdateManager<>(this);
new PacketManager<>(this);
this.updateChecker = new UpdateChecker<>(this);
}

/**
Expand Down
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);
}
}
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) {
}
}
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());
}
}
}
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);
}
}
}
Loading

0 comments on commit 2bb68e3

Please sign in to comment.