Thanks the help!
Here's the code
@Override
public void onBlockPlacedBy(World world, BlockPos pos1, BlockState state, LivingEntity placer,
ItemStack stack) {
if (!world.isRemote()) {
ServerWorld w = world.getServer().getWorld(placer.dimension);
BlockPos pos2 = w.findNearestStructure("Village", pos1, 100, false);
if (pos2 == null) {
destroyIt(world, pos1, state, placer, stack);
return;
}
double i = pos1.getX() - pos2.getX();
double j = pos1.getZ() - pos2.getZ();
double d = MathHelper.sqrt((float) (i * i + j * j));
if (d > 100) {
destroyIt(world, pos1, state, placer, stack);
return;
}
}
}
private void destroyIt(World world, BlockPos pos1, BlockState state, LivingEntity placer, ItemStack stack) {
if(placer instanceof PlayerEntity) {
world.destroyBlock(pos1, !((PlayerEntity) placer).isCreative());
((PlayerEntity) placer)
.sendMessage(new TranslationTextComponent("block.cae.colony_table.placedInWrongPlace"));
}
}