How to fix this error?
Type mismatch: cannot convert from element type Object to Block
I see it at this line:
for (Block b : blocksToSkip){
Here is the full code.
@EventHandler(priority=EventPriority.NORMAL, ignoreCancelled=true)
public void onEntityExplode(EntityExplodeEvent ev){
ArrayList blocksToSkip = new ArrayList();
Location rootLoc = ev.getLocation();
if (!SkyMagic.IsInIslandWorld(rootLoc)) return;
for (Block b : ev.blockList()){
Location loc = b.getLocation();
IslandData data = SkyMagic.GetIslandAt(loc);
if ((data != null) && (data.owner != null)){
blocksToSkip.add(b);
}
}
for (Block b : blocksToSkip){
ev.blockList().remove(b);
}
}
This is a raw type :
ArrayList blocksToSkip
Java expects everything, not only the Block
type. Therefore, you need a type cast .
ArrayList blocksToSkip = new ArrayList();
// Rest of your code
for (Object b : blocksToSkip){
ev.blockList().remove( (Block)b );
}
Note it is discouraged to use raw types. You should parameterize instead.
ArrayList<Block> blocksToSkip = new ArrayList<Block>();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.