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

Commit

Permalink
make sync locks less broad
Browse files Browse the repository at this point in the history
  • Loading branch information
BillyGalbreath committed Jul 3, 2023
1 parent c697db7 commit deb8337
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions src/main/java/net/pl3x/map/mobs/markers/MobsLayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,36 +67,36 @@ public MobsLayer(@NotNull Pl3xMapMobs plugin, @NotNull WorldConfig config) {

@Override
public @NotNull Collection<Marker<?>> getMarkers() {
if (!this.running) {
this.running = true;
Bukkit.getScheduler().runTask(this.plugin, this::syncUpdate);
}
synchronized (this.syncLock) {
if (!this.running) {
this.running = true;
Bukkit.getScheduler().runTask(this.plugin, this::syncUpdate);
}
return this.markers;
}
}

public void syncUpdate() {
synchronized (this.syncLock) {
Collection<Marker<?>> markers = new HashSet<>();
World bukkitWorld = Bukkit.getWorld(this.config.getWorld().getName());
if (bukkitWorld == null) {
Collection<Marker<?>> markers = new HashSet<>();
World bukkitWorld = Bukkit.getWorld(this.config.getWorld().getName());
if (bukkitWorld == null) {
return;
}
bukkitWorld.getEntitiesByClass(Mob.class).forEach(mob -> {
if (this.config.ONLY_SHOW_MOBS_EXPOSED_TO_SKY && bukkitWorld.getHighestBlockYAt(mob.getLocation()) > mob.getLocation().getY()) {
return;
}
bukkitWorld.getEntitiesByClass(Mob.class).forEach(mob -> {
if (this.config.ONLY_SHOW_MOBS_EXPOSED_TO_SKY && bukkitWorld.getHighestBlockYAt(mob.getLocation()) > mob.getLocation().getY()) {
return;
}
String key = String.format("%s_%s_%s", KEY, getWorld().getName(), mob.getUniqueId());
markers.add(Marker.icon(key, point(mob.getLocation()), Icon.get(mob).getKey(), this.config.ICON_SIZE)
.setPane(this.config.LAYER_PANE)
.setOptions(Options.builder()
.tooltipOffset(Point.of(0, -Math.round(this.config.ICON_SIZE.z() / 4F)))
.tooltipDirection(Tooltip.Direction.TOP)
.tooltipContent(this.config.ICON_TOOLTIP_CONTENT
.replace("<mob-id>", mob(mob))
).build()));
});
String key = String.format("%s_%s_%s", KEY, getWorld().getName(), mob.getUniqueId());
markers.add(Marker.icon(key, point(mob.getLocation()), Icon.get(mob).getKey(), this.config.ICON_SIZE)
.setPane(this.config.LAYER_PANE)
.setOptions(Options.builder()
.tooltipOffset(Point.of(0, -Math.round(this.config.ICON_SIZE.z() / 4F)))
.tooltipDirection(Tooltip.Direction.TOP)
.tooltipContent(this.config.ICON_TOOLTIP_CONTENT
.replace("<mob-id>", mob(mob))
).build()));
});
synchronized (this.syncLock) {
this.markers.clear();
this.markers.addAll(markers);
this.running = false;
Expand Down

0 comments on commit deb8337

Please sign in to comment.