diff --git a/src/main/java/com/github/johnnyjayjay/spigotmaps/rendering/AbstractMapRenderer.java b/src/main/java/com/github/johnnyjayjay/spigotmaps/rendering/AbstractMapRenderer.java index 79005be..fcd98b3 100644 --- a/src/main/java/com/github/johnnyjayjay/spigotmaps/rendering/AbstractMapRenderer.java +++ b/src/main/java/com/github/johnnyjayjay/spigotmaps/rendering/AbstractMapRenderer.java @@ -25,11 +25,13 @@ */ public abstract class AbstractMapRenderer extends MapRenderer { - private final Set alreadyReceived; + private final Set alreadyReceived; private final boolean renderForAllPlayers, renderOnce; private final Set receivers; private final Predicate precondition; + private boolean stop; + protected AbstractMapRenderer(Set receivers, boolean renderOnce, Predicate precondition) { super(!receivers.isEmpty()); this.renderForAllPlayers = receivers.isEmpty(); @@ -37,6 +39,7 @@ protected AbstractMapRenderer(Set receivers, boolean renderOnce, Predica this.renderOnce = renderOnce; this.precondition = precondition; this.alreadyReceived = new HashSet<>(); // TODO consider an implementation with less overhead + this.stop = false; } @Override @@ -45,13 +48,14 @@ public final void render(MapView map, MapCanvas canvas, Player player) { if (mayRender(context)) { render(context); if (renderOnce) - alreadyReceived.add(player); + alreadyReceived.add(context); } } private boolean mayRender(RenderContext context) { - return (renderForAllPlayers || receivers.contains(context.getPlayer())) - && (!renderOnce || !alreadyReceived.contains(context.getPlayer())) + return !stop + &&(renderForAllPlayers || receivers.contains(context.getPlayer())) + && (!renderOnce || !alreadyReceived.contains(context)) && precondition.test(context); } @@ -97,12 +101,21 @@ public boolean isRenderOnce() { return renderOnce; } + /** + * Makes this renderer stop rendering anything, forever. + */ + public void stopRendering() { + this.stop = true; + } + /** * Renders the map after the preconditions have passed, i.e.: *
    - *
  • The predicate's test was successful
  • *
  • This renderer applies to the player or
  • *
  • This renderer renders maps for all players
  • + *
  • This renderer does not only render once or
  • + *
  • This renderer has not rendered for the given context yet
  • + *
  • The predicate's test was successful
  • *
* * @param context the context for this rendering operation. diff --git a/src/main/java/com/github/johnnyjayjay/spigotmaps/rendering/RenderContext.java b/src/main/java/com/github/johnnyjayjay/spigotmaps/rendering/RenderContext.java index 832a9c2..3e30fd9 100644 --- a/src/main/java/com/github/johnnyjayjay/spigotmaps/rendering/RenderContext.java +++ b/src/main/java/com/github/johnnyjayjay/spigotmaps/rendering/RenderContext.java @@ -5,6 +5,8 @@ import org.bukkit.map.MapCanvas; import org.bukkit.map.MapView; +import java.util.Objects; + /** * A container class for every map rendering operation. It contains the subject * {@link MapView}, a {@link MapCanvas} as well as the {@link Player} the map is rendered for. @@ -60,4 +62,18 @@ public MapCanvas getCanvas() { public Player getPlayer() { return player; } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + RenderContext that = (RenderContext) o; + return mapView.getId() == that.mapView.getId() + && Objects.equals(player, that.player); + } + + @Override + public int hashCode() { + return Objects.hash(mapView.getId(), player); + } }