Search code examples
javaminecraftbukkit

Minecraft Bukkit coding Type mismatch: cannot convert from element type Object to String


Here is the full code for it:

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);
        }
    }
}

And I also have another issue "Type mismatch: cannot convert from element type Object to Block"

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;
   }

I currently don't have someone that can look over the code I personally do not see the issue but I've been working on it for hours so yeah ;/ Thanks. This code is to do with a Minecraft plugin it's tracking a players location and sending the information to the player that executed the command.


Solution

  • Use

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

    and

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