Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ dependencyResolutionManagement {
version("luckperms-minestom-loader", "5.6-SNAPSHOT")
version("minestom-extensions", "2.1.1")
version("guava", "33.7.1-jre")
version("pica", "0.1.0")

library("aonyx.bom", "net.onelitefeather", "aonyx-bom").versionRef("aonyx")

Expand All @@ -64,6 +65,7 @@ dependencyResolutionManagement {
library("minestom-extensions-bom", "net.onelitefeather", "minestom-extensions-bom").versionRef("minestom-extensions")
library("minestom-extensions", "net.onelitefeather", "minestom-extensions").withoutVersion()
library("minestom-extensions-processor", "net.onelitefeather", "minestom-extensions-processor").withoutVersion()
library("pica", "net.onelitefeather", "pica").versionRef("pica")

library("cloudnet-bom", "eu.cloudnetservice.cloudnet", "bom").versionRef("cloudnet")
library("cloudnet-driver-api", "eu.cloudnetservice.cloudnet", "driver-api").withoutVersion()
Expand Down
1 change: 1 addition & 0 deletions setup/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ dependencies {
runtimeOnly(libs.slf4j.simple)
implementation(libs.xerus)
implementation(libs.guira)
implementation(libs.pica)

implementation(platform(libs.minestom.extensions.bom))
implementation(libs.minestom.extensions)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import net.theevilreaper.bounce.common.bootstrap.ServiceBootstrap;
import net.theevilreaper.bounce.setup.command.GameModeCommand;
import net.theevilreaper.bounce.setup.command.SetupCommand;
import net.theevilreaper.bounce.setup.dialog.DialogRegistry;
import net.theevilreaper.bounce.setup.dialog.SetupDialogRegistry;
import net.theevilreaper.bounce.setup.dialog.event.PlayerDialogRequestEvent;
import net.theevilreaper.bounce.setup.event.map.MapSetupSelectEvent;
import net.theevilreaper.bounce.setup.event.ground.PlayerGroundBlockSelectEvent;
Expand All @@ -30,7 +28,7 @@
import net.theevilreaper.bounce.setup.listener.PlayerDisconnectListener;
import net.theevilreaper.bounce.setup.listener.PlayerItemListener;
import net.theevilreaper.bounce.setup.listener.PlayerSpawnListener;
import net.theevilreaper.bounce.setup.listener.dialog.PlayerCustomClickEventListener;
import net.theevilreaper.bounce.setup.listener.dialog.DialogPayloadListener;
import net.theevilreaper.bounce.setup.listener.dialog.PlayerDeletePromptListener;
import net.theevilreaper.bounce.setup.listener.dialog.PlayerDialogRequestListener;
import net.theevilreaper.bounce.setup.listener.dialog.SaveValidationPromptListener;
Expand Down Expand Up @@ -58,14 +56,12 @@ public final class BounceSetup implements ListenerHandling {
private final SetupMapProvider mapProvider;
private final SetupDataService setupDataService;
private final InventoryService inventoryService;
private final DialogRegistry dialogRegistry;

public BounceSetup() {
Path path = ServiceBootstrap.resolveWorkingDirectory();
this.mapProvider = new SetupMapProvider(path);
this.setupDataService = SetupDataService.create();
this.inventoryService = new InventoryService(this.mapProvider::getEntries);
this.dialogRegistry = new SetupDialogRegistry();
MinecraftServer.getSchedulerManager().buildShutdownTask(this::onShutdown);
MinecraftServer.getConnectionManager().setPlayerProvider(SetupPlayer::new);
}
Expand Down Expand Up @@ -101,15 +97,15 @@ private void registerListener(@NotNull EventNode<Event> node) {

node.addListener(SetupFinishEvent.class, new SetupFinishListener(instanceSwitcher, this.setupDataService::remove));
node.addListener(SetupDiscardEvent.class, new SetupDiscardListener(instanceSwitcher, this.setupDataService::remove));
node.addListener(SaveValidationPromptEvent.class, new SaveValidationPromptListener(dialogRegistry));
node.addListener(SaveValidationPromptEvent.class, new SaveValidationPromptListener());
node.addListener(PlayerGroundBlockSelectEvent.class, new PlayerBlockSelectListener(this.setupDataService::get));
node.addListener(SetupInventorySwitchEvent.class, new SetupInventorySwitchListener(this.inventoryService, this.setupDataService::get));
node.addListener(GameMapBuilderStateNotifyEvent.class, new GameMapBuilderStateNotifyListener());
node.addListener(PlayerPushBlockSelectEvent.class, new PlayerPushBlockSelectListener(this.setupDataService::get));
node.addListener(PlayerPushIndexChangeEvent.class, new PlayerPushIndexChangeListener(this.setupDataService::get));
node.addListener(PlayerDeletePromptEvent.class, new PlayerDeletePromptListener(dialogRegistry));
node.addListener(PlayerCustomClickEvent.class, new PlayerCustomClickEventListener(this.dialogRegistry, this.setupDataService::get));
node.addListener(PlayerDialogRequestEvent.class, new PlayerDialogRequestListener(this.dialogRegistry));
node.addListener(PlayerDeletePromptEvent.class, new PlayerDeletePromptListener());
node.addListener(PlayerCustomClickEvent.class, new DialogPayloadListener(this.setupDataService::get));
node.addListener(PlayerDialogRequestEvent.class, new PlayerDialogRequestListener());
node.addListener(AddEntityToInstanceEvent.class, new EntityAddToInstanceListener(instanceSupplier));

}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package net.theevilreaper.bounce.setup.dialog;

import net.kyori.adventure.key.Key;
import net.kyori.adventure.nbt.CompoundBinaryTag;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.minestom.server.dialog.DialogAction;
import net.minestom.server.dialog.DialogAfterAction;
import net.minestom.server.entity.Player;
import net.onelitefeather.pica.dialog.DialogTemplate;
import net.onelitefeather.pica.dialog.type.DialogType;
import org.jetbrains.annotations.NotNull;

public final class AuthorDialogs extends DialogBase {

public static final Key AUTHOR_AMOUNT_KEY = create("author_amount_dialog");
public static final Key AUTHOR_INPUT_KEY = create("bounce_author_setup");

public static void openAuthorAmountDialog(@NotNull Player player) {
DialogTemplate dialogTemplate = DialogType.confirm(AUTHOR_AMOUNT_KEY)
.meta(dialogMeta -> {
dialogMeta.closeWithEscape(false);
dialogMeta.pause(false);
dialogMeta.afterAction(DialogAfterAction.CLOSE);
dialogMeta.title(Component.text("Request Author(s)"));
dialogMeta.messageBody(template ->
template.contents(Component.text("How many builders should the map have?")));
dialogMeta.range("amount", range -> range
.label(Component.text("Amount"))
.start(1)
.initial(1)
.end(10)
.step(1));
})
.yesButton(button -> button.width(100).label(Component.text("Save")).tooltip(Component.text("Click to confirm", NamedTextColor.GREEN))
.action(new DialogAction.DynamicCustom(AUTHOR_AMOUNT_KEY, getEmptyPayload()))
)
.noButton(button -> button.width(101).label(Component.text("Cancel")).tooltip(Component.text("Click to cancel", NamedTextColor.RED)))
.build();
dialogTemplate.open(player);
}

public static void openAuthorInputDialog(@NotNull Player player, int amount) {
DialogTemplate dialogTemplate = DialogType.confirm(AUTHOR_INPUT_KEY)
.meta(dialogMeta -> {
dialogMeta.closeWithEscape(false);
dialogMeta.pause(false);
dialogMeta.afterAction(DialogAfterAction.CLOSE);
dialogMeta.title(Component.text("Setup Author(s)"));
dialogMeta.messageBody(template ->
template.contents(Component.text("Please enter the builder(s)")));

for (int i = 0; i < amount; i++) {
String key = "author" + i;
Component label = Component.text("Author " + i);
dialogMeta.text(key, textInputTemplate ->
textInputTemplate.activeLabel(false).label(label).maxLength(32).initial(""));
}
})
.yesButton(button -> button.width(100).label(Component.text("Save")).tooltip(Component.text("Click to confirm", NamedTextColor.GREEN))
.action(new DialogAction.DynamicCustom(AUTHOR_INPUT_KEY, getAmountPayload(amount)))
)
.noButton(button -> button.width(101).label(Component.text("Cancel")).tooltip(Component.text("Click to cancel", NamedTextColor.RED)))
.build();
dialogTemplate.open(player);
}

private AuthorDialogs() {
// Nothing to do here
}

private static CompoundBinaryTag getAmountPayload(int amount) {
return CompoundBinaryTag.builder().putInt("amount", amount).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package net.theevilreaper.bounce.setup.dialog;

import net.kyori.adventure.key.Key;
import net.kyori.adventure.nbt.CompoundBinaryTag;
import net.kyori.adventure.text.Component;
import org.jetbrains.annotations.Contract;

public abstract class DialogBase {

protected static final Component NO_COMPONENT = Component.text("No");

/**
* Creates a new instance of a {@link Key} in the bounce namespace.
*
* @param value the value of the key
* @return the created instance
*/
protected static Key create(String value) {
return Key.key("bounce", value);
}

/**
* Creates a new {@link CompoundBinaryTag} with no data for the dialog.
*
* @return the created tag
*/
@Contract(pure = true)
protected static CompoundBinaryTag getEmptyPayload() {
return CompoundBinaryTag.builder().build();
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
package net.theevilreaper.bounce.setup.dialog;

import net.kyori.adventure.key.Key;
import net.kyori.adventure.nbt.CompoundBinaryTag;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import net.minestom.server.dialog.DialogAction;
import net.minestom.server.dialog.DialogAfterAction;
import net.minestom.server.entity.Player;
import net.onelitefeather.pica.dialog.DialogTemplate;
import net.onelitefeather.pica.dialog.type.DialogType;
import net.theevilreaper.bounce.setup.inventory.overview.OverviewType;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;

import java.util.List;

public final class MapDialogs extends DialogBase {

public static final Key NAME_KEY = create("name_setup_dialog");
public static final Key DELETE_KEY = create("delete_dialog");
public static final Key SAVE_VALIDATION_KEY = create("save_validation_dialog");

public static void openNameDialog(@NotNull Player player) {
DialogTemplate dialogTemplate = DialogType.confirm(NAME_KEY)
.meta(dialogMeta -> {
dialogMeta.closeWithEscape(false);
dialogMeta.pause(false);
dialogMeta.afterAction(DialogAfterAction.CLOSE);
dialogMeta.title(Component.text("Setup Map Name"));
dialogMeta.messageBody(template ->
template.contents(Component.text("How the name of the map should be?")));
dialogMeta.text("name", textInputTemplate ->
textInputTemplate.activeLabel(true).label(Component.text("Name")).maxLength(32).initial(""));
})
.yesButton(button -> button.width(100).label(Component.text("Save")).tooltip(Component.text("§7Click to submit"))
.action(new DialogAction.DynamicCustom(NAME_KEY, getEmptyPayload()))
)
.noButton(button -> button.width(101).label(Component.text("Cancel")).tooltip(Component.text("§7Click to cancel")))
.build();
dialogTemplate.open(player);
}

public static void openDeleteDialog(@NotNull Player player, @NotNull OverviewType overviewType) {
DialogTemplate dialogTemplate = DialogType.confirm(DELETE_KEY)
.meta(dialogMeta -> {
dialogMeta.closeWithEscape(false);
dialogMeta.pause(false);
dialogMeta.afterAction(DialogAfterAction.CLOSE);
dialogMeta.title(Component.text("Confirm data deletion"));
dialogMeta.messageBody(template ->
template.contents(Component.text("The following map data would be deleted:")).width(150));
dialogMeta.messageBody(template -> template.contents(Component.empty()).width(1));
dialogMeta.messageBody(template -> template.contents(Component.text(overviewType.getName())).width(100));
})
.yesButton(button -> button.width(100).label(Component.text("Yes")).tooltip(Component.text("Click to confirm", NamedTextColor.GREEN))
.action(new DialogAction.DynamicCustom(DELETE_KEY, getTypePayload(overviewType)))
)
.noButton(button -> button.width(101).label(NO_COMPONENT).tooltip(Component.text("Click to cancel", NamedTextColor.RED)))
.build();
dialogTemplate.open(player);
}

public static void openSaveValidationDialog(@NotNull Player player, @NotNull List<String> missingFields) {
DialogTemplate dialogTemplate = DialogType.confirm(SAVE_VALIDATION_KEY)
.meta(dialogMeta -> {
dialogMeta.closeWithEscape(false);
dialogMeta.pause(false);
dialogMeta.afterAction(DialogAfterAction.CLOSE);
dialogMeta.title(Component.text("This map isn't ready yet"));
dialogMeta.messageBody(template ->
template.contents(Component.text("The following data is still missing:")).width(200));
dialogMeta.messageBody(template -> template.contents(Component.empty()).width(1));

if (missingFields.isEmpty()) {
dialogMeta.messageBody(template ->
template.contents(Component.text("Unknown", NamedTextColor.RED)).width(200));
} else {
for (String missingField : missingFields) {
dialogMeta.messageBody(template ->
template.contents(Component.text("- " + missingField, NamedTextColor.RED)).width(200));
}
}

dialogMeta.messageBody(template -> template.contents(Component.empty()).width(1));
dialogMeta.messageBody(template ->
template.contents(Component.text("Go back and fill them in, or delete this setup.")).width(200));
})
.yesButton(button -> button.width(155).label(Component.text("Delete data")).tooltip(Component.text("Click to confirm", NamedTextColor.GREEN))
.action(new DialogAction.DynamicCustom(SAVE_VALIDATION_KEY, getEmptyPayload()))
)
.noButton(button -> button.width(155).label(Component.text("Back")).tooltip(Component.text("Click to cancel", NamedTextColor.RED)))
.build();
dialogTemplate.open(player);
}

private MapDialogs() {
// Nothing to do here
}

@Contract(pure = true)
private static CompoundBinaryTag getTypePayload(@NotNull OverviewType overviewType) {
return CompoundBinaryTag.builder().putInt("type", overviewType.ordinal()).build();
}
}
Loading
Loading