Tidy up Node add/remove/clear API events

This commit is contained in:
Luck committed 2021-01-02 21:16:45 +00:00
1 parent a8b1dc8c07
commit 0a99a96188
6 files changed
+114 -67

No files matched your search

@@ -30,6 +30,10 @@ import net.luckperms.api.node.Node;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* Called when a node is added to a holder
*/
@@ -40,7 +44,14 @@ public interface NodeAddEvent extends NodeMutateEvent {
*
* @return the node that was added
*/
@Param(4)
@Param(3)
@NonNull Node getNode();
@Override
default @NonNull Set<Node> getDataBefore() {
// Get data after, then reverse the action
Set<Node> nodes = new HashSet<>(this.getDataAfter());
nodes.remove(this.getNode());
return Collections.unmodifiableSet(nodes);
}
}
@@ -25,9 +25,34 @@
package net.luckperms.api.event.node;
import net.luckperms.api.event.util.Param;
import net.luckperms.api.node.Node;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* Called when a holder has their nodes cleared
*/
public interface NodeClearEvent extends NodeMutateEvent {
/**
* Gets the nodes that were cleared
*
* @return the nodes that were removed
* @since 5.3
*/
@Param(3)
@NonNull Set<Node> getNodes();
@Override
default @NonNull Set<Node> getDataBefore() {
// Get data after, then reverse the action
Set<Node> nodes = new HashSet<>(this.getDataAfter());
nodes.addAll(this.getNodes());
return Collections.unmodifiableSet(nodes);
}
}
@@ -63,7 +63,6 @@ public interface NodeMutateEvent extends LuckPermsEvent {
*
* @return the data before the change
*/
@Param(2)
@NonNull Set<Node> getDataBefore();
/**
@@ -71,7 +70,7 @@ public interface NodeMutateEvent extends LuckPermsEvent {
*
* @return the data after the change
*/
@Param(3)
@Param(2)
@NonNull Set<Node> getDataAfter();
/**
@@ -30,6 +30,10 @@ import net.luckperms.api.node.Node;
import org.checkerframework.checker.nullness.qual.NonNull;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
/**
* Called when a node is removed from a holder
*/
@@ -40,7 +44,15 @@ public interface NodeRemoveEvent extends NodeMutateEvent {
*
* @return the node that was removed
*/
@Param(4)
@Param(3)
@NonNull Node getNode();
@Override
default @NonNull Set<Node> getDataBefore() {
// Get data after, then reverse the action
Set<Node> nodes = new HashSet<>(this.getDataAfter());
nodes.add(this.getNode());
return Collections.unmodifiableSet(nodes);
}
}