mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 22:16:22 +00:00
13/15
This commit is contained in:
1 parent
74f95eac02
commit
c4ea3e2182
3 files changed
+62
-30
No files matched your search
@@ -1,50 +1,76 @@
|
|||||||
package net.draycia.carbon.commands;
|
package net.draycia.carbon.commands;
|
||||||
|
|
||||||
import co.aikar.commands.BaseCommand;
|
import dev.jorel.commandapi.CommandAPICommand;
|
||||||
import co.aikar.commands.annotation.*;
|
import dev.jorel.commandapi.CommandPermission;
|
||||||
|
import dev.jorel.commandapi.arguments.Argument;
|
||||||
import net.draycia.carbon.CarbonChat;
|
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 net.draycia.carbon.util.CarbonUtils;
|
||||||
|
import net.kyori.adventure.audience.Audience;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import net.kyori.adventure.text.TextComponent;
|
import net.kyori.adventure.text.TextComponent;
|
||||||
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
@CommandAlias("chlist|channellist")
|
public class ChannelListCommand {
|
||||||
@CommandPermission("carbonchat.channellist")
|
|
||||||
public class ChannelListCommand extends BaseCommand {
|
|
||||||
|
|
||||||
@Dependency
|
private final CarbonChat carbonChat;
|
||||||
private CarbonChat carbonChat;
|
|
||||||
|
|
||||||
@Default
|
public ChannelListCommand(CarbonChat carbonChat) {
|
||||||
@Syntax("[player]")
|
this.carbonChat = carbonChat;
|
||||||
public void baseCommand(Player player) {
|
|
||||||
|
String commandName = carbonChat.getConfig().getString("commands.channellist.name", "channellist");
|
||||||
|
List<String> commandAliases = carbonChat.getConfig().getStringList("commands.channellist.aliases");
|
||||||
|
|
||||||
|
LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||||
|
|
||||||
|
new CommandAPICommand(commandName)
|
||||||
|
.withArguments(channelArguments)
|
||||||
|
.withAliases(commandAliases.toArray(new String[0]))
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.channellist"))
|
||||||
|
.executesPlayer(this::executeSelf)
|
||||||
|
.register();
|
||||||
|
|
||||||
|
LinkedHashMap<String, Argument> argumentsOther = new LinkedHashMap<>();
|
||||||
|
argumentsOther.put("player", CarbonUtils.chatUserArgument());
|
||||||
|
|
||||||
|
new CommandAPICommand(commandName)
|
||||||
|
.withArguments(argumentsOther)
|
||||||
|
.withAliases(commandAliases.toArray(new String[0]))
|
||||||
|
.withPermission(CommandPermission.fromString("carbonchat.channellist.other"))
|
||||||
|
.executes(this::executeOther)
|
||||||
|
.register();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void executeSelf(Player player, Object[] args) {
|
||||||
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
|
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
|
||||||
ChatUser user = carbonChat.getUserService().wrap(player);
|
ChatUser user = carbonChat.getUserService().wrap(player);
|
||||||
|
|
||||||
getListAndSend(player, user, allChannels);
|
getListAndSend(player, user, allChannels);
|
||||||
}
|
}
|
||||||
|
|
||||||
@CommandPermission("carbonchat.channellist.others")
|
public void executeOther(CommandSender sender, Object[] args) {
|
||||||
@Subcommand("user")
|
Audience cmdSender = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||||
@CommandCompletion("@players @nothing")
|
ChatUser user = (ChatUser) args[0];
|
||||||
@Syntax("<player>")
|
|
||||||
public void baseCommand(Player player, ChatUser user) {
|
if (!user.isOnline()) {
|
||||||
ChatUser cmdSender = carbonChat.getUserService().wrap(player);
|
String mustBeOnline = carbonChat.getLanguage().getString("user-must-be-online");
|
||||||
if (!user.isOnline()) {
|
cmdSender.sendMessage(carbonChat.getAdventureManager().processMessage(mustBeOnline, "br", "\n", "player", user.asOfflinePlayer().getName()));
|
||||||
String mustBeOnline = carbonChat.getLanguage().getString("user-must-be-online");
|
return;
|
||||||
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) {
|
Iterator<ChatChannel> allChannels = carbonChat.getChannelManager().getRegistry().values().iterator();
|
||||||
|
getListAndSend(sender, user, allChannels);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void getListAndSend(CommandSender sender, ChatUser user, Iterator<ChatChannel> allChannels) {
|
||||||
ChatChannel channel;
|
ChatChannel channel;
|
||||||
List<ChatChannel> canSee = new ArrayList<>();
|
List<ChatChannel> canSee = new ArrayList<>();
|
||||||
List<ChatChannel> cannotSee = new ArrayList<>();
|
List<ChatChannel> cannotSee = new ArrayList<>();
|
||||||
@@ -68,9 +94,11 @@ public class ChannelListCommand extends BaseCommand {
|
|||||||
Component availableComponent = carbonChat.getAdventureManager().processMessage(availableFormat, "br", "\n");
|
Component availableComponent = carbonChat.getAdventureManager().processMessage(availableFormat, "br", "\n");
|
||||||
availableComponent = ((TextComponent)availableComponent).replaceFirst(Pattern.compile(Pattern.quote("<list>")), (ac) -> availableList);
|
availableComponent = ((TextComponent)availableComponent).replaceFirst(Pattern.compile(Pattern.quote("<list>")), (ac) -> availableList);
|
||||||
|
|
||||||
carbonChat.getUserService().wrap(player).sendMessage(availableComponent);
|
Audience audience = carbonChat.getAdventureManager().getAudiences().audience(sender);
|
||||||
|
|
||||||
if (player.hasPermission("carbonchat.channellist.bypass") && !cannotSee.isEmpty()) {
|
audience.sendMessage(availableComponent);
|
||||||
|
|
||||||
|
if (sender.hasPermission("carbonchat.channellist.bypass") && !cannotSee.isEmpty()) {
|
||||||
|
|
||||||
Iterator<ChatChannel> invisibleChannels = cannotSee.iterator();
|
Iterator<ChatChannel> invisibleChannels = cannotSee.iterator();
|
||||||
TextComponent.Builder unavailableList = TextComponent.builder("");
|
TextComponent.Builder unavailableList = TextComponent.builder("");
|
||||||
@@ -81,13 +109,14 @@ public class ChannelListCommand extends BaseCommand {
|
|||||||
Component unavailableComponent = carbonChat.getAdventureManager().processMessage(unavailableFormat, "br", "\n");
|
Component unavailableComponent = carbonChat.getAdventureManager().processMessage(unavailableFormat, "br", "\n");
|
||||||
unavailableComponent = ((TextComponent)unavailableComponent).replaceFirst(Pattern.compile(Pattern.quote("<list>")), (uac) -> unavailableList);
|
unavailableComponent = ((TextComponent)unavailableComponent).replaceFirst(Pattern.compile(Pattern.quote("<list>")), (uac) -> unavailableList);
|
||||||
|
|
||||||
carbonChat.getUserService().wrap(player).sendMessage(unavailableComponent);
|
audience.sendMessage(unavailableComponent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void makeList(Iterator<ChatChannel> iterator, TextComponent.Builder list) {
|
private void makeList(Iterator<ChatChannel> iterator, TextComponent.Builder list) {
|
||||||
String listSeparator = carbonChat.getLanguage().getString("channel-list-separator", ", ");
|
String listSeparator = carbonChat.getLanguage().getString("channel-list-separator", ", ");
|
||||||
Component listSeparatorComponent = listSeparatorComponent = TextComponent.of(listSeparator);
|
// TODO: Larry, why did you double assign the listSeparatorComponent?
|
||||||
|
Component listSeparatorComponent = TextComponent.of(listSeparator);
|
||||||
|
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
ChatChannel channel = iterator.next();
|
ChatChannel channel = iterator.next();
|
||||||
|
|||||||
@@ -82,7 +82,7 @@ public class CommandManager {
|
|||||||
|
|
||||||
public void reloadCommands(CarbonChat carbonChat) {
|
public void reloadCommands(CarbonChat carbonChat) {
|
||||||
this.commandManager.registerCommand(new ChannelCommand());
|
this.commandManager.registerCommand(new ChannelCommand());
|
||||||
this.commandManager.registerCommand(new ChannelListCommand());
|
new ChannelListCommand(carbonChat);
|
||||||
new ChatReloadCommand(carbonChat);
|
new ChatReloadCommand(carbonChat);
|
||||||
new ClearChatCommand(carbonChat);
|
new ClearChatCommand(carbonChat);
|
||||||
new IgnoreCommand(carbonChat);
|
new IgnoreCommand(carbonChat);
|
||||||
|
|||||||
@@ -179,4 +179,7 @@ commands:
|
|||||||
aliases: ['msg', 'whisper', 'w']
|
aliases: ['msg', 'whisper', 'w']
|
||||||
ignore:
|
ignore:
|
||||||
name: 'ignore'
|
name: 'ignore'
|
||||||
aliases: []
|
aliases: []
|
||||||
|
channellist:
|
||||||
|
name: 'channellist'
|
||||||
|
aliases: ['chlist']
|
||||||
Reference in new issue
Block a user