13
0
Dieses Repository wurde am 2024-08-05 archiviert. Du kannst Dateien ansehen und es klonen, aber nicht pushen oder Issues/Pull-Requests öffnen.
LobbySystem2.0/src/de/steamwar/lobby/particle/ParticleInventory.java

111 Zeilen
4.6 KiB
Java

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 16:54:29 +01:00
import de.steamwar.lobby.particle.decorator.CircleParticle;
import de.steamwar.lobby.particle.decorator.CloudParticle;
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.Particle;
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() {
}
private static SWInventory createInventory(Player player) {
LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId());
SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId());
UserGroup userGroup = steamwarUser.getUserGroup();
List<SWListInv.SWListEntry<SpecialParticle>> 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<Integer> 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<SpecialParticle> particleSWListInv = new SWListInv<>(player, "§6Partikel", false, particleList, (clickType, particle) -> {
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
});
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();
}
}