From 69a865c8f2cf50db8b82ab12365a7d5dbcc406a0 Mon Sep 17 00:00:00 2001 From: Zoriot Date: Sun, 27 Sep 2026 01:18:06 +0200 Subject: [PATCH 1/3] feat: add plot lifecycle event API --- .../api/event/PlotAbandonedEvent.java | 43 +++++++++++++++++++ .../api/event/PlotCreatedEvent.java | 28 ++++++++++++ .../api/event/PlotFeedbackUpdatedEvent.java | 28 ++++++++++++ .../api/event/PlotInactivityWarningEvent.java | 37 ++++++++++++++++ .../api/event/PlotRejectedEvent.java | 28 ++++++++++++ .../api/event/PlotReviewUndoneEvent.java | 28 ++++++++++++ .../api/event/PlotReviewedEvent.java | 28 ++++++++++++ .../api/event/PlotSubmissionUndoneEvent.java | 28 ++++++++++++ .../api/event/PlotSubmittedEvent.java | 28 ++++++++++++ .../plotsystem/api/event/package-info.java | 17 ++++++++ .../menus/review/ReviewPlotTogglesMenu.java | 4 ++ .../core/system/plot/PlotHandler.java | 23 ++++++++-- .../generator/loader/AbstractPlotLoader.java | 2 +- .../core/system/review/PlotReview.java | 6 +++ 14 files changed, 323 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/alpsbte/plotsystem/api/event/PlotAbandonedEvent.java create mode 100644 src/main/java/com/alpsbte/plotsystem/api/event/PlotCreatedEvent.java create mode 100644 src/main/java/com/alpsbte/plotsystem/api/event/PlotFeedbackUpdatedEvent.java create mode 100644 src/main/java/com/alpsbte/plotsystem/api/event/PlotInactivityWarningEvent.java create mode 100644 src/main/java/com/alpsbte/plotsystem/api/event/PlotRejectedEvent.java create mode 100644 src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewUndoneEvent.java create mode 100644 src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewedEvent.java create mode 100644 src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmissionUndoneEvent.java create mode 100644 src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmittedEvent.java create mode 100644 src/main/java/com/alpsbte/plotsystem/api/event/package-info.java diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotAbandonedEvent.java b/src/main/java/com/alpsbte/plotsystem/api/event/PlotAbandonedEvent.java new file mode 100644 index 00000000..e57f006d --- /dev/null +++ b/src/main/java/com/alpsbte/plotsystem/api/event/PlotAbandonedEvent.java @@ -0,0 +1,43 @@ +package com.alpsbte.plotsystem.api.event; + +import com.alpsbte.plotsystem.core.system.plot.AbstractPlot; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +import java.util.Objects; + +public final class PlotAbandonedEvent extends Event { + public enum Reason { + INACTIVITY, + MANUAL, + COMMAND, + SYSTEM + } + + private static final HandlerList HANDLERS = new HandlerList(); + private final AbstractPlot plot; + private final Reason reason; + + public PlotAbandonedEvent(@NotNull AbstractPlot plot, @NotNull Reason reason) { + this.plot = Objects.requireNonNull(plot, "plot"); + this.reason = Objects.requireNonNull(reason, "reason"); + } + + public @NotNull AbstractPlot getPlot() { + return plot; + } + + public @NotNull Reason getReason() { + return reason; + } + + public static @NotNull HandlerList getHandlerList() { + return HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } +} diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotCreatedEvent.java b/src/main/java/com/alpsbte/plotsystem/api/event/PlotCreatedEvent.java new file mode 100644 index 00000000..658a9d69 --- /dev/null +++ b/src/main/java/com/alpsbte/plotsystem/api/event/PlotCreatedEvent.java @@ -0,0 +1,28 @@ +package com.alpsbte.plotsystem.api.event; + +import com.alpsbte.plotsystem.core.system.plot.AbstractPlot; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public final class PlotCreatedEvent extends Event { + private static final HandlerList HANDLERS = new HandlerList(); + private final AbstractPlot plot; + + public PlotCreatedEvent(@NotNull AbstractPlot plot) { + this.plot = plot; + } + + public @NotNull AbstractPlot getPlot() { + return plot; + } + + public static @NotNull HandlerList getHandlerList() { + return HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } +} diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotFeedbackUpdatedEvent.java b/src/main/java/com/alpsbte/plotsystem/api/event/PlotFeedbackUpdatedEvent.java new file mode 100644 index 00000000..3c2c5cc9 --- /dev/null +++ b/src/main/java/com/alpsbte/plotsystem/api/event/PlotFeedbackUpdatedEvent.java @@ -0,0 +1,28 @@ +package com.alpsbte.plotsystem.api.event; + +import com.alpsbte.plotsystem.core.system.review.PlotReview; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public final class PlotFeedbackUpdatedEvent extends Event { + private static final HandlerList HANDLERS = new HandlerList(); + private final PlotReview review; + + public PlotFeedbackUpdatedEvent(@NotNull PlotReview review) { + this.review = review; + } + + public @NotNull PlotReview getReview() { + return review; + } + + public static @NotNull HandlerList getHandlerList() { + return HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } +} diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotInactivityWarningEvent.java b/src/main/java/com/alpsbte/plotsystem/api/event/PlotInactivityWarningEvent.java new file mode 100644 index 00000000..2b839bfe --- /dev/null +++ b/src/main/java/com/alpsbte/plotsystem/api/event/PlotInactivityWarningEvent.java @@ -0,0 +1,37 @@ +package com.alpsbte.plotsystem.api.event; + +import com.alpsbte.plotsystem.core.system.plot.Plot; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +import java.time.LocalDate; +import java.util.Objects; + +public final class PlotInactivityWarningEvent extends Event { + private static final HandlerList HANDLERS = new HandlerList(); + private final Plot plot; + private final LocalDate abandonmentDate; + + public PlotInactivityWarningEvent(@NotNull Plot plot, @NotNull LocalDate abandonmentDate) { + this.plot = Objects.requireNonNull(plot, "plot"); + this.abandonmentDate = Objects.requireNonNull(abandonmentDate, "abandonmentDate"); + } + + public @NotNull Plot getPlot() { + return plot; + } + + public @NotNull LocalDate getAbandonmentDate() { + return abandonmentDate; + } + + public static @NotNull HandlerList getHandlerList() { + return HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } +} diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotRejectedEvent.java b/src/main/java/com/alpsbte/plotsystem/api/event/PlotRejectedEvent.java new file mode 100644 index 00000000..74552ecf --- /dev/null +++ b/src/main/java/com/alpsbte/plotsystem/api/event/PlotRejectedEvent.java @@ -0,0 +1,28 @@ +package com.alpsbte.plotsystem.api.event; + +import com.alpsbte.plotsystem.core.system.review.PlotReview; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public final class PlotRejectedEvent extends Event { + private static final HandlerList HANDLERS = new HandlerList(); + private final PlotReview review; + + public PlotRejectedEvent(@NotNull PlotReview review) { + this.review = review; + } + + public @NotNull PlotReview getReview() { + return review; + } + + public static @NotNull HandlerList getHandlerList() { + return HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } +} diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewUndoneEvent.java b/src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewUndoneEvent.java new file mode 100644 index 00000000..06104a5d --- /dev/null +++ b/src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewUndoneEvent.java @@ -0,0 +1,28 @@ +package com.alpsbte.plotsystem.api.event; + +import com.alpsbte.plotsystem.core.system.review.PlotReview; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public final class PlotReviewUndoneEvent extends Event { + private static final HandlerList HANDLERS = new HandlerList(); + private final PlotReview review; + + public PlotReviewUndoneEvent(@NotNull PlotReview review) { + this.review = review; + } + + public @NotNull PlotReview getReview() { + return review; + } + + public static @NotNull HandlerList getHandlerList() { + return HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } +} diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewedEvent.java b/src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewedEvent.java new file mode 100644 index 00000000..c875164e --- /dev/null +++ b/src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewedEvent.java @@ -0,0 +1,28 @@ +package com.alpsbte.plotsystem.api.event; + +import com.alpsbte.plotsystem.core.system.review.PlotReview; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public final class PlotReviewedEvent extends Event { + private static final HandlerList HANDLERS = new HandlerList(); + private final PlotReview review; + + public PlotReviewedEvent(@NotNull PlotReview review) { + this.review = review; + } + + public @NotNull PlotReview getReview() { + return review; + } + + public static @NotNull HandlerList getHandlerList() { + return HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } +} diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmissionUndoneEvent.java b/src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmissionUndoneEvent.java new file mode 100644 index 00000000..96a6f16d --- /dev/null +++ b/src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmissionUndoneEvent.java @@ -0,0 +1,28 @@ +package com.alpsbte.plotsystem.api.event; + +import com.alpsbte.plotsystem.core.system.plot.Plot; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public final class PlotSubmissionUndoneEvent extends Event { + private static final HandlerList HANDLERS = new HandlerList(); + private final Plot plot; + + public PlotSubmissionUndoneEvent(@NotNull Plot plot) { + this.plot = plot; + } + + public @NotNull Plot getPlot() { + return plot; + } + + public static @NotNull HandlerList getHandlerList() { + return HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } +} diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmittedEvent.java b/src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmittedEvent.java new file mode 100644 index 00000000..a03c58fd --- /dev/null +++ b/src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmittedEvent.java @@ -0,0 +1,28 @@ +package com.alpsbte.plotsystem.api.event; + +import com.alpsbte.plotsystem.core.system.plot.Plot; +import org.bukkit.event.Event; +import org.bukkit.event.HandlerList; +import org.jetbrains.annotations.NotNull; + +public final class PlotSubmittedEvent extends Event { + private static final HandlerList HANDLERS = new HandlerList(); + private final Plot plot; + + public PlotSubmittedEvent(@NotNull Plot plot) { + this.plot = plot; + } + + public @NotNull Plot getPlot() { + return plot; + } + + public static @NotNull HandlerList getHandlerList() { + return HANDLERS; + } + + @Override + public @NotNull HandlerList getHandlers() { + return HANDLERS; + } +} diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/package-info.java b/src/main/java/com/alpsbte/plotsystem/api/event/package-info.java new file mode 100644 index 00000000..b406e89a --- /dev/null +++ b/src/main/java/com/alpsbte/plotsystem/api/event/package-info.java @@ -0,0 +1,17 @@ +/** + * Stable lifecycle events published by Plot System for external integrations. + * + *

Integrations should register a Bukkit listener and translate these events + * into their own transport or application API. Plot System does not depend on + * any integration implementation.

+ * + *
{@code
+ * public final class MyIntegrationListener implements Listener {
+ *     @EventHandler
+ *     public void onPlotSubmitted(PlotSubmittedEvent event) {
+ *         // Translate event.getPlot() to the integration's model.
+ *     }
+ * }
+ * }
+ */ +package com.alpsbte.plotsystem.api.event; diff --git a/src/main/java/com/alpsbte/plotsystem/core/menus/review/ReviewPlotTogglesMenu.java b/src/main/java/com/alpsbte/plotsystem/core/menus/review/ReviewPlotTogglesMenu.java index 988c00ca..a8a27e59 100644 --- a/src/main/java/com/alpsbte/plotsystem/core/menus/review/ReviewPlotTogglesMenu.java +++ b/src/main/java/com/alpsbte/plotsystem/core/menus/review/ReviewPlotTogglesMenu.java @@ -3,6 +3,8 @@ import com.alpsbte.alpslib.utils.item.ItemBuilder; import com.alpsbte.alpslib.utils.item.LoreBuilder; import com.alpsbte.plotsystem.PlotSystem; +import com.alpsbte.plotsystem.api.event.PlotRejectedEvent; +import com.alpsbte.plotsystem.api.event.PlotReviewedEvent; import com.alpsbte.plotsystem.core.database.DataProvider; import com.alpsbte.plotsystem.core.menus.AbstractMenu; import com.alpsbte.plotsystem.core.system.Builder; @@ -129,9 +131,11 @@ private void submitReview() { if (!isRejected) { reviewerConfirmationMessage = Utils.ChatUtils.getInfoFormat(LangUtil.getInstance().get(getMenuPlayer(), LangPaths.Message.Info.PLOT_MARKED_REVIEWED, Integer.toString(plot.getId()), getParticipantsString())); if (!acceptPlot(review.getScore(), review.getSplitScore())) return; + Bukkit.getPluginManager().callEvent(new PlotReviewedEvent(review)); } else { reviewerConfirmationMessage = Utils.ChatUtils.getInfoFormat(LangUtil.getInstance().get(getMenuPlayer(), LangPaths.Message.Info.PLOT_REJECTED, Integer.toString(plot.getId()), getParticipantsString())); PlotHandler.undoSubmit(plot); + Bukkit.getPluginManager().callEvent(new PlotRejectedEvent(review)); } Bukkit.getScheduler().runTask(PlotSystem.getPlugin(), () -> { diff --git a/src/main/java/com/alpsbte/plotsystem/core/system/plot/PlotHandler.java b/src/main/java/com/alpsbte/plotsystem/core/system/plot/PlotHandler.java index 102f8cf2..62ca6b2d 100644 --- a/src/main/java/com/alpsbte/plotsystem/core/system/plot/PlotHandler.java +++ b/src/main/java/com/alpsbte/plotsystem/core/system/plot/PlotHandler.java @@ -1,6 +1,10 @@ package com.alpsbte.plotsystem.core.system.plot; import com.alpsbte.plotsystem.PlotSystem; +import com.alpsbte.plotsystem.api.event.PlotAbandonedEvent; +import com.alpsbte.plotsystem.api.event.PlotCreatedEvent; +import com.alpsbte.plotsystem.api.event.PlotSubmissionUndoneEvent; +import com.alpsbte.plotsystem.api.event.PlotSubmittedEvent; import com.alpsbte.plotsystem.core.database.DataProvider; import com.alpsbte.plotsystem.core.system.Builder; import com.alpsbte.plotsystem.core.system.CityProject; @@ -26,13 +30,12 @@ import com.sk89q.worldedit.extent.clipboard.io.ClipboardWriter; import com.sk89q.worldedit.function.operation.ForwardExtentCopy; import com.sk89q.worldedit.function.operation.Operations; -import com.sk89q.worldedit.math.BlockVector2; import com.sk89q.worldedit.math.BlockVector3; import com.sk89q.worldedit.math.Vector3; import com.sk89q.worldedit.math.transform.AffineTransform; import com.sk89q.worldedit.regions.CuboidRegion; import com.sk89q.worldedit.regions.Polygonal2DRegion; -import com.sk89q.worldedit.world.World; +import org.bukkit.Bukkit; import org.bukkit.SoundCategory; import org.bukkit.configuration.file.FileConfiguration; import org.bukkit.entity.Player; @@ -134,6 +137,9 @@ public static boolean generatePlot(Builder builder, Plot plot, PlotType type) { } DefaultPlotLoader loader = new DefaultPlotLoader(plot, builder, type, PlotWorld.getByType(type, plot)); + if (loader.isSuccessful()) { + Bukkit.getPluginManager().callEvent(new PlotCreatedEvent(plot)); + } return loader.isSuccessful(); } @@ -158,6 +164,10 @@ private static boolean tryStartGeneration(Builder builder) { @SuppressWarnings("BooleanMethodIsAlwaysInverted") public static boolean abandonPlot(AbstractPlot plot) { + return abandonPlot(plot, PlotAbandonedEvent.Reason.MANUAL); + } + + public static boolean abandonPlot(AbstractPlot plot, PlotAbandonedEvent.Reason reason) { try { boolean successfullyAbandoned = plot.getWorld().onAbandon(); if (!successfullyAbandoned) { @@ -193,11 +203,14 @@ public static boolean abandonPlot(AbstractPlot plot) { if (!successful) { PlotSystem.getPlugin().getComponentLogger().error(text("Failed to abandon plot with the ID " + plot.getId() + "!")); } + if (successful) { + Bukkit.getPluginManager().callEvent(new PlotAbandonedEvent(plot, reason)); + } return successful; } public static boolean deletePlot(Plot plot) { - if (!abandonPlot(plot)) { + if (!abandonPlot(plot, PlotAbandonedEvent.Reason.INACTIVITY)) { PlotSystem.getPlugin().getComponentLogger().warn(text("Failed to delete plot with the ID " + plot.getId() + "!")); return false; } @@ -218,7 +231,7 @@ public static void abandonInactivePlots() { if (interval == -2 || lastActivity == null || lastActivity.plusDays(interval).isAfter(LocalDate.now())) continue; CompletableFuture.runAsync(() -> { - if (!abandonPlot(plot)) { + if (!abandonPlot(plot, PlotAbandonedEvent.Reason.COMMAND)) { PlotSystem.getPlugin().getComponentLogger().warn(text("An error occurred while abandoning plot #" + plot.getId() + " due to inactivity!")); return; } @@ -242,6 +255,7 @@ public static void submitPlot(@NotNull Plot plot) { plot.getPermissions().removeBuilderPerms(builder.getUUID()); } } + Bukkit.getPluginManager().callEvent(new PlotSubmittedEvent(plot)); } public static void undoSubmit(@NotNull Plot plot) { @@ -253,6 +267,7 @@ public static void undoSubmit(@NotNull Plot plot) { plot.getPermissions().addBuilderPerms(builder.getUUID()); } } + Bukkit.getPluginManager().callEvent(new PlotSubmissionUndoneEvent(plot)); } public static void removePlayerFromGenerationHistory(UUID playerUuid) { diff --git a/src/main/java/com/alpsbte/plotsystem/core/system/plot/generator/loader/AbstractPlotLoader.java b/src/main/java/com/alpsbte/plotsystem/core/system/plot/generator/loader/AbstractPlotLoader.java index 066c0f3c..5914ffe1 100644 --- a/src/main/java/com/alpsbte/plotsystem/core/system/plot/generator/loader/AbstractPlotLoader.java +++ b/src/main/java/com/alpsbte/plotsystem/core/system/plot/generator/loader/AbstractPlotLoader.java @@ -347,7 +347,7 @@ public static void pasteSchematic(boolean ignoreAir, byte[] schematicFile, @NotN protected void onException(Exception e) { if (abandonOnFailure) { try { - if (!PlotHandler.abandonPlot(this.plot)) { + if (!PlotHandler.abandonPlot(this.plot, com.alpsbte.plotsystem.api.event.PlotAbandonedEvent.Reason.SYSTEM)) { PlotSystem.getPlugin().getComponentLogger().error("Failed to clean up plot #{} after generation error!", plot.getId()); } } catch (Exception ex) { diff --git a/src/main/java/com/alpsbte/plotsystem/core/system/review/PlotReview.java b/src/main/java/com/alpsbte/plotsystem/core/system/review/PlotReview.java index a2e3c407..682cbeeb 100644 --- a/src/main/java/com/alpsbte/plotsystem/core/system/review/PlotReview.java +++ b/src/main/java/com/alpsbte/plotsystem/core/system/review/PlotReview.java @@ -1,6 +1,8 @@ package com.alpsbte.plotsystem.core.system.review; import com.alpsbte.plotsystem.PlotSystem; +import com.alpsbte.plotsystem.api.event.PlotFeedbackUpdatedEvent; +import com.alpsbte.plotsystem.api.event.PlotReviewUndoneEvent; import com.alpsbte.plotsystem.core.database.DataProvider; import com.alpsbte.plotsystem.core.system.Builder; import com.alpsbte.plotsystem.core.system.plot.Plot; @@ -67,6 +69,7 @@ public UUID getReviewerUUID() { public boolean updateFeedback(String feedback) { if (DataProvider.REVIEW.updateFeedback(reviewId, feedback)) { this.feedback = feedback; + PlotSystem.getPlugin().getServer().getPluginManager().callEvent(new PlotFeedbackUpdatedEvent(this)); return true; } return false; @@ -99,6 +102,9 @@ public boolean undoReview() { PlotSystem.getPlugin().getComponentLogger().error("Failed to remove plot review with ID {} from database!", reviewId); } + if (successful) { + PlotSystem.getPlugin().getServer().getPluginManager().callEvent(new PlotReviewUndoneEvent(this)); + } return successful; } From 301f94f42e0f31dc84b761a9851539fe5e9b9ee4 Mon Sep 17 00:00:00 2001 From: Zoriot Date: Sun, 27 Sep 2026 01:33:04 +0200 Subject: [PATCH 2/3] refactor: publish standalone Plot System API module --- .github/workflows/deploy-api.yml | 34 ++++++++++++ build.gradle.kts | 1 + plot-system-api/build.gradle.kts | 49 +++++++++++++++++ .../api/event/PlotAbandonedEvent.java | 20 +++---- .../api/event/PlotCreatedEvent.java | 8 +-- .../api/event/PlotFeedbackUpdatedEvent.java | 8 +-- .../api/event/PlotInactivityWarningEvent.java | 8 +-- .../api/event/PlotRejectedEvent.java | 8 +-- .../api/event/PlotReviewUndoneEvent.java | 8 +-- .../api/event/PlotReviewedEvent.java | 8 +-- .../api/event/PlotSubmissionUndoneEvent.java | 8 +-- .../api/event/PlotSubmittedEvent.java | 8 +-- .../plotsystem/api/event/package-info.java | 0 .../api/model/PlotAbandonReason.java | 8 +++ .../plotsystem/api/model/PlotDifficulty.java | 7 +++ .../plotsystem/api/model/PlotSnapshot.java | 21 ++++++++ .../plotsystem/api/model/PlotStatus.java | 8 +++ .../plotsystem/api/model/PlotType.java | 8 +++ .../plotsystem/api/model/ReviewSnapshot.java | 12 +++++ settings.gradle.kts | 1 + .../core/integration/PlotEventSnapshots.java | 53 +++++++++++++++++++ .../menus/review/ReviewPlotTogglesMenu.java | 5 +- .../core/system/plot/PlotHandler.java | 18 ++++--- .../generator/loader/AbstractPlotLoader.java | 2 +- .../core/system/review/PlotReview.java | 5 +- 25 files changed, 258 insertions(+), 58 deletions(-) create mode 100644 .github/workflows/deploy-api.yml create mode 100644 plot-system-api/build.gradle.kts rename {src => plot-system-api/src}/main/java/com/alpsbte/plotsystem/api/event/PlotAbandonedEvent.java (62%) rename {src => plot-system-api/src}/main/java/com/alpsbte/plotsystem/api/event/PlotCreatedEvent.java (72%) rename {src => plot-system-api/src}/main/java/com/alpsbte/plotsystem/api/event/PlotFeedbackUpdatedEvent.java (71%) rename {src => plot-system-api/src}/main/java/com/alpsbte/plotsystem/api/event/PlotInactivityWarningEvent.java (77%) rename {src => plot-system-api/src}/main/java/com/alpsbte/plotsystem/api/event/PlotRejectedEvent.java (71%) rename {src => plot-system-api/src}/main/java/com/alpsbte/plotsystem/api/event/PlotReviewUndoneEvent.java (71%) rename {src => plot-system-api/src}/main/java/com/alpsbte/plotsystem/api/event/PlotReviewedEvent.java (71%) rename {src => plot-system-api/src}/main/java/com/alpsbte/plotsystem/api/event/PlotSubmissionUndoneEvent.java (72%) rename {src => plot-system-api/src}/main/java/com/alpsbte/plotsystem/api/event/PlotSubmittedEvent.java (72%) rename {src => plot-system-api/src}/main/java/com/alpsbte/plotsystem/api/event/package-info.java (100%) create mode 100644 plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotAbandonReason.java create mode 100644 plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotDifficulty.java create mode 100644 plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotSnapshot.java create mode 100644 plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotStatus.java create mode 100644 plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotType.java create mode 100644 plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/ReviewSnapshot.java create mode 100644 src/main/java/com/alpsbte/plotsystem/core/integration/PlotEventSnapshots.java diff --git a/.github/workflows/deploy-api.yml b/.github/workflows/deploy-api.yml new file mode 100644 index 00000000..ece6637e --- /dev/null +++ b/.github/workflows/deploy-api.yml @@ -0,0 +1,34 @@ +name: Build and Deploy Plot System API + +on: + workflow_dispatch: + push: + branches: [ main ] + paths: + - 'plot-system-api/**' + +jobs: + build-and-deploy: + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v7 + + - name: Set up JDK + uses: actions/setup-java@v6 + with: + distribution: 'temurin' + java-version: '25' + + - name: Setup Gradle + uses: gradle/actions/setup-gradle@v6 + + - name: Build with Gradle + run: ./gradlew :plot-system-api:build + + - name: Deploy Plot System API to Maven repository + run: ./gradlew :plot-system-api:publish + env: + ORG_GRADLE_PROJECT_alpsMavenUser: ${{ secrets.MAVEN_USERNAME }} + ORG_GRADLE_PROJECT_alpsMavenPassword: ${{ secrets.MAVEN_PASSWORD }} \ No newline at end of file diff --git a/build.gradle.kts b/build.gradle.kts index 71a49ce2..b6c82b56 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -47,6 +47,7 @@ val guavaPackage = "com.google.guava" val gsonPackage = "com.google.code.gson" dependencies { + implementation(project(":plot-system-api")) implementation(libs.com.alpsbte.canvas) implementation(libs.com.alpsbte.alpslib.alpslib.io) implementation(libs.com.alpsbte.alpslib.alpslib.hologram) diff --git a/plot-system-api/build.gradle.kts b/plot-system-api/build.gradle.kts new file mode 100644 index 00000000..12cdf873 --- /dev/null +++ b/plot-system-api/build.gradle.kts @@ -0,0 +1,49 @@ +plugins { + `java-library` + `maven-publish` +} + +repositories { + maven { url = uri("https://repo.papermc.io/repository/maven-public/") } + mavenCentral() +} + +group = rootProject.group +version = rootProject.version +description = "Plot System API." + +dependencies { + compileOnly(libs.io.papermc.paper.paper.api) +} + +java { + toolchain { + languageVersion.set(rootProject.providers.gradleProperty("targetJava").map(JavaLanguageVersion::of).orElse(JavaLanguageVersion.of(25))) + } + withSourcesJar() +} + +tasks.withType().configureEach { + options.encoding = "UTF-8" + options.release.set(rootProject.providers.gradleProperty("targetJava").map(String::toInt).orElse(25)) +} + +val alpsMavenUser: String? = project.findProperty("alpsMavenUser") as String? +val alpsMavenPassword: String? = project.findProperty("alpsMavenPassword") as String? + +publishing { + publications { + create("mavenJava") { + from(components["java"]) + } + } + repositories { + maven { + credentials { + username = alpsMavenUser + password = alpsMavenPassword + } + url = uri("https://mvn.alps-bte.com/repository/alps-bte/") + } + } +} diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotAbandonedEvent.java b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotAbandonedEvent.java similarity index 62% rename from src/main/java/com/alpsbte/plotsystem/api/event/PlotAbandonedEvent.java rename to plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotAbandonedEvent.java index e57f006d..19caaf6e 100644 --- a/src/main/java/com/alpsbte/plotsystem/api/event/PlotAbandonedEvent.java +++ b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotAbandonedEvent.java @@ -1,6 +1,7 @@ package com.alpsbte.plotsystem.api.event; -import com.alpsbte.plotsystem.core.system.plot.AbstractPlot; +import com.alpsbte.plotsystem.api.model.PlotAbandonReason; +import com.alpsbte.plotsystem.api.model.PlotSnapshot; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; @@ -8,27 +9,20 @@ import java.util.Objects; public final class PlotAbandonedEvent extends Event { - public enum Reason { - INACTIVITY, - MANUAL, - COMMAND, - SYSTEM - } - private static final HandlerList HANDLERS = new HandlerList(); - private final AbstractPlot plot; - private final Reason reason; + private final PlotSnapshot plot; + private final PlotAbandonReason reason; - public PlotAbandonedEvent(@NotNull AbstractPlot plot, @NotNull Reason reason) { + public PlotAbandonedEvent(@NotNull PlotSnapshot plot, @NotNull PlotAbandonReason reason) { this.plot = Objects.requireNonNull(plot, "plot"); this.reason = Objects.requireNonNull(reason, "reason"); } - public @NotNull AbstractPlot getPlot() { + public @NotNull PlotSnapshot getPlot() { return plot; } - public @NotNull Reason getReason() { + public @NotNull PlotAbandonReason getReason() { return reason; } diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotCreatedEvent.java b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotCreatedEvent.java similarity index 72% rename from src/main/java/com/alpsbte/plotsystem/api/event/PlotCreatedEvent.java rename to plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotCreatedEvent.java index 658a9d69..bc86c596 100644 --- a/src/main/java/com/alpsbte/plotsystem/api/event/PlotCreatedEvent.java +++ b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotCreatedEvent.java @@ -1,19 +1,19 @@ package com.alpsbte.plotsystem.api.event; -import com.alpsbte.plotsystem.core.system.plot.AbstractPlot; +import com.alpsbte.plotsystem.api.model.PlotSnapshot; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; public final class PlotCreatedEvent extends Event { private static final HandlerList HANDLERS = new HandlerList(); - private final AbstractPlot plot; + private final PlotSnapshot plot; - public PlotCreatedEvent(@NotNull AbstractPlot plot) { + public PlotCreatedEvent(@NotNull PlotSnapshot plot) { this.plot = plot; } - public @NotNull AbstractPlot getPlot() { + public @NotNull PlotSnapshot getPlot() { return plot; } diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotFeedbackUpdatedEvent.java b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotFeedbackUpdatedEvent.java similarity index 71% rename from src/main/java/com/alpsbte/plotsystem/api/event/PlotFeedbackUpdatedEvent.java rename to plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotFeedbackUpdatedEvent.java index 3c2c5cc9..e6c43bc7 100644 --- a/src/main/java/com/alpsbte/plotsystem/api/event/PlotFeedbackUpdatedEvent.java +++ b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotFeedbackUpdatedEvent.java @@ -1,19 +1,19 @@ package com.alpsbte.plotsystem.api.event; -import com.alpsbte.plotsystem.core.system.review.PlotReview; +import com.alpsbte.plotsystem.api.model.ReviewSnapshot; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; public final class PlotFeedbackUpdatedEvent extends Event { private static final HandlerList HANDLERS = new HandlerList(); - private final PlotReview review; + private final ReviewSnapshot review; - public PlotFeedbackUpdatedEvent(@NotNull PlotReview review) { + public PlotFeedbackUpdatedEvent(@NotNull ReviewSnapshot review) { this.review = review; } - public @NotNull PlotReview getReview() { + public @NotNull ReviewSnapshot getReview() { return review; } diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotInactivityWarningEvent.java b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotInactivityWarningEvent.java similarity index 77% rename from src/main/java/com/alpsbte/plotsystem/api/event/PlotInactivityWarningEvent.java rename to plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotInactivityWarningEvent.java index 2b839bfe..79063018 100644 --- a/src/main/java/com/alpsbte/plotsystem/api/event/PlotInactivityWarningEvent.java +++ b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotInactivityWarningEvent.java @@ -1,6 +1,6 @@ package com.alpsbte.plotsystem.api.event; -import com.alpsbte.plotsystem.core.system.plot.Plot; +import com.alpsbte.plotsystem.api.model.PlotSnapshot; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; @@ -10,15 +10,15 @@ public final class PlotInactivityWarningEvent extends Event { private static final HandlerList HANDLERS = new HandlerList(); - private final Plot plot; + private final PlotSnapshot plot; private final LocalDate abandonmentDate; - public PlotInactivityWarningEvent(@NotNull Plot plot, @NotNull LocalDate abandonmentDate) { + public PlotInactivityWarningEvent(@NotNull PlotSnapshot plot, @NotNull LocalDate abandonmentDate) { this.plot = Objects.requireNonNull(plot, "plot"); this.abandonmentDate = Objects.requireNonNull(abandonmentDate, "abandonmentDate"); } - public @NotNull Plot getPlot() { + public @NotNull PlotSnapshot getPlot() { return plot; } diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotRejectedEvent.java b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotRejectedEvent.java similarity index 71% rename from src/main/java/com/alpsbte/plotsystem/api/event/PlotRejectedEvent.java rename to plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotRejectedEvent.java index 74552ecf..00ffabe6 100644 --- a/src/main/java/com/alpsbte/plotsystem/api/event/PlotRejectedEvent.java +++ b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotRejectedEvent.java @@ -1,19 +1,19 @@ package com.alpsbte.plotsystem.api.event; -import com.alpsbte.plotsystem.core.system.review.PlotReview; +import com.alpsbte.plotsystem.api.model.ReviewSnapshot; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; public final class PlotRejectedEvent extends Event { private static final HandlerList HANDLERS = new HandlerList(); - private final PlotReview review; + private final ReviewSnapshot review; - public PlotRejectedEvent(@NotNull PlotReview review) { + public PlotRejectedEvent(@NotNull ReviewSnapshot review) { this.review = review; } - public @NotNull PlotReview getReview() { + public @NotNull ReviewSnapshot getReview() { return review; } diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewUndoneEvent.java b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewUndoneEvent.java similarity index 71% rename from src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewUndoneEvent.java rename to plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewUndoneEvent.java index 06104a5d..48586fe7 100644 --- a/src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewUndoneEvent.java +++ b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewUndoneEvent.java @@ -1,19 +1,19 @@ package com.alpsbte.plotsystem.api.event; -import com.alpsbte.plotsystem.core.system.review.PlotReview; +import com.alpsbte.plotsystem.api.model.ReviewSnapshot; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; public final class PlotReviewUndoneEvent extends Event { private static final HandlerList HANDLERS = new HandlerList(); - private final PlotReview review; + private final ReviewSnapshot review; - public PlotReviewUndoneEvent(@NotNull PlotReview review) { + public PlotReviewUndoneEvent(@NotNull ReviewSnapshot review) { this.review = review; } - public @NotNull PlotReview getReview() { + public @NotNull ReviewSnapshot getReview() { return review; } diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewedEvent.java b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewedEvent.java similarity index 71% rename from src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewedEvent.java rename to plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewedEvent.java index c875164e..6f870ba6 100644 --- a/src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewedEvent.java +++ b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotReviewedEvent.java @@ -1,19 +1,19 @@ package com.alpsbte.plotsystem.api.event; -import com.alpsbte.plotsystem.core.system.review.PlotReview; +import com.alpsbte.plotsystem.api.model.ReviewSnapshot; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; public final class PlotReviewedEvent extends Event { private static final HandlerList HANDLERS = new HandlerList(); - private final PlotReview review; + private final ReviewSnapshot review; - public PlotReviewedEvent(@NotNull PlotReview review) { + public PlotReviewedEvent(@NotNull ReviewSnapshot review) { this.review = review; } - public @NotNull PlotReview getReview() { + public @NotNull ReviewSnapshot getReview() { return review; } diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmissionUndoneEvent.java b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmissionUndoneEvent.java similarity index 72% rename from src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmissionUndoneEvent.java rename to plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmissionUndoneEvent.java index 96a6f16d..a3e9e17d 100644 --- a/src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmissionUndoneEvent.java +++ b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmissionUndoneEvent.java @@ -1,19 +1,19 @@ package com.alpsbte.plotsystem.api.event; -import com.alpsbte.plotsystem.core.system.plot.Plot; +import com.alpsbte.plotsystem.api.model.PlotSnapshot; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; public final class PlotSubmissionUndoneEvent extends Event { private static final HandlerList HANDLERS = new HandlerList(); - private final Plot plot; + private final PlotSnapshot plot; - public PlotSubmissionUndoneEvent(@NotNull Plot plot) { + public PlotSubmissionUndoneEvent(@NotNull PlotSnapshot plot) { this.plot = plot; } - public @NotNull Plot getPlot() { + public @NotNull PlotSnapshot getPlot() { return plot; } diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmittedEvent.java b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmittedEvent.java similarity index 72% rename from src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmittedEvent.java rename to plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmittedEvent.java index a03c58fd..94541d6c 100644 --- a/src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmittedEvent.java +++ b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/PlotSubmittedEvent.java @@ -1,19 +1,19 @@ package com.alpsbte.plotsystem.api.event; -import com.alpsbte.plotsystem.core.system.plot.Plot; +import com.alpsbte.plotsystem.api.model.PlotSnapshot; import org.bukkit.event.Event; import org.bukkit.event.HandlerList; import org.jetbrains.annotations.NotNull; public final class PlotSubmittedEvent extends Event { private static final HandlerList HANDLERS = new HandlerList(); - private final Plot plot; + private final PlotSnapshot plot; - public PlotSubmittedEvent(@NotNull Plot plot) { + public PlotSubmittedEvent(@NotNull PlotSnapshot plot) { this.plot = plot; } - public @NotNull Plot getPlot() { + public @NotNull PlotSnapshot getPlot() { return plot; } diff --git a/src/main/java/com/alpsbte/plotsystem/api/event/package-info.java b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/package-info.java similarity index 100% rename from src/main/java/com/alpsbte/plotsystem/api/event/package-info.java rename to plot-system-api/src/main/java/com/alpsbte/plotsystem/api/event/package-info.java diff --git a/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotAbandonReason.java b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotAbandonReason.java new file mode 100644 index 00000000..8c9dc1b4 --- /dev/null +++ b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotAbandonReason.java @@ -0,0 +1,8 @@ +package com.alpsbte.plotsystem.api.model; + +public enum PlotAbandonReason { + INACTIVITY, + MANUAL, + COMMAND, + SYSTEM +} diff --git a/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotDifficulty.java b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotDifficulty.java new file mode 100644 index 00000000..183d51a6 --- /dev/null +++ b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotDifficulty.java @@ -0,0 +1,7 @@ +package com.alpsbte.plotsystem.api.model; + +public enum PlotDifficulty { + EASY, + MEDIUM, + HARD +} diff --git a/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotSnapshot.java b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotSnapshot.java new file mode 100644 index 00000000..9117a7ad --- /dev/null +++ b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotSnapshot.java @@ -0,0 +1,21 @@ +package com.alpsbte.plotsystem.api.model; + +import java.time.LocalDate; +import java.util.List; +import java.util.UUID; + +public record PlotSnapshot( + int id, + UUID owner, + PlotStatus status, + PlotType type, + PlotDifficulty difficulty, + String cityProjectId, + String countryCode, + LocalDate lastActivity, + List members +) { + public PlotSnapshot { + members = List.copyOf(members); + } +} diff --git a/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotStatus.java b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotStatus.java new file mode 100644 index 00000000..aca507b1 --- /dev/null +++ b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotStatus.java @@ -0,0 +1,8 @@ +package com.alpsbte.plotsystem.api.model; + +public enum PlotStatus { + UNCLAIMED, + UNFINISHED, + UNREVIEWED, + COMPLETED +} diff --git a/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotType.java b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotType.java new file mode 100644 index 00000000..7f9d6012 --- /dev/null +++ b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/PlotType.java @@ -0,0 +1,8 @@ +package com.alpsbte.plotsystem.api.model; + +public enum PlotType { + FOCUS_MODE, + LOCAL_INSPIRATION_MODE, + CITY_INSPIRATION_MODE, + TUTORIAL +} diff --git a/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/ReviewSnapshot.java b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/ReviewSnapshot.java new file mode 100644 index 00000000..57a55f36 --- /dev/null +++ b/plot-system-api/src/main/java/com/alpsbte/plotsystem/api/model/ReviewSnapshot.java @@ -0,0 +1,12 @@ +package com.alpsbte.plotsystem.api.model; + +import java.util.UUID; + +public record ReviewSnapshot( + int id, + PlotSnapshot plot, + UUID reviewer, + int score, + int splitScore, + String feedback +) {} diff --git a/settings.gradle.kts b/settings.gradle.kts index 22487c71..252c20cd 100644 --- a/settings.gradle.kts +++ b/settings.gradle.kts @@ -1 +1,2 @@ rootProject.name = "PlotSystem" +include(":plot-system-api") diff --git a/src/main/java/com/alpsbte/plotsystem/core/integration/PlotEventSnapshots.java b/src/main/java/com/alpsbte/plotsystem/core/integration/PlotEventSnapshots.java new file mode 100644 index 00000000..4f00b559 --- /dev/null +++ b/src/main/java/com/alpsbte/plotsystem/core/integration/PlotEventSnapshots.java @@ -0,0 +1,53 @@ +package com.alpsbte.plotsystem.core.integration; + +import com.alpsbte.plotsystem.api.model.PlotDifficulty; +import com.alpsbte.plotsystem.api.model.PlotSnapshot; +import com.alpsbte.plotsystem.api.model.PlotStatus; +import com.alpsbte.plotsystem.api.model.PlotType; +import com.alpsbte.plotsystem.api.model.ReviewSnapshot; +import com.alpsbte.plotsystem.core.system.plot.AbstractPlot; +import com.alpsbte.plotsystem.core.system.plot.Plot; +import com.alpsbte.plotsystem.core.system.review.PlotReview; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +public final class PlotEventSnapshots { + private PlotEventSnapshots() {} + + public static @NotNull PlotSnapshot plot(@NotNull AbstractPlot plot) { + if (plot instanceof Plot typedPlot) { + return new PlotSnapshot( + typedPlot.getId(), + typedPlot.getPlotOwner() == null ? null : typedPlot.getPlotOwner().getUUID(), + PlotStatus.valueOf(typedPlot.getStatus().name().toUpperCase()), + PlotType.valueOf(typedPlot.getPlotType().name()), + PlotDifficulty.valueOf(typedPlot.getDifficulty().name()), + typedPlot.getCityProject().getId(), + typedPlot.getCityProject().getCountry().getCode(), + typedPlot.getLastActivity(), + typedPlot.getPlotMembers().stream().map(member -> member.getUUID()).toList()); + } + + return new PlotSnapshot( + plot.getId(), + plot.getPlotOwner() == null ? null : plot.getPlotOwner().getUUID(), + PlotStatus.valueOf(plot.getStatus().name().toUpperCase()), + PlotType.valueOf(plot.getPlotType().name()), + null, + null, + null, + plot.getLastActivity(), + List.of()); + } + + public static @NotNull ReviewSnapshot review(@NotNull PlotReview review) { + return new ReviewSnapshot( + review.getReviewId(), + plot(review.getPlot()), + review.getReviewerUUID(), + review.getScore(), + review.getSplitScore(), + review.getFeedback()); + } +} diff --git a/src/main/java/com/alpsbte/plotsystem/core/menus/review/ReviewPlotTogglesMenu.java b/src/main/java/com/alpsbte/plotsystem/core/menus/review/ReviewPlotTogglesMenu.java index a8a27e59..c67a2251 100644 --- a/src/main/java/com/alpsbte/plotsystem/core/menus/review/ReviewPlotTogglesMenu.java +++ b/src/main/java/com/alpsbte/plotsystem/core/menus/review/ReviewPlotTogglesMenu.java @@ -5,6 +5,7 @@ import com.alpsbte.plotsystem.PlotSystem; import com.alpsbte.plotsystem.api.event.PlotRejectedEvent; import com.alpsbte.plotsystem.api.event.PlotReviewedEvent; +import com.alpsbte.plotsystem.core.integration.PlotEventSnapshots; import com.alpsbte.plotsystem.core.database.DataProvider; import com.alpsbte.plotsystem.core.menus.AbstractMenu; import com.alpsbte.plotsystem.core.system.Builder; @@ -131,11 +132,11 @@ private void submitReview() { if (!isRejected) { reviewerConfirmationMessage = Utils.ChatUtils.getInfoFormat(LangUtil.getInstance().get(getMenuPlayer(), LangPaths.Message.Info.PLOT_MARKED_REVIEWED, Integer.toString(plot.getId()), getParticipantsString())); if (!acceptPlot(review.getScore(), review.getSplitScore())) return; - Bukkit.getPluginManager().callEvent(new PlotReviewedEvent(review)); + Bukkit.getPluginManager().callEvent(new PlotReviewedEvent(PlotEventSnapshots.review(review))); } else { reviewerConfirmationMessage = Utils.ChatUtils.getInfoFormat(LangUtil.getInstance().get(getMenuPlayer(), LangPaths.Message.Info.PLOT_REJECTED, Integer.toString(plot.getId()), getParticipantsString())); PlotHandler.undoSubmit(plot); - Bukkit.getPluginManager().callEvent(new PlotRejectedEvent(review)); + Bukkit.getPluginManager().callEvent(new PlotRejectedEvent(PlotEventSnapshots.review(review))); } Bukkit.getScheduler().runTask(PlotSystem.getPlugin(), () -> { diff --git a/src/main/java/com/alpsbte/plotsystem/core/system/plot/PlotHandler.java b/src/main/java/com/alpsbte/plotsystem/core/system/plot/PlotHandler.java index 62ca6b2d..5fafe845 100644 --- a/src/main/java/com/alpsbte/plotsystem/core/system/plot/PlotHandler.java +++ b/src/main/java/com/alpsbte/plotsystem/core/system/plot/PlotHandler.java @@ -5,6 +5,8 @@ import com.alpsbte.plotsystem.api.event.PlotCreatedEvent; import com.alpsbte.plotsystem.api.event.PlotSubmissionUndoneEvent; import com.alpsbte.plotsystem.api.event.PlotSubmittedEvent; +import com.alpsbte.plotsystem.api.model.PlotAbandonReason; +import com.alpsbte.plotsystem.core.integration.PlotEventSnapshots; import com.alpsbte.plotsystem.core.database.DataProvider; import com.alpsbte.plotsystem.core.system.Builder; import com.alpsbte.plotsystem.core.system.CityProject; @@ -138,7 +140,7 @@ public static boolean generatePlot(Builder builder, Plot plot, PlotType type) { DefaultPlotLoader loader = new DefaultPlotLoader(plot, builder, type, PlotWorld.getByType(type, plot)); if (loader.isSuccessful()) { - Bukkit.getPluginManager().callEvent(new PlotCreatedEvent(plot)); + Bukkit.getPluginManager().callEvent(new PlotCreatedEvent(PlotEventSnapshots.plot(plot))); } return loader.isSuccessful(); } @@ -164,10 +166,10 @@ private static boolean tryStartGeneration(Builder builder) { @SuppressWarnings("BooleanMethodIsAlwaysInverted") public static boolean abandonPlot(AbstractPlot plot) { - return abandonPlot(plot, PlotAbandonedEvent.Reason.MANUAL); + return abandonPlot(plot, PlotAbandonReason.MANUAL); } - public static boolean abandonPlot(AbstractPlot plot, PlotAbandonedEvent.Reason reason) { + public static boolean abandonPlot(AbstractPlot plot, PlotAbandonReason reason) { try { boolean successfullyAbandoned = plot.getWorld().onAbandon(); if (!successfullyAbandoned) { @@ -204,13 +206,13 @@ public static boolean abandonPlot(AbstractPlot plot, PlotAbandonedEvent.Reason r PlotSystem.getPlugin().getComponentLogger().error(text("Failed to abandon plot with the ID " + plot.getId() + "!")); } if (successful) { - Bukkit.getPluginManager().callEvent(new PlotAbandonedEvent(plot, reason)); + Bukkit.getPluginManager().callEvent(new PlotAbandonedEvent(PlotEventSnapshots.plot(plot), reason)); } return successful; } public static boolean deletePlot(Plot plot) { - if (!abandonPlot(plot, PlotAbandonedEvent.Reason.INACTIVITY)) { + if (!abandonPlot(plot, PlotAbandonReason.INACTIVITY)) { PlotSystem.getPlugin().getComponentLogger().warn(text("Failed to delete plot with the ID " + plot.getId() + "!")); return false; } @@ -231,7 +233,7 @@ public static void abandonInactivePlots() { if (interval == -2 || lastActivity == null || lastActivity.plusDays(interval).isAfter(LocalDate.now())) continue; CompletableFuture.runAsync(() -> { - if (!abandonPlot(plot, PlotAbandonedEvent.Reason.COMMAND)) { + if (!abandonPlot(plot, PlotAbandonReason.COMMAND)) { PlotSystem.getPlugin().getComponentLogger().warn(text("An error occurred while abandoning plot #" + plot.getId() + " due to inactivity!")); return; } @@ -255,7 +257,7 @@ public static void submitPlot(@NotNull Plot plot) { plot.getPermissions().removeBuilderPerms(builder.getUUID()); } } - Bukkit.getPluginManager().callEvent(new PlotSubmittedEvent(plot)); + Bukkit.getPluginManager().callEvent(new PlotSubmittedEvent(PlotEventSnapshots.plot(plot))); } public static void undoSubmit(@NotNull Plot plot) { @@ -267,7 +269,7 @@ public static void undoSubmit(@NotNull Plot plot) { plot.getPermissions().addBuilderPerms(builder.getUUID()); } } - Bukkit.getPluginManager().callEvent(new PlotSubmissionUndoneEvent(plot)); + Bukkit.getPluginManager().callEvent(new PlotSubmissionUndoneEvent(PlotEventSnapshots.plot(plot))); } public static void removePlayerFromGenerationHistory(UUID playerUuid) { diff --git a/src/main/java/com/alpsbte/plotsystem/core/system/plot/generator/loader/AbstractPlotLoader.java b/src/main/java/com/alpsbte/plotsystem/core/system/plot/generator/loader/AbstractPlotLoader.java index 5914ffe1..5bbb963a 100644 --- a/src/main/java/com/alpsbte/plotsystem/core/system/plot/generator/loader/AbstractPlotLoader.java +++ b/src/main/java/com/alpsbte/plotsystem/core/system/plot/generator/loader/AbstractPlotLoader.java @@ -347,7 +347,7 @@ public static void pasteSchematic(boolean ignoreAir, byte[] schematicFile, @NotN protected void onException(Exception e) { if (abandonOnFailure) { try { - if (!PlotHandler.abandonPlot(this.plot, com.alpsbte.plotsystem.api.event.PlotAbandonedEvent.Reason.SYSTEM)) { + if (!PlotHandler.abandonPlot(this.plot, com.alpsbte.plotsystem.api.model.PlotAbandonReason.SYSTEM)) { PlotSystem.getPlugin().getComponentLogger().error("Failed to clean up plot #{} after generation error!", plot.getId()); } } catch (Exception ex) { diff --git a/src/main/java/com/alpsbte/plotsystem/core/system/review/PlotReview.java b/src/main/java/com/alpsbte/plotsystem/core/system/review/PlotReview.java index 682cbeeb..112b6acd 100644 --- a/src/main/java/com/alpsbte/plotsystem/core/system/review/PlotReview.java +++ b/src/main/java/com/alpsbte/plotsystem/core/system/review/PlotReview.java @@ -3,6 +3,7 @@ import com.alpsbte.plotsystem.PlotSystem; import com.alpsbte.plotsystem.api.event.PlotFeedbackUpdatedEvent; import com.alpsbte.plotsystem.api.event.PlotReviewUndoneEvent; +import com.alpsbte.plotsystem.core.integration.PlotEventSnapshots; import com.alpsbte.plotsystem.core.database.DataProvider; import com.alpsbte.plotsystem.core.system.Builder; import com.alpsbte.plotsystem.core.system.plot.Plot; @@ -69,7 +70,7 @@ public UUID getReviewerUUID() { public boolean updateFeedback(String feedback) { if (DataProvider.REVIEW.updateFeedback(reviewId, feedback)) { this.feedback = feedback; - PlotSystem.getPlugin().getServer().getPluginManager().callEvent(new PlotFeedbackUpdatedEvent(this)); + PlotSystem.getPlugin().getServer().getPluginManager().callEvent(new PlotFeedbackUpdatedEvent(PlotEventSnapshots.review(this))); return true; } return false; @@ -103,7 +104,7 @@ public boolean undoReview() { } if (successful) { - PlotSystem.getPlugin().getServer().getPluginManager().callEvent(new PlotReviewUndoneEvent(this)); + PlotSystem.getPlugin().getServer().getPluginManager().callEvent(new PlotReviewUndoneEvent(PlotEventSnapshots.review(this))); } return successful; } From 2664d3f3fd0610f06117fb80d18721c4ff4322dd Mon Sep 17 00:00:00 2001 From: Zoriot Date: Sun, 27 Sep 2026 02:03:13 +0200 Subject: [PATCH 3/3] fix: complete plot lifecycle event semantics Capture pre-abandonment snapshots, publish tutorial and inactivity events, and use distinct abandonment reasons. --- .../core/system/plot/PlotHandler.java | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/alpsbte/plotsystem/core/system/plot/PlotHandler.java b/src/main/java/com/alpsbte/plotsystem/core/system/plot/PlotHandler.java index 5fafe845..ca5cf61e 100644 --- a/src/main/java/com/alpsbte/plotsystem/core/system/plot/PlotHandler.java +++ b/src/main/java/com/alpsbte/plotsystem/core/system/plot/PlotHandler.java @@ -3,6 +3,7 @@ import com.alpsbte.plotsystem.PlotSystem; import com.alpsbte.plotsystem.api.event.PlotAbandonedEvent; import com.alpsbte.plotsystem.api.event.PlotCreatedEvent; +import com.alpsbte.plotsystem.api.event.PlotInactivityWarningEvent; import com.alpsbte.plotsystem.api.event.PlotSubmissionUndoneEvent; import com.alpsbte.plotsystem.api.event.PlotSubmittedEvent; import com.alpsbte.plotsystem.api.model.PlotAbandonReason; @@ -140,7 +141,7 @@ public static boolean generatePlot(Builder builder, Plot plot, PlotType type) { DefaultPlotLoader loader = new DefaultPlotLoader(plot, builder, type, PlotWorld.getByType(type, plot)); if (loader.isSuccessful()) { - Bukkit.getPluginManager().callEvent(new PlotCreatedEvent(PlotEventSnapshots.plot(plot))); + publishEvent(new PlotCreatedEvent(PlotEventSnapshots.plot(plot))); } return loader.isSuccessful(); } @@ -170,6 +171,7 @@ public static boolean abandonPlot(AbstractPlot plot) { } public static boolean abandonPlot(AbstractPlot plot, PlotAbandonReason reason) { + var snapshot = PlotEventSnapshots.plot(plot); try { boolean successfullyAbandoned = plot.getWorld().onAbandon(); if (!successfullyAbandoned) { @@ -181,7 +183,10 @@ public static boolean abandonPlot(AbstractPlot plot, PlotAbandonReason reason) { return false; } - if (plot.getPlotType() == PlotType.TUTORIAL) return true; + if (plot.getPlotType() == PlotType.TUTORIAL) { + publishEvent(new PlotAbandonedEvent(snapshot, reason)); + return true; + } Plot dPlot = (Plot) plot; boolean successful = DataProvider.REVIEW.removeAllReviewsOfPlot(dPlot.getId()); @@ -206,13 +211,13 @@ public static boolean abandonPlot(AbstractPlot plot, PlotAbandonReason reason) { PlotSystem.getPlugin().getComponentLogger().error(text("Failed to abandon plot with the ID " + plot.getId() + "!")); } if (successful) { - Bukkit.getPluginManager().callEvent(new PlotAbandonedEvent(PlotEventSnapshots.plot(plot), reason)); + publishEvent(new PlotAbandonedEvent(snapshot, reason)); } return successful; } public static boolean deletePlot(Plot plot) { - if (!abandonPlot(plot, PlotAbandonReason.INACTIVITY)) { + if (!abandonPlot(plot, PlotAbandonReason.COMMAND)) { PlotSystem.getPlugin().getComponentLogger().warn(text("Failed to delete plot with the ID " + plot.getId() + "!")); return false; } @@ -232,8 +237,11 @@ public static void abandonInactivePlots() { long interval = plot.isRejected() ? rejectedInactivityIntervalDays : inactivityIntervalDays; if (interval == -2 || lastActivity == null || lastActivity.plusDays(interval).isAfter(LocalDate.now())) continue; + publishEvent(new PlotInactivityWarningEvent( + PlotEventSnapshots.plot(plot), + lastActivity.plusDays(interval))); CompletableFuture.runAsync(() -> { - if (!abandonPlot(plot, PlotAbandonReason.COMMAND)) { + if (!abandonPlot(plot, PlotAbandonReason.INACTIVITY)) { PlotSystem.getPlugin().getComponentLogger().warn(text("An error occurred while abandoning plot #" + plot.getId() + " due to inactivity!")); return; } @@ -242,6 +250,13 @@ public static void abandonInactivePlots() { } } + private static void publishEvent(org.bukkit.event.Event event) { + Utils.runSync(() -> { + Bukkit.getPluginManager().callEvent(event); + return null; + }); + } + public static void submitPlot(@NotNull Plot plot) { plot.setStatus(Status.unreviewed); @@ -257,7 +272,7 @@ public static void submitPlot(@NotNull Plot plot) { plot.getPermissions().removeBuilderPerms(builder.getUUID()); } } - Bukkit.getPluginManager().callEvent(new PlotSubmittedEvent(PlotEventSnapshots.plot(plot))); + publishEvent(new PlotSubmittedEvent(PlotEventSnapshots.plot(plot))); } public static void undoSubmit(@NotNull Plot plot) { @@ -269,7 +284,7 @@ public static void undoSubmit(@NotNull Plot plot) { plot.getPermissions().addBuilderPerms(builder.getUUID()); } } - Bukkit.getPluginManager().callEvent(new PlotSubmissionUndoneEvent(PlotEventSnapshots.plot(plot))); + publishEvent(new PlotSubmissionUndoneEvent(PlotEventSnapshots.plot(plot))); } public static void removePlayerFromGenerationHistory(UUID playerUuid) {