✨ Allow triggering states from anywhere
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 10 Feb 2024 08:16:05 +0000 (09:16 +0100)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Sat, 10 Feb 2024 08:16:05 +0000 (09:16 +0100)
src/main/java/net/pterodactylus/rhynodge/State.java
src/main/java/net/pterodactylus/rhynodge/states/AbstractState.java

index 2a8ba1c..966dbe3 100644 (file)
@@ -55,9 +55,12 @@ public interface State {
         * @return {@code true} if this state triggers a change notification,
         * {@code false} otherwise
         */
-       default boolean triggered() {
-               return false;
-       }
+       boolean triggered();
+
+       /**
+        * Sets whether this state will trigger a notification.
+        */
+       void trigger();
 
        boolean isEmpty();
 
index f3b37e5..ecd520f 100644 (file)
@@ -49,6 +49,7 @@ public abstract class AbstractState implements State {
        @JsonProperty
        private final boolean success;
        private final boolean empty;
+       private boolean triggered = false;
 
        /** The optional exception that occured while retrieving the state. */
        private final Throwable exception;
@@ -167,6 +168,16 @@ public abstract class AbstractState implements State {
                return empty;
        }
 
+       @Override
+       public boolean triggered() {
+               return triggered;
+       }
+
+       @Override
+       public void trigger() {
+               triggered = true;
+       }
+
        /**
         * {@inheritDoc}
         */