From 92f5214c91a27e98a214e910b7c2606fe06b88c0 Mon Sep 17 00:00:00 2001 From: LCastr0 Date: Fri, 17 Mar 2017 19:39:41 -0300 Subject: [PATCH 1/6] Added spring halo particle --- .../mineplex/core/gadget/GadgetManager.java | 2 + .../gadgets/particle/ParticleSpringHalo.java | 63 +++++++++++++++++++ .../core/gadget/types/ParticleGadget.java | 9 ++- .../core/particleeffects/CircleEffect.java | 19 +++++- 4 files changed, 90 insertions(+), 3 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleSpringHalo.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java index d2acbf740..242017566 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java @@ -164,6 +164,7 @@ import mineplex.core.gadget.gadgets.particle.ParticleCoalFumes; import mineplex.core.gadget.gadgets.particle.ParticleFairy; import mineplex.core.gadget.gadgets.particle.ParticleFireRings; import mineplex.core.gadget.gadgets.particle.ParticleLegend; +import mineplex.core.gadget.gadgets.particle.ParticleSpringHalo; import mineplex.core.gadget.gadgets.particle.ParticleWingsAngel; import mineplex.core.gadget.gadgets.particle.ParticleWingsDemons; import mineplex.core.gadget.gadgets.particle.ParticleWingsInfernal; @@ -447,6 +448,7 @@ public class GadgetManager extends MiniPlugin addGadget(new ParticleFreedom(this)); addGadget(new ParticleChristmasTree(this)); addGadget(new ParticleWingsLove(this)); + addGadget(new ParticleSpringHalo(this)); // Arrow Trails addGadget(new ArrowTrailFrostLord(this)); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleSpringHalo.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleSpringHalo.java new file mode 100644 index 000000000..c39203a27 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleSpringHalo.java @@ -0,0 +1,63 @@ +package mineplex.core.gadget.gadgets.particle; + +import java.awt.Color; +import java.time.Month; +import java.time.YearMonth; +import java.util.HashMap; +import java.util.Map; + +import org.bukkit.Material; +import org.bukkit.entity.Player; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.LineFormat; +import mineplex.core.common.util.UtilText; +import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.types.ParticleGadget; +import mineplex.core.particleeffects.CircleEffect; +import mineplex.core.updater.event.UpdateEvent; + +public class ParticleSpringHalo extends ParticleGadget +{ + + private Map _effects = new HashMap<>(); + + public ParticleSpringHalo(GadgetManager manager) + { + // TODO CHANGE LORE BEFORE RELEASE + super(manager, "Spring Halo", UtilText.splitLinesToArray(new String[]{C.cGray + "Placeholder"}, LineFormat.LORE), -14, Material.GLASS, (byte) 0, YearMonth.of(2017, Month.APRIL)); + } + + @Override + public void enableCustom(Player player, boolean message) + { + super.enableCustom(player, message); + CircleEffect circleEffect = new CircleEffect(Manager.getPlugin(), player, 0.7d, Color.RED, false); + circleEffect.addRandomColor(Color.YELLOW); + circleEffect.addRandomColor(Color.BLUE); + circleEffect.addRandomColor(Color.GREEN); + circleEffect.setYOffset(2.3d); + circleEffect.start(); + _effects.put(player, circleEffect); + } + + @Override + public void disableCustom(Player player, boolean message) + { + super.disableCustom(player, message); + if (_effects.containsKey(player)) + { + CircleEffect circleEffect = _effects.get(player); + if (circleEffect != null) + { + circleEffect.stop(); + } + } + _effects.remove(player); + } + + @Override + public void playParticle(Player player, UpdateEvent event) + {} + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/ParticleGadget.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/ParticleGadget.java index 06af3908b..e04db2a61 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/ParticleGadget.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/types/ParticleGadget.java @@ -1,5 +1,7 @@ package mineplex.core.gadget.types; +import java.time.YearMonth; + import org.bukkit.Material; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; @@ -28,7 +30,12 @@ public abstract class ParticleGadget extends Gadget public ParticleGadget(GadgetManager manager, String name, String[] desc, int cost, Material mat, byte data, String...altNames) { super(manager, GadgetType.PARTICLE, name, desc, cost, mat, data, 1, altNames); - } + } + + public ParticleGadget(GadgetManager manager, String name, String[] desc, int cost, Material mat, byte data, YearMonth yearMonth, String... altNames) + { + super(manager, GadgetType.PARTICLE, name, desc, cost, mat, data, yearMonth, 1, altNames); + } @Override public void enableCustom(Player player, boolean message) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/CircleEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/CircleEffect.java index 8d1ae23d1..f9ff7b3a3 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/CircleEffect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/CircleEffect.java @@ -5,6 +5,7 @@ import java.util.ArrayList; import java.util.List; import org.bukkit.Location; +import org.bukkit.entity.Entity; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; @@ -23,6 +24,7 @@ public class CircleEffect extends Effect private List _randomColors = new ArrayList<>(); private int _maxCircles = -1; private int _totalCircles = 0; + private double _yOffset = 0.0; private static final double RANDOM_COLOR_CHANCE = 0.5; private static final int PARTICLES_PER_CIRCLE = 20; @@ -40,6 +42,14 @@ public class CircleEffect extends Effect _instantly = instantly; } + public CircleEffect(JavaPlugin plugin, Entity entity, double radius, Color color, boolean instantly) + { + super(-1, new EffectLocation(entity), plugin); + _radius = radius; + _color = color; + _instantly = instantly; + } + public void addRandomColor(Color color) { _randomColors.add(color); @@ -50,6 +60,11 @@ public class CircleEffect extends Effect _maxCircles = circles; } + public void setYOffset(double yOffset) + { + _yOffset = yOffset; + } + @Override public void runEffect() { @@ -57,7 +72,7 @@ public class CircleEffect extends Effect { for (int i = 0; i < PARTICLES_PER_CIRCLE; i++) { - Location location = getEffectLocation().getFixedLocation(); + Location location = getEffectLocation().getLocation().add(0, _yOffset, 0); double increment = (2 * Math.PI) / PARTICLES_PER_CIRCLE; double angle = _steps * increment; Vector vector = new Vector(Math.cos(angle) * _radius, 0, Math.sin(angle) * _radius); @@ -86,7 +101,7 @@ public class CircleEffect extends Effect return; } } - Location location = getEffectLocation().getFixedLocation(); + Location location = getEffectLocation().getLocation().add(0, _yOffset, 0); double increment = (2 * Math.PI) / PARTICLES_PER_CIRCLE; double angle = _steps * increment; Vector vector = new Vector(Math.cos(angle) * _radius, 0, Math.sin(angle) * _radius); From d8b68e4716d5eaa2a6f3ab73d5aa293276c05fa5 Mon Sep 17 00:00:00 2001 From: LCastr0 Date: Fri, 17 Mar 2017 20:01:48 -0300 Subject: [PATCH 2/6] Multi colored circle --- .../gadgets/particle/ParticleSpringHalo.java | 12 +-- .../particleeffects/ColoredCircleEffect.java | 94 +++++++++++++++++++ 2 files changed, 99 insertions(+), 7 deletions(-) create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/particleeffects/ColoredCircleEffect.java diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleSpringHalo.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleSpringHalo.java index c39203a27..bc7d54980 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleSpringHalo.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleSpringHalo.java @@ -14,13 +14,13 @@ import mineplex.core.common.util.LineFormat; import mineplex.core.common.util.UtilText; import mineplex.core.gadget.GadgetManager; import mineplex.core.gadget.types.ParticleGadget; -import mineplex.core.particleeffects.CircleEffect; +import mineplex.core.particleeffects.ColoredCircleEffect; import mineplex.core.updater.event.UpdateEvent; public class ParticleSpringHalo extends ParticleGadget { - private Map _effects = new HashMap<>(); + private Map _effects = new HashMap<>(); public ParticleSpringHalo(GadgetManager manager) { @@ -32,10 +32,8 @@ public class ParticleSpringHalo extends ParticleGadget public void enableCustom(Player player, boolean message) { super.enableCustom(player, message); - CircleEffect circleEffect = new CircleEffect(Manager.getPlugin(), player, 0.7d, Color.RED, false); - circleEffect.addRandomColor(Color.YELLOW); - circleEffect.addRandomColor(Color.BLUE); - circleEffect.addRandomColor(Color.GREEN); + ColoredCircleEffect circleEffect = new ColoredCircleEffect(Manager.getPlugin(), player, 0.7d, false, + Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW); circleEffect.setYOffset(2.3d); circleEffect.start(); _effects.put(player, circleEffect); @@ -47,7 +45,7 @@ public class ParticleSpringHalo extends ParticleGadget super.disableCustom(player, message); if (_effects.containsKey(player)) { - CircleEffect circleEffect = _effects.get(player); + ColoredCircleEffect circleEffect = _effects.get(player); if (circleEffect != null) { circleEffect.stop(); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/ColoredCircleEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/ColoredCircleEffect.java new file mode 100644 index 000000000..2218cba9c --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/ColoredCircleEffect.java @@ -0,0 +1,94 @@ +package mineplex.core.particleeffects; + +import java.awt.Color; + +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.plugin.java.JavaPlugin; +import org.bukkit.util.Vector; + +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilParticle; +import mineplex.core.common.util.particles.ColoredParticle; +import mineplex.core.common.util.particles.DustSpellColor; + +public class ColoredCircleEffect extends Effect +{ + + private double _radius; + private Color[] _colors; + private int _steps = 0; + private boolean _instantly = true; + private int _maxCircles = -1; + private int _totalCircles = 0; + private double _yOffset = 0.0; + + private static final int PARTICLES_PER_CIRCLE = 20; + + public ColoredCircleEffect(JavaPlugin plugin, Entity entity, double radius, boolean instantly, Color... colors) + { + super(-1, new EffectLocation(entity), plugin); + _radius = radius; + _colors = colors; + _instantly = instantly; + } + + public void setMaxCircles(int circles) + { + _maxCircles = circles; + } + + public void setYOffset(double yOffset) + { + _yOffset = yOffset; + } + + @Override + public void runEffect() + { + if (_instantly) + { + for (int i = 0; i < PARTICLES_PER_CIRCLE; i++) + { + Location location = getEffectLocation().getLocation().add(0, _yOffset, 0); + double increment = (2 * Math.PI) / PARTICLES_PER_CIRCLE; + double angle = _steps * increment; + Vector vector = new Vector(Math.cos(angle) * _radius, 0, Math.sin(angle) * _radius); + ColoredParticle coloredParticle = new ColoredParticle(UtilParticle.ParticleType.RED_DUST, new DustSpellColor(getNextColor()), location.add(vector)); + coloredParticle.display(); + _steps++; + } + stop(); + } + else + { + if (_maxCircles != -1) + { + if (_totalCircles >= _maxCircles) + { + stop(); + return; + } + } + Location location = getEffectLocation().getLocation().add(0, _yOffset, 0); + double increment = (2 * Math.PI) / PARTICLES_PER_CIRCLE; + double angle = _steps * increment; + Vector vector = new Vector(Math.cos(angle) * _radius, 0, Math.sin(angle) * _radius); + ColoredParticle coloredParticle = new ColoredParticle(UtilParticle.ParticleType.RED_DUST, new DustSpellColor(getNextColor()), location.add(vector)); + coloredParticle.display(); + _steps++; + if (_steps >= PARTICLES_PER_CIRCLE) + { + _totalCircles++; + _steps = 0; + } + } + } + + private Color getNextColor() + { + int r = UtilMath.random.nextInt(_colors.length - 1); + return _colors[r]; + } + +} From e1d9a568c953146edf245c0657771d719b61a610 Mon Sep 17 00:00:00 2001 From: LCastr0 Date: Sat, 18 Mar 2017 00:49:12 -0300 Subject: [PATCH 3/6] Added flower as a hat --- .../core/gadget/gadgets/particle/ParticleSpringHalo.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleSpringHalo.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleSpringHalo.java index bc7d54980..e47574e7e 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleSpringHalo.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleSpringHalo.java @@ -8,11 +8,14 @@ import java.util.Map; import org.bukkit.Material; import org.bukkit.entity.Player; +import org.bukkit.inventory.ItemStack; import mineplex.core.common.util.C; import mineplex.core.common.util.LineFormat; import mineplex.core.common.util.UtilText; import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.types.GadgetType; +import mineplex.core.gadget.types.OutfitGadget; import mineplex.core.gadget.types.ParticleGadget; import mineplex.core.particleeffects.ColoredCircleEffect; import mineplex.core.updater.event.UpdateEvent; @@ -32,11 +35,14 @@ public class ParticleSpringHalo extends ParticleGadget public void enableCustom(Player player, boolean message) { super.enableCustom(player, message); + Manager.removeGadgetType(player, GadgetType.MORPH, this); + Manager.removeOutfit(player, OutfitGadget.ArmorSlot.HELMET); ColoredCircleEffect circleEffect = new ColoredCircleEffect(Manager.getPlugin(), player, 0.7d, false, Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW); circleEffect.setYOffset(2.3d); circleEffect.start(); _effects.put(player, circleEffect); + player.getEquipment().setHelmet(new ItemStack(Material.RED_ROSE, 1, (byte) 8)); } @Override @@ -52,6 +58,7 @@ public class ParticleSpringHalo extends ParticleGadget } } _effects.remove(player); + player.getInventory().setHelmet(null); } @Override From 75ad5b9d513a93b28209ce016643341e3fd754f1 Mon Sep 17 00:00:00 2001 From: LCastr0 Date: Mon, 20 Mar 2017 08:23:32 -0300 Subject: [PATCH 4/6] Flowers where player walks --- .../mineplex/core/common/util/UtilBlock.java | 31 ++-- .../mineplex/core/gadget/GadgetManager.java | 2 +- .../gadgets/particle/ParticleSpringHalo.java | 68 -------- .../particle/spring/ParticleSpringHalo.java | 161 ++++++++++++++++++ .../particle/spring/SpringHaloData.java | 34 ++++ 5 files changed, 217 insertions(+), 79 deletions(-) delete mode 100644 Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleSpringHalo.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/ParticleSpringHalo.java create mode 100644 Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/SpringHaloData.java diff --git a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java index 6a43363de..91c93c620 100644 --- a/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java +++ b/Plugins/Mineplex.Core.Common/src/mineplex/core/common/util/UtilBlock.java @@ -7,6 +7,16 @@ import java.util.HashSet; import java.util.Set; import java.util.UUID; +import net.minecraft.server.v1_8_R3.BlockPosition; +import net.minecraft.server.v1_8_R3.Blocks; +import net.minecraft.server.v1_8_R3.IBlockData; +import net.minecraft.server.v1_8_R3.Item; +import net.minecraft.server.v1_8_R3.MathHelper; +import net.minecraft.server.v1_8_R3.MinecraftKey; +import net.minecraft.server.v1_8_R3.NBTTagCompound; +import net.minecraft.server.v1_8_R3.TileEntityFlowerPot; +import net.minecraft.server.v1_8_R3.WorldServer; + import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.SkullType; @@ -35,15 +45,6 @@ import com.mojang.authlib.GameProfile; import mineplex.core.common.Pair; import mineplex.core.common.block.MultiBlockUpdaterAgent; import mineplex.core.common.skin.SkinData; -import net.minecraft.server.v1_8_R3.BlockPosition; -import net.minecraft.server.v1_8_R3.Blocks; -import net.minecraft.server.v1_8_R3.IBlockData; -import net.minecraft.server.v1_8_R3.Item; -import net.minecraft.server.v1_8_R3.MathHelper; -import net.minecraft.server.v1_8_R3.MinecraftKey; -import net.minecraft.server.v1_8_R3.NBTTagCompound; -import net.minecraft.server.v1_8_R3.TileEntityFlowerPot; -import net.minecraft.server.v1_8_R3.WorldServer; public class UtilBlock { @@ -394,7 +395,17 @@ public class UtilBlock { return blockUseSet.contains(block); } - + + public static Set getBlocksInRadius(Location loc, double radius) + { + return getInRadius(loc, radius).keySet(); + } + + public static Set getBlocksInRadius(Location loc, double radius, int maxHeight) + { + return getInRadius(loc, radius, maxHeight).keySet(); + } + public static HashMap getInRadius(Location loc, double dR) { return getInRadius(loc, dR, 9999); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java index 242017566..35ae1e96c 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/GadgetManager.java @@ -164,7 +164,7 @@ import mineplex.core.gadget.gadgets.particle.ParticleCoalFumes; import mineplex.core.gadget.gadgets.particle.ParticleFairy; import mineplex.core.gadget.gadgets.particle.ParticleFireRings; import mineplex.core.gadget.gadgets.particle.ParticleLegend; -import mineplex.core.gadget.gadgets.particle.ParticleSpringHalo; +import mineplex.core.gadget.gadgets.particle.spring.ParticleSpringHalo; import mineplex.core.gadget.gadgets.particle.ParticleWingsAngel; import mineplex.core.gadget.gadgets.particle.ParticleWingsDemons; import mineplex.core.gadget.gadgets.particle.ParticleWingsInfernal; diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleSpringHalo.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleSpringHalo.java deleted file mode 100644 index e47574e7e..000000000 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/ParticleSpringHalo.java +++ /dev/null @@ -1,68 +0,0 @@ -package mineplex.core.gadget.gadgets.particle; - -import java.awt.Color; -import java.time.Month; -import java.time.YearMonth; -import java.util.HashMap; -import java.util.Map; - -import org.bukkit.Material; -import org.bukkit.entity.Player; -import org.bukkit.inventory.ItemStack; - -import mineplex.core.common.util.C; -import mineplex.core.common.util.LineFormat; -import mineplex.core.common.util.UtilText; -import mineplex.core.gadget.GadgetManager; -import mineplex.core.gadget.types.GadgetType; -import mineplex.core.gadget.types.OutfitGadget; -import mineplex.core.gadget.types.ParticleGadget; -import mineplex.core.particleeffects.ColoredCircleEffect; -import mineplex.core.updater.event.UpdateEvent; - -public class ParticleSpringHalo extends ParticleGadget -{ - - private Map _effects = new HashMap<>(); - - public ParticleSpringHalo(GadgetManager manager) - { - // TODO CHANGE LORE BEFORE RELEASE - super(manager, "Spring Halo", UtilText.splitLinesToArray(new String[]{C.cGray + "Placeholder"}, LineFormat.LORE), -14, Material.GLASS, (byte) 0, YearMonth.of(2017, Month.APRIL)); - } - - @Override - public void enableCustom(Player player, boolean message) - { - super.enableCustom(player, message); - Manager.removeGadgetType(player, GadgetType.MORPH, this); - Manager.removeOutfit(player, OutfitGadget.ArmorSlot.HELMET); - ColoredCircleEffect circleEffect = new ColoredCircleEffect(Manager.getPlugin(), player, 0.7d, false, - Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW); - circleEffect.setYOffset(2.3d); - circleEffect.start(); - _effects.put(player, circleEffect); - player.getEquipment().setHelmet(new ItemStack(Material.RED_ROSE, 1, (byte) 8)); - } - - @Override - public void disableCustom(Player player, boolean message) - { - super.disableCustom(player, message); - if (_effects.containsKey(player)) - { - ColoredCircleEffect circleEffect = _effects.get(player); - if (circleEffect != null) - { - circleEffect.stop(); - } - } - _effects.remove(player); - player.getInventory().setHelmet(null); - } - - @Override - public void playParticle(Player player, UpdateEvent event) - {} - -} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/ParticleSpringHalo.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/ParticleSpringHalo.java new file mode 100644 index 000000000..0b995504d --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/ParticleSpringHalo.java @@ -0,0 +1,161 @@ +package mineplex.core.gadget.gadgets.particle.spring; + +import java.awt.Color; +import java.time.Month; +import java.time.YearMonth; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; + +import org.bukkit.Material; +import org.bukkit.block.Block; +import org.bukkit.entity.Player; +import org.bukkit.event.EventHandler; +import org.bukkit.event.player.PlayerMoveEvent; +import org.bukkit.inventory.ItemStack; + +import mineplex.core.common.util.C; +import mineplex.core.common.util.LineFormat; +import mineplex.core.common.util.UtilMath; +import mineplex.core.common.util.UtilText; +import mineplex.core.common.util.UtilTime; +import mineplex.core.gadget.GadgetManager; +import mineplex.core.gadget.types.GadgetType; +import mineplex.core.gadget.types.OutfitGadget; +import mineplex.core.gadget.types.ParticleGadget; +import mineplex.core.particleeffects.ColoredCircleEffect; +import mineplex.core.updater.UpdateType; +import mineplex.core.updater.event.UpdateEvent; + +public class ParticleSpringHalo extends ParticleGadget +{ + + private Map _effects = new HashMap<>(); + private List _springHaloData = new ArrayList<>(); + private Map> _playerSpringHaloData = new HashMap<>(); + + public ParticleSpringHalo(GadgetManager manager) + { + // TODO CHANGE LORE BEFORE RELEASE + super(manager, "Spring Halo", UtilText.splitLinesToArray(new String[]{C.cGray + "Placeholder"}, LineFormat.LORE), -14, Material.GLASS, (byte) 0, YearMonth.of(2017, Month.APRIL)); + } + + @Override + public void enableCustom(Player player, boolean message) + { + super.enableCustom(player, message); + Manager.removeGadgetType(player, GadgetType.MORPH, this); + Manager.removeOutfit(player, OutfitGadget.ArmorSlot.HELMET); + ColoredCircleEffect circleEffect = new ColoredCircleEffect(Manager.getPlugin(), player, 0.7d, false, + Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW); + circleEffect.setYOffset(2.3d); + circleEffect.start(); + _effects.put(player, circleEffect); + player.getEquipment().setHelmet(new ItemStack(Material.RED_ROSE, 1, (byte) 8)); + } + + @Override + public void disableCustom(Player player, boolean message) + { + super.disableCustom(player, message); + if (_effects.containsKey(player)) + { + ColoredCircleEffect circleEffect = _effects.get(player); + if (circleEffect != null) + { + circleEffect.stop(); + } + } + _effects.remove(player); + player.getInventory().setHelmet(null); + if (_playerSpringHaloData.containsKey(player)) + { + Iterator iterator = _playerSpringHaloData.get(player).iterator(); + while (iterator.hasNext()) + { + SpringHaloData springHaloData = iterator.next(); + springHaloData.getBlock().setType(Material.AIR); + springHaloData.getBlock().setData((byte) 0); + removeSpringHalo(springHaloData); + } + _playerSpringHaloData.get(player).clear(); + _playerSpringHaloData.remove(player); + } + } + + @Override + public void playParticle(Player player, UpdateEvent event) + { + } + + @EventHandler + public void spawnFlowers(PlayerMoveEvent event) + { + if (!isActive(event.getPlayer())) + return; + + Player player = event.getPlayer(); + + Block block = event.getFrom().getBlock(); + if (block.getType() != Material.AIR) + return; + + if (block.getLocation().subtract(0, 1, 0).getBlock().getType() != Material.GRASS + && block.getLocation().subtract(0, 1, 0).getBlock().getType() != Material.DIRT) + return; + + block.setType(Material.RED_ROSE); + block.setData((byte) UtilMath.random.nextInt(8)); + SpringHaloData springHaloData = new SpringHaloData(player, block, System.currentTimeMillis()); + addFlower(player, springHaloData); + } + + @EventHandler + public void onUpdate(UpdateEvent event) + { + if (event.getType() != UpdateType.TICK) + return; + + Iterator iterator = _springHaloData.iterator(); + while (iterator.hasNext()) + { + SpringHaloData springHaloData = iterator.next(); + if (UtilTime.elapsed(springHaloData.getSpawned(), 1500)) + { + springHaloData.getBlock().setType(Material.AIR); + springHaloData.getBlock().setData((byte) 0); + removeSpringHalo(springHaloData); + iterator.remove(); + } + } + } + + private void addFlower(Player player, SpringHaloData springHaloData) + { + _springHaloData.add(springHaloData); + if (_playerSpringHaloData.containsKey(player)) + { + List list = _playerSpringHaloData.get(player); + list.add(springHaloData); + } + else + { + List list = new ArrayList<>(); + list.add(springHaloData); + _playerSpringHaloData.put(player, list); + } + } + + private void removeSpringHalo(SpringHaloData springHaloData) + { + Player player = springHaloData.getPlayer(); + List list = _playerSpringHaloData.get(player); + if (list != null) + { + list.remove(springHaloData); + } + } + +} diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/SpringHaloData.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/SpringHaloData.java new file mode 100644 index 000000000..c497b99a9 --- /dev/null +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/SpringHaloData.java @@ -0,0 +1,34 @@ +package mineplex.core.gadget.gadgets.particle.spring; + +import org.bukkit.block.Block; +import org.bukkit.entity.Player; + +public class SpringHaloData +{ + + private Player _player; + private Block _block; + private long _spawned; + + public SpringHaloData(Player player, Block block, long spawned) + { + _player = player; + _block = block; + _spawned = spawned; + } + + public Player getPlayer() + { + return _player; + } + + public Block getBlock() + { + return _block; + } + + public long getSpawned() + { + return _spawned; + } +} From afad64bec3126fbc8ddf4ecec5ee40756980b30c Mon Sep 17 00:00:00 2001 From: LCastr0 Date: Mon, 20 Mar 2017 08:49:20 -0300 Subject: [PATCH 5/6] Fixed CME --- .../core/gadget/gadgets/particle/spring/ParticleSpringHalo.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/ParticleSpringHalo.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/ParticleSpringHalo.java index 0b995504d..8aa34525b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/ParticleSpringHalo.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/ParticleSpringHalo.java @@ -78,7 +78,7 @@ public class ParticleSpringHalo extends ParticleGadget SpringHaloData springHaloData = iterator.next(); springHaloData.getBlock().setType(Material.AIR); springHaloData.getBlock().setData((byte) 0); - removeSpringHalo(springHaloData); + iterator.remove(); } _playerSpringHaloData.get(player).clear(); _playerSpringHaloData.remove(player); From d55690f9047a3608a65506d819d6cdb1f913e7bd Mon Sep 17 00:00:00 2001 From: LCastr0 Date: Mon, 20 Mar 2017 19:22:50 -0300 Subject: [PATCH 6/6] Changed colors --- .../particle/spring/ParticleSpringHalo.java | 13 +++++-- .../particleeffects/ColoredCircleEffect.java | 36 ++++++++++++++++--- 2 files changed, 42 insertions(+), 7 deletions(-) diff --git a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/ParticleSpringHalo.java b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/ParticleSpringHalo.java index 8aa34525b..4b24315ca 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/ParticleSpringHalo.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/gadget/gadgets/particle/spring/ParticleSpringHalo.java @@ -1,6 +1,5 @@ package mineplex.core.gadget.gadgets.particle.spring; -import java.awt.Color; import java.time.Month; import java.time.YearMonth; import java.util.ArrayList; @@ -18,6 +17,8 @@ import org.bukkit.inventory.ItemStack; import mineplex.core.common.util.C; import mineplex.core.common.util.LineFormat; +import mineplex.core.common.util.RGBData; +import mineplex.core.common.util.UtilColor; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilText; import mineplex.core.common.util.UtilTime; @@ -48,8 +49,14 @@ public class ParticleSpringHalo extends ParticleGadget super.enableCustom(player, message); Manager.removeGadgetType(player, GadgetType.MORPH, this); Manager.removeOutfit(player, OutfitGadget.ArmorSlot.HELMET); - ColoredCircleEffect circleEffect = new ColoredCircleEffect(Manager.getPlugin(), player, 0.7d, false, - Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW); + ColoredCircleEffect circleEffect = new ColoredCircleEffect(Manager.getPlugin(), player, 0.7d, false); + RGBData colorA = UtilColor.hexToRgb(0x5a92ed); + RGBData colorB = UtilColor.hexToRgb(0xdb5aed); + RGBData colorC = UtilColor.hexToRgb(0xd2cdf2); + RGBData colorD = UtilColor.hexToRgb(0x7c6df2); + RGBData colorE = UtilColor.hexToRgb(0xedeb97); + RGBData colorF = UtilColor.hexToRgb(0xeac07c); + circleEffect.addColors(colorA, colorB, colorC, colorD, colorE, colorF); circleEffect.setYOffset(2.3d); circleEffect.start(); _effects.put(player, circleEffect); diff --git a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/ColoredCircleEffect.java b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/ColoredCircleEffect.java index 2218cba9c..51851e40b 100644 --- a/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/ColoredCircleEffect.java +++ b/Plugins/Mineplex.Core/src/mineplex/core/particleeffects/ColoredCircleEffect.java @@ -1,12 +1,16 @@ package mineplex.core.particleeffects; import java.awt.Color; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import org.bukkit.Location; import org.bukkit.entity.Entity; import org.bukkit.plugin.java.JavaPlugin; import org.bukkit.util.Vector; +import mineplex.core.common.util.RGBData; import mineplex.core.common.util.UtilMath; import mineplex.core.common.util.UtilParticle; import mineplex.core.common.util.particles.ColoredParticle; @@ -16,7 +20,7 @@ public class ColoredCircleEffect extends Effect { private double _radius; - private Color[] _colors; + private List _colors; private int _steps = 0; private boolean _instantly = true; private int _maxCircles = -1; @@ -29,8 +33,9 @@ public class ColoredCircleEffect extends Effect { super(-1, new EffectLocation(entity), plugin); _radius = radius; - _colors = colors; + _colors = new ArrayList<>(); _instantly = instantly; + Collections.addAll(_colors, colors); } public void setMaxCircles(int circles) @@ -43,6 +48,29 @@ public class ColoredCircleEffect extends Effect _yOffset = yOffset; } + public void addColor(Color color) + { + _colors.add(color); + } + + public void addColors(Color... colors) + { + Collections.addAll(_colors, colors); + } + + public void addColor(RGBData rgbData) + { + _colors.add(new Color(rgbData.getFullRed(), rgbData.getFullGreen(), rgbData.getFullBlue())); + } + + public void addColors(RGBData... rgbDatas) + { + for (RGBData rgbData : rgbDatas) + { + addColor(rgbData); + } + } + @Override public void runEffect() { @@ -87,8 +115,8 @@ public class ColoredCircleEffect extends Effect private Color getNextColor() { - int r = UtilMath.random.nextInt(_colors.length - 1); - return _colors[r]; + int r = UtilMath.random.nextInt(_colors.size()); + return _colors.get(r); } }