private final Map<Player, List<Player>> hiddenPlayerMap = new HashMap<>();
@EventHandler
public void playerClickEvent(PlayerInteractEntityEvent event) {
if(!(event.getRightClicked() instanceof Player target)) {
return;
}
Player clicker = event.getPlayer();
if(isPlayerHidden(clicker, target)) {
showPlayer(clicker, target);
} else {
hidePlayer(clicker, target);
}
}
private void hidePlayer(Player clicker, Player target) {
List<Player> players = hiddenPlayerMap.get(clicker);
players.add(target);
hiddenPlayerMap.put(clicker, players);
// TODO: Скрыть никнейм над головой игрока target только для игрока clicker
}
private void showPlayer(Player clicker, Player target) {
List<Player> players = hiddenPlayerMap.get(clicker);
players.remove(target);
hiddenPlayerMap.put(clicker, players);
// TODO: Показать никнейм над головой игрока target только для игрока clicker
}
private boolean isPlayerHidden(Player clicker, Player target) {
if(!(hiddenPlayerMap.containsKey(clicker))) {
return false;
}
List<Player> players = hiddenPlayerMap.get(clicker);
return players.contains(target);
}