Hide Event lib from API

This commit is contained in:
Draycia committed 2023-07-08 15:55:17 -07:00
1 parent 43d2754018
commit 09054b7332
15 files changed
+213 -114

No files matched your search

@@ -24,9 +24,6 @@ import java.util.UUID;
import net.draycia.carbon.api.channels.ChannelRegistry;
import net.draycia.carbon.api.event.CarbonEventHandler;
import net.draycia.carbon.api.users.UserManager;
import net.kyori.adventure.audience.Audience;
import net.kyori.adventure.text.Component;
import net.kyori.moonshine.message.IMessageRenderer;
import org.apache.logging.log4j.Logger;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.framework.qual.DefaultQualifier;
@@ -98,12 +95,4 @@ public interface CarbonChat {
*/
ChannelRegistry channelRegistry();
/**
* The message renderer, tailored for the current platform.
*
* @return the message renderer
* @since 2.0.0
*/
<T extends Audience> IMessageRenderer<T, String, Component, Component> messageRenderer();
}
@@ -0,0 +1,28 @@
/*
* CarbonChat
*
* Copyright (c) 2023 Josua Parks (Vicarious)
* Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.draycia.carbon.api.event;
public interface Cancellable {
boolean cancelled();
void cancelled(final boolean cancelled);
}
@@ -19,9 +19,9 @@
*/
package net.draycia.carbon.api.event.events;
import com.seiama.event.Cancellable;
import java.util.List;
import net.draycia.carbon.api.channels.ChatChannel;
import net.draycia.carbon.api.event.Cancellable;
import net.draycia.carbon.api.event.CarbonEvent;
import net.draycia.carbon.api.users.CarbonPlayer;
import net.draycia.carbon.api.util.KeyedRenderer;
@@ -30,7 +30,6 @@ import net.kyori.adventure.chat.SignedMessage;
import net.kyori.adventure.text.Component;
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.NonNull;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.checkerframework.framework.qual.DefaultQualifier;
/**
@@ -39,44 +38,7 @@ import org.checkerframework.framework.qual.DefaultQualifier;
* @since 2.0.0
*/
@DefaultQualifier(NonNull.class)
public class CarbonChatEvent implements CarbonEvent, Cancellable {
private final List<KeyedRenderer> renderers;
private final CarbonPlayer sender;
private final Component originalMessage;
private final List<? extends Audience> recipients;
private final @MonotonicNonNull ChatChannel chatChannel;
private final @MonotonicNonNull SignedMessage signedMessage;
private Component message;
private boolean cancelled = false;
/**
* Event that's called when players send messages in chat.
*
* @param sender the sender of the message
* @param originalMessage the original message that was sent
* @param recipients the recipients of the message
* @param renderers the renderers of the message
* @param chatChannel the channel the message was sent in
* @param signedMessage the signature information for the message, if present
* @since 2.0.0
*/
public CarbonChatEvent(
final CarbonPlayer sender,
final Component originalMessage,
final List<? extends Audience> recipients,
final List<KeyedRenderer> renderers,
final @Nullable ChatChannel chatChannel,
final @Nullable SignedMessage signedMessage
) {
this.sender = sender;
this.originalMessage = originalMessage;
this.message = originalMessage;
this.recipients = recipients;
this.renderers = renderers;
this.chatChannel = chatChannel;
this.signedMessage = signedMessage;
}
public interface CarbonChatEvent extends CarbonEvent, Cancellable {
/**
* Get the renderers used to construct components for each of the recipients.
@@ -84,9 +46,7 @@ public class CarbonChatEvent implements CarbonEvent, Cancellable {
* @return The per-recipient component renderers.
* @since 2.0.0
*/
public List<KeyedRenderer> renderers() {
return this.renderers;
}
List<KeyedRenderer> renderers();
/**
* If the message is being previewed by the player.
@@ -94,9 +54,7 @@ public class CarbonChatEvent implements CarbonEvent, Cancellable {
* @return if the message is being previewed
* @since 2.1.0
*/
public @MonotonicNonNull SignedMessage signedMessage() {
return this.signedMessage;
}
@MonotonicNonNull SignedMessage signedMessage();
/**
* Get the sender of the message.
@@ -104,9 +62,7 @@ public class CarbonChatEvent implements CarbonEvent, Cancellable {
* @return The message sender.
* @since 2.0.0
*/
public CarbonPlayer sender() {
return this.sender;
}
CarbonPlayer sender();
/**
* Get the original message that was sent.
@@ -114,9 +70,7 @@ public class CarbonChatEvent implements CarbonEvent, Cancellable {
* @return The original message.
* @since 2.0.0
*/
public Component originalMessage() {
return this.originalMessage;
}
Component originalMessage();
/**
* Get the chat message that will be sent.
@@ -124,9 +78,7 @@ public class CarbonChatEvent implements CarbonEvent, Cancellable {
* @return The chat message.
* @since 2.0.0
*/
public Component message() {
return this.message;
}
Component message();
/**
* Set the chat message that will be sent.
@@ -134,9 +86,7 @@ public class CarbonChatEvent implements CarbonEvent, Cancellable {
* @param message new message
* @since 2.0.0
*/
public void message(final Component message) {
this.message = message;
}
void message(final Component message);
/**
* The chat channel the message was sent in.
@@ -144,9 +94,7 @@ public class CarbonChatEvent implements CarbonEvent, Cancellable {
* @return the chat channel
* @since 2.0.0
*/
public @MonotonicNonNull ChatChannel chatChannel() {
return this.chatChannel;
}
@MonotonicNonNull ChatChannel chatChannel();
/**
* The recipients of the message.
@@ -156,18 +104,6 @@ public class CarbonChatEvent implements CarbonEvent, Cancellable {
* entries may be players, console, or other audience implementations
* @since 2.0.0
*/
public List<? extends Audience> recipients() {
return this.recipients;
}
@Override
public boolean cancelled() {
return this.cancelled;
}
@Override
public void cancelled(final boolean cancelled) {
this.cancelled = cancelled;
}
List<? extends Audience> recipients();
}
@@ -1,123 +0,0 @@
/*
* CarbonChat
*
* Copyright (c) 2023 Josua Parks (Vicarious)
* Contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
package net.draycia.carbon.api.util;
import java.util.regex.Pattern;
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 org.checkerframework.framework.qual.DefaultQualifier;
/**
* Basic color related utilities.
*
* @since 1.0.0
*/
@DefaultQualifier(NonNull.class)
public final class ColorUtils {
private static final 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 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 String hexReplacement = "<#$1$2$3$4$5$6>";
private ColorUtils() {
}
/**
* Parses the input into a color.<br>
* Supports named colors, legacy, and hex inputs.
*
* @param input the color input
* @return the color
* @since 1.0.0
*/
public static @Nullable TextColor parseColor(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);
}
/**
* Converts the input legacy, legacy rgb, and alternate color formats to MiniMessage color tags.
*
* @param input the message to convert
* @return the converted message
* @since 1.0.0
*/
public static String legacyToMiniMessage(final 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 @Nullable LegacyFormat format = LegacyComponentSerializer.parseChar(Character.toLowerCase(c));
if (format != null) {
final @Nullable TextColor color = format.color();
if (color != null) {
output = output.replaceAll("[§&]" + c, "<" + color.asHexString() + ">");
}
}
}
// Legacy Formatting
for (final char c : "klmnoKLMNO".toCharArray()) {
final @Nullable LegacyFormat format = LegacyComponentSerializer.parseChar(Character.toLowerCase(c));
if (format != null) {
final @Nullable TextDecoration decoration = format.decoration();
if (decoration != null) {
output = output.replaceAll("[§&]" + c, "<" + decoration.name() + ">");
}
}
}
return output;
}
}