What is wrong with the setBlock method?

I have some questions about the setBlock method. The default parameters for this method is

boolean setBlock(Block block);

Well the first thing is the return value. It returns a boolean. But how can that method know when it is allowed to set the block? Shouldn’t the method(s) be this

boolean setBlock(Block block, Player player);

boolean setBlock(Block block, String fakeplayer);

As it is obvious, that something has demanded the block to be changed (possible a player).

  • Worldedit - Doesn’t give a blockbreak/change event for other plugins.
  • A magical plugin that allows to manipulate the world

Off course I wouldn’t remove the old method as it could be helpfully for administration plugins that don’t want that other plugins log/cancel their changes.


I’m pretty sure when you place a block, there is going to be a blockPlaceEvent which includes the block and player.
Plugins would use that event to determine if the player may place the block or not, and then the setBlock method is called.

So your saying that plugins need to fire of the event before they set the block? Well we have seen that enough in bukkit and forge. And it always ended up that devs where to lazy to fire off the event what resulted in massive griefing (especially in with forge mods). What I am saying is that that method has to fire the event and returns it value.

1 Like

I feel like that this thread didn’t had much attention so … .

You are right there, but what about plugins like WE? Mass block manipulations like that shouldn’t trigger an event for every single block, it would flood the eventbus and possibly stall the server.

That all depends of the implementation of the setblock method :smile:.
Sponge even has an Event for it, https://github.com/SpongePowered/SpongeAPI/blob/master/src/main/java/org/spongepowered/api/event/block/BulkBlockEvent.java.
So worldedit just has to use an Array version of that method. Like this:

block[] blocks = selection.getBlocks();
world.setBlock(blocks, selection.getPlayer());