Skip to content

Commit

Permalink
Rework whitelist to use HashSet
Browse files Browse the repository at this point in the history
  • Loading branch information
Axionize committed Aug 26, 2024
1 parent 4515d21 commit dd7bb81
Showing 1 changed file with 5 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,15 @@
import com.github.retrooper.packetevents.util.Vector3i;
import org.bukkit.util.Vector;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.*;

@CheckData(name = "LineOfSightPlace")
public class LineOfSightPlace extends BlockPlaceCheck {

double flagBuffer = 0; // If the player flags once, force them to play legit, or we will cancel the tick before.
boolean ignorePost = false;
boolean useBlockWhitelist;
private HashMap<StateType, Boolean> blockWhitelist;
private HashSet<StateType> blockWhitelist;

public LineOfSightPlace(GrimPlayer player) {
super(player);
Expand Down Expand Up @@ -121,18 +118,18 @@ private Vector3i getTargetBlock(Vector eyePosition, Vector eyeDirection, double
}

private boolean isBlockTypeWhitelisted(StateType type) {
return blockWhitelist.get(type) != null;
return blockWhitelist.contains(type);
}

@Override
public void reload() {
super.reload();

useBlockWhitelist = getConfig().getBooleanElse("LineOfSightPlace.use-block-whitelist", false);
blockWhitelist = new HashMap<>();
blockWhitelist = new HashSet<>();
List<String> blocks = getConfig().getList("LineOfSightPlace.block-whitelist");
for (String block : blocks) {
blockWhitelist.put(StateTypes.getByName(block), true);
blockWhitelist.add(StateTypes.getByName(block));
}
}
}

0 comments on commit dd7bb81

Please sign in to comment.