Make ChatChannel an interface

This commit is contained in:
Draycia committed 2020-09-25 01:43:17 -07:00
1 parent b33ca93e94
commit 508ad88e26
2 files changed
+36 -62

No files matched your search

@@ -12,14 +12,13 @@ import java.util.Collection;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public abstract class ChatChannel implements ForwardingAudience { public interface ChatChannel extends ForwardingAudience {
/** /**
* Gets a list of {@link ChatUser}s to send channel messages to. * Gets a list of {@link ChatUser}s to send channel messages to.
* @return All {@link ChatUser}s that can see messages in this channel. * @return All {@link ChatUser}s that can see messages in this channel.
*/ */
@NonNull @NonNull List<ChatUser> audiences();
public abstract List<ChatUser> audiences();
/** /**
* Gets the {@link TextColor} the supplied {@link ChatUser} has set for this channel. * Gets the {@link TextColor} the supplied {@link ChatUser} has set for this channel.
@@ -27,111 +26,86 @@ public abstract class ChatChannel implements ForwardingAudience {
* @param user The user that may have a color set. * @param user The user that may have a color set.
* @return The color the user may have set, otherwise the channel's color. * @return The color the user may have set, otherwise the channel's color.
*/ */
@Nullable @Nullable TextColor channelColor(@NonNull ChatUser user);
public abstract TextColor channelColor(@NonNull ChatUser user);
/** /**
* Gets the string format for the specified group. * Gets the string format for the specified group.
* @param group The group. * @param group The group.
* @return The string format for the specified group. * @return The string format for the specified group.
*/ */
@Nullable @Nullable String format(@NonNull String group);
public abstract String format(@NonNull String group);
/** /**
* If this channel is the channel players get when they join for the first time. * If this channel is the channel players get when they join for the first time.
* Also the fallback channel in case the code is unable to find any given channel. * Also the fallback channel in case the code is unable to find any given channel.
* @return If this is the default channel. * @return If this is the default channel.
*/ */
public abstract boolean isDefault(); boolean isDefault();
/** /**
* If this channel can be ignored, such as through the /toggle command. * If this channel can be ignored, such as through the /toggle command.
* @return IF this channel can be ignored / toggled. * @return IF this channel can be ignored / toggled.
*/ */
public abstract boolean ignorable(); boolean ignorable();
/** /**
* If this channel syncs between servers, typically through the messaging service. * If this channel syncs between servers, typically through the messaging service.
* @return If this channel syncs between servers, typically through the messaging service. * @return If this channel syncs between servers, typically through the messaging service.
*/ */
public abstract boolean crossServer(); boolean crossServer();
@NonNull @NonNull String name();
public abstract String name();
@NonNull @NonNull String key();
public abstract String key();
@Nullable @Nullable String messagePrefix();
public abstract String messagePrefix();
@Nullable @Nullable String aliases();
public abstract String aliases();
@Nullable @Nullable String switchMessage();
public abstract String switchMessage();
@Nullable @Nullable String switchOtherMessage();
public abstract String switchOtherMessage();
@Nullable @Nullable String switchFailureMessage();
public abstract String switchFailureMessage();
@Nullable @Nullable String cannotIgnoreMessage();
public abstract String cannotIgnoreMessage();
@Nullable @Nullable String toggleOffMessage();
public abstract String toggleOffMessage();
@Nullable @Nullable String toggleOnMessage();
public abstract String toggleOnMessage();
@Nullable @Nullable String toggleOtherOnMessage();
public abstract String toggleOtherOnMessage();
@Nullable @Nullable String toggleOtherOffMessage();
public abstract String toggleOtherOffMessage();
@Nullable @Nullable String cannotUseMessage();
public abstract String cannotUseMessage();
public abstract boolean primaryGroupOnly(); boolean primaryGroupOnly();
public abstract boolean honorsRecipientList(); boolean honorsRecipientList();
public abstract boolean permissionGroupMatching(); boolean permissionGroupMatching();
public abstract boolean shouldCancelChatEvent(); boolean shouldCancelChatEvent();
public abstract boolean testContext(@NonNull ChatUser sender, @NonNull ChatUser target); boolean testContext(@NonNull ChatUser sender, @NonNull ChatUser target);
@NonNull @NonNull List<@NonNull Pattern> itemLinkPatterns();
public abstract List<@NonNull Pattern> itemLinkPatterns();
@Nullable @Nullable Context context(@NonNull String key);
public abstract Context context(@NonNull String key);
@NonNull @NonNull List<@NonNull String> groupOverrides();
public abstract List<@NonNull String> groupOverrides();
public abstract boolean canPlayerUse(@NonNull ChatUser user); boolean canPlayerUse(@NonNull ChatUser user);
public abstract boolean canPlayerSee(@NonNull ChatUser sender, @NonNull ChatUser target, boolean checkSpying); boolean canPlayerSee(@NonNull ChatUser sender, @NonNull ChatUser target, boolean checkSpying);
public abstract boolean canPlayerSee(@NonNull ChatUser target, boolean checkSpying); boolean canPlayerSee(@NonNull ChatUser target, boolean checkSpying);
@NonNull @NonNull Component sendMessage(@NonNull ChatUser user, @NonNull String message, boolean fromBungee);
public abstract Component sendMessage(@NonNull ChatUser user, @NonNull String message, boolean fromBungee);
@NonNull @NonNull Component sendMessage(@NonNull ChatUser user, @NonNull Collection<@NonNull ChatUser> recipients, @NonNull String message, boolean fromBungee);
public abstract Component sendMessage(@NonNull ChatUser user, @NonNull Collection<@NonNull ChatUser> recipients, @NonNull String message, boolean fromBungee);
public abstract void sendComponent(@NonNull ChatUser user, @NonNull Component component); void sendComponent(@NonNull ChatUser user, @NonNull Component component);
@Nullable
public String processPlaceholders(@NonNull final ChatUser user, @Nullable final String input) {
return input;
}
} }
@@ -29,7 +29,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
public class CarbonChatChannel extends ChatChannel { public class CarbonChatChannel implements ChatChannel {
@NonNull @NonNull
private final String key; private final String key;
@@ -164,7 +164,7 @@ public class CarbonChatChannel extends ChatChannel {
"message", formatEvent.message()); "message", formatEvent.message());
if (this.isUserSpying(user, target)) { if (this.isUserSpying(user, target)) {
final String prefix = this.processPlaceholders(user, this.carbonChat.getConfig().getString("spy-prefix")); final String prefix = this.carbonChat.getConfig().getString("spy-prefix");
formatComponent = (TextComponent) MiniMessage.get().parse(prefix, "color", formatComponent = (TextComponent) MiniMessage.get().parse(prefix, "color",
targetColor.asHexString()).append(formatComponent); targetColor.asHexString()).append(formatComponent);