mirror of
https://github.com/darksaid98/Carbon.git
synced 2026-12-02 22:16:22 +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
+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);
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
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.settings.CommandSettings;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class MeCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public MeCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
channelArguments.put("message", new GreedyStringArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(channelArguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.me"))
|
||||
.executesPlayer(this::execute)
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final String message = ((String) args[0]).replace("</pre>", "");
|
||||
String format = PlaceholderAPI.setPlaceholders(player, this.carbonChat.translations().roleplayFormat());
|
||||
|
||||
if (!player.hasPermission("carbonchat.me.formatting")) {
|
||||
format = format.replace("<message>", "<pre><message></pre>");
|
||||
}
|
||||
|
||||
final Component component = this.carbonChat.messageProcessor().processMessage(format, "br", "\n",
|
||||
"displayname", player.getDisplayName(), "message", message);
|
||||
|
||||
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
|
||||
if (user.shadowMuted()) {
|
||||
user.sendMessage(component);
|
||||
} else {
|
||||
for (final Player onlinePlayer : Bukkit.getOnlinePlayers()) {
|
||||
if (this.carbonChat.userService().wrap(onlinePlayer.getUniqueId()).ignoringUser(user)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
this.carbonChat.messageProcessor().audiences().player(onlinePlayer.getUniqueId()).sendMessage(component);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+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"));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,90 @@
|
||||
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.settings.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.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
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.LinkedHashMap;
|
||||
|
||||
public class MuteCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public MuteCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("player", CarbonUtils.chatUserArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(arguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.mute"))
|
||||
.executes(this::execute)
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@NonNull final CommandSender sender, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser user = (ChatUser) args[0];
|
||||
|
||||
final Audience cmdSender;
|
||||
|
||||
if (sender instanceof Player) {
|
||||
cmdSender = this.carbonChat.userService().wrap(((Player) sender).getUniqueId());
|
||||
} else {
|
||||
cmdSender = this.carbonChat.messageProcessor().audiences().console();
|
||||
}
|
||||
|
||||
final OfflinePlayer player = Bukkit.getOfflinePlayer(user.uuid());
|
||||
|
||||
if (user.shadowMuted()) {
|
||||
user.muted(false);
|
||||
final String format = this.carbonChat.translations().noLongerMuted();
|
||||
|
||||
final Component message = this.carbonChat.messageProcessor().processMessage(format, "br", "\n",
|
||||
"player", player.getName());
|
||||
|
||||
cmdSender.sendMessage(message);
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> {
|
||||
final Permission permission = this.carbonChat.permission();
|
||||
final String format;
|
||||
|
||||
if (permission.playerHas(null, player, "carbonchat.mute.exempt")) {
|
||||
format = this.carbonChat.translations().muteExempt();
|
||||
} else {
|
||||
user.muted(true);
|
||||
format = this.carbonChat.translations().nowMuted();
|
||||
}
|
||||
|
||||
final Component message = this.carbonChat.messageProcessor().processMessage(format, "br", "\n",
|
||||
"player", player.getName());
|
||||
|
||||
cmdSender.sendMessage(message);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+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()));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
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.settings.CommandSettings;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class ReplyCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ReplyCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("message", new GreedyStringArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(arguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.reply"))
|
||||
.executesPlayer(this::execute)
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final String input = (String) args[0];
|
||||
|
||||
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
|
||||
if (input.isEmpty()) {
|
||||
final String message = this.carbonChat.translations().replyMessageBlank();
|
||||
final Component component = this.carbonChat.messageProcessor().processMessage(message, "br", "\n");
|
||||
|
||||
user.sendMessage(component);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (user.replyTarget() == null) {
|
||||
final String message = this.carbonChat.translations().noReplyTarget();
|
||||
final Component component = this.carbonChat.messageProcessor().processMessage(message, "br", "\n");
|
||||
|
||||
user.sendMessage(component);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
final ChatUser targetUser = this.carbonChat.userService().wrap(user.replyTarget());
|
||||
|
||||
targetUser.sendMessage(user, input);
|
||||
}
|
||||
|
||||
}
|
||||
+70
@@ -0,0 +1,70 @@
|
||||
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.settings.CommandSettings;
|
||||
import net.draycia.carbon.api.users.UserChannelSettings;
|
||||
import net.draycia.carbon.util.CarbonUtils;
|
||||
import net.draycia.carbon.util.CommandUtils;
|
||||
import net.kyori.adventure.text.format.TextColor;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class SetColorCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SetColorCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (final ChatChannel channel : this.carbonChat.channelRegistry()) {
|
||||
final LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("channel", new LiteralArgument(channel.key()));
|
||||
arguments.put("color", CarbonUtils.textColorArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(arguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.setcolor"))
|
||||
.executesPlayer((player, args) -> {
|
||||
final TextColor color = (TextColor) args[0];
|
||||
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
|
||||
if (!player.hasPermission("carbonchat.setcolor." + channel.key())) {
|
||||
user.sendMessage(carbonChat.messageProcessor().processMessage(
|
||||
this.carbonChat.translations().cannotSetColor(),
|
||||
"br", "\n", "input", color.asHexString(),
|
||||
"channel", channel.name()));
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
final UserChannelSettings settings = user.channelSettings(channel);
|
||||
|
||||
settings.color(color);
|
||||
|
||||
user.sendMessage(carbonChat.messageProcessor().processMessage(
|
||||
this.carbonChat.translations().channelColorSet(),
|
||||
"br", "\n", "color", "<color:" + color.asHexString() + ">", "channel",
|
||||
channel.name(), "hex", color.asHexString()));
|
||||
})
|
||||
.register();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
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.settings.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.kyori.adventure.audience.Audience;
|
||||
import net.kyori.adventure.text.Component;
|
||||
import net.milkbowl.vault.permission.Permission;
|
||||
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.LinkedHashMap;
|
||||
|
||||
public class ShadowMuteCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ShadowMuteCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final LinkedHashMap<String, Argument> arguments = new LinkedHashMap<>();
|
||||
arguments.put("player", CarbonUtils.chatUserArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(arguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.shadowmute"))
|
||||
.executes(this::execute)
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@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 (user.shadowMuted()) {
|
||||
user.shadowMuted(false);
|
||||
final String format = this.carbonChat.translations().noLongerShadowMuted();
|
||||
|
||||
final Component message = this.carbonChat.messageProcessor().processMessage(format, "br", "\n",
|
||||
"player", player.getName());
|
||||
|
||||
cmdSender.sendMessage(message);
|
||||
} else {
|
||||
Bukkit.getScheduler().runTaskAsynchronously(this.carbonChat, () -> {
|
||||
final Permission permission = this.carbonChat.permission();
|
||||
final String format;
|
||||
|
||||
if (permission.playerHas(null, player, "carbonchat.shadowmute.exempt")) {
|
||||
format = this.carbonChat.translations().shadowMuteExempt();
|
||||
} else {
|
||||
user.shadowMuted(true);
|
||||
format = this.carbonChat.translations().nowShadowMuted();
|
||||
}
|
||||
|
||||
final Component message = this.carbonChat.messageProcessor().processMessage(format, "br", "\n",
|
||||
"player", player.getName());
|
||||
|
||||
cmdSender.sendMessage(message);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
+133
@@ -0,0 +1,133 @@
|
||||
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.settings.CommandSettings;
|
||||
import net.draycia.carbon.api.users.UserChannelSettings;
|
||||
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.BooleanArgument;
|
||||
import dev.jorel.commandapi.arguments.LiteralArgument;
|
||||
import net.draycia.carbon.CarbonChatBukkit;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.checkerframework.checker.nullness.qual.NonNull;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class SpyChannelCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SpyChannelCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
channelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(channelArguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.spy"))
|
||||
.executesPlayer(this::execute)
|
||||
.register();
|
||||
|
||||
final LinkedHashMap<String, Argument> whisperArguments = new LinkedHashMap<>();
|
||||
whisperArguments.put("channel", new LiteralArgument("whispers"));
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(whisperArguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.spy"))
|
||||
.executesPlayer(this::executeWhispers)
|
||||
.register();
|
||||
|
||||
final LinkedHashMap<String, Argument> everythingArguments = new LinkedHashMap<>();
|
||||
everythingArguments.put("channel", new LiteralArgument("*"));
|
||||
everythingArguments.put("should-spy", new BooleanArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(everythingArguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.spy"))
|
||||
.executesPlayer(this::executeEverything) // lul
|
||||
.register();
|
||||
}
|
||||
|
||||
private void execute(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatChannel chatChannel = (ChatChannel) args[0];
|
||||
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
|
||||
final String message;
|
||||
|
||||
final UserChannelSettings settings = user.channelSettings(chatChannel);
|
||||
|
||||
if (settings.spying()) {
|
||||
settings.spying(false);
|
||||
message = this.carbonChat.translations().spyToggledOff();
|
||||
} else {
|
||||
settings.spying(true);
|
||||
message = this.carbonChat.translations().spyToggledOn();
|
||||
}
|
||||
|
||||
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "br", "\n",
|
||||
"color", "<color:" + chatChannel.channelColor(user).toString() + ">", "channel", chatChannel.name()));
|
||||
}
|
||||
|
||||
private void executeWhispers(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
|
||||
final String message;
|
||||
|
||||
if (user.spyingwhispers()) {
|
||||
user.spyingWhispers(false);
|
||||
message = this.carbonChat.translations().spyWhispersOff();
|
||||
} else {
|
||||
user.spyingWhispers(true);
|
||||
message = this.carbonChat.translations().spyWhispersOn();
|
||||
}
|
||||
|
||||
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "br", "\n"));
|
||||
}
|
||||
|
||||
private void executeEverything(@NonNull final Player player, @NonNull final Object @NonNull [] args) {
|
||||
final Boolean shouldSpy = (Boolean) args[0];
|
||||
|
||||
final ChatUser user = this.carbonChat.userService().wrap(player.getUniqueId());
|
||||
|
||||
final String message;
|
||||
|
||||
if (shouldSpy) {
|
||||
user.spyingWhispers(true);
|
||||
|
||||
for (final ChatChannel channel : this.carbonChat.channelRegistry()) {
|
||||
user.channelSettings(channel).spying(true);
|
||||
}
|
||||
|
||||
message = this.carbonChat.translations().spyEverythingOff();
|
||||
} else {
|
||||
user.spyingWhispers(false);
|
||||
|
||||
for (final ChatChannel channel : this.carbonChat.channelRegistry()) {
|
||||
user.channelSettings(channel).spying(false);
|
||||
}
|
||||
|
||||
message = this.carbonChat.translations().spyEverythingOn();
|
||||
}
|
||||
|
||||
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "br", "\n"));
|
||||
}
|
||||
|
||||
}
|
||||
+97
@@ -0,0 +1,97 @@
|
||||
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;
|
||||
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.draycia.carbon.api.commands.settings.CommandSettings;
|
||||
import net.kyori.adventure.audience.Audience;
|
||||
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;
|
||||
|
||||
import java.util.LinkedHashMap;
|
||||
|
||||
public class SudoChannelCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public SudoChannelCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final LinkedHashMap<String, Argument> setOtherChannelArguments = new LinkedHashMap<>();
|
||||
setOtherChannelArguments.put("player", CarbonUtils.onlineChatUserArgument());
|
||||
setOtherChannelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(setOtherChannelArguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channel.others"))
|
||||
.executes((sender, args) -> {
|
||||
this.otherChannel(sender, (ChatUser) args[0], (ChatChannel) args[1]);
|
||||
})
|
||||
.register();
|
||||
|
||||
final LinkedHashMap<String, Argument> sendMessageOtherArguments = new LinkedHashMap<>();
|
||||
sendMessageOtherArguments.put("player", CarbonUtils.onlineChatUserArgument());
|
||||
sendMessageOtherArguments.put("channel", CarbonUtils.channelArgument());
|
||||
sendMessageOtherArguments.put("message", new GreedyStringArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(sendMessageOtherArguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.channel.others.message"))
|
||||
.executes((sender, args) -> {
|
||||
this.sendMessageOther(sender, (ChatUser) args[0], (ChatChannel) args[1], (String) args[2]);
|
||||
})
|
||||
.register();
|
||||
}
|
||||
|
||||
private void otherChannel(@NonNull final CommandSender sender, @NonNull final ChatUser user, @NonNull final ChatChannel channel) {
|
||||
user.selectedChannel(channel);
|
||||
|
||||
final String message = channel.switchMessage();
|
||||
final String otherMessage = channel.switchOtherMessage();
|
||||
|
||||
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(
|
||||
this.carbonChat.messageProcessor().processMessage(otherMessage, "br", "\n",
|
||||
"color", "<color:" + channel.channelColor(user).toString() + ">", "channel", channel.name(),
|
||||
"player", Bukkit.getOfflinePlayer(user.uuid()).getName()));
|
||||
}
|
||||
|
||||
private void sendMessageOther(@NonNull final CommandSender sender, @NonNull final ChatUser user,
|
||||
@NonNull final ChatChannel channel, @NonNull final String message) {
|
||||
final Component component = channel.sendMessage(user, message, false);
|
||||
|
||||
this.carbonChat.messageProcessor().audiences().console().sendMessage(component);
|
||||
}
|
||||
|
||||
}
|
||||
+111
@@ -0,0 +1,111 @@
|
||||
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.settings.CommandSettings;
|
||||
import net.draycia.carbon.api.users.UserChannelSettings;
|
||||
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.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 ToggleCommand {
|
||||
|
||||
@NonNull
|
||||
private final CarbonChat carbonChat;
|
||||
|
||||
public ToggleCommand(@NonNull final CommandManager<ChatUser, SimpleCommandMeta> commandManager, @NonNull final CommandSettings commandSettings) {
|
||||
this.carbonChat = CarbonChatProvider.carbonChat();
|
||||
|
||||
if (!commandSettings.enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final LinkedHashMap<String, Argument> channelArguments = new LinkedHashMap<>();
|
||||
channelArguments.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(channelArguments)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.toggle"))
|
||||
.executesPlayer(this::executeSelf)
|
||||
.register();
|
||||
|
||||
final LinkedHashMap<String, Argument> argumentsOther = new LinkedHashMap<>();
|
||||
argumentsOther.put("players", CarbonUtils.chatUserArgument());
|
||||
argumentsOther.put("channel", CarbonUtils.channelArgument());
|
||||
|
||||
new CommandAPICommand(commandSettings.name())
|
||||
.withArguments(argumentsOther)
|
||||
.withAliases(commandSettings.aliases())
|
||||
.withPermission(CommandPermission.fromString("carbonchat.toggle"))
|
||||
.executes(this::executeOther)
|
||||
.register();
|
||||
}
|
||||
|
||||
private void executeSelf(@NonNull final CommandContext<ChatUser> context) {
|
||||
final ChatUser user = context.getSender();
|
||||
final ChatChannel channel = (ChatChannel) args[0];
|
||||
|
||||
final String message;
|
||||
|
||||
final UserChannelSettings settings = user.channelSettings(channel);
|
||||
|
||||
if (!channel.ignorable()) {
|
||||
message = channel.cannotIgnoreMessage();
|
||||
} else if (settings.ignored()) {
|
||||
settings.ignoring(false);
|
||||
message = channel.toggleOffMessage();
|
||||
} else {
|
||||
settings.ignoring(true);
|
||||
message = channel.toggleOnMessage();
|
||||
}
|
||||
|
||||
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "br", "\n",
|
||||
"color", "<color:" + channel.channelColor(user).toString() + ">", "channel", channel.name()));
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
final UserChannelSettings settings = user.channelSettings(channel);
|
||||
|
||||
if (settings.ignored()) {
|
||||
settings.ignoring(false);
|
||||
message = channel.toggleOffMessage();
|
||||
otherMessage = channel.toggleOtherOffMessage();
|
||||
} else {
|
||||
settings.ignoring(true);
|
||||
message = channel.toggleOnMessage();
|
||||
otherMessage = channel.toggleOtherOnMessage();
|
||||
}
|
||||
|
||||
user.sendMessage(this.carbonChat.messageProcessor().processMessage(message, "br", "\n",
|
||||
"color", "<color:" + channel.channelColor(user).toString() + ">", "channel", channel.name()));
|
||||
|
||||
sender.sendMessage(
|
||||
this.carbonChat.messageProcessor().processMessage(otherMessage,
|
||||
"br", "\n", "color", "<color:" + channel.channelColor(user).toString() + ">",
|
||||
"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