Sparky983 / vision-gui

A minimal GUI API for Paper
http://vision.sparky983.me
MIT License
15 stars 0 forks source link

`Gui.onClick` #204

Open Sparky983 opened 5 months ago

Sparky983 commented 4 months ago

The current Click API returns a non-null Button which would not work if we were to publish clicks of empty slots to a Gui. I'm hesitant to change it to @Nullable since existing usages such as even in our examples:

final Button counter = Button.of(ItemType.DIAMOND)
    .onClick((click) -> sender.sendMessage(click.button().name()));

would start to produce nullable dereference warnings without a nice way to suppress it.

Sparky983 commented 3 months ago

Idea: Sealed Interface Hierachy

Option 1

sealed interface Click {
  me.sparky983.vision.@Nullable Button button();

  non-sealed interface Button extends Click {
    me.sparky983.vision.Button button();
  }

  non-sealed interface Gui extends Click {}
}

Option 2

I think this option makes more sense with type usages being Button.Click and Gui.Click

sealed interface Click permits Button.Click, Gui.Click {
  Button button();
}

non-sealed interface Button.Click extends me.sparky983.vision.Click {
  @Nullable Button button();
}

non-sealed interface Gui.Click extends me.sparky983.vision.Click {}