Minecraft programming: what is the best way to do a spawn protection?

Ke
6

How do I best program them?

@EventHandler
public void onSPFail (BlockBreakEvent e) {
Location l = e.getPlayer (). GetLocation ();

if (l.getX () <50 && l.getX ()> -50
&& l.getZ () <50 && l.getZ ()> -50) {
e.setCancelled (true);
}
}

Is that so good? So said a 100x100 area around the spawn?

Or would you do it differently?

Ra

Can you do that already… I would just do it via worldguard… It's less work

Ke

My goal is to program a lot myself to leave out WorldGuard etc.

Ra

Well, you don't have to reinvent the wheel… But if you think so, you could do it… With your algorithm, the spawn has to be 0.0

Sk

You take the position of the player who breaks the block.

Better take the position of the block.

Ke

But you don't have to reinvent the wheel…

I don't want to either
just want to build a bike instead of getting it for free somewhere.

Da

You are already on the right path.

However, you should take the position of the block that is being dismantled. Otherwise people outside the spawn can mine blocks.

e.getBlock (). GetLocation ()

Then you have to think about what else can happen.

Place

BlockState (e.g. Opening doors)

Block updates

piston

TNT cannons

If you only do a lobby or something, you can do it well because the more complex options, if the players do not get such items, do not have to be considered.

If you want to do FreeBuild or something, use WorldGuard.