Skip to content

Commit

Permalink
2.0.0 part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
BenceX100 committed Aug 4, 2024
1 parent 18266a6 commit 8c891f8
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 22 deletions.
6 changes: 2 additions & 4 deletions src/main/java/com/artillexstudios/axvaults/AxVaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,8 @@ public static void registerCommands() {
}

public void disable() {
for (VaultPlayer vaultPlayer : VaultManager.getPlayers().values()) {
for (Vault vault : vaultPlayer.getVaultMap().values()) {
AxVaults.getDatabase().saveVault(vault);
}
for (Vault vault : VaultManager.getVaults()) {
AxVaults.getDatabase().saveVault(vault);
}
AutoSaveScheduler.stop();
database.disable();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ public void delete(@NotNull Player sender, @NotNull OfflinePlayer player, int nu
MESSAGEUTILS.sendLang(sender, "view.not-found", replacements);
return;
}
VaultManager.getVaults().remove(vault);
VaultManager.removeVault(vault);
AxVaults.getDatabase().deleteVault(player.getUniqueId(), number);
MESSAGEUTILS.sendLang(sender, "delete", replacements);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private void convert() { // todo: clean db
}
}
}
} catch (SQLException ex) {
} catch (Exception ex) {
ex.printStackTrace();
}
Bukkit.getConsoleSender().sendMessage(StringUtils.formatToString("&#33FF33[AxVaults] Successfully converted " + am + " vaults in " + (System.currentTimeMillis() - time) + "ms"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void convert() { // todo: clean db
}
}
}
} catch (SQLException ex) {
} catch (Exception ex) {
ex.printStackTrace();
}
Bukkit.getConsoleSender().sendMessage(StringUtils.formatToString("&#33FF33[AxVaults] Successfully converted " + am + " vaults in " + (System.currentTimeMillis() - time) + "ms"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import org.bukkit.event.inventory.InventoryCloseEvent;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.Map;

import static com.artillexstudios.axvaults.AxVaults.MESSAGES;
Expand All @@ -22,7 +21,7 @@ public class InventoryCloseListener implements Listener {
public void onClose(@NotNull InventoryCloseEvent event) {
AxVaults.getThreadedQueue().submit(() -> {
Vault v = null;
for (Vault vault : new ArrayList<>(VaultManager.getVaults())) {
for (Vault vault : VaultManager.getVaults()) {
if (!vault.getStorage().equals(event.getInventory())) continue;
v = vault;
break;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
package com.artillexstudios.axvaults.schedulers;

import com.artillexstudios.axapi.scheduler.Scheduler;
import com.artillexstudios.axvaults.AxVaults;
import com.artillexstudios.axvaults.vaults.Vault;
import com.artillexstudios.axvaults.vaults.VaultManager;
import com.artillexstudios.axvaults.vaults.VaultPlayer;
import org.bukkit.Bukkit;

import java.util.Iterator;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
Expand All @@ -23,19 +22,20 @@ public static void start() {
service = Executors.newSingleThreadScheduledExecutor();
service.scheduleAtFixedRate(() -> {
try {
for (VaultPlayer vaultPlayer : VaultManager.getPlayers().values()) {
for (Vault vault : vaultPlayer.getVaultMap().values()) {
AxVaults.getDatabase().saveVault(vault);
if (vault.isOpened()) continue;
if (Bukkit.getPlayer(vault.getUUID()) != null) continue;
if (System.currentTimeMillis() - vault.getLastOpen() <= (time - 1) * 1_000L) continue;
Scheduler.get().run(scheduledTask -> VaultManager.removeVault(vault));
}
final Iterator<Vault> iterator = VaultManager.getVaults().iterator();
while (iterator.hasNext()) {
final Vault vault = iterator.next();
AxVaults.getDatabase().saveVault(vault);
if (vault.isOpened()) continue;
if (Bukkit.getPlayer(vault.getUUID()) != null) continue;
if (System.currentTimeMillis() - vault.getLastOpen() <= (time - 1) * 1_000L) continue;
VaultManager.removeVault(vault);
iterator.remove();
}
} catch (Exception ex) {
ex.printStackTrace();
}
}, time, time, TimeUnit.MINUTES); // TODO: MINUTES
}, time, time, TimeUnit.MINUTES);
}

public static void stop() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@
import org.bukkit.entity.Player;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.function.Consumer;

public class VaultManager {
private static final ConcurrentHashMap<UUID, VaultPlayer> players = new ConcurrentHashMap<>();
private static final ArrayList<Vault> vaults = new ArrayList<>();
private static final ConcurrentLinkedQueue<Vault> vaults = new ConcurrentLinkedQueue<>();

public static void loadPlayer(@NotNull UUID uuid) {
getPlayer(uuid, vaultPlayer -> {});
Expand Down Expand Up @@ -74,7 +74,7 @@ public static void reload() {
}
}

public static ArrayList<Vault> getVaults() {
public static ConcurrentLinkedQueue<Vault> getVaults() {
return vaults;
}
}

0 comments on commit 8c891f8

Please sign in to comment.