mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 06:28:54 +00:00
Merge pull request #26 from Laarryy/channel-list-update
Add Channel List Command
This commit is contained in:
4 files changed
+107
-14
No files matched your search
@@ -313,24 +313,12 @@ public class CarbonChatChannel extends ChatChannel {
|
||||
public Boolean canPlayerSee(ChatUser sender, ChatUser target, boolean checkSpying) {
|
||||
Player targetPlayer = target.asPlayer();
|
||||
|
||||
if (checkSpying && targetPlayer.hasPermission("carbonchat.spy." + getName())) {
|
||||
if (target.getChannelSettings(this).isSpying()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (!targetPlayer.hasPermission("carbonchat.channels." + getName() + ".see")) {
|
||||
if (!canPlayerSee(target, checkSpying)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (isIgnorable()) {
|
||||
if (target.isIgnoringUser(sender) && !targetPlayer.hasPermission("carbonchat.ignore.exempt")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (target.getChannelSettings(this).isIgnored()) {
|
||||
return false;
|
||||
}
|
||||
return !target.isIgnoringUser(sender) || targetPlayer.hasPermission("carbonchat.ignore.exempt");
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
package net.draycia.carbon.commands;
|
||||
|
||||
import co.aikar.commands.BaseCommand;
|
||||
import co.aikar.commands.annotation.*;
|
||||
import net.draycia.carbon.CarbonChat;
|
||||
import net.draycia.carbon.channels.ChatChannel;
|
||||
import net.draycia.carbon.storage.ChatUser;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@CommandAlias("chlist|channellist")
|
||||
@CommandPermission("carbonchat.channellist")
|
||||
public class ChannelListCommand extends BaseCommand {
|
||||
|
||||
@Dependency
|
||||
private CarbonChat carbonChat;
|
||||
|
||||
@Default
|
||||
@Syntax("[player]")
|
||||
public void baseCommand(Player player) {
|
||||
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
|
||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||
getListAndSend(player, user, allChannels);
|
||||
}
|
||||
|
||||
@CommandPermission("carbonchat.channellist.others")
|
||||
@Subcommand("user")
|
||||
@CommandCompletion("@players")
|
||||
@Syntax("<player>")
|
||||
public void baseCommand(Player player, ChatUser user) {
|
||||
ChatUser cmdSender = carbonChat.getUserService().wrap(player);
|
||||
if (!user.isOnline()) {
|
||||
String mustBeOnline = carbonChat.getLanguage().getString("user-must-be-online");
|
||||
cmdSender.sendMessage(carbonChat.getAdventureManager().processMessage(mustBeOnline, "br", "\n", "player", user.asOfflinePlayer().getName()));
|
||||
return;
|
||||
}
|
||||
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
|
||||
getListAndSend(player, user, allChannels);
|
||||
}
|
||||
|
||||
private void getListAndSend(Player player, ChatUser user, Iterator<ChatChannel> allChannels) {
|
||||
ChatChannel channel;
|
||||
List<ChatChannel> canSee = new ArrayList<>();
|
||||
List<ChatChannel> cannotSee = new ArrayList<>();
|
||||
|
||||
while (allChannels.hasNext()) {
|
||||
channel = allChannels.next();
|
||||
|
||||
if (channel.canPlayerSee(user, true)) {
|
||||
canSee.add(channel);
|
||||
} else {
|
||||
cannotSee.add(channel);
|
||||
}
|
||||
}
|
||||
|
||||
Iterator<ChatChannel> visibleChannels = canSee.iterator();
|
||||
TextComponent.Builder availableList = TextComponent.builder("");
|
||||
|
||||
makeList(visibleChannels, availableList);
|
||||
|
||||
String availableFormat = carbonChat.getLanguage().getString("available-channels-list");
|
||||
Component availableComponent = carbonChat.getAdventureManager().processMessage(availableFormat, "br", "\n");
|
||||
availableComponent = ((TextComponent)availableComponent).replaceFirst(Pattern.compile(Pattern.quote("<list>")), (ac) -> availableList);
|
||||
|
||||
carbonChat.getUserService().wrap(player).sendMessage(availableComponent);
|
||||
|
||||
if (player.hasPermission("carbonchat.channellist.bypass") && !cannotSee.isEmpty()) {
|
||||
|
||||
Iterator<ChatChannel> invisibleChannels = cannotSee.iterator();
|
||||
TextComponent.Builder unavailableList = TextComponent.builder("");
|
||||
|
||||
makeList(invisibleChannels, unavailableList);
|
||||
|
||||
String unavailableFormat = carbonChat.getLanguage().getString("unavailable-channels-list");
|
||||
Component unavailableComponent = carbonChat.getAdventureManager().processMessage(unavailableFormat, "br", "\n");
|
||||
unavailableComponent = ((TextComponent)unavailableComponent).replaceFirst(Pattern.compile(Pattern.quote("<list>")), (uac) -> unavailableList);
|
||||
|
||||
carbonChat.getUserService().wrap(player).sendMessage(unavailableComponent);
|
||||
}
|
||||
}
|
||||
|
||||
private void makeList(Iterator<ChatChannel> iterator, TextComponent.Builder list) {
|
||||
String listSeparator = carbonChat.getLanguage().getString("channel-list-separator", ", ");
|
||||
Component listSeparatorComponent = listSeparatorComponent = TextComponent.of(listSeparator);
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
ChatChannel channel = iterator.next();
|
||||
list.append(TextComponent.of(channel.getName()));
|
||||
if (iterator.hasNext()) {
|
||||
list.append(listSeparatorComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,6 +83,7 @@ public class CommandManager {
|
||||
public void reloadCommands() {
|
||||
this.commandManager.registerCommand(new ToggleCommand());
|
||||
this.commandManager.registerCommand(new ChannelCommand());
|
||||
this.commandManager.registerCommand(new ChannelListCommand());
|
||||
this.commandManager.registerCommand(new IgnoreCommand());
|
||||
this.commandManager.registerCommand(new ChatReloadCommand());
|
||||
this.commandManager.registerCommand(new MeCommand());
|
||||
|
||||
@@ -17,6 +17,10 @@ no-reply-target: '<red>You have no one to reply to!'
|
||||
empty-channel: 'NONE' #<channel>, set to "NONE" to disable
|
||||
other-nickname-set: '<green><user><reset>''s nickname was set to <nickname><green>!'
|
||||
other-nickname-reset: '<green><user><reset>''s nickname was reset!'
|
||||
available-channels-list: '<green>Available Channels:<reset> <list>.'
|
||||
unavailable-channels-list: '<red>Unavailable Channels:<reset> <list>.'
|
||||
channel-list-separator: ', '
|
||||
user-must-be-online: '<red><player> must be online!'
|
||||
|
||||
# The following messages are compatible with PlaceholderAPI and MiniMessage/MineDown
|
||||
me: '<italic><dark_purple>*<displayname> <reset><message>*</dark_purple></italic>'
|
||||
|
||||
Reference in new issue
Block a user