Skip to content

Commit bd883be

Browse files
committed
Use preconditions
1 parent 6c4621d commit bd883be

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/main/java/ch/njol/skript/classes/Changer.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package ch.njol.skript.classes;
22

3+
import com.google.common.base.Preconditions;
34
import org.bukkit.event.Event;
45
import org.jetbrains.annotations.NotNull;
56
import org.jetbrains.annotations.Nullable;
@@ -104,17 +105,18 @@ public static boolean acceptsChangeTypes(Class<?>[] validTypes, Class<?> @NotNul
104105
* Gets the types that can be added/removed via arithmetic for the given type.
105106
* This is used to determine accepted change types for add/remove when no changer is present.
106107
* @param type The type to get arithmetic change types for.
107-
* @param mode Whether to get addition or subtraction types.
108+
* @param mode Whether to get addition or subtraction types. Only {@link ChangeMode#ADD} and {@link ChangeMode#REMOVE} are supported.
108109
* @param filter A filter to apply to the available operations. Used for custom constraints on the operations, like
109110
* ensuring the return type matches the left type.
110111
* @return The types that can be added/removed via arithmetic for the given type and mode, after applying the filter.
111112
* @param <T> The type to get arithmetic change types for.
112113
*/
113114
public static <T> Class<?>[] getArithmeticChangeTypes(Class<T> type, ChangeMode mode, Predicate<OperationInfo<T, ? ,?>> filter) {
114-
List<OperationInfo<T, ?, ?>> opInfos = List.of();
115+
Preconditions.checkState(mode == ChangeMode.ADD || mode == ChangeMode.REMOVE, "Only ADD and REMOVE modes are supported for arithmetic change types");
116+
List<OperationInfo<T, ?, ?>> opInfos;
115117
if (mode == ChangeMode.ADD) {
116118
opInfos = Arithmetics.getOperations(Operator.ADDITION, type);
117-
} else if (mode == ChangeMode.REMOVE) {
119+
} else {
118120
opInfos = Arithmetics.getOperations(Operator.SUBTRACTION, type);
119121
}
120122
return opInfos.stream()

0 commit comments

Comments
 (0)