src/main/java/de/viper/survivalplus/Manager/BlockManager.java aktualisiert
This commit is contained in:
@@ -1,37 +1,37 @@
|
|||||||
package de.viper.survivalplus.Manager;
|
package de.viper.survivalplus.Manager;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
public class BlockManager {
|
public class BlockManager {
|
||||||
|
|
||||||
private final Map<UUID, Set<UUID>> blockedPlayers = new HashMap<>();
|
private final Map<UUID, Set<UUID>> blockedPlayers = new HashMap<>();
|
||||||
|
|
||||||
public void blockPlayer(Player blocker, Player toBlock) {
|
public void blockPlayer(Player blocker, Player toBlock) {
|
||||||
blockedPlayers.computeIfAbsent(blocker.getUniqueId(), k -> new HashSet<>()).add(toBlock.getUniqueId());
|
blockedPlayers.computeIfAbsent(blocker.getUniqueId(), k -> new HashSet<>()).add(toBlock.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unblockPlayer(Player blocker, Player toUnblock) {
|
public void unblockPlayer(Player blocker, Player toUnblock) {
|
||||||
Set<UUID> blocked = blockedPlayers.get(blocker.getUniqueId());
|
Set<UUID> blocked = blockedPlayers.get(blocker.getUniqueId());
|
||||||
if (blocked != null) {
|
if (blocked != null) {
|
||||||
blocked.remove(toUnblock.getUniqueId());
|
blocked.remove(toUnblock.getUniqueId());
|
||||||
if (blocked.isEmpty()) {
|
if (blocked.isEmpty()) {
|
||||||
blockedPlayers.remove(blocker.getUniqueId());
|
blockedPlayers.remove(blocker.getUniqueId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasBlocked(Player blocker, Player potentialBlocked) {
|
public boolean hasBlocked(Player blocker, Player potentialBlocked) {
|
||||||
return blockedPlayers.getOrDefault(blocker.getUniqueId(), Collections.emptySet())
|
return blockedPlayers.getOrDefault(blocker.getUniqueId(), Collections.emptySet())
|
||||||
.contains(potentialBlocked.getUniqueId());
|
.contains(potentialBlocked.getUniqueId());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<UUID> getBlockedPlayers(Player player) {
|
public Set<UUID> getBlockedPlayers(Player player) {
|
||||||
return blockedPlayers.getOrDefault(player.getUniqueId(), Collections.emptySet());
|
return blockedPlayers.getOrDefault(player.getUniqueId(), Collections.emptySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clear(Player player) {
|
public void clear(Player player) {
|
||||||
blockedPlayers.remove(player.getUniqueId());
|
blockedPlayers.remove(player.getUniqueId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user