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

54 lines
2.0 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;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import net.kyori.adventure.text.minimessage.tag.resolver.TagResolver;
2021-08-04 13:46:45 +00:00
import org.apache.commons.lang.StringUtils;
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;
2022-05-24 01:06:34 +00:00
import java.util.*;
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;
2022-05-24 01:06:34 +00:00
private static 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(Collections.emptyList());
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) {
2021-08-04 13:46:45 +00:00
if(!(sender instanceof Player player)) { // must be a player
return true;
}
2022-05-24 01:06:34 +00:00
if(args.length == 0) {
player.sendMiniMessage(Config.PARTY_TOGGLED, TagResolver.resolver(
Placeholder.unparsed("channel", channel.getChannelName()),
Placeholder.unparsed("status", toggleableForCustomChannel.toggle(player.getUniqueId())
? "<green>on</green>" : "<red>off</red>")));
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
}