MinecraftDev icon indicating copy to clipboard operation
MinecraftDev copied to clipboard

useless isCancelled Check is not useless

Open Faithcaio opened this issue 8 years ago • 4 comments

Basicly if setCancelled is called checking if the event is cancelled is a valid thing to do.

Example:

@Listener
public void onChangeBlock(ChangeBlockEvent event)
{
    if (something)
    {
        event.setCancelled(true);
    }
    // Now event.isCancelled() is no longer useless
}

Faithcaio avatar Mar 11 '17 12:03 Faithcaio

I mean, you could store it in a variable, but your point stands.

ryantheleach avatar Mar 11 '17 17:03 ryantheleach

@ryantheleach while yes you could store the cancelled value in a variable, that would result in the code having higher coupling, since any code block using the variable would be dependent on that variable being both declared and assigned.

That's the exact use case of this method; it lets you check if an event is cancelled without any care over if you're the one that cancelled it or not.

G-Rath avatar Sep 11 '17 20:09 G-Rath

@G-Rath I was agreeing with faith.

ryantheleach avatar Sep 12 '17 02:09 ryantheleach

image I use MinecraftDev plugin for Spigot development but there's the same issue. Even if ignoreCancelled = true, checking isCancelled is not useless after calling a method that potentially calls e.setCancelled(false)

Toshimichi0915 avatar Jul 09 '22 09:07 Toshimichi0915