/* * 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.particle.decorator.CircleParticle; import de.steamwar.lobby.particle.decorator.CloudParticle; 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.Particle; 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 SWInventory createInventory(Player player) { LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); UserGroup userGroup = steamwarUser.getUserGroup(); List> particleList; if (userGroup == UserGroup.Member) { if (steamwarUser.getTeam() != 0) { particleList = new ArrayList<>(TEAM_PARTICLES_ENTRIES); } else { if (TEAM_PARTICLES.contains(lobbyPlayer.getParticle())) { lobbyPlayer.setParticle(null); } particleList = new ArrayList<>(PLAYER_PARTICLES_ENTRIES); } } else { particleList = new ArrayList<>(SERVERTEAM_PARTICLES_ENTRIES); } Set events = steamwarUser.getTeam() == 0 ? new HashSet<>() : TeamTeilnahme.getEvents(steamwarUser.getTeam()).stream().map(Event::getEventID).collect(Collectors.toSet()); for (EventParticle eventParticle : EventParticle.eventParticles) { boolean clickablePlacement = userGroup.isTeamGroup(); clickablePlacement |= (steamwarUser.getTeam() != 0 && contains(eventParticle.placementTeams, steamwarUser.getTeam())); if (clickablePlacement) { particleList.add(new SWListInv.SWListEntry<>(eventParticle.placementParticle.getItem(), eventParticle.placementParticle)); } else { SWItem swItem = eventParticle.placementParticle.getItem(); swItem.setName(swItem.getItemMeta().getDisplayName() + " §8- §c§lGesperrt"); particleList.add(new SWListInv.SWListEntry<>(swItem, null)); } if (eventParticle.placementTeams.length != 0 && (userGroup.isTeamGroup() || events.contains(eventParticle.event))) { particleList.add(new SWListInv.SWListEntry<>(eventParticle.participationParticles.getItem(), eventParticle.participationParticles)); } else { SWItem swItem = eventParticle.participationParticles.getItem(); swItem.setName(swItem.getItemMeta().getDisplayName() + " §8- §c§lGesperrt"); particleList.add(new SWListInv.SWListEntry<>(swItem, null)); } } SWListInv particleSWListInv = new SWListInv<>(player, "§6Partikel", false, particleList, (clickType, particle) -> { if (particle == null) return; lobbyPlayer.setParticle(particle); player.closeInventory(); }); particleSWListInv.setItem(49, Material.BARRIER, "§8Keine Partikel", new ArrayList<>(), false, clickType -> { lobbyPlayer.setParticle(null); }); return particleSWListInv; } 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(); } }