From 7c16a7a315e46aed6ce2f580380d0582964c12c0 Mon Sep 17 00:00:00 2001 From: yoyosource Date: Thu, 24 Mar 2022 17:01:47 +0100 Subject: [PATCH] Update ParticleListener Update LobbyPlayer Update ParticleInventory --- .../lobby/listener/ParticleListener.java | 13 ++++---- .../lobby/particle/EventParticle.java | 9 +++--- .../lobby/particle/ParticleInventory.java | 30 +++++++++---------- src/de/steamwar/lobby/util/LobbyPlayer.java | 14 ++++----- 4 files changed, 34 insertions(+), 32 deletions(-) diff --git a/src/de/steamwar/lobby/listener/ParticleListener.java b/src/de/steamwar/lobby/listener/ParticleListener.java index 9b408e2..d9b6688 100644 --- a/src/de/steamwar/lobby/listener/ParticleListener.java +++ b/src/de/steamwar/lobby/listener/ParticleListener.java @@ -20,8 +20,9 @@ package de.steamwar.lobby.listener; import de.steamwar.lobby.LobbySystem; +import de.steamwar.lobby.particle.BaseParticle; +import de.steamwar.lobby.particle.ParticleData; import de.steamwar.lobby.particle.ParticleInventory; -import de.steamwar.lobby.particle.SpecialParticle; import de.steamwar.lobby.util.LobbyPlayer; import org.bukkit.Bukkit; import org.bukkit.entity.Player; @@ -40,9 +41,11 @@ public class ParticleListener extends BasicListener { if (deg > 360) deg = 0; Bukkit.getOnlinePlayers().forEach(player -> { LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); - SpecialParticle particle = lobbyPlayer.getParticle(); + BaseParticle particle = lobbyPlayer.getParticle(); if (particle == null) return; - particle.execute(player.getWorld(), player, deg); + if (particle.needsTick()) { + particle.particle(new ParticleData(player.getWorld(), player, deg)); + } }); }, 0, 1); } @@ -59,9 +62,9 @@ public class ParticleListener extends BasicListener { public void handlePlayerMove(PlayerMoveEvent event) { Player player = event.getPlayer(); LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); - SpecialParticle particle = lobbyPlayer.getParticle(); + BaseParticle particle = lobbyPlayer.getParticle(); if (particle == null) return; - particle.execute(player.getWorld(), player, deg); + particle.particle(new ParticleData(player.getWorld(), player, deg)); } } diff --git a/src/de/steamwar/lobby/particle/EventParticle.java b/src/de/steamwar/lobby/particle/EventParticle.java index 2268766..e5e6ea8 100644 --- a/src/de/steamwar/lobby/particle/EventParticle.java +++ b/src/de/steamwar/lobby/particle/EventParticle.java @@ -19,6 +19,8 @@ package de.steamwar.lobby.particle; +import de.steamwar.lobby.particle.decorator.CircleParticle; +import de.steamwar.lobby.particle.decorator.CloudParticle; import org.bukkit.Material; import org.bukkit.Particle; @@ -31,16 +33,15 @@ public enum EventParticle { public static EventParticle[] eventParticles = values(); - EventParticle(int event, int[] placementTeams, SpecialParticle placementParticle, SpecialParticle participationParticles) { + EventParticle(int event, int[] placementTeams, BaseParticle placementParticle, BaseParticle participationParticles) { this.event = event; this.placementTeams = placementTeams; this.placementParticle = placementParticle; this.participationParticles = participationParticles; - } public final int event; public final int[] placementTeams; - public final SpecialParticle placementParticle; - public final SpecialParticle participationParticles; + public final BaseParticle placementParticle; + public final BaseParticle participationParticles; } diff --git a/src/de/steamwar/lobby/particle/ParticleInventory.java b/src/de/steamwar/lobby/particle/ParticleInventory.java index b95c73e..bed37dc 100644 --- a/src/de/steamwar/lobby/particle/ParticleInventory.java +++ b/src/de/steamwar/lobby/particle/ParticleInventory.java @@ -22,15 +22,12 @@ 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; @@ -44,23 +41,24 @@ public class ParticleInventory { private ParticleInventory() { } + private static void calculateParticles(ParticleEnum[] particles, Player player, List> particleList) { + for (ParticleEnum particle : particles) { + particleList.add(new SWListInv.SWListEntry<>(particle.getParticle().getItem().toSWItem(player), particle.getParticle())); + } + } + 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); + List> particleList = new ArrayList<>(); + 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); } Set events = steamwarUser.getTeam() == 0 ? new HashSet<>() : TeamTeilnahme.getEvents(steamwarUser.getTeam()).stream().map(Event::getEventID).collect(Collectors.toSet()); @@ -84,7 +82,7 @@ public class ParticleInventory { } } - SWListInv particleSWListInv = new SWListInv<>(player, "§6Partikel", false, particleList, (clickType, particle) -> { + SWListInv particleSWListInv = new SWListInv<>(player, "§6Partikel", false, particleList, (clickType, particle) -> { if (particle == null) return; lobbyPlayer.setParticle(particle); player.closeInventory(); diff --git a/src/de/steamwar/lobby/util/LobbyPlayer.java b/src/de/steamwar/lobby/util/LobbyPlayer.java index ed0a018..a3d5ba1 100644 --- a/src/de/steamwar/lobby/util/LobbyPlayer.java +++ b/src/de/steamwar/lobby/util/LobbyPlayer.java @@ -19,7 +19,7 @@ package de.steamwar.lobby.util; -import de.steamwar.lobby.particle.SpecialParticle; +import de.steamwar.lobby.particle.BaseParticle; import org.bukkit.entity.Player; import java.util.HashMap; @@ -30,13 +30,13 @@ public class LobbyPlayer { private static Map cache = new HashMap<>(); - private SpecialParticle specialParticle; + private BaseParticle particle; private boolean fly; private LobbyPlayer(UUID uuid) { cache.put(uuid, this); - specialParticle = null; + particle = null; } public boolean isFlying() { @@ -47,12 +47,12 @@ public class LobbyPlayer { this.fly = fly; } - public SpecialParticle getParticle() { - return specialParticle; + public BaseParticle getParticle() { + return particle; } - public void setParticle(SpecialParticle specialParticle) { - this.specialParticle = specialParticle; + public void setParticle(BaseParticle specialParticle) { + this.particle = specialParticle; } public static LobbyPlayer getLobbyPlayer(UUID uuid) {