mirror of
https://github.com/Multiverse/Multiverse-Core.git
synced 2026-11-04 16:50:03 -05:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9926041c2f | ||
|
|
1c99898d0d | ||
|
|
41e0261eee | ||
|
|
642f3ab1b8 | ||
|
|
57d1844756 | ||
|
|
73e1650fc3 | ||
|
|
800709ca95 | ||
|
|
935cbad21c | ||
|
|
0e2a27b298 | ||
|
|
baaa175423 | ||
|
|
e2b7a31191 |
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());
|
||||
|
||||
+13
-3
@@ -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);
|
||||
});
|
||||
}));
|
||||
|
||||
Reference in new issue
Block a user