Skip to content

Commit

Permalink
Merge pull request #107 from Nookure/dev
Browse files Browse the repository at this point in the history
Release 1.2.1
  • Loading branch information
Angelillo15 authored Jun 16, 2024
2 parents e72d332 + 8046df7 commit b5d4ea2
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 9 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "NookureStaff-Protobuf"]
path = NookureStaff-Protobuf
url = https://github.com/Nookure/NookureStaff-Proto
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +30,8 @@
*/
@Singleton
public final class PlayerWrapperManager<T> {
@Inject
private Logger logger;
private final BiMap<T, PlayerWrapper> playerWrappersByPlayerClass = HashBiMap.create();
private final LinkedHashMap<UUID, PlayerWrapper> playerWrappersByUUID = new LinkedHashMap<>();
private final ArrayList<UUID> staffPlayers = new ArrayList<>();
Expand Down Expand Up @@ -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());
}
}
}

/**
Expand All @@ -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());
}
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions NookureStaff-Protobuf
Submodule NookureStaff-Protobuf added at 3f4cce
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
major=1
minor=2
patch=0
patch=1

0 comments on commit b5d4ea2

Please sign in to comment.