Skip to content

Commit

Permalink
Merge pull request #50 from AlpsBTE/47-plot-generator-rework
Browse files Browse the repository at this point in the history
Plot Generator Rework
  • Loading branch information
LordTuxn authored Oct 3, 2021
2 parents d03a472 + 712a90e commit 1244f17
Show file tree
Hide file tree
Showing 8 changed files with 509 additions and 278 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@
import com.alpsbte.plotsystem.commands.BaseCommand;
import com.alpsbte.plotsystem.commands.ICommand;
import com.alpsbte.plotsystem.commands.SubCommand;
import com.alpsbte.plotsystem.core.system.Builder;
import com.alpsbte.plotsystem.core.system.plot.Plot;
import com.alpsbte.plotsystem.core.system.plot.PlotHandler;
import com.alpsbte.plotsystem.core.system.plot.PlotManager;
import com.alpsbte.plotsystem.core.system.plot.generator.DefaultPlotGenerator;
import com.alpsbte.plotsystem.utils.Utils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
Expand All @@ -53,9 +55,7 @@ public void onCommand(CommandSender sender, String[] args) {
if (PlotManager.plotExists(plotID)) {
PlotHandler.teleportPlayer(new Plot(plotID), getPlayer(sender));
} else if (sender.hasPermission("plotsystem.admin")) {
// new PlotGenerator(new Plot(plotID), new Builder(getPlayer(sender).getUniqueId()));
// TODO: Unfinished feature / Waiting for PlotGenerator rework
// Currently there are no queries, which can lead to errors.
new DefaultPlotGenerator(new Plot(plotID), new Builder(getPlayer(sender).getUniqueId()));
} else {
sender.sendMessage(Utils.getErrorMessageFormat("This plot does not exist!"));
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/alpsbte/plotsystem/core/EventListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@

import com.alpsbte.plotsystem.PlotSystem;
import com.alpsbte.plotsystem.core.config.ConfigPaths;
import com.alpsbte.plotsystem.core.system.plot.PlotGenerator;
import com.alpsbte.plotsystem.core.system.plot.PlotManager;
import com.alpsbte.plotsystem.core.menus.CompanionMenu;
import com.alpsbte.plotsystem.core.menus.ReviewMenu;
import com.alpsbte.plotsystem.core.database.DatabaseConnection;
import com.alpsbte.plotsystem.core.system.plot.Plot;
import com.alpsbte.plotsystem.core.system.plot.PlotHandler;
import com.alpsbte.plotsystem.core.system.Builder;
import com.alpsbte.plotsystem.core.system.plot.generator.DefaultPlotGenerator;
import com.alpsbte.plotsystem.utils.items.SpecialBlocks;
import com.alpsbte.plotsystem.utils.Utils;
import com.alpsbte.plotsystem.utils.enums.Status;
Expand Down Expand Up @@ -208,7 +208,7 @@ public void onPlayerQuitEvent(PlayerQuitEvent event) throws SQLException {
if(PlotManager.isPlotWorld(event.getPlayer().getWorld())) {
PlotHandler.unloadPlot(PlotManager.getPlotByWorld(event.getPlayer().getWorld()));
}
PlotGenerator.playerPlotGenerationHistory.remove(event.getPlayer().getUniqueId());
DefaultPlotGenerator.playerPlotGenerationHistory.remove(event.getPlayer().getUniqueId());
}

@EventHandler
Expand Down
49 changes: 11 additions & 38 deletions src/main/java/com/alpsbte/plotsystem/core/menus/CompanionMenu.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import com.alpsbte.plotsystem.core.system.Builder;
import com.alpsbte.plotsystem.core.system.CityProject;
import com.alpsbte.plotsystem.core.system.plot.Plot;
import com.alpsbte.plotsystem.core.system.plot.PlotGenerator;
import com.alpsbte.plotsystem.core.system.plot.PlotManager;
import com.alpsbte.plotsystem.core.config.ConfigPaths;
import com.alpsbte.plotsystem.core.system.plot.generator.DefaultPlotGenerator;
import com.alpsbte.plotsystem.utils.Utils;
import com.alpsbte.plotsystem.utils.enums.PlotDifficulty;
import com.alpsbte.plotsystem.utils.enums.Slot;
Expand All @@ -46,7 +46,6 @@
import org.ipvp.canvas.mask.Mask;

import java.sql.SQLException;
import java.time.LocalDateTime;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.logging.Level;
Expand Down Expand Up @@ -172,49 +171,23 @@ protected void setItemClickEventsAsync() {
Builder builder = new Builder(clickPlayer.getUniqueId());
int cityID = cityProjects.get(itemSlot).getID();

if (builder.getFreeSlot() != null) {
PlotDifficulty plotDifficultyForCity = selectedPlotDifficulty != null ? selectedPlotDifficulty : PlotManager.getPlotDifficultyForBuilder(cityID, builder).get();
if (PlotManager.getPlots(cityID, plotDifficultyForCity, Status.unclaimed).size() != 0) {
if (selectedPlotDifficulty != null && PlotSystem.getPlugin().getConfigManager().getConfig().getBoolean(ConfigPaths.ENABLE_SCORE_REQUIREMENT) && !PlotManager.hasPlotDifficultyScoreRequirement(builder, selectedPlotDifficulty)) {
clickPlayer.sendMessage(Utils.getErrorMessageFormat("You need a higher score to build in this difficulty level."));
clickPlayer.playSound(clickPlayer.getLocation(), Utils.ErrorSound, 1, 1);
return;
}

if (PlotGenerator.playerPlotGenerationHistory.containsKey(builder.getUUID())) {
if (PlotGenerator.playerPlotGenerationHistory.get(builder.getUUID()).isBefore(LocalDateTime.now().minusSeconds(10))) {
PlotGenerator.playerPlotGenerationHistory.remove(builder.getUUID());
} else {
clickPlayer.sendMessage(Utils.getErrorMessageFormat("Please wait few seconds before creating a new plot!"));
clickPlayer.playSound(clickPlayer.getLocation(), Utils.ErrorSound, 1, 1);
return;
}
}

clickPlayer.sendMessage(Utils.getInfoMessageFormat("Creating a new plot..."));
clickPlayer.playSound(clickPlayer.getLocation(), Utils.CreatePlotSound, 1, 1);

Bukkit.getScheduler().runTask(PlotSystem.getPlugin(), () -> {
try {
new PlotGenerator(cityID, plotDifficultyForCity, builder);
} catch (SQLException ex) {
clickPlayer.sendMessage(Utils.getErrorMessageFormat("An internal error occurred! Please try again or contact a staff member."));
clickPlayer.playSound(clickPlayer.getLocation(), Utils.ErrorSound, 1, 1);
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
}
});
} else {
clickPlayer.sendMessage(Utils.getErrorMessageFormat("This city project doesn't have any more plots left. Please select another project."));
PlotDifficulty plotDifficultyForCity = selectedPlotDifficulty != null ? selectedPlotDifficulty : PlotManager.getPlotDifficultyForBuilder(cityID, builder).get();
if (PlotManager.getPlots(cityID, plotDifficultyForCity, Status.unclaimed).size() != 0) {
if (selectedPlotDifficulty != null && PlotSystem.getPlugin().getConfigManager().getConfig().getBoolean(ConfigPaths.ENABLE_SCORE_REQUIREMENT) && !PlotManager.hasPlotDifficultyScoreRequirement(builder, selectedPlotDifficulty)) {
clickPlayer.sendMessage(Utils.getErrorMessageFormat("You need a higher score to build in this difficulty level."));
clickPlayer.playSound(clickPlayer.getLocation(), Utils.ErrorSound, 1, 1);
return;
}

new DefaultPlotGenerator(cityID, plotDifficultyForCity, builder);
} else {
clickPlayer.sendMessage(Utils.getErrorMessageFormat("All your slots are occupied! Please finish your current plots before creating a new one."));
clickPlayer.sendMessage(Utils.getErrorMessageFormat("This city project doesn't have any more plots left. Please select another project."));
clickPlayer.playSound(clickPlayer.getLocation(), Utils.ErrorSound, 1, 1);
}
} catch (SQLException | ExecutionException | InterruptedException ex) {
clickPlayer.sendMessage(Utils.getErrorMessageFormat("An internal error occurred! Please try again!"));
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
clickPlayer.sendMessage(Utils.getErrorMessageFormat("An error occurred! Please try again!"));
clickPlayer.playSound(clickPlayer.getLocation(), Utils.ErrorSound, 1, 1);
Bukkit.getLogger().log(Level.SEVERE, "An internal error occurred!", ex);
}
} else {
clickPlayer.playSound(clickPlayer.getLocation(), Utils.ErrorSound, 1, 1);
Expand Down
Loading

0 comments on commit 1244f17

Please sign in to comment.