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

124 Zeilen
5.4 KiB
Java

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.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.*;
2023-04-04 14:54:38 +02:00
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;
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;
2023-04-04 14:54:38 +02:00
import de.steamwar.sql.UserConfig;
import lombok.experimental.UtilityClass;
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;
2023-04-07 12:55:43 +02:00
import java.util.concurrent.atomic.AtomicBoolean;
2022-02-12 11:11:16 +01:00
import java.util.stream.Collectors;
2023-04-04 14:54:38 +02:00
@UtilityClass
2022-02-12 11:11:16 +01:00
public class ParticleInventory {
2023-04-04 14:54:38 +02:00
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();
2022-02-12 11:11:16 +01:00
}
2023-04-04 14:54:38 +02:00
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;
}
}
2023-04-04 14:54:38 +02:00
if (clazz != null) {
try {
return (ParticleEnum) Enum.valueOf((Class<? extends Enum>) clazz, split[1]);
} catch (Exception e) {
return null;
}
}
// TODO: Add conversion from last version
return null;
}
2023-04-07 12:55:43 +02:00
public void openInventory(Player player, boolean onlyUnlocked) {
2022-02-12 11:11:16 +01:00
LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId());
2023-04-04 14:54:38 +02:00
SteamwarUser user = SteamwarUser.get(player.getUniqueId());
Set<Integer> 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);
2022-02-12 11:11:16 +01:00
2023-04-07 12:55:43 +02:00
AtomicBoolean hasOneLocked = new AtomicBoolean(false);
2023-04-04 14:54:38 +02:00
List<SWListInv.SWListEntry<ParticleEnum>> particleList = new ArrayList<>();
for (Class<?> clazz : PARTICLES) {
2023-04-07 12:55:43 +02:00
addParticles(particleList, (ParticleEnum[]) clazz.getEnumConstants(), player, onlyUnlocked, hasOneLocked, user, events, eggHuntConfig);
}
for (int i = 0; i < particleList.size() % 45; i++) {
particleList.add(new SWListInv.SWListEntry<>(new SWItem(Material.BLACK_STAINED_GLASS_PANE, " "), null));
2022-04-14 15:03:40 +02:00
}
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
});
2023-04-07 12:55:43 +02:00
particleSWListInv.setItem(48, Material.BARRIER, LobbySystem.getMessage().parse("PARTICLE_DESELECT", player), new ArrayList<>(), false, clickType -> {
2022-02-12 11:11:16 +01:00
lobbyPlayer.setParticle(null);
});
2023-04-07 12:55:43 +02:00
if (!hasOneLocked.get()) {
particleSWListInv.setItem(50, Material.GRAY_BANNER, LobbySystem.getMessage().parse("PARTICLE_SHOW_HAS_ALL", player), new ArrayList<>(), false, clickType -> {
});
} else if (onlyUnlocked) {
particleSWListInv.setItem(50, Material.LIME_BANNER, LobbySystem.getMessage().parse("PARTICLE_SHOW_ALL", player), new ArrayList<>(), false, clickType -> {
openInventory(player, false);
});
} else {
particleSWListInv.setItem(50, Material.RED_BANNER, LobbySystem.getMessage().parse("PARTICLE_SHOW_UNLOCKED", player), new ArrayList<>(), false, clickType -> {
openInventory(player, true);
});
}
2023-04-04 14:54:38 +02:00
particleSWListInv.open();
2022-03-25 09:51:04 +01:00
}
2023-04-07 12:55:43 +02:00
private void addParticles(List<SWListInv.SWListEntry<ParticleEnum>> particleList, ParticleEnum[] particleEnums, Player player, boolean onlyUnlocked, AtomicBoolean hasOneLocked, SteamwarUser user, Set<Integer> events, String eggHuntConfig) {
2023-04-04 14:54:38 +02:00
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 {
2023-04-07 12:55:43 +02:00
hasOneLocked.set(true);
if (!onlyUnlocked) {
particleList.add(new SWListInv.SWListEntry<>(swItem, null));
}
2023-04-04 14:54:38 +02:00
}
2022-02-12 11:11:16 +01:00
}
2023-04-07 12:55:43 +02:00
for (int i = 0; i < particleList.size() % 9; i++) {
particleList.add(new SWListInv.SWListEntry<>(new SWItem(Material.BLACK_STAINED_GLASS_PANE, " "), null));
}
2022-02-12 11:11:16 +01:00
}
}