Wie mache ich ein Random Spawn (und 2 blöcke in der erde) Plugin?

Ich mache gerade ein Plugin wobei der Spawn random in der erde ist (Oberflächen Y -2) aber es funktioniert nicht, hier der Code:

   
    Location locationRaw;
    Location locationRaw2;
    Location location;
    Location location2;
    
    @EventHandler
    private void onPlayerJoin(PlayerJoinEvent e, PlayerSpawnLocationEvent e1) {
        
        for(Player p : Bukkit.getOnlinePlayers()) {
            
            World world = Bukkit.getWorlds().get(0);
            int X = getRandom(1500, -1500);
            int Y = getRandom(250, 1);
            Block blockY = world.getBlockAt(location2);
            if(blockY.getType() == Material.GRASS_BLOCK) {
                int rawY = world.getHighestBlockYAt(locationRaw2);
                int Z = getRandom(1500, -1500);
    
                locationRaw2 = new Location(world, X, Y, Z);
                locationRaw = new Location(world, X, rawY, Z);
                location = new Location(world, X, rawY -2, Z);
                location2 = new Location(world, X, rawY -1, Z);
                
                Block block1 = world.getBlockAt(locationRaw);
                block1.setType(Material.AIR);
                Block block2 = world.getBlockAt(locationRaw);
                block2.setType(Material.AIR);
                Block block3 = world.getBlockAt(location2);
                block3.setType(Material.AIR);
                
                e1.setSpawnLocation(location);
                p.teleport(location);
            }
        }
    }
    
    public int getRandom(int lower, int upper) {
        Random random = new Random();
        return random.nextInt((upper - lower) + 1) + lower;
    }

}

...zum Beitrag

Schau dich am besten mal in Foren um, in denen dieses Thema speziell behandelt wird.

...zur Antwort