mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 14:38:51 +00:00
Change how channel messaging works
This commit is contained in:
1 parent
8de4305e91
commit
35ab8ec954
3 files changed
+42
-15
No files matched your search
@@ -11,6 +11,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public interface ChatChannel extends ForwardingAudience {
|
public interface ChatChannel extends ForwardingAudience {
|
||||||
@@ -112,9 +113,9 @@ public interface ChatChannel extends ForwardingAudience {
|
|||||||
|
|
||||||
boolean canPlayerSee(@NonNull ChatUser target, boolean checkSpying);
|
boolean canPlayerSee(@NonNull ChatUser target, boolean checkSpying);
|
||||||
|
|
||||||
@NonNull Component sendMessage(@NonNull ChatUser user, @NonNull String message, boolean fromBungee);
|
@NonNull Map<ChatUser, Component> parseMessage(@NonNull ChatUser user, @NonNull String message, boolean fromBungee);
|
||||||
|
|
||||||
@NonNull Component sendMessage(@NonNull ChatUser user, @NonNull Collection<@NonNull ChatUser> recipients, @NonNull String message, boolean fromBungee);
|
@NonNull Map<ChatUser, Component> parseMessage(@NonNull ChatUser user, @NonNull Collection<@NonNull ChatUser> recipients, @NonNull String message, boolean fromBungee);
|
||||||
|
|
||||||
void sendComponent(@NonNull ChatUser user, @NonNull Component component);
|
void sendComponent(@NonNull ChatUser user, @NonNull Component component);
|
||||||
|
|
||||||
|
|||||||
+27
-6
@@ -16,6 +16,7 @@ import org.checkerframework.checker.nullness.qual.NonNull;
|
|||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class BukkitChatListener implements Listener {
|
public class BukkitChatListener implements Listener {
|
||||||
|
|
||||||
@@ -79,17 +80,37 @@ public class BukkitChatListener implements Listener {
|
|||||||
event.getRecipients().clear();
|
event.getRecipients().clear();
|
||||||
|
|
||||||
if (event.isAsynchronous()) {
|
if (event.isAsynchronous()) {
|
||||||
final Component component = selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
|
final Map<ChatUser, Component> messages =
|
||||||
|
selectedChannel.parseMessage(user, recipients, event.getMessage(), false);
|
||||||
|
|
||||||
if (!component.equals(TextComponent.empty())) {
|
for (final Map.Entry<ChatUser, Component> entry : messages.entrySet()) {
|
||||||
event.setFormat(PlainComponentSerializer.plain().serialize(component)
|
if (entry.getValue().equals(TextComponent.empty())) {
|
||||||
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.getKey().sendMessage(entry.getValue());
|
||||||
|
|
||||||
|
if (user.equals(entry.getKey())) {
|
||||||
|
event.setFormat(PlainComponentSerializer.plain().serialize(entry.getValue())
|
||||||
|
.replaceAll("(?:[^%]|\\A)%(?:[^%]|\\z)", "%%"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> {
|
||||||
final Component component = selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
|
final Map<ChatUser, Component> messages =
|
||||||
|
selectedChannel.parseMessage(user, recipients, event.getMessage(), false);
|
||||||
|
|
||||||
this.carbonChat.messageProcessor().audiences().console().sendMessage(component);
|
for (final Map.Entry<ChatUser, Component> entry : messages.entrySet()) {
|
||||||
|
if (entry.getValue().equals(TextComponent.empty())) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
entry.getKey().sendMessage(entry.getValue());
|
||||||
|
|
||||||
|
if (user.equals(entry.getKey())) {
|
||||||
|
this.carbonChat.messageProcessor().audiences().console().sendMessage(entry.getValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (this.carbonChat.getConfig().getBoolean("show-tips")) {
|
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: Sync chat event! I cannot set the message format due to this. :(");
|
||||||
|
|||||||
+12
-7
@@ -23,7 +23,10 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
|||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@@ -98,7 +101,7 @@ public class CarbonChatChannel implements ChatChannel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public Component sendMessage(final @NonNull ChatUser user, final @NonNull Collection<@NonNull ChatUser> recipients, final @NonNull String message, final boolean fromRemote) {
|
public Map<ChatUser, Component> parseMessage(final @NonNull ChatUser user, final @NonNull Collection<@NonNull ChatUser> recipients, final @NonNull String message, final boolean fromRemote) {
|
||||||
//this.updateUserNickname(user);
|
//this.updateUserNickname(user);
|
||||||
|
|
||||||
final MessageContextEvent event = new MessageContextEvent(this, user);
|
final MessageContextEvent event = new MessageContextEvent(this, user);
|
||||||
@@ -106,7 +109,7 @@ public class CarbonChatChannel implements ChatChannel {
|
|||||||
CarbonEvents.post(event);
|
CarbonEvents.post(event);
|
||||||
|
|
||||||
if (event.cancelled()) {
|
if (event.cancelled()) {
|
||||||
return TextComponent.empty();
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get player's formatting
|
// Get player's formatting
|
||||||
@@ -120,7 +123,7 @@ public class CarbonChatChannel implements ChatChannel {
|
|||||||
// Return if cancelled or message is emptied
|
// Return if cancelled or message is emptied
|
||||||
|
|
||||||
if (preFormatEvent.cancelled() || preFormatEvent.message().trim().isEmpty()) {
|
if (preFormatEvent.cancelled() || preFormatEvent.message().trim().isEmpty()) {
|
||||||
return TextComponent.empty();
|
return Collections.emptyMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
final String displayName;
|
final String displayName;
|
||||||
@@ -131,6 +134,8 @@ public class CarbonChatChannel implements ChatChannel {
|
|||||||
displayName = user.displayName();
|
displayName = user.displayName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Map<ChatUser, Component> users = new HashMap<>();
|
||||||
|
|
||||||
// Iterate through players who should receive messages in this channel
|
// Iterate through players who should receive messages in this channel
|
||||||
for (final ChatUser target : recipients) {
|
for (final ChatUser target : recipients) {
|
||||||
// Call second format event. Used for relational stuff (placeholders etc)
|
// Call second format event. Used for relational stuff (placeholders etc)
|
||||||
@@ -165,7 +170,7 @@ public class CarbonChatChannel implements ChatChannel {
|
|||||||
|
|
||||||
CarbonEvents.post(newEvent);
|
CarbonEvents.post(newEvent);
|
||||||
|
|
||||||
target.sendMessage(newEvent.component());
|
users.put(newEvent.target(), newEvent.component());
|
||||||
}
|
}
|
||||||
|
|
||||||
final ChatFormatEvent consoleFormatEvent = new ChatFormatEvent(user, null, this, preFormatEvent.format(),
|
final ChatFormatEvent consoleFormatEvent = new ChatFormatEvent(user, null, this, preFormatEvent.format(),
|
||||||
@@ -192,13 +197,13 @@ public class CarbonChatChannel implements ChatChannel {
|
|||||||
this.sendMessageToBungee(user.uuid(), consoleEvent.component());
|
this.sendMessageToBungee(user.uuid(), consoleEvent.component());
|
||||||
}
|
}
|
||||||
|
|
||||||
return consoleEvent.component();
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NonNull
|
@NonNull
|
||||||
public Component sendMessage(final @NonNull ChatUser user, final @NonNull String message, final boolean fromRemote) {
|
public Map<ChatUser, Component> parseMessage(final @NonNull ChatUser user, final @NonNull String message, final boolean fromRemote) {
|
||||||
return this.sendMessage(user, this.audiences(), message, fromRemote);
|
return this.parseMessage(user, this.audiences(), message, fromRemote);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
Reference in new issue
Block a user