Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] #147 Database Rework #148

Draft
wants to merge 44 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
5bcee49
add builderprovider and sql implementation
Cinnazeyy Dec 13, 2024
17e3df1
Add BuildTeamProvider and SQL implementation
Cinnazeyy Dec 13, 2024
a641300
remove interface abstraction
Cinnazeyy Jan 16, 2025
e518344
update Builder and BuilderProvider
LordTuxn Jan 19, 2025
614a75d
Fix CMD_Plots.java, CMD_Tpll.java and PlotSystem.java
Cinnazeyy Jan 20, 2025
eaafbf2
update BuilderProvider
LordTuxn Jan 20, 2025
455ab72
Merge remote-tracking branch 'origin/main' into update/1.21-data-abst…
LordTuxn Jan 20, 2025
28c8d2f
Fix all plot commands
Cinnazeyy Jan 20, 2025
4809b64
cleanup commands
Cinnazeyy Jan 21, 2025
da81b45
fix CMD_Review.java and CMD_UndoReview.java
Cinnazeyy Jan 21, 2025
315c7ba
update all review commands to work with database rework
Cinnazeyy Jan 22, 2025
3748d11
add CityProject, Country and Difficulty Providers
Cinnazeyy Jan 22, 2025
6ca11f7
open review menu if no args are provided in review command
Cinnazeyy Jan 22, 2025
9ae7b01
fix errors
Cinnazeyy Jan 22, 2025
bfa6b90
add Utils.getConfiguredItem
Cinnazeyy Jan 23, 2025
95356f8
extract notices into separate method and fix compiler error
Cinnazeyy Jan 23, 2025
fb60152
turn CityProject.java into a proper model and extract various methods…
Cinnazeyy Jan 24, 2025
3e51a8b
Finish city project model and fix CMD_Setup_City.java
Cinnazeyy Jan 24, 2025
d2cbb14
Finish BuildTeam model and fix CMD_Setup_BuildTeam.java
Cinnazeyy Jan 29, 2025
65f83c6
remove getReviewers method from build team dataprovider
Cinnazeyy Jan 29, 2025
2a16654
delete redundant Server.java model and implement ServerProvider.java
Cinnazeyy Jan 29, 2025
fd90219
start reworking plot generation with database rework
Cinnazeyy Feb 9, 2025
6f4c9bc
Merge branch 'main' into update/1.21-data-abstraction
Cinnazeyy Feb 9, 2025
9a00208
fix issues from merging
Cinnazeyy Feb 9, 2025
f21e8c6
finish country model and CMD_Setup_Country.java
Cinnazeyy Feb 9, 2025
f7092a5
finish difficulty model and CMD_Setup_Difficulty.java
Cinnazeyy Feb 9, 2025
0e85e98
delete Reviewer class
Cinnazeyy Feb 9, 2025
de48a19
Cleanup EventListener and change plottype to be of PlotType type inst…
Cinnazeyy Feb 9, 2025
35314a0
delete FTPConfiguration.java!! 🎉🎉🎉
Cinnazeyy Feb 9, 2025
f812d25
delete Payout.java
Cinnazeyy Feb 9, 2025
b9b60bd
update CityProjects data provider
LordTuxn Feb 9, 2025
805f17d
update TutorialPlot data provider
LordTuxn Feb 9, 2025
3007701
fix remaining compiler issues!! 🎉🎉🎉
Cinnazeyy Feb 9, 2025
c826044
fix warnings
Cinnazeyy Feb 10, 2025
e7f5e94
Add a specific interval for rejected plots
Zoriot Feb 10, 2025
e407f87
Make the owner head in /p members clickable
Zoriot Feb 14, 2025
0c1870e
add database related values to language files
Cinnazeyy Feb 15, 2025
108b83e
implement country provider logic
Cinnazeyy Feb 15, 2025
844b40e
implement server provider logic
Cinnazeyy Feb 16, 2025
0ebe768
implement difficulty provider logic
Cinnazeyy Feb 16, 2025
ef704cd
Check only first numbers for tutorial height
Zoriot Feb 18, 2025
8b09ff3
implement remaining methods of builder provider
Cinnazeyy Feb 20, 2025
6f6a993
Merge remote-tracking branch 'origin/update/1.21-data-abstraction' in…
Cinnazeyy Feb 20, 2025
8ceb4ea
Send a repeated message for unfinished plots
Zoriot Feb 20, 2025
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<!-- PROJECT DESCRIPTION -->
<!--suppress HtmlDeprecatedAttribute -->
<br />

<p align="Center">
Expand Down
7 changes: 0 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,6 @@
<version>4.0.3</version>
<scope>compile</scope>
</dependency>
<!-- Apache Commons VFS -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-vfs2</artifactId>
<version>2.4</version> <!-- TODO: Use another SFTP/FTP dependency -->
<scope>compile</scope>
</dependency>
<!-- Apache Commons Net -->
<dependency>
<groupId>commons-net</groupId>
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/com/alpsbte/plotsystem/PlotSystem.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ public void onEnable() {
DecentHologramDisplay.registerPlugin(this);
HologramRegister.init();
PlotUtils.checkPlotsForLastActivity();
PlotUtils.syncPlotSchematicFiles();
Utils.ChatUtils.checkForChatInputExpiry();
PlotUtils.Effects.startTimer();

Expand Down Expand Up @@ -234,7 +233,8 @@ public void onDisable() {
} else {
// Unload plots
for (UUID player : PlotUtils.Cache.getCachedInProgressPlots().keySet()) {
for (Plot plot : PlotUtils.Cache.getCachedInProgressPlots(Builder.byUUID(player))) {
Builder builder = Builder.byUUID(player);
for (Plot plot : PlotUtils.Cache.getCachedInProgressPlots(builder)) {
if (plot != null) plot.getWorld().unloadWorld(true);
}
}
Expand Down Expand Up @@ -270,7 +270,6 @@ public void saveConfig() {
public static PlotSystem getPlugin() {
return plugin;
}

public CommandManager getCommandManager() {
return commandManager;
}
Expand Down
30 changes: 9 additions & 21 deletions src/main/java/com/alpsbte/plotsystem/commands/CMD_Companion.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* The MIT License (MIT)
*
* Copyright © 2023, Alps BTE <[email protected]>
* Copyright © 2025, Alps BTE <[email protected]>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -24,7 +24,6 @@

package com.alpsbte.plotsystem.commands;

import com.alpsbte.plotsystem.PlotSystem;
import com.alpsbte.plotsystem.core.menus.companion.CompanionMenu;
import com.alpsbte.plotsystem.core.menus.tutorial.TutorialStagesMenu;
import com.alpsbte.plotsystem.core.menus.tutorial.TutorialsMenu;
Expand All @@ -33,19 +32,13 @@
import com.alpsbte.plotsystem.core.system.tutorial.Tutorial;
import com.alpsbte.plotsystem.core.system.tutorial.TutorialCategory;
import com.alpsbte.plotsystem.utils.Utils;
import com.alpsbte.plotsystem.utils.io.ConfigPaths;
import com.alpsbte.plotsystem.utils.io.LangPaths;
import com.alpsbte.plotsystem.utils.io.LangUtil;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.sql.SQLException;

import static net.kyori.adventure.text.Component.text;

public class CMD_Companion extends BaseCommand {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String s, String[] args) {
Expand All @@ -54,20 +47,15 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
return true;
}

if (getPlayer(sender) == null) return true;
Player player = getPlayer(sender);
if (player == null) return true;

try {
FileConfiguration config = PlotSystem.getPlugin().getConfig();
Tutorial tutorial = AbstractTutorial.getActiveTutorial(getPlayer(sender).getUniqueId());
if (tutorial != null) {
new TutorialStagesMenu(getPlayer(sender), tutorial.getId());
} else if (config.getBoolean(ConfigPaths.TUTORIAL_ENABLE) && config.getBoolean(ConfigPaths.TUTORIAL_REQUIRE_BEGINNER_TUTORIAL) &&
!TutorialPlot.isPlotCompleted(getPlayer(sender), TutorialCategory.BEGINNER.getId()) && getPlayer(sender).hasPermission("plotsystem.tutorial")) {
new TutorialsMenu(getPlayer(sender));
} else CompanionMenu.open((Player) sender);
} catch (SQLException ex) {
PlotSystem.getPlugin().getComponentLogger().error(text("A SQL error occurred!"), ex);
}
Tutorial tutorial = AbstractTutorial.getActiveTutorial(player.getUniqueId());
if (tutorial != null) {
new TutorialStagesMenu(player, tutorial.getId());
} else if (TutorialPlot.isRequiredAndInProgress(TutorialCategory.BEGINNER.getId(), player.getUniqueId()) && player.hasPermission("plotsystem.tutorial")) {
new TutorialsMenu(player);
} else CompanionMenu.open((Player) sender);

return true;
}
Expand Down
47 changes: 23 additions & 24 deletions src/main/java/com/alpsbte/plotsystem/commands/CMD_Plots.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,49 +30,48 @@
import com.alpsbte.plotsystem.utils.Utils;
import com.alpsbte.plotsystem.utils.io.LangPaths;
import com.alpsbte.plotsystem.utils.io.LangUtil;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.NamedTextColor;
import org.bukkit.Bukkit;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.sql.SQLException;

import static net.kyori.adventure.text.Component.text;
import java.util.concurrent.CompletableFuture;

public class CMD_Plots extends BaseCommand {
@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String s, String[] args) {
if (!sender.hasPermission(getPermission())) {
sender.sendMessage(Utils.ChatUtils.getAlertFormat(LangUtil.getInstance().get(sender, LangPaths.Message.Error.PLAYER_HAS_NO_PERMISSIONS)));
Player player = getPlayer(sender);
if (player == null) {
Bukkit.getConsoleSender().sendMessage(Component.text("This command can only be used as a player!", NamedTextColor.RED));
return true;
}

if (getPlayer(sender) == null) {
Bukkit.getConsoleSender().sendMessage(text("This command can only be used as a player!", NamedTextColor.RED));
if (!sender.hasPermission(getPermission())) {
sender.sendMessage(Utils.ChatUtils.getAlertFormat(LangUtil.getInstance().get(sender, LangPaths.Message.Error.PLAYER_HAS_NO_PERMISSIONS)));
return true;
}

Player player = (Player) sender;

try {
if (args.length < 1) {
new PlayerPlotsMenu(player, Builder.byUUID(player.getUniqueId()));
return true;
}
if (args.length < 1) {
CompletableFuture.runAsync(() -> {
Builder builder = Builder.byUUID(player.getUniqueId());
Bukkit.getScheduler().runTask(PlotSystem.getPlugin(), () -> new PlayerPlotsMenu(player, builder));
});
}

Builder builder = Builder.getBuilderByName(args[0]);
if (builder == null) {
player.sendMessage(Utils.ChatUtils.getAlertFormat(LangUtil.getInstance().get(sender, LangPaths.Message.Error.PLAYER_NOT_FOUND)));
return true;
}
CompletableFuture.runAsync(() -> {
Builder builder = Builder.byName(args[0]);
Bukkit.getScheduler().runTask(PlotSystem.getPlugin(), () -> {
if (builder == null) {
player.sendMessage(Utils.ChatUtils.getAlertFormat(LangUtil.getInstance().get(sender, LangPaths.Message.Error.PLAYER_NOT_FOUND)));
return;
}

new PlayerPlotsMenu(player, builder);
} catch (SQLException ex) {
sender.sendMessage(Utils.ChatUtils.getAlertFormat(LangUtil.getInstance().get(sender, LangPaths.Message.Error.ERROR_OCCURRED)));
PlotSystem.getPlugin().getComponentLogger().error(text("A SQL error occurred!"), ex);
}
new PlayerPlotsMenu(player, builder);
});
});
return true;
}

Expand Down
125 changes: 65 additions & 60 deletions src/main/java/com/alpsbte/plotsystem/commands/CMD_Tpll.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@

import java.io.IOException;
import java.math.RoundingMode;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
Expand Down Expand Up @@ -74,78 +73,84 @@ public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @N
return true;
}

try {
if (args == null || args.length < 2 || args.length > 3) {
sendInfo(sender);
return true;
}
if (args == null || args.length < 2 || args.length > 3) {
sendInfo(sender);
return true;
}

String[] splitCoords = args[0].split(",");
if (splitCoords.length == 2) {
args = splitCoords;
}
String[] splitCoords = args[0].split(",");
if (splitCoords.length == 2) {
args = splitCoords;
}

if (args[0].endsWith(",")) {
args[0] = args[0].substring(0, args[0].length() - 1);
}
if (args[1].endsWith(",")) {
args[1] = args[1].substring(0, args[1].length() - 1);
}
if (args[0].endsWith(",")) {
args[0] = args[0].substring(0, args[0].length() - 1);
}
if (args[1].endsWith(",")) {
args[1] = args[1].substring(0, args[1].length() - 1);
}

// Parse coordinates to doubles
double lat;
double lon;
try {
lat = Double.parseDouble(args[0]);
lon = Double.parseDouble(args[1]);
} catch (Exception ignore) {
sendInfo(sender);
return true;
}

// Parse coordinates to doubles
double lat;
double lon;
CompletableFuture.runAsync(() -> {
try {
lat = Double.parseDouble(args[0]);
lon = Double.parseDouble(args[1]);
} catch (Exception ignore) {
sendInfo(sender);
return true;
}
// Get the terra coordinates from the irl coordinates
double[] terraCoords = CoordinateConversion.convertFromGeo(lon, lat);

// Get the terra coordinates from the irl coordinates
double[] terraCoords = CoordinateConversion.convertFromGeo(lon, lat);
// Get plot, that the player is in
AbstractPlot plot = PlotUtils.getCurrentPlot(Builder.byUUID(player.getUniqueId()), Status.unfinished, Status.unreviewed, Status.completed);

// Get plot, that the player is in
AbstractPlot plot = PlotUtils.getCurrentPlot(Builder.byUUID(player.getUniqueId()), Status.unfinished, Status.unreviewed, Status.completed);
// Convert terra coordinates to plot relative coordinates
CompletableFuture<double[]> plotCoordsFuture = plot != null ? PlotUtils.convertTerraToPlotXZ(plot, terraCoords) : null;

// Convert terra coordinates to plot relative coordinates
CompletableFuture<double[]> plotCoords = plot != null ? PlotUtils.convertTerraToPlotXZ(plot, terraCoords) : null;
if (plotCoordsFuture == null) {
player.sendMessage(Utils.ChatUtils.getAlertFormat(langUtil.get(sender, LangPaths.Message.Error.CANNOT_TELEPORT_OUTSIDE_PLOT)));
return;
}

if (plotCoords == null) {
player.sendMessage(Utils.ChatUtils.getAlertFormat(langUtil.get(sender, LangPaths.Message.Error.CANNOT_TELEPORT_OUTSIDE_PLOT)));
return true;
}
double[] plotCoordinates = plotCoordsFuture.get();

// Get Highest Y
int highestY = 0;
Location block = new Location(playerWorld, plotCoords.get()[0], 0, plotCoords.get()[1]);
for (int i = 1; i < 256; i++) {
block.add(0, 1, 0);
if (!block.getBlock().isEmpty()) {
highestY = i;
}
}
if (highestY < PlotWorld.MIN_WORLD_HEIGHT) {
highestY = PlotWorld.MIN_WORLD_HEIGHT;
}
Bukkit.getScheduler().runTask(PlotSystem.getPlugin(), () -> {
int highestY = getHighestY(playerWorld, plotCoordinates);

player.teleport(new Location(playerWorld, plotCoords.get()[0], highestY + 1, plotCoords.get()[1], player.getLocation().getYaw(), player.getLocation().getPitch()));
player.teleport(new Location(playerWorld, plotCoordinates[0], highestY + 1, plotCoordinates[1], player.getLocation().getYaw(), player.getLocation().getPitch()));

DecimalFormat df = new DecimalFormat("##.#####");
df.setRoundingMode(RoundingMode.FLOOR);
player.sendMessage(Utils.ChatUtils.getInfoFormat(langUtil.get(sender, LangPaths.Message.Info.TELEPORTING_TPLL, df.format(lat), df.format(lon))));
DecimalFormat df = new DecimalFormat("##.#####");
df.setRoundingMode(RoundingMode.FLOOR);
player.sendMessage(Utils.ChatUtils.getInfoFormat(langUtil.get(sender, LangPaths.Message.Info.TELEPORTING_TPLL, df.format(lat), df.format(lon))));
});
} catch (IOException | OutOfProjectionBoundsException ex) {
PlotSystem.getPlugin().getComponentLogger().error(text("A coordinate conversion error occurred!"), ex);
player.sendMessage(Utils.ChatUtils.getAlertFormat(LangUtil.getInstance().get(sender, LangPaths.Message.Error.ERROR_OCCURRED)));
} catch (InterruptedException | ExecutionException ex) {
sendInfo(sender);
}
});
return true;
}

} catch (SQLException ex) {
PlotSystem.getPlugin().getComponentLogger().error(text("A SQL error occurred!"), ex);
player.sendMessage(Utils.ChatUtils.getAlertFormat(LangUtil.getInstance().get(sender, LangPaths.Message.Error.ERROR_OCCURRED)));
} catch (IOException | OutOfProjectionBoundsException ex) {
PlotSystem.getPlugin().getComponentLogger().error(text("A coordinate conversion error occurred!"), ex);
player.sendMessage(Utils.ChatUtils.getAlertFormat(LangUtil.getInstance().get(sender, LangPaths.Message.Error.ERROR_OCCURRED)));
} catch (InterruptedException | ExecutionException ex) {
sendInfo(sender);
private static int getHighestY(World playerWorld, double[] plotCoordinates) {
int highestY = 0;
Location block = new Location(playerWorld, plotCoordinates[0], 0, plotCoordinates[1]);
for (int i = 1; i < 256; i++) {
block.add(0, 1, 0);
if (!block.getBlock().isEmpty()) {
highestY = i;
}
}
return true;
if (highestY < PlotWorld.MIN_WORLD_HEIGHT) {
highestY = PlotWorld.MIN_WORLD_HEIGHT;
}
return highestY;
}

@Override
Expand Down
43 changes: 22 additions & 21 deletions src/main/java/com/alpsbte/plotsystem/commands/CMD_Tutorial.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,29 +47,30 @@ public class CMD_Tutorial extends BaseCommand {

@Override
public boolean onCommand(@NotNull CommandSender sender, @NotNull Command cmd, @NotNull String s, String[] args) {
if (sender.hasPermission(getPermission())) {
if (getPlayer(sender) != null) {
if (PlotSystem.getPlugin().getConfig().getBoolean(ConfigPaths.TUTORIAL_ENABLE)) {
if (args.length == 0) {
Tutorial tutorial = AbstractTutorial.getActiveTutorial(getPlayer(sender).getUniqueId());
if (tutorial != null) {
new TutorialStagesMenu(tutorial.getPlayer(), tutorial.getId());
} else {
new TutorialsMenu(getPlayer(sender));
}
} else if (args.length == 1 && AlpsUtils.tryParseInt(args[0]) != null) {
int tutorialId = Integer.parseInt(args[0]);
if (TutorialCategory.byId(tutorialId) == null) return true;
AbstractTutorial.loadTutorial(getPlayer(sender), tutorialId);
}
} else {
sender.sendMessage(Utils.ChatUtils.getAlertFormat(LangUtil.getInstance().get(sender, LangPaths.Message.Error.TUTORIAL_DISABLED)));
}
if (!sender.hasPermission(getPermission())) {
sender.sendMessage(Utils.ChatUtils.getAlertFormat(LangUtil.getInstance().get(sender, LangPaths.Message.Error.PLAYER_HAS_NO_PERMISSIONS)));
return true;
}
if (getPlayer(sender) == null) {
Bukkit.getConsoleSender().sendMessage(Component.text("This command can only be used as a player!", NamedTextColor.RED));
return true;
}
if (!PlotSystem.getPlugin().getConfig().getBoolean(ConfigPaths.TUTORIAL_ENABLE)) {
sender.sendMessage(Utils.ChatUtils.getAlertFormat(LangUtil.getInstance().get(sender, LangPaths.Message.Error.TUTORIAL_DISABLED)));
return true;
}

if (args.length == 0) {
Tutorial tutorial = AbstractTutorial.getActiveTutorial(getPlayer(sender).getUniqueId());
if (tutorial != null) {
new TutorialStagesMenu(tutorial.getPlayer(), tutorial.getId());
} else {
Bukkit.getConsoleSender().sendMessage(Component.text("This command can only be used as a player!", NamedTextColor.RED));
new TutorialsMenu(getPlayer(sender));
}
} else {
sender.sendMessage(Utils.ChatUtils.getAlertFormat(LangUtil.getInstance().get(sender, LangPaths.Message.Error.PLAYER_HAS_NO_PERMISSIONS)));
} else if (args.length == 1 && AlpsUtils.tryParseInt(args[0]) != null) {
int tutorialId = Integer.parseInt(args[0]);
if (TutorialCategory.byId(tutorialId) == null) return true;
AbstractTutorial.loadTutorial(getPlayer(sender), tutorialId);
}
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@

public class CommandManager {

public final List<BaseCommand> baseCommands = new ArrayList<BaseCommand>() {{
public final List<BaseCommand> baseCommands = new ArrayList<>() {{
// Default Commands
add(new CMD_CancelChat());
add(new CMD_Companion());
Expand Down
Loading