Commits

DerFrZocker authored and md_5 committed 0a7bd6c81a3
#1493: Improve reroute performance and add some tests
No tags

src/main/java/org/bukkit/craftbukkit/legacy/reroute/RequirePluginVersionData.java

Modified
1 1 package org.bukkit.craftbukkit.legacy.reroute;
2 2
3 3 import org.bukkit.craftbukkit.util.ApiVersion;
4 4
5 5 public record RequirePluginVersionData(ApiVersion minInclusive, ApiVersion maxInclusive) {
6 6
7 7 public static RequirePluginVersionData create(RequirePluginVersion requirePluginVersion) {
8 8 if (!requirePluginVersion.value().isBlank()) {
9 9 if (!requirePluginVersion.minInclusive().isBlank() || !requirePluginVersion.maxInclusive().isBlank()) {
10 - throw new RuntimeException("When setting value, min inclusive and max inclusive data is not allowed.");
10 + throw new IllegalArgumentException("When setting value, min inclusive and max inclusive data is not allowed.");
11 11 }
12 12
13 13 return new RequirePluginVersionData(ApiVersion.getOrCreateVersion(requirePluginVersion.value()), ApiVersion.getOrCreateVersion(requirePluginVersion.value()));
14 14 }
15 15
16 16 ApiVersion minInclusive = null;
17 17 ApiVersion maxInclusive = null;
18 18
19 19 if (!requirePluginVersion.minInclusive().isBlank()) {
20 20 minInclusive = ApiVersion.getOrCreateVersion(requirePluginVersion.minInclusive());
21 21 }
22 22 if (!requirePluginVersion.maxInclusive().isBlank()) {
23 23 maxInclusive = ApiVersion.getOrCreateVersion(requirePluginVersion.maxInclusive());
24 24 }
25 25
26 + if (minInclusive != null && maxInclusive != null) {
27 + if (minInclusive.isNewerThan(maxInclusive)) {
28 + throw new IllegalArgumentException("Min inclusive cannot be newer than max inclusive.");
29 + }
30 + }
31 +
26 32 return new RequirePluginVersionData(minInclusive, maxInclusive);
27 33 }
28 34
29 35 public boolean test(ApiVersion pluginVersion) {
30 36 if (minInclusive != null && pluginVersion.isOlderThan(minInclusive)) {
31 37 return false;
32 38 }
33 39
34 40 if (maxInclusive != null && pluginVersion.isNewerThan(maxInclusive)) {
35 41 return false;

Everything looks good. We'll let you know here if there's anything you should know about.

Add shortcut