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) {
if(!hiddenPlayerMap.containsKey(clicker)) {
List<Player> list = new ArrayList<>();
hiddenPlayerMap.put(clicker, list);
}
List<Player> players = hiddenPlayerMap.get(clicker);
players.add(target);
hiddenPlayerMap.put(clicker, players);
// TODO: Скрыть никнейм над головой игрока target только для игрока clicker
clicker.hidePlayer(PrivateCore.getInstance(), target);
clicker.showPlayer(PrivateCore.getInstance(), target);
}
private void showPlayer(Player clicker, Player target) {
List<Player> players = hiddenPlayerMap.get(clicker);
players.remove(target);
hiddenPlayerMap.put(clicker, players);
// TODO: Показать никнейм над головой игрока target только для игрока clicker
clicker.hidePlayer(PrivateCore.getInstance(), target);
clicker.showPlayer(PrivateCore.getInstance(), target);
}
private boolean isPlayerHidden(Player clicker, Player target) {
if(!(hiddenPlayerMap.containsKey(clicker))) {
return false;
}
List<Player> players = hiddenPlayerMap.get(clicker);
return players.contains(target);
}