From deb83375f2477d33660c3971956184dacbb1e135 Mon Sep 17 00:00:00 2001 From: William Blake Galbreath Date: Mon, 3 Jul 2023 02:53:09 -0500 Subject: [PATCH] make sync locks less broad --- .../net/pl3x/map/mobs/markers/MobsLayer.java | 44 +++++++++---------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/net/pl3x/map/mobs/markers/MobsLayer.java b/src/main/java/net/pl3x/map/mobs/markers/MobsLayer.java index 4c93a93..13f6a44 100644 --- a/src/main/java/net/pl3x/map/mobs/markers/MobsLayer.java +++ b/src/main/java/net/pl3x/map/mobs/markers/MobsLayer.java @@ -67,36 +67,36 @@ public MobsLayer(@NotNull Pl3xMapMobs plugin, @NotNull WorldConfig config) { @Override public @NotNull Collection> 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> markers = new HashSet<>(); - World bukkitWorld = Bukkit.getWorld(this.config.getWorld().getName()); - if (bukkitWorld == null) { + Collection> 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(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(mob)) + ).build())); + }); + synchronized (this.syncLock) { this.markers.clear(); this.markers.addAll(markers); this.running = false;