mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 22:15:45 +00:00
Event stuff
This commit is contained in:
1 parent
3506fc2fb8
commit
0c7b65d978
16 files changed
+181
-2
No files matched your search
@@ -2,6 +2,7 @@ package net.draycia.carbon.bukkit;
|
||||
|
||||
import io.papermc.lib.PaperLib;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.events.CarbonEventHandler;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
@@ -24,6 +25,7 @@ import static net.kyori.adventure.text.format.NamedTextColor.WHITE;
|
||||
|
||||
public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
private final Logger logger = LogManager.getLogger("CarbonChat");
|
||||
private final CarbonEventHandler eventHandler = new CarbonEventHandler();
|
||||
|
||||
private static final int BSTATS_PLUGIN_ID = 8720;
|
||||
|
||||
@@ -51,6 +53,12 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
return this.logger;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull CarbonEventHandler eventHandler() {
|
||||
// TODO: move to common
|
||||
return this.eventHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Component createComponent(final @NonNull UUID uuid) {
|
||||
final Player player = Bukkit.getPlayer(uuid); // This is temporary (it's not)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
package net.draycia.carbon.bukkit.listeners;
|
||||
|
||||
import io.papermc.paper.event.player.AsyncChatEvent;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class BukkitChatListener implements Listener {
|
||||
|
||||
@EventHandler
|
||||
public void onPlayerchat(final @NonNull AsyncChatEvent event) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
package net.draycia.carbon.bukkit.util;
|
||||
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.format.TextDecoration;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyFormat;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public final class ColorUtils {
|
||||
|
||||
private ColorUtils() {
|
||||
|
||||
}
|
||||
|
||||
public static @Nullable TextColor parseColor(@NonNull String input) {
|
||||
if (input.isEmpty()) {
|
||||
return NamedTextColor.WHITE;
|
||||
}
|
||||
|
||||
for (final NamedTextColor namedColor : NamedTextColor.NAMES.values()) {
|
||||
if (namedColor.toString().equalsIgnoreCase(input)) {
|
||||
return namedColor;
|
||||
}
|
||||
}
|
||||
|
||||
if (input.contains("&") || input.contains("§")) {
|
||||
input = input.replace("&", "§");
|
||||
|
||||
return LegacyComponentSerializer.legacySection().deserialize(input).color();
|
||||
}
|
||||
|
||||
return TextColor.fromCSSHexString(input);
|
||||
}
|
||||
|
||||
private static final @NonNull Pattern spigotLegacyRGB =
|
||||
Pattern.compile("[§&]x[§&]([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 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;
|
||||
|
||||
// Legacy RGB
|
||||
output = spigotLegacyRGB.matcher(output).replaceAll(hexReplacement);
|
||||
|
||||
// Alternate RGB, TAB (neznamy) && KiteBoard
|
||||
output = pluginRGB.matcher(output).replaceAll(hexReplacement);
|
||||
|
||||
// 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 (color != null) {
|
||||
output = output.replaceAll("[§&]" + c, "<" + color.asHexString() + ">");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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 (decoration != null) {
|
||||
output = output.replaceAll("[§&]" + c, "<" + decoration.name() + ">");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user