If you're going to use java why not something like this
Code:
DialogueBuilder dialogue = new DialogueBuilder();
dialogue.option(
new DialogueOption("Change magic book", () -> StaticCall::changeMagicBook),
new DialogueOption("Change spell book", () -> StaticCall::changeSpellBook)
);
player.start(dialogue);
here you wouldn't have to create a new class implementation for every dialogue tree you build, plus it's more readable.
here's another example from some stuff I wrote a couple of years ago
Code:
public class SelectGameModeDialogue extends DialogueBuilder {
private static final int TUTORIAL_NPC = 30_306;
private final Consumer<Player> selectionConsumer;
/**
* Create a new SelectGameModeDialogue.
* @Param player
* the player
* @Param selectionConsumer
* a consumer to be called when a game mode is selected.
*/
public SelectGameModeDialogue(Player player, Consumer<Player> selectionConsumer) {
super(player);
this.selectionConsumer = selectionConsumer;
option("Select Game Mode",
new DialogueOption("Standard", player1 -> select(player1, GameMode.NORMAL)),
new DialogueOption("Ironman", player1 -> select(player1, GameMode.IRONMAN)),
new DialogueOption("Hardcore Ironman", player1 -> select(player1, GameMode.HARDCORE_IRONMAN)),
new DialogueOption("Explain modes", player1 -> explain(player1)));
}
private void select(Player player, GameMode mode) {
player.start(new DialogueBuilder(player).setNpcId(TUTORIAL_NPC)
.npc("You have selected to play the " + mode.toString() + " mode.", "Would you like to continue with this selection?")
.option(mode.toString() + "?",
new DialogueOption("Yes", player1 -> confirm(player, mode)),
new DialogueOption("No", player1 -> player1.start(new SelectGameModeDialogue(player1, selectionConsumer)))
)
);
}
private void confirm(Player player, GameMode mode) {
player.closeDialogue();
player.setGameMode(mode);
InformationTab.updateGameMode(player);
player.flag(UpdateFlags.UpdateFlag.APPEARANCE);
if (selectionConsumer != null) {
selectionConsumer.accept(player);
}
}
private void explain(Player player) {
player.start(new DialogueBuilder(player).setNpcId(TUTORIAL_NPC)
.npc("Standard mode is the default mode.", "In standard mode all content is available to play freely.")
.npc("Ironman mode is a restriction where you cannot", "receive items from other players and", "must be self sufficient.")
.npc("Hardcore Ironman mode is the same as regular", "Ironman mode except when you die you will", "become a regular Ironman.")
.continueAction(player1 -> player1.start(new SelectGameModeDialogue(player1, selectionConsumer)))
);
}
}