Drop MineDown & Mojangson

This commit is contained in:
Draycia committed 2021-05-07 03:50:45 -07:00
1 parent dc09504bd3
commit d7b3b01c2b
7 files changed
+20 -78

No files matched your search

@@ -1,8 +0,0 @@
package net.draycia.carbon.api.adventure;
public enum FormatType {
MOJANG,
MINIMESSAGE_MARKDOWN,
MINIMESSAGE,
MINEDOWN
}
@@ -11,6 +11,4 @@ public interface MessageProcessor {
@NonNull AudienceProvider audiences();
@NonNull FormatType formatType();
}
@@ -1,6 +1,5 @@
package net.draycia.carbon.api.config;
import net.draycia.carbon.api.adventure.FormatType;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.spongepowered.configurate.CommentedConfigurationNode;
@@ -64,10 +63,6 @@ public final class CarbonSettings {
" channel as well as this setting.")
private @NonNull MessagingType messagingType = MessagingType.NONE;
@Setting
@Comment("Options: MOJANG, MINIMESSAGE_MARKDOWN, MINIMESSAGE, MINEDOWN")
private @NonNull FormatType formatType = FormatType.MINIMESSAGE;
@Setting
@Comment("The credentials necessary to connect to your redis server")
private @NonNull RedisCredentials redisCredentials = new RedisCredentials();
@@ -136,8 +131,4 @@ public final class CarbonSettings {
public @NonNull WhisperOptions whisperOptions() {
return this.whisperOptions;
}
public @NonNull FormatType formatType() {
return this.formatType;
}
}
@@ -128,7 +128,7 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
// Setup Adventure
final BukkitAudiences audiences = BukkitAudiences.create(this);
this.messageProcessor = new AdventureManager(audiences, this.carbonSettings.formatType());
this.messageProcessor = new AdventureManager(audiences);
// Initialize managers
this.channelManager = new ChannelManager(this);
@@ -1,9 +1,7 @@
package net.draycia.carbon.common.adventure;
import de.themoep.minedown.adventure.MineDown;
import net.draycia.carbon.api.CarbonChat;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.adventure.FormatType;
import net.draycia.carbon.api.adventure.MessageProcessor;
import net.draycia.carbon.common.utils.ColorUtils;
import net.kyori.adventure.platform.AudienceProvider;
@@ -18,11 +16,8 @@ public class AdventureManager implements MessageProcessor {
private final @NonNull CarbonChat carbonChat;
private final @NonNull FormatType formatType;
public AdventureManager(final @NonNull AudienceProvider provider, final @NonNull FormatType formatType) {
public AdventureManager(final @NonNull AudienceProvider provider) {
this.provider = provider;
this.formatType = formatType;
this.carbonChat = CarbonChatProvider.carbonChat();
}
@@ -39,17 +34,7 @@ public class AdventureManager implements MessageProcessor {
format = this.processPlaceholders(format, placeholders);
switch (this.formatType) {
case MINEDOWN:
return MineDown.parse(format);
case MOJANG:
return this.processMojang(format);
case MINIMESSAGE_MARKDOWN:
return MiniMessage.markdown().parse(format);
case MINIMESSAGE:
default:
return MiniMessage.get().parse(format);
}
return MiniMessage.get().parse(format);
}
private @NonNull Component processMojang(final @NonNull String input) {
@@ -67,11 +52,6 @@ public class AdventureManager implements MessageProcessor {
return input;
}
@Override
public @NonNull FormatType formatType() {
return this.formatType;
}
@Override
public @NonNull AudienceProvider audiences() {
return this.provider;
@@ -1,11 +1,7 @@
package net.draycia.carbon.common.utils;
import net.draycia.carbon.api.CarbonChatProvider;
import net.draycia.carbon.api.adventure.MessageProcessor;
import net.draycia.carbon.api.users.CarbonUser;
import net.draycia.carbon.api.users.PlayerUser;
import net.draycia.carbon.common.adventure.AdventureManager;
import net.draycia.carbon.api.adventure.FormatType;
import net.kyori.adventure.text.format.NamedTextColor;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.format.TextDecoration;
@@ -56,51 +52,39 @@ public final class ColorUtils {
private static final @NonNull Pattern pluginRGB =
Pattern.compile("[§&]#([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])([0-9a-fA-F])");
private static final @NonNull String hexReplacement = "<#$1$2$3$4$5$6>";
public static @NonNull String translateAlternateColors(final @NonNull String input) {
String output = input;
String hexReplacement = "<#$1$2$3$4$5$6>";
boolean legacyCapable = false;
final MessageProcessor messageProcessor = CarbonChatProvider.carbonChat().messageProcessor();
if (messageProcessor instanceof AdventureManager) {
if (messageProcessor.formatType() == FormatType.MINEDOWN) {
hexReplacement = "&#$1$2$3$4$5$6&";
legacyCapable = true;
}
}
// Legacy RGB
output = spigotLegacyRGB.matcher(output).replaceAll(hexReplacement);
// Alternate RGB, TAB (neznamy) && KiteBoard
output = pluginRGB.matcher(output).replaceAll(hexReplacement);
if (!legacyCapable) {
// Legacy Colors
for (final char c : "0123456789abcdefABCDEF".toCharArray()) {
final LegacyFormat format = LegacyComponentSerializer.parseChar(Character.toLowerCase(c));
// Legacy Colors
for (final char c : "0123456789abcdefABCDEF".toCharArray()) {
final LegacyFormat format = LegacyComponentSerializer.parseChar(Character.toLowerCase(c));
if (format != null) {
final TextColor color = format.color();
if (format != null) {
final TextColor color = format.color();
if (color != null) {
output = output.replaceAll("[§&]" + c, "<" + color.asHexString() + ">");
}
if (color != null) {
output = output.replaceAll("[§&]" + c, "<" + color.asHexString() + ">");
}
}
}
// Legacy Formatting
for (final char c : "klmnoKLMNO".toCharArray()) {
final LegacyFormat format = LegacyComponentSerializer.parseChar(Character.toLowerCase(c));
// Legacy Formatting
for (final char c : "klmnoKLMNO".toCharArray()) {
final LegacyFormat format = LegacyComponentSerializer.parseChar(Character.toLowerCase(c));
if (format != null) {
final TextDecoration decoration = format.decoration();
if (format != null) {
final TextDecoration decoration = format.decoration();
if (decoration != null) {
output = output.replaceAll("[§&]" + c, "<" + decoration.name() + ">");
}
if (decoration != null) {
output = output.replaceAll("[§&]" + c, "<" + decoration.name() + ">");
}
}
}
@@ -21,9 +21,6 @@ channel-pings:
pitch: 1
source: PLAYER
volume: 10
# Options: MOJANG, MINIMESSAGE_MARKDOWN, MINIMESSAGE, MINEDOWN
format-type: MINIMESSAGE
# The list of regex patterns to show items in chat. '\\Q' and '\\E' just denote that the content isn't regex.
item-link-patterns: