From 9115c15f91c9b5899ccf0481a97546bbf365c8c4 Mon Sep 17 00:00:00 2001 From: Angelillo15 Date: Fri, 14 Jun 2024 16:58:09 +0200 Subject: [PATCH 1/5] Add NookureStaff Protocol --- .gitmodules | 3 +++ NookureStaff-Protobuf | 1 + 2 files changed, 4 insertions(+) create mode 100644 .gitmodules create mode 160000 NookureStaff-Protobuf diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..65cf18a5 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,3 @@ +[submodule "NookureStaff-Protobuf"] + path = NookureStaff-Protobuf + url = https://github.com/Nookure/NookureStaff-Proto diff --git a/NookureStaff-Protobuf b/NookureStaff-Protobuf new file mode 160000 index 00000000..b8934f84 --- /dev/null +++ b/NookureStaff-Protobuf @@ -0,0 +1 @@ +Subproject commit b8934f84ddc0701322eeedf5bf1af4d653be65f7 From 84ab38d3b65a0c2edbae9cb0655afe860b4fde0b Mon Sep 17 00:00:00 2001 From: Angelillo15 Date: Sun, 16 Jun 2024 21:57:42 +0200 Subject: [PATCH 2/5] Upstream NookureStaff-Protobuf --- NookureStaff-Protobuf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NookureStaff-Protobuf b/NookureStaff-Protobuf index b8934f84..3f4cce05 160000 --- a/NookureStaff-Protobuf +++ b/NookureStaff-Protobuf @@ -1 +1 @@ -Subproject commit b8934f84ddc0701322eeedf5bf1af4d653be65f7 +Subproject commit 3f4cce056c188068919b85bcf99aa7481f162652 From 64597a58ec7f1ef1b3e23369e106588b1455f282 Mon Sep 17 00:00:00 2001 From: Angelillo15 Date: Sun, 16 Jun 2024 22:06:14 +0200 Subject: [PATCH 3/5] Add independent Staff mode permission --- .../src/main/java/com/nookure/staff/api/Permissions.java | 5 +++++ .../com/nookure/staff/paper/command/StaffModeCommand.java | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/NookureStaff-API/src/main/java/com/nookure/staff/api/Permissions.java b/NookureStaff-API/src/main/java/com/nookure/staff/api/Permissions.java index 8d1a6aaf..82e01a23 100644 --- a/NookureStaff-API/src/main/java/com/nookure/staff/api/Permissions.java +++ b/NookureStaff-API/src/main/java/com/nookure/staff/api/Permissions.java @@ -13,6 +13,11 @@ public final class Permissions { * instead of a {@link PlayerWrapper}. */ public static final String STAFF_PERMISSION = "nookure.staff"; + /** + * Permission to use the staff mode. + * This permission is required to use the staff mode. + */ + public static final String STAFF_MODE_PERMISSION = "nookure.staff.mode"; /** * Permission to use the admin commands. * This permission is required to use any admin command. diff --git a/NookureStaff-Paper/src/main/java/com/nookure/staff/paper/command/StaffModeCommand.java b/NookureStaff-Paper/src/main/java/com/nookure/staff/paper/command/StaffModeCommand.java index 9054a050..960139db 100644 --- a/NookureStaff-Paper/src/main/java/com/nookure/staff/paper/command/StaffModeCommand.java +++ b/NookureStaff-Paper/src/main/java/com/nookure/staff/paper/command/StaffModeCommand.java @@ -11,7 +11,7 @@ @CommandData( name = "staff", description = "Main command for staff", - permission = Permissions.STAFF_PERMISSION + permission = Permissions.STAFF_MODE_PERMISSION ) public class StaffModeCommand extends StaffCommand { @Override From 5c2cd39c8930642f361fde823e524c26823018eb Mon Sep 17 00:00:00 2001 From: Angelillo15 Date: Sun, 16 Jun 2024 22:25:13 +0200 Subject: [PATCH 4/5] Fix some synchronization problems --- .../api/manager/PlayerWrapperManager.java | 44 ++++++++++++++++--- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/NookureStaff-API/src/main/java/com/nookure/staff/api/manager/PlayerWrapperManager.java b/NookureStaff-API/src/main/java/com/nookure/staff/api/manager/PlayerWrapperManager.java index 807b7818..daf27ee0 100644 --- a/NookureStaff-API/src/main/java/com/nookure/staff/api/manager/PlayerWrapperManager.java +++ b/NookureStaff-API/src/main/java/com/nookure/staff/api/manager/PlayerWrapperManager.java @@ -2,7 +2,9 @@ import com.google.common.collect.BiMap; import com.google.common.collect.HashBiMap; +import com.google.inject.Inject; import com.google.inject.Singleton; +import com.nookure.staff.api.Logger; import com.nookure.staff.api.PlayerWrapper; import com.nookure.staff.api.StaffPlayerWrapper; import org.jetbrains.annotations.NotNull; @@ -28,6 +30,8 @@ */ @Singleton public final class PlayerWrapperManager { + @Inject + private Logger logger; private final BiMap playerWrappersByPlayerClass = HashBiMap.create(); private final LinkedHashMap playerWrappersByUUID = new LinkedHashMap<>(); private final ArrayList staffPlayers = new ArrayList<>(); @@ -101,10 +105,29 @@ public void addPlayerWrapper(@NotNull T player, @NotNull PlayerWrapper playerWra Objects.requireNonNull(player, "Player cannot be null"); Objects.requireNonNull(playerWrapper, "PlayerWrapper cannot be null"); - playerWrappersByPlayerClass.put(player, playerWrapper); - playerWrappersByUUID.put(playerWrapper.getUniqueId(), playerWrapper); + synchronized (playerWrappersByPlayerClass) { + if (playerWrappersByPlayerClass.containsKey(player)) { + logger.warning("PlayerWrapper already exists for player: %s", player); + return; + } + + playerWrappersByPlayerClass.put(player, playerWrapper); + } + + synchronized (playerWrappersByUUID) { + if (playerWrappersByUUID.containsKey(playerWrapper.getUniqueId())) { + logger.warning("PlayerWrapper already exists for UUID: %s", playerWrapper.getUniqueId()); + return; + } + + playerWrappersByUUID.put(playerWrapper.getUniqueId(), playerWrapper); + } - if (isStaff) staffPlayers.add(playerWrapper.getUniqueId()); + if (isStaff) { + synchronized (staffPlayers) { + staffPlayers.add(playerWrapper.getUniqueId()); + } + } } /** @@ -124,11 +147,18 @@ public void addPlayerWrapper(@NotNull T player, @NotNull PlayerWrapper playerWra */ public void removePlayerWrapper(@NotNull T player) { Objects.requireNonNull(player, "Player cannot be null"); + synchronized (playerWrappersByPlayerClass) { + PlayerWrapper playerWrapper = playerWrappersByPlayerClass.remove(player); + if (playerWrapper == null) { + logger.warning("PlayerWrapper not found for player: %s", player); + return; + } + if (playerWrapper instanceof StaffPlayerWrapper) staffPlayers.remove(playerWrapper.getUniqueId()); - PlayerWrapper playerWrapper = playerWrappersByPlayerClass.remove(player); - playerWrappersByUUID.remove(playerWrapper.getUniqueId()); - - if (playerWrapper instanceof StaffPlayerWrapper) staffPlayers.remove(playerWrapper.getUniqueId()); + synchronized (playerWrappersByUUID) { + playerWrappersByUUID.remove(playerWrapper.getUniqueId()); + } + } } /** From 8046df777b0aa02e193f30ffa0656be099b927b3 Mon Sep 17 00:00:00 2001 From: Angelillo15 Date: Sun, 16 Jun 2024 22:25:24 +0200 Subject: [PATCH 5/5] Bump version --- gradle.properties | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gradle.properties b/gradle.properties index 126cb2c4..078b28ca 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,3 +1,3 @@ major=1 minor=2 -patch=0 \ No newline at end of file +patch=1 \ No newline at end of file