mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Add channel whisper functionality (#91)
* ChatChannel -> TextChannel, WhisperChannel, GroupChannel * Add basic whisper channel support * Move WhisperPings into WhisperOptions * Add defaults to WhisperOptions * Various deprecation and refactor fixes * Test and fux bugs
This commit is contained in:
1 parent
14dfcfbf38
commit
f9cac355b6
44 files changed
+797
-304
No files matched your search
@@ -9,8 +9,10 @@ dependencies {
|
||||
|
||||
compile 'net.kyori:adventure-api:4.0.0-SNAPSHOT'
|
||||
compile 'net.kyori:adventure-nbt:4.0.0-SNAPSHOT'
|
||||
compile 'net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT'
|
||||
compile 'net.kyori:adventure-platform-api:4.0.0-SNAPSHOT'
|
||||
compile 'net.kyori:adventure-text-serializer-plain:4.0.0-SNAPSHOT'
|
||||
compile 'net.kyori:adventure-text-serializer-gson:4.0.0-SNAPSHOT'
|
||||
compile 'net.kyori:adventure-text-serializer-legacy:4.0.0-SNAPSHOT'
|
||||
compile 'net.kyori:adventure-text-minimessage:4.0.0-SNAPSHOT'
|
||||
|
||||
compile 'de.themoep:minedown-adventure:1.6.1-SNAPSHOT'
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.draycia.carbon.api;
|
||||
|
||||
import net.draycia.carbon.api.adventure.CarbonTranslations;
|
||||
import net.draycia.carbon.api.config.CarbonTranslations;
|
||||
import net.draycia.carbon.api.adventure.MessageProcessor;
|
||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettingsRegistry;
|
||||
@@ -10,6 +10,7 @@ import net.draycia.carbon.api.config.ModerationSettings;
|
||||
import net.draycia.carbon.api.messaging.MessageService;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.users.UserService;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.slf4j.Logger;
|
||||
@@ -50,4 +51,6 @@ public interface CarbonChat {
|
||||
|
||||
@NonNull ModerationSettings moderationSettings();
|
||||
|
||||
@NonNull GsonComponentSerializer gsonSerializer();
|
||||
|
||||
}
|
||||
@@ -21,8 +21,10 @@ public class ChannelRegistry implements Registry<String, ChatChannel> {
|
||||
public @NonNull ChatChannel register(final @NonNull String key, final @NonNull ChatChannel value) {
|
||||
this.registry.putIfAbsent(key, value);
|
||||
|
||||
if (this.defaultChannel == null && value.isDefault()) {
|
||||
this.defaultChannel = value;
|
||||
if (value instanceof TextChannel) {
|
||||
if (this.defaultChannel == null && ((TextChannel) value).isDefault()) {
|
||||
this.defaultChannel = value;
|
||||
}
|
||||
}
|
||||
|
||||
return value;
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package net.draycia.carbon.api.channels;
|
||||
|
||||
import net.draycia.carbon.api.Context;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.luckperms.api.model.group.Group;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
@@ -14,13 +12,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public interface ChatChannel extends ForwardingAudience {
|
||||
|
||||
/**
|
||||
* Gets a list of {@link ChatUser}s to send channel messages to.
|
||||
* @return All {@link ChatUser}s that can see messages in this channel.
|
||||
*/
|
||||
@NonNull List<ChatUser> audiences();
|
||||
public interface ChatChannel extends Audience {
|
||||
|
||||
/**
|
||||
* Gets the {@link TextColor} the supplied {@link ChatUser} has set for this channel.
|
||||
@@ -30,28 +22,26 @@ public interface ChatChannel extends ForwardingAudience {
|
||||
*/
|
||||
@Nullable TextColor channelColor(@NonNull ChatUser user);
|
||||
|
||||
/**
|
||||
* Gets the string format for the specified group.
|
||||
* @param group The group.
|
||||
* @return The string format for the specified group.
|
||||
*/
|
||||
@Nullable String format(@NonNull Group group);
|
||||
@NonNull
|
||||
Map<ChatUser, Component> parseMessage(@NonNull ChatUser user, @NonNull String message, boolean fromRemote);
|
||||
|
||||
/**
|
||||
* Gets the string format for the specified group.
|
||||
* @param group The group.
|
||||
* @return The string format for the specified group.
|
||||
*/
|
||||
@Nullable String format(@NonNull String group);
|
||||
@NonNull
|
||||
Map<ChatUser, Component> parseMessage(@NonNull ChatUser user, @NonNull Collection<@NonNull ChatUser> recipients,
|
||||
@NonNull String message, boolean fromRemote);
|
||||
|
||||
boolean canPlayerUse(@NonNull ChatUser user);
|
||||
|
||||
boolean canPlayerSee(@NonNull ChatUser sender, @NonNull ChatUser target, boolean checkSpying);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @return If this is the default channel.
|
||||
*/
|
||||
boolean isDefault();
|
||||
boolean canPlayerSee(@NonNull ChatUser target, boolean checkSpying);
|
||||
|
||||
void sendComponents(final @NonNull Map<ChatUser, Component> components);
|
||||
|
||||
void sendComponentsAndLog(final @NonNull Map<ChatUser, Component> components);
|
||||
|
||||
@NonNull String name();
|
||||
|
||||
@NonNull String key();
|
||||
|
||||
/**
|
||||
* If this channel can be ignored, such as through the /toggle command.
|
||||
@@ -59,19 +49,7 @@ public interface ChatChannel extends ForwardingAudience {
|
||||
*/
|
||||
boolean ignorable();
|
||||
|
||||
/**
|
||||
* If this channel syncs between servers, typically through the messaging service.
|
||||
* @return If this channel syncs between servers, typically through the messaging service.
|
||||
*/
|
||||
boolean crossServer();
|
||||
|
||||
@NonNull String name();
|
||||
|
||||
@NonNull String key();
|
||||
|
||||
@Nullable String messagePrefix();
|
||||
|
||||
@Nullable List<String> aliases();
|
||||
@NonNull List<@NonNull Pattern> itemLinkPatterns();
|
||||
|
||||
@Nullable String switchMessage();
|
||||
|
||||
@@ -91,36 +69,4 @@ public interface ChatChannel extends ForwardingAudience {
|
||||
|
||||
@Nullable String cannotUseMessage();
|
||||
|
||||
boolean primaryGroupOnly();
|
||||
|
||||
boolean honorsRecipientList();
|
||||
|
||||
boolean permissionGroupMatching();
|
||||
|
||||
boolean shouldCancelChatEvent();
|
||||
|
||||
boolean testContext(@NonNull ChatUser sender, @NonNull ChatUser target);
|
||||
|
||||
@NonNull List<@NonNull Pattern> itemLinkPatterns();
|
||||
|
||||
@Nullable Context context(@NonNull String key);
|
||||
|
||||
@NonNull List<@NonNull String> groupOverrides();
|
||||
|
||||
boolean canPlayerUse(@NonNull ChatUser user);
|
||||
|
||||
boolean canPlayerSee(@NonNull ChatUser sender, @NonNull ChatUser target, boolean checkSpying);
|
||||
|
||||
boolean canPlayerSee(@NonNull ChatUser target, boolean checkSpying);
|
||||
|
||||
@NonNull Map<ChatUser, Component> parseMessage(@NonNull ChatUser user, @NonNull String message, boolean fromBungee);
|
||||
|
||||
@NonNull Map<ChatUser, Component> parseMessage(@NonNull ChatUser user, @NonNull Collection<@NonNull ChatUser> recipients, @NonNull String message, boolean fromBungee);
|
||||
|
||||
void sendComponents(final @NonNull Map<ChatUser, Component> components);
|
||||
|
||||
void sendComponentsAndLog(final @NonNull Map<ChatUser, Component> components);
|
||||
|
||||
void sendComponent(@NonNull ChatUser user, @NonNull Component component);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
package net.draycia.carbon.api.channels;
|
||||
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public interface GroupChannel extends ChatChannel, ForwardingAudience {
|
||||
|
||||
@NonNull ChatUser owner();
|
||||
|
||||
@Override
|
||||
@NonNull Collection<@NonNull ChatUser> audiences();
|
||||
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
package net.draycia.carbon.api.channels;
|
||||
|
||||
import net.draycia.carbon.api.Context;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.luckperms.api.model.group.Group;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
// TODO: rename this to something that's less... weird?
|
||||
public interface TextChannel extends ChatChannel, ForwardingAudience {
|
||||
|
||||
@Override
|
||||
@NonNull List<@NonNull ChatUser> audiences();
|
||||
|
||||
/**
|
||||
* Gets the string format for the specified group.
|
||||
* @param group The group.
|
||||
* @return The string format for the specified group.
|
||||
*/
|
||||
@Nullable String format(@NonNull Group group);
|
||||
|
||||
/**
|
||||
* Gets the string format for the specified group.
|
||||
* @param group The group.
|
||||
* @return The string format for the specified group.
|
||||
*/
|
||||
@Nullable String format(@NonNull String group);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @return If this is the default channel.
|
||||
*/
|
||||
boolean isDefault();
|
||||
|
||||
/**
|
||||
* If this channel syncs between servers, typically through the messaging service.
|
||||
* @return If this channel syncs between servers, typically through the messaging service.
|
||||
*/
|
||||
boolean crossServer();
|
||||
|
||||
@Nullable String messagePrefix();
|
||||
|
||||
@Nullable List<String> aliases();
|
||||
|
||||
boolean primaryGroupOnly();
|
||||
|
||||
boolean honorsRecipientList();
|
||||
|
||||
boolean permissionGroupMatching();
|
||||
|
||||
boolean testContext(@NonNull ChatUser sender, @NonNull ChatUser target);
|
||||
|
||||
@Nullable Context context(@NonNull String key);
|
||||
|
||||
@NonNull List<@NonNull String> groupOverrides();
|
||||
|
||||
void sendComponent(@NonNull ChatUser user, @NonNull Component component);
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package net.draycia.carbon.api.channels;
|
||||
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public interface WhisperChannel extends ChatChannel, ForwardingAudience.Single {
|
||||
|
||||
@NonNull ChatUser sender();
|
||||
|
||||
/**
|
||||
* The recipient for this channel, where messages are sent to.
|
||||
* @return The channel recipient.
|
||||
*/
|
||||
@Override
|
||||
@NonNull ChatUser audience();
|
||||
|
||||
@Override
|
||||
default @NonNull String name() {
|
||||
return "Party";
|
||||
}
|
||||
|
||||
@Override
|
||||
default @NonNull String key() {
|
||||
return "party";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -74,8 +74,8 @@ public class CarbonSettings {
|
||||
@Setting(comment = "Plays a sound and highlights the message when someone types your name")
|
||||
private @NonNull ChannelPings channelPings = new ChannelPings();
|
||||
|
||||
@Setting(comment = "Plays a sound when receiving private messages with /whisper /msg")
|
||||
private @NonNull WhisperPings whisperPings = new WhisperPings();
|
||||
@Setting(comment = "")
|
||||
private @NonNull WhisperOptions whisperOptions = new WhisperOptions();
|
||||
|
||||
@Setting(comment = "Sets the player's channel to the specified channel when they join" +
|
||||
"\nSet to \"\" or remove to disable" +
|
||||
@@ -132,8 +132,8 @@ public class CarbonSettings {
|
||||
return this.channelPings;
|
||||
}
|
||||
|
||||
public @NonNull WhisperPings whisperPings() {
|
||||
return this.whisperPings;
|
||||
public @NonNull WhisperOptions whisperOptions() {
|
||||
return this.whisperOptions;
|
||||
}
|
||||
|
||||
}
|
||||
+6
-11
@@ -1,4 +1,4 @@
|
||||
package net.draycia.carbon.api.adventure;
|
||||
package net.draycia.carbon.api.config;
|
||||
|
||||
import org.spongepowered.configurate.CommentedConfigurationNode;
|
||||
import org.spongepowered.configurate.objectmapping.ObjectMapper;
|
||||
@@ -28,8 +28,6 @@ public class CarbonTranslations {
|
||||
}
|
||||
|
||||
@Setting private String reloaded = "<yellow>Chat config has been reloaded!";
|
||||
@Setting private String messageToOther = "<green>[<gray>Me <gold>-> <gray><target><reset><green>] <message>";
|
||||
@Setting private String messageFromOther = "<green>[<gray><sender><reset> <gold>-> <gray>Me<green>] <message>";
|
||||
@Setting private String otherPlayerOffline = "<red>That player is offline!";
|
||||
@Setting private String spyWhispers = "<yellow>Spy [<gray><sender><reset> <gold>-> <gray><target><reset><yellow>] <message>";
|
||||
@Setting private String noReplyTarget = "<red>You have no one to reply to!";
|
||||
@@ -63,19 +61,12 @@ public class CarbonTranslations {
|
||||
@Setting private String muteExempt = "<red>Player <player> is exempt from being muted!";
|
||||
@Setting private String clearNotify = "<yellow>Chat has been cleared by <player>.";
|
||||
@Setting private String clearExempt = "<yellow>You were exempt from the clear due to your permissions!";
|
||||
@Setting private String cannotWhisperSelf = "<yellow>You cannot whisper yourself!";
|
||||
|
||||
public String reloaded() {
|
||||
return this.reloaded;
|
||||
}
|
||||
|
||||
public String messageToOther() {
|
||||
return this.messageToOther;
|
||||
}
|
||||
|
||||
public String messageFromOther() {
|
||||
return this.messageFromOther;
|
||||
}
|
||||
|
||||
public String otherPlayerOffline() {
|
||||
return this.otherPlayerOffline;
|
||||
}
|
||||
@@ -208,4 +199,8 @@ public class CarbonTranslations {
|
||||
return this.clearExempt;
|
||||
}
|
||||
|
||||
public String cannotWhisperSelf() {
|
||||
return this.cannotWhisperSelf;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -103,6 +103,8 @@ public class ChannelOptions {
|
||||
settings.key = "global";
|
||||
settings.isDefault = true;
|
||||
settings.name = "Global";
|
||||
settings.color = "#FFFFFF";
|
||||
settings.defaultFormatName = "default";
|
||||
settings.formats = Collections.singletonMap("default", "<color><<displayname><reset><color>> <message>");
|
||||
|
||||
return settings;
|
||||
|
||||
@@ -12,7 +12,7 @@ public final class ChannelPings {
|
||||
@Setting private @NonNull String prefix = "";
|
||||
@Setting private boolean caseSensitive = false;
|
||||
@Setting private @NonNull Key sound =
|
||||
Key.of(Key.MINECRAFT_NAMESPACE, "entity.experience_orb.pickup");
|
||||
Key.key(Key.MINECRAFT_NAMESPACE, "entity.experience_orb.pickup");
|
||||
@Setting private Sound.Source source = Sound.Source.PLAYER;
|
||||
@Setting private float volume = 10.0F;
|
||||
@Setting private float pitch = 1.0F;
|
||||
|
||||
@@ -30,7 +30,8 @@ public class ChannelSettings {
|
||||
MAPPER.bind(this).serialize(node);
|
||||
}
|
||||
|
||||
@Setting(comment = "All options here act like the defaults for all channels.\nAdding any of these options to any channel overrides the relevant defaults.")
|
||||
@Setting(comment = "All options here act like the defaults for all channels.\n" +
|
||||
"Adding any of these options to any channel overrides the relevant defaults.")
|
||||
private SharedChannelOptions sharedChannelOptions = new SharedChannelOptions();
|
||||
|
||||
@Setting
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
package net.draycia.carbon.api.config;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
import org.spongepowered.configurate.objectmapping.Setting;
|
||||
import org.spongepowered.configurate.serialize.ConfigSerializable;
|
||||
|
||||
@ConfigSerializable
|
||||
public class WhisperOptions {
|
||||
|
||||
@Setting(comment = "Plays a sound when receiving private messages with /whisper /msg")
|
||||
private @NonNull WhisperPings pings = new WhisperPings();
|
||||
|
||||
@Setting(comment = "")
|
||||
private String switchMessage = "<gray>You are now in <color><channel> <gray>chat!";
|
||||
|
||||
@Setting(comment = "")
|
||||
private String switchOtherMessage = "<gray><player> <reset><gray>is now in <color><channel> <gray>chat!";
|
||||
|
||||
@Setting(comment = "")
|
||||
private String switchFailureMessage = "<red>You cannot use channel <channel>!";
|
||||
|
||||
@Setting(comment = "")
|
||||
private String toggleOnMessage = "<gray>You can now see <color><channel> <gray>chat!";
|
||||
|
||||
@Setting(comment = "")
|
||||
private String toggleOffMessage = "<gray>You can no longer see <color><channel> <gray>chat!";
|
||||
|
||||
@Setting(comment = "")
|
||||
private String toggleOtherOnMessage = "<gray><player> <reset><gray>can now see <color><channel> <gray>chat!";
|
||||
|
||||
@Setting(comment = "")
|
||||
private String toggleOtherOffMessage = "<gray><player> <reset><gray>can no longer see <color><channel> <gray>chat!";
|
||||
|
||||
@Setting(comment = "")
|
||||
private String cannotUseMessage = "You cannot use that channel!";
|
||||
|
||||
@Setting(comment = "")
|
||||
private String cannotIgnoreMessage = "<red>You cannot ignore that channel!";
|
||||
|
||||
@Setting(comment = "")
|
||||
private String senderFormat = "<gold>[<white>Me <gray>-> <white><receiver><gold>] <message>";
|
||||
|
||||
@Setting(comment = "")
|
||||
private String receiverFormat = "<gold>[<white><sender> <gray>-> <white>Me<gold>] <message>";
|
||||
|
||||
@Setting(comment = "")
|
||||
private String consoleFormat = "<gold>[<white><sender> <gray>-> <white><receiver><gold>] <message>";
|
||||
|
||||
@Setting(comment = "")
|
||||
private boolean logToConsole = true;
|
||||
|
||||
public boolean logToConsole() {
|
||||
return this.logToConsole;
|
||||
}
|
||||
|
||||
public @NonNull WhisperPings pings() {
|
||||
return this.pings;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String consoleFormat() {
|
||||
return this.consoleFormat;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String senderFormat() {
|
||||
return this.senderFormat;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String receiverFormat() {
|
||||
return this.receiverFormat;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String switchMessage() {
|
||||
return this.switchMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String switchOtherMessage() {
|
||||
return this.switchOtherMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String switchFailureMessage() {
|
||||
return this.switchFailureMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String cannotIgnoreMessage() {
|
||||
return this.cannotIgnoreMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String toggleOffMessage() {
|
||||
return this.toggleOffMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String toggleOnMessage() {
|
||||
return this.toggleOnMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String toggleOtherOnMessage() {
|
||||
return this.toggleOtherOnMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String toggleOtherOffMessage() {
|
||||
return this.toggleOtherOffMessage;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String cannotUseMessage() {
|
||||
return this.cannotUseMessage;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -8,29 +8,22 @@ import org.spongepowered.configurate.serialize.ConfigSerializable;
|
||||
|
||||
@ConfigSerializable
|
||||
public final class WhisperPings {
|
||||
|
||||
@Setting private boolean enabled = true;
|
||||
@Setting private @NonNull Key sound = Key.of(Key.MINECRAFT_NAMESPACE, "entity.experience_orb.pickup");
|
||||
@Setting private Sound.Source source = Sound.Source.PLAYER;
|
||||
@Setting private float volume = 10.0F;
|
||||
@Setting private float pitch = 1.0F;
|
||||
|
||||
@Setting private @NonNull Sound sound = Sound.sound(
|
||||
Key.key(Key.MINECRAFT_NAMESPACE, "entity.experience_orb.pickup"),
|
||||
Sound.Source.PLAYER,
|
||||
10.0F,
|
||||
1.0F
|
||||
);
|
||||
|
||||
public boolean enabled() {
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public Key sound() {
|
||||
public Sound sound() {
|
||||
return this.sound;
|
||||
}
|
||||
|
||||
public Sound.Source source() {
|
||||
return this.source;
|
||||
}
|
||||
|
||||
public float volume() {
|
||||
return this.volume;
|
||||
}
|
||||
|
||||
public float pitch() {
|
||||
return this.pitch;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package net.draycia.carbon.api.events;
|
||||
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.channels.TextChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.Context;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvent;
|
||||
@@ -9,11 +9,11 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class MessageContextEvent implements CarbonEvent, Cancellable {
|
||||
|
||||
private final @NonNull ChatChannel channel;
|
||||
private final @NonNull TextChannel channel;
|
||||
private final @NonNull ChatUser user;
|
||||
private boolean cancelled = false;
|
||||
|
||||
public MessageContextEvent(final @NonNull ChatChannel channel, final @NonNull ChatUser user) {
|
||||
public MessageContextEvent(final @NonNull TextChannel channel, final @NonNull ChatUser user) {
|
||||
this.channel = channel;
|
||||
this.user = user;
|
||||
}
|
||||
@@ -32,7 +32,7 @@ public class MessageContextEvent implements CarbonEvent, Cancellable {
|
||||
return this.channel.context(key);
|
||||
}
|
||||
|
||||
public @NonNull ChatChannel channel() {
|
||||
public @NonNull TextChannel channel() {
|
||||
return this.channel;
|
||||
}
|
||||
|
||||
|
||||
+4
-4
@@ -1,6 +1,6 @@
|
||||
package net.draycia.carbon.api.events;
|
||||
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.channels.TextChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.Context;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvent;
|
||||
@@ -9,12 +9,12 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class ReceiverContextEvent implements CarbonEvent, Cancellable {
|
||||
|
||||
private final @NonNull ChatChannel channel;
|
||||
private final @NonNull TextChannel channel;
|
||||
private final @NonNull ChatUser sender;
|
||||
private final @NonNull ChatUser recipient;
|
||||
private boolean cancelled = false;
|
||||
|
||||
public ReceiverContextEvent(final @NonNull ChatChannel channel, final @NonNull ChatUser sender, final @NonNull ChatUser recipient) {
|
||||
public ReceiverContextEvent(final @NonNull TextChannel channel, final @NonNull ChatUser sender, final @NonNull ChatUser recipient) {
|
||||
this.channel = channel;
|
||||
this.sender = sender;
|
||||
this.recipient = recipient;
|
||||
@@ -34,7 +34,7 @@ public class ReceiverContextEvent implements CarbonEvent, Cancellable {
|
||||
this.cancelled = cancelled;
|
||||
}
|
||||
|
||||
public @NonNull ChatChannel channel() {
|
||||
public @NonNull TextChannel channel() {
|
||||
return this.channel;
|
||||
}
|
||||
|
||||
|
||||
@@ -49,7 +49,7 @@ public interface ChatUser extends Audience {
|
||||
|
||||
@NonNull Map<@NonNull String, @NonNull ? extends UserChannelSettings> channelSettings();
|
||||
|
||||
boolean spyingwhispers();
|
||||
boolean spyingWhispers();
|
||||
|
||||
default void spyingWhispers(final boolean spyingWhispers) {
|
||||
this.spyingWhispers(spyingWhispers, false);
|
||||
|
||||
@@ -7,6 +7,8 @@ description = 'CarbonChat-Bukkit'
|
||||
|
||||
dependencies {
|
||||
compile 'org.spongepowered:configurate-hocon:4.0.0-SNAPSHOT'
|
||||
compile 'net.kyori:adventure-text-serializer-bungeecord:4.0.0-SNAPSHOT'
|
||||
compile 'net.kyori:adventure-platform-bukkit:4.0.0-SNAPSHOT'
|
||||
|
||||
compile project(":CarbonChat-Common")
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
|
||||
import com.intellectualsites.commands.paper.PaperCommandManager;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.adventure.CarbonTranslations;
|
||||
import net.draycia.carbon.api.config.CarbonTranslations;
|
||||
import net.draycia.carbon.api.adventure.MessageProcessor;
|
||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettingsRegistry;
|
||||
@@ -24,7 +24,7 @@ import net.draycia.carbon.api.config.SQLCredentials;
|
||||
import net.draycia.carbon.common.messaging.RedisMessageService;
|
||||
import net.draycia.carbon.listeners.contexts.DistanceContext;
|
||||
import net.draycia.carbon.listeners.contexts.EconomyContext;
|
||||
import net.draycia.carbon.listeners.contexts.FilterContext;
|
||||
import net.draycia.carbon.common.contexts.FilterContext;
|
||||
import net.draycia.carbon.listeners.contexts.TownyContext;
|
||||
import net.draycia.carbon.listeners.contexts.WorldGuardContext;
|
||||
import net.draycia.carbon.listeners.contexts.mcMMOContext;
|
||||
@@ -57,6 +57,8 @@ import net.draycia.carbon.util.Metrics;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.platform.bukkit.BukkitAudiences;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.serializer.craftbukkit.BukkitComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -121,7 +123,8 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
this.reloadConfig();
|
||||
|
||||
// Setup Adventure
|
||||
this.messageProcessor = new AdventureManager(BukkitAudiences.create(this), FormatType.MINIMESSAGE); // TODO: get format type from config
|
||||
final BukkitAudiences audiences = BukkitAudiences.create(this);
|
||||
this.messageProcessor = new AdventureManager(audiences, FormatType.MINIMESSAGE); // TODO: get format type from config
|
||||
|
||||
// Initialize managers
|
||||
this.channelManager = new ChannelManager(this);
|
||||
@@ -402,4 +405,9 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
return this.getDataFolder().toPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull GsonComponentSerializer gsonSerializer() {
|
||||
return BukkitComponentSerializer.gson();
|
||||
}
|
||||
|
||||
}
|
||||
+14
-3
@@ -1,6 +1,7 @@
|
||||
package net.draycia.carbon.listeners.contexts;
|
||||
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.channels.TextChannel;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.PreChatFormatEvent;
|
||||
import net.draycia.carbon.api.Context;
|
||||
@@ -21,7 +22,12 @@ public class EconomyContext {
|
||||
this.economy = this.carbonChat.getServer().getServicesManager().getRegistration(Economy.class).getProvider();
|
||||
|
||||
CarbonEvents.register(PreChatFormatEvent.class, event -> {
|
||||
final Context context = event.channel().context("vault-balance");
|
||||
if (!(event.channel() instanceof TextChannel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final TextChannel channel = (TextChannel) event.channel();
|
||||
final Context context = channel.context("vault-balance");
|
||||
|
||||
if (context == null) {
|
||||
return;
|
||||
@@ -30,7 +36,7 @@ public class EconomyContext {
|
||||
final Double requiredBal;
|
||||
|
||||
if (context.isNumber()) {
|
||||
requiredBal = context.asNumber().doubleValue();;
|
||||
requiredBal = context.asNumber().doubleValue();
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
@@ -50,7 +56,12 @@ public class EconomyContext {
|
||||
});
|
||||
|
||||
CarbonEvents.register(PreChatFormatEvent.class, event -> {
|
||||
final Context context = event.channel().context("vault-cost");
|
||||
if (!(event.channel() instanceof TextChannel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final TextChannel channel = (TextChannel) event.channel();
|
||||
final Context context = channel.context("vault-cost");
|
||||
|
||||
if (context == null) {
|
||||
return;
|
||||
|
||||
+17
-9
@@ -4,8 +4,9 @@ import com.palmergames.bukkit.towny.TownyAPI;
|
||||
import com.palmergames.bukkit.towny.event.TownRemoveResidentEvent;
|
||||
import com.palmergames.bukkit.towny.exceptions.NotRegisteredException;
|
||||
import com.palmergames.bukkit.towny.object.Resident;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.channels.TextChannel;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.ChannelSwitchEvent;
|
||||
import net.draycia.carbon.api.events.MessageContextEvent;
|
||||
@@ -25,9 +26,9 @@ public final class TownyContext implements Listener {
|
||||
private static final String KEY = "towny-town";
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public TownyContext(final @NonNull CarbonChatBukkit carbonChat) {
|
||||
public TownyContext(final @NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
CarbonEvents.register(ReceiverContextEvent.class, event -> {
|
||||
@@ -39,11 +40,16 @@ public final class TownyContext implements Listener {
|
||||
});
|
||||
|
||||
CarbonEvents.register(ChannelSwitchEvent.class, event -> {
|
||||
final Context context = event.channel().context(KEY);
|
||||
if (!(event.channel() instanceof TextChannel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final TextChannel channel = (TextChannel) event.channel();
|
||||
final Context context = channel.context(KEY);
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean()) {
|
||||
if (!this.isInTown(event.user())) {
|
||||
event.failureMessage(carbonChat.getConfig().getString("contexts.Towny.cancellation-message"));
|
||||
//event.failureMessage(carbonChat.getConfig().getString("contexts.Towny.cancellation-message"));
|
||||
event.cancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -67,11 +73,12 @@ public final class TownyContext implements Listener {
|
||||
final ChatUser user = this.carbonChat.userService().wrap(Bukkit.getPlayer(name).getUniqueId());
|
||||
final ChatChannel channel = user.selectedChannel();
|
||||
|
||||
if (channel == null) {
|
||||
if (!(channel instanceof TextChannel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Context context = channel.context(KEY);
|
||||
final TextChannel textChannel = (TextChannel) channel;
|
||||
final Context context = textChannel.context(KEY);
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean()) {
|
||||
user.clearSelectedChannel();
|
||||
@@ -83,11 +90,12 @@ public final class TownyContext implements Listener {
|
||||
final ChatUser user = this.carbonChat.userService().wrap(event.getPlayer().getUniqueId());
|
||||
final ChatChannel channel = user.selectedChannel();
|
||||
|
||||
if (channel == null) {
|
||||
if (!(channel instanceof TextChannel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Context context = channel.context(KEY);
|
||||
final TextChannel textChannel = (TextChannel) channel;
|
||||
final Context context = textChannel.context(KEY);
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean() && !this.isInTown(user)) {
|
||||
user.clearSelectedChannel();
|
||||
|
||||
+14
-7
@@ -2,8 +2,9 @@ package net.draycia.carbon.listeners.contexts;
|
||||
|
||||
import com.gmail.nossr50.api.PartyAPI;
|
||||
import com.gmail.nossr50.events.party.McMMOPartyChangeEvent;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.channels.TextChannel;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.ChannelSwitchEvent;
|
||||
import net.draycia.carbon.api.events.MessageContextEvent;
|
||||
@@ -21,12 +22,12 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
public final class mcMMOContext implements Listener {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
@NonNull
|
||||
private static final String KEY = "mcmmo-party";
|
||||
|
||||
public mcMMOContext(final @NonNull CarbonChatBukkit carbonChat) {
|
||||
public mcMMOContext(final @NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
CarbonEvents.register(ReceiverContextEvent.class, PostOrders.NORMAL, false, event -> {
|
||||
@@ -39,11 +40,16 @@ public final class mcMMOContext implements Listener {
|
||||
});
|
||||
|
||||
CarbonEvents.register(ChannelSwitchEvent.class, PostOrders.NORMAL, false, event -> {
|
||||
final Context context = event.channel().context(KEY);
|
||||
if (!(event.channel() instanceof TextChannel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final TextChannel channel = (TextChannel) event.channel();
|
||||
final Context context = channel.context(KEY);
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean()) {
|
||||
if (!this.isInParty(event.user())) {
|
||||
event.failureMessage(carbonChat.getConfig().getString("contexts.mcMMO.cancellation-message"));
|
||||
//event.failureMessage(carbonChat.carbonSettings().getString("contexts.mcMMO.cancellation-message"));
|
||||
event.cancelled(true);
|
||||
}
|
||||
}
|
||||
@@ -79,11 +85,12 @@ public final class mcMMOContext implements Listener {
|
||||
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
final ChatChannel channel = user.selectedChannel();
|
||||
|
||||
if (channel == null) {
|
||||
if (!(channel instanceof TextChannel)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Context context = channel.context(KEY);
|
||||
final TextChannel textChannel = (TextChannel) channel;
|
||||
final Context context = textChannel.context(KEY);
|
||||
|
||||
if (context != null && context.isBoolean() && context.asBoolean() && !this.isInParty(user)) {
|
||||
user.clearSelectedChannel();
|
||||
|
||||
+21
-30
@@ -1,21 +1,18 @@
|
||||
package net.draycia.carbon.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.channels.TextChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.serializer.plain.PlainComponentSerializer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
|
||||
public class BukkitChatListener implements Listener {
|
||||
@@ -41,18 +38,24 @@ public class BukkitChatListener implements Listener {
|
||||
channel = this.carbonChat.channelRegistry().defaultChannel();
|
||||
}
|
||||
|
||||
if (channel.shouldCancelChatEvent()) {
|
||||
event.setCancelled(true);
|
||||
}
|
||||
// if (channel.shouldCancelChatEvent()) {
|
||||
// event.setCancelled(true);
|
||||
// }
|
||||
|
||||
for (final ChatChannel entry : this.carbonChat.channelRegistry()) {
|
||||
if (entry.messagePrefix() == null || entry.messagePrefix().isEmpty()) {
|
||||
if (!(entry instanceof TextChannel)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (event.getMessage().startsWith(entry.messagePrefix())) {
|
||||
final TextChannel textChannel = (TextChannel) entry;
|
||||
|
||||
if (textChannel.messagePrefix() == null || textChannel.messagePrefix().isEmpty()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (event.getMessage().startsWith(textChannel.messagePrefix())) {
|
||||
if (entry.canPlayerUse(user)) {
|
||||
event.setMessage(event.getMessage().substring(entry.messagePrefix().length()));
|
||||
event.setMessage(event.getMessage().substring(textChannel.messagePrefix().length()));
|
||||
channel = entry;
|
||||
break;
|
||||
}
|
||||
@@ -65,26 +68,14 @@ public class BukkitChatListener implements Listener {
|
||||
return;
|
||||
}
|
||||
|
||||
final Collection<ChatUser> recipients;
|
||||
|
||||
if (selectedChannel.honorsRecipientList()) {
|
||||
recipients = new HashSet<>();
|
||||
|
||||
for (final Player recipient : event.getRecipients()) {
|
||||
recipients.add(this.carbonChat.userService().wrap(recipient.getUniqueId()));
|
||||
}
|
||||
} else {
|
||||
recipients = selectedChannel.audiences();
|
||||
}
|
||||
|
||||
event.getRecipients().clear();
|
||||
|
||||
if (event.isAsynchronous()) {
|
||||
final Map<ChatUser, Component> messages =
|
||||
selectedChannel.parseMessage(user, recipients, event.getMessage(), false);
|
||||
selectedChannel.parseMessage(user, event.getMessage(), false);
|
||||
|
||||
for (final Map.Entry<ChatUser, Component> entry : messages.entrySet()) {
|
||||
if (entry.getValue().equals(TextComponent.empty())) {
|
||||
if (entry.getValue().equals(Component.empty())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -98,13 +89,13 @@ public class BukkitChatListener implements Listener {
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> {
|
||||
selectedChannel.sendComponentsAndLog(
|
||||
selectedChannel.parseMessage(user, recipients, event.getMessage(), false));
|
||||
selectedChannel.parseMessage(user, event.getMessage(), false));
|
||||
|
||||
if (this.carbonChat.getConfig().getBoolean("show-tips")) {
|
||||
this.carbonChat.logger().info("Tip: Sync chat event! I cannot set the message format due to this. :(");
|
||||
this.carbonChat.logger().info("Tip: To 'solve' this, do a binary search and see which plugin is triggering");
|
||||
this.carbonChat.logger().info("Tip: sync chat events and causing this, and let that plugin author know.");
|
||||
}
|
||||
// if (this.carbonChat.getConfig().getBoolean("show-tips")) {
|
||||
// this.carbonChat.logger().info("Tip: Sync chat event! I cannot set the message format due to this. :(");
|
||||
// this.carbonChat.logger().info("Tip: To 'solve' this, do a binary search and see which plugin is triggering");
|
||||
// this.carbonChat.logger().info("Tip: sync chat events and causing this, and let that plugin author know.");
|
||||
// }
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -28,17 +28,17 @@ public class ItemLinkHandler {
|
||||
|
||||
final Component itemComponent = CarbonUtils.createComponent(player);
|
||||
|
||||
if (itemComponent.equals(TextComponent.empty())) {
|
||||
if (itemComponent.equals(Component.empty())) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final Pattern pattern : event.channel().itemLinkPatterns()) {
|
||||
final String patternContent = pattern.toString().replace("\\Q", "").replace("\\E", "");
|
||||
final String patternContent = pattern.toString().replace("\\Q", "")
|
||||
.replace("\\E", "");
|
||||
|
||||
if (event.originalMessage().contains(patternContent)) {
|
||||
final TextComponent component = (TextComponent) event.component().replaceFirstText(pattern, input -> {
|
||||
return TextComponent.builder().append(itemComponent);
|
||||
});
|
||||
final TextComponent component = (TextComponent) event.component()
|
||||
.replaceFirstText(pattern, input -> itemComponent);
|
||||
|
||||
event.component(component);
|
||||
break;
|
||||
|
||||
@@ -11,8 +11,6 @@ import net.draycia.carbon.api.events.ChannelSwitchEvent;
|
||||
import net.draycia.carbon.api.events.PrivateMessageEvent;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.luckperms.api.LuckPerms;
|
||||
import net.luckperms.api.LuckPermsProvider;
|
||||
@@ -45,7 +43,7 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
@MonotonicNonNull // @NonNull but not initialised in all constructors.
|
||||
private UUID uuid;
|
||||
@Nullable
|
||||
private String selectedChannel = null;
|
||||
private String selectedChannelKey = null;
|
||||
private boolean muted = false;
|
||||
private boolean shadowMuted = false;
|
||||
private boolean spyingWhispers = false;
|
||||
@@ -53,6 +51,9 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
@Nullable
|
||||
private String nickname = null;
|
||||
|
||||
@Nullable
|
||||
private transient ChatChannel selectedChannel = null;
|
||||
|
||||
@Nullable
|
||||
private transient UUID replyTarget = null;
|
||||
|
||||
@@ -115,9 +116,9 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
|
||||
onlinePlayer.setDisplayName(newNickname);
|
||||
|
||||
if (this.carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) {
|
||||
onlinePlayer.setPlayerListName(newNickname);
|
||||
}
|
||||
// if (this.carbonChat.getConfig().getBoolean("nicknames-set-tab-name")) {
|
||||
// onlinePlayer.setPlayerListName(newNickname);
|
||||
// }
|
||||
}
|
||||
|
||||
if (!fromRemote) {
|
||||
@@ -158,11 +159,15 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatChannel selectedChannel() {
|
||||
if (this.selectedChannel == null) {
|
||||
return null;
|
||||
if (this.selectedChannel != null) {
|
||||
return this.selectedChannel;
|
||||
}
|
||||
|
||||
return this.carbonChat.channelRegistry().channelOrDefault(this.selectedChannel);
|
||||
if (this.selectedChannelKey != null) {
|
||||
return this.carbonChat.channelRegistry().channelOrDefault(this.selectedChannelKey);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -180,7 +185,8 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
return;
|
||||
}
|
||||
|
||||
this.selectedChannel = chatChannel.key();
|
||||
this.selectedChannelKey = chatChannel.key();
|
||||
this.selectedChannel = chatChannel;
|
||||
|
||||
if (!fromRemote) {
|
||||
this.carbonChat.messageManager().sendMessage("selected-channel", this.uuid(), byteArray -> {
|
||||
@@ -344,7 +350,7 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean spyingwhispers() {
|
||||
public boolean spyingWhispers() {
|
||||
return this.spyingWhispers;
|
||||
}
|
||||
|
||||
@@ -354,8 +360,8 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
return;
|
||||
}
|
||||
|
||||
final String toPlayerFormat = this.carbonChat.translations().messageToOther();
|
||||
final String fromPlayerFormat = this.carbonChat.translations().messageFromOther();
|
||||
final String toPlayerFormat = this.carbonChat.carbonSettings().whisperOptions().senderFormat();
|
||||
final String fromPlayerFormat = this.carbonChat.carbonSettings().whisperOptions().receiverFormat();
|
||||
|
||||
final OfflinePlayer offlineSender = Bukkit.getOfflinePlayer(sender.uuid());
|
||||
String senderName = offlineSender.getName();
|
||||
@@ -403,15 +409,6 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
|
||||
sender.replyTarget(this);
|
||||
this.replyTarget(sender);
|
||||
|
||||
if (this.carbonChat.getConfig().getBoolean("pings.on-whisper")) {
|
||||
final Key key = Key.of(this.carbonChat.getConfig().getString("pings.sound"));
|
||||
final Sound.Source source = Sound.Source.valueOf(this.carbonChat.getConfig().getString("pings.source"));
|
||||
final float volume = (float) this.carbonChat.getConfig().getDouble("pings.volume");
|
||||
final float pitch = (float) this.carbonChat.getConfig().getDouble("pings.pitch");
|
||||
|
||||
this.playSound(Sound.of(key, source, volume, pitch));
|
||||
}
|
||||
}
|
||||
} else if (offlineSender.isOnline()) {
|
||||
final String targetNameFinal = targetName;
|
||||
@@ -453,7 +450,7 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
this.carbonChat.messageManager().sendMessage("whisper-component", sender.uuid(), byteArray -> {
|
||||
byteArray.writeLong(this.uuid().getMostSignificantBits());
|
||||
byteArray.writeLong(this.uuid().getLeastSignificantBits());
|
||||
byteArray.writeUTF(this.carbonChat.messageProcessor().audiences().gsonSerializer().serialize(fromPlayerComponent));
|
||||
byteArray.writeUTF(this.carbonChat.gsonSerializer().serialize(fromPlayerComponent));
|
||||
});
|
||||
});
|
||||
}
|
||||
@@ -461,7 +458,7 @@ public class BukkitChatUser implements ChatUser, ForwardingAudience {
|
||||
for (final Player player : Bukkit.getOnlinePlayers()) {
|
||||
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
|
||||
if (!user.spyingwhispers()) {
|
||||
if (!user.spyingWhispers()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ package net.draycia.carbon.util;
|
||||
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeCordComponentSerializer;
|
||||
import net.kyori.adventure.text.serializer.bungeecord.BungeeComponentSerializer;
|
||||
import net.md_5.bungee.api.ChatColor;
|
||||
import net.md_5.bungee.api.chat.ComponentBuilder;
|
||||
import net.md_5.bungee.api.chat.HoverEvent;
|
||||
@@ -58,13 +58,13 @@ public final class CarbonUtils {
|
||||
@NonNull
|
||||
public static Component createComponent(final @NonNull Player player) {
|
||||
if (!FunctionalityConstants.HAS_HOVER_EVENT_METHOD) {
|
||||
return net.kyori.adventure.text.TextComponent.empty();
|
||||
return net.kyori.adventure.text.Component.empty();
|
||||
}
|
||||
|
||||
final ItemStack itemStack = player.getInventory().getItemInMainHand();
|
||||
|
||||
if (itemStack.getType().isAir()) {
|
||||
return net.kyori.adventure.text.TextComponent.empty();
|
||||
return net.kyori.adventure.text.Component.empty();
|
||||
}
|
||||
|
||||
final Content content = Bukkit.getItemFactory().hoverContentOf(itemStack);
|
||||
@@ -86,7 +86,7 @@ public final class CarbonUtils {
|
||||
|
||||
component.color(ChatColor.WHITE).append("]");
|
||||
|
||||
return BungeeCordComponentSerializer.get().deserialize(component.create());
|
||||
return BungeeComponentSerializer.get().deserialize(component.create());
|
||||
}
|
||||
|
||||
}
|
||||
+8
-3
@@ -1,10 +1,11 @@
|
||||
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.MessageProcessor;
|
||||
import net.kyori.adventure.platform.AudienceProvider;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -14,18 +15,22 @@ public class AdventureManager implements MessageProcessor {
|
||||
@NonNull
|
||||
private final AudienceProvider provider;
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
@NonNull
|
||||
private final FormatType formatType;
|
||||
|
||||
public AdventureManager(final @NonNull AudienceProvider provider, final @NonNull FormatType formatType) {
|
||||
this.provider = provider;
|
||||
this.formatType = formatType;
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Component processMessage(@Nullable final String input, final @NonNull String @NonNull ... placeholders) {
|
||||
if (input == null || input.trim().isEmpty()) {
|
||||
return TextComponent.empty();
|
||||
return Component.empty();
|
||||
}
|
||||
|
||||
switch (this.formatType) {
|
||||
@@ -49,7 +54,7 @@ public class AdventureManager implements MessageProcessor {
|
||||
input = input.replace("<" + placeholder + ">", replacement);
|
||||
}
|
||||
|
||||
return this.audiences().gsonSerializer().deserialize(input);
|
||||
return this.carbonChat.gsonSerializer().deserialize(input);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+9
-9
@@ -1,10 +1,10 @@
|
||||
package net.draycia.carbon.common.channels;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.channels.TextChannel;
|
||||
import net.draycia.carbon.api.config.ChannelOptions;
|
||||
import net.draycia.carbon.api.users.ConsoleUser;
|
||||
import net.draycia.carbon.common.utils.ColorUtils;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.ChatComponentEvent;
|
||||
import net.draycia.carbon.api.events.ChatFormatEvent;
|
||||
@@ -31,7 +31,7 @@ import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CarbonChatChannel implements ChatChannel {
|
||||
public class CarbonChatChannel implements TextChannel {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
@@ -205,7 +205,7 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
@Override
|
||||
public void sendComponents(final @NonNull Map<ChatUser, Component> components) {
|
||||
for (final Map.Entry<ChatUser, Component> entry : components.entrySet()) {
|
||||
if (entry.getValue().equals(TextComponent.empty())) {
|
||||
if (entry.getValue().equals(Component.empty())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -216,7 +216,7 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
@Override
|
||||
public void sendComponentsAndLog(final @NonNull Map<ChatUser, Component> components) {
|
||||
for (final Map.Entry<ChatUser, Component> entry : components.entrySet()) {
|
||||
if (entry.getValue().equals(TextComponent.empty())) {
|
||||
if (entry.getValue().equals(Component.empty())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -327,7 +327,7 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
public void sendMessageToBungee(final @NonNull UUID uuid, final @NonNull Component component) {
|
||||
this.carbonChat.messageService().sendMessage("channel-component", uuid, byteArray -> {
|
||||
byteArray.writeUTF(this.key());
|
||||
byteArray.writeUTF(this.carbonChat.messageProcessor().audiences().gsonSerializer().serialize(component));
|
||||
byteArray.writeUTF(this.carbonChat.gsonSerializer().serialize(component));
|
||||
});
|
||||
}
|
||||
|
||||
@@ -495,10 +495,10 @@ public class CarbonChatChannel implements ChatChannel {
|
||||
return this.options().primaryGroupOnly();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldCancelChatEvent() {
|
||||
return this.options().shouldCancelChatEvent();
|
||||
}
|
||||
// @Override
|
||||
// public boolean shouldCancelChatEvent() {
|
||||
// return this.options().shouldCancelChatEvent();
|
||||
// }
|
||||
|
||||
@Override
|
||||
@NonNull
|
||||
|
||||
+278
@@ -0,0 +1,278 @@
|
||||
package net.draycia.carbon.common.channels;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.WhisperChannel;
|
||||
import net.draycia.carbon.api.events.ChatComponentEvent;
|
||||
import net.draycia.carbon.api.events.ChatFormatEvent;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.users.ConsoleUser;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import net.kyori.adventure.text.format.NamedTextColor;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class CarbonWhisperChannel implements WhisperChannel {
|
||||
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
private final @NonNull ChatUser sender;
|
||||
private final @NonNull ChatUser audience;
|
||||
|
||||
public CarbonWhisperChannel(final @NonNull ChatUser sender, final @NonNull ChatUser audience) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
this.sender = sender;
|
||||
this.audience = audience;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull ChatUser sender() {
|
||||
return this.sender;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull ChatUser audience() {
|
||||
return this.audience;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable TextColor channelColor(@NonNull final ChatUser user) {
|
||||
return NamedTextColor.WHITE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Map<ChatUser, Component> parseMessage(@NonNull final ChatUser user, @NonNull final String message,
|
||||
final boolean fromRemote) {
|
||||
return this.parseMessage(user, Collections.singleton(this.audience()), message, fromRemote);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Map<ChatUser, Component> parseMessage(@NonNull final ChatUser user,
|
||||
@NonNull final Collection<@NonNull ChatUser> recipients,
|
||||
@NonNull final String message, final boolean fromRemote) {
|
||||
// TODO: extract to method, this is just the same thing but twice
|
||||
final Map<ChatUser, Component> result = new HashMap<>();
|
||||
|
||||
// Formats
|
||||
final String senderFormat = this.senderFormat();
|
||||
final String receiverFormat = this.receiverFormat();
|
||||
|
||||
final ChatFormatEvent senderFormatEvent = new ChatFormatEvent(this.sender, this.sender, this, senderFormat, message);
|
||||
|
||||
CarbonEvents.post(senderFormatEvent);
|
||||
|
||||
if (senderFormatEvent.cancelled() || senderFormatEvent.message().trim().isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
final ChatFormatEvent receiverFormatEvent = new ChatFormatEvent(this.sender, this.audience, this, receiverFormat, message);
|
||||
|
||||
CarbonEvents.post(receiverFormatEvent);
|
||||
|
||||
if (receiverFormatEvent.cancelled() || receiverFormatEvent.message().trim().isEmpty()) {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
// Display names
|
||||
final String senderName;
|
||||
|
||||
if (this.sender.nickname() != null) {
|
||||
senderName = this.sender.nickname();
|
||||
} else {
|
||||
senderName = this.sender.displayName();
|
||||
}
|
||||
|
||||
final String receiverName;
|
||||
|
||||
if (this.audience.nickname() != null) {
|
||||
receiverName = this.audience.nickname();
|
||||
} else {
|
||||
receiverName = this.audience.displayName();
|
||||
}
|
||||
|
||||
// Components
|
||||
final TextComponent senderComponent = (TextComponent) this.carbonChat.messageProcessor().processMessage(
|
||||
senderFormatEvent.format(),
|
||||
"br", "\n",
|
||||
"senderdisplayname", senderName,
|
||||
"sender", this.sender.name(),
|
||||
"receiverdisplayname", receiverName,
|
||||
"receiver", this.audience.name(),
|
||||
"phase", Long.toString(System.currentTimeMillis() % 25),
|
||||
"server", this.carbonChat.carbonSettings().serverName(),
|
||||
"message", senderFormatEvent.message());
|
||||
|
||||
final ChatComponentEvent senderComponentEvent = new ChatComponentEvent(this.sender, this.sender, this,
|
||||
senderComponent, senderFormatEvent.message());
|
||||
|
||||
CarbonEvents.post(senderComponentEvent);
|
||||
|
||||
result.put(this.sender, senderComponentEvent.component());
|
||||
|
||||
final TextComponent receiverComponent = (TextComponent) this.carbonChat.messageProcessor().processMessage(
|
||||
receiverFormatEvent.format(),
|
||||
"br", "\n",
|
||||
"senderdisplayname", senderName,
|
||||
"sender", this.sender.name(),
|
||||
"receiverdisplayname", receiverName,
|
||||
"receiver", this.audience.name(),
|
||||
"phase", Long.toString(System.currentTimeMillis() % 25),
|
||||
"server", this.carbonChat.carbonSettings().serverName(),
|
||||
"message", senderFormatEvent.message());
|
||||
|
||||
final ChatComponentEvent receiverComponentEvent = new ChatComponentEvent(this.sender, this.audience, this,
|
||||
receiverComponent, receiverFormatEvent.message());
|
||||
|
||||
CarbonEvents.post(receiverComponentEvent);
|
||||
|
||||
result.put(this.audience, receiverComponentEvent.component());
|
||||
|
||||
System.out.println(this.sender.equals(this.audience));
|
||||
|
||||
final ChatFormatEvent consoleFormatEvent = new ChatFormatEvent(this.sender, null, this,
|
||||
this.consoleFormat(), message);
|
||||
|
||||
CarbonEvents.post(consoleFormatEvent);
|
||||
|
||||
final TextComponent consoleFormat = (TextComponent) this.carbonChat.messageProcessor().processMessage(
|
||||
consoleFormatEvent.format(),
|
||||
"br", "\n",
|
||||
"senderdisplayname", senderName,
|
||||
"sender", this.sender.name(),
|
||||
"receiverdisplayname", receiverName,
|
||||
"receiver", this.audience.name(),
|
||||
"phase", Long.toString(System.currentTimeMillis() % 25),
|
||||
"server", this.carbonChat.carbonSettings().serverName(),
|
||||
"message", senderFormatEvent.message());
|
||||
|
||||
// TODO: add ConsoleUser to users map
|
||||
final ChatComponentEvent consoleEvent = new ChatComponentEvent(this.sender, null, this, consoleFormat,
|
||||
consoleFormatEvent.message());
|
||||
|
||||
CarbonEvents.post(consoleEvent);
|
||||
|
||||
System.out.println(result.size());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlayerUse(@NonNull final ChatUser user) {
|
||||
return user.equals(this.sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlayerSee(@NonNull final ChatUser sender, @NonNull final ChatUser target, final boolean checkSpying) {
|
||||
return (checkSpying && target.spyingWhispers()) || (sender.equals(this.sender) && target.equals(this.audience));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlayerSee(@NonNull final ChatUser target, final boolean checkSpying) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendComponents(final @NonNull Map<ChatUser, Component> components) {
|
||||
for (final Map.Entry<ChatUser, Component> entry : components.entrySet()) {
|
||||
entry.getKey().sendMessage(entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendComponentsAndLog(final @NonNull Map<ChatUser, Component> components) {
|
||||
for (final Map.Entry<ChatUser, Component> entry : components.entrySet()) {
|
||||
entry.getKey().sendMessage(entry.getValue());
|
||||
|
||||
if (entry.getKey() instanceof ConsoleUser) {
|
||||
this.carbonChat.messageProcessor().audiences().console().sendMessage(entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String name() {
|
||||
return "Whisper";
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull String key() {
|
||||
return "whisper";
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean ignorable() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull List<@NonNull Pattern> itemLinkPatterns() {
|
||||
return this.carbonChat.carbonSettings().itemLinkPatterns();
|
||||
}
|
||||
|
||||
public @Nullable String senderFormat() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().senderFormat();
|
||||
}
|
||||
|
||||
public @Nullable String receiverFormat() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().receiverFormat();
|
||||
}
|
||||
|
||||
public @Nullable String consoleFormat() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().consoleFormat();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String switchMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().switchMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String switchOtherMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().switchOtherMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String switchFailureMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().switchFailureMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String cannotIgnoreMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().cannotIgnoreMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String toggleOffMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().toggleOffMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String toggleOnMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().toggleOnMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String toggleOtherOnMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().toggleOtherOnMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String toggleOtherOffMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().toggleOtherOffMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String cannotUseMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().cannotUseMessage();
|
||||
}
|
||||
}
|
||||
+11
-4
@@ -1,6 +1,7 @@
|
||||
package net.draycia.carbon.common.channels;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.channels.TextChannel;
|
||||
import net.draycia.carbon.api.config.ChannelOptions;
|
||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
@@ -50,9 +51,11 @@ public class ChannelManager {
|
||||
public void registerChannel(final @NonNull ChatChannel channel) {
|
||||
this.registry().register(channel.key(), channel);
|
||||
|
||||
if (channel.isDefault() && this.defaultChannelKey == null) {
|
||||
this.carbonChat.logger().info("Default channel registered: " + channel.name());
|
||||
this.defaultChannelKey = channel.key();
|
||||
if (channel instanceof TextChannel) {
|
||||
if (((TextChannel) channel).isDefault() && this.defaultChannelKey == null) {
|
||||
this.carbonChat.logger().info("Default channel registered: " + channel.name());
|
||||
this.defaultChannelKey = channel.key();
|
||||
}
|
||||
}
|
||||
|
||||
CarbonEvents.post(new ChannelRegisterEvent(Collections.singletonList(channel), this.registry()));
|
||||
@@ -95,7 +98,11 @@ public class ChannelManager {
|
||||
|
||||
if (channel != null) {
|
||||
this.registerChannel(channel);
|
||||
String prefix = channel.messagePrefix();
|
||||
String prefix = null;
|
||||
|
||||
if (channel instanceof TextChannel) {
|
||||
prefix = ((TextChannel) channel).messagePrefix();
|
||||
}
|
||||
|
||||
if (prefix != null && !prefix.trim().isEmpty()) {
|
||||
prefix = "(" + prefix + ") ";
|
||||
|
||||
+4
-4
@@ -5,7 +5,7 @@ import com.intellectualsites.commands.arguments.standard.StringArgument;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.channels.TextChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
@@ -13,11 +13,11 @@ public class AliasedChannelCommand {
|
||||
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
private final @NonNull ChatChannel chatChannel;
|
||||
private final @NonNull TextChannel chatChannel;
|
||||
|
||||
private final @NonNull String commandName;
|
||||
|
||||
public AliasedChannelCommand(final @NonNull CommandManager<ChatUser> commandManager, final @NonNull ChatChannel chatChannel) {
|
||||
public AliasedChannelCommand(final @NonNull CommandManager<ChatUser> commandManager, final @NonNull TextChannel chatChannel) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
this.chatChannel = chatChannel;
|
||||
this.commandName = chatChannel.key();
|
||||
@@ -62,7 +62,7 @@ public class AliasedChannelCommand {
|
||||
});
|
||||
}
|
||||
|
||||
public @NonNull ChatChannel chatChannel() {
|
||||
public @NonNull TextChannel chatChannel() {
|
||||
return this.chatChannel;
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -5,6 +5,7 @@ import com.intellectualsites.commands.arguments.standard.StringArgument;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.TextChannel;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
@@ -45,7 +46,7 @@ public class ChannelCommand {
|
||||
|
||||
private void channel(final @NonNull CommandContext<ChatUser> context) {
|
||||
final ChatUser user = context.getSender();
|
||||
final ChatChannel channel = context.getRequired("channel");
|
||||
final TextChannel channel = context.getRequired("channel");
|
||||
|
||||
if (user.channelSettings(channel).ignored()) {
|
||||
user.sendMessage(this.carbonChat.messageProcessor().processMessage(channel.cannotUseMessage(),
|
||||
|
||||
+4
-4
@@ -83,7 +83,7 @@ public class ChannelListCommand {
|
||||
}
|
||||
|
||||
final Iterator<ChatChannel> visibleChannels = canSee.iterator();
|
||||
final TextComponent.Builder availableList = TextComponent.builder("");
|
||||
final TextComponent.Builder availableList = Component.text();
|
||||
|
||||
this.makeList(visibleChannels, availableList);
|
||||
|
||||
@@ -95,7 +95,7 @@ public class ChannelListCommand {
|
||||
|
||||
if (sender.hasPermission("carbonchat.channellist.bypass") && !cannotSee.isEmpty()) {
|
||||
final Iterator<ChatChannel> invisibleChannels = cannotSee.iterator();
|
||||
final TextComponent.Builder unavailableList = TextComponent.builder("");
|
||||
final TextComponent.Builder unavailableList = Component.text();
|
||||
|
||||
this.makeList(invisibleChannels, unavailableList);
|
||||
|
||||
@@ -110,10 +110,10 @@ public class ChannelListCommand {
|
||||
private void makeList(final @NonNull Iterator<@NonNull ChatChannel> iterator, final TextComponent.@NonNull Builder list) {
|
||||
final String listSeparator = this.carbonChat.translations().channelListSeparator();
|
||||
// TODO: Larry, why did you double assign the listSeparatorComponent?
|
||||
final Component listSeparatorComponent = TextComponent.of(listSeparator);
|
||||
final Component listSeparatorComponent = Component.text(listSeparator);
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
list.append(TextComponent.of(iterator.next().name()));
|
||||
list.append(Component.text(iterator.next().name()));
|
||||
|
||||
if (iterator.hasNext()) {
|
||||
list.append(listSeparatorComponent);
|
||||
|
||||
+21
-3
@@ -7,9 +7,12 @@ import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.common.channels.CarbonWhisperChannel;
|
||||
import net.draycia.carbon.common.utils.CommandUtils;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class MessageCommand {
|
||||
|
||||
@NonNull
|
||||
@@ -31,15 +34,30 @@ public class MessageCommand {
|
||||
.withSenderType(ChatUser.class) // player
|
||||
.withPermission("carbonchat.message")
|
||||
.argument(CommandUtils.chatUserArgument())
|
||||
.argument(StringArgument.<ChatUser>newBuilder("message").greedy().build())
|
||||
.argument(StringArgument.<ChatUser>newBuilder("message").greedy().asOptional().build())
|
||||
.handler(this::sendMessage)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
private void sendMessage(final @NonNull CommandContext<ChatUser> context) {
|
||||
context.<ChatUser>getRequired("target")
|
||||
.sendMessage(context.getSender(), context.getRequired("message"));
|
||||
final ChatUser sender = context.getSender();
|
||||
final ChatUser receiver = context.getRequired("user");
|
||||
|
||||
if (sender.equals(receiver)) {
|
||||
final String message = this.carbonChat.translations().cannotWhisperSelf();
|
||||
sender.sendMessage(this.carbonChat.messageProcessor().processMessage(message));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
final Optional<String> message = context.get("message");
|
||||
|
||||
if (message.isPresent()) {
|
||||
receiver.sendMessage(sender, message.get());
|
||||
} else {
|
||||
sender.selectedChannel(new CarbonWhisperChannel(sender, receiver));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -85,7 +85,7 @@ public class SpyChannelCommand {
|
||||
|
||||
final String message;
|
||||
|
||||
if (user.spyingwhispers()) {
|
||||
if (user.spyingWhispers()) {
|
||||
user.spyingWhispers(false);
|
||||
message = this.carbonChat.translations().spyWhispersOff();
|
||||
} else {
|
||||
|
||||
@@ -44,7 +44,7 @@ public final class KeySerializer extends ScalarSerializer<Key> {
|
||||
}
|
||||
|
||||
try {
|
||||
return Key.of(obj.toString());
|
||||
return Key.key(obj.toString());
|
||||
} catch(final InvalidKeyException ex) {
|
||||
throw new ObjectMappingException(ex);
|
||||
}
|
||||
|
||||
+3
-2
@@ -63,7 +63,7 @@ public final class SoundSerializer implements TypeSerializer<Sound> {
|
||||
throw new ObjectMappingException("A name and source are required to deserialize a Sound");
|
||||
}
|
||||
|
||||
return Sound.of(name, source, volume, pitch);
|
||||
return Sound.sound(name, source, volume, pitch);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -72,10 +72,11 @@ public final class SoundSerializer implements TypeSerializer<Sound> {
|
||||
value.setValue(null);
|
||||
return;
|
||||
}
|
||||
|
||||
value.getNode(NAME).setValue(KeySerializer.INSTANCE.type(), obj.name());
|
||||
value.getNode(SOURCE).setValue(SOURCE_TYPE, obj.source());
|
||||
value.getNode(VOLUME).setValue(obj.volume());
|
||||
value.getNode(PITCH).setValue(obj.pitch());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+11
-6
@@ -1,7 +1,8 @@
|
||||
package net.draycia.carbon.listeners.contexts;
|
||||
package net.draycia.carbon.common.contexts;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.channels.TextChannel;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.PreChatFormatEvent;
|
||||
import net.draycia.carbon.api.Context;
|
||||
@@ -26,7 +27,7 @@ public class FilterContext {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.user().permissible() && event.user().hasPermission("carbonchat.filter.exempt")) {
|
||||
if (event.user().hasPermission("carbonchat.filter.exempt")) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -62,13 +63,17 @@ public class FilterContext {
|
||||
}
|
||||
|
||||
private boolean channelUsesFilter(final @NonNull ChatChannel chatChannel) {
|
||||
final Context context = chatChannel.context("filter");
|
||||
if (chatChannel instanceof TextChannel) {
|
||||
final Context context = ((TextChannel) chatChannel).context("filter");
|
||||
|
||||
if (context == null) {
|
||||
return false;
|
||||
if (context == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return context.isBoolean() && context.asBoolean();
|
||||
}
|
||||
|
||||
return context.isBoolean() && context.asBoolean();
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -41,7 +41,7 @@ public class PingHandler {
|
||||
final float volume = carbonChat.carbonSettings().channelPings().volume();
|
||||
final float pitch = carbonChat.carbonSettings().channelPings().pitch();
|
||||
|
||||
event.target().playSound(Sound.of(key, source, volume, pitch));
|
||||
event.target().playSound(Sound.sound(key, source, volume, pitch));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+2
-11
@@ -4,8 +4,6 @@ import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.PrivateMessageEvent;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.event.PostOrders;
|
||||
|
||||
public class WhisperPingHandler {
|
||||
@@ -22,16 +20,9 @@ public class WhisperPingHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!carbonChat.carbonSettings().whisperPings().enabled()) {
|
||||
return;
|
||||
if (carbonChat.carbonSettings().whisperOptions().pings().enabled()) {
|
||||
event.target().playSound(carbonChat.carbonSettings().whisperOptions().pings().sound());
|
||||
}
|
||||
|
||||
final Key key = carbonChat.carbonSettings().whisperPings().sound();
|
||||
final Sound.Source source = carbonChat.carbonSettings().whisperPings().source();
|
||||
final float volume = carbonChat.carbonSettings().whisperPings().volume();
|
||||
final float pitch = carbonChat.carbonSettings().whisperPings().pitch();
|
||||
|
||||
event.sender().playSound(Sound.of(key, source, volume, pitch));
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+5
-9
@@ -1,13 +1,13 @@
|
||||
package net.draycia.carbon.common.messaging;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.channels.TextChannel;
|
||||
import net.draycia.carbon.api.messaging.MessageService;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.UUID;
|
||||
@@ -21,13 +21,9 @@ public class MessageManager {
|
||||
@NonNull
|
||||
private final MessageService messageService;
|
||||
|
||||
@NonNull
|
||||
private final GsonComponentSerializer gsonSerializer;
|
||||
|
||||
public MessageManager(final @NonNull CarbonChat carbonChat, final @NonNull MessageService messageService) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.messageService = messageService;
|
||||
this.gsonSerializer = this.carbonChat.messageProcessor().audiences().gsonSerializer();
|
||||
|
||||
this.registerDefaultListeners();
|
||||
}
|
||||
@@ -96,10 +92,10 @@ public class MessageManager {
|
||||
final ChatChannel channel = this.carbonChat.channelRegistry().get(byteArray.readUTF());
|
||||
final ChatUser user = this.carbonChat.userService().wrap(uuid);
|
||||
|
||||
if (channel != null) {
|
||||
final Component component = this.gsonSerializer.deserialize(byteArray.readUTF());
|
||||
if (channel instanceof TextChannel) {
|
||||
final Component component = this.carbonChat.gsonSerializer().deserialize(byteArray.readUTF());
|
||||
|
||||
channel.sendComponent(user, component);
|
||||
((TextChannel) channel).sendComponent(user, component);
|
||||
|
||||
this.carbonChat.messageProcessor().audiences().console().sendMessage(component);
|
||||
}
|
||||
@@ -113,7 +109,7 @@ public class MessageManager {
|
||||
|
||||
if (!target.ignoringUser(uuid)) {
|
||||
target.replyTarget(uuid);
|
||||
target.sendMessage(this.gsonSerializer.deserialize(message));
|
||||
target.sendMessage(this.carbonChat.gsonSerializer().deserialize(message));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
+2
-2
@@ -218,8 +218,8 @@ public class MySQLUserService<T extends ChatUser> implements UserService<T> {
|
||||
this.carbonChat.logger().info("Saving user data!");
|
||||
stm.executeUpdateQuery("INSERT INTO sc_users (uuid, channel, muted, shadowmuted, spyingwhispers, nickname) VALUES (?, ?, ?, ?, ?, ?) " +
|
||||
"ON DUPLICATE KEY UPDATE channel = ?, muted = ?, shadowmuted = ?, spyingwhispers = ?, nickname =?",
|
||||
user.uuid().toString(), selectedName, user.muted(), user.shadowMuted(), user.spyingwhispers(), user.nickname(),
|
||||
selectedName, user.muted(), user.shadowMuted(), user.spyingwhispers(), user.nickname());
|
||||
user.uuid().toString(), selectedName, user.muted(), user.shadowMuted(), user.spyingWhispers(), user.nickname(),
|
||||
selectedName, user.muted(), user.shadowMuted(), user.spyingWhispers(), user.nickname());
|
||||
|
||||
this.carbonChat.logger().info("Saving user channel settings!");
|
||||
// Save user channel settings
|
||||
|
||||
@@ -19,8 +19,8 @@ public final class ColorUtils {
|
||||
|
||||
@Nullable
|
||||
public static TextColor parseColor(@Nullable final ChatUser user, @Nullable String input) {
|
||||
if (input == null) {
|
||||
input = "white";
|
||||
if (input == null || input.isEmpty()) {
|
||||
return NamedTextColor.WHITE;
|
||||
}
|
||||
|
||||
// TODO: find out way to do this
|
||||
|
||||
@@ -2,10 +2,15 @@ package net.draycia.carbon.common.utils;
|
||||
|
||||
import com.intellectualsites.commands.arguments.CommandArgument;
|
||||
import com.intellectualsites.commands.arguments.parser.ArgumentParseResult;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.channels.TextChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.users.UserService;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.Queue;
|
||||
|
||||
public final class CommandUtils {
|
||||
|
||||
@@ -14,21 +19,24 @@ public final class CommandUtils {
|
||||
}
|
||||
|
||||
// TODO: turn this into a proper class that handles suggestions
|
||||
public static CommandArgument<ChatUser, ChatChannel> channelArgument() {
|
||||
return CommandArgument.<ChatUser, ChatChannel>ofType(ChatChannel.class, "channel")
|
||||
public static CommandArgument<ChatUser, TextChannel> channelArgument() {
|
||||
return CommandArgument.<ChatUser, TextChannel>ofType(TextChannel.class, "channel")
|
||||
.asRequired()
|
||||
.withParser((c, i) -> {
|
||||
final String input = i.peek();
|
||||
final String input = i.poll();
|
||||
|
||||
if (input == null) {
|
||||
// TODO: make exception messages configurable
|
||||
return ArgumentParseResult.failure(new IllegalArgumentException("Channel cannot be null"));
|
||||
}
|
||||
|
||||
final ChatChannel channel = CarbonChatProvider.carbonChat()
|
||||
.channelRegistry().get(input);
|
||||
|
||||
if (channel != null) {
|
||||
return ArgumentParseResult.success(channel);
|
||||
if (channel instanceof TextChannel) {
|
||||
return ArgumentParseResult.success((TextChannel) channel);
|
||||
} else if (channel != null) {
|
||||
return ArgumentParseResult.failure(new IllegalArgumentException("Channel is not public!"));
|
||||
} else {
|
||||
return ArgumentParseResult.failure(new IllegalArgumentException("Channel does not exist"));
|
||||
}
|
||||
@@ -39,22 +47,7 @@ public final class CommandUtils {
|
||||
public static CommandArgument<ChatUser, ChatUser> optionalChatUserArgument() {
|
||||
return CommandArgument.<ChatUser, ChatUser>ofType(ChatUser.class, "user")
|
||||
.asOptional()
|
||||
.withParser((c, i) -> {
|
||||
final String input = i.peek();
|
||||
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new IllegalArgumentException("Player cannot be null"));
|
||||
}
|
||||
|
||||
final UserService<?> userService = CarbonChatProvider.carbonChat().userService();
|
||||
final ChatUser user = userService.wrap(userService.resolve(input));
|
||||
|
||||
if (user != null) {
|
||||
return ArgumentParseResult.success(user);
|
||||
} else {
|
||||
return ArgumentParseResult.failure(new IllegalArgumentException("Player does not exist"));
|
||||
}
|
||||
})
|
||||
.withParser(CommandUtils::parse)
|
||||
.build();
|
||||
}
|
||||
|
||||
@@ -62,23 +55,24 @@ public final class CommandUtils {
|
||||
public static CommandArgument<ChatUser, ChatUser> chatUserArgument() {
|
||||
return CommandArgument.<ChatUser, ChatUser>ofType(ChatUser.class, "user")
|
||||
.asRequired()
|
||||
.withParser((c, i) -> {
|
||||
final String input = i.peek();
|
||||
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new IllegalArgumentException("Player cannot be null"));
|
||||
}
|
||||
|
||||
final UserService<?> userService = CarbonChatProvider.carbonChat().userService();
|
||||
final ChatUser user = userService.wrap(userService.resolve(input));
|
||||
|
||||
if (user != null) {
|
||||
return ArgumentParseResult.success(user);
|
||||
} else {
|
||||
return ArgumentParseResult.failure(new IllegalArgumentException("Player does not exist"));
|
||||
}
|
||||
})
|
||||
.withParser(CommandUtils::parse)
|
||||
.build();
|
||||
}
|
||||
|
||||
private static @NonNull ArgumentParseResult<ChatUser> parse(final CommandContext<ChatUser> c, final Queue<String> i) {
|
||||
final String input = i.poll();
|
||||
|
||||
if (input == null) {
|
||||
return ArgumentParseResult.failure(new IllegalArgumentException("Player cannot be null"));
|
||||
}
|
||||
|
||||
final UserService<?> userService = CarbonChatProvider.carbonChat().userService();
|
||||
final ChatUser user = userService.wrap(userService.resolve(input));
|
||||
|
||||
if (user != null) {
|
||||
return ArgumentParseResult.success(user);
|
||||
} else {
|
||||
return ArgumentParseResult.failure(new IllegalArgumentException("Player does not exist"));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user