Home > Enterprise >  Replacing every block in a chunk crashes server
Replacing every block in a chunk crashes server

Time:02-26

I am replacing blocks in chunks. Every time a chunk is loaded, I replace generating blocks with a random other one. So here is my code

package de.belinked.chunkrandomizer;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;

import org.bukkit.Bukkit;
import org.bukkit.Chunk;
import org.bukkit.Material;
import org.bukkit.block.Block;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.ChunkLoadEvent;
import org.bukkit.plugin.java.JavaPlugin;

public class ChunkRandomizer extends JavaPlugin implements Listener {
    
    public List<Material> blocks = Arrays.asList(
            Material.ACACIA_LEAVES,
            Material.ACACIA_LOG,

            // I'll leave this out, just every full, solid block

            Material.YELLOW_STAINED_GLASS,
            Material.YELLOW_TERRACOTTA,
            Material.YELLOW_WOOL
    );
    
    @Override
    public void onEnable() {
        getServer().getPluginManager().registerEvents(this, this);
        Bukkit.broadcastMessage(this.prefix   "Der Chunk-Randomizer wurde erfolgreich geladen");
    }
    
    @Override
    public void onDisable() {
        
    }
    
    public Material getRandomMaterial(List l) {
        int rnd = ThreadLocalRandom.current().nextInt(l.size());
        Material m = (Material) l.get(rnd);
        return m;
    }
    
    @EventHandler
    public void onChunkLoad(ChunkLoadEvent e) {
        if(e.isNewChunk()) {
            Chunk chunk = e.getChunk();
            Block b;
            Material m = getRandomMaterial(this.blocks);
            for(int y = -64; y <= 320; y  ) {
                for(int x = 0; x < 16; x  ) {
                    for(int z = 0; z < 16; z  ) {
                        b = chunk.getBlock(x, y, z);
                        if(!b.getType().isAir() 
                                && b.getType() != Material.BEDROCK 
                                && b.getType() != Material.WATER 
                                && b.getType() != Material.LAVA
                                && b.getType() != Material.END_PORTAL_FRAME
                                && b.getType() != Material.END_PORTAL) {
                            b.setType(m);
                        }
                    }
                }
            }
        }
    }
}

but when I join the server and load a few chunks then I get this log:

https://pastebin.com/vA8qHSUr

Can anyone help me fix this?

Edit: now I get kicked and for a while nothing happens, then I get this log which is even to long for the console: https://pastebin.com/8eZ4Ja4m

CodePudding user response:

In the error, line 77, it says :

Cannot get data for not block BRICK

I think the problem comes from your list blocks. Somewhere in it, there must be a Material.BRICK, but in fact, I think the material should be Material.BRICKS, Bricks being the whole block, and Brick being the cooked clay item to make the Bricks block.

CodePudding user response:

You should check that you well have api-version: 1.13 in your plugin.yml.

It's because some mapping names changes, and they are not well detected by spigot without this option.

  • Related