Chat/galaxy/src/main/java/com/alttd/chat/commands/ChatChannel.java

56 lines
2.1 KiB
Java
Raw Normal View History

2021-08-04 13:46:45 +00:00
package com.alttd.chat.commands;
import com.alttd.chat.config.Config;
import com.alttd.chat.objects.channels.CustomChannel;
2022-05-24 02:18:34 +00:00
import com.alttd.chat.util.ToggleableForCustomChannel;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
2022-09-03 10:46:04 +00:00
import org.apache.commons.lang3.StringUtils;
2021-08-04 13:46:45 +00:00
import org.bukkit.command.CommandSender;
2021-08-05 09:40:42 +00:00
import org.bukkit.command.defaults.BukkitCommand;
2021-08-04 13:46:45 +00:00
import org.bukkit.entity.Player;
2021-08-05 09:40:42 +00:00
import org.jetbrains.annotations.NotNull;
2025-06-20 22:53:55 +00:00
import java.util.ArrayList;
import java.util.List;
2021-08-05 09:40:42 +00:00
public class ChatChannel extends BukkitCommand {
CustomChannel channel;
2021-08-05 09:40:42 +00:00
String command;
ToggleableForCustomChannel toggleableForCustomChannel;
2025-06-20 22:53:55 +00:00
private static final List<ChatChannel> activeCommands = new ArrayList<>();
2021-08-05 09:40:42 +00:00
public ChatChannel(CustomChannel channel) {
2021-08-05 09:40:42 +00:00
super(channel.getChannelName().toLowerCase());
this.channel = channel;
this.command = channel.getChannelName().toLowerCase();
this.description = "Chat channel named " + channel.getChannelName() + ".";
this.usageMessage = "/" + command + " <message>";
this.setAliases(channel.getAliases());
2022-05-24 01:06:34 +00:00
activeCommands.add(this);
this.toggleableForCustomChannel = new ToggleableForCustomChannel(channel);
2021-08-05 09:40:42 +00:00
}
2021-08-04 13:46:45 +00:00
@Override
2021-08-05 09:40:42 +00:00
public boolean execute(@NotNull CommandSender sender, @NotNull String command, @NotNull String[] args) {
2025-06-20 22:53:55 +00:00
if (!(sender instanceof Player player)) { // must be a player
2021-08-04 13:46:45 +00:00
return true;
}
2025-06-20 22:53:55 +00:00
if (args.length == 0 && player.hasPermission(channel.getPermission())) {
player.sendRichMessage(Config.CUSTOM_CHANNEL_TOGGLED, TagResolver.resolver(
Placeholder.unparsed("channel", channel.getChannelName()),
Placeholder.component("status", toggleableForCustomChannel.toggle(player.getUniqueId())
? Config.TOGGLED_ON : Config.TOGGLED_OFF)));
2022-05-24 01:06:34 +00:00
return false;
}
2021-08-04 13:46:45 +00:00
String message = StringUtils.join(args, " ", 0, args.length);
toggleableForCustomChannel.sendMessage(player, message);
2022-05-24 01:06:34 +00:00
return false;
}
2021-08-04 13:46:45 +00:00
}