[ERROR] Maximum block processing depth exceeded!

Hello everyone,
I am developping a plugin who restrict construction in some areas and i get this error ([16:25:23 ERROR] [Sponge]: /**************************************************** - Pastebin.com) when cancel ChangeBlockEvent.Place event :

public void onBlockPlace(ChangeBlockEvent.Place event) {
    event.setCancelled(true);
}

The error appear only when placing a rail (any type)

Thank you for your help !

Just sanity check me. Are you using Sponge forge or vanilla?

And any other plugins/mods on the server?

spongevanilla-1.12.2-7.1.5.jar
with LuckPerms-Sponge-4.3.80.jar

Are you getting this error JUST like this: Just a simple event listener that you are cancelling right now,as part of a control test? Because it would make more sense if you were trying to check a location at some point, or looping through something, when deciding if/when to cancel and the error is caused by a tug-of-war battle between checking on things and causing a change that causes that to register as a change and falling into an infinity hole.

Its also much likely that it is very scenario-specific, such as for example, you placing a rail onto a block that triggers a block-place/change event by itself like placing onto flowers or grass, andthe system is trying to ‘place air’ first for the rail to go down into, but being blocked before it con do the rail, etc, etc…

Or you are trying to place in the op-protected spawn area on your server where the system is already trying to cancel things and causing a circle?

Is this error generated only with a raw, simple listener that you show, cancelling the event always? Or is your listener code morecomplex than the simple-case you show?

Firstly thank you for your answer

I created a test plugin with JUST this code and i get the same error when placing rails but no error with normal blocks:

@Plugin(
        id = "test",
        name = "Test"
)
public class Test {

	@Inject
	private Logger logger;

	@Listener
	public void onServerStart(GameStartedServerEvent event) {
	    logger.info("Running ...");
	}

	@Listener()
	public void onBlockPlace(ChangeBlockEvent.Place event) {
	    event.setCancelled(true);
	}

	@Listener()
	public void onBlockBreak(ChangeBlockEvent.Break event) {
	    event.setCancelled(true);
	}
}

i think not because i’m near x:2400 z:2500

Thanks

[EDIT]
I tried on a fresh server with just this test plugin and it works only in the protected OP zone but beyond it fails with the same error

Valuable information. The event might not be being thrown in the op-protected area, without knowing when it is triggered and being canceled vs just not being triggered requires some reporting, but its prob not triggering within op protected area.

Are you in creative mode or survival?
Are you op on the server - and yes, with luckperms, there “is no such thing”, but if you have been opped before adding luckperms, the op-protection still works differently.

Are you saying that you CAN place down rails but only within the op-protected area, or are you unable to place in op-protected, but don’t see the errors (because its not triggered, likely)?

Most importantly: What API version are you using, in order to try to replicate?

I m in creative mode , not op and without luckperms plugin
Im using the last stable version of sponge 1.12
And the rail is placed and trigger the error but i can t break it because of the event.setCancelled
I hope i ve understood all yours messages because im not english …

What sponge API version are you using to compile your plugin?

Sponge api 7.0.0

I’m not sure which APIs are recommended to use with 1.12.2-7.1.5 spongevanilla, but I have confirmed your bug on the 7.1.0 SpongeAPI as well. I made the listeners listen only for @Root Player activity to cut down on noise.

The ops protected area ‘is fine’ because the system cancels block change events and wont even generate the events.

If a reporter is included in the event listener, and the event is cancelled, then the log will spam the block place event 100 times, without cancelling it, and then spew out the phase-error message.
If the transaction is made invalid, instead of cancelling the event, the result is still the same - the event is reported 100 times, however the rail placement IS prevented, but it also spews out the phase-error message.

This is definitely a sponge bug to report in Github, for whatever it is worth for this version.

There isn’t much of a workaround for this problem - sure, you can setValid(false) the transaction for rail placement, instead of just cancelling the event, and that will work, but you will still have the log spammed with errors each time.

The alternative for you FOR NOW might be to check the player-interact-block event, for secondary-interaction, and if they have rails in their hand, prevent the interaction. That will prevent them from being able to place the rails on a block in the first place. The side effect is that they won’t be able to hold rails while opening a chest or dispenser, or maybe a crafting table.

Check in the interact-block event if they are secondary-interacting with any of the types of rails that cause this phase-error to appear. If they are, then apply whatever logic you have for checking their region, and cancel the event here if possible . It will stop rail placement from happening further upstream, and won’t generate a block-place event at all to worry about.
BUT, if they are okay for being able to place rails, then the interact isn’t cancelled, and the block-place will be generated. So make sure to test if they are placing rails in the block-place event first, and if they are, then just allow the event to occur (because you already determined they are in an okay area). For ALL OTHER block placements, do your region-check in the block-place event, and cancel those.

That way you won’t be cancelling or invalidating the block-place event with rails, and causing the server to get stuck in a loop.

Thank you very much !