mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-03 22:15:45 +00:00
allow channels to use recipients list
This commit is contained in:
1 parent
e01ab04877
commit
94078a40c9
4 files changed
+46
-8
No files matched your search
@@ -7,7 +7,9 @@ import net.kyori.adventure.text.Component;
|
|||||||
import net.kyori.adventure.text.format.TextColor;
|
import net.kyori.adventure.text.format.TextColor;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public abstract class ChatChannel implements ForwardingAudience {
|
public abstract class ChatChannel implements ForwardingAudience {
|
||||||
@@ -75,6 +77,8 @@ public abstract class ChatChannel implements ForwardingAudience {
|
|||||||
|
|
||||||
public abstract Boolean primaryGroupOnly();
|
public abstract Boolean primaryGroupOnly();
|
||||||
|
|
||||||
|
public abstract Boolean honorsRecipientList();
|
||||||
|
|
||||||
public abstract boolean testContext(ChatUser sender, ChatUser target);
|
public abstract boolean testContext(ChatUser sender, ChatUser target);
|
||||||
|
|
||||||
public abstract Object getContext(String key);
|
public abstract Object getContext(String key);
|
||||||
@@ -102,6 +106,8 @@ public abstract class ChatChannel implements ForwardingAudience {
|
|||||||
*/
|
*/
|
||||||
public abstract void sendMessage(ChatUser user, String message, boolean fromBungee);
|
public abstract void sendMessage(ChatUser user, String message, boolean fromBungee);
|
||||||
|
|
||||||
|
public abstract void sendMessage(ChatUser user, Collection<ChatUser> recipients, String message, boolean fromBungee);
|
||||||
|
|
||||||
public abstract void sendComponent(ChatUser user, Component component);
|
public abstract void sendComponent(ChatUser user, Component component);
|
||||||
|
|
||||||
public String processPlaceholders(ChatUser user, String input) { return input; }
|
public String processPlaceholders(ChatUser user, String input) { return input; }
|
||||||
|
|||||||
@@ -84,8 +84,7 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void sendMessage(ChatUser user, Collection<ChatUser> recipients, String message, boolean fromRemote) {
|
||||||
public void sendMessage(ChatUser user, String message, boolean fromRemote) {
|
|
||||||
updateUserNickname(user);
|
updateUserNickname(user);
|
||||||
|
|
||||||
// Get player's formatting
|
// Get player's formatting
|
||||||
@@ -106,7 +105,7 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Iterate through players who should receive messages in this channel
|
// Iterate through players who should receive messages in this channel
|
||||||
for (ChatUser target : audiences()) {
|
for (ChatUser target : recipients) {
|
||||||
// Call second format event. Used for relational stuff (placeholders etc)
|
// Call second format event. Used for relational stuff (placeholders etc)
|
||||||
ChatFormatEvent formatEvent = new ChatFormatEvent(user, target, this, preFormatEvent.getFormat(), preFormatEvent.getMessage());
|
ChatFormatEvent formatEvent = new ChatFormatEvent(user, target, this, preFormatEvent.getFormat(), preFormatEvent.getMessage());
|
||||||
Bukkit.getPluginManager().callEvent(formatEvent);
|
Bukkit.getPluginManager().callEvent(formatEvent);
|
||||||
@@ -170,6 +169,11 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void sendMessage(ChatUser user, String message, boolean fromRemote) {
|
||||||
|
this.sendMessage(user, this.audiences(), message, fromRemote);
|
||||||
|
}
|
||||||
|
|
||||||
public String getFormat(ChatUser user) {
|
public String getFormat(ChatUser user) {
|
||||||
if (primaryGroupOnly()) {
|
if (primaryGroupOnly()) {
|
||||||
return getPrimaryGroupFormat(user);
|
return getPrimaryGroupFormat(user);
|
||||||
@@ -327,6 +331,11 @@ public class CarbonChatChannel extends ChatChannel {
|
|||||||
return getBoolean("should-bungee");
|
return getBoolean("should-bungee");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean honorsRecipientList() {
|
||||||
|
return getBoolean("honors-recipient-list");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
String name = getString("name");
|
String name = getString("name");
|
||||||
|
|||||||
@@ -4,11 +4,17 @@ import net.draycia.carbon.CarbonChat;
|
|||||||
import net.draycia.carbon.channels.ChatChannel;
|
import net.draycia.carbon.channels.ChatChannel;
|
||||||
import net.draycia.carbon.storage.ChatUser;
|
import net.draycia.carbon.storage.ChatUser;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.EventHandler;
|
import org.bukkit.event.EventHandler;
|
||||||
import org.bukkit.event.EventPriority;
|
import org.bukkit.event.EventPriority;
|
||||||
import org.bukkit.event.Listener;
|
import org.bukkit.event.Listener;
|
||||||
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
import org.bukkit.event.player.AsyncPlayerChatEvent;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
public class BukkitChatListener implements Listener {
|
public class BukkitChatListener implements Listener {
|
||||||
|
|
||||||
private final CarbonChat carbonChat;
|
private final CarbonChat carbonChat;
|
||||||
@@ -20,12 +26,12 @@ public class BukkitChatListener implements Listener {
|
|||||||
// Chat messages
|
// Chat messages
|
||||||
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
@EventHandler(priority = EventPriority.HIGHEST, ignoreCancelled = true)
|
||||||
public void onPlayerchat(AsyncPlayerChatEvent event) {
|
public void onPlayerchat(AsyncPlayerChatEvent event) {
|
||||||
event.getRecipients().clear();
|
|
||||||
|
|
||||||
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
ChatUser user = carbonChat.getUserService().wrap(event.getPlayer());
|
||||||
ChatChannel channel = user.getSelectedChannel();
|
ChatChannel channel = user.getSelectedChannel();
|
||||||
|
|
||||||
if (channel.shouldCancelChatEvent()) event.setCancelled(true);
|
if (channel.shouldCancelChatEvent()) {
|
||||||
|
event.setCancelled(true);
|
||||||
|
}
|
||||||
|
|
||||||
for (ChatChannel entry : carbonChat.getChannelManager().getRegistry().values()) {
|
for (ChatChannel entry : carbonChat.getChannelManager().getRegistry().values()) {
|
||||||
if (entry.getMessagePrefix() == null) {
|
if (entry.getMessagePrefix() == null) {
|
||||||
@@ -47,11 +53,25 @@ public class BukkitChatListener implements Listener {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final Collection<ChatUser> recipients;
|
||||||
|
|
||||||
|
if (selectedChannel.honorsRecipientList()) {
|
||||||
|
recipients = new HashSet<>();
|
||||||
|
|
||||||
|
for (Player recipient : event.getRecipients()) {
|
||||||
|
recipients.add(carbonChat.getUserService().wrap(recipient));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
recipients = (List<ChatUser>)selectedChannel.audiences();
|
||||||
|
}
|
||||||
|
|
||||||
|
event.getRecipients().clear();
|
||||||
|
|
||||||
if (event.isAsynchronous()) {
|
if (event.isAsynchronous()) {
|
||||||
selectedChannel.sendMessage(user, event.getMessage(), false);
|
selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
|
||||||
} else {
|
} else {
|
||||||
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
Bukkit.getScheduler().runTaskAsynchronously(carbonChat, () -> {
|
||||||
selectedChannel.sendMessage(user, event.getMessage(), false);
|
selectedChannel.sendMessage(user, recipients, event.getMessage(), false);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,6 +54,9 @@ default:
|
|||||||
# As such, setting this on private channels is recommended.
|
# As such, setting this on private channels is recommended.
|
||||||
# For example, use this if DiscordSRV is sending messages when you don't want it to.
|
# For example, use this if DiscordSRV is sending messages when you don't want it to.
|
||||||
cancel-message-event: false
|
cancel-message-event: false
|
||||||
|
# For plugin compatibility. If true, this channel will use bukkit's list of players to send the messages to.
|
||||||
|
# It's advised to leave this off unless absolutely necessary.
|
||||||
|
honors-recipient-list: false
|
||||||
|
|
||||||
channels:
|
channels:
|
||||||
global:
|
global:
|
||||||
|
|||||||
Reference in new issue
Block a user