Кодирование Minecraft Bukkit Несоответствие типов: невозможно преобразовать тип элемента Object в String - PullRequest
0 голосов
/ 28 ноября 2018

Вот полный код для этого:

public void trackAll() {
    int north = count(Direction.North) * 25;
    int east = count(Direction.East) * 25;
    int south = count(Direction.South) * 25;
    int west = count(Direction.West) * 25;

    if ((north == 0) && (east == 0) && (south == 0) && (west == 0)) {
        this.player.sendMessage(ChatColor.RED + "Not a valid tracking compass.");
        return;
    }

    for (Direction direction : Direction.values()) {
        int length = count(direction) * 25;
        if (length != 0) {
            @SuppressWarnings("rawtypes")
            Set players = new TreeSet();
            for (Player player : Bukkit.getOnlinePlayers()) {
                if (this.player.canSee(player)) if ((on(player, direction) & !player.equals(this.player))) {
                    players.add(player.getDisplayName());

                }
            }
            FancyMessage message = new FancyMessage(direction + " (" + length + "): ").color(ChatColor.DARK_AQUA);
            int i = 0;
            for (String str : players) {
                if (i == players.size() - 1)
                    message.then(str).color(ChatColor.GRAY).tooltip(ChatColor.GREEN + "Click here to track " + ChatColor.RESET + str + ChatColor.GREEN + ".").command("/track " + ChatColor.stripColor(str));
                else {
                    message.then(str).color(ChatColor.GRAY).tooltip(ChatColor.GREEN + "Click here to track " + ChatColor.RESET + str + ChatColor.GREEN + ".").command("/track " + ChatColor.stripColor(str)).then(", ");
                }
                i++;
            }

            message.send(this.player);
        }
    }
}

И у меня также есть еще одна проблема "Несоответствие типов: невозможно преобразовать из типа элемента Объект в блок"

public int count(Direction direction, boolean b) {
     int length = 0;

    @SuppressWarnings("rawtypes")
    Set toDelete = new HashSet();

     for (int i = 1; i < 10000; i++) {
       Block next = this.middle.getRelative(BlockFace.valueOf(direction.toString().toUpperCase()), i);

       if (next.getType() == Material.COBBLESTONE) {
         length++;
         toDelete.add(next); } else {
         if (next.getType() == Material.STONE) {
           length++;
           toDelete.add(next);
           toDelete.add(this.middle);
           break;
         }
         length = 0;
         toDelete.clear();
         break;
       }
     }

     if (b) {
       for (Block block : toDelete) {
         block.getWorld().playEffect(block.getLocation(), Effect.STEP_SOUND, block.getTypeId());
         block.setType(Material.AIR);
       }
     }

     return length;
   }

Я в настоящее времяУ меня нет человека, который может просмотреть код, я лично не вижу проблемы, но я работал над этим часами, так что да; / Спасибо.Этот код связан с плагином Minecraft, который отслеживает местоположение игроков и отправляет информацию игроку, выполнившему команду.

1 Ответ

0 голосов
/ 28 ноября 2018

Используйте

Set<String> players = new TreeSet<>();

и

Set<Block> toDelete = new HashSet<>();
...