Skip to content

Commit

Permalink
Slightly lazy fetching of face-drawing predicate
Browse files Browse the repository at this point in the history
  • Loading branch information
bazke committed Oct 29, 2023
1 parent d85a3df commit c1d329b
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/main/java/com/lovetropics/extras/data/poi/MapPoiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,8 @@ public class MapPoiManager extends SavedData {
public static final BoundingBox MAP_BB = new BoundingBox(2013, 0, 1883, 2910, 0, 2799);
private static final Codec<Map<String, Poi>> CODEC = Codec.unboundedMap(Codec.STRING, Poi.CODEC);
private static final String STORAGE_ID = LTExtras.MODID + "_map_poi";
private static final RoleOverrideType<Boolean> HOST_ROLE = (RoleOverrideType<Boolean>) RoleOverrideType.byId("host");
private static final Predicate<ServerPlayer> SPECIAL_RULE = p -> PermissionsApi.lookup().byPlayer(p).overrides().test(HOST_ROLE);
private final Map<String, Poi> pois;


public MapPoiManager(final Map<String, Poi> pois) {
this.pois = pois;
}
Expand Down Expand Up @@ -193,7 +190,7 @@ private static void removeFacesInWrongDimensions(MapPoiManager manager, Set<Serv
private static Set<ServerPlayer> getHosts(final MinecraftServer server) {
return server.getPlayerList().getPlayers()
.stream()
.filter(SPECIAL_RULE)
.filter(FacePredicate::shouldDrawFace)
.collect(Collectors.toSet());
}

Expand All @@ -218,4 +215,13 @@ private static void removeNoLongerHostingFaces(final MapPoiManager manager, fina
}
}
}

private static class FacePredicate {
private static final RoleOverrideType<Boolean> HOST_ROLE = (RoleOverrideType<Boolean>) RoleOverrideType.byId("host");
private static final Predicate<ServerPlayer> SPECIAL_RULE = p -> PermissionsApi.lookup().byPlayer(p).overrides().test(HOST_ROLE);

public static boolean shouldDrawFace(ServerPlayer player) {
return SPECIAL_RULE.test(player);
}
}
}

0 comments on commit c1d329b

Please sign in to comment.