Lobby/src/main/java/eu/univento/lobby/listeners/PlayerHider.java

115 lines
3.8 KiB
Java

/*
* Copyright (c) 2018 univento.eu - All rights reserved
* You are not allowed to use, distribute or modify this code
*/
package eu.univento.lobby.listeners;
import eu.univento.commons.player.rank.Rank;
import eu.univento.core.api.player.CustomPlayer;
import lombok.Getter;
import org.bukkit.Bukkit;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.block.Action;
import org.bukkit.event.player.PlayerInteractEvent;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.ArrayList;
/**
* lets players show/hide other players
* @author joethei
* @version 1.0
*/
public class PlayerHider implements Listener{
@Getter private static ArrayList<CustomPlayer> hidden = new ArrayList<>();
@Getter private static ArrayList<CustomPlayer> silentlobby = new ArrayList<>();
private ItemStack getHide(CustomPlayer p) {
//Messages msgs = new Messages(p);
ItemStack hide = new ItemStack(Material.GLOWSTONE_DUST);
ItemMeta hideMeta = hide.getItemMeta();
//hideMeta.setDisplayName(msgs.LobbyItems_PLAYER_HIDER_ON());
hide.setItemMeta(hideMeta);
return hide;
}
private ItemStack getShow(CustomPlayer p) {
//Messages msgs = new Messages(p);
ItemStack show = new ItemStack(Material.SUGAR);
ItemMeta showMeta = show.getItemMeta();
//showMeta.setDisplayName(msgs.LobbyItems_PLAYER_HIDER_OFF());
show.setItemMeta(showMeta);
return show;
}
@EventHandler
public void onInteract(PlayerInteractEvent e) throws InterruptedException {
CustomPlayer p = CustomPlayer.getPlayer(e.getPlayer().getName());
//Messages msgs = new Messages(p);
if(e.getAction() == Action.RIGHT_CLICK_AIR || e.getAction() == Action.RIGHT_CLICK_BLOCK) {
ItemStack item = p.getItemInHand();
if(item.getType() == Material.SUGAR) {
hidden.remove(p);
Bukkit.getOnlinePlayers().stream().filter(players -> !silentlobby.contains(players)).forEach(p::showPlayer);
//p.sendMessage(msgs.PREFIX() + msgs.Lobby_PLAYERS_SHOW());
p.getInventory().remove(getShow(p));
p.getInventory().addItem(getHide(p));
p.playSound(p.getEyeLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0F, 1.0F);
}
if(item.getType() == Material.GLOWSTONE_DUST) {
hidden.add(p);
for(Player players : Bukkit.getOnlinePlayers()) {
CustomPlayer player = CustomPlayer.getPlayer(players.getName());
if(!player.getDatabasePlayer().isAllowed(Rank.Supporter)) {
p.hidePlayer(players);
}
}
//p.sendMessage(msgs.PREFIX() + msgs.Lobby_PLAYERS_HIDE());
p.getInventory().remove(getHide(p));
p.getInventory().addItem(getShow(p));
p.playSound(p.getEyeLocation(), Sound.ENTITY_ARROW_HIT_PLAYER, 1.0F, 1.0F);
}
if(item.getType() == Material.TNT) {
if(p.getDatabasePlayer().isAllowed(Rank.VIP)) {
if(silentlobby.contains(p)) {
silentlobby.remove(p);
p.getInventory().clear();
//p.sendMessage(msgs.PREFIX() + msgs.Lobby_SILENT_LOBBY_OFF());
for(Player players : Bukkit.getOnlinePlayers()) {
p.showPlayer(players);
if(!hidden.contains(players)) {
players.showPlayer(p);
}
}
}else {
silentlobby.add(p);
//p.sendMessage(msgs.PREFIX() + msgs.Lobby_SILENT_LOBBY_ON());
for(Player players : Bukkit.getOnlinePlayers()) {
p.hidePlayer(players);
players.hidePlayer(p);
}
}
}
}
}
}
}