diff --git a/core/src/main/java/tc/oc/pgm/core/CoreMatchModule.java b/core/src/main/java/tc/oc/pgm/core/CoreMatchModule.java index 9a10303fcd..27d6235f5c 100644 --- a/core/src/main/java/tc/oc/pgm/core/CoreMatchModule.java +++ b/core/src/main/java/tc/oc/pgm/core/CoreMatchModule.java @@ -42,6 +42,10 @@ public CoreMatchModule(Match match, List cores) { this.cores = cores; } + public List getCores() { + return this.cores; + } + @Override public void enable() { if (this.match.getMap().getProto().isOlderThan(MODES_IMPLEMENTATION_VERSION)) { @@ -151,11 +155,15 @@ public void lavaProtection(final BlockTransformEvent event) { } } - @EventHandler(priority = EventPriority.MONITOR) + @EventHandler(priority = EventPriority.HIGHEST) public void onObjectiveModeSwitch(final ObjectiveModeChangeEvent event) { for (Core core : this.cores) { if (core.getModes() == null || core.getModes().contains(event.getMode())) { core.replaceBlocks(event.getMode().getMaterialData()); + // if at least one of the cores are visible, the mode change message will be sent + if (core.isVisible()) { + event.setVisible(true); + } } } } diff --git a/core/src/main/java/tc/oc/pgm/destroyable/DestroyableMatchModule.java b/core/src/main/java/tc/oc/pgm/destroyable/DestroyableMatchModule.java index 67fa15cad1..5d133b0e36 100644 --- a/core/src/main/java/tc/oc/pgm/destroyable/DestroyableMatchModule.java +++ b/core/src/main/java/tc/oc/pgm/destroyable/DestroyableMatchModule.java @@ -119,12 +119,16 @@ public void processBlockDamage(BlockDamageEvent event) { } } - @EventHandler(priority = EventPriority.MONITOR) + @EventHandler(priority = EventPriority.HIGHEST) public void onObjectiveModeSwitch(final ObjectiveModeChangeEvent event) { for (Destroyable destroyable : this.destroyables) { if (destroyable.getModes() == null || destroyable.getModes().contains(event.getMode())) { double oldCompletion = destroyable.getCompletion(); destroyable.replaceBlocks(event.getMode().getMaterialData()); + // if at least one of the destroyables are visible, the mode change message will be sent + if (destroyable.isVisible()) { + event.setVisible(true); + } if (oldCompletion != destroyable.getCompletion()) { // Multi-stage destroyables can have their total completion changed by this this.match.callEvent(new DestroyableHealthChangeEvent(this.match, destroyable, null)); diff --git a/core/src/main/java/tc/oc/pgm/modes/ObjectiveModeChangeEvent.java b/core/src/main/java/tc/oc/pgm/modes/ObjectiveModeChangeEvent.java index d69f28b88e..7133058381 100644 --- a/core/src/main/java/tc/oc/pgm/modes/ObjectiveModeChangeEvent.java +++ b/core/src/main/java/tc/oc/pgm/modes/ObjectiveModeChangeEvent.java @@ -14,11 +14,13 @@ public class ObjectiveModeChangeEvent extends MatchEvent { private final Mode mode; private String name; + private boolean visible; private static final HandlerList handlers = new HandlerList(); public ObjectiveModeChangeEvent(Match match, final Mode mode) { super(match); this.mode = mode; + this.visible = false; if (this.mode.getName() != null) { this.name = this.mode.getName(); @@ -42,10 +44,18 @@ public ObjectiveModeChangeEvent(Match match, final Mode mode) { } } + public boolean isVisible() { + return this.visible; + } + public final Mode getMode() { return this.mode; } + public void setVisible(boolean visible) { + this.visible = visible; + } + public void setName(@Nonnull String name) { this.name = Preconditions.checkNotNull(name, "name"); } diff --git a/core/src/main/java/tc/oc/pgm/modes/ObjectiveModesMatchModule.java b/core/src/main/java/tc/oc/pgm/modes/ObjectiveModesMatchModule.java index c2b4234d85..a20e341236 100644 --- a/core/src/main/java/tc/oc/pgm/modes/ObjectiveModesMatchModule.java +++ b/core/src/main/java/tc/oc/pgm/modes/ObjectiveModesMatchModule.java @@ -128,13 +128,15 @@ public boolean apply(@Nullable ModeChangeCountdown countdown) { @EventHandler(priority = EventPriority.MONITOR, ignoreCancelled = true) public void onObjectiveModeChange(ObjectiveModeChangeEvent event) { - Component broadcast = - text() - .append(text("> > > > ", NamedTextColor.DARK_AQUA)) - .append(text(event.getName(), NamedTextColor.DARK_RED)) - .append(text(" < < < <", NamedTextColor.DARK_AQUA)) - .build(); - event.getMatch().sendMessage(broadcast); - event.getMatch().playSound(SOUND); + if (event.isVisible()) { + Component broadcast = + text() + .append(text("> > > > ", NamedTextColor.DARK_AQUA)) + .append(text(event.getName(), NamedTextColor.DARK_RED)) + .append(text(" < < < <", NamedTextColor.DARK_AQUA)) + .build(); + match.sendMessage(broadcast); + match.playSound(SOUND); + } } }