Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,12 @@ public boolean checkMatch(String value) {
if (!hasValidRegex()) {
return false;
}
String text = ChatTextFormatter.removeColor(String.valueOf(value)).toLowerCase();
String text = ChatTextFormatter.removeColor(String.valueOf(value));
if (text == null) {
return false;
}
try {
return regexPattern.matcher(text).find();
return regexPattern.matcher(text.toLowerCase()).find();
} catch (PatternSyntaxException ignored) {
Logging.warning("Error parsing regex '%s' for input '%s'", regexString, text);
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ void asyncPlayerChat(AsyncPlayerChatEvent event) {
String prefixChatFormat = config.getPrefixChatFormat();
prefixChatFormat = prefixChatFormat.replace("%world%", worldName).replace("%chat%", chat);
prefixChatFormat = ChatTextFormatter.colorize(prefixChatFormat);

event.setFormat(prefixChatFormat);
if (prefixChatFormat != null) {
event.setFormat(prefixChatFormat);
}
}

private String getWorldName(Player player) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,45 @@
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
import net.kyori.adventure.text.serializer.plain.PlainTextComponentSerializer;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

final class AdventureTextFormatter implements TextFormatter {
@Override
public void sendFormattedMessage(CommandSender sender, String message) {
sender.sendMessage(colorize(message));
public void sendFormattedMessage(@NotNull CommandSender sender, @Nullable String message) {
String colorizedMessage = colorize(message);
if (colorizedMessage == null) {
return; // Avoid sending null messages

Check warning on line 15 in src/main/java/org/mvplugins/multiverse/core/utils/text/AdventureTextFormatter.java

View workflow job for this annotation

GitHub Actions / checkstyle / checkstyle

[checkstyle] reported by reviewdog 🐶 Don't use trailing comments. Raw Output: /github/workspace/./src/main/java/org/mvplugins/multiverse/core/utils/text/AdventureTextFormatter.java:15:21: warning: Don't use trailing comments. (com.puppycrawl.tools.checkstyle.checks.TrailingCommentCheck)
}
sender.sendMessage(colorizedMessage);
}

@Override
public String removeColor(String message) {
TextComponent sectionComponent = LegacyComponentSerializer.legacySection().deserialize(colorize(message));
return PlainTextComponentSerializer.plainText().serialize(sectionComponent);
public @Nullable String removeColor(@Nullable String message) {
TextComponent sectionComponent = LegacyComponentSerializer.legacySection().deserializeOrNull(colorize(message));
return PlainTextComponentSerializer.plainText().serializeOrNull(sectionComponent);
}

public String removeAmpColor(String message) {
return PlainTextComponentSerializer.plainText().serialize(toAmpComponent(message));
@Override
public @Nullable String removeAmpColor(@Nullable String message) {
return PlainTextComponentSerializer.plainText().serializeOrNull(toAmpComponent(message));
}

public String removeSectionColor(String message) {
return PlainTextComponentSerializer.plainText().serialize(toSectionComponent(message));
@Override
public @Nullable String removeSectionColor(@Nullable String message) {
return PlainTextComponentSerializer.plainText().serializeOrNull(toSectionComponent(message));
}

@Override
public String colorize(String message) {
return LegacyComponentSerializer.legacySection().serialize(toAmpComponent(message));
public @Nullable String colorize(@Nullable String message) {
return LegacyComponentSerializer.legacySection().serializeOrNull(toAmpComponent(message));
}

private TextComponent toAmpComponent(String message) {
return LegacyComponentSerializer.legacyAmpersand().deserialize(message);
private @Nullable TextComponent toAmpComponent(@Nullable String message) {
return LegacyComponentSerializer.legacyAmpersand().deserializeOrNull(message);
}

private TextComponent toSectionComponent(String message) {
return LegacyComponentSerializer.legacySection().deserialize(message);
private @Nullable TextComponent toSectionComponent(@Nullable String message) {
return LegacyComponentSerializer.legacySection().deserializeOrNull(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,36 @@

import org.bukkit.ChatColor;
import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

@SuppressWarnings("deprecation")
final class ChatColorTextFormatter implements TextFormatter {
@Override
public void sendFormattedMessage(CommandSender sender, String message) {
public void sendFormattedMessage(@NotNull CommandSender sender, String message) {
sender.sendMessage(colorize(message));
}

@Override
public String removeColor(String message) {
public @Nullable String removeColor(@Nullable String message) {
return ChatColor.stripColor(colorize(message));
}

@Override
public String removeAmpColor(String message) {
public @Nullable String removeAmpColor(@Nullable String message) {
return removeColor(message);
}

@Override
public String removeSectionColor(String message) {
public @Nullable String removeSectionColor(@Nullable String message) {
return ChatColor.stripColor(message);
}

@Override
public String colorize(String message) {
public @Nullable String colorize(@Nullable String message) {
if (message == null) {
return null;
}
return ChatColor.translateAlternateColorCodes('&', message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.mvplugins.multiverse.core.utils.ReflectHelper;

/**
Expand Down Expand Up @@ -32,7 +34,7 @@ public final class ChatTextFormatter {
* @since 5.1
*/
@ApiStatus.AvailableSince("5.1")
public static void sendFormattedMessage(CommandSender sender, String message) {
public static void sendFormattedMessage(@NotNull CommandSender sender, @Nullable String message) {
wrapper.sendFormattedMessage(sender, message);
}

Expand All @@ -44,7 +46,7 @@ public static void sendFormattedMessage(CommandSender sender, String message) {
*
* @since 5.1
*/
public static String removeColor(String message) {
public static @Nullable String removeColor(@Nullable String message) {
return wrapper.removeColor(message);
}

Expand All @@ -57,7 +59,7 @@ public static String removeColor(String message) {
* @since 5.1
*/
@ApiStatus.AvailableSince("5.1")
public static String removeAmpColor(String message) {
public static @Nullable String removeAmpColor(@Nullable String message) {
return wrapper.removeAmpColor(message);
}

Expand All @@ -70,7 +72,7 @@ public static String removeAmpColor(String message) {
* @since 5.1
*/
@ApiStatus.AvailableSince("5.1")
public static String removeSectionColor(String message) {
public static @Nullable String removeSectionColor(@Nullable String message) {
return wrapper.removeSectionColor(message);
}

Expand All @@ -83,7 +85,7 @@ public static String removeSectionColor(String message) {
* @since 5.1
*/
@ApiStatus.AvailableSince("5.1")
public static String colorize(String message) {
public static @Nullable String colorize(@Nullable String message) {
return wrapper.colorize(message);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
package org.mvplugins.multiverse.core.utils.text;

import org.bukkit.command.CommandSender;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

interface TextFormatter {
void sendFormattedMessage(CommandSender sender, String message);
void sendFormattedMessage(@NotNull CommandSender sender, @Nullable String message);

String removeColor(String message);
@Nullable String removeColor(@Nullable String message);

String removeAmpColor(String message);
@Nullable String removeAmpColor(@Nullable String message);

String removeSectionColor(String message);
@Nullable String removeSectionColor(@Nullable String message);

String colorize(String message);
@Nullable String colorize(@Nullable String message);
}
Original file line number Diff line number Diff line change
Expand Up @@ -957,6 +957,9 @@ public Option<MultiverseWorld> getUnloadedWorldByNameOrAlias(@Nullable String wo
}

private Option<MultiverseWorld> getUnloadedWorldByAlias(@Nullable String alias) {
if (alias == null || alias.isEmpty()) {
return Option.none();
}
String colourlessAlias = ChatTextFormatter.removeColor(alias);
return Option.ofOptional(worldsMap.values().stream()
.filter(world -> !world.isLoaded())
Expand Down Expand Up @@ -1027,6 +1030,9 @@ public Option<LoadedMultiverseWorld> getLoadedWorldByNameOrAlias(@Nullable Strin
}

private Option<LoadedMultiverseWorld> getLoadedWorldByAlias(@Nullable String alias) {
if (alias == null || alias.isEmpty()) {
return Option.none();
}
return Option.ofOptional(loadedWorldsMap.values().stream()
.filter(world -> world.getColourlessAlias()
.equalsIgnoreCase(ChatTextFormatter.removeColor(alias)))
Expand Down