mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-01 22:15:08 +00:00
Start commands and other stuff
This commit is contained in:
1 parent
64295c84ea
commit
16d3589773
38 files changed
+872
-794
No files matched your search
@@ -13,5 +13,7 @@ dependencies {
|
||||
compile 'net.kyori:event-api:3.0.0'
|
||||
compile 'net.kyori:registry:1.0.0-SNAPSHOT'
|
||||
|
||||
compile 'com.intellectualsites:cloud-core:1.0-SNAPSHOT'
|
||||
|
||||
compileOnly 'org.spongepowered:configurate-yaml:4.0.0-SNAPSHOT'
|
||||
}
|
||||
@@ -3,7 +3,7 @@ package net.draycia.carbon.api;
|
||||
import net.draycia.carbon.api.adventure.CarbonTranslations;
|
||||
import net.draycia.carbon.api.adventure.MessageProcessor;
|
||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||
import net.draycia.carbon.api.commands.CommandSettingsRegistry;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettingsRegistry;
|
||||
import net.draycia.carbon.api.users.UserService;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
package net.draycia.carbon.api;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class CarbonChatProvider {
|
||||
|
||||
private CarbonChatProvider() {
|
||||
|
||||
}
|
||||
|
||||
private static CarbonChat instance;
|
||||
|
||||
public static void register(final @NonNull CarbonChat carbonChat) {
|
||||
CarbonChatProvider.instance = carbonChat;
|
||||
}
|
||||
|
||||
public static CarbonChat carbonChat() {
|
||||
return CarbonChatProvider.instance;
|
||||
}
|
||||
|
||||
}
|
||||
+6
-5
@@ -1,10 +1,11 @@
|
||||
package net.draycia.carbon.api.commands;
|
||||
package net.draycia.carbon.api.commands.settings;
|
||||
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.spongepowered.configurate.objectmapping.Setting;
|
||||
import org.spongepowered.configurate.serialize.ConfigSerializable;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@ConfigSerializable
|
||||
public class CommandSettings {
|
||||
@@ -16,16 +17,16 @@ public class CommandSettings {
|
||||
private @NonNull final String name;
|
||||
|
||||
@Setting
|
||||
private @NonNull final List<@NonNull String> aliases;
|
||||
private @NonNull final Set<@NonNull String> aliases;
|
||||
|
||||
public CommandSettings(final boolean enabled, @NonNull final String name, @NonNull final List<@NonNull String> aliases) {
|
||||
public CommandSettings(final boolean enabled, @NonNull final String name, @NonNull final Set<@NonNull String> aliases) {
|
||||
this.enabled = enabled;
|
||||
this.name = name;
|
||||
this.aliases = aliases;
|
||||
}
|
||||
|
||||
public @NonNull String @NonNull [] aliases() {
|
||||
return this.aliases.toArray(new String[0]);
|
||||
public @NonNull Set<@NonNull String> aliases() {
|
||||
return this.aliases;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package net.draycia.carbon.api.commands;
|
||||
package net.draycia.carbon.api.commands.settings;
|
||||
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.kyori.registry.Registry;
|
||||
@@ -1,5 +1,6 @@
|
||||
package net.draycia.carbon.api.users;
|
||||
|
||||
import com.intellectualsites.commands.sender.CommandSender;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@@ -7,26 +8,33 @@ import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public interface ChatUser extends Audience {
|
||||
public interface ChatUser extends Audience, CommandSender {
|
||||
|
||||
@NonNull
|
||||
UUID uuid();
|
||||
|
||||
@Nullable
|
||||
String nickname();
|
||||
@NonNull UUID uuid();
|
||||
|
||||
@Deprecated
|
||||
boolean permissible();
|
||||
|
||||
|
||||
boolean online();
|
||||
|
||||
@Override
|
||||
boolean hasPermission(@NonNull String permission);
|
||||
|
||||
default void nickname(@NonNull final String nickname) {
|
||||
@Nullable String nickname();
|
||||
|
||||
default void nickname(@Nullable final String nickname) {
|
||||
this.nickname(nickname, false);
|
||||
}
|
||||
|
||||
void nickname(@Nullable String nickname, boolean fromRemote);
|
||||
|
||||
@Nullable
|
||||
ChatChannel selectedChannel();
|
||||
@Nullable String displayName();
|
||||
|
||||
void displayName(@Nullable String displayName);
|
||||
|
||||
@NonNull String name();
|
||||
|
||||
@Nullable ChatChannel selectedChannel();
|
||||
|
||||
default void selectedChannel(@NonNull final ChatChannel channel) {
|
||||
this.selectedChannel(channel, false);
|
||||
@@ -36,8 +44,7 @@ public interface ChatUser extends Audience {
|
||||
|
||||
void clearSelectedChannel();
|
||||
|
||||
@NonNull
|
||||
UserChannelSettings channelSettings(@NonNull ChatChannel channel);
|
||||
@NonNull UserChannelSettings channelSettings(@NonNull ChatChannel channel);
|
||||
|
||||
boolean spyingwhispers();
|
||||
|
||||
@@ -63,8 +70,7 @@ public interface ChatUser extends Audience {
|
||||
|
||||
void shadowMuted(boolean shadowMuted, boolean fromRemote);
|
||||
|
||||
@Nullable
|
||||
UUID replyTarget();
|
||||
@Nullable UUID replyTarget();
|
||||
|
||||
default void replyTarget(@Nullable final UUID target) {
|
||||
this.replyTarget(target, false);
|
||||
|
||||
@@ -22,4 +22,6 @@ public interface UserService {
|
||||
|
||||
void validate(@NonNull ChatUser user);
|
||||
|
||||
@NonNull Iterable<@NonNull ChatUser> onlineUsers();
|
||||
|
||||
}
|
||||
@@ -18,7 +18,7 @@ dependencies {
|
||||
compile 'io.github.leonardosnt:bungeechannelapi:1.0.0-SNAPSHOT'
|
||||
|
||||
// Commands
|
||||
compile "dev.jorel:commandapi-shade:4.2"
|
||||
compile "com.intellectualsites:cloud-paper:1.0-SNAPSHOT"
|
||||
|
||||
// Plugins
|
||||
compileOnly('com.gmail.nossr50.mcMMO:mcMMO:2.1.143') {
|
||||
@@ -30,9 +30,10 @@ dependencies {
|
||||
}
|
||||
compileOnly 'me.clip:placeholderapi:2.10.9'
|
||||
compileOnly 'com.github.TownyAdvanced:Towny:0.96.1.11'
|
||||
compileOnly 'com.github.MilkBowl:VaultAPI:1.7'
|
||||
compileOnly 'com.vexsoftware:nuvotifier-universal:2.6.0'
|
||||
|
||||
compileOnly 'net.luckperms:api:5.1'
|
||||
compileOnly 'com.github.MilkBowl:VaultAPI:1.7' // TODO: remove
|
||||
|
||||
// Server
|
||||
compileOnly 'com.destroystokyo.paper:paper-api:1.16.2-R0.1-SNAPSHOT'
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package net.draycia.carbon;
|
||||
|
||||
import com.intellectualsites.commands.PaperCommandManager;
|
||||
import com.intellectualsites.commands.execution.CommandExecutionCoordinator;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.adventure.CarbonTranslations;
|
||||
import net.draycia.carbon.api.adventure.MessageProcessor;
|
||||
import net.draycia.carbon.api.channels.ChannelRegistry;
|
||||
import net.draycia.carbon.api.commands.CommandSettingsRegistry;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettingsRegistry;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.common.adventure.FormatType;
|
||||
import net.draycia.carbon.common.messaging.EmptyMessageService;
|
||||
import net.draycia.carbon.listeners.contexts.DistanceContext;
|
||||
@@ -44,6 +48,7 @@ import net.kyori.adventure.text.serializer.legacy.LegacyComponentSerializer;
|
||||
import net.milkbowl.vault.economy.Economy;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPlugin;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
@@ -83,6 +88,8 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
|
||||
@Override
|
||||
public void onLoad() {
|
||||
CarbonChatProvider.register(this);
|
||||
|
||||
CommandAPI.onLoad(false);
|
||||
}
|
||||
|
||||
@@ -164,6 +171,25 @@ public final class CarbonChatBukkit extends JavaPlugin implements CarbonChat {
|
||||
new WhisperPingHandler(this);
|
||||
}
|
||||
|
||||
private void setupCommands() {
|
||||
try {
|
||||
final PaperCommandManager<ChatUser> manager = new PaperCommandManager<>(this,
|
||||
CommandExecutionCoordinator
|
||||
.simpleCoordinator(), sender -> {
|
||||
if (sender instanceof Player) {
|
||||
return this.userService().wrap(((Player) sender).getUniqueId());
|
||||
} else {
|
||||
// TODO: weeeeee fix this
|
||||
throw new IllegalArgumentException("Non-players not supported yet!");
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
} catch (final Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void reloadConfig() {
|
||||
super.reloadConfig();
|
||||
|
||||
-84
@@ -1,84 +0,0 @@
|
||||
package net.draycia.carbon.commands;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.CommandPermission;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class AliasedChannelCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
|
||||
@NonNull
|
||||
private final ChatChannel chatChannel;
|
||||
|
||||
@NonNull
|
||||
private final String commandName;
|
||||
|
||||
public AliasedChannelCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final ChatChannel chatChannel) {
|
||||
this.carbonChat = carbonChat;
|
||||
this.chatChannel = chatChannel;
|
||||
|
||||
this.commandName = chatChannel.key();
|
||||
|
||||
final LinkedHashMap<String, Argument> setChannelArguments = new LinkedHashMap<>();
|
||||
|
||||
new CommandAPICommand(this.commandName)
|
||||
.withArguments(setChannelArguments)
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channel"))
|
||||
.executesPlayer(this::channel)
|
||||
.register();
|
||||
|
||||
final LinkedHashMap<String, Argument> sendMessageArguments = new LinkedHashMap<>();
|
||||
sendMessageArguments.put("message", new GreedyStringArgument());
|
||||
|
||||
new CommandAPICommand(this.commandName)
|
||||
.withArguments(sendMessageArguments)
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channel.message"))
|
||||
.executesPlayer(this::sendMessage)
|
||||
.register();
|
||||
}
|
||||
|
||||
private void channel(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
|
||||
if (user.channelSettings(this.chatChannel()).ignored()) {
|
||||
user.sendMessage(this.carbonChat.messageProcessor().processMessage(this.chatChannel().cannotUseMessage(),
|
||||
"br", "\n",
|
||||
"color", "<" + this.chatChannel().channelColor(user).toString() + ">",
|
||||
"channel", this.chatChannel().name()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
user.selectedChannel(this.chatChannel());
|
||||
}
|
||||
|
||||
private void sendMessage(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
final String message = (String) args[0];
|
||||
|
||||
final Component component = this.chatChannel().sendMessage(user, message, false);
|
||||
|
||||
this.carbonChat.messageProcessor().audiences().console().sendMessage(component);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public ChatChannel chatChannel() {
|
||||
return this.chatChannel;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String commandName() {
|
||||
return this.commandName;
|
||||
}
|
||||
}
|
||||
@@ -1,81 +0,0 @@
|
||||
package net.draycia.carbon.commands;
|
||||
|
||||
import net.draycia.carbon.api.commands.CommandSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.CommandPermission;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class ChannelCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
|
||||
public ChannelCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
final LinkedHashMap<String, Argument> setChannelArguments = new LinkedHashMap<>();
|
||||
setChannelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(setChannelArguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channel"))
|
||||
.executesPlayer(this::channel)
|
||||
.register();
|
||||
|
||||
final LinkedHashMap<String, Argument> sendMessageArguments = new LinkedHashMap<>();
|
||||
sendMessageArguments.put("channel", CarbonUtils.channelArgument());
|
||||
sendMessageArguments.put("message", new GreedyStringArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(sendMessageArguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channel.message"))
|
||||
.executesPlayer(this::sendMessage)
|
||||
.register();
|
||||
}
|
||||
|
||||
private void channel(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
final ChatChannel channel = (ChatChannel) args[0];
|
||||
|
||||
if (user.channelSettings(channel).ignored()) {
|
||||
user.sendMessage(this.carbonChat.messageProcessor().processMessage(channel.cannotUseMessage(),
|
||||
"br", "\n",
|
||||
"color", "<" + channel.channelColor(user).toString() + ">",
|
||||
"channel", channel.name()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
user.selectedChannel(channel);
|
||||
}
|
||||
|
||||
private void sendMessage(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
final ChatChannel channel = (ChatChannel) args[0];
|
||||
final String message = (String) args[1];
|
||||
|
||||
final Component component = channel.sendMessage(user, message, false);
|
||||
|
||||
this.carbonChat.messageProcessor().audiences().console().sendMessage(component);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,153 +0,0 @@
|
||||
package net.draycia.carbon.commands;
|
||||
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.CommandPermission;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.commands.CommandSettings;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ChannelListCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
|
||||
public ChannelListCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
final LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(channelArguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channellist"))
|
||||
.executesPlayer(this::executeSelf)
|
||||
.register();
|
||||
|
||||
final LinkedHashMap<String, Argument> argumentsOther = new LinkedHashMap<>();
|
||||
argumentsOther.put("player", CarbonUtils.onlineChatUserArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(argumentsOther)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channellist.other"))
|
||||
.executes(this::executeOther)
|
||||
.register();
|
||||
}
|
||||
|
||||
public void executeSelf(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final Iterator<ChatChannel> allChannels = this.carbonChat.channelRegistry().iterator();
|
||||
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
|
||||
this.listAndSend(player, user, allChannels);
|
||||
}
|
||||
|
||||
public void executeOther(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
|
||||
final Audience cmdSender;
|
||||
|
||||
if (sender instanceof Player) {
|
||||
cmdSender = this.carbonChat.userService().wrap(((Player) sender).getUniqueId());
|
||||
} else {
|
||||
cmdSender = this.carbonChat.messageProcessor().audiences().console();
|
||||
}
|
||||
|
||||
final ChatUser user = (ChatUser) args[0];
|
||||
|
||||
final OfflinePlayer player = Bukkit.getOfflinePlayer(user.uuid());
|
||||
|
||||
if (!player.isOnline()) {
|
||||
final String mustBeOnline = this.carbonChat.translations().userMustBeOnline();
|
||||
cmdSender.sendMessage(this.carbonChat.messageProcessor().processMessage(mustBeOnline, "br", "\n", "player", player.getName()));
|
||||
return;
|
||||
}
|
||||
|
||||
final Iterator<ChatChannel> allChannels = this.carbonChat.channelRegistry().iterator();
|
||||
this.listAndSend(sender, user, allChannels);
|
||||
}
|
||||
|
||||
private void listAndSend(@NonNull final CommandSender sender, @NonNull final ChatUser user,
|
||||
@NonNull final Iterator<ChatChannel> allChannels) {
|
||||
ChatChannel channel;
|
||||
final List<ChatChannel> canSee = new ArrayList<>();
|
||||
final List<ChatChannel> cannotSee = new ArrayList<>();
|
||||
|
||||
while (allChannels.hasNext()) {
|
||||
channel = allChannels.next();
|
||||
|
||||
if (channel.canPlayerSee(user, true)) {
|
||||
canSee.add(channel);
|
||||
} else {
|
||||
cannotSee.add(channel);
|
||||
}
|
||||
}
|
||||
|
||||
final Iterator<ChatChannel> visibleChannels = canSee.iterator();
|
||||
final TextComponent.Builder availableList = TextComponent.builder("");
|
||||
|
||||
this.makeList(visibleChannels, availableList);
|
||||
|
||||
final String availableFormat = this.carbonChat.translations().availableChannelsList();
|
||||
Component availableComponent = this.carbonChat.messageProcessor().processMessage(availableFormat, "br", "\n");
|
||||
availableComponent = availableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), ac -> availableList);
|
||||
|
||||
final Audience cmdSender;
|
||||
|
||||
if (sender instanceof Player) {
|
||||
cmdSender = this.carbonChat.userService().wrap(((Player) sender).getUniqueId());
|
||||
} else {
|
||||
cmdSender = this.carbonChat.messageProcessor().audiences().console();
|
||||
}
|
||||
|
||||
cmdSender.sendMessage(availableComponent);
|
||||
|
||||
if (sender.hasPermission("carbonchat.channellist.bypass") && !cannotSee.isEmpty()) {
|
||||
final Iterator<ChatChannel> invisibleChannels = cannotSee.iterator();
|
||||
final TextComponent.Builder unavailableList = TextComponent.builder("");
|
||||
|
||||
this.makeList(invisibleChannels, unavailableList);
|
||||
|
||||
final String unavailableFormat = this.carbonChat.translations().unavailableChannelsList();
|
||||
Component unavailableComponent = this.carbonChat.messageProcessor().processMessage(unavailableFormat, "br", "\n");
|
||||
unavailableComponent = unavailableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), uac -> unavailableList);
|
||||
|
||||
cmdSender.sendMessage(unavailableComponent);
|
||||
}
|
||||
}
|
||||
|
||||
private void makeList(@NonNull final Iterator<@NonNull ChatChannel> iterator, final TextComponent.@NonNull Builder list) {
|
||||
final String listSeparator = this.carbonChat.translations().channelListSeparator();
|
||||
// TODO: Larry, why did you double assign the listSeparatorComponent?
|
||||
final Component listSeparatorComponent = TextComponent.of(listSeparator);
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
list.append(TextComponent.of(iterator.next().name()));
|
||||
|
||||
if (iterator.hasNext()) {
|
||||
list.append(listSeparatorComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
package net.draycia.carbon.commands;
|
||||
|
||||
import net.draycia.carbon.api.commands.CommandSettings;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.CommandPermission;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class ChatReloadCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
|
||||
public ChatReloadCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.reload"))
|
||||
.executes(this::execute)
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
|
||||
this.carbonChat.reloadConfig();
|
||||
this.carbonChat.reloadFilters();
|
||||
|
||||
final Component message = this.carbonChat.messageProcessor()
|
||||
.processMessage(this.carbonChat.translations().reloaded().replace("br", "\n"));
|
||||
|
||||
final Audience cmdSender;
|
||||
|
||||
if (sender instanceof Player) {
|
||||
cmdSender = this.carbonChat.userService().wrap(((Player) sender).getUniqueId());
|
||||
} else {
|
||||
cmdSender = this.carbonChat.messageProcessor().audiences().console();
|
||||
}
|
||||
|
||||
cmdSender.sendMessage(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
package net.draycia.carbon.commands;
|
||||
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.commands.CommandSettings;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.CommandPermission;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class ClearChatCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
|
||||
public ClearChatCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.clearchat.clear"))
|
||||
.executes(this::execute)
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
|
||||
final String format = this.carbonChat.moderationConfig().getString("clear-chat.message", "");
|
||||
final Component component = this.carbonChat.messageProcessor().processMessage(format, "br", "\n");
|
||||
|
||||
for (final Player player : Bukkit.getOnlinePlayers()) {
|
||||
final ChatUser audience = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
|
||||
if (player.hasPermission("carbonchat.clearchat.exempt")) {
|
||||
final String message = this.carbonChat.translations().clearExempt();
|
||||
audience.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "player", sender.getName()));
|
||||
} else {
|
||||
for (int i = 0; i < this.carbonChat.moderationConfig().getInt("clear-chat.message-count", 100); i++) {
|
||||
audience.sendMessage(component);
|
||||
}
|
||||
}
|
||||
|
||||
if (player.hasPermission("carbonchat.clearchat.notify")) {
|
||||
final String message = this.carbonChat.translations().clearNotify();
|
||||
audience.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "player", sender.getName()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
package net.draycia.carbon.commands;
|
||||
|
||||
import net.draycia.carbon.api.commands.CommandSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.CommandPermission;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class IgnoreCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
|
||||
public IgnoreCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
final LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
channelArguments.put("player", CarbonUtils.chatUserArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(channelArguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.ignore"))
|
||||
.executesPlayer(this::execute)
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser targetUser = (ChatUser) args[0];
|
||||
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(user.uuid());
|
||||
|
||||
if (user.ignoringUser(targetUser)) {
|
||||
user.ignoringUser(targetUser, false);
|
||||
user.sendMessage(this.carbonChat.messageProcessor().processMessage(
|
||||
this.carbonChat.translations().notIgnoringUser(),
|
||||
"br", "\n", "player", offlinePlayer.getName()));
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> {
|
||||
final Permission permission = this.carbonChat.permission();
|
||||
final String format;
|
||||
|
||||
if (permission.playerHas(null, offlinePlayer, "carbonchat.ignore.exempt")) {
|
||||
format = this.carbonChat.translations().ignoreExempt();
|
||||
} else {
|
||||
user.ignoringUser(targetUser, true);
|
||||
format = this.carbonChat.translations().ignoringUser();
|
||||
}
|
||||
|
||||
final Component message = this.carbonChat.messageProcessor().processMessage(format,
|
||||
"br", "\n", "sender", player.getDisplayName(), "player", offlinePlayer.getName());
|
||||
|
||||
user.sendMessage(message);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package net.draycia.carbon.commands;
|
||||
|
||||
import net.draycia.carbon.api.commands.CommandSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.CommandPermission;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class MessageCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
|
||||
public MessageCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
final LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("player", CarbonUtils.chatUserArgument());
|
||||
arguments.put("message", new GreedyStringArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(arguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.message"))
|
||||
.executesPlayer(this::execute)
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser targetUser = (ChatUser) args[0];
|
||||
final String message = (String) args[1];
|
||||
|
||||
final ChatUser sender = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
|
||||
targetUser.sendMessage(sender, message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,111 +0,0 @@
|
||||
package net.draycia.carbon.commands;
|
||||
|
||||
import net.draycia.carbon.api.commands.CommandSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.CommandPermission;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
import dev.jorel.commandapi.arguments.StringArgument;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class NicknameCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
|
||||
public NicknameCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
final LinkedHashMap<String, Argument> selfArguments = new LinkedHashMap<>();
|
||||
selfArguments.put("nickname", new StringArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(selfArguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.nickname"))
|
||||
.executesPlayer(this::executeSelf)
|
||||
.register();
|
||||
|
||||
final LinkedHashMap<String, Argument> otherArguments = new LinkedHashMap<>();
|
||||
otherArguments.put("player", CarbonUtils.chatUserArgument());
|
||||
otherArguments.put("nickname", new StringArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(otherArguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.nickname.others"))
|
||||
.executes(this::executeOther)
|
||||
.register();
|
||||
}
|
||||
|
||||
private void executeSelf(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
String nickname = (String) args[0];
|
||||
final ChatUser sender = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
|
||||
if (nickname.equalsIgnoreCase("off") || nickname.equalsIgnoreCase(player.getName())) {
|
||||
nickname = null;
|
||||
}
|
||||
|
||||
sender.nickname(nickname);
|
||||
|
||||
final String message;
|
||||
|
||||
if (nickname == null) {
|
||||
message = this.carbonChat.translations().nicknameReset();
|
||||
} else {
|
||||
message = this.carbonChat.translations().nicknameSet();
|
||||
}
|
||||
|
||||
sender.sendMessage(this.carbonChat.messageProcessor().processMessage(
|
||||
message, "nickname", nickname == null ? "" : nickname,
|
||||
"user", Bukkit.getOfflinePlayer(sender.uuid()).getName()));
|
||||
}
|
||||
|
||||
private void executeOther(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
|
||||
final Audience cmdSender;
|
||||
|
||||
if (sender instanceof Player) {
|
||||
cmdSender = this.carbonChat.userService().wrap(((Player) sender).getUniqueId());
|
||||
} else {
|
||||
cmdSender = this.carbonChat.messageProcessor().audiences().console();
|
||||
}
|
||||
|
||||
final ChatUser target = (ChatUser) args[0];
|
||||
String nickname = (String) args[1];
|
||||
|
||||
if (nickname.equalsIgnoreCase("off") ||
|
||||
nickname.equalsIgnoreCase(Bukkit.getOfflinePlayer(target.uuid()).getName())) {
|
||||
nickname = null;
|
||||
}
|
||||
|
||||
target.nickname(nickname);
|
||||
|
||||
final String message;
|
||||
|
||||
if (nickname == null) {
|
||||
message = this.carbonChat.translations().otherNicknameReset();
|
||||
} else {
|
||||
message = this.carbonChat.translations().otherNicknameSet();
|
||||
}
|
||||
|
||||
cmdSender.sendMessage(this.carbonChat.messageProcessor().processMessage(
|
||||
message, "nickname", nickname == null ? "" : nickname,
|
||||
"user", Bukkit.getOfflinePlayer(target.uuid()).getName()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,22 +1,22 @@
|
||||
package net.draycia.carbon.managers;
|
||||
|
||||
import net.draycia.carbon.commands.ChannelCommand;
|
||||
import net.draycia.carbon.commands.ChannelListCommand;
|
||||
import net.draycia.carbon.commands.ChatReloadCommand;
|
||||
import net.draycia.carbon.commands.ClearChatCommand;
|
||||
import net.draycia.carbon.commands.IgnoreCommand;
|
||||
import net.draycia.carbon.commands.MeCommand;
|
||||
import net.draycia.carbon.commands.MessageCommand;
|
||||
import net.draycia.carbon.commands.MuteCommand;
|
||||
import net.draycia.carbon.commands.NicknameCommand;
|
||||
import net.draycia.carbon.commands.ReplyCommand;
|
||||
import net.draycia.carbon.commands.SetColorCommand;
|
||||
import net.draycia.carbon.commands.SpyChannelCommand;
|
||||
import net.draycia.carbon.commands.SudoChannelCommand;
|
||||
import net.draycia.carbon.commands.ToggleCommand;
|
||||
import net.draycia.carbon.api.commands.CommandSettings;
|
||||
import net.draycia.carbon.common.commands.ChannelCommand;
|
||||
import net.draycia.carbon.common.commands.ChannelListCommand;
|
||||
import net.draycia.carbon.common.commands.ChatReloadCommand;
|
||||
import net.draycia.carbon.common.commands.ClearChatCommand;
|
||||
import net.draycia.carbon.common.commands.IgnoreCommand;
|
||||
import net.draycia.carbon.common.commands.MeCommand;
|
||||
import net.draycia.carbon.common.commands.MessageCommand;
|
||||
import net.draycia.carbon.common.commands.MuteCommand;
|
||||
import net.draycia.carbon.common.commands.NicknameCommand;
|
||||
import net.draycia.carbon.common.commands.ReplyCommand;
|
||||
import net.draycia.carbon.common.commands.SetColorCommand;
|
||||
import net.draycia.carbon.common.commands.SpyChannelCommand;
|
||||
import net.draycia.carbon.common.commands.SudoChannelCommand;
|
||||
import net.draycia.carbon.common.commands.ToggleCommand;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.draycia.carbon.commands.ShadowMuteCommand;
|
||||
import net.draycia.carbon.common.commands.ShadowMuteCommand;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class CommandManager {
|
||||
|
||||
+26
-1
@@ -14,6 +14,7 @@ import net.kyori.adventure.audience.ForwardingAudience;
|
||||
import net.kyori.adventure.key.Key;
|
||||
import net.kyori.adventure.sound.Sound;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.luckperms.api.LuckPermsProvider;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -84,7 +85,8 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(@NonNull final String permission) {
|
||||
return Bukkit.getPlayer(this.uuid()).hasPermission(permission);
|
||||
return LuckPermsProvider.get().getUserManager().getUser(this.uuid())
|
||||
.getCachedData().getPermissionData().checkPermission(permission).asBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -120,6 +122,29 @@ public class CarbonChatUser implements ChatUser, ForwardingAudience {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public @Nullable String displayName() {
|
||||
final Player player = Bukkit.getPlayer(this.uuid());
|
||||
|
||||
if (player != null) {
|
||||
return player.getDisplayName();
|
||||
}
|
||||
|
||||
return this.name();
|
||||
}
|
||||
|
||||
public void displayName(final @Nullable String displayName) {
|
||||
final Player player = Bukkit.getPlayer(this.uuid());
|
||||
|
||||
if (player != null) {
|
||||
player.setDisplayName(displayName);
|
||||
}
|
||||
}
|
||||
|
||||
public @Nullable String name() {
|
||||
return Bukkit.getOfflinePlayer(this.uuid()).getName();
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public ChatChannel selectedChannel() {
|
||||
|
||||
+6
-11
@@ -1,9 +1,10 @@
|
||||
package net.draycia.carbon.storage.impl;
|
||||
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.users.UserChannelSettings;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
import org.checkerframework.checker.nullness.qual.Nullable;
|
||||
@@ -13,7 +14,7 @@ import java.util.UUID;
|
||||
public class SimpleUserChannelSettings implements UserChannelSettings {
|
||||
|
||||
@NonNull
|
||||
private final transient CarbonChatBukkit carbonChat;
|
||||
private final transient CarbonChat carbonChat = CarbonChatProvider.carbonChat();
|
||||
private boolean spying;
|
||||
private boolean ignored;
|
||||
@Nullable
|
||||
@@ -23,20 +24,14 @@ public class SimpleUserChannelSettings implements UserChannelSettings {
|
||||
@MonotonicNonNull // @NonNull but not initialised in all constructors.
|
||||
private String channel;
|
||||
|
||||
private SimpleUserChannelSettings() {
|
||||
this.carbonChat = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
}
|
||||
|
||||
public SimpleUserChannelSettings(@NonNull final UUID uuid, @NonNull final String channel) {
|
||||
this.uuid = uuid;
|
||||
this.channel = channel;
|
||||
|
||||
this.carbonChat = (CarbonChatBukkit) Bukkit.getPluginManager().getPlugin("CarbonChat");
|
||||
}
|
||||
|
||||
@NonNull
|
||||
private CarbonChatUser user() {
|
||||
return (CarbonChatUser) this.carbonChat.userService().wrap(this.uuid);
|
||||
private ChatUser user() {
|
||||
return this.carbonChat.userService().wrap(this.uuid);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package net.draycia.carbon.util;
|
||||
|
||||
import dev.jorel.commandapi.CommandAPI;
|
||||
import net.draycia.carbon.api.commands.CommandSettings;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public final class CommandUtils {
|
||||
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.components.standard.StringComponent;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class AliasedChannelCommand {
|
||||
|
||||
private final @NonNull CarbonChat carbonChat;
|
||||
|
||||
private final @NonNull ChatChannel chatChannel;
|
||||
|
||||
private final @NonNull String commandName;
|
||||
|
||||
public AliasedChannelCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final ChatChannel chatChannel) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
this.chatChannel = chatChannel;
|
||||
this.commandName = chatChannel.key();
|
||||
|
||||
commandManager.command(
|
||||
commandManager.commandBuilder(this.commandName)
|
||||
.withSenderType(ChatUser.class) // player
|
||||
.withPermission("carbonchat.channel")
|
||||
.handler(this::channel)
|
||||
.build()
|
||||
);
|
||||
|
||||
commandManager.command(
|
||||
commandManager.commandBuilder(this.commandName)
|
||||
.withSenderType(ChatUser.class) // player
|
||||
.withPermission("carbonchat.channel.message")
|
||||
.component(StringComponent.required("message"))
|
||||
.handler(this::sendMessage)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
private void channel(@NonNull final CommandContext<ChatUser> context) {
|
||||
final ChatUser user = context.getSender();
|
||||
|
||||
if (user.channelSettings(this.chatChannel()).ignored()) {
|
||||
user.sendMessage(this.carbonChat.messageProcessor().processMessage(this.chatChannel().cannotUseMessage(),
|
||||
"br", "\n",
|
||||
"color", "<" + this.chatChannel().channelColor(user).toString() + ">",
|
||||
"channel", this.chatChannel().name()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
user.selectedChannel(this.chatChannel());
|
||||
}
|
||||
|
||||
private void sendMessage(@NonNull final CommandContext<ChatUser> context) {
|
||||
context.<String>get("message").ifPresent(message -> {
|
||||
final Component component = this.chatChannel().sendMessage(context.getSender(), message, false);
|
||||
|
||||
this.carbonChat.messageProcessor().audiences().console().sendMessage(component);
|
||||
});
|
||||
}
|
||||
|
||||
public @NonNull ChatChannel chatChannel() {
|
||||
return this.chatChannel;
|
||||
}
|
||||
|
||||
public @NonNull String commandName() {
|
||||
return this.commandName;
|
||||
}
|
||||
}
|
||||
+75
@@ -0,0 +1,75 @@
|
||||
package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.components.standard.StringComponent;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.common.utils.CommandUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class ChannelCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ChannelCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
commandManager.command(
|
||||
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
|
||||
commandManager.createDefaultCommandMeta())
|
||||
.withSenderType(ChatUser.class) // player
|
||||
.withPermission("carbonchat.channel")
|
||||
.component(CommandUtils.channelComponent())
|
||||
.handler(this::channel)
|
||||
.build()
|
||||
);
|
||||
|
||||
commandManager.command(
|
||||
commandManager.commandBuilder(commandSettings.name())
|
||||
.withSenderType(ChatUser.class) // player
|
||||
.withPermission("carbonchat.channel.message")
|
||||
.component(CommandUtils.channelComponent())
|
||||
.component(StringComponent.required("message"))
|
||||
.handler(this::sendMessage)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
private void channel(@NonNull final CommandContext<ChatUser> context) {
|
||||
final ChatUser user = context.getSender();
|
||||
final ChatChannel channel = context.getRequired("channel");
|
||||
|
||||
if (user.channelSettings(channel).ignored()) {
|
||||
user.sendMessage(this.carbonChat.messageProcessor().processMessage(channel.cannotUseMessage(),
|
||||
"br", "\n",
|
||||
"color", "<" + channel.channelColor(user).toString() + ">",
|
||||
"channel", channel.name()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
user.selectedChannel(channel);
|
||||
}
|
||||
|
||||
private void sendMessage(@NonNull final CommandContext<ChatUser> context) {
|
||||
final ChatUser user = context.getSender();
|
||||
final ChatChannel channel = context.getRequired("channel");
|
||||
final String message = context.getRequired("message");
|
||||
|
||||
final Component component = channel.sendMessage(user, message, false);
|
||||
|
||||
this.carbonChat.messageProcessor().audiences().console().sendMessage(component);
|
||||
}
|
||||
|
||||
}
|
||||
+125
@@ -0,0 +1,125 @@
|
||||
package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.common.utils.CommandUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.kyori.adventure.text.TextComponent;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
public class ChannelListCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ChannelListCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
commandManager.command(
|
||||
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
|
||||
commandManager.createDefaultCommandMeta())
|
||||
.withSenderType(ChatUser.class) // player
|
||||
.withPermission("carbonchat.channellist")
|
||||
.handler(this::toggleSelf)
|
||||
.build()
|
||||
);
|
||||
|
||||
commandManager.command(
|
||||
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
|
||||
commandManager.createDefaultCommandMeta())
|
||||
.withSenderType(ChatUser.class) // console & player
|
||||
.withPermission("carbonchat.channellist.other")
|
||||
.component(CommandUtils.chatUserComponent())
|
||||
.handler(this::toggleOther)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
public void toggleSelf(@NonNull final CommandContext<ChatUser> context) {
|
||||
this.listAndSend(context.getSender(), context.getSender(), this.carbonChat.channelRegistry().iterator());
|
||||
}
|
||||
|
||||
public void toggleOther(@NonNull final CommandContext<ChatUser> context) {
|
||||
final ChatUser sender = context.getSender();
|
||||
final ChatUser user = context.getRequired("user");
|
||||
|
||||
if (!user.online()) {
|
||||
final String mustBeOnline = this.carbonChat.translations().userMustBeOnline();
|
||||
sender.sendMessage(this.carbonChat.messageProcessor().processMessage(mustBeOnline, "br", "\n", "player", user.name()));
|
||||
return;
|
||||
}
|
||||
|
||||
final Iterator<ChatChannel> allChannels = this.carbonChat.channelRegistry().iterator();
|
||||
this.listAndSend(sender, user, allChannels);
|
||||
}
|
||||
|
||||
private void listAndSend(@NonNull final ChatUser sender, @NonNull final ChatUser user,
|
||||
@NonNull final Iterator<ChatChannel> allChannels) {
|
||||
ChatChannel channel;
|
||||
final List<ChatChannel> canSee = new ArrayList<>();
|
||||
final List<ChatChannel> cannotSee = new ArrayList<>();
|
||||
|
||||
while (allChannels.hasNext()) {
|
||||
channel = allChannels.next();
|
||||
|
||||
if (channel.canPlayerSee(user, true)) {
|
||||
canSee.add(channel);
|
||||
} else {
|
||||
cannotSee.add(channel);
|
||||
}
|
||||
}
|
||||
|
||||
final Iterator<ChatChannel> visibleChannels = canSee.iterator();
|
||||
final TextComponent.Builder availableList = TextComponent.builder("");
|
||||
|
||||
this.makeList(visibleChannels, availableList);
|
||||
|
||||
final String availableFormat = this.carbonChat.translations().availableChannelsList();
|
||||
Component availableComponent = this.carbonChat.messageProcessor().processMessage(availableFormat, "br", "\n");
|
||||
availableComponent = availableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), ac -> availableList);
|
||||
|
||||
sender.sendMessage(availableComponent);
|
||||
|
||||
if (sender.hasPermission("carbonchat.channellist.bypass") && !cannotSee.isEmpty()) {
|
||||
final Iterator<ChatChannel> invisibleChannels = cannotSee.iterator();
|
||||
final TextComponent.Builder unavailableList = TextComponent.builder("");
|
||||
|
||||
this.makeList(invisibleChannels, unavailableList);
|
||||
|
||||
final String unavailableFormat = this.carbonChat.translations().unavailableChannelsList();
|
||||
Component unavailableComponent = this.carbonChat.messageProcessor().processMessage(unavailableFormat, "br", "\n");
|
||||
unavailableComponent = unavailableComponent.replaceFirstText(Pattern.compile(Pattern.quote("<list>")), uac -> unavailableList);
|
||||
|
||||
sender.sendMessage(unavailableComponent);
|
||||
}
|
||||
}
|
||||
|
||||
private void makeList(@NonNull final Iterator<@NonNull ChatChannel> iterator, final TextComponent.@NonNull Builder list) {
|
||||
final String listSeparator = this.carbonChat.translations().channelListSeparator();
|
||||
// TODO: Larry, why did you double assign the listSeparatorComponent?
|
||||
final Component listSeparatorComponent = TextComponent.of(listSeparator);
|
||||
|
||||
while (iterator.hasNext()) {
|
||||
list.append(TextComponent.of(iterator.next().name()));
|
||||
|
||||
if (iterator.hasNext()) {
|
||||
list.append(listSeparatorComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class ChatReloadCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ChatReloadCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
commandManager.command(
|
||||
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
|
||||
commandManager.createDefaultCommandMeta())
|
||||
.withSenderType(ChatUser.class) // player & console
|
||||
.withPermission("carbonchat.reload")
|
||||
.handler(this::reloadConfig)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
private void reloadConfig(@NonNull final CommandContext<ChatUser> context) {
|
||||
this.carbonChat.reloadConfig();
|
||||
this.carbonChat.reloadFilters();
|
||||
|
||||
final Component message = this.carbonChat.messageProcessor()
|
||||
.processMessage(this.carbonChat.translations().reloaded().replace("br", "\n"));
|
||||
|
||||
context.getSender().sendMessage(message);
|
||||
}
|
||||
|
||||
}
|
||||
+57
@@ -0,0 +1,57 @@
|
||||
package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class ClearChatCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ClearChatCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
commandManager.command(
|
||||
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
|
||||
commandManager.createDefaultCommandMeta())
|
||||
.withSenderType(ChatUser.class) // player & console
|
||||
.withPermission("carbonchat.clearchat.clear")
|
||||
.handler(this::clearChat)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
private void clearChat(@NonNull final CommandContext<ChatUser> context) {
|
||||
final String sender = context.getSender().name();
|
||||
final String format = this.carbonChat.moderationConfig().getString("clear-chat.message", "");
|
||||
final Component component = this.carbonChat.messageProcessor().processMessage(format, "br", "\n");
|
||||
|
||||
for (final ChatUser user : this.carbonChat.userService().onlineUsers()) {
|
||||
if (user.hasPermission("carbonchat.clearchat.exempt")) {
|
||||
final String message = this.carbonChat.translations().clearExempt();
|
||||
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "player", sender));
|
||||
} else {
|
||||
for (int i = 0; i < this.carbonChat.moderationConfig().getInt("clear-chat.message-count", 100); i++) {
|
||||
user.sendMessage(component);
|
||||
}
|
||||
}
|
||||
|
||||
if (user.hasPermission("carbonchat.clearchat.notify")) {
|
||||
final String message = this.carbonChat.translations().clearNotify();
|
||||
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "player", sender));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.common.utils.CommandUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class IgnoreCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public IgnoreCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
commandManager.command(
|
||||
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
|
||||
commandManager.createDefaultCommandMeta())
|
||||
.withSenderType(ChatUser.class) // console & player
|
||||
.withPermission("carbonchat.ignore")
|
||||
.component(CommandUtils.chatUserComponent())
|
||||
.handler(this::ignoreUser)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
private void ignoreUser(@NonNull final CommandContext<ChatUser> context) {
|
||||
final ChatUser sender = context.getSender();
|
||||
final ChatUser targetUser = context.getRequired("user");
|
||||
|
||||
final OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(sender.uuid());
|
||||
|
||||
if (sender.ignoringUser(targetUser)) {
|
||||
sender.ignoringUser(targetUser, false);
|
||||
sender.sendMessage(this.carbonChat.messageProcessor().processMessage(
|
||||
this.carbonChat.translations().notIgnoringUser(),
|
||||
"br", "\n", "player", offlinePlayer.getName()));
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> {
|
||||
final Permission permission = this.carbonChat.permission();
|
||||
final String format;
|
||||
|
||||
if (permission.playerHas(null, offlinePlayer, "carbonchat.ignore.exempt")) {
|
||||
format = this.carbonChat.translations().ignoreExempt();
|
||||
} else {
|
||||
user.ignoringUser(targetUser, true);
|
||||
format = this.carbonChat.translations().ignoringUser();
|
||||
}
|
||||
|
||||
final Component message = this.carbonChat.messageProcessor().processMessage(format,
|
||||
"br", "\n", "sender", player.getDisplayName(), "player", offlinePlayer.getName());
|
||||
|
||||
user.sendMessage(message);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+10
-7
@@ -1,13 +1,18 @@
|
||||
package net.draycia.carbon.commands;
|
||||
package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.CommandPermission;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||
import me.clip.placeholderapi.PlaceholderAPI;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.commands.CommandSettings;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -19,17 +24,15 @@ import java.util.LinkedHashMap;
|
||||
public class MeCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public MeCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
public MeCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
final LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
channelArguments.put("message", new GreedyStringArgument());
|
||||
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.components.standard.StringComponent;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.common.utils.CommandUtils;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class MessageCommand {
|
||||
|
||||
public MessageCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
commandManager.command(
|
||||
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
|
||||
commandManager.createDefaultCommandMeta())
|
||||
.withSenderType(ChatUser.class) // player
|
||||
.withPermission("carbonchat.message")
|
||||
.component(CommandUtils.chatUserComponent())
|
||||
.component(StringComponent.<ChatUser>newBuilder("message").greedy().build())
|
||||
.handler(this::sendMessage)
|
||||
.build()
|
||||
);
|
||||
}
|
||||
|
||||
private void sendMessage(@NonNull final CommandContext<ChatUser> context) {
|
||||
context.<ChatUser>getRequired("target")
|
||||
.sendMessage(context.getSender(), context.getRequired("message"));
|
||||
}
|
||||
|
||||
}
|
||||
+10
-7
@@ -1,7 +1,12 @@
|
||||
package net.draycia.carbon.commands;
|
||||
package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.commands.CommandSettings;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
@@ -22,17 +27,15 @@ import java.util.LinkedHashMap;
|
||||
public class MuteCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public MuteCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
public MuteCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
final LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("player", CarbonUtils.chatUserArgument());
|
||||
|
||||
+104
@@ -0,0 +1,104 @@
|
||||
package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.components.standard.StringComponent;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.common.utils.CommandUtils;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
public class NicknameCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public NicknameCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
commandManager.command(
|
||||
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
|
||||
commandManager.createDefaultCommandMeta())
|
||||
.withSenderType(ChatUser.class) // player
|
||||
.withPermission("carbonchat.nickname")
|
||||
.component(StringComponent.<ChatUser>newBuilder("nickname").single().build())
|
||||
.handler(this::nicknameOther)
|
||||
.build()
|
||||
);
|
||||
|
||||
commandManager.command(
|
||||
commandManager.commandBuilder(commandSettings.name(), commandSettings.aliases(),
|
||||
commandManager.createDefaultCommandMeta())
|
||||
.withSenderType(ChatUser.class) // player
|
||||
.withPermission("carbonchat.nickname")
|
||||
.component(CommandUtils.chatUserComponent())
|
||||
.component(StringComponent.<ChatUser>newBuilder("nickname").single().build())
|
||||
.handler(this::nicknameOther)
|
||||
.build()
|
||||
);
|
||||
|
||||
selfArguments.put("nickname", new StringArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(selfArguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.nickname"))
|
||||
.executesPlayer(this::executeSelf)
|
||||
.register();
|
||||
}
|
||||
|
||||
private void nicknameSelf(@NonNull final CommandContext<ChatUser> context) {
|
||||
final ChatUser user = context.getSender();
|
||||
String nickname = context.getRequired("nickname");
|
||||
|
||||
if (nickname.equalsIgnoreCase("off") || nickname.equalsIgnoreCase(user.name())) {
|
||||
nickname = null;
|
||||
}
|
||||
|
||||
user.nickname(nickname);
|
||||
|
||||
final String message;
|
||||
|
||||
if (nickname == null) {
|
||||
message = this.carbonChat.translations().nicknameReset();
|
||||
} else {
|
||||
message = this.carbonChat.translations().nicknameSet();
|
||||
}
|
||||
|
||||
user.sendMessage(this.carbonChat.messageProcessor().processMessage(
|
||||
message, "nickname", nickname == null ? "" : nickname,
|
||||
"user", user.name()));
|
||||
}
|
||||
|
||||
private void nicknameOther(@NonNull final CommandContext<ChatUser> context) {
|
||||
final ChatUser target = context.getRequired("user");
|
||||
String nickname = context.getRequired("nickname");
|
||||
|
||||
if (nickname.equalsIgnoreCase("off") ||
|
||||
nickname.equalsIgnoreCase(target.name())) {
|
||||
nickname = null;
|
||||
}
|
||||
|
||||
target.nickname(nickname);
|
||||
|
||||
final String message;
|
||||
|
||||
if (nickname == null) {
|
||||
message = this.carbonChat.translations().otherNicknameReset();
|
||||
} else {
|
||||
message = this.carbonChat.translations().otherNicknameSet();
|
||||
}
|
||||
|
||||
context.getSender().sendMessage(this.carbonChat.messageProcessor().processMessage(
|
||||
message, "nickname", nickname == null ? "" : nickname,
|
||||
"user", target.name()));
|
||||
}
|
||||
|
||||
}
|
||||
+10
-7
@@ -1,12 +1,17 @@
|
||||
package net.draycia.carbon.commands;
|
||||
package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.CommandPermission;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.commands.CommandSettings;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
@@ -17,17 +22,15 @@ import java.util.LinkedHashMap;
|
||||
public class ReplyCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ReplyCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
public ReplyCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
final LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("message", new GreedyStringArgument());
|
||||
|
||||
+9
-7
@@ -1,13 +1,17 @@
|
||||
package net.draycia.carbon.commands;
|
||||
package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
import dev.jorel.commandapi.CommandPermission;
|
||||
import dev.jorel.commandapi.arguments.Argument;
|
||||
import dev.jorel.commandapi.arguments.LiteralArgument;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.commands.CommandSettings;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.api.users.UserChannelSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
@@ -19,17 +23,15 @@ import java.util.LinkedHashMap;
|
||||
public class SetColorCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SetColorCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
public SetColorCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
for (final ChatChannel channel : this.carbonChat.channelRegistry()) {
|
||||
final LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("channel", new LiteralArgument(channel.key()));
|
||||
+9
-7
@@ -1,7 +1,11 @@
|
||||
package net.draycia.carbon.commands;
|
||||
package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.commands.CommandSettings;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
@@ -22,17 +26,15 @@ import java.util.LinkedHashMap;
|
||||
public class ShadowMuteCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ShadowMuteCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
public ShadowMuteCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
final LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("player", CarbonUtils.chatUserArgument());
|
||||
|
||||
+10
-7
@@ -1,8 +1,13 @@
|
||||
package net.draycia.carbon.commands;
|
||||
package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.commands.CommandSettings;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.api.users.UserChannelSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
@@ -20,17 +25,15 @@ import java.util.LinkedHashMap;
|
||||
public class SpyChannelCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SpyChannelCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
public SpyChannelCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
final LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
channelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
+10
-7
@@ -1,5 +1,10 @@
|
||||
package net.draycia.carbon.commands;
|
||||
package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
import dev.jorel.commandapi.CommandAPICommand;
|
||||
@@ -9,7 +14,7 @@ import dev.jorel.commandapi.arguments.GreedyStringArgument;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.commands.CommandSettings;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
@@ -22,17 +27,15 @@ import java.util.LinkedHashMap;
|
||||
public class SudoChannelCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SudoChannelCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
public SudoChannelCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
final LinkedHashMap<String, Argument> setOtherChannelArguments = new LinkedHashMap<>();
|
||||
setOtherChannelArguments.put("player", CarbonUtils.onlineChatUserArgument());
|
||||
setOtherChannelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
+19
-22
@@ -1,8 +1,14 @@
|
||||
package net.draycia.carbon.commands;
|
||||
package net.draycia.carbon.common.commands;
|
||||
|
||||
import com.intellectualsites.commands.CommandManager;
|
||||
import com.intellectualsites.commands.context.CommandContext;
|
||||
import com.intellectualsites.commands.meta.CommandMeta;
|
||||
import com.intellectualsites.commands.meta.SimpleCommandMeta;
|
||||
import net.draycia.carbon.api.CarbonChat;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
import net.draycia.carbon.api.commands.CommandSettings;
|
||||
import net.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.draycia.carbon.api.users.UserChannelSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
@@ -21,17 +27,15 @@ import java.util.LinkedHashMap;
|
||||
public class ToggleCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChatBukkit carbonChat;
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ToggleCommand(@NonNull final CarbonChatBukkit carbonChat, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = carbonChat;
|
||||
public ToggleCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
CommandUtils.handleDuplicateCommands(commandSettings);
|
||||
|
||||
final LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
channelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
@@ -54,8 +58,8 @@ public class ToggleCommand {
|
||||
.register();
|
||||
}
|
||||
|
||||
private void executeSelf(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
private void executeSelf(@NonNull final CommandContext<ChatUser> context) {
|
||||
final ChatUser user = context.getSender();
|
||||
final ChatChannel channel = (ChatChannel) args[0];
|
||||
|
||||
final String message;
|
||||
@@ -76,9 +80,10 @@ public class ToggleCommand {
|
||||
"color", "<color:" + channel.channelColor(user).toString() + ">", "channel", channel.name()));
|
||||
}
|
||||
|
||||
private void executeOther(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser user = (ChatUser) args[0];
|
||||
final ChatChannel channel = (ChatChannel) args[1];
|
||||
private void executeOther(@NonNull final CommandContext<ChatUser> context) {
|
||||
final ChatUser sender = context.getSender();
|
||||
final ChatUser user = context.getRequired("user");
|
||||
final ChatChannel channel = context.getRequired("channel");
|
||||
|
||||
final String message;
|
||||
final String otherMessage;
|
||||
@@ -98,17 +103,9 @@ public class ToggleCommand {
|
||||
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "br", "\n",
|
||||
"color", "<color:" + channel.channelColor(user).toString() + ">", "channel", channel.name()));
|
||||
|
||||
final Audience cmdSender;
|
||||
|
||||
if (sender instanceof Player) {
|
||||
cmdSender = this.carbonChat.userService().wrap(((Player) sender).getUniqueId());
|
||||
} else {
|
||||
cmdSender = this.carbonChat.messageProcessor().audiences().console();
|
||||
}
|
||||
|
||||
cmdSender.sendMessage(
|
||||
sender.sendMessage(
|
||||
this.carbonChat.messageProcessor().processMessage(otherMessage,
|
||||
"br", "\n", "color", "<color:" + channel.channelColor(user).toString() + ">",
|
||||
"channel", channel.name(), "player", Bukkit.getOfflinePlayer(user.uuid()).getName()));
|
||||
"channel", channel.name(), "player", user.name()));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
package net.draycia.carbon.common.utils;
|
||||
|
||||
import com.intellectualsites.commands.components.CommandComponent;
|
||||
import com.intellectualsites.commands.components.parser.ComponentParseResult;
|
||||
import net.draycia.carbon.api.CarbonChatProvider;
|
||||
import net.draycia.carbon.api.channels.ChatChannel;
|
||||
import net.draycia.carbon.api.users.ChatUser;
|
||||
|
||||
public final class CommandUtils {
|
||||
|
||||
private CommandUtils() {
|
||||
|
||||
}
|
||||
|
||||
// TODO: turn this into a proper class that handles suggestions
|
||||
private static final CommandComponent<ChatUser, ChatChannel> commandComponent =
|
||||
CommandComponent.<ChatUser, ChatChannel>ofType(ChatChannel.class, "channel")
|
||||
.asRequired()
|
||||
.withParser((c, i) -> {
|
||||
final String input = i.peek();
|
||||
|
||||
if (input == null) {
|
||||
return ComponentParseResult.failure(new IllegalArgumentException("Channel cannot be null"));
|
||||
}
|
||||
|
||||
final ChatChannel channel = CarbonChatProvider.carbonChat()
|
||||
.channelRegistry().get(input);
|
||||
|
||||
if (channel != null) {
|
||||
return ComponentParseResult.success(channel);
|
||||
} else {
|
||||
return ComponentParseResult.failure(new IllegalArgumentException("Channel does not exist"));
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
||||
public static CommandComponent<ChatUser, ChatChannel> channelComponent() {
|
||||
return commandComponent;
|
||||
}
|
||||
|
||||
// TODO: turn this into a proper class that handles suggestions
|
||||
private static final CommandComponent<ChatUser, ChatUser> chatUserComponent =
|
||||
CommandComponent.<ChatUser, ChatUser>ofType(ChatUser.class, "user")
|
||||
.asRequired()
|
||||
.withParser((c, i) -> {
|
||||
final String input = i.peek();
|
||||
|
||||
if (input == null) {
|
||||
return ComponentParseResult.failure(new IllegalArgumentException("Player cannot be null"));
|
||||
}
|
||||
|
||||
final ChatUser user = CarbonChatProvider.carbonChat()
|
||||
.userService().wrap(null); // TODO: find way to resolve name -> uuid
|
||||
|
||||
if (user != null) {
|
||||
return ComponentParseResult.success(user);
|
||||
} else {
|
||||
return ComponentParseResult.failure(new IllegalArgumentException("Player does not exist"));
|
||||
}
|
||||
})
|
||||
.build();
|
||||
|
||||
public static CommandComponent<ChatUser, ChatUser> chatUserComponent() {
|
||||
return chatUserComponent;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user