diff --git a/src/de/steamwar/lobby/inventories/ParticleInventory.java b/src/de/steamwar/lobby/inventories/ParticleInventory.java index d137fe7..bfa6db1 100644 --- a/src/de/steamwar/lobby/inventories/ParticleInventory.java +++ b/src/de/steamwar/lobby/inventories/ParticleInventory.java @@ -20,6 +20,7 @@ package de.steamwar.lobby.inventories; import de.steamwar.inventory.SWInventory; +import de.steamwar.inventory.SWListInv; import de.steamwar.lobby.particle.CircleParticle; import de.steamwar.lobby.particle.FunctionalParticle; import de.steamwar.lobby.particle.SimpleParticle; @@ -29,9 +30,9 @@ import de.steamwar.sql.SteamwarUser; import de.steamwar.sql.UserGroup; import org.bukkit.Material; import org.bukkit.Particle; -import org.bukkit.block.data.type.Fire; import org.bukkit.entity.Player; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -42,65 +43,60 @@ public class ParticleInventory { private static final List lore = Arrays.asList("§aKlicken zum Auswählen"); - private static final SpecialParticle SNEEZE = new SimpleParticle(Material.SLIME_BLOCK, "§aSneeze", lore, Particle.SNEEZE, 0.2F, 0.2F, 0.2F, 0.01); - private static final SpecialParticle SMOKE = new SimpleParticle(Material.COBWEB, "§7Smoke", lore, Particle.SMOKE_NORMAL, 0.2F, 0.2F, 0.2F, 0.01); - private static final SpecialParticle FLAME = new SimpleParticle(Material.LAVA_BUCKET, "§cFeuer", lore, Particle.DRIP_LAVA); - private static final SpecialParticle WATER = new SimpleParticle(Material.WATER_BUCKET, "§bWasser", lore, Particle.DRIP_WATER); - private static final SpecialParticle HEART = new FunctionalParticle(Material.RED_DYE, "§cHerzen", lore, (world, player, integer) -> world.spawnParticle(Particle.HEART, player.getLocation().add(0, 2.2, 0), 5)); - private static final SpecialParticle NOTES = new FunctionalParticle(Material.NOTE_BLOCK, "§eNoten", lore, (world, player, integer) -> world.spawnParticle(Particle.NOTE, player.getLocation().add(0, 2.2, 0), 5)); - private static final SpecialParticle NAUTILIS = new SimpleParticle(Material.NAUTILUS_SHELL, "§aNautilis", lore, Particle.NAUTILUS, 0.2F, 0F, 0.2F, 0.01); + private static final List playerParticles = new ArrayList<>(); + private static final List teamParticles = new ArrayList<>(); - private static final SpecialParticle SNOWBALL = new SimpleParticle(Material.SNOWBALL, "§fSnowball", lore, Particle.SNOWBALL, 0.2F, 0F, 0.2F, 0.01); - private static final SpecialParticle EFFECT = new SimpleParticle(Material.GLASS_BOTTLE, "§5Effekt", lore, Particle.REDSTONE, 0F, 0.2F, 0F, 0.01); - private static final SpecialParticle CAMPFIRE = new SimpleParticle(Material.CAMPFIRE, "§7Rauch", lore, Particle.CAMPFIRE_COSY_SMOKE, 0.0F, 0.2F, 0F, 0.01); - private static final SpecialParticle MAGIC = new SimpleParticle(Material.CAULDRON, "§5Magie", lore, Particle.CRIT_MAGIC, 0.2F, 0.2F, 0.2F, 0.01); - private static final SpecialParticle RAGE = new SimpleParticle(Material.REDSTONE_BLOCK, "§4Wut", lore, Particle.VILLAGER_ANGRY, 0.2F, 0.02F, 0.2F, 0.01); - private static final SpecialParticle SLIME = new SimpleParticle(Material.SLIME_BALL, "§aSchleim", lore, Particle.SLIME); - private static final SpecialParticle MOB = new SimpleParticle(Material.ZOMBIE_HEAD, "§7Mob", lore, Particle.SPELL_MOB); + private static final List> playerParticlesEntries = new ArrayList<>(); + private static final List> teamParticlesEntries = new ArrayList<>(); - private static final SpecialParticle DAMAGE = new SimpleParticle(Material.SPIDER_EYE, "§5Damage", lore, Particle.DAMAGE_INDICATOR, 0.2F, 0F, 0.2F, 0.01); - private static final SpecialParticle WITCH = new SimpleParticle(Material.EXPERIENCE_BOTTLE, "§5Hexe", lore, Particle.SPELL_WITCH); - private static final SpecialParticle ENCHANTING = new SimpleParticle(Material.ENCHANTING_TABLE, "§eZauber", lore, Particle.ENCHANTMENT_TABLE); - private static final SpecialParticle FRIEND = new SimpleParticle(Material.EMERALD_BLOCK, "§2Freude", lore, Particle.VILLAGER_HAPPY, 0.2F, 0.2F, 0.2F, 0.01); - private static final SpecialParticle FIRE = new SimpleParticle(Material.FLINT_AND_STEEL, "§7Flammen", lore, Particle.FLAME, 0F, 0.2F, 0F, 0.01); - private static final SpecialParticle TOTEM = new SimpleParticle(Material.TOTEM_OF_UNDYING, "§aTotem", lore, Particle.TOTEM, 0F, 0.2F, 0F, 0.01); - private static final SpecialParticle END = new SimpleParticle(Material.END_ROD, "§fEnd Rod", lore, Particle.END_ROD, 0.2F, 0.2F, 0.2F, 0.01); + static { + playerParticles.add(new SimpleParticle(Material.SLIME_BLOCK, "§aSneeze", lore, Particle.SNEEZE, 0.2F, 0.2F, 0.2F, 0.01)); + playerParticles.add(new SimpleParticle(Material.COBWEB, "§7Smoke", lore, Particle.SMOKE_NORMAL, 0.2F, 0.2F, 0.2F, 0.01)); + playerParticles.add(new SimpleParticle(Material.LAVA_BUCKET, "§cFeuer", lore, Particle.DRIP_LAVA)); + playerParticles.add(new SimpleParticle(Material.WATER_BUCKET, "§bWasser", lore, Particle.DRIP_WATER)); + playerParticles.add(new FunctionalParticle(Material.RED_DYE, "§cHerzen", lore, (world, player, integer) -> world.spawnParticle(Particle.HEART, player.getLocation().add(0, 2.2, 0), 5))); + playerParticles.add(new FunctionalParticle(Material.NOTE_BLOCK, "§eNoten", lore, (world, player, integer) -> world.spawnParticle(Particle.NOTE, player.getLocation().add(0, 2.2, 0), 5))); + playerParticles.add(new SimpleParticle(Material.NAUTILUS_SHELL, "§aNautilis", lore, Particle.NAUTILUS, 0.2F, 0F, 0.2F, 0.01)); + playerParticles.add(new SimpleParticle(Material.SNOWBALL, "§fSnowball", lore, Particle.SNOWBALL, 0.2F, 0F, 0.2F, 0.01)); + playerParticles.add(new SimpleParticle(Material.GLASS_BOTTLE, "§5Effekt", lore, Particle.REDSTONE, 0F, 0.2F, 0F, 0.01)); + playerParticles.add(new SimpleParticle(Material.CAMPFIRE, "§7Rauch", lore, Particle.CAMPFIRE_COSY_SMOKE, 0.0F, 0.2F, 0F, 0.01)); + playerParticles.add(new SimpleParticle(Material.CAULDRON, "§5Magie", lore, Particle.CRIT_MAGIC, 0.2F, 0.2F, 0.2F, 0.01)); + playerParticles.add(new SimpleParticle(Material.REDSTONE_BLOCK, "§4Wut", lore, Particle.VILLAGER_ANGRY, 0.2F, 0.02F, 0.2F, 0.01)); + playerParticles.add(new SimpleParticle(Material.SLIME_BALL, "§aSchleim", lore, Particle.SLIME)); + playerParticles.add(new SimpleParticle(Material.ZOMBIE_HEAD, "§7Mob", lore, Particle.SPELL_MOB)); - private static final SpecialParticle FIRE_RING = new CircleParticle(Material.MAGMA_BLOCK, "§7Flammen Ring", lore, Particle.FLAME, location -> location.add(0, 1.1, 0)); + teamParticles.addAll(playerParticles); + teamParticles.add(new SimpleParticle(Material.SPIDER_EYE, "§5Damage", lore, Particle.DAMAGE_INDICATOR, 0.2F, 0F, 0.2F, 0.01)); + teamParticles.add(new SimpleParticle(Material.EXPERIENCE_BOTTLE, "§5Hexe", lore, Particle.SPELL_WITCH)); + teamParticles.add(new SimpleParticle(Material.ENCHANTING_TABLE, "§eZauber", lore, Particle.ENCHANTMENT_TABLE)); + teamParticles.add(new SimpleParticle(Material.EMERALD_BLOCK, "§2Freude", lore, Particle.VILLAGER_HAPPY, 0.2F, 0.2F, 0.2F, 0.01)); + teamParticles.add(new SimpleParticle(Material.FLINT_AND_STEEL, "§7Flammen", lore, Particle.FLAME, 0F, 0.2F, 0F, 0.01)); + teamParticles.add(new SimpleParticle(Material.TOTEM_OF_UNDYING, "§aTotem", lore, Particle.TOTEM, 0F, 0.2F, 0F, 0.01)); + teamParticles.add(new SimpleParticle(Material.END_ROD, "§fEnd Rod", lore, Particle.END_ROD, 0.2F, 0.2F, 0.2F, 0.01)); + teamParticles.add(new CircleParticle(Material.MAGMA_BLOCK, "§7Flammen Ring", lore, Particle.FLAME, location -> location.add(0, 1.1, 0), 0F, 0.0F, 0F, 0.01)); + teamParticles.add(new CircleParticle(Material.ENCHANTED_BOOK, "§fEnchanted Ring", lore, Particle.ENCHANTMENT_TABLE, location -> location.add(0, 1.1, 0), 0.0F, 0.0F, 0.0F, 0.01)); + teamParticles.add(new CircleParticle(Material.NOTE_BLOCK, "§eNoten Ring", lore, Particle.NOTE, location -> location.add(0, 2.2, 0), 0.0F, 0.0F, 0.0F, 0.01)); - private static final SpecialParticle[] row_1 = new SpecialParticle[]{SNEEZE, SMOKE, FLAME, WATER, HEART, NOTES, NAUTILIS}; - private static final SpecialParticle[] row_2 = new SpecialParticle[]{SNOWBALL, EFFECT, CAMPFIRE, MAGIC, RAGE, SLIME, MOB}; - private static final SpecialParticle[] row_3 = new SpecialParticle[]{DAMAGE, WITCH, ENCHANTING, FRIEND, FIRE, TOTEM, END}; - private static final SpecialParticle[] row_4 = new SpecialParticle[]{FIRE_RING}; + playerParticles.forEach(specialParticle -> playerParticlesEntries.add(new SWListInv.SWListEntry<>(specialParticle.getItem(), specialParticle))); + teamParticles.forEach(specialParticle -> teamParticlesEntries.add(new SWListInv.SWListEntry<>(specialParticle.getItem(), specialParticle))); + } private static SWInventory createInventory(Player player) { LobbyPlayer lobbyPlayer = LobbyPlayer.getLobbyPlayer(player.getUniqueId()); SteamwarUser steamwarUser = SteamwarUser.get(player.getUniqueId()); UserGroup userGroup = steamwarUser.getUserGroup(); - SWInventory swInventory = new SWInventory(player, 9 * (userGroup == UserGroup.Member ? 5 : 6), "§6Partikel"); - - add(swInventory, row_1, 10, lobbyPlayer); - add(swInventory, row_2, 19, lobbyPlayer); - + SWListInv particleSWListInv; if (userGroup == UserGroup.Member) { - swInventory.setItem(31, Material.BARRIER, "§8Keine Partikel", lore, false, clickType -> { - lobbyPlayer.setParticle(null); - }); + particleSWListInv = new SWListInv<>(player, "§6Partikel", false, playerParticlesEntries, (clickType, particle) -> lobbyPlayer.setParticle(particle)); } else { - add(swInventory, row_3, 28, lobbyPlayer); - swInventory.setItem(40, Material.BARRIER, "§8Keine Partikel", lore, false, clickType -> { - lobbyPlayer.setParticle(null); - }); + particleSWListInv = new SWListInv<>(player, "§6Partikel", false, teamParticlesEntries, (clickType, particle) -> lobbyPlayer.setParticle(particle)); } + particleSWListInv.setItem(49, Material.BARRIER, "§8Keine Partikel", lore, false, clickType -> { + lobbyPlayer.setParticle(null); + }); - return swInventory; - } - - private static void add(SWInventory swInventory, SpecialParticle[] specialParticles, int index, LobbyPlayer lobbyPlayer) { - for (int i = 0; i < specialParticles.length; i++) { - specialParticles[i].add(swInventory, i + index, lobbyPlayer); - } + return particleSWListInv; } public static void openParticleInventory(Player player) { diff --git a/src/de/steamwar/lobby/listener/ParticleListener.java b/src/de/steamwar/lobby/listener/ParticleListener.java index deee72e..6b55a6b 100644 --- a/src/de/steamwar/lobby/listener/ParticleListener.java +++ b/src/de/steamwar/lobby/listener/ParticleListener.java @@ -34,14 +34,12 @@ import org.bukkit.event.player.PlayerMoveEvent; public class ParticleListener implements Listener { - private static int deg = 0; + private static double deg = 0; public ParticleListener() { Bukkit.getScheduler().runTaskTimer(LobbySystem.getInstance(), () -> { - deg++; - if (deg > 360) { - deg = 0; - } + deg += 0.1; + if (deg > 360) deg = 0; }, 0, 1); } diff --git a/src/de/steamwar/lobby/particle/CircleParticle.java b/src/de/steamwar/lobby/particle/CircleParticle.java index a57d702..bca7529 100644 --- a/src/de/steamwar/lobby/particle/CircleParticle.java +++ b/src/de/steamwar/lobby/particle/CircleParticle.java @@ -30,12 +30,16 @@ import org.bukkit.util.Vector; import java.util.List; import java.util.function.Function; -import java.util.function.Supplier; public class CircleParticle extends SpecialParticle { private Particle particle; private Function locationShift; + private boolean customVelocity = false; + private float vx; + private float vy; + private float vz; + private double time = 1; public CircleParticle(Material material, String name, List lore, Particle particle, Function locationShift) { super(material, name, lore); @@ -43,11 +47,26 @@ public class CircleParticle extends SpecialParticle { this.locationShift = locationShift; } + public CircleParticle(Material material, String name, List lore, Particle particle, Function locationShift, float vx, float vy, float vz, double time) { + super(material, name, lore); + this.particle = particle; + this.locationShift = locationShift; + customVelocity = true; + this.vx = vx; + this.vy = vy; + this.vz = vz; + this.time = time; + } + @Override - public void particle(World world, Player player, int deg) { + public void particle(World world, Player player, double deg) { Vector vector = new Vector(1, 0, 0); vector.rotateAroundY(deg); - world.spawnParticle(particle, locationShift.apply(player.getLocation().add(vector)), 5); + if (customVelocity) { + world.spawnParticle(particle, locationShift.apply(player.getLocation().add(vector)), 1, vx, vy, vz, time); + } else { + world.spawnParticle(particle, locationShift.apply(player.getLocation().add(vector)), 1); + } } } diff --git a/src/de/steamwar/lobby/particle/FunctionalParticle.java b/src/de/steamwar/lobby/particle/FunctionalParticle.java index c8bc297..f2bc6dc 100644 --- a/src/de/steamwar/lobby/particle/FunctionalParticle.java +++ b/src/de/steamwar/lobby/particle/FunctionalParticle.java @@ -37,7 +37,7 @@ public class FunctionalParticle extends SpecialParticle { } @Override - public void particle(World world, Player player, int deg) { + public void particle(World world, Player player, double deg) { particleFunction.accept(world, player, deg); } diff --git a/src/de/steamwar/lobby/particle/ParticleFunction.java b/src/de/steamwar/lobby/particle/ParticleFunction.java index 13f475a..1e62c03 100644 --- a/src/de/steamwar/lobby/particle/ParticleFunction.java +++ b/src/de/steamwar/lobby/particle/ParticleFunction.java @@ -26,5 +26,5 @@ import org.bukkit.entity.Player; @FunctionalInterface public interface ParticleFunction { - void accept(World world, Player player, Integer time); + void accept(World world, Player player, double time); } diff --git a/src/de/steamwar/lobby/particle/SimpleParticle.java b/src/de/steamwar/lobby/particle/SimpleParticle.java index 14930cb..4695220 100644 --- a/src/de/steamwar/lobby/particle/SimpleParticle.java +++ b/src/de/steamwar/lobby/particle/SimpleParticle.java @@ -33,7 +33,7 @@ public class SimpleParticle extends SpecialParticle { private float vx; private float vy; private float vz; - private double time; + private double time = 1; public SimpleParticle(Material material, String name, List lore, Particle particle) { super(material, name, lore); @@ -51,7 +51,7 @@ public class SimpleParticle extends SpecialParticle { } @Override - public void particle(World world, Player player, int deg) { + public void particle(World world, Player player, double deg) { Location location = player.getLocation().add(0.0, 0.2, 0.0); if (particle == Particle.REDSTONE) { world.spawnParticle(particle, location, 5, getParticleDust()); diff --git a/src/de/steamwar/lobby/particle/SpecialParticle.java b/src/de/steamwar/lobby/particle/SpecialParticle.java index f8ffa2d..8e2f808 100644 --- a/src/de/steamwar/lobby/particle/SpecialParticle.java +++ b/src/de/steamwar/lobby/particle/SpecialParticle.java @@ -19,9 +19,7 @@ package de.steamwar.lobby.particle; -import de.steamwar.inventory.SWInventory; import de.steamwar.inventory.SWItem; -import de.steamwar.lobby.utils.LobbyPlayer; import org.bukkit.Color; import org.bukkit.Material; import org.bukkit.Particle; @@ -62,16 +60,10 @@ public abstract class SpecialParticle { this.lore = lore; } - public final SWItem getItem(LobbyPlayer lobbyPlayer) { - return new SWItem(material, name, lore, false, clickType -> { - lobbyPlayer.setParticle(this); - }); + public final SWItem getItem() { + return new SWItem(material, name, lore, false, clickType -> {}); } - public final void add(SWInventory swInventory, int pos, LobbyPlayer lobbyPlayer) { - swInventory.setItem(pos, getItem(lobbyPlayer)); - } - - public abstract void particle(World world, Player player, int deg); + public abstract void particle(World world, Player player, double deg); }