Compare commits

...
11 Commits
Author SHA1 Message Date
Ben Woo 9926041c2f Merge pull request #3321 from KioProject123/fix/spawn-location-angle
fix spawn location angle
2025-08-18 15:06:10 +08:00
KioProject 1c99898d0d fix 2025-08-18 13:49:01 +08:00
KioProject 41e0261eee fix spawn location angle 2025-08-18 13:13:25 +08:00
Ben Woo 642f3ab1b8 Merge pull request #3320 from MrXiaoM/patch-1
Fix adventure dep in spigot-based server
2025-08-17 22:57:20 +08:00
人間工作 57d1844756 fix NoClassDefFoundError in spigot-based server 2025-08-17 22:09:17 +08:00
Ben Woo 73e1650fc3 Merge pull request #3318 from Multiverse/fix/match-invalid-regex
Properly handle error from invalid regex string in matcher
2025-08-11 13:08:49 +08:00
Ben Woo 800709ca95 Properly annotate parameters for matcher classes 2025-08-11 12:43:38 +08:00
Ben Woo 935cbad21c Properly handle error from invalid wildcard string in matcher 2025-08-11 12:40:05 +08:00
Ben Woo 0e2a27b298 Merge pull request #3317 from Multiverse/fix/remove-logging
Fix unwanted warning logging for matcher
2025-08-11 12:28:59 +08:00
Ben Woo baaa175423 Properly handle error from invalid regex string in matcher 2025-08-11 12:24:36 +08:00
Ben Woo e2b7a31191 Fix unwanted warning logging for matcher 2025-08-11 12:15:16 +08:00
7 changed files with 54 additions and 23 deletions

No files matched your search

@@ -1,6 +1,8 @@
package org.mvplugins.multiverse.core.utils.matcher;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.Collection;
import java.util.HashSet;
@@ -34,7 +36,7 @@ public class ExactStringMatcher implements StringMatcher {
* @since 5.2
*/
@ApiStatus.AvailableSince("5.2")
public ExactStringMatcher(String exactMatch) {
public ExactStringMatcher(@NotNull String exactMatch) {
this.exactMatches = new HashSet<>();
this.exactMatches.add(exactMatch);
}
@@ -47,7 +49,7 @@ public class ExactStringMatcher implements StringMatcher {
* @since 5.2
*/
@ApiStatus.AvailableSince("5.2")
public ExactStringMatcher(Collection<String> exactMatches) {
public ExactStringMatcher(@NotNull Collection<String> exactMatches) {
this.exactMatches = new HashSet<>(exactMatches);
}
@@ -59,7 +61,7 @@ public class ExactStringMatcher implements StringMatcher {
* @since 5.2
*/
@ApiStatus.AvailableSince("5.2")
public void addExactMatch(String value) {
public void addExactMatch(@NotNull String value) {
this.exactMatches.add(value);
}
@@ -67,7 +69,7 @@ public class ExactStringMatcher implements StringMatcher {
* {@inheritDoc}
*/
@Override
public boolean matches(String value) {
public boolean matches(@Nullable String value) {
return exactMatches.contains(value);
}
}
@@ -2,6 +2,8 @@ package org.mvplugins.multiverse.core.utils.matcher;
import com.dumptruckman.minecraft.util.Logging;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.ArrayList;
import java.util.Collection;
@@ -38,7 +40,7 @@ public class MatcherGroup implements StringMatcher {
* @since 5.2
*/
@ApiStatus.AvailableSince("5.2")
public MatcherGroup(Collection<String> matchStrings) {
public MatcherGroup(@NotNull Collection<String> matchStrings) {
this();
for (String matchString : matchStrings) {
addMatcher(matchString);
@@ -53,16 +55,18 @@ public class MatcherGroup implements StringMatcher {
* @since 5.2
*/
@ApiStatus.AvailableSince("5.2")
public void addMatcher(String matchString) {
public void addMatcher(@Nullable String matchString) {
if (matchString == null || matchString.isEmpty()) {
return;
}
if (isExact(matchString)) {
Logging.warning("Exact: " + matchString);
exactMatcher.addExactMatch(matchString);
} else {
stringMatchers.add(StringMatcher.fromString(matchString));
}
}
private boolean isExact(String matcherString) {
private boolean isExact(@NotNull String matcherString) {
return !matcherString.contains("*") && !matcherString.startsWith("r=");
}
@@ -74,7 +78,7 @@ public class MatcherGroup implements StringMatcher {
* @since 5.2
*/
@ApiStatus.AvailableSince("5.2")
public void addMatcher(StringMatcher matcher) {
public void addMatcher(@NotNull StringMatcher matcher) {
stringMatchers.add(matcher);
}
@@ -82,7 +86,7 @@ public class MatcherGroup implements StringMatcher {
* {@inheritDoc}
*/
@Override
public boolean matches(String value) {
public boolean matches(@Nullable String value) {
if (exactMatcher.matches(value)) {
return true;
}
@@ -1,6 +1,10 @@
package org.mvplugins.multiverse.core.utils.matcher;
import com.dumptruckman.minecraft.util.Logging;
import io.vavr.control.Try;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.regex.Pattern;
@@ -12,8 +16,8 @@ import java.util.regex.Pattern;
*/
@ApiStatus.AvailableSince("5.2")
public class RegexStringMatcher implements StringMatcher {
private final String regexString;
private final Pattern regexPattern;
private final @NotNull String regexString;
private final @Nullable Pattern regexPattern;
/**
* Creates a new RegexStringMatcher with a regex string. 'r=' prefix will be stripped if present.
@@ -23,7 +27,7 @@ public class RegexStringMatcher implements StringMatcher {
* @since 5.2
*/
@ApiStatus.AvailableSince("5.2")
public RegexStringMatcher(String regexString) {
public RegexStringMatcher(@NotNull String regexString) {
this.regexString = regexString;
this.regexPattern = compileRegex(regexString);
}
@@ -32,14 +36,22 @@ public class RegexStringMatcher implements StringMatcher {
if (regexString.startsWith("r=")) {
regexString = regexString.substring(2);
}
return Pattern.compile(regexString);
String finalRegexString = regexString;
return Try.of(() -> Pattern.compile(finalRegexString))
.onFailure(ex -> Logging.warning("Failed to compile regex '%s': %s",
finalRegexString, ex.getMessage()))
.getOrNull();
}
/**
* {@inheritDoc}
*/
@Override
public boolean matches(String value) {
public boolean matches(@Nullable String value) {
if (regexPattern == null || value == null) {
return false;
}
return regexPattern.matcher(value).matches();
}
}
@@ -1,6 +1,8 @@
package org.mvplugins.multiverse.core.utils.matcher;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.List;
import java.util.stream.Collectors;
@@ -26,7 +28,7 @@ public interface StringMatcher {
* @since 5.2
*/
@ApiStatus.AvailableSince("5.2")
static StringMatcher fromString(String matcherString) {
static @NotNull StringMatcher fromString(@NotNull String matcherString) {
if (matcherString.startsWith("r=")) {
return new RegexStringMatcher(matcherString);
} else if (matcherString.contains("*")) {
@@ -45,7 +47,7 @@ public interface StringMatcher {
* @since 5.2
*/
@ApiStatus.AvailableSince("5.2")
boolean matches(String value);
boolean matches(@Nullable String value);
/**
* Filters a list of strings, returning only those that match the pattern defined by this StringMatcher.
@@ -57,7 +59,7 @@ public interface StringMatcher {
* @since 5.2
*/
@ApiStatus.AvailableSince("5.2")
default List<String> filter(List<String> values) {
default @NotNull List<String> filter(@NotNull List<String> values) {
return values.stream()
.filter(this::matches)
.collect(Collectors.toList());
@@ -1,6 +1,10 @@
package org.mvplugins.multiverse.core.utils.matcher;
import com.dumptruckman.minecraft.util.Logging;
import io.vavr.control.Try;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.regex.Pattern;
@@ -25,16 +29,22 @@ public class WildcardStringMatcher implements StringMatcher {
* @param wildcard the wildcard string to match against.
*/
@ApiStatus.AvailableSince("5.2")
public WildcardStringMatcher(String wildcard) {
public WildcardStringMatcher(@NotNull String wildcard) {
this.wildcard = wildcard;
this.pattern = Pattern.compile(("\\Q" + wildcard + "\\E").replace("*", "\\E.*\\Q"));
this.pattern = Try.of(() -> Pattern.compile(("\\Q" + wildcard + "\\E").replace("*", "\\E.*\\Q")))
.onFailure(ex -> Logging.warning("Failed to compile wildcard '%s': %s",
wildcard, ex.getMessage()))
.getOrNull();
}
/**
* {@inheritDoc}
*/
@Override
public boolean matches(String value) {
public boolean matches(@Nullable String value) {
if (pattern == null || value == null) {
return false;
}
return pattern.matcher(value).matches();
}
}
@@ -18,7 +18,8 @@ public final class ChatTextFormatter {
private static final TextFormatter wrapper;
static {
if (ReflectHelper.hasClass("net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer")) {
if (ReflectHelper.hasClass("net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer")
&& ReflectHelper.hasClass("net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer")) {
wrapper = new AdventureTextFormatter();
} else {
wrapper = new ChatColorTextFormatter();
@@ -238,7 +238,7 @@ final class WorldConfigNodes {
if (!(world instanceof LoadedMultiverseWorld loadedWorld)) return;
if (newValue == null || newValue instanceof NullSpawnLocation) return;
loadedWorld.getBukkitWorld().peek(bukkitWorld -> {
bukkitWorld.setSpawnLocation(newValue.getBlockX(), newValue.getBlockY(), newValue.getBlockZ());
bukkitWorld.setSpawnLocation(newValue);
newValue.setWorld(bukkitWorld);
});
}));