Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
failsafe test
Browse files Browse the repository at this point in the history
  • Loading branch information
Pan4ur committed Aug 12, 2024
1 parent dd2d0ea commit bf96b62
Show file tree
Hide file tree
Showing 6 changed files with 184 additions and 110 deletions.
2 changes: 0 additions & 2 deletions src/main/java/thunder/hack/core/Managers.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import thunder.hack.core.manager.player.CombatManager;
import thunder.hack.core.manager.player.FriendManager;
import thunder.hack.core.manager.player.PlayerManager;
import thunder.hack.core.manager.world.DeadManager;
import thunder.hack.core.manager.world.HoleManager;
import thunder.hack.core.manager.world.WayPointManager;
import thunder.hack.utility.ThunderUtility;
Expand All @@ -28,7 +27,6 @@ public class Managers {
public static final PlayerManager PLAYER = new PlayerManager();

// World
public static final DeadManager DEAD = new DeadManager();
public static final HoleManager HOLE = new HoleManager();
public static final WayPointManager WAYPOINT = new WayPointManager();

Expand Down
114 changes: 114 additions & 0 deletions src/main/java/thunder/hack/core/manager/world/CrystalManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package thunder.hack.core.manager.world;

import net.minecraft.entity.decoration.EndCrystalEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import thunder.hack.core.Managers;
import thunder.hack.core.manager.IManager;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class CrystalManager implements IManager {
private final Map<Integer, Long> deadCrystals = new ConcurrentHashMap<>();
private final Map<Integer, Attempt> attackedCrystals = new ConcurrentHashMap<>();
private final Map<BlockPos, Attempt> awaitingPositions = new ConcurrentHashMap<>();

public void onAttack(EndCrystalEntity crystal) {
setDead(crystal.getId(), System.currentTimeMillis());
addAttack(crystal);
}

public void reset() {
deadCrystals.clear();
attackedCrystals.clear();
awaitingPositions.clear();
}

public void update() {
long time = System.currentTimeMillis();
deadCrystals.entrySet().removeIf(entry -> time - entry.getValue() > Managers.SERVER.getPing() * 2L);
awaitingPositions.entrySet().removeIf(entry -> Math.abs(entry.getValue().getDistance() - mc.player.squaredDistanceTo(entry.getKey().toCenterPos())) >= 1f);
attackedCrystals.entrySet().removeIf(entry -> Math.abs(entry.getValue().getDistance() - mc.player.squaredDistanceTo(entry.getValue().getPos())) >= 1f);
}

public boolean isDead(Integer id) {
return deadCrystals.containsKey(id);
}

public void setDead(Integer id, long deathTime) {
deadCrystals.putIfAbsent(id, deathTime);
}

public boolean isBlocked(Integer id) {
return attackedCrystals.containsKey(id) && attackedCrystals.get(id).canSetPosBlocked();
}

public void addAttack(EndCrystalEntity entity) {
attackedCrystals.compute(entity.getId(), (pos, attempt) -> {
if (attempt == null) {
return new Attempt(System.currentTimeMillis(), 1, entity.getPos());
} else {
attempt.addAttempt();
return attempt;
}
});
}

public Map<BlockPos, Attempt> getAwaitingPositions() {
return awaitingPositions;
}

public void confirmSpawn(BlockPos bp) {
awaitingPositions.remove(bp);
}

public void addAwaitingPos(BlockPos blockPos) {
awaitingPositions.compute(blockPos, (pos, attempt) -> {
if (attempt == null) {
return new Attempt(System.currentTimeMillis(), 1, blockPos.toCenterPos());
} else {
attempt.addAttempt();
return attempt;
}
});
}

public boolean isPositionBlocked(BlockPos bp) {
return awaitingPositions.containsKey(bp) && awaitingPositions.get(bp).canSetPosBlocked();
}

public class Attempt {
long time;
int attempts;
float distance;
public Vec3d pos;

Attempt(long time, int attempts, Vec3d pos) {
this.time = time;
this.pos = pos;
this.attempts = attempts;
distance = (float) mc.player.squaredDistanceTo(pos);
}

public Vec3d getPos() {
return pos;
}

public long getTime() {
return time;
}

public float getDistance() {
return distance;
}

public void addAttempt() {
attempts++;
}

public boolean canSetPosBlocked() {
return attempts >= 5;
}
}
}
37 changes: 0 additions & 37 deletions src/main/java/thunder/hack/core/manager/world/DeadManager.java

This file was deleted.

Loading

0 comments on commit bf96b62

Please sign in to comment.