package de.steamwar.lobby.particle; 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.particle.particles.custom.CustomEasterParticle; import de.steamwar.lobby.particle.particles.custom.CustomPlayerParticle; import de.steamwar.lobby.particle.particles.custom.CustomTeamParticle; import de.steamwar.lobby.special.easter.EggHunt; 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.UserConfig; import lombok.experimental.UtilityClass; 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; @UtilityClass public class ParticleInventory { private final Class[] PARTICLES = { PlayerParticle.class, CustomPlayerParticle.class, TeamParticle.class, CustomTeamParticle.class, ServerTeamParticle.class, EventParticle.class, EventParticlePlacement.class, EventParticleParticipation.class, EasterParticle.class, CustomEasterParticle.class, }; public String convertToString(ParticleEnum particleEnum) { return particleEnum.getClass().getSimpleName() + "@" + ((Enum)particleEnum).name(); } public ParticleEnum convertFromString(String string) { String[] split = string.split("@"); Class clazz = null; for (Class aClass : PARTICLES) { if (aClass.getSimpleName().equals(split[0])) { clazz = aClass; break; } } if (clazz != null) { try { return (ParticleEnum) Enum.valueOf((Class) clazz, split[1]); } catch (Exception e) { return null; } } // TODO: Add conversion from last version return null; } public void openInventory(Player player) { LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); SteamwarUser user = SteamwarUser.get(player.getUniqueId()); Set events = user.getTeam() == 0 ? new HashSet<>() : TeamTeilnahme.getEvents(user.getTeam()).stream().map(Event::getEventID).collect(Collectors.toSet()); String eggHuntConfig = UserConfig.getConfig(user.getId(), EggHunt.EGG_HUNT_CONFIG_KEY); List> particleList = new ArrayList<>(); for (Class clazz : PARTICLES) { addParticles(particleList, (ParticleEnum[]) clazz.getEnumConstants(), player, user, events, eggHuntConfig); } 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); }); particleSWListInv.open(); } private void addParticles(List> particleList, ParticleEnum[] particleEnums, Player player, SteamwarUser user, Set events, String eggHuntConfig) { for (ParticleEnum particle : particleEnums) { ParticleData particleData = particle.getParticle(); SWItem swItem = particleData.toSWItem(player, user, events, eggHuntConfig); if (particleData.getRequirement().test(user, events, eggHuntConfig)) { particleList.add(new SWListInv.SWListEntry<>(swItem, particle)); } else { particleList.add(new SWListInv.SWListEntry<>(swItem, null)); } } } }