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

47 lines
1.5 KiB
Java
Raw Normal View History

2021-08-04 13:46:45 +00:00
package com.alttd.chat.commands;
import com.alttd.chat.ChatPlugin;
import com.alttd.chat.objects.channels.CustomChannel;
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;
import org.bukkit.scheduler.BukkitRunnable;
2021-08-05 09:40:42 +00:00
import org.jetbrains.annotations.NotNull;
import java.util.Collections;
public class ChatChannel extends BukkitCommand {
CustomChannel channel;
2021-08-05 09:40:42 +00:00
String command;
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());
}
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;
}
if(args.length == 0) return false;
String message = StringUtils.join(args, " ", 0, args.length);
new BukkitRunnable() {
@Override
public void run() {
2021-08-05 09:40:42 +00:00
ChatPlugin.getInstance().getChatHandler().chatChannel(player, channel, message);
2021-08-04 13:46:45 +00:00
}
}.runTaskAsynchronously(ChatPlugin.getInstance());
return false;
}
}