Skip to content

Commit

Permalink
fix issue with deleting finished schematic files after undoing review
Browse files Browse the repository at this point in the history
  • Loading branch information
LordTuxn committed Jan 16, 2022
1 parent 76f53df commit 68ea3f2
Showing 1 changed file with 28 additions and 24 deletions.
52 changes: 28 additions & 24 deletions src/main/java/com/alpsbte/plotsystem/core/system/Review.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,36 +197,40 @@ public static void undoReview(Review review) throws SQLException {
try {
Plot plot = new Plot(review.getPlotID());

for (Builder member : plot.getPlotMembers()) {
member.addScore(-plot.getSharedScore());
member.addCompletedBuild(-1);

if (member.getFreeSlot() != null) {
member.setPlot(plot.getID(), member.getFreeSlot());
if (plot.getWorld().loadWorld()) {
for (Builder member : plot.getPlotMembers()) {
member.addScore(-plot.getSharedScore());
member.addCompletedBuild(-1);

if (member.getFreeSlot() != null) {
member.setPlot(plot.getID(), member.getFreeSlot());
}
}
}

plot.getPlotOwner().addScore(-plot.getSharedScore());
plot.getPlotOwner().addCompletedBuild(-1);
plot.setTotalScore(-1);
plot.setStatus(Status.unreviewed);
plot.setPasted(false);
plot.getPlotOwner().addScore(-plot.getSharedScore());
plot.getPlotOwner().addCompletedBuild(-1);
plot.setTotalScore(-1);
plot.setStatus(Status.unreviewed);
plot.setPasted(false);

if (plot.getPlotOwner().getFreeSlot() != null) {
plot.getPlotOwner().setPlot(plot.getID(), plot.getPlotOwner().getFreeSlot());
}
if (plot.getPlotOwner().getFreeSlot() != null) {
plot.getPlotOwner().setPlot(plot.getID(), plot.getPlotOwner().getFreeSlot());
}

Files.deleteIfExists(Paths.get(PlotManager.getDefaultSchematicPath(), String.valueOf(plot.getCity().getCountry().getServer().getID()), "finishedSchematics", String.valueOf(plot.getCity().getID()), plot.getID() + ".schematic"));
Server plotServer = plot.getCity().getCountry().getServer();
if (plotServer.getFTPConfiguration() != null) {
FTPManager.deleteSchematics(FTPManager.getFTPUrl(plotServer, plot.getCity().getID()), plot.getID() + ".schematic", true);
}
Files.deleteIfExists(Paths.get(PlotManager.getDefaultSchematicPath(), String.valueOf(plot.getCity().getCountry().getServer().getID()), "finishedSchematics", String.valueOf(plot.getCity().getID()), plot.getID() + ".schematic"));
Server plotServer = plot.getCity().getCountry().getServer();
if (plotServer.getFTPConfiguration() != null) {
FTPManager.deleteSchematics(FTPManager.getFTPUrl(plotServer, plot.getCity().getID()), plot.getID() + ".schematic", true);
}

DatabaseConnection.createStatement("UPDATE plotsystem_plots SET review_id = DEFAULT(review_id) WHERE id = ?")
.setValue(review.getPlotID()).executeUpdate();
DatabaseConnection.createStatement("UPDATE plotsystem_plots SET review_id = DEFAULT(review_id) WHERE id = ?")
.setValue(review.getPlotID()).executeUpdate();

DatabaseConnection.createStatement("DELETE FROM plotsystem_reviews WHERE id = ?")
.setValue(review.reviewID).executeUpdate();
DatabaseConnection.createStatement("DELETE FROM plotsystem_reviews WHERE id = ?")
.setValue(review.reviewID).executeUpdate();

plot.getWorld().unloadWorld(false);
}
} catch (SQLException | IOException | URISyntaxException ex) {
Bukkit.getLogger().log(Level.SEVERE, "An error occurred while undoing review!", ex);
}
Expand Down

0 comments on commit 68ea3f2

Please sign in to comment.