mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
Add checkerframework compilation checking (#109)
* Reorder nullability annotations again * Add checker validation to API module * Add checker validation to Common module * Begin checker validation for Bukkit module * It compiles!
This commit is contained in:
1 parent
3314a51df8
commit
d9ab711adc
83 files changed
+1127
-717
No files matched your search
+7
-7
@@ -14,20 +14,20 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
public class AdventureManager implements MessageProcessor {
|
||||
|
||||
private @NonNull final AudienceProvider provider;
|
||||
private final @NonNull AudienceProvider provider;
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
private @NonNull final FormatType formatType;
|
||||
private final @NonNull FormatType formatType;
|
||||
|
||||
public AdventureManager(@NonNull final AudienceProvider provider, @NonNull 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, @NonNull final String @NonNull ... placeholders) {
|
||||
public @NonNull Component processMessage(final @Nullable String input, final @NonNull String @NonNull ... placeholders) {
|
||||
if (input == null || input.trim().isEmpty()) {
|
||||
return Component.empty();
|
||||
}
|
||||
@@ -52,11 +52,11 @@ public class AdventureManager implements MessageProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private @NonNull Component processMojang(@NonNull final String input) {
|
||||
private @NonNull Component processMojang(final @NonNull String input) {
|
||||
return this.carbonChat.gsonSerializer().deserialize(input);
|
||||
}
|
||||
|
||||
private @NonNull String processPlaceholders(@NonNull String input, @NonNull final String @NonNull ... placeholders) {
|
||||
private @NonNull String processPlaceholders(@NonNull String input, final @NonNull String @NonNull ... placeholders) {
|
||||
for (int i = 0; i < placeholders.length; i += 2) {
|
||||
final String placeholder = placeholders[i];
|
||||
final String replacement = placeholders[i + 1];
|
||||
|
||||
+75
-51
@@ -35,11 +35,11 @@ import java.util.regex.Pattern;
|
||||
|
||||
public class CarbonChatChannel implements TextChannel {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
private @NonNull final ChannelOptions options;
|
||||
private final @NonNull ChannelOptions options;
|
||||
|
||||
public CarbonChatChannel(@NonNull final CarbonChat carbonChat, @Nullable final ChannelOptions options) {
|
||||
public CarbonChatChannel(final @NonNull CarbonChat carbonChat, final @NonNull ChannelOptions options) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.options = options;
|
||||
}
|
||||
@@ -53,7 +53,7 @@ public class CarbonChatChannel implements TextChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean testContext(@NonNull final PlayerUser sender, @NonNull final PlayerUser target) {
|
||||
public boolean testContext(final @NonNull PlayerUser sender, final @NonNull PlayerUser target) {
|
||||
final ReceiverContextEvent event = new ReceiverContextEvent(this, sender, target);
|
||||
|
||||
CarbonEvents.post(event);
|
||||
@@ -62,7 +62,7 @@ public class CarbonChatChannel implements TextChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlayerUse(@NonNull final PlayerUser user) {
|
||||
public boolean canPlayerUse(final @NonNull PlayerUser user) {
|
||||
return user.hasPermission("carbonchat.channels." + this.name() + ".use");
|
||||
}
|
||||
|
||||
@@ -79,7 +79,7 @@ public class CarbonChatChannel implements TextChannel {
|
||||
return audience;
|
||||
}
|
||||
|
||||
// private void updateUserNickname(@NonNull final ChatUser user) {
|
||||
// private void updateUserNickname(final @NonNull ChatUser user) {
|
||||
// final Player player = Bukkit.getPlayer(user.uuid());
|
||||
//
|
||||
// if (player != null) {
|
||||
@@ -99,7 +99,7 @@ public class CarbonChatChannel implements TextChannel {
|
||||
// }
|
||||
|
||||
@Override
|
||||
public @NonNull Map<CarbonUser, Component> parseMessage(@NonNull final PlayerUser user, @NonNull final Collection<@NonNull PlayerUser> recipients, @NonNull final String message, final boolean fromRemote) {
|
||||
public @NonNull Map<CarbonUser, Component> parseMessage(final @NonNull PlayerUser user, final @NonNull Collection<@NonNull PlayerUser> recipients, final @NonNull String message, final boolean fromRemote) {
|
||||
//this.updateUserNickname(user);
|
||||
|
||||
final MessageContextEvent event = new MessageContextEvent(this, user);
|
||||
@@ -124,13 +124,7 @@ public class CarbonChatChannel implements TextChannel {
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
final String displayName;
|
||||
|
||||
if (user.nickname() != null) {
|
||||
displayName = user.nickname();
|
||||
} else {
|
||||
displayName = user.displayName();
|
||||
}
|
||||
final String displayName = user.nickname();
|
||||
|
||||
final Map<CarbonUser, Component> users = new HashMap<>();
|
||||
|
||||
@@ -166,9 +160,14 @@ public class CarbonChatChannel implements TextChannel {
|
||||
|
||||
CarbonEvents.post(newEvent);
|
||||
|
||||
users.put(newEvent.target(), newEvent.component());
|
||||
final PlayerUser targetUser = newEvent.target();
|
||||
|
||||
if (targetUser != null) {
|
||||
users.put(targetUser, newEvent.component());
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: ChatFormatEvent ConsoleUser support for target, specify ConsoleUser as target
|
||||
final ChatFormatEvent consoleFormatEvent = new ChatFormatEvent(user, null, this, preFormatEvent.format(),
|
||||
preFormatEvent.message());
|
||||
|
||||
@@ -188,7 +187,11 @@ public class CarbonChatChannel implements TextChannel {
|
||||
CarbonEvents.post(consoleEvent);
|
||||
|
||||
if (!consoleEvent.cancelled()) {
|
||||
users.put(this.carbonChat.userService().consoleUser(), consoleEvent.component());
|
||||
final ConsoleUser consoleUser = this.carbonChat.userService().consoleUser();
|
||||
|
||||
if (consoleUser != null) {
|
||||
users.put(consoleUser, consoleEvent.component());
|
||||
}
|
||||
}
|
||||
|
||||
if (user.online() && !fromRemote && this.crossServer()) {
|
||||
@@ -199,8 +202,8 @@ public class CarbonChatChannel implements TextChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendComponents(@NonNull final Identity identity,
|
||||
@NonNull final Map<? extends CarbonUser, Component> components) {
|
||||
public void sendComponents(final @NonNull Identity identity,
|
||||
final @NonNull Map<? extends CarbonUser, Component> components) {
|
||||
for (final Map.Entry<? extends CarbonUser, Component> entry : components.entrySet()) {
|
||||
if (entry.getValue().equals(Component.empty())) {
|
||||
continue;
|
||||
@@ -211,8 +214,8 @@ public class CarbonChatChannel implements TextChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendComponentsAndLog(@NonNull final Identity identity,
|
||||
@NonNull final Map<? extends CarbonUser, Component> components) {
|
||||
public void sendComponentsAndLog(final @NonNull Identity identity,
|
||||
final @NonNull Map<? extends CarbonUser, Component> components) {
|
||||
for (final Map.Entry<? extends CarbonUser, Component> entry : components.entrySet()) {
|
||||
if (entry.getValue().equals(Component.empty())) {
|
||||
continue;
|
||||
@@ -228,11 +231,11 @@ public class CarbonChatChannel implements TextChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Map<CarbonUser, Component> parseMessage(@NonNull final PlayerUser user, @NonNull final String message, final boolean fromRemote) {
|
||||
public @NonNull Map<CarbonUser, Component> parseMessage(final @NonNull PlayerUser user, final @NonNull String message, final boolean fromRemote) {
|
||||
return this.parseMessage(user, this.audiences(), message, fromRemote);
|
||||
}
|
||||
|
||||
public @Nullable String format(@NonNull final PlayerUser user) {
|
||||
public @NonNull String format(final @NonNull PlayerUser user) {
|
||||
for (final String group : this.groupOverrides()) {
|
||||
if (this.userHasGroup(user, group)) {
|
||||
final String format = this.format(group);
|
||||
@@ -250,7 +253,7 @@ public class CarbonChatChannel implements TextChannel {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean userHasGroup(@NonNull final PlayerUser user, @NonNull final String group) {
|
||||
private boolean userHasGroup(final @NonNull PlayerUser user, final @NonNull String group) {
|
||||
if (user.hasGroup(group)) {
|
||||
return true;
|
||||
}
|
||||
@@ -262,7 +265,7 @@ public class CarbonChatChannel implements TextChannel {
|
||||
return false;
|
||||
}
|
||||
|
||||
private @NonNull String firstFoundUserFormat(@NonNull final PlayerUser user) {
|
||||
private @NonNull String firstFoundUserFormat(final @NonNull PlayerUser user) {
|
||||
for (final Group group : user.groups()) {
|
||||
final String groupFormat = this.format(group);
|
||||
|
||||
@@ -274,8 +277,13 @@ public class CarbonChatChannel implements TextChannel {
|
||||
return this.defaultFormat();
|
||||
}
|
||||
|
||||
private @NonNull String primaryGroupFormat(@NonNull final PlayerUser user) {
|
||||
private @NonNull String primaryGroupFormat(final @NonNull PlayerUser user) {
|
||||
final Group primaryGroup = user.primaryGroup();
|
||||
|
||||
if (primaryGroup == null) {
|
||||
return this.defaultFormat();
|
||||
}
|
||||
|
||||
final String primaryGroupFormat = this.format(primaryGroup);
|
||||
|
||||
if (primaryGroupFormat != null) {
|
||||
@@ -286,20 +294,32 @@ public class CarbonChatChannel implements TextChannel {
|
||||
}
|
||||
|
||||
private @NonNull String defaultFormat() {
|
||||
return this.format(this.defaultFormatName());
|
||||
final String defaultFormatName = this.defaultFormatName();
|
||||
|
||||
if (defaultFormatName == null) {
|
||||
return "<<displayname>> <message>";
|
||||
}
|
||||
|
||||
final String defaultFormat = this.format(defaultFormatName);
|
||||
|
||||
if (defaultFormat == null) {
|
||||
return "<<displayname>> <message>";
|
||||
}
|
||||
|
||||
return defaultFormat;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String format(@NonNull final Group group) {
|
||||
public @Nullable String format(final @NonNull Group group) {
|
||||
return this.format(group.getName());
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String format(@NonNull final String group) {
|
||||
public @Nullable String format(final @NonNull String group) {
|
||||
return this.options().format(group);
|
||||
}
|
||||
|
||||
private boolean isUserSpying(@NonNull final PlayerUser sender, @NonNull final PlayerUser target) {
|
||||
private boolean isUserSpying(final @NonNull PlayerUser sender, final @NonNull PlayerUser target) {
|
||||
if (!this.canPlayerSee(sender, target, false)) {
|
||||
return target.channelSettings(this).spying();
|
||||
}
|
||||
@@ -308,7 +328,7 @@ public class CarbonChatChannel implements TextChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendComponent(@NonNull final PlayerUser player, @NonNull final Component component) {
|
||||
public void sendComponent(final @NonNull PlayerUser player, final @NonNull Component component) {
|
||||
for (final PlayerUser user : this.audiences()) {
|
||||
if (!user.ignoringUser(player)) {
|
||||
user.sendMessage(player.identity(), component);
|
||||
@@ -316,7 +336,7 @@ public class CarbonChatChannel implements TextChannel {
|
||||
}
|
||||
}
|
||||
|
||||
public void sendMessageToBungee(@NonNull final UUID uuid, @NonNull final Component component) {
|
||||
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.gsonSerializer().serialize(component));
|
||||
@@ -324,7 +344,7 @@ public class CarbonChatChannel implements TextChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlayerSee(@NonNull final PlayerUser target, final boolean checkSpying) {
|
||||
public boolean canPlayerSee(final @NonNull PlayerUser target, final boolean checkSpying) {
|
||||
if (checkSpying && target.hasPermission("carbonchat.spy." + this.name())) {
|
||||
if (target.channelSettings(this).spying()) {
|
||||
return true;
|
||||
@@ -342,7 +362,7 @@ public class CarbonChatChannel implements TextChannel {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean canPlayerSee(@NonNull final PlayerUser sender, @NonNull final PlayerUser target, final boolean checkSpying) {
|
||||
public boolean canPlayerSee(final @NonNull PlayerUser sender, final @NonNull PlayerUser target, final boolean checkSpying) {
|
||||
|
||||
if (!this.canPlayerSee(target, checkSpying)) {
|
||||
return false;
|
||||
@@ -356,7 +376,7 @@ public class CarbonChatChannel implements TextChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable TextColor channelColor(@NonNull final CarbonUser user) {
|
||||
public @NonNull TextColor channelColor(final @NonNull CarbonUser user) {
|
||||
if (user instanceof PlayerUser) {
|
||||
final TextColor userColor = ((PlayerUser) user).channelSettings(this).color();
|
||||
|
||||
@@ -367,18 +387,22 @@ public class CarbonChatChannel implements TextChannel {
|
||||
|
||||
final String input = this.options().color();
|
||||
|
||||
final TextColor color = ColorUtils.parseColor(user, input);
|
||||
if (input != null) {
|
||||
final TextColor color = ColorUtils.parseColor(user, input);
|
||||
|
||||
if (color == null) {
|
||||
if (this.carbonChat.carbonSettings().showTips()) {
|
||||
this.carbonChat.logger().error("Tip: Channel color found (" + input + ") is invalid!");
|
||||
this.carbonChat.logger().error("Falling back to #FFFFFF");
|
||||
if (color == null) {
|
||||
if (this.carbonChat.carbonSettings().showTips()) {
|
||||
this.carbonChat.logger().error("Tip: Channel color found (" + input + ") is invalid!");
|
||||
this.carbonChat.logger().error("Falling back to #FFFFFF");
|
||||
}
|
||||
|
||||
return NamedTextColor.WHITE;
|
||||
}
|
||||
|
||||
return NamedTextColor.WHITE;
|
||||
return color;
|
||||
}
|
||||
|
||||
return color;
|
||||
return NamedTextColor.WHITE;
|
||||
}
|
||||
|
||||
public @Nullable String defaultFormatName() {
|
||||
@@ -426,47 +450,47 @@ public class CarbonChatChannel implements TextChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String switchMessage() {
|
||||
public @NonNull String switchMessage() {
|
||||
return this.options().switchMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String switchOtherMessage() {
|
||||
public @NonNull String switchOtherMessage() {
|
||||
return this.options().switchOtherMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String switchFailureMessage() {
|
||||
public @NonNull String switchFailureMessage() {
|
||||
return this.options().switchFailureMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String cannotIgnoreMessage() {
|
||||
public @NonNull String cannotIgnoreMessage() {
|
||||
return this.options().cannotIgnoreMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String toggleOffMessage() {
|
||||
public @NonNull String toggleOffMessage() {
|
||||
return this.options().toggleOffMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String toggleOnMessage() {
|
||||
public @NonNull String toggleOnMessage() {
|
||||
return this.options().toggleOnMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String toggleOtherOnMessage() {
|
||||
public @NonNull String toggleOtherOnMessage() {
|
||||
return this.options().toggleOtherOnMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String toggleOtherOffMessage() {
|
||||
public @NonNull String toggleOtherOffMessage() {
|
||||
return this.options().toggleOtherOffMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String cannotUseMessage() {
|
||||
public @NonNull String cannotUseMessage() {
|
||||
return this.options().cannotUseMessage();
|
||||
}
|
||||
|
||||
@@ -491,7 +515,7 @@ public class CarbonChatChannel implements TextChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Context context(@NonNull final String key) {
|
||||
public @Nullable Context context(final @NonNull String key) {
|
||||
return this.options().context(key);
|
||||
}
|
||||
|
||||
|
||||
+59
-56
@@ -26,12 +26,12 @@ import java.util.regex.Pattern;
|
||||
|
||||
public class CarbonWhisperChannel implements WhisperChannel {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
private @NonNull final PlayerUser sender;
|
||||
private @NonNull final PlayerUser audience;
|
||||
private final @NonNull PlayerUser sender;
|
||||
private final @NonNull PlayerUser audience;
|
||||
|
||||
public CarbonWhisperChannel(@NonNull final PlayerUser sender, @NonNull final PlayerUser audience) {
|
||||
public CarbonWhisperChannel(final @NonNull PlayerUser sender, final @NonNull PlayerUser audience) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
this.sender = sender;
|
||||
this.audience = audience;
|
||||
@@ -48,26 +48,34 @@ public class CarbonWhisperChannel implements WhisperChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable TextColor channelColor(@NonNull final CarbonUser user) {
|
||||
public @NonNull TextColor channelColor(final @NonNull CarbonUser user) {
|
||||
return NamedTextColor.WHITE;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Map<CarbonUser, Component> parseMessage(@NonNull final PlayerUser user, @NonNull final String message,
|
||||
public @NonNull Map<CarbonUser, Component> parseMessage(final @NonNull PlayerUser user, final @NonNull String message,
|
||||
final boolean fromRemote) {
|
||||
return this.parseMessage(user, Collections.singleton(this.audience()), message, fromRemote);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NonNull Map<CarbonUser, Component> parseMessage(@NonNull final PlayerUser user,
|
||||
@NonNull final Collection<@NonNull PlayerUser> recipients,
|
||||
@NonNull final String message, final boolean fromRemote) {
|
||||
public @NonNull Map<CarbonUser, Component> parseMessage(final @NonNull PlayerUser user,
|
||||
final @NonNull Collection<@NonNull PlayerUser> recipients,
|
||||
final @NonNull String message, final boolean fromRemote) {
|
||||
final Map<CarbonUser, Component> result = new HashMap<>();
|
||||
|
||||
// Formats
|
||||
final String senderFormat = this.senderFormat();
|
||||
final String receiverFormat = this.receiverFormat();
|
||||
|
||||
if (senderFormat == null) {
|
||||
throw new IllegalArgumentException("Sender format (whispers) not found!");
|
||||
}
|
||||
|
||||
if (receiverFormat == null) {
|
||||
throw new IllegalArgumentException("Receiver format (whispers) not found!");
|
||||
}
|
||||
|
||||
final ChatFormatEvent senderFormatEvent = new ChatFormatEvent(this.sender, this.sender, this, senderFormat, message);
|
||||
|
||||
CarbonEvents.post(senderFormatEvent);
|
||||
@@ -85,21 +93,8 @@ public class CarbonWhisperChannel implements WhisperChannel {
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
final String senderName = this.sender.nickname();
|
||||
final String receiverName = this.audience.nickname();
|
||||
|
||||
// Components
|
||||
final TextComponent senderComponent = (TextComponent) this.carbonChat.messageProcessor().processMessage(
|
||||
@@ -134,27 +129,35 @@ public class CarbonWhisperChannel implements WhisperChannel {
|
||||
|
||||
result.put(this.audience, receiverComponentEvent.component());
|
||||
|
||||
final ChatFormatEvent consoleFormatEvent = new ChatFormatEvent(this.sender, null, this,
|
||||
this.consoleFormat(), message);
|
||||
final String consoleFormatString = this.consoleFormat();
|
||||
|
||||
CarbonEvents.post(consoleFormatEvent);
|
||||
if (consoleFormatString != null) {
|
||||
final ChatFormatEvent consoleFormatEvent = new ChatFormatEvent(this.sender, null, this,
|
||||
consoleFormatString, message);
|
||||
|
||||
final TextComponent consoleFormat = (TextComponent) this.carbonChat.messageProcessor().processMessage(
|
||||
consoleFormatEvent.format(),
|
||||
"senderdisplayname", senderName,
|
||||
"sender", this.sender.name(),
|
||||
"receiverdisplayname", receiverName,
|
||||
"receiver", this.audience.name(),
|
||||
"phase", Long.toString(System.currentTimeMillis() % 25),
|
||||
"message", senderFormatEvent.message());
|
||||
CarbonEvents.post(consoleFormatEvent);
|
||||
|
||||
final ChatComponentEvent consoleEvent = new ChatComponentEvent(this.sender, null, this, consoleFormat,
|
||||
consoleFormatEvent.message());
|
||||
final TextComponent consoleFormat = (TextComponent) this.carbonChat.messageProcessor().processMessage(
|
||||
consoleFormatEvent.format(),
|
||||
"senderdisplayname", senderName,
|
||||
"sender", this.sender.name(),
|
||||
"receiverdisplayname", receiverName,
|
||||
"receiver", this.audience.name(),
|
||||
"phase", Long.toString(System.currentTimeMillis() % 25),
|
||||
"message", senderFormatEvent.message());
|
||||
|
||||
CarbonEvents.post(consoleEvent);
|
||||
final ChatComponentEvent consoleEvent = new ChatComponentEvent(this.sender, null, this, consoleFormat,
|
||||
consoleFormatEvent.message());
|
||||
|
||||
if (!consoleEvent.cancelled()) {
|
||||
result.put(this.carbonChat.userService().consoleUser(), consoleEvent.component());
|
||||
CarbonEvents.post(consoleEvent);
|
||||
|
||||
if (!consoleEvent.cancelled()) {
|
||||
final ConsoleUser consoleUser = this.carbonChat.userService().consoleUser();
|
||||
|
||||
if (consoleUser != null) {
|
||||
result.put(consoleUser, consoleEvent.component());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.sender.replyTarget(this.audience);
|
||||
@@ -164,31 +167,31 @@ public class CarbonWhisperChannel implements WhisperChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlayerUse(@NonNull final PlayerUser user) {
|
||||
public boolean canPlayerUse(final @NonNull PlayerUser user) {
|
||||
return user.equals(this.sender);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlayerSee(@NonNull final PlayerUser sender, @NonNull final PlayerUser target, final boolean checkSpying) {
|
||||
public boolean canPlayerSee(final @NonNull PlayerUser sender, final @NonNull PlayerUser target, final boolean checkSpying) {
|
||||
return (checkSpying && target.spyingWhispers()) || (sender.equals(this.sender) && target.equals(this.audience));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canPlayerSee(@NonNull final PlayerUser target, final boolean checkSpying) {
|
||||
public boolean canPlayerSee(final @NonNull PlayerUser target, final boolean checkSpying) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendComponents(@NonNull final Identity identity,
|
||||
@NonNull final Map<? extends CarbonUser, Component> components) {
|
||||
public void sendComponents(final @NonNull Identity identity,
|
||||
final @NonNull Map<? extends CarbonUser, Component> components) {
|
||||
for (final Map.Entry<? extends CarbonUser, Component> entry : components.entrySet()) {
|
||||
entry.getKey().sendMessage(identity, entry.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendComponentsAndLog(@NonNull final Identity identity,
|
||||
@NonNull final Map<? extends CarbonUser, Component> components) {
|
||||
public void sendComponentsAndLog(final @NonNull Identity identity,
|
||||
final @NonNull Map<? extends CarbonUser, Component> components) {
|
||||
for (final Map.Entry<? extends CarbonUser, Component> entry : components.entrySet()) {
|
||||
entry.getKey().sendMessage(Identity.nil(), entry.getValue());
|
||||
|
||||
@@ -232,47 +235,47 @@ public class CarbonWhisperChannel implements WhisperChannel {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String switchMessage() {
|
||||
public @NonNull String switchMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().switchMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String switchOtherMessage() {
|
||||
public @NonNull String switchOtherMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().switchOtherMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String switchFailureMessage() {
|
||||
public @NonNull String switchFailureMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().switchFailureMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String cannotIgnoreMessage() {
|
||||
public @NonNull String cannotIgnoreMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().cannotIgnoreMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String toggleOffMessage() {
|
||||
public @NonNull String toggleOffMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().toggleOffMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String toggleOnMessage() {
|
||||
public @NonNull String toggleOnMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().toggleOnMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String toggleOtherOnMessage() {
|
||||
public @NonNull String toggleOtherOnMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().toggleOtherOnMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String toggleOtherOffMessage() {
|
||||
public @NonNull String toggleOtherOffMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().toggleOtherOffMessage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String cannotUseMessage() {
|
||||
public @NonNull String cannotUseMessage() {
|
||||
return this.carbonChat.carbonSettings().whisperOptions().cannotUseMessage();
|
||||
}
|
||||
}
|
||||
+11
-11
@@ -16,23 +16,23 @@ import java.util.Map;
|
||||
|
||||
public class ChannelManager {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
private @NonNull final ChannelRegistry registry;
|
||||
private final @NonNull ChannelRegistry registry;
|
||||
|
||||
@Nullable
|
||||
@MonotonicNonNull
|
||||
private String defaultChannelKey = null;
|
||||
private @MonotonicNonNull String defaultChannelKey = null;
|
||||
|
||||
public ChannelManager(@NonNull final CarbonChat carbonChat) {
|
||||
@SuppressWarnings("method.invocation.invalid")
|
||||
public ChannelManager(final @NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.registry = new ChannelRegistry();
|
||||
|
||||
this.carbonChat.logger().info("Loading channels!");
|
||||
this.reload();
|
||||
|
||||
this.loadChannels();
|
||||
}
|
||||
|
||||
public @Nullable ChatChannel loadChannel(@NonNull final ChannelOptions settings) {
|
||||
public @Nullable ChatChannel loadChannel(final @NonNull ChannelOptions settings) {
|
||||
final ChatChannel channel = new CarbonChatChannel(this.carbonChat, settings);
|
||||
|
||||
final String name = settings.name();
|
||||
@@ -46,7 +46,7 @@ public class ChannelManager {
|
||||
return channel;
|
||||
}
|
||||
|
||||
public void registerChannel(@NonNull final ChatChannel channel) {
|
||||
public void registerChannel(final @NonNull ChatChannel channel) {
|
||||
this.registry().register(channel.key(), channel);
|
||||
|
||||
if (channel instanceof TextChannel) {
|
||||
@@ -71,7 +71,7 @@ public class ChannelManager {
|
||||
return null;
|
||||
}
|
||||
|
||||
public @Nullable ChatChannel channelOrDefault(@Nullable final String key) {
|
||||
public @Nullable ChatChannel channelOrDefault(final @Nullable String key) {
|
||||
if (key == null) {
|
||||
return this.defaultChannel();
|
||||
}
|
||||
@@ -85,7 +85,7 @@ public class ChannelManager {
|
||||
return channel;
|
||||
}
|
||||
|
||||
private void reload() {
|
||||
private void loadChannels() {
|
||||
this.carbonChat.logger().info("Channels found: " +
|
||||
this.carbonChat.channelSettings().channelOptions().size());
|
||||
|
||||
|
||||
+7
-6
@@ -13,13 +13,14 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class AliasedChannelCommand {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
private @NonNull final TextChannel chatChannel;
|
||||
private final @NonNull TextChannel chatChannel;
|
||||
|
||||
private @NonNull final String commandName;
|
||||
private final @NonNull String commandName;
|
||||
|
||||
public AliasedChannelCommand(@NonNull final CommandManager<CarbonUser> commandManager, @NonNull final TextChannel chatChannel) {
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
public AliasedChannelCommand(final @NonNull CommandManager<CarbonUser> commandManager, final @NonNull TextChannel chatChannel) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
this.chatChannel = chatChannel;
|
||||
this.commandName = chatChannel.key();
|
||||
@@ -44,7 +45,7 @@ public class AliasedChannelCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private void channel(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void channel(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final PlayerUser user = (PlayerUser) context.getSender();
|
||||
|
||||
if (user.channelSettings(this.chatChannel()).ignored()) {
|
||||
@@ -58,7 +59,7 @@ public class AliasedChannelCommand {
|
||||
user.selectedChannel(this.chatChannel());
|
||||
}
|
||||
|
||||
private void sendMessage(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void sendMessage(final @NonNull CommandContext<CarbonUser> context) {
|
||||
context.<String>getOptional("message").ifPresent(message -> {
|
||||
this.chatChannel().sendComponentsAndLog(
|
||||
context.getSender().identity(),
|
||||
|
||||
+6
-5
@@ -16,14 +16,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class ChannelCommand {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public ChannelCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
public ChannelCommand(final @NonNull CommandManager<CarbonUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("channel");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
if (commandSettings == null || !commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -49,7 +50,7 @@ public class ChannelCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private void channel(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void channel(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final PlayerUser user = (PlayerUser) context.getSender();
|
||||
final TextChannel channel = context.get("channel");
|
||||
|
||||
@@ -64,7 +65,7 @@ public class ChannelCommand {
|
||||
user.selectedChannel(channel);
|
||||
}
|
||||
|
||||
private void sendMessage(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void sendMessage(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final ChatChannel channel = context.get("channel");
|
||||
final String message = context.get("message");
|
||||
|
||||
|
||||
+9
-8
@@ -21,14 +21,15 @@ import java.util.regex.Pattern;
|
||||
|
||||
public class ChannelListCommand {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public ChannelListCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
public ChannelListCommand(final @NonNull CommandManager<CarbonUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("channellist");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
if (commandSettings == null || !commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -52,11 +53,11 @@ public class ChannelListCommand {
|
||||
);
|
||||
}
|
||||
|
||||
public void channelListSelf(@NonNull final CommandContext<CarbonUser> context) {
|
||||
public void channelListSelf(final @NonNull CommandContext<CarbonUser> context) {
|
||||
this.listAndSend(context.getSender(), (PlayerUser) context.getSender(), this.carbonChat.channelRegistry().iterator());
|
||||
}
|
||||
|
||||
public void channelListOther(@NonNull final CommandContext<CarbonUser> context) {
|
||||
public void channelListOther(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final CarbonUser sender = context.getSender();
|
||||
final PlayerUser user = context.get("user");
|
||||
|
||||
@@ -73,8 +74,8 @@ public class ChannelListCommand {
|
||||
this.listAndSend(sender, user, allChannels);
|
||||
}
|
||||
|
||||
private void listAndSend(@NonNull final CarbonUser sender, @NonNull final PlayerUser user,
|
||||
@NonNull final Iterator<ChatChannel> allChannels) {
|
||||
private void listAndSend(final @NonNull CarbonUser sender, final @NonNull PlayerUser user,
|
||||
final @NonNull Iterator<ChatChannel> allChannels) {
|
||||
ChatChannel channel;
|
||||
final List<ChatChannel> canSee = new ArrayList<>();
|
||||
final List<ChatChannel> cannotSee = new ArrayList<>();
|
||||
@@ -114,7 +115,7 @@ public class ChannelListCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private void makeList(@NonNull final Iterator<@NonNull ChatChannel> iterator, final TextComponent.@NonNull Builder list) {
|
||||
private void makeList(final @NonNull Iterator<@NonNull ChatChannel> iterator, final TextComponent.@NonNull Builder list) {
|
||||
final String listSeparator = this.carbonChat.translations().channelListSeparator();
|
||||
final Component listSeparatorComponent = Component.text(listSeparator);
|
||||
|
||||
|
||||
+5
-4
@@ -12,14 +12,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class ChatReloadCommand {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public ChatReloadCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
public ChatReloadCommand(final @NonNull CommandManager<CarbonUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("chatreload");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
if (commandSettings == null || !commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -33,7 +34,7 @@ public class ChatReloadCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private void reloadConfig(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void reloadConfig(final @NonNull CommandContext<CarbonUser> context) {
|
||||
this.carbonChat.reloadConfig();
|
||||
|
||||
final Component message = this.carbonChat.messageProcessor()
|
||||
|
||||
+7
-6
@@ -14,14 +14,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class ClearChatCommand {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public ClearChatCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
public ClearChatCommand(final @NonNull CommandManager<CarbonUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("clearchat");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
if (commandSettings == null || !commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -45,7 +46,7 @@ public class ClearChatCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private void clearChat(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void clearChat(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final String sender = context.getSender().name();
|
||||
final String format = this.carbonChat.moderationSettings().clearChat().message();
|
||||
final Component component = this.carbonChat.messageProcessor().processMessage(format, "br", "\n");
|
||||
@@ -55,7 +56,7 @@ public class ClearChatCommand {
|
||||
}
|
||||
}
|
||||
|
||||
private void clearChatPlayer(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void clearChatPlayer(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final PlayerUser target = context.get("user");
|
||||
final String sender = context.getSender().name();
|
||||
final String format = this.carbonChat.moderationSettings().clearChat().message();
|
||||
@@ -64,7 +65,7 @@ public class ClearChatCommand {
|
||||
this.clearUserChat(target, component, sender);
|
||||
}
|
||||
|
||||
private void clearUserChat(@NonNull final CarbonUser user, @NonNull final Component component, @NonNull final String sender) {
|
||||
private void clearUserChat(final @NonNull CarbonUser user, final @NonNull Component component, final @NonNull String sender) {
|
||||
if (user.hasPermission("carbonchat.clearchat.exempt")) {
|
||||
final String message = this.carbonChat.translations().clearExempt();
|
||||
user.sendMessage(Identity.nil(), this.carbonChat.messageProcessor()
|
||||
|
||||
+5
-4
@@ -14,14 +14,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class IgnoreCommand {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public IgnoreCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
public IgnoreCommand(final @NonNull CommandManager<CarbonUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("ignore");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
if (commandSettings == null || !commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,7 +37,7 @@ public class IgnoreCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private void ignoreUser(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void ignoreUser(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final PlayerUser sender = (PlayerUser) context.getSender();
|
||||
final PlayerUser targetUser = context.get("user");
|
||||
|
||||
|
||||
@@ -13,14 +13,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class MeCommand {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public MeCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
public MeCommand(final @NonNull CommandManager<CarbonUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("me");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
if (commandSettings == null || !commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -35,7 +36,7 @@ public class MeCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private void message(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void message(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final PlayerUser user = (PlayerUser) context.getSender();
|
||||
|
||||
final String message = context.<String>get("message").replace("</pre>", "");
|
||||
|
||||
+5
-4
@@ -19,15 +19,16 @@ import java.util.Optional;
|
||||
|
||||
public class MessageCommand {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public MessageCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
public MessageCommand(final @NonNull CommandManager<CarbonUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
final CommandSettings commandSettings = carbonChat.commandSettings().get("message");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
if (commandSettings == null || !commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -43,7 +44,7 @@ public class MessageCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private void sendMessage(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void sendMessage(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final PlayerUser sender = (PlayerUser) context.getSender();
|
||||
final PlayerUser receiver = context.get("user");
|
||||
|
||||
|
||||
+14
-5
@@ -15,14 +15,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class MsgToggleCommand {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public MsgToggleCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
public MsgToggleCommand(final @NonNull CommandManager<CarbonUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("msgtoggle");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
if (commandSettings == null || !commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -46,10 +47,14 @@ public class MsgToggleCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private void toggleSelf(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void toggleSelf(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final PlayerUser user = (PlayerUser) context.getSender();
|
||||
final ChatChannel channel = this.carbonChat.channelRegistry().get("whisper");
|
||||
|
||||
if (channel == null) {
|
||||
throw new IllegalArgumentException("Whisper channel not found!");
|
||||
}
|
||||
|
||||
final String message;
|
||||
|
||||
final UserChannelSettings settings = user.channelSettings(channel);
|
||||
@@ -67,11 +72,15 @@ public class MsgToggleCommand {
|
||||
user.sendMessage(Identity.nil(), this.carbonChat.messageProcessor().processMessage(message));
|
||||
}
|
||||
|
||||
private void toggleOther(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void toggleOther(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final CarbonUser sender = context.getSender();
|
||||
final PlayerUser user = context.get("user");
|
||||
final ChatChannel channel = this.carbonChat.channelRegistry().get("whisper");
|
||||
|
||||
if (channel == null) {
|
||||
throw new IllegalArgumentException("Whisper channel not found!");
|
||||
}
|
||||
|
||||
final String message;
|
||||
final String otherMessage;
|
||||
|
||||
|
||||
@@ -14,14 +14,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class MuteCommand {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public MuteCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
public MuteCommand(final @NonNull CommandManager<CarbonUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("mute");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
if (commandSettings == null || !commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,7 +37,7 @@ public class MuteCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private void mute(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void mute(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final CarbonUser user = context.getSender();
|
||||
final PlayerUser target = context.get("user");
|
||||
|
||||
|
||||
+6
-5
@@ -14,14 +14,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class NicknameCommand {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public NicknameCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
public NicknameCommand(final @NonNull CommandManager<CarbonUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("nickname");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
if (commandSettings == null || !commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -47,7 +48,7 @@ public class NicknameCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private void nicknameSelf(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void nicknameSelf(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final PlayerUser user = (PlayerUser) context.getSender();
|
||||
String nickname = context.get("nickname");
|
||||
|
||||
@@ -70,7 +71,7 @@ public class NicknameCommand {
|
||||
"user", user.name(), "sender", context.getSender().name()));
|
||||
}
|
||||
|
||||
private void nicknameOther(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void nicknameOther(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final PlayerUser target = context.get("user");
|
||||
String nickname = context.get("nickname");
|
||||
|
||||
|
||||
+14
-7
@@ -12,16 +12,19 @@ import net.kyori.adventure.identity.Identity;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class ReplyCommand {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public ReplyCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
public ReplyCommand(final @NonNull CommandManager<CarbonUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("reply");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
if (commandSettings == null || !commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,7 +39,7 @@ public class ReplyCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private void reply(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void reply(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final PlayerUser user = (PlayerUser) context.getSender();
|
||||
final String input = context.get("message");
|
||||
|
||||
@@ -49,7 +52,9 @@ public class ReplyCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.replyTarget() == null) {
|
||||
final UUID replyTarget = user.replyTarget();
|
||||
|
||||
if (replyTarget == null) {
|
||||
final String message = this.carbonChat.translations().noReplyTarget();
|
||||
final Component component = this.carbonChat.messageProcessor().processMessage(message, "br", "\n");
|
||||
|
||||
@@ -58,9 +63,11 @@ public class ReplyCommand {
|
||||
return;
|
||||
}
|
||||
|
||||
final PlayerUser targetUser = this.carbonChat.userService().wrap(user.replyTarget());
|
||||
final PlayerUser targetUser = this.carbonChat.userService().wrap(replyTarget);
|
||||
|
||||
targetUser.sendMessage(user, input);
|
||||
if (targetUser != null) {
|
||||
targetUser.sendMessage(user, input);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+4
-3
@@ -16,14 +16,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class SetColorCommand {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public SetColorCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
public SetColorCommand(final @NonNull CommandManager<CarbonUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("setcolor");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
if (commandSettings == null || !commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -14,14 +14,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class ShadowMuteCommand {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public ShadowMuteCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
public ShadowMuteCommand(final @NonNull CommandManager<CarbonUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("shadowmute");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
if (commandSettings == null || !commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -36,7 +37,7 @@ public class ShadowMuteCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private void shadowMute(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void shadowMute(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final CarbonUser user = context.getSender();
|
||||
final PlayerUser target = context.get("user");
|
||||
|
||||
|
||||
+7
-6
@@ -17,14 +17,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class SpyChannelCommand {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public SpyChannelCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
public SpyChannelCommand(final @NonNull CommandManager<CarbonUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("spy");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
if (commandSettings == null || !commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,7 +61,7 @@ public class SpyChannelCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private void spyChannel(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void spyChannel(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final PlayerUser user = (PlayerUser) context.getSender();
|
||||
final ChatChannel chatChannel = context.get("channel");
|
||||
|
||||
@@ -81,7 +82,7 @@ public class SpyChannelCommand {
|
||||
"channel", chatChannel.name()));
|
||||
}
|
||||
|
||||
private void spyWhispers(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void spyWhispers(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final PlayerUser user = (PlayerUser) context.getSender();
|
||||
|
||||
final String message;
|
||||
@@ -97,7 +98,7 @@ public class SpyChannelCommand {
|
||||
user.sendMessage(Identity.nil(), this.carbonChat.messageProcessor().processMessage(message));
|
||||
}
|
||||
|
||||
private void spyEverything(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void spyEverything(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final PlayerUser user = (PlayerUser) context.getSender();
|
||||
final Boolean shouldSpy = context.get("enabled");
|
||||
|
||||
|
||||
+6
-5
@@ -16,14 +16,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class SudoChannelCommand {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public SudoChannelCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
public SudoChannelCommand(final @NonNull CommandManager<CarbonUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("sudochannel");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
if (commandSettings == null || !commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -51,7 +52,7 @@ public class SudoChannelCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private void otherChannel(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void otherChannel(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final CarbonUser sender = context.getSender();
|
||||
final PlayerUser user = context.get("user");
|
||||
final ChatChannel channel = context.get("channel");
|
||||
@@ -70,7 +71,7 @@ public class SudoChannelCommand {
|
||||
"channel", channel.name(), "player", user.name()));
|
||||
}
|
||||
|
||||
private void sendMessageOther(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void sendMessageOther(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final PlayerUser user = context.get("user");
|
||||
final ChatChannel channel = context.get("channel");
|
||||
final String message = context.get("message");
|
||||
|
||||
+6
-5
@@ -16,14 +16,15 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class ToggleCommand {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public ToggleCommand(@NonNull final CommandManager<CarbonUser> commandManager) {
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
public ToggleCommand(final @NonNull CommandManager<CarbonUser> commandManager) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
final CommandSettings commandSettings = this.carbonChat.commandSettings().get("toggle");
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
if (commandSettings == null || !commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -49,7 +50,7 @@ public class ToggleCommand {
|
||||
);
|
||||
}
|
||||
|
||||
private void toggleSelf(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void toggleSelf(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final PlayerUser user = (PlayerUser) context.getSender();
|
||||
final ChatChannel channel = context.get("channel");
|
||||
|
||||
@@ -72,7 +73,7 @@ public class ToggleCommand {
|
||||
"channel", channel.name()));
|
||||
}
|
||||
|
||||
private void toggleOther(@NonNull final CommandContext<CarbonUser> context) {
|
||||
private void toggleOther(final @NonNull CommandContext<CarbonUser> context) {
|
||||
final CarbonUser sender = context.getSender();
|
||||
final PlayerUser user = context.get("user");
|
||||
final ChatChannel channel = context.get("channel");
|
||||
|
||||
+4
-4
@@ -21,8 +21,8 @@ public final class ChannelArgument<C> extends CommandArgument<C, TextChannel> {
|
||||
TextChannel.class, ChannelArgument::suggestions);
|
||||
}
|
||||
|
||||
private static <C> ArgumentParseResult<TextChannel> parser(@NonNull final CommandContext<C> commandContext,
|
||||
@NonNull final Queue<String> inputs) {
|
||||
private static <C> ArgumentParseResult<TextChannel> parser(final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<String> inputs) {
|
||||
final String input = inputs.poll();
|
||||
|
||||
final ExceptionMessages exceptions = CarbonChatProvider.carbonChat().translations().exceptionMessages();
|
||||
@@ -43,8 +43,8 @@ public final class ChannelArgument<C> extends CommandArgument<C, TextChannel> {
|
||||
}
|
||||
}
|
||||
|
||||
private static <C> List<String> suggestions(@NonNull final CommandContext<C> commandContext,
|
||||
@NonNull final String input) {
|
||||
private static <C> List<String> suggestions(final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull String input) {
|
||||
return CarbonChatProvider.carbonChat().channelRegistry().stream()
|
||||
.map(ChatChannel::key).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
+4
-4
@@ -21,8 +21,8 @@ public final class PlayerUserArgument<C> extends CommandArgument<C, PlayerUser>
|
||||
PlayerUser.class, PlayerUserArgument::suggestions);
|
||||
}
|
||||
|
||||
private static <C> ArgumentParseResult<PlayerUser> parser(@NonNull final CommandContext<C> commandContext,
|
||||
@NonNull final Queue<String> inputs) {
|
||||
private static <C> ArgumentParseResult<PlayerUser> parser(final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull Queue<String> inputs) {
|
||||
final String input = inputs.poll();
|
||||
|
||||
final String playerNotFound = CarbonChatProvider.carbonChat().translations().exceptionMessages()
|
||||
@@ -47,8 +47,8 @@ public final class PlayerUserArgument<C> extends CommandArgument<C, PlayerUser>
|
||||
return ArgumentParseResult.success(user);
|
||||
}
|
||||
|
||||
private static <C> List<String> suggestions(@NonNull final CommandContext<C> commandContext,
|
||||
@NonNull final String input) {
|
||||
private static <C> List<String> suggestions(final @NonNull CommandContext<C> commandContext,
|
||||
final @NonNull String input) {
|
||||
return StreamSupport
|
||||
.stream(CarbonChatProvider.carbonChat().userService().onlineUsers().spliterator(), false)
|
||||
.map(PlayerUser::name)
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ public final class CommandRegistrar {
|
||||
|
||||
}
|
||||
|
||||
public static void registerCommands(@NonNull final CommandManager<CarbonUser> commandManager) {
|
||||
public static void registerCommands(final @NonNull CommandManager<CarbonUser> commandManager) {
|
||||
new ChannelCommand(commandManager);
|
||||
new ChannelListCommand(commandManager);
|
||||
new ChatReloadCommand(commandManager);
|
||||
|
||||
+3
-3
@@ -49,9 +49,9 @@ public final class SoundSerializer implements TypeSerializer<Sound> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable Sound deserialize(@NonNull final Type type, @NonNull final ConfigurationNode value) throws SerializationException {
|
||||
public @NonNull Sound deserialize(final @NonNull Type type, final @NonNull ConfigurationNode value) throws SerializationException {
|
||||
if (value.empty()) {
|
||||
return null;
|
||||
throw new SerializationException("Value not found for sound!");
|
||||
}
|
||||
|
||||
final Key name = value.node(NAME).get(KeySerializer.INSTANCE.type());
|
||||
@@ -67,7 +67,7 @@ public final class SoundSerializer implements TypeSerializer<Sound> {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serialize(@NonNull final Type type, @Nullable final Sound obj, @NonNull final ConfigurationNode value) throws SerializationException {
|
||||
public void serialize(final @NonNull Type type, final @Nullable Sound obj, final @NonNull ConfigurationNode value) throws SerializationException {
|
||||
if (obj == null) {
|
||||
value.set(null);
|
||||
return;
|
||||
|
||||
+4
-3
@@ -16,9 +16,10 @@ import java.util.regex.Pattern;
|
||||
|
||||
public class FilterContext {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public FilterContext(@NonNull final CarbonChat carbonChat) {
|
||||
@SuppressWarnings("method.invocation.invalid")
|
||||
public FilterContext(final @NonNull CarbonChat carbonChat) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
||||
@@ -61,7 +62,7 @@ public class FilterContext {
|
||||
});
|
||||
}
|
||||
|
||||
private boolean channelUsesFilter(@NonNull final ChatChannel chatChannel) {
|
||||
private boolean channelUsesFilter(final @NonNull ChatChannel chatChannel) {
|
||||
if (chatChannel instanceof TextChannel) {
|
||||
final Context context = ((TextChannel) chatChannel).context("filter");
|
||||
|
||||
|
||||
+5
-2
@@ -2,17 +2,20 @@ package net.draycia.carbon.common.listeners.events;
|
||||
|
||||
import net.draycia.carbon.api.events.misc.CarbonEvents;
|
||||
import net.draycia.carbon.api.events.ChatFormatEvent;
|
||||
import net.draycia.carbon.api.users.PlayerUser;
|
||||
import net.kyori.event.PostOrders;
|
||||
|
||||
public class IgnoredPlayerHandler {
|
||||
|
||||
public IgnoredPlayerHandler() {
|
||||
CarbonEvents.register(ChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
||||
if (event.target() == null) {
|
||||
final PlayerUser target = event.target();
|
||||
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.target().ignoringUser(event.sender())) {
|
||||
if (target.ignoringUser(event.sender())) {
|
||||
event.cancelled(true);
|
||||
}
|
||||
});
|
||||
|
||||
+6
-3
@@ -4,6 +4,7 @@ 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.ChatComponentEvent;
|
||||
import net.draycia.carbon.api.users.PlayerUser;
|
||||
import net.kyori.event.PostOrders;
|
||||
|
||||
public class PingHandler {
|
||||
@@ -16,11 +17,13 @@ public class PingHandler {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.target() == null) {
|
||||
final PlayerUser target = event.target();
|
||||
|
||||
if (target == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final String targetName = event.target().name();
|
||||
final String targetName = target.name();
|
||||
final String prefix = carbonChat.carbonSettings().channelPings().prefix();
|
||||
final boolean caseSensitive = carbonChat.carbonSettings().channelPings().caseSensitive();
|
||||
|
||||
@@ -34,7 +37,7 @@ public class PingHandler {
|
||||
}
|
||||
}
|
||||
|
||||
event.target().playSound(carbonChat.carbonSettings().channelPings().sound());
|
||||
target.playSound(carbonChat.carbonSettings().channelPings().sound());
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+1
@@ -7,6 +7,7 @@ import net.kyori.event.PostOrders;
|
||||
|
||||
public class UserFormattingHandler {
|
||||
|
||||
@SuppressWarnings("method.invocation.invalid")
|
||||
public UserFormattingHandler() {
|
||||
CarbonEvents.register(PreChatFormatEvent.class, PostOrders.FIRST, false, event -> {
|
||||
if (!event.user().hasPermission("carbonchat.formatting") &&
|
||||
|
||||
+4
-4
@@ -13,22 +13,22 @@ import java.util.function.Consumer;
|
||||
public class EmptyMessageService implements MessageService {
|
||||
|
||||
@Override
|
||||
public void registerUserMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull PlayerUser, @NonNull ByteArrayDataInput> listener) {
|
||||
public void registerUserMessageListener(final @NonNull String key, final @NonNull BiConsumer<@NonNull PlayerUser, @NonNull ByteArrayDataInput> listener) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerUUIDMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
|
||||
public void registerUUIDMessageListener(final @NonNull String key, final @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterMessageListener(@NonNull final String key) {
|
||||
public void unregisterMessageListener(final @NonNull String key) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(@NonNull final String key, @NonNull final UUID uuid, @NonNull final Consumer<@NonNull ByteArrayDataOutput> consumer) {
|
||||
public void sendMessage(final @NonNull String key, final @NonNull UUID uuid, final @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
+45
-18
@@ -16,11 +16,12 @@ import java.util.function.Consumer;
|
||||
|
||||
public class MessageManager {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
private @NonNull final MessageService messageService;
|
||||
private final @NonNull MessageService messageService;
|
||||
|
||||
public MessageManager(@NonNull final CarbonChat carbonChat, @NonNull final MessageService messageService) {
|
||||
@SuppressWarnings("method.invocation.invalid")
|
||||
public MessageManager(final @NonNull CarbonChat carbonChat, final @NonNull MessageService messageService) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.messageService = messageService;
|
||||
|
||||
@@ -45,7 +46,11 @@ public class MessageManager {
|
||||
});
|
||||
|
||||
this.messageService().registerUserMessageListener("selected-channel", (user, byteArray) -> {
|
||||
user.selectedChannel(this.carbonChat.channelRegistry().get(byteArray.readUTF()), true);
|
||||
final ChatChannel channel = this.carbonChat.channelRegistry().get(byteArray.readUTF());
|
||||
|
||||
if (channel != null) {
|
||||
user.selectedChannel(channel, true);
|
||||
}
|
||||
});
|
||||
|
||||
this.messageService().registerUserMessageListener("spying-whispers", (user, byteArray) -> {
|
||||
@@ -64,35 +69,55 @@ public class MessageManager {
|
||||
user.replyTarget(new UUID(byteArray.readLong(), byteArray.readLong()), true);
|
||||
});
|
||||
|
||||
this.messageService().registerUserMessageListener("reply-target-reset", (user, byteArray) -> {
|
||||
user.replyTarget((UUID) null, true);
|
||||
});
|
||||
|
||||
this.messageService().registerUserMessageListener("ignoring-user", (user, byteArray) -> {
|
||||
user.ignoringUser(new UUID(byteArray.readLong(), byteArray.readLong()), byteArray.readBoolean(), true);
|
||||
});
|
||||
|
||||
this.messageService().registerUserMessageListener("ignoring-channel", (user, byteArray) -> {
|
||||
user.channelSettings(this.carbonChat.channelRegistry().get(byteArray.readUTF()))
|
||||
.ignoring(byteArray.readBoolean(), true);
|
||||
final ChatChannel channel = this.carbonChat.channelRegistry().get(byteArray.readUTF());
|
||||
|
||||
if (channel != null) {
|
||||
user.channelSettings(channel)
|
||||
.ignoring(byteArray.readBoolean(), true);
|
||||
}
|
||||
});
|
||||
|
||||
this.messageService().registerUserMessageListener("spying-channel", (user, byteArray) -> {
|
||||
user.channelSettings(this.carbonChat.channelRegistry().get(byteArray.readUTF()))
|
||||
.spying(byteArray.readBoolean(), true);
|
||||
final ChatChannel channel = this.carbonChat.channelRegistry().get(byteArray.readUTF());
|
||||
|
||||
if (channel != null) {
|
||||
user.channelSettings(channel)
|
||||
.spying(byteArray.readBoolean(), true);
|
||||
}
|
||||
});
|
||||
|
||||
this.messageService().registerUserMessageListener("channel-color", (user, byteArray) -> {
|
||||
user.channelSettings(this.carbonChat.channelRegistry().get(byteArray.readUTF()))
|
||||
.color(TextColor.fromHexString(byteArray.readUTF()), true);
|
||||
final ChatChannel channel = this.carbonChat.channelRegistry().get(byteArray.readUTF());
|
||||
|
||||
if (channel != null) {
|
||||
user.channelSettings(channel)
|
||||
.color(TextColor.fromHexString(byteArray.readUTF()), true);
|
||||
}
|
||||
});
|
||||
|
||||
this.messageService().registerUserMessageListener("channel-color-reset", (user, byteArray) -> {
|
||||
user.channelSettings(this.carbonChat.channelRegistry().get(byteArray.readUTF()))
|
||||
.color(null, true);
|
||||
final ChatChannel channel = this.carbonChat.channelRegistry().get(byteArray.readUTF());
|
||||
|
||||
if (channel != null) {
|
||||
user.channelSettings(channel)
|
||||
.color(null, true);
|
||||
}
|
||||
});
|
||||
|
||||
this.messageService().registerUUIDMessageListener("channel-component", (uuid, byteArray) -> {
|
||||
final ChatChannel channel = this.carbonChat.channelRegistry().get(byteArray.readUTF());
|
||||
final PlayerUser user = this.carbonChat.userService().wrap(uuid);
|
||||
|
||||
if (channel instanceof TextChannel) {
|
||||
if (user != null && channel instanceof TextChannel) {
|
||||
final Component component = this.carbonChat.gsonSerializer().deserialize(byteArray.readUTF());
|
||||
|
||||
((TextChannel) channel).sendComponent(user, component);
|
||||
@@ -107,9 +132,11 @@ public class MessageManager {
|
||||
final PlayerUser target = this.carbonChat.userService().wrap(recipient);
|
||||
final String message = byteArray.readUTF();
|
||||
|
||||
if (!target.ignoringUser(uuid)) {
|
||||
target.replyTarget(uuid);
|
||||
target.sendMessage(Identity.identity(uuid), this.carbonChat.gsonSerializer().deserialize(message));
|
||||
if (target != null) {
|
||||
if (!target.ignoringUser(uuid)) {
|
||||
target.replyTarget(uuid);
|
||||
target.sendMessage(Identity.identity(uuid), this.carbonChat.gsonSerializer().deserialize(message));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -118,8 +145,8 @@ public class MessageManager {
|
||||
return this.messageService;
|
||||
}
|
||||
|
||||
public void sendMessage(@NonNull final String key, @NonNull final UUID uuid,
|
||||
@NonNull final Consumer<@NonNull ByteArrayDataOutput> consumer) {
|
||||
public void sendMessage(final @NonNull String key, final @NonNull UUID uuid,
|
||||
final @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer) {
|
||||
this.messageService().sendMessage(key, uuid, consumer);
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -10,23 +10,23 @@ public interface RedisListener extends RedisPubSubListener<String, String> {
|
||||
void message(@NonNull String channel, @NonNull String message);
|
||||
|
||||
@Override
|
||||
default void message(@NonNull final String pattern, @NonNull final String channel, @NonNull final String message) {
|
||||
default void message(final @NonNull String pattern, final @NonNull String channel, final @NonNull String message) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void subscribed(@NonNull final String channel, final long count) {
|
||||
default void subscribed(final @NonNull String channel, final long count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void psubscribed(@NonNull final String pattern, final long count) {
|
||||
default void psubscribed(final @NonNull String pattern, final long count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void unsubscribed(@NonNull final String channel, final long count) {
|
||||
default void unsubscribed(final @NonNull String channel, final long count) {
|
||||
}
|
||||
|
||||
@Override
|
||||
default void punsubscribed(@NonNull final String pattern, final long count) {
|
||||
default void punsubscribed(final @NonNull String pattern, final long count) {
|
||||
}
|
||||
|
||||
}
|
||||
+17
-14
@@ -22,26 +22,29 @@ import java.util.function.Consumer;
|
||||
|
||||
public class RedisMessageService implements MessageService {
|
||||
|
||||
private @NonNull final Map<@NonNull String, @NonNull BiConsumer<@NonNull PlayerUser, @NonNull ByteArrayDataInput>> userLoadedListeners = new HashMap<>();
|
||||
private final @NonNull Map<@NonNull String, @NonNull BiConsumer<@NonNull PlayerUser, @NonNull ByteArrayDataInput>> userLoadedListeners = new HashMap<>();
|
||||
|
||||
private @NonNull final Map<@NonNull String, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput>> userNotLoadedListeners = new HashMap<>();
|
||||
private final @NonNull Map<@NonNull String, @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput>> userNotLoadedListeners = new HashMap<>();
|
||||
|
||||
private @NonNull final RedisPubSubCommands<@NonNull String, @NonNull String> subscribeSync;
|
||||
private final @NonNull RedisPubSubCommands<@NonNull String, @NonNull String> subscribeSync;
|
||||
|
||||
private @NonNull final RedisPubSubCommands<@NonNull String, @NonNull String> publishSync;
|
||||
private final @NonNull RedisPubSubCommands<@NonNull String, @NonNull String> publishSync;
|
||||
|
||||
private @NonNull final UUID serverUUID = UUID.randomUUID();
|
||||
private final @NonNull UUID serverUUID = UUID.randomUUID();
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
public RedisMessageService(@NonNull final CarbonChat carbonChat, @NonNull final RedisCredentials credentials) {
|
||||
@SuppressWarnings("method.invocation.invalid")
|
||||
public RedisMessageService(final @NonNull CarbonChat carbonChat, final @NonNull RedisCredentials credentials) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
final RedisURI.Builder builder = RedisURI.Builder.redis(credentials.host(), credentials.port())
|
||||
.withDatabase(credentials.database());
|
||||
|
||||
if (credentials.password() != null) {
|
||||
builder.withPassword(credentials.password().toCharArray());
|
||||
final String password = credentials.password();
|
||||
|
||||
if (password != null) {
|
||||
builder.withPassword(password.toCharArray());
|
||||
}
|
||||
|
||||
final RedisClient client = RedisClient.create(builder.build());
|
||||
@@ -67,7 +70,7 @@ public class RedisMessageService implements MessageService {
|
||||
});
|
||||
}
|
||||
|
||||
private void receiveMessage(@NonNull final UUID uuid, @NonNull final String key, @NonNull final ByteArrayDataInput value) {
|
||||
private void receiveMessage(final @NonNull UUID uuid, final @NonNull String key, final @NonNull ByteArrayDataInput value) {
|
||||
final PlayerUser user = this.carbonChat.userService().wrapIfLoaded(uuid);
|
||||
|
||||
if (user != null) {
|
||||
@@ -86,19 +89,19 @@ public class RedisMessageService implements MessageService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerUserMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull PlayerUser, @NonNull ByteArrayDataInput> listener) {
|
||||
public void registerUserMessageListener(final @NonNull String key, final @NonNull BiConsumer<@NonNull PlayerUser, @NonNull ByteArrayDataInput> listener) {
|
||||
this.userLoadedListeners.put(key, listener);
|
||||
this.subscribeSync.subscribe(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerUUIDMessageListener(@NonNull final String key, @NonNull final BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
|
||||
public void registerUUIDMessageListener(final @NonNull String key, final @NonNull BiConsumer<@NonNull UUID, @NonNull ByteArrayDataInput> listener) {
|
||||
this.userNotLoadedListeners.put(key, listener);
|
||||
this.subscribeSync.subscribe(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unregisterMessageListener(@NonNull final String key) {
|
||||
public void unregisterMessageListener(final @NonNull String key) {
|
||||
this.userLoadedListeners.remove(key);
|
||||
this.userNotLoadedListeners.remove(key);
|
||||
|
||||
@@ -106,7 +109,7 @@ public class RedisMessageService implements MessageService {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendMessage(@NonNull final String key, @NonNull final UUID uuid, @NonNull final Consumer<@NonNull ByteArrayDataOutput> consumer) {
|
||||
public void sendMessage(final @NonNull String key, final @NonNull UUID uuid, final @NonNull Consumer<@NonNull ByteArrayDataOutput> consumer) {
|
||||
final ByteArrayDataOutput msg = ByteStreams.newDataOutput();
|
||||
|
||||
msg.writeLong(this.serverUUID.getMostSignificantBits());
|
||||
|
||||
+33
-27
@@ -30,24 +30,25 @@ import java.util.function.Supplier;
|
||||
|
||||
public class JSONUserService<T extends PlayerUser, C extends ConsoleUser> implements UserService<T> {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private @NonNull final Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
private @NonNull final Type userType;
|
||||
private @NonNull final Supplier<@NonNull Iterable<@NonNull T>> supplier;
|
||||
private @NonNull final Function<UUID, T> userFactory;
|
||||
private @NonNull final Function<String, UUID> nameResolver;
|
||||
private @NonNull final Supplier<C> consoleFactory;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
private final @NonNull Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||
private final @NonNull Type userType;
|
||||
private final @NonNull Supplier<@NonNull Iterable<@NonNull T>> supplier;
|
||||
private final @NonNull Function<UUID, T> userFactory;
|
||||
private final @NonNull Function<String, UUID> nameResolver;
|
||||
private final @NonNull Supplier<C> consoleFactory;
|
||||
|
||||
private @NonNull final LoadingCache<@NonNull UUID, @NonNull T> userCache = CacheBuilder.newBuilder()
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
private final @NonNull LoadingCache<@NonNull UUID, @NonNull T> userCache = CacheBuilder.newBuilder()
|
||||
.removalListener(this::saveUser)
|
||||
.build(CacheLoader.from(this::loadUser));
|
||||
|
||||
public JSONUserService(@NonNull final Class<? extends CarbonUser> userType,
|
||||
@NonNull final CarbonChat carbonChat,
|
||||
@NonNull final Supplier<@NonNull Iterable<@NonNull T>> supplier,
|
||||
@NonNull final Function<UUID, T> userFactory,
|
||||
@NonNull final Function<String, UUID> nameResolver,
|
||||
@NonNull final Supplier<C> consoleFactory) {
|
||||
public JSONUserService(final @NonNull Class<? extends CarbonUser> userType,
|
||||
final @NonNull CarbonChat carbonChat,
|
||||
final @NonNull Supplier<@NonNull Iterable<@NonNull T>> supplier,
|
||||
final @NonNull Function<UUID, T> userFactory,
|
||||
final @NonNull Function<String, UUID> nameResolver,
|
||||
final @NonNull Supplier<C> consoleFactory) {
|
||||
this.userType = userType;
|
||||
this.carbonChat = carbonChat;
|
||||
this.supplier = supplier;
|
||||
@@ -66,7 +67,7 @@ public class JSONUserService<T extends PlayerUser, C extends ConsoleUser> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID resolve(@NonNull final String name) {
|
||||
public UUID resolve(final @NonNull String name) {
|
||||
return this.nameResolver.apply(name);
|
||||
}
|
||||
|
||||
@@ -77,12 +78,11 @@ public class JSONUserService<T extends PlayerUser, C extends ConsoleUser> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable T wrap(@NonNull final UUID uuid) {
|
||||
public @NonNull T wrap(final @NonNull UUID uuid) {
|
||||
try {
|
||||
return this.userCache.get(uuid);
|
||||
} catch (final ExecutionException exception) {
|
||||
exception.printStackTrace();
|
||||
return null;
|
||||
throw new IllegalStateException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,24 +92,24 @@ public class JSONUserService<T extends PlayerUser, C extends ConsoleUser> implem
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable T wrapIfLoaded(@NonNull final UUID uuid) {
|
||||
public @Nullable T wrapIfLoaded(final @NonNull UUID uuid) {
|
||||
return this.userCache.getIfPresent(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable T refreshUser(@NonNull final UUID uuid) {
|
||||
public @Nullable T refreshUser(final @NonNull UUID uuid) {
|
||||
this.userCache.invalidate(uuid);
|
||||
|
||||
return this.wrap(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate(@NonNull final T user) {
|
||||
public void invalidate(final @NonNull T user) {
|
||||
this.userCache.invalidate(user.uuid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(@NonNull final T user) {
|
||||
public void validate(final @NonNull T user) {
|
||||
this.userCache.put(user.uuid(), user);
|
||||
}
|
||||
|
||||
@@ -118,7 +118,7 @@ public class JSONUserService<T extends PlayerUser, C extends ConsoleUser> implem
|
||||
return this.supplier.get();
|
||||
}
|
||||
|
||||
private @NonNull T loadUser(@NonNull final UUID uuid) {
|
||||
private @NonNull T loadUser(final @NonNull UUID uuid) {
|
||||
final File userFile = new File(this.carbonChat.dataFolder().toFile(), "users/" + uuid.toString() + ".json");
|
||||
this.ensureFileExists(userFile);
|
||||
|
||||
@@ -135,7 +135,7 @@ public class JSONUserService<T extends PlayerUser, C extends ConsoleUser> implem
|
||||
return this.userFactory.apply(uuid);
|
||||
}
|
||||
|
||||
private void saveUser(@NonNull final RemovalNotification<@NonNull UUID, @NonNull T> notification) {
|
||||
private void saveUser(final @NonNull RemovalNotification<@NonNull UUID, @NonNull T> notification) {
|
||||
final File userFile = new File(this.carbonChat.dataFolder().toFile(), "users/" + notification.getKey().toString() + ".json");
|
||||
this.ensureFileExists(userFile);
|
||||
|
||||
@@ -146,9 +146,15 @@ public class JSONUserService<T extends PlayerUser, C extends ConsoleUser> implem
|
||||
}
|
||||
}
|
||||
|
||||
private void ensureFileExists(@NonNull final File file) {
|
||||
if (!file.getParentFile().exists()) {
|
||||
file.getParentFile().mkdirs();
|
||||
private void ensureFileExists(final @NonNull File file) {
|
||||
final File parentFile = file.getParentFile();
|
||||
|
||||
if (parentFile == null) {
|
||||
throw new IllegalStateException("Parent file not present!");
|
||||
}
|
||||
|
||||
if (!parentFile.exists()) {
|
||||
parentFile.mkdirs();
|
||||
}
|
||||
|
||||
if (!file.exists()) {
|
||||
|
||||
+31
-29
@@ -34,22 +34,23 @@ import java.util.function.Supplier;
|
||||
|
||||
public class MySQLUserService<T extends PlayerUser, C extends ConsoleUser> implements UserService<T> {
|
||||
|
||||
private @NonNull final CarbonChat carbonChat;
|
||||
private @NonNull final Database database;
|
||||
private @NonNull final Supplier<@NonNull Iterable<@NonNull T>> supplier;
|
||||
private @NonNull final Function<UUID, T> userFactory;
|
||||
private @NonNull final Function<String, UUID> nameResolver;
|
||||
private @NonNull final Supplier<C> consoleFactory;
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
private final @NonNull Database database;
|
||||
private final @NonNull Supplier<@NonNull Iterable<@NonNull T>> supplier;
|
||||
private final @NonNull Function<UUID, T> userFactory;
|
||||
private final @NonNull Function<String, UUID> nameResolver;
|
||||
private final @NonNull Supplier<C> consoleFactory;
|
||||
|
||||
private @NonNull final LoadingCache<@NonNull UUID, @NonNull T> userCache = CacheBuilder.newBuilder()
|
||||
@SuppressWarnings("methodref.receiver.bound.invalid")
|
||||
private final @NonNull LoadingCache<@NonNull UUID, @NonNull T> userCache = CacheBuilder.newBuilder()
|
||||
.removalListener(this::saveUser)
|
||||
.build(CacheLoader.from(this::loadUser));
|
||||
|
||||
public MySQLUserService(@NonNull final CarbonChat carbonChat, @NonNull final SQLCredentials credentials,
|
||||
@NonNull final Supplier<@NonNull Iterable<@NonNull T>> supplier,
|
||||
@NonNull final Function<UUID, T> userFactory,
|
||||
@NonNull final Function<String, UUID> nameResolver,
|
||||
@NonNull final Supplier<C> consoleFactory) {
|
||||
public MySQLUserService(final @NonNull CarbonChat carbonChat, final @NonNull SQLCredentials credentials,
|
||||
final @NonNull Supplier<@NonNull Iterable<@NonNull T>> supplier,
|
||||
final @NonNull Function<UUID, T> userFactory,
|
||||
final @NonNull Function<String, UUID> nameResolver,
|
||||
final @NonNull Supplier<C> consoleFactory) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.supplier = supplier;
|
||||
this.userFactory = userFactory;
|
||||
@@ -99,7 +100,7 @@ public class MySQLUserService<T extends PlayerUser, C extends ConsoleUser> imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public UUID resolve(@NonNull final String name) {
|
||||
public UUID resolve(final @NonNull String name) {
|
||||
return this.nameResolver.apply(name);
|
||||
}
|
||||
|
||||
@@ -111,12 +112,11 @@ public class MySQLUserService<T extends PlayerUser, C extends ConsoleUser> imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable T wrap(@NonNull final UUID uuid) {
|
||||
public @NonNull T wrap(final @NonNull UUID uuid) {
|
||||
try {
|
||||
return this.userCache.get(uuid);
|
||||
} catch (final ExecutionException exception) {
|
||||
exception.printStackTrace();
|
||||
return null;
|
||||
throw new IllegalStateException(exception);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -126,24 +126,24 @@ public class MySQLUserService<T extends PlayerUser, C extends ConsoleUser> imple
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable T wrapIfLoaded(@NonNull final UUID uuid) {
|
||||
public @Nullable T wrapIfLoaded(final @NonNull UUID uuid) {
|
||||
return this.userCache.getIfPresent(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable T refreshUser(@NonNull final UUID uuid) {
|
||||
public @Nullable T refreshUser(final @NonNull UUID uuid) {
|
||||
this.userCache.invalidate(uuid);
|
||||
|
||||
return this.wrap(uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void invalidate(@NonNull final T user) {
|
||||
public void invalidate(final @NonNull T user) {
|
||||
this.userCache.invalidate(user.uuid());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void validate(@NonNull final T user) {
|
||||
public void validate(final @NonNull T user) {
|
||||
this.userCache.put(user.uuid(), user);
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public class MySQLUserService<T extends PlayerUser, C extends ConsoleUser> imple
|
||||
return this.supplier.get();
|
||||
}
|
||||
|
||||
private @Nullable T loadUser(@NonNull final UUID uuid) {
|
||||
private @Nullable T loadUser(final @NonNull UUID uuid) {
|
||||
final T user = this.userFactory.apply(uuid);
|
||||
|
||||
try (final DbStatement statement = this.database.query("SELECT * from sc_users WHERE uuid = ?;")) {
|
||||
@@ -169,9 +169,7 @@ public class MySQLUserService<T extends PlayerUser, C extends ConsoleUser> imple
|
||||
|
||||
final ChatChannel channel = this.carbonChat.channelRegistry().getOrDefault(users.getString("channel"));
|
||||
|
||||
if (channel != null) {
|
||||
user.selectedChannel(channel, true);
|
||||
}
|
||||
user.selectedChannel(channel, true);
|
||||
|
||||
final String nickname = users.getString("nickname");
|
||||
|
||||
@@ -210,15 +208,18 @@ public class MySQLUserService<T extends PlayerUser, C extends ConsoleUser> imple
|
||||
return user;
|
||||
}
|
||||
|
||||
private void saveUser(@NonNull final RemovalNotification<@NonNull UUID, @NonNull T> notification) {
|
||||
@SuppressWarnings("argument.type.incompatible")
|
||||
private void saveUser(final @NonNull RemovalNotification<@NonNull UUID, @NonNull T> notification) {
|
||||
final T user = notification.getValue();
|
||||
|
||||
this.database.createTransaction(stm -> {
|
||||
// Save user general data
|
||||
String selectedName = null;
|
||||
|
||||
if (user.selectedChannel() != null) {
|
||||
selectedName = user.selectedChannel().key();
|
||||
final ChatChannel channel = user.selectedChannel();
|
||||
|
||||
if (channel != null) {
|
||||
selectedName = channel.key();
|
||||
}
|
||||
|
||||
this.carbonChat.logger().info("Saving user data!");
|
||||
@@ -233,9 +234,10 @@ public class MySQLUserService<T extends PlayerUser, C extends ConsoleUser> imple
|
||||
final UserChannelSettings value = entry.getValue();
|
||||
|
||||
String colorString = null;
|
||||
final TextColor color = value.color();
|
||||
|
||||
if (value.color() != null) {
|
||||
colorString = value.color().asHexString();
|
||||
if (color != null) {
|
||||
colorString = color.asHexString();
|
||||
}
|
||||
|
||||
stm.executeUpdateQuery("INSERT INTO sc_channel_settings (uuid, channel, spying, ignored, color) VALUES (?, ?, ?, ?, ?) " +
|
||||
|
||||
@@ -22,16 +22,16 @@ public final class ColorUtils {
|
||||
|
||||
}
|
||||
|
||||
public @Nullable static TextColor parseColor(@Nullable final String input) {
|
||||
public static @Nullable TextColor parseColor(final @NonNull String input) {
|
||||
return parseColor(null, input);
|
||||
}
|
||||
|
||||
public @Nullable static TextColor parseColor(@Nullable final CarbonUser user, @Nullable String input) {
|
||||
public static @Nullable TextColor parseColor(final @Nullable CarbonUser user, @NonNull String input) {
|
||||
if (user instanceof PlayerUser) {
|
||||
input = ((PlayerUser) user).parsePlaceholders(input);
|
||||
}
|
||||
|
||||
if (input == null || input.isEmpty()) {
|
||||
if (input.isEmpty()) {
|
||||
return NamedTextColor.WHITE;
|
||||
}
|
||||
|
||||
@@ -50,14 +50,13 @@ public final class ColorUtils {
|
||||
return TextColor.fromCSSHexString(input);
|
||||
}
|
||||
|
||||
private static @NonNull final Pattern spigotLegacyRGB =
|
||||
private static final @NonNull Pattern spigotLegacyRGB =
|
||||
Pattern.compile("[§&]x[§&]([0-9a-f])[§&]([0-9a-f])[§&]([0-9a-f])[§&]([0-9a-f])[§&]([0-9a-f])[§&]([0-9a-f])");
|
||||
|
||||
private static @NonNull final Pattern pluginRGB =
|
||||
private static final @NonNull Pattern pluginRGB =
|
||||
Pattern.compile("[§&]#([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])([0-9a-f])");
|
||||
|
||||
@NonNull
|
||||
public static String translateAlternateColors(@NonNull final String input) {
|
||||
public static @NonNull String translateAlternateColors(final @NonNull String input) {
|
||||
// TODO: check if MiniMessage or MineDown
|
||||
String output = input;
|
||||
|
||||
@@ -83,17 +82,27 @@ public final class ColorUtils {
|
||||
// Legacy Colors
|
||||
for (final char c : "0123456789abcdef".toCharArray()) {
|
||||
final LegacyFormat format = LegacyComponentSerializer.parseChar(c);
|
||||
final TextColor color = format.color();
|
||||
|
||||
output = output.replaceAll("[§&]" + c, "<" + color.asHexString() + ">");
|
||||
if (format != null) {
|
||||
final TextColor color = format.color();
|
||||
|
||||
if (color != null) {
|
||||
output = output.replaceAll("[§&]" + c, "<" + color.asHexString() + ">");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Legacy Formatting
|
||||
for (final char c : "klmno".toCharArray()) {
|
||||
final LegacyFormat format = LegacyComponentSerializer.parseChar(c);
|
||||
final TextDecoration decoration = format.decoration();
|
||||
|
||||
output = output.replaceAll("[§&]" + c, "<" + decoration.name() + ">");
|
||||
if (format != null) {
|
||||
final TextDecoration decoration = format.decoration();
|
||||
|
||||
if (decoration != null) {
|
||||
output = output.replaceAll("[§&]" + c, "<" + decoration.name() + ">");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user