/* * This file is a part of the SteamWar software. * * Copyright (C) 2021 SteamWar.de-Serverteam * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU Affero General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Affero General Public License for more details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ package de.steamwar.lobby.particle; import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; import de.steamwar.inventory.SWListInv; import de.steamwar.lobby.LobbySystem; import de.steamwar.lobby.particle.particles.*; import de.steamwar.lobby.util.LobbyPlayer; import de.steamwar.sql.Event; import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.TeamTeilnahme; import de.steamwar.sql.UserGroup; import org.bukkit.Material; import org.bukkit.entity.Player; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; import java.util.stream.Collectors; public class ParticleInventory { private ParticleInventory() { } private static void calculateParticles(ParticleEnum[] particles, Player player, List> particleList) { for (ParticleEnum particle : particles) { particleList.add(new SWListInv.SWListEntry<>(particle.getParticle().getItem().toSWItem(player), particle)); } } private static SWInventory createInventory(Player player) { LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); UserGroup userGroup = steamwarUser.getUserGroup(); List> particleList = new ArrayList<>(); calculateParticles(PlayerParticle.particles, player, particleList); if (steamwarUser.getTeam() != 0 || userGroup != UserGroup.Member) { calculateParticles(TeamParticle.particles, player, particleList); } if (userGroup != UserGroup.Member) { calculateParticles(ServerTeamParticle.particles, player, particleList); } Set events = steamwarUser.getTeam() == 0 ? new HashSet<>() : TeamTeilnahme.getEvents(steamwarUser.getTeam()).stream().map(Event::getEventID).collect(Collectors.toSet()); if (!events.isEmpty()) { calculateParticles(EventParticle.particles, player, particleList); } for (EventParticlePlacement particle : EventParticlePlacement.particles) { boolean clickable = userGroup.isTeamGroup(); clickable |= (steamwarUser.getTeam() != 0 && contains(particle.getPlacementTeams(), steamwarUser.getTeam())); addParticle(particleList, particle, clickable, player); } for (EventParticleParticipation particle : EventParticleParticipation.particles) { boolean clickable = userGroup.isTeamGroup(); clickable |= events.contains(particle.getEvent()); addParticle(particleList, particle, clickable, player); } for (SpecialTeamParticle particle : SpecialTeamParticle.particles) { if (particle.getTeamId() == 0 || steamwarUser.getTeam() == particle.getTeamId()) { addParticle(particleList, particle, true, player); } } SWListInv particleSWListInv = new SWListInv<>(player, LobbySystem.getMessage().parse("PARTICLE_INVENTORY", player), false, particleList, (clickType, particle) -> { if (particle == null) return; lobbyPlayer.setParticle(particle); player.closeInventory(); }); particleSWListInv.setItem(49, Material.BARRIER, LobbySystem.getMessage().parse("PARTICLE_DESELECT", player), new ArrayList<>(), false, clickType -> { lobbyPlayer.setParticle(null); }); return particleSWListInv; } private static void addParticle(List> particleList, ParticleEnum particle, boolean clickable, Player player) { if (clickable) { particleList.add(new SWListInv.SWListEntry<>(particle.getParticle().getItem().toSWItem(player), particle)); } else { SWItem swItem = particle.getParticle().getItem().toSWItem(player); swItem.setName(LobbySystem.getMessage().parse("PARTICLE_LOCKED", player, swItem.getItemMeta().getDisplayName())); particleList.add(new SWListInv.SWListEntry<>(swItem, null)); } } private static boolean contains(int[] ints, int element) { for (int i : ints) { if (i == element) return true; } return false; } public static void openParticleInventory(Player player) { createInventory(player).open(); } }