Multi colored circle
This commit is contained in:
parent
92f5214c91
commit
d8b68e4716
@ -14,13 +14,13 @@ import mineplex.core.common.util.LineFormat;
|
|||||||
import mineplex.core.common.util.UtilText;
|
import mineplex.core.common.util.UtilText;
|
||||||
import mineplex.core.gadget.GadgetManager;
|
import mineplex.core.gadget.GadgetManager;
|
||||||
import mineplex.core.gadget.types.ParticleGadget;
|
import mineplex.core.gadget.types.ParticleGadget;
|
||||||
import mineplex.core.particleeffects.CircleEffect;
|
import mineplex.core.particleeffects.ColoredCircleEffect;
|
||||||
import mineplex.core.updater.event.UpdateEvent;
|
import mineplex.core.updater.event.UpdateEvent;
|
||||||
|
|
||||||
public class ParticleSpringHalo extends ParticleGadget
|
public class ParticleSpringHalo extends ParticleGadget
|
||||||
{
|
{
|
||||||
|
|
||||||
private Map<Player, CircleEffect> _effects = new HashMap<>();
|
private Map<Player, ColoredCircleEffect> _effects = new HashMap<>();
|
||||||
|
|
||||||
public ParticleSpringHalo(GadgetManager manager)
|
public ParticleSpringHalo(GadgetManager manager)
|
||||||
{
|
{
|
||||||
@ -32,10 +32,8 @@ public class ParticleSpringHalo extends ParticleGadget
|
|||||||
public void enableCustom(Player player, boolean message)
|
public void enableCustom(Player player, boolean message)
|
||||||
{
|
{
|
||||||
super.enableCustom(player, message);
|
super.enableCustom(player, message);
|
||||||
CircleEffect circleEffect = new CircleEffect(Manager.getPlugin(), player, 0.7d, Color.RED, false);
|
ColoredCircleEffect circleEffect = new ColoredCircleEffect(Manager.getPlugin(), player, 0.7d, false,
|
||||||
circleEffect.addRandomColor(Color.YELLOW);
|
Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW);
|
||||||
circleEffect.addRandomColor(Color.BLUE);
|
|
||||||
circleEffect.addRandomColor(Color.GREEN);
|
|
||||||
circleEffect.setYOffset(2.3d);
|
circleEffect.setYOffset(2.3d);
|
||||||
circleEffect.start();
|
circleEffect.start();
|
||||||
_effects.put(player, circleEffect);
|
_effects.put(player, circleEffect);
|
||||||
@ -47,7 +45,7 @@ public class ParticleSpringHalo extends ParticleGadget
|
|||||||
super.disableCustom(player, message);
|
super.disableCustom(player, message);
|
||||||
if (_effects.containsKey(player))
|
if (_effects.containsKey(player))
|
||||||
{
|
{
|
||||||
CircleEffect circleEffect = _effects.get(player);
|
ColoredCircleEffect circleEffect = _effects.get(player);
|
||||||
if (circleEffect != null)
|
if (circleEffect != null)
|
||||||
{
|
{
|
||||||
circleEffect.stop();
|
circleEffect.stop();
|
||||||
|
@ -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];
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user