Untitled

mail@pastecode.io avatar
unknown
java
a year ago
1.7 kB
3
Indexable
Never
package net.hollowrealms.commands.Testing.subcommands;


import net.hollowrealms.commands.SubCommand;
import org.bukkit.Bukkit;
import org.bukkit.entity.Player;

import java.util.ArrayList;
import java.util.List;

import static net.hollowrealms.util.ColorTranslator.translateColorCodes;

public class TestSubCommand extends SubCommand {
    @Override
    public String getName() {
        return "msg";
    }

    @Override
    public String getDescription() {
        return "Sends a msg";
    }

    @Override
    public String getSyntax() {
        return "/test msg <playerName>";
    }

    @Override
    public void execute(Player sender, String[] args) {
        if (args.length > 1) {
            Player target = Bukkit.getPlayer(args[1]);


            target.sendMessage(translateColorCodes("&a" + sender.getName() + " sent you a msg"));

            sender.sendMessage(translateColorCodes("&a You sent a msg to " + target.getName()));
        } else if (args.length == 1) {
            sender.sendMessage(translateColorCodes("&cPlease provide a player to send a msg to."));
            sender.sendMessage(translateColorCodes("&c/test msg <playerName>"));
        }
    }

    @Override
    public List<String> getSubCommandArgs(Player player, String[] args) {
        if (args.length == 2) {
            List<String> playerNames = new ArrayList<>();
            Player[] players = new Player[Bukkit.getServer().getOnlinePlayers().size()];
            Bukkit.getServer().getOnlinePlayers().toArray(players);
            for (int i = 0; i < players.length; i++) {
                playerNames.add(players[i].getName());
            }
            return playerNames;

        }
        return null;
    }
}