Skip to content
Draft
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ target/
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
replay_pid*
SimplePMs.iml
*.iml
41 changes: 41 additions & 0 deletions common/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>simplexity.simplepms</groupId>
<artifactId>common</artifactId>
<version>2.4.2</version>

<parent>
<groupId>simplexity</groupId>
<artifactId>SimplePMs</artifactId>
<version>2.4.2</version>
</parent>

<build>
<finalName>${project.parent.artifactId}-${project.artifactId}-${project.version}</finalName>
</build>

<properties>
<maven.compiler.source>21</maven.compiler.source>
<maven.compiler.target>21</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<dependencies>
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>6.3.0</version>
</dependency>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>26.0.2</version>
<scope>compile</scope>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package simplexity.simplepms.saving;
package com.simplexity.simplepms.common.database;

import org.bukkit.Bukkit;
import org.bukkit.entity.Player;
import simplexity.simplepms.SimplePMs;
import simplexity.simplepms.config.LocaleMessage;
import simplexity.simplepms.saving.objects.PlayerBlock;
import simplexity.simplepms.saving.objects.PlayerSettings;
import com.simplexity.simplepms.common.logic.LocaleKey;
import com.simplexity.simplepms.common.logic.PlatformBridge;
import com.simplexity.simplepms.common.database.objects.PlayerBlock;
import com.simplexity.simplepms.common.database.objects.PlayerSettings;

import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -17,7 +15,7 @@
public class Cache {
public static final HashMap<UUID, List<PlayerBlock>> blockList = new HashMap<>();
public static final HashMap<UUID, PlayerSettings> playerSettings = new HashMap<>();
public static final HashSet<Player> spyingPlayers = new HashSet<>();
public static final HashSet<UUID> spyingPlayers = new HashSet<>();

public static List<PlayerBlock> getBlockList(UUID uuid) {
return blockList.get(uuid);
Expand All @@ -27,20 +25,16 @@ public static PlayerSettings getPlayerSettings(UUID uuid) {
return playerSettings.get(uuid);
}

public static void populateCache(UUID uuid, boolean hasSpyPerms) {
List<PlayerBlock> blocklist = SQLHandler.getInstance().getBlockedPlayers(uuid);
blockList.put(uuid, blocklist);
populateNullNames(uuid);

public static void populateCache(UUID uuid, Player player, boolean hasSpyPerms) {
Bukkit.getScheduler().runTaskAsynchronously(SimplePMs.getInstance(), () -> {
SqlHandler.getInstance().getBlockedPlayers(uuid).thenAccept(blocklist -> {
blockList.put(uuid, blocklist);
populateNullNames(uuid);
});
SqlHandler.getInstance().getSettings(uuid).thenAccept(settings -> {
playerSettings.put(uuid, settings);
if (hasSpyPerms && settings.isSocialSpyEnabled()) {
spyingPlayers.add(player);
}
});
});
PlayerSettings settings = SQLHandler.getInstance().getSettings(uuid);
playerSettings.put(uuid, settings);
if (hasSpyPerms && settings.isSocialSpyEnabled()) {
spyingPlayers.add(uuid);
}
}

/**
Expand Down Expand Up @@ -71,7 +65,7 @@ public static void updateSocialSpySettings(UUID uuid, boolean socialSpy) {
PlayerSettings settings = playerSettings.get(uuid);
settings.setSocialSpyEnabled(socialSpy);
playerSettings.put(uuid, settings);
SqlHandler.getInstance().updateSettings(uuid, settings.isSocialSpyEnabled(), settings.areMessagesDisabled());
SQLHandler.getInstance().updateSettings(uuid, settings.isSocialSpyEnabled(), settings.areMessagesDisabled());
}

/**
Expand All @@ -84,7 +78,7 @@ public static void updateMessageSettings(UUID uuid, boolean messageDisabled) {
PlayerSettings settings = playerSettings.get(uuid);
settings.setMessagesDisabled(messageDisabled);
playerSettings.put(uuid, settings);
SqlHandler.getInstance().updateSettings(uuid, settings.isSocialSpyEnabled(), settings.areMessagesDisabled());
SQLHandler.getInstance().updateSettings(uuid, settings.isSocialSpyEnabled(), settings.areMessagesDisabled());
}

/**
Expand All @@ -99,7 +93,7 @@ public static void addBlockedUser(UUID uuid, PlayerBlock playerBlock) {
List<PlayerBlock> blockedPlayers = blockList.get(uuid);
blockedPlayers.add(playerBlock);
blockList.put(uuid, blockedPlayers);
SqlHandler.getInstance().addBlockedPlayer(uuid, playerBlock.getBlockedPlayerUUID(), playerBlock.getBlockedPlayerName(), playerBlock.getBlockReason());
SQLHandler.getInstance().addBlockedPlayer(uuid, playerBlock.getBlockedPlayerUUID(), playerBlock.getBlockedPlayerName(), playerBlock.getBlockReason());
}

/**
Expand All @@ -117,7 +111,7 @@ public static void removeBlockedUser(UUID uuid, UUID blockedPlayerUuid) {
}
}
blockList.put(uuid, userBlockList);
SqlHandler.getInstance().removeBlockedPlayer(uuid, blockedPlayerUuid);
SQLHandler.getInstance().removeBlockedPlayer(uuid, blockedPlayerUuid);
}

private static void removeCachedDuplicates(UUID blockingUuid, UUID blockedUuid) {
Expand All @@ -132,15 +126,15 @@ private static void populateNullNames(UUID uuidToCheck) {
if (playerBlocks == null || playerBlocks.isEmpty()) return;
for (PlayerBlock block : playerBlocks) {
if (block.getBlockedPlayerName() == null || block.getBlockedPlayerName().isEmpty()) {
String newName = Bukkit.getOfflinePlayer(block.getBlockedPlayerUUID()).getName();
if (newName == null) newName = LocaleMessage.ERROR_NAME_NOT_FOUND.getMessage();
String newName = PlatformBridge.getPlatformAdapter().getPlayerName(block.getBlockedPlayerUUID());
if (newName == null) newName = PlatformBridge.getPlatformAdapter().getLocaleString(LocaleKey.ERROR_NAME_NOT_FOUND);
block.setBlockedPlayerName(newName);
}
}
blockList.put(uuidToCheck, playerBlocks);
}

public static Set<Player> getSpyingPlayers() {
public static Set<UUID> getSpyingPlayers() {
return spyingPlayers;
}
}
Loading