2022-03-10 13:09:04 +01:00
|
|
|
/*
|
|
|
|
* This file is a part of the SteamWar software.
|
|
|
|
*
|
2022-03-10 14:56:20 +01:00
|
|
|
* Copyright (C) 2021 SteamWar.de-Serverteam
|
2022-03-10 13:09:04 +01:00
|
|
|
*
|
|
|
|
* 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 <https://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2022-03-10 14:56:20 +01:00
|
|
|
package de.steamwar.lobby.particle;
|
2022-02-12 11:11:16 +01:00
|
|
|
|
|
|
|
import de.steamwar.inventory.SWInventory;
|
|
|
|
import de.steamwar.inventory.SWItem;
|
|
|
|
import de.steamwar.inventory.SWListInv;
|
2022-03-24 17:07:39 +01:00
|
|
|
import de.steamwar.lobby.LobbySystem;
|
2022-03-25 09:57:38 +01:00
|
|
|
import de.steamwar.lobby.particle.particles.*;
|
2022-02-12 11:11:16 +01:00
|
|
|
import de.steamwar.lobby.util.LobbyPlayer;
|
2022-03-10 14:56:20 +01:00
|
|
|
import de.steamwar.sql.Event;
|
|
|
|
import de.steamwar.sql.SteamwarUser;
|
|
|
|
import de.steamwar.sql.TeamTeilnahme;
|
|
|
|
import de.steamwar.sql.UserGroup;
|
2022-02-12 11:11:16 +01:00
|
|
|
import org.bukkit.Material;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
2022-03-10 14:56:20 +01:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.Set;
|
2022-02-12 11:11:16 +01:00
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
public class ParticleInventory {
|
|
|
|
|
|
|
|
private ParticleInventory() {
|
|
|
|
}
|
|
|
|
|
2022-03-25 09:51:04 +01:00
|
|
|
private static void calculateParticles(ParticleEnum[] particles, Player player, List<SWListInv.SWListEntry<ParticleEnum>> particleList) {
|
2022-03-24 17:01:47 +01:00
|
|
|
for (ParticleEnum particle : particles) {
|
2022-03-25 09:51:04 +01:00
|
|
|
particleList.add(new SWListInv.SWListEntry<>(particle.getParticle().getItem().toSWItem(player), particle));
|
2022-03-24 17:01:47 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-12 11:11:16 +01:00
|
|
|
private static SWInventory createInventory(Player player) {
|
|
|
|
LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId());
|
|
|
|
SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId());
|
|
|
|
UserGroup userGroup = steamwarUser.getUserGroup();
|
|
|
|
|
2022-03-25 09:51:04 +01:00
|
|
|
List<SWListInv.SWListEntry<ParticleEnum>> particleList = new ArrayList<>();
|
2022-03-24 17:01:47 +01:00
|
|
|
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);
|
2022-02-12 11:11:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Set<Integer> events = steamwarUser.getTeam() == 0 ? new HashSet<>() : TeamTeilnahme.getEvents(steamwarUser.getTeam()).stream().map(Event::getEventID).collect(Collectors.toSet());
|
2022-03-25 10:23:49 +01:00
|
|
|
if (!events.isEmpty()) {
|
|
|
|
calculateParticles(EventParticle.particles, player, particleList);
|
|
|
|
}
|
2022-03-25 09:51:04 +01:00
|
|
|
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);
|
2022-02-12 11:11:16 +01:00
|
|
|
}
|
|
|
|
|
2022-03-25 09:51:04 +01:00
|
|
|
SWListInv<ParticleEnum> particleSWListInv = new SWListInv<>(player, LobbySystem.getMessage().parse("PARTICLE_INVENTORY", player), false, particleList, (clickType, particle) -> {
|
2022-02-12 11:11:16 +01:00
|
|
|
if (particle == null) return;
|
|
|
|
lobbyPlayer.setParticle(particle);
|
2022-03-10 14:56:20 +01:00
|
|
|
player.closeInventory();
|
2022-02-12 11:11:16 +01:00
|
|
|
});
|
2022-03-24 17:07:39 +01:00
|
|
|
particleSWListInv.setItem(49, Material.BARRIER, LobbySystem.getMessage().parse("PARTICLE_DESELECT", player), new ArrayList<>(), false, clickType -> {
|
2022-02-12 11:11:16 +01:00
|
|
|
lobbyPlayer.setParticle(null);
|
|
|
|
});
|
|
|
|
|
|
|
|
return particleSWListInv;
|
|
|
|
}
|
|
|
|
|
2022-03-25 09:51:04 +01:00
|
|
|
private static void addParticle(List<SWListInv.SWListEntry<ParticleEnum>> 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));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-02-12 11:11:16 +01:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|