Skip to content

Commit

Permalink
Merge pull request #11 from AlpsBTE/v3.0
Browse files Browse the repository at this point in the history
Ready for release
  • Loading branch information
LordTuxn authored Sep 25, 2022
2 parents 7176c9c + 743447a commit 3f9766a
Show file tree
Hide file tree
Showing 13 changed files with 419 additions and 232 deletions.
12 changes: 6 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@

<groupId>com.alpsbte</groupId>
<artifactId>PlotSystem-Terra</artifactId>
<version>2.1</version>
<version>3.0</version>

<repositories>
<!-- World Edit -->
<!-- AlpsBTE Repo (WorldEdit, WorldGuard, FAWE) -->
<repository>
<id>nachwahl-repo</id>
<url>https://maven.nachwahl.dev/</url>
<id>alpsbte-repo</id>
<url>https://mvn.alps-bte.com/repository/alps-bte/</url>
</repository>

<!-- JitPack -->
Expand Down Expand Up @@ -97,9 +97,9 @@

<!-- JSCH -->
<dependency>
<groupId>com.jcraft</groupId>
<groupId>com.github.mwiede</groupId>
<artifactId>jsch</artifactId>
<version>0.1.55</version>
<version>0.2.0</version>
<scope>compile</scope>
</dependency>

Expand Down
13 changes: 11 additions & 2 deletions src/main/java/com/alpsbte/plotsystemterra/PlotSystemTerra.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.alpsbte.plotsystemterra;

import com.alpsbte.plotsystemterra.commands.CMD_CreatePlot;
import com.alpsbte.plotsystemterra.commands.CMD_PastePlot;
import com.alpsbte.plotsystemterra.core.DatabaseConnection;
import com.alpsbte.plotsystemterra.core.EventListener;
import com.alpsbte.plotsystemterra.core.config.ConfigManager;
Expand All @@ -26,15 +27,17 @@

public class PlotSystemTerra extends JavaPlugin {

private static final String VERSION = "2.1";
private static final String VERSION = "3.0";

private static PlotSystemTerra plugin;
private ConfigManager configManager;
private PlotPaster plotPaster;

private boolean pluginEnabled = false;

@Override
public void onEnable() {
System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.NoOpLog"); // Disable Logging
plugin = this;

String successPrefix = ChatColor.DARK_GRAY + "[" + ChatColor.DARK_GREEN + "✔" + ChatColor.DARK_GRAY + "] " + ChatColor.GRAY;
Expand Down Expand Up @@ -97,6 +100,7 @@ public void onEnable() {
// Register commands
try {
this.getCommand("createplot").setExecutor(new CMD_CreatePlot());
this.getCommand("pasteplot").setExecutor(new CMD_PastePlot());
Bukkit.getConsoleSender().sendMessage(successPrefix + "Successfully registered commands.");
} catch (Exception ex) {
Bukkit.getConsoleSender().sendMessage(errorPrefix + "Could not register commands.");
Expand All @@ -122,7 +126,8 @@ public void onEnable() {
});

// Start checking for plots to paste
new PlotPaster().start();
plotPaster = new PlotPaster();
plotPaster.start();

pluginEnabled = true;
Bukkit.getConsoleSender().sendMessage(" ");
Expand Down Expand Up @@ -164,6 +169,10 @@ public static PlotSystemTerra getPlugin() {
return plugin;
}

public PlotPaster getPlotPaster() {
return plotPaster;
}

public static class DependencyManager {

// List with all missing dependencies
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.alpsbte.plotsystemterra.commands;

import com.alpsbte.plotsystemterra.PlotSystemTerra;
import com.alpsbte.plotsystemterra.core.DatabaseConnection;
import com.alpsbte.plotsystemterra.core.plotsystem.CityProject;
import com.alpsbte.plotsystemterra.core.plotsystem.PlotPaster;
import com.alpsbte.plotsystemterra.utils.Utils;
import com.sk89q.worldedit.Vector;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandExecutor;
import org.bukkit.command.CommandSender;

import java.sql.ResultSet;
import java.util.logging.Level;

public class CMD_PastePlot implements CommandExecutor {
@Override
public boolean onCommand(CommandSender sender, Command cmd, String s, String[] args) {
if(Utils.hasPermission(sender, "pasteplot")) {
try {
if (args.length >= 1 && Utils.tryParseInt(args[0]) != null) {
int plotID = Integer.parseInt(args[0]);

try (ResultSet rs = DatabaseConnection.createStatement("SELECT status, city_project_id, mc_coordinates, version FROM plotsystem_plots WHERE id = ?")
.setValue(plotID).executeQuery()) {

if (rs.next() && rs.getString(1).equals("completed")) {
PlotPaster plotPaster = PlotSystemTerra.getPlugin().getPlotPaster();

String[] splitCoordinates = rs.getString(3).split(",");
Vector mcCoordinates = Vector.toBlockPoint(
Float.parseFloat(splitCoordinates[0]),
Float.parseFloat(splitCoordinates[1]),
Float.parseFloat(splitCoordinates[2])
);

try {
PlotPaster.pastePlotSchematic(plotID, new CityProject(rs.getInt(2)), plotPaster.world, mcCoordinates, rs.getDouble(4), plotPaster.fastMode);
Bukkit.broadcastMessage("§7§l>§a Pasted §61 §aplot!");
} catch (Exception ex) {
Bukkit.getLogger().log(Level.SEVERE, "An error occurred while pasting plot with the ID " + plotID + "!", ex);
sender.sendMessage(Utils.getErrorMessageFormat("An error occurred while pasting plot!"));
}
} else sender.sendMessage(Utils.getErrorMessageFormat("Plot with the ID " + plotID + " is not completed!"));

DatabaseConnection.closeResultSet(rs);
}
} else {
sender.sendMessage(Utils.getErrorMessageFormat("Incorrect Input! Try /pasteplot <ID>"));
}
} catch (Exception ex) {
Bukkit.getLogger().log(Level.SEVERE, "An error occurred while pasting plot!", ex);
sender.sendMessage(Utils.getErrorMessageFormat("An error occurred while pasting plot!"));
}
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public static void InitializeDatabase() throws ClassNotFoundException {
dataSource = new HikariDataSource(config);
}

@Deprecated
public static Connection getConnection() {
int retries = 3;
while (retries > 0) {
Expand Down Expand Up @@ -73,31 +72,6 @@ public static void closeResultSet(ResultSet resultSet) throws SQLException {
Bukkit.getLogger().log(Level.SEVERE, "There are multiple database connections opened. Please report this issue.");
}

/**
* Returns a missing auto increment id
* @param table in the database
* @return smallest missing auto increment id in the table
*/
public static int getTableID(String table) {
try {
String query ="SELECT id + 1 available_id FROM $table t WHERE NOT EXISTS (SELECT * FROM $table WHERE $table.id = t.id + 1) ORDER BY id LIMIT 1"
.replace("$table", table);
try (ResultSet rs = DatabaseConnection.createStatement(query).executeQuery()) {
if (rs.next()) {
int i = rs.getInt(1);
DatabaseConnection.closeResultSet(rs);
return i;
}

DatabaseConnection.closeResultSet(rs);
return 1;
}
} catch (SQLException ex) {
Bukkit.getLogger().log(Level.SEVERE, "A SQL error occurred!", ex);
return 1;
}
}

public static class StatementBuilder {
private final String sql;
private final List<Object> values = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

public class Config extends YamlConfiguration {

public static final double VERSION = 1.3;
public static final double VERSION = 1.4;

private final File file;
private final String fileName;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ public abstract class ConfigPaths {
public static final String DATABASE_PASSWORD = DATABASE + "password";


// PLOT SCANNING
private static final String ENVIRONMENT = "environment.";
public static final String ENVIRONMENT_ENABLED = ENVIRONMENT + "enabled";
public static final String ENVIRONMENT_RADIUS = ENVIRONMENT + "radius";


// PLOT PASTING
public static final String WORLD_NAME = "world-name";
public static final String FAST_MODE = "fast-mode";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public Menu getDifficultyMenu() {
);
difficultyMenu.getSlot(10).setClickHandler((clickPlayer, clickInformation) -> {
clickPlayer.closeInventory();
CompletableFuture.supplyAsync(() -> PlotCreator.Create(clickPlayer, cityProject, 1));
PlotCreator.Create(clickPlayer, cityProject, 1);
});

difficultyMenu.getSlot(13).setItem(
Expand All @@ -109,7 +109,7 @@ public Menu getDifficultyMenu() {
);
difficultyMenu.getSlot(13).setClickHandler((clickPlayer, clickInformation) -> {
clickPlayer.closeInventory();
CompletableFuture.supplyAsync(() -> PlotCreator.Create(clickPlayer, cityProject, 2));
PlotCreator.Create(clickPlayer, cityProject, 2);
});

difficultyMenu.getSlot(16).setItem(
Expand All @@ -119,7 +119,7 @@ public Menu getDifficultyMenu() {
);
difficultyMenu.getSlot(16).setClickHandler((clickPlayer, clickInformation) -> {
clickPlayer.closeInventory();
CompletableFuture.supplyAsync(() -> PlotCreator.Create(clickPlayer, cityProject, 3));
PlotCreator.Create(clickPlayer, cityProject, 3);
});

return difficultyMenu;
Expand Down
Loading

0 comments on commit 3f9766a

Please sign in to comment.