Skip to content

Commit

Permalink
Remove Deleted Objects from SQL Database
Browse files Browse the repository at this point in the history
  • Loading branch information
gmitch215 committed Dec 6, 2023
1 parent 53e05f2 commit 4b4316e
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1491,12 +1491,26 @@ public static Business byOwner(@Nullable OfflinePlayer p) {
public static void remove(@Nullable Business b) {
if (b == null) return;

for (File f : b.folder.listFiles()) {
if (f == null) continue;
f.delete();
}
BUSINESS_CACHE.clear();

b.folder.delete();
if (NovaConfig.getConfiguration().isDatabaseEnabled()) {
Connection db = NovaConfig.getConfiguration().getDatabaseConnection();
try {
PreparedStatement ps = db.prepareStatement("DELETE FROM businesses WHERE id = ?");
ps.setString(1, b.id.toString());
ps.executeUpdate();
ps.close();
} catch (SQLException e) {
NovaConfig.print(e);
}
} else {
for (File f : b.folder.listFiles()) {
if (f == null) continue;
f.delete();
}

b.folder.delete();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -914,12 +914,25 @@ public static void removeCorporation(@NotNull Corporation c) {

CORPORATION_CACHE.clear();

for (File f : c.folder.listFiles()) {
if (f == null) continue;
f.delete();
}
if (NovaConfig.getConfiguration().isDatabaseEnabled()) {
Connection db = NovaConfig.getConfiguration().getDatabaseConnection();

try {
PreparedStatement ps = db.prepareStatement("DELETE FROM corporations WHERE id = ?");
ps.setString(1, c.getUniqueId().toString());
ps.executeUpdate();
ps.close();
} catch (SQLException e) {
NovaConfig.print(e);
}
} else {
for (File f : c.folder.listFiles()) {
if (f == null) continue;
f.delete();
}

c.folder.delete();
c.folder.delete();
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,9 @@ public boolean setTax(boolean tax) {
*/
public static void removeEconomy(@Nullable Economy econ) throws IllegalArgumentException {
if (econ == null) throw new IllegalArgumentException("Economy cannot be null");

ECONOMY_CACHE.clear();

for (OfflinePlayer p : Bukkit.getOfflinePlayers()) {
NovaPlayer np = new NovaPlayer(p);
Map<String, Object> data = np.getPlayerData();
Expand All @@ -260,7 +263,21 @@ public static void removeEconomy(@Nullable Economy econ) throws IllegalArgumentE
.forEach(data::remove);
}

econ.file.delete();
if (NovaConfig.getConfiguration().isDatabaseEnabled()) {
Connection db = NovaConfig.getConfiguration().getDatabaseConnection();

try {
PreparedStatement ps = db.prepareStatement("DELETE FROM economies WHERE id = ?");
ps.setString(1, econ.getUniqueId().toString());
ps.executeUpdate();
ps.close();
} catch (SQLException e) {
NovaConfig.print(e);
}
} else {
econ.file.delete();
}

NovaConfig.getConfiguration().reloadHooks();
}

Expand Down

0 comments on commit 4b4316e

Please sign in to comment.