Hello, i am trying to update a block type inside on the ChangeBlockEvent.Place, the block place correctly but it throw some errors in the console
My code:
@Listener
public void onBlockPlace(ChangeBlockEvent.Place e){
Optional<Player> player = Helper.playerCause(e.getCause());
if(player.isPresent()){
BlockSnapshot block = e.getTransactions().get(0).getFinal();
block.getLocation().get().copy().sub(5, 5, 5).setBlockType(BlockTypes.BEDROCK, Cause.source(SpongyPS.getInstance().getPluginContainer()).build());
}
}
The error:
Version:
Thanks ;)
you should modify the transactions or add it to a task
~@Liach is correct, the whole point of the transaction is to be able to get the original, and swap out the result. setting the blocktype using the API will just throw another event.~
~Adding it as a task should really only be used as a last resort, as it will still set the original final from the place event, and then fire an event again that you will be listening to.~
~I'm leaving this open for input on whether this should be closed, or moved to SpongeCommon as a bug that it allowed the block to be set, whilst throwing an error.~
*correction
I should have been paying more attention, this is definitely a bug in my eyes.
I didn't notice that you were adjusting a different block then what was being set in the event.
I'm not sure it's possible to add additional blocks to the transaction, so we definitely should at least be doing something about this.
I'm not sure it's possible to add additional blocks to the transaction, so we definitely should at least be doing something about this.
I thought we could add more transaction in this case. Using Sponge.getScheduler().createTaskBuiler() and make a task for the next tick may be a temporary workaround.
This should be in implementation to be honest, as it's a SpongeCommon bug, not an API bug. Re-open there please.
Most helpful comment
*correction
I should have been paying more attention, this is definitely a bug in my eyes.
I didn't notice that you were adjusting a different block then what was being set in the event.
I'm not sure it's possible to add additional blocks to the transaction, so we definitely should at least be doing something about this.