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-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-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()); + } + } } /** 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 diff --git a/NookureStaff-Protobuf b/NookureStaff-Protobuf new file mode 160000 index 00000000..3f4cce05 --- /dev/null +++ b/NookureStaff-Protobuf @@ -0,0 +1 @@ +Subproject commit 3f4cce056c188068919b85bcf99aa7481f162652 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