Skip to content

Commit

Permalink
Fix bug caused by lag
Browse files Browse the repository at this point in the history
  • Loading branch information
KoutaChan committed Dec 30, 2023
1 parent 60417a8 commit f296258
Showing 1 changed file with 41 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public void onInteract(PlayerInteractEvent event) {
Block block = event.world.getBlockState(event.pos).getBlock();
if (block == Blocks.chest) {
TileEntity tileEntity = event.world.getTileEntity(event.pos);
if (!(tileEntity instanceof TileEntityChest) || clickedPos.contains(event.pos))
if (!(tileEntity instanceof TileEntityChest))
return;
if (((TileEntityChest) tileEntity).numPlayersUsing == 0) {
clickedPos.add(event.pos);
Expand Down Expand Up @@ -277,23 +277,24 @@ public void onReceivePacket(PacketEvent.ReceiveEvent event) {
return;
}
String roomName = RoomDetection.roomName;
if (roomName.equals("undefined") || DungeonRooms.roomsJson.get(roomName) == null || secretsList == null) return;
if (roomName.equals("undefined") || DungeonRooms.roomsJson.get(roomName) == null || secretsList == null)
return;
if (DungeonRooms.waypointsJson.get(roomName) != null) {
JsonArray secretsArray = DungeonRooms.waypointsJson.get(roomName).getAsJsonArray();
int arraySize = secretsArray.size();
for(int i = 0; i < arraySize; i++) {
for (int i = 0; i < arraySize; i++) {
JsonObject secretsObject = secretsArray.get(i).getAsJsonObject();
if (secretsObject.get("category").getAsString().equals("item") || secretsObject.get("category").getAsString().equals("bat")) {
BlockPos relative = new BlockPos(secretsObject.get("x").getAsInt(), secretsObject.get("y").getAsInt(), secretsObject.get("z").getAsInt());
BlockPos pos = MapUtils.relativeToActual(relative, RoomDetection.roomDirection, RoomDetection.roomCorner);

if (entity.getDistanceSq(pos) <= 36D) {
for(int j = 1; j <= secretNum; j++) {
if (secretsObject.get("secretName").getAsString().substring(0,2).replaceAll("[\\D]", "").equals(String.valueOf(j))) {
if (!Waypoints.secretsList.get(j-1)) continue;
Waypoints.secretsList.set(j-1, false);
for (int j = 1; j <= secretNum; j++) {
if (secretsObject.get("secretName").getAsString().substring(0, 2).replaceAll("[\\D]", "").equals(String.valueOf(j))) {
if (!Waypoints.secretsList.get(j - 1)) continue;
Waypoints.secretsList.set(j - 1, false);
Waypoints.allSecretsMap.replace(roomName, Waypoints.secretsList);
DungeonRooms.logger.info("DungeonRooms: " + entity.getCommandSenderEntity().getName() + " picked up " + StringUtils.stripControlCodes(name) + " from a " + secretsObject.get("category").getAsString() + " secret, turning off waypoint for secret #" + j);
DungeonRooms.logger.info("DungeonRooms: " + entity.getCommandSenderEntity().getName() + " picked up " + StringUtils.stripControlCodes(name) + " from a " + secretsObject.get("category").getAsString() + " secret, turning off waypoint for secret #" + j);
return;
}
}
Expand All @@ -306,38 +307,46 @@ public void onReceivePacket(PacketEvent.ReceiveEvent event) {
} else if (event.packet instanceof S24PacketBlockAction) {
S24PacketBlockAction packet = (S24PacketBlockAction) event.packet;
// The chest has not been opened
if (packet.getData2() == 0 || packet.getBlockType() != Blocks.chest)
if (packet.getData2() == 0 || packet.getBlockType() != Blocks.chest || clickedPos.isEmpty())
return;
while (clickedPos.size() > 0) {
BlockPos pos = clickedPos.remove();
// Do nothing if someone else has possibly opened the chest in order to follow Hypixel rules
if (!packet.getBlockPosition().equals(pos))
boolean removed = false;
for (Iterator<BlockPos> it = clickedPos.iterator(); it.hasNext(); ) {
BlockPos pos = it.next();
if (!packet.getBlockPosition().equals(pos)) {
continue;
String roomName = RoomDetection.roomName;
if (roomName.equals("undefined") || DungeonRooms.roomsJson.get(roomName) == null || secretsList == null)
return;
if (DungeonRooms.waypointsJson.get(roomName) != null) {
JsonArray secretsArray = DungeonRooms.waypointsJson.get(roomName).getAsJsonArray();
int arraySize = secretsArray.size();
for (int i = 0; i < arraySize; i++) {
JsonObject secretsObject = secretsArray.get(i).getAsJsonObject();
if (secretsObject.get("category").getAsString().equals("chest")) {
BlockPos relative = new BlockPos(secretsObject.get("x").getAsInt(), secretsObject.get("y").getAsInt(), secretsObject.get("z").getAsInt());
BlockPos roomPos = MapUtils.relativeToActual(relative, RoomDetection.roomDirection, RoomDetection.roomCorner);

if (roomPos.equals(packet.getBlockPosition())) {
for (int j = 1; j <= secretNum; j++) {
if (secretsObject.get("secretName").getAsString().substring(0, 2).replaceAll("[\\D]", "").equals(String.valueOf(j))) {
Waypoints.secretsList.set(j - 1, false);
Waypoints.allSecretsMap.replace(roomName, Waypoints.secretsList);
DungeonRooms.logger.info("DungeonRooms: Detected open " + secretsObject.get("category").getAsString() + ", turning off waypoint for secret #" + j);
return;
}
if (!removed) {
String roomName = RoomDetection.roomName;
if (roomName.equals("undefined") || DungeonRooms.roomsJson.get(roomName) == null || secretsList == null)
continue;
if (DungeonRooms.waypointsJson.get(roomName) != null) {
JsonArray secretsArray = DungeonRooms.waypointsJson.get(roomName).getAsJsonArray();
int arraySize = secretsArray.size();
foreach:
{
for (int i = 0; i < arraySize; i++) {
JsonObject secretsObject = secretsArray.get(i).getAsJsonObject();
if (secretsObject.get("category").getAsString().equals("chest")) {
BlockPos relative = new BlockPos(secretsObject.get("x").getAsInt(), secretsObject.get("y").getAsInt(), secretsObject.get("z").getAsInt());
BlockPos roomPos = MapUtils.relativeToActual(relative, RoomDetection.roomDirection, RoomDetection.roomCorner);

if (roomPos.equals(packet.getBlockPosition())) {
for (int j = 1; j <= secretNum; j++) {
if (secretsObject.get("secretName").getAsString().substring(0, 2).replaceAll("[\\D]", "").equals(String.valueOf(j))) {
Waypoints.secretsList.set(j - 1, false);
Waypoints.allSecretsMap.replace(roomName, Waypoints.secretsList);
DungeonRooms.logger.info("DungeonRooms: Detected open " + secretsObject.get("category").getAsString() + ", turning off waypoint for secret #" + j);
break foreach;
}
}
}
}
}
}
removed = true;
}
}
it.remove();
}
}
}
Expand Down

0 comments on commit f296258

Please sign in to comment.