package cat.freya.khs.command.map.blockhunt.blocks; import cat.freya.khs.Main; import cat.freya.khs.command.util.ICommand; import cat.freya.khs.configuration.Config; import cat.freya.khs.configuration.Localization; import cat.freya.khs.configuration.Map; import cat.freya.khs.configuration.Maps; import cat.freya.khs.game.util.Status; import org.bukkit.Material; import org.bukkit.entity.Player; import org.jetbrains.annotations.NotNull; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class Add implements ICommand { public void execute(Player sender, String[] args) { if (!Main.getInstance().supports(9)) { sender.sendMessage(Config.errorPrefix + Localization.message("BLOCKHUNT_UNSUPPORTED")); return; } if (Main.getInstance().getGame().getStatus() != Status.STANDBY) { sender.sendMessage(Config.errorPrefix + Localization.message("GAME_INPROGRESS")); return; } Map map = Maps.getMap(args[0]); if(map == null) { sender.sendMessage(Config.errorPrefix + Localization.message("INVALID_MAP")); return; } Material block; try { block = Material.valueOf(args[1]); } catch (IllegalArgumentException e) { sender.sendMessage(Config.errorPrefix + Localization.message("COMMAND_INVALID_ARG").addAmount(args[1])); return; } List blocks = map.getBlockHunt(); if(blocks.contains(block)) { sender.sendMessage(Config.errorPrefix + Localization.message("BLOCKHUNT_BLOCK_EXISTS").addAmount(args[1])); } blocks.add(block); map.setBlockhunt(map.isBlockHuntEnabled(), blocks); Maps.setMap(map.getName(), map); sender.sendMessage(Config.messagePrefix + Localization.message("BLOCKHUNT_BLOCK_ADDED").addAmount(args[1])); } public String getLabel() { return "add"; } public String getUsage() { return " "; } public String getDescription() { return "Add a blockhunt block to a map!"; } public List autoComplete(@NotNull String parameter, @NotNull String typed) { if(parameter.equals("map")) { return Maps.getAllMaps().stream().map(Map::getName).collect(Collectors.toList()); } else if(parameter.equals("block")) { return Arrays.stream(Material.values()) .filter(Material::isBlock) .map(Material::toString) .filter(s -> s.toUpperCase().startsWith(typed.toUpperCase())) .collect(Collectors.toList()); } return null; } }