Skip to content
Open
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
12 changes: 12 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,11 @@
<id>dmulloy2-repo</id>
<url>https://repo.dmulloy2.net/repository/public/</url>
</repository>
<!-- Maven Central for Discord Plot-System API -->
<repository>
<id>sonatype</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
</repository>
</repositories>

<dependencies>
Expand Down Expand Up @@ -132,6 +137,13 @@
<version>2.8.12</version>
<scope>provided</scope>
</dependency>
<!-- Discord Integration -->
<dependency>
<groupId>asia.buildtheearth.asean.discord</groupId>
<artifactId>discord-plotsystem-api</artifactId>
<version>1.2.3</version>
<scope>provided</scope>
</dependency>
<!-- Alps Utils -->
<dependency>
<groupId>com.alpsbte.alpslib</groupId>
Expand Down
16 changes: 15 additions & 1 deletion src/main/java/com/alpsbte/plotsystem/PlotSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import com.alpsbte.plotsystem.core.system.tutorial.TutorialEventListener;
import com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialNPCTurnTracker;
import com.alpsbte.plotsystem.core.system.tutorial.utils.TutorialUtils;
import com.alpsbte.plotsystem.utils.DiscordUtil;
import com.alpsbte.plotsystem.utils.PacketListener;
import com.alpsbte.plotsystem.utils.Utils;
import com.alpsbte.plotsystem.utils.io.ConfigPaths;
Expand All @@ -61,6 +62,7 @@
import org.bukkit.plugin.java.JavaPlugin;
import org.ipvp.canvas.MenuFunctionListener;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -208,6 +210,12 @@ public void onEnable() {
Bukkit.getScheduler().runTaskTimerAsynchronously(FancyNpcsPlugin.get().getPlugin(), new TutorialNPCTurnTracker(), 0, 1L);
}

// Register discord Integration
org.bukkit.plugin.Plugin discordPlugin = PlotSystem.DependencyManager.getDiscordPlotSystemPlugin();
if(discordPlugin != null) {
DiscordUtil.init(discordPlugin);
}

pluginEnabled = true;
Bukkit.getConsoleSender().sendMessage(empty());
Bukkit.getConsoleSender().sendMessage(text("Enabled Plot-System plugin.", DARK_GREEN));
Expand Down Expand Up @@ -335,6 +343,10 @@ public static boolean isWorldGuardExtraFlagsEnabled() {
return plugin.getServer().getPluginManager().isPluginEnabled("WorldGuardExtraFlags");
}

public static @Nullable org.bukkit.plugin.Plugin getDiscordPlotSystemPlugin() {
return plugin.getServer().getPluginManager().getPlugin("DiscordPlotSystem");
}

/**
* @param worldName Name of the world
* @return Config path for the world
Expand Down Expand Up @@ -375,7 +387,9 @@ public static String getWorldGuardConfigPath(String worldName) {
/**
* @return Protocol Lib Instance
*/
public static ProtocolManager getProtocolManager() {return ProtocolLibrary.getProtocolManager();}
public static ProtocolManager getProtocolManager() {
return ProtocolLibrary.getProtocolManager();
}
}

public static class UpdateChecker {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.alpsbte.plotsystem.core.system.plot.AbstractPlot;
import com.alpsbte.plotsystem.core.system.plot.Plot;
import com.alpsbte.plotsystem.core.system.plot.utils.PlotUtils;
import com.alpsbte.plotsystem.utils.DiscordUtil;
import com.alpsbte.plotsystem.utils.Utils;
import com.alpsbte.plotsystem.utils.enums.Status;
import com.alpsbte.plotsystem.utils.io.LangPaths;
Expand Down Expand Up @@ -77,7 +78,7 @@ public void onCommand(CommandSender sender, String[] args) {
}

if (Objects.requireNonNull(plot).getStatus() == Status.unfinished) {
if (Utils.isOwnerOrReviewer(sender, player, plot) && PlotUtils.Actions.abandonPlot(plot)) {
if (Utils.isOwnerOrReviewer(sender, player, plot) && PlotUtils.Actions.abandonPlot(plot, DiscordUtil.AbandonType.MANUALLY)) {
sender.sendMessage(Utils.ChatUtils.getInfoFormat(langUtil.get(sender, LangPaths.Message.Info.ABANDONED_PLOT, plot.getID() + "")));
if (player != null) player.playSound(player.getLocation(), Utils.SoundUtils.ABANDON_PLOT_SOUND, 1, 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.alpsbte.plotsystem.core.system.plot.AbstractPlot;
import com.alpsbte.plotsystem.core.system.plot.Plot;
import com.alpsbte.plotsystem.core.system.plot.utils.PlotUtils;
import com.alpsbte.plotsystem.utils.DiscordUtil;
import com.alpsbte.plotsystem.utils.Utils;
import com.alpsbte.plotsystem.utils.enums.Status;
import com.alpsbte.plotsystem.utils.io.LangPaths;
Expand Down Expand Up @@ -79,6 +80,8 @@ public void onCommand(CommandSender sender, String[] args) {
if (Objects.requireNonNull(plot).getStatus() == Status.unreviewed) {
if (Utils.isOwnerOrReviewer(sender, player, plot)) {
PlotUtils.Actions.undoSubmit(plot);
DiscordUtil.getOpt(plot.getID()).ifPresent(DiscordUtil.PlotEventAction::onPlotUndoSubmit);

sender.sendMessage(Utils.ChatUtils.getInfoFormat(langUtil.get(sender, LangPaths.Message.Info.UNDID_SUBMISSION, plot.getID() + "")));
if (player != null) player.playSound(player.getLocation(), Utils.SoundUtils.FINISH_PLOT_SOUND, 1, 1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.alpsbte.plotsystem.core.system.Review;
import com.alpsbte.plotsystem.core.system.plot.Plot;
import com.alpsbte.plotsystem.core.system.plot.utils.PlotUtils;
import com.alpsbte.plotsystem.utils.DiscordUtil;
import com.alpsbte.plotsystem.utils.Utils;
import com.alpsbte.plotsystem.utils.io.LangPaths;
import com.alpsbte.plotsystem.utils.io.LangUtil;
Expand Down Expand Up @@ -72,6 +73,8 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
return true;
}

DiscordUtil.getOpt(plot.getID()).ifPresent(DiscordUtil.PlotEventAction::onPlotUndoReview);

Review.undoReview(plot.getReview());
sender.sendMessage(Utils.ChatUtils.getInfoFormat(LangUtil.getInstance().get(sender, LangPaths.Message.Info.UNDID_REVIEW, plot.getID() + "", plot.getPlotOwner().getName())));
} catch (SQLException ex) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.alpsbte.plotsystem.core.system.Review;
import com.alpsbte.plotsystem.core.system.plot.Plot;
import com.alpsbte.plotsystem.core.system.plot.utils.PlotUtils;
import com.alpsbte.plotsystem.utils.DiscordUtil;
import com.alpsbte.plotsystem.utils.Utils;
import com.alpsbte.plotsystem.utils.chat.ChatInput;
import com.alpsbte.plotsystem.utils.chat.PlayerFeedbackChatInput;
Expand Down Expand Up @@ -225,6 +226,8 @@ protected void setItemClickEventsAsync() {
plot.getReview().setFeedback("No Feedback");
plot.getPlotOwner().addCompletedBuild(1);

DiscordUtil.getOpt(plot.getID()).ifPresent(DiscordUtil.PlotEventAction::onPlotApprove);

// Remove Plot from Owner
plot.getPlotOwner().removePlot(plot.getSlot());

Expand Down Expand Up @@ -272,6 +275,8 @@ protected void setItemClickEventsAsync() {
reviewerConfirmationMessage = Utils.ChatUtils.getInfoFormat(LangUtil.getInstance().get(getMenuPlayer(), LangPaths.Message.Info.PLOT_REJECTED, Integer.toString(plot.getID()), sb.toString()));
}

DiscordUtil.getOpt(plot.getID()).ifPresent(DiscordUtil.PlotEventAction::onPlotReject);

PlotUtils.Actions.undoSubmit(plot);
}

Expand Down
7 changes: 7 additions & 0 deletions src/main/java/com/alpsbte/plotsystem/core/system/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.alpsbte.plotsystem.PlotSystem;
import com.alpsbte.plotsystem.core.database.DatabaseConnection;
import com.alpsbte.plotsystem.core.system.plot.Plot;
import com.alpsbte.plotsystem.utils.DiscordUtil;
import com.alpsbte.plotsystem.utils.enums.Category;
import com.alpsbte.plotsystem.utils.enums.Status;
import com.alpsbte.plotsystem.utils.io.FTPManager;
Expand All @@ -45,13 +46,16 @@

public class Review {
private final int reviewID;
private final Integer plotID;

public Review(int reviewID) {
this.reviewID = reviewID;
this.plotID = null;
}

public Review(int plotID, UUID reviewer, String rating) throws SQLException {
this.reviewID = DatabaseConnection.getTableID("plotsystem_reviews");
this.plotID = plotID;

DatabaseConnection.createStatement("INSERT INTO plotsystem_reviews (id, reviewer_uuid, rating, review_date, feedback) VALUES (?, ?, ?, ?, ?)")
.setValue(this.reviewID)
Expand Down Expand Up @@ -173,6 +177,9 @@ public void setRating(String ratingFormat) throws SQLException {
public void setFeedback(String feedback) throws SQLException {
DatabaseConnection.createStatement("UPDATE plotsystem_reviews SET feedback = ? WHERE id = ?")
.setValue(feedback).setValue(this.reviewID).executeUpdate();

DiscordUtil.getOpt(this.plotID == null? this.getPlotID() : this.plotID)
.ifPresent(event -> event.onPlotFeedback(feedback));
}

public void setFeedbackSent(boolean isSent) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.alpsbte.plotsystem.core.system.plot.world.CityPlotWorld;
import com.alpsbte.plotsystem.core.system.plot.world.OnePlotWorld;
import com.alpsbte.plotsystem.core.system.plot.world.PlotWorld;
import com.alpsbte.plotsystem.utils.DiscordUtil;
import com.alpsbte.plotsystem.utils.Utils;
import com.alpsbte.plotsystem.utils.io.ConfigPaths;
import com.alpsbte.plotsystem.utils.io.ConfigUtil;
Expand Down Expand Up @@ -142,7 +143,7 @@ private AbstractPlotGenerator(@NotNull AbstractPlot plot, @NotNull Builder build
}

if (exception != null) {
PlotUtils.Actions.abandonPlot(plot);
PlotUtils.Actions.abandonPlot(plot, DiscordUtil.AbandonType.SYSTEM);
onException(exception);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.alpsbte.plotsystem.core.system.plot.utils.PlotType;
import com.alpsbte.plotsystem.core.system.plot.utils.PlotUtils;
import com.alpsbte.plotsystem.core.system.plot.world.PlotWorld;
import com.alpsbte.plotsystem.utils.DiscordUtil;
import com.alpsbte.plotsystem.utils.Utils;
import com.alpsbte.plotsystem.utils.enums.PlotDifficulty;
import com.alpsbte.plotsystem.utils.enums.Status;
Expand Down Expand Up @@ -133,6 +134,9 @@ protected void onComplete(boolean failed, boolean unloadWorld) throws SQLExcepti

plot.getWorld().teleportPlayer(getBuilder().getPlayer());
LangUtil.getInstance().broadcast(LangPaths.Message.Info.CREATED_NEW_PLOT, plot.getPlotOwner().getName());

// Create the plot to discord forum
DiscordUtil.getOpt(plot.getID()).ifPresent(event -> event.onPlotCreate(this.plot));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.alpsbte.plotsystem.core.system.plot.world.CityPlotWorld;
import com.alpsbte.plotsystem.core.system.plot.world.OnePlotWorld;
import com.alpsbte.plotsystem.core.system.plot.world.PlotWorld;
import com.alpsbte.plotsystem.utils.DiscordUtil;
import com.alpsbte.plotsystem.utils.ShortLink;
import com.alpsbte.plotsystem.utils.Utils;
import com.alpsbte.plotsystem.utils.enums.Status;
Expand Down Expand Up @@ -86,6 +87,10 @@
import java.sql.ResultSet;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionException;
Expand Down Expand Up @@ -313,18 +318,43 @@ public static void checkPlotsForLastActivity() {
try {
List<Plot> plots = Plot.getPlots(Status.unfinished);
FileConfiguration config = PlotSystem.getPlugin().getConfig();
long millisInDays = config.getLong(ConfigPaths.INACTIVITY_INTERVAL) * 24 * 60 * 60 * 1000; // Remove all plots which have no activity for the last x days
long inactivityIntervalDays = config.getLong(ConfigPaths.INACTIVITY_INTERVAL, -2);
int inactivityNotificationDays = config.getInt(ConfigPaths.INACTIVITY_NOTIFICATION_DAYS, 0);
int inactivityNotificationTime = config.getInt(ConfigPaths.INACTIVITY_NOTIFICATION_TIME, 16);
if (inactivityIntervalDays == -2) return;

// Determine if the current time is within the notification window.
// Run within a ±minute window around a set local time.
LocalTime now = LocalTime.now();
LocalTime start = LocalTime.of(inactivityNotificationTime, 0).minusMinutes(30);
LocalTime end = LocalTime.of(inactivityNotificationTime, 0).plusMinutes(30);
boolean inNotificationWindow = inactivityNotificationDays > 0 && !now.isBefore(start) && !now.isAfter(end);;

for (Plot plot : plots) {
if (plot.getLastActivity() != null && plot.getLastActivity().getTime() < (new Date().getTime() - millisInDays)) {
Bukkit.getScheduler().runTask(PlotSystem.getPlugin(), () -> {
if (Actions.abandonPlot(plot)) {
PlotSystem.getPlugin().getComponentLogger().info(text("Abandoned plot #" + plot.getID() + " due to inactivity!"));
} else {
PlotSystem.getPlugin().getComponentLogger().warn(text("An error occurred while abandoning plot #" + plot.getID() + " due to inactivity!"));
}
});
LocalDate lastActivity = switch (plot.getLastActivity()) {
case java.sql.Date date -> date.toLocalDate();
case java.util.Date date -> date.toInstant().atZone(ZoneId.systemDefault()).toLocalDate();
};

if(lastActivity == null) continue;

LocalDate abandonDate = lastActivity.plusDays(inactivityIntervalDays);

// Check if today is within X days before the plot's abandon date
if(inNotificationWindow && LocalDate.now().isAfter(abandonDate.minusDays(inactivityNotificationDays))) {
// Notify the plot's owner on discord
DiscordUtil.getOpt(plot.getID()).ifPresent(event -> event.onPlotInactivity(abandonDate));
}

if(abandonDate.isAfter(LocalDate.now())) continue;

Bukkit.getScheduler().runTask(PlotSystem.getPlugin(), () -> {
if (Actions.abandonPlot(plot, DiscordUtil.AbandonType.INACTIVE)) {
PlotSystem.getPlugin().getComponentLogger().info(text("Abandoned plot #" + plot.getID() + " due to inactivity!"));
} else {
PlotSystem.getPlugin().getComponentLogger().warn(text("An error occurred while abandoning plot #" + plot.getID() + " due to inactivity!"));
}
});
}
} catch (SQLException ex) {
Utils.logSqlException(ex);
Expand Down Expand Up @@ -384,6 +414,8 @@ public static void submitPlot(@NotNull Plot plot) throws SQLException {
plot.getPermissions().removeBuilderPerms(builder.getUUID());
}
}

DiscordUtil.getOpt(plot.getID()).ifPresent(DiscordUtil.PlotEventAction::onPlotSubmit);
}

public static void undoSubmit(@NotNull Plot plot) throws SQLException {
Expand All @@ -397,7 +429,7 @@ public static void undoSubmit(@NotNull Plot plot) throws SQLException {
}
}

public static boolean abandonPlot(@NotNull AbstractPlot plot) {
public static boolean abandonPlot(@NotNull AbstractPlot plot, @NotNull DiscordUtil.AbandonType type) {
try {
if (plot.getWorld() instanceof OnePlotWorld) {
if (plot.getWorld().isWorldGenerated()) {
Expand Down Expand Up @@ -431,6 +463,8 @@ public static boolean abandonPlot(@NotNull AbstractPlot plot) {
if (plot.getWorld().isWorldLoaded()) plot.getWorld().unloadWorld(false);
}
}
// Send to discord
DiscordUtil.getOpt(plot.getID()).ifPresent(event -> event.onPlotAbandon(type));
} catch (SQLException | IOException | WorldEditException ex) {
PlotSystem.getPlugin().getComponentLogger().error(text("Failed to abandon plot with the ID " + plot.getID() + "!"), ex);
return false;
Expand Down Expand Up @@ -478,7 +512,7 @@ private static boolean updateDatabase(@NotNull AbstractPlot plot) {
}

public static boolean deletePlot(Plot plot) {
if (abandonPlot(plot)) {
if (abandonPlot(plot, DiscordUtil.AbandonType.COMMANDS)) {
try {
CompletableFuture.runAsync(() -> {
try {
Expand Down
Loading