Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
dan28000 committed Sep 24, 2024
1 parent 5b9eb4c commit 95b8a5e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ public BaseProfileManager() {
@EventHandler
public void onPlayerJoin(PlayerJoinEvent event) {
Player player = event.getPlayer();
PlayerBaseProfile profile = databaseManager.getPlayerBaseProfile(player.getName());
profilesCache.put(player.getName(), profile);
databaseManager.restoreInv(player.getUniqueId());
databaseManager.getPlayerBaseProfile(player.getName()).thenAccept(profile -> {
profilesCache.put(player.getName(), profile);
databaseManager.restoreInv(player.getUniqueId());
});
}

@EventHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.time.LocalDate;
import java.time.temporal.TemporalAdjusters;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;

import static com.badbones69.crazycrates.CrazyCrates.LOGGER;
Expand All @@ -50,7 +51,7 @@ public class DatabaseManager {
private final ShopManager shopManager;

public DatabaseManager(List<Crate> crateList) {
connection = BLibs.getApi().getDatabaseHandler().loadSQLite(JavaPlugin.getPlugin(CrazyCrates.class), "gamba", "crates.db");
connection = BLibs.getApi().getDatabaseHandler().loadSQLite(CrazyCrates.getPlugin(), "gamba", "crates.db");
crateSettings = crateList.stream().map(Crate::getCrateSettings).filter(Objects::nonNull).collect(Collectors.toList());
crateSettingsSplit = Lists.partition(crateSettings, 3);
createCrateTable();
Expand Down Expand Up @@ -153,7 +154,6 @@ private void resetLimits() {
LOGGER.warning(e.getMessage());
}
}).join();

}

public void restoreInv(UUID target) {
Expand All @@ -171,7 +171,7 @@ public void restoreInv(UUID target) {

OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(UUID.fromString(uuid));

Bukkit.getScheduler().runTaskLater(CrazyCrates.getPlugin(CrazyCrates.class), () -> {
Bukkit.getScheduler().runTaskLater(CrazyCrates.getPlugin(), () -> {
CMIUser user = CMI.getInstance().getPlayerManager().getUser(offlinePlayer);
Player player = user.getPlayer();

Expand Down Expand Up @@ -273,7 +273,7 @@ public PlayerProfile getPlayerProfile(String playerName, CrateSettings crateSett
}).join();
}

public PlayerBaseProfile getPlayerBaseProfile(String playerName) {
public CompletableFuture<PlayerBaseProfile> getPlayerBaseProfile(String playerName) {
if (!hasPlayerData(playerName)) {
addBlankPlayerData(playerName, null);
}
Expand All @@ -288,7 +288,7 @@ public PlayerBaseProfile getPlayerBaseProfile(String playerName) {
LOGGER.warning(e.getMessage());
}
return null;
}).join();
});
}

public void savePlayerBaseProfile(String playerName, PlayerBaseProfile profile) {
Expand Down Expand Up @@ -353,21 +353,14 @@ private <OUT> OUT deserialize(byte[] profileString) {
}

private byte[] compress(final byte[] data) {
LZ4Factory lz4Factory = LZ4Factory.nativeInstance();
LZ4Compressor fastCompressor = lz4Factory.highCompressor();
int maxCompressedLength = fastCompressor.maxCompressedLength(data.length);
byte[] comp = new byte[maxCompressedLength];
int compressedLength = fastCompressor.compress(data, 0, data.length, comp, 0, maxCompressedLength);

LZ4Compressor fastCompressor = LZ4Factory.fastestInstance().highCompressor();
byte[] comp = new byte[fastCompressor.maxCompressedLength(data.length)];
int compressedLength = fastCompressor.compress(data, 0, data.length, comp, 0, comp.length);
return Arrays.copyOf(comp, compressedLength);
}

private byte[] decompress(final byte[] compressed) {
LZ4Factory lz4Factory = LZ4Factory.nativeInstance();
LZ4SafeDecompressor decompressor = lz4Factory.safeDecompressor();
byte[] decomp = new byte[compressed.length * 100];
decomp = decompressor.decompress(Arrays.copyOf(compressed, compressed.length), decomp.length);

return decomp;
LZ4SafeDecompressor decompressor = LZ4Factory.fastestInstance().safeDecompressor();
return decompressor.decompress(compressed, compressed.length * 100);
}
}

0 comments on commit 95b8a5e

Please sign in to comment.