Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
16 changes: 15 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<version>3.14.0</version>
<configuration>
<release>21</release>
</configuration>
Expand Down Expand Up @@ -56,6 +56,10 @@
<pattern>net.kyori</pattern>
<shadedPattern>com.drtshock.playervaults.lib.net.kyori</shadedPattern>
</relocation>
<relocation>
<pattern>com.tcoded.folialib</pattern>
<shadedPattern>com.drtshock.playervaults.lib.folialib</shadedPattern>
</relocation>
<relocation>
<pattern>org.kitteh</pattern>
<shadedPattern>com.drtshock.playervaults.lib.org.kitteh</shadedPattern>
Expand Down Expand Up @@ -95,6 +99,10 @@
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/groups/public/</url>
</repository>
<repository>
<id>tcoded-releases</id>
<url>https://repo.tcoded.com/releases</url>
</repository>
<repository>
<id>placeholderapi</id>
<url>https://repo.extendedclip.com/content/repositories/placeholderapi/</url>
Expand Down Expand Up @@ -193,6 +201,12 @@
<version>1.21.10-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.tcoded</groupId>
<artifactId>FoliaLib</artifactId>
<version>0.5.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/drtshock/playervaults/Metrics.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void run() {
}
// Nevertheless we want our code to run in the Bukkit main thread, so we have to use the Bukkit scheduler
// Don't be afraid! The connection to the bStats server is still async, only the stats collection is sync ;)
Bukkit.getScheduler().runTask(plugin, () -> submitData());
PlayerVaults.scheduler().runNextTick(task -> submitData());
}
}, 1000 * 60 * 5, 1000 * 60 * 30);
// Submit the data every 30 minutes, first time after 5 minutes to give other plugins enough time to start
Expand Down
120 changes: 65 additions & 55 deletions src/main/java/com/drtshock/playervaults/PlayerVaults.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,11 @@
import com.drtshock.playervaults.vaultmanagement.EconomyOperations;
import com.drtshock.playervaults.vaultmanagement.VaultManager;
import com.drtshock.playervaults.vaultmanagement.VaultViewInfo;
import com.google.common.collect.Sets;
import com.google.gson.Gson;
import net.kyori.adventure.audience.Audience;
import com.tcoded.folialib.FoliaLib;
import com.tcoded.folialib.impl.PlatformScheduler;
import dev.kitteh.cardboardbox.CardboardBox;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.format.TextColor;
import net.kyori.adventure.text.minimessage.MiniMessage;
Expand All @@ -59,8 +62,6 @@
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;
import org.bukkit.scheduler.BukkitRunnable;
import dev.kitteh.cardboardbox.CardboardBox;
import sun.misc.Unsafe;

import java.io.BufferedReader;
Expand All @@ -87,6 +88,7 @@
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.function.Supplier;
import java.util.logging.Level;
Expand All @@ -96,13 +98,15 @@
public class PlayerVaults extends JavaPlugin {
public static boolean DEBUG;
private static PlayerVaults instance;
private final HashMap<String, SignSetInfo> setSign = new HashMap<>();
private static FoliaLib foliaLib;
private static PlatformScheduler scheduler;
private final ConcurrentHashMap<String, SignSetInfo> setSign = new ConcurrentHashMap<>();
// Player name - VaultViewInfo
private final HashMap<String, VaultViewInfo> inVault = new HashMap<>();
private final ConcurrentHashMap<String, VaultViewInfo> inVault = new ConcurrentHashMap<>();
// VaultViewInfo - Inventory
private final HashMap<String, Inventory> openInventories = new HashMap<>();
private final Set<Material> blockedMats = new HashSet<>();
private final Set<Enchantment> blockedEnchs = new HashSet<>();
private final ConcurrentHashMap<String, Inventory> openInventories = new ConcurrentHashMap<>();
private final Set<Material> blockedMats = Sets.newConcurrentHashSet();
private final Set<Enchantment> blockedEnchs = Sets.newConcurrentHashSet();
private boolean blockWithModelData = false;
private boolean blockWithoutModelData = false;
private boolean useVault;
Expand All @@ -126,6 +130,14 @@ public static PlayerVaults getInstance() {
return instance;
}

public static FoliaLib foliaLib() {
return foliaLib;
}

public static PlatformScheduler scheduler() {
return scheduler;
}

public static void debug(String s, long start) {
if (DEBUG) {
instance.getLogger().log(Level.INFO, "{0} took {1}ms", new Object[]{s, (System.currentTimeMillis() - start)});
Expand All @@ -146,6 +158,8 @@ public void onEnable() {
return;
}
instance = this;
foliaLib = new FoliaLib(this);
scheduler = foliaLib.getScheduler();
long start = System.currentTimeMillis();
long time = System.currentTimeMillis();
UpdateCheck update = new UpdateCheck("PlayerVaultsX", this.getDescription().getVersion(), this.getServer().getName(), this.getServer().getVersion());
Expand Down Expand Up @@ -186,17 +200,15 @@ public void onEnable() {
debug("setup economy", time);

if (getConf().getPurge().isEnabled()) {
getServer().getScheduler().runTaskAsynchronously(this, new Cleanup(getConf().getPurge().getDaysSinceLastEdit()));
final int days = getConf().getPurge().getDaysSinceLastEdit();
PlayerVaults.scheduler().runLaterAsync(new Cleanup(days), 1L);
}

new BukkitRunnable() {
@Override
public void run() {
if (saveQueued) {
saveSignsFile();
}
PlayerVaults.scheduler().runTimer(() -> {
if (saveQueued) {
saveSignsFile();
}
}.runTaskTimer(this, 20, 20);
}, 20, 20);

this.metrics = new Metrics(this, 6905);
Plugin vault = getServer().getPluginManager().getPlugin("Vault");
Expand Down Expand Up @@ -296,42 +308,40 @@ public void run() {

this.updateCheck = new Gson().toJson(update);
if (!HelpMeCommand.likesCats) return;
new BukkitRunnable() {
@Override
public void run() {
try {
URL url = new URL("https://update.plugin.party/check");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "application/json");
try (OutputStream out = con.getOutputStream()) {
out.write(PlayerVaults.this.updateCheck.getBytes(StandardCharsets.UTF_8));
}
String reply = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
Response response = new Gson().fromJson(reply, Response.class);
if (response.isSuccess()) {
if (response.isUpdateAvailable()) {
PlayerVaults.this.updateResponse = response;
if (response.isUrgent()) {
PlayerVaults.this.getServer().getOnlinePlayers().forEach(PlayerVaults.this::updateNotification);
}
PlayerVaults.this.getLogger().warning("Update available: " + response.getLatestVersion() + (response.getMessage() == null ? "" : (" - " + response.getMessage())));
PlayerVaults.scheduler().runTimerAsync(task -> {
try {
URL url = new URL("https://update.plugin.party/check");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("POST");
con.setDoOutput(true);
con.setRequestProperty("Content-Type", "application/json");
con.setRequestProperty("Accept", "application/json");
try (OutputStream out = con.getOutputStream()) {
out.write(PlayerVaults.this.updateCheck.getBytes(StandardCharsets.UTF_8));
}
String reply = new BufferedReader(new InputStreamReader(con.getInputStream(), StandardCharsets.UTF_8)).lines().collect(Collectors.joining("\n"));
Response response = new Gson().fromJson(reply, Response.class);
if (response.isSuccess()) {
if (response.isUpdateAvailable()) {
PlayerVaults.this.updateResponse = response;
if (response.isUrgent()) {
PlayerVaults.this.getServer().getOnlinePlayers().forEach(PlayerVaults.this::updateNotification);
}
PlayerVaults.this.getLogger().warning("Update available: " + response.getLatestVersion() + (response.getMessage() == null ? "" : (" - " + response.getMessage())));
}
} else {
if (response.getMessage().equals("INVALID")) {
task.cancel();
} else if (response.getMessage().equals("TOO_FAST")) {
// Nothing for now
} else {
if (response.getMessage().equals("INVALID")) {
this.cancel();
} else if (response.getMessage().equals("TOO_FAST")) {
// Nothing for now
} else {
PlayerVaults.this.getLogger().warning("Failed to check for updates: " + response.getMessage());
}
PlayerVaults.this.getLogger().warning("Failed to check for updates: " + response.getMessage());
}
} catch (Exception ignored) {
}
} catch (Exception ignored) {
// Ignored case/handler.
}
}.runTaskTimerAsynchronously(this, 1, 20 /* ticks */ * 60 /* seconds in a minute */ * 60 /* minutes in an hour*/);
}, 1, 20 /* ticks */ * 60 /* seconds in a minute */ * 60 /* minutes in an hour*/);
}

private void metricsLine(String name, Callable<Integer> callable) {
Expand Down Expand Up @@ -365,15 +375,15 @@ public void onDisable() {
Inventory inventory = player.getOpenInventory().getTopInventory();
if (inventory.getViewers().size() == 1) {
VaultViewInfo info = this.inVault.get(player.getUniqueId().toString());
VaultManager.getInstance().saveVault(inventory, player.getUniqueId().toString(), info.getNumber());
VaultManager.getInstance().saveVault(inventory, info.getVaultName(), info.getNumber());
this.openInventories.remove(info.toString());
// try this to make sure that they can't make further edits if the process hangs.
player.closeInventory();
PlayerVaults.scheduler().runAtEntity(player, task -> player.closeInventory());
}

this.inVault.remove(player.getUniqueId().toString());
debug("Closing vault for " + player.getName());
player.closeInventory();
PlayerVaults.scheduler().runAtEntity(player, task -> player.closeInventory());
}
}

Expand Down Expand Up @@ -542,15 +552,15 @@ private void saveSignsFile() {
}
}

public HashMap<String, SignSetInfo> getSetSign() {
public ConcurrentHashMap<String, SignSetInfo> getSetSign() {
return this.setSign;
}

public HashMap<String, VaultViewInfo> getInVault() {
public ConcurrentHashMap<String, VaultViewInfo> getInVault() {
return this.inVault;
}

public HashMap<String, Inventory> getOpenInventories() {
public ConcurrentHashMap<String, Inventory> getOpenInventories() {
return this.openInventories;
}

Expand Down Expand Up @@ -731,7 +741,7 @@ public Component getComponent() {
}
}

private final Set<UUID> told = new HashSet<>();
private final Set<UUID> told = Sets.newConcurrentHashSet();

public void updateNotification(Player player) {
if (updateResponse == null || !player.hasPermission(Permission.ADMIN)) {
Expand Down Expand Up @@ -759,7 +769,7 @@ public <T extends Throwable> T addException(T t) {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
t.printStackTrace(printWriter);
builder.append(stringWriter.toString());
builder.append(stringWriter);
this.exceptions.add(builder.toString());
}
return t;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public boolean onCommand(final CommandSender sender, Command command, String lab
} else {
// Fork into background
this.plugin.getTL().convertBackground().title().send(sender);
PlayerVaults.getInstance().getServer().getScheduler().runTaskLaterAsynchronously(PlayerVaults.getInstance(), () -> {
PlayerVaults.scheduler().runLaterAsync(() -> {
int converted = 0;
VaultOperations.setLocked(true);
for (Converter converter : applicableConverters) {
Expand All @@ -88,4 +88,4 @@ public boolean onCommand(final CommandSender sender, Command command, String lab
}
return true;
}
}
}
Loading