Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
6.6 kB
2
Indexable
Never
package me.lajzy.manhunt;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;

import java.util.stream.Collectors;

public class ManhuntCommand implements CommandExecutor {

    @Override
    public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
        Player player = (Player) sender;
        if (player.hasPermission("manhunt.manhunt")) {
            if (args.length == 0) {
                if (cmd.getName().equalsIgnoreCase("manhunt") || cmd.getName().equalsIgnoreCase("mh")) {
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&d&lManhunt by Lajzy"));
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7 - &bThis is a manhunt plugin made for easy manhunt setup."));
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7 - &bUse '/manhunt help' for instructions on commands."));
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7 - &bVersion: &7" + Main.Version));
                }
            } else if (args.length == 1) {
                if (args[0].equalsIgnoreCase("help")) {
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&d&lManhunt help page"));
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7 - &bUse &7'/manhunt' &bfor main command."));
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7 - &bUse &7'/manhunt help' &bfor instructions on commands."));
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7 - &bUse &7'/manhunt hunter <player>' &bto add a player to the hunters list."));
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7 - &bUse &7'/manhunt hunter remove <player>' &bto remove a player from the hunters list."));
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7 - &bUse &7'/manhunt runner <player>' &bto add a player to the runners list."));
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7 - &bUse &7'/manhunt runner remove <player>' &bto remove a player from the hunters list."));
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7 - &bUse &7'/manhunt  list' &bfor the list of runners and hunters."));
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7 - &bUse &7'/manhunt start' &bto give compasses to the hunters and start the game."));
                    player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&7 - &bUse &7'/manhunt end' &bto remove compasses from the hunters and end the game."));

                } else if (args[0].equalsIgnoreCase("list")) {
                    player.sendMessage(ChatColor.LIGHT_PURPLE + "Hunters:");
                    player.sendMessage(Main.hunterslist.stream().map(Player::getName).collect(Collectors.joining(", ")));
                    player.sendMessage(ChatColor.AQUA + "Runners:");
                    player.sendMessage(Main.runnerslist.stream().map(Player::getName).collect(Collectors.joining(", ")));

                } else if (args[0].equalsIgnoreCase("start")) {
                    Compass.onStart();

                } else if (args[0].equalsIgnoreCase("end")) {
                    Compass.onEnd();
                }

            } else if (args.length == 2) {
                if (args[0].equalsIgnoreCase("hunter")) {
                    if (player.hasPermission("manhunt.addhunter")) {
                        Player target = Bukkit.getPlayer(args[1]);
                        if (!Bukkit.getOnlinePlayers().contains(target)) {
                            player.sendMessage(ChatColor.RED + "There is no such player online.");
                        } else if (Bukkit.getOnlinePlayers().contains(target)) {
                            String p = target.getDisplayName();
                            if (!Main.hunterslist.contains(target) || !Main.runnerslist.contains(target)) {
                                Main.hunterslist.add(target);
                                player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&2Player: &7" + p + " &2is now a hunter."));
                            } else if (Main.runnerslist.contains(target)) {
                                Main.hunterslist.add(target);
                                player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&2Player: &7" + p + " have been moved from runner to hunter."));
                            } else if (Main.hunterslist.contains(target)) {
                                player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cPlayer: &7" + p + " is already a hunter."));
                            }
                        }
                    }

                } else if (args[0].equalsIgnoreCase("runner")) {
                    if (player.hasPermission("manhunt.addrunner")) {
                        Player target = Bukkit.getPlayer(args[1]);
                        String p = target.getDisplayName();
                        if (!Bukkit.getOnlinePlayers().contains(target)) {
                            player.sendMessage(ChatColor.RED + "There is no such player online.");
                        } else if (Bukkit.getOnlinePlayers().contains(target)) {
                            if (!Main.runnerslist.contains(target) || !Main.hunterslist.contains(target)) {
                                Main.runnerslist.add(target);
                                player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&2Player: &7" + p + " &2is now a runner."));
                            } else if (Main.hunterslist.contains(target)) {
                                Main.runnerslist.add(target);
                                player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&2Player: &7" + p + " have been moved from hunter to runner."));
                            } else if (Main.runnerslist.contains(target)) {
                                player.sendMessage(ChatColor.translateAlternateColorCodes('&', "&cPlayer: &7" + p + " is already a runner."));
                            }
                        }
                    }
                }
            }
        }
        return false;
    }
}