|
| 1 | +package de.slikey.effectlib.effect; |
| 2 | + |
| 3 | +import java.awt.Color; |
| 4 | +import java.awt.Font; |
| 5 | +import java.awt.image.BufferedImage; |
| 6 | + |
| 7 | +import org.bukkit.Location; |
| 8 | +import org.bukkit.util.Vector; |
| 9 | + |
| 10 | +import de.slikey.effectlib.EffectManager; |
| 11 | +import de.slikey.effectlib.EffectType; |
| 12 | +import de.slikey.effectlib.util.MathUtils; |
| 13 | +import de.slikey.effectlib.util.ParticleEffect; |
| 14 | +import de.slikey.effectlib.util.StringParser; |
| 15 | +import de.slikey.effectlib.util.VectorUtils; |
| 16 | + |
| 17 | +public class TextLocationEffect extends LocationEffect { |
| 18 | + |
| 19 | + public ParticleEffect particle = ParticleEffect.FLAME; |
| 20 | + public String text = "Text"; |
| 21 | + public boolean invert = false; |
| 22 | + public int stepX = 2; |
| 23 | + public int stepY = 2; |
| 24 | + public float size = (float) 1 / 15; |
| 25 | + |
| 26 | + protected final StringParser parser; |
| 27 | + |
| 28 | + public TextLocationEffect(EffectManager effectManager, Location location) { |
| 29 | + this(effectManager, location, new Font("Tahoma", Font.PLAIN, 48)); |
| 30 | + } |
| 31 | + |
| 32 | + public TextLocationEffect(EffectManager effectManager, Location location, Font font) { |
| 33 | + super(effectManager, location); |
| 34 | + parser = new StringParser(font); |
| 35 | + type = EffectType.REPEATING; |
| 36 | + period = 10; |
| 37 | + iterations = -1; |
| 38 | + } |
| 39 | + |
| 40 | + @Override |
| 41 | + public void onRun() { |
| 42 | + int clr = 0; |
| 43 | + BufferedImage image = parser.stringToBufferedImage(text); |
| 44 | + for (int y = 0; y < image.getHeight(); y += stepY) { |
| 45 | + for (int x = 0; x < image.getWidth(); x += stepX) { |
| 46 | + clr = image.getRGB(x, y); |
| 47 | + if (!invert && Color.black.getRGB() != clr) |
| 48 | + continue; |
| 49 | + else if (invert && Color.black.getRGB() == clr) |
| 50 | + continue; |
| 51 | + Vector v = new Vector(x, image.getHeight() - y, 0).multiply(size); |
| 52 | + VectorUtils.rotateAroundAxisY(v, -location.getYaw() * MathUtils.degreesToRadians); |
| 53 | + particle.display(location.add(v), visibleRange); |
| 54 | + location.subtract(v); |
| 55 | + } |
| 56 | + } |
| 57 | + } |
| 58 | +} |
0 commit comments