From 202441422e1bbc6386d5be87af90d4dfd8296d2b Mon Sep 17 00:00:00 2001 From: Chronoken Date: Thu, 16 May 2019 19:16:50 +0200 Subject: [PATCH 01/44] 1.13 support for BLOCK_CRACK, BLOCK_DUST, FALLING_DUST particles --- src/main/resources/plugin.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/plugin.yml b/src/main/resources/plugin.yml index 8c6812f0..896ce974 100644 --- a/src/main/resources/plugin.yml +++ b/src/main/resources/plugin.yml @@ -7,3 +7,4 @@ website: http://www.kevin-carstens.de/ prefix: Effect Library load: POSTWORLD database: false +api-version: 1.13 From 59ded337a295991d89af5def92a73822e3bbf9b5 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Sun, 21 Jul 2019 22:30:56 +0200 Subject: [PATCH 02/44] Fixes and new features. --- src/main/java/de/slikey/effectlib/Effect.java | 20 ++++++++----- .../slikey/effectlib/effect/CircleEffect.java | 16 +++++----- .../slikey/effectlib/effect/CloudEffect.java | 29 ++++++++++--------- .../effectlib/effect/ColoredImageEffect.java | 11 ++++--- .../slikey/effectlib/effect/ImageEffect.java | 11 ++++--- .../slikey/effectlib/effect/ShieldEffect.java | 15 ++++++---- .../slikey/effectlib/effect/SphereEffect.java | 17 ++++++----- .../effectlib/effect/TornadoEffect.java | 20 ++++++++----- .../effectlib/util/BaseImageEffect.java | 24 +++++++-------- 9 files changed, 92 insertions(+), 71 deletions(-) diff --git a/src/main/java/de/slikey/effectlib/Effect.java b/src/main/java/de/slikey/effectlib/Effect.java index eb4fcf66..455e1af7 100644 --- a/src/main/java/de/slikey/effectlib/Effect.java +++ b/src/main/java/de/slikey/effectlib/Effect.java @@ -1,17 +1,17 @@ package de.slikey.effectlib; -import de.slikey.effectlib.util.DynamicLocation; +import java.util.List; +import java.util.ArrayList; -import org.bukkit.Particle; import org.bukkit.Color; +import org.bukkit.Particle; import org.bukkit.Location; import org.bukkit.Material; +import org.bukkit.util.Vector; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; -import org.bukkit.util.Vector; -import java.util.ArrayList; -import java.util.List; +import de.slikey.effectlib.util.DynamicLocation; public abstract class Effect implements Runnable { @@ -466,6 +466,12 @@ public void setTargetLocation(Location location) { target = new DynamicLocation(location); } - public Player getTargetPlayer() {return this.targetPlayer; } - public void setTargetPlayer(Player p){ this.targetPlayer = p; } + public Player getTargetPlayer() { + return this.targetPlayer; + } + + public void setTargetPlayer(Player p) { + this.targetPlayer = p; + } + } diff --git a/src/main/java/de/slikey/effectlib/effect/CircleEffect.java b/src/main/java/de/slikey/effectlib/effect/CircleEffect.java index 7a7ccd38..7f1aa3ce 100644 --- a/src/main/java/de/slikey/effectlib/effect/CircleEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/CircleEffect.java @@ -1,15 +1,15 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; import org.bukkit.Particle; -import de.slikey.effectlib.util.VectorUtils; import org.bukkit.Location; import org.bukkit.util.Vector; -public class CircleEffect extends Effect { +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.VectorUtils; +public class CircleEffect extends Effect { /* * ParticleType of spawned particle @@ -90,10 +90,8 @@ public void onRun() { v.setX(Math.cos(angle) * radius); v.setZ(Math.sin(angle) * radius); VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); - if (enableRotation) { - VectorUtils.rotateVector(v, angularVelocityX * step, angularVelocityY * step, angularVelocityZ * step); - } - display(particle, location.clone().add(v), 0, 30); + if (enableRotation) VectorUtils.rotateVector(v, angularVelocityX * step, angularVelocityY * step, angularVelocityZ * step); + display(particle, location.clone().add(v)); step++; } } diff --git a/src/main/java/de/slikey/effectlib/effect/CloudEffect.java b/src/main/java/de/slikey/effectlib/effect/CloudEffect.java index 2c726ba1..be701807 100644 --- a/src/main/java/de/slikey/effectlib/effect/CloudEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/CloudEffect.java @@ -1,14 +1,15 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; -import org.bukkit.Particle; -import de.slikey.effectlib.util.RandomUtils; import org.bukkit.Color; import org.bukkit.Location; +import org.bukkit.Particle; import org.bukkit.util.Vector; +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.RandomUtils; + public class CloudEffect extends Effect { /* @@ -16,6 +17,7 @@ public class CloudEffect extends Effect { */ public Particle cloudParticle = Particle.CLOUD; public Color cloudColor = null; + public float cloudSpeed = 0; /* * Particle of the rain/snow @@ -37,6 +39,9 @@ public class CloudEffect extends Effect { */ public double yOffset = .8; + // Should the effect increase its height every iteration? + public boolean increaseHeight = true; + public CloudEffect(EffectManager manager) { super(manager); type = EffectType.REPEATING; @@ -50,23 +55,21 @@ public void onRun() { location.add(0, yOffset, 0); for (int i = 0; i < 50; i++) { Vector v = RandomUtils.getRandomCircleVector().multiply(RandomUtils.random.nextDouble() * cloudSize); - display(cloudParticle, location.add(v), cloudColor, 0, 7); + display(cloudParticle, location.add(v), cloudColor, cloudSpeed, 1); location.subtract(v); } - Location l = location.add(0, .2, 0); + Location l; + if (increaseHeight) l = location.add(0, 0.2, 0); + else l = location; for (int i = 0; i < 15; i++) { int r = RandomUtils.random.nextInt(2); double x = RandomUtils.random.nextDouble() * particleRadius; double z = RandomUtils.random.nextDouble() * particleRadius; l.add(x, 0, z); - if (r != 1) { - display(mainParticle, l); - } + if (r != 1) display(mainParticle, l); l.subtract(x, 0, z); l.subtract(x, 0, z); - if (r != 1) { - display(mainParticle, l); - } + if (r != 1) display(mainParticle, l); l.add(x, 0, z); } } diff --git a/src/main/java/de/slikey/effectlib/effect/ColoredImageEffect.java b/src/main/java/de/slikey/effectlib/effect/ColoredImageEffect.java index 38df0cbd..c56402a4 100644 --- a/src/main/java/de/slikey/effectlib/effect/ColoredImageEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/ColoredImageEffect.java @@ -1,14 +1,16 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.util.BaseImageEffect; +import java.awt.Color; +import java.awt.image.BufferedImage; + import org.bukkit.Location; import org.bukkit.util.Vector; -import java.awt.Color; -import java.awt.image.BufferedImage; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.BaseImageEffect; public class ColoredImageEffect extends BaseImageEffect { + public ColoredImageEffect(EffectManager effectManager) { super(effectManager); } @@ -21,4 +23,5 @@ protected void display(BufferedImage image, Vector v, Location location, int pix display(particle, location.add(v), org.bukkit.Color.fromRGB(r, g, b)); location.subtract(v); } + } diff --git a/src/main/java/de/slikey/effectlib/effect/ImageEffect.java b/src/main/java/de/slikey/effectlib/effect/ImageEffect.java index cbd14607..96ff2061 100644 --- a/src/main/java/de/slikey/effectlib/effect/ImageEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/ImageEffect.java @@ -1,14 +1,13 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.util.BaseImageEffect; -import de.slikey.effectlib.util.MathUtils; -import de.slikey.effectlib.util.VectorUtils; +import java.awt.Color; +import java.awt.image.BufferedImage; + import org.bukkit.Location; import org.bukkit.util.Vector; -import java.awt.Color; -import java.awt.image.BufferedImage; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.BaseImageEffect; public class ImageEffect extends BaseImageEffect { diff --git a/src/main/java/de/slikey/effectlib/effect/ShieldEffect.java b/src/main/java/de/slikey/effectlib/effect/ShieldEffect.java index ff850d7f..b498a9c3 100644 --- a/src/main/java/de/slikey/effectlib/effect/ShieldEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/ShieldEffect.java @@ -1,13 +1,14 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; import org.bukkit.Particle; -import de.slikey.effectlib.util.RandomUtils; import org.bukkit.Location; import org.bukkit.util.Vector; +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.RandomUtils; + public class ShieldEffect extends Effect { /** @@ -30,6 +31,9 @@ public class ShieldEffect extends Effect { */ public boolean sphere = false; + // Set to true to reverse the direction of the shield (works only if sphere is set to false) + public boolean reverse = false; + public ShieldEffect(EffectManager effectManager) { super(effectManager); type = EffectType.REPEATING; @@ -43,7 +47,8 @@ public void onRun() { for (int i = 0; i < particles; i++) { Vector vector = RandomUtils.getRandomVector().multiply(radius); if (!sphere) { - vector.setY(Math.abs(vector.getY())); + if (reverse) vector.setY(Math.abs(vector.getY()) * -1); + else vector.setY(Math.abs(vector.getY())); } location.add(vector); display(particle, location); diff --git a/src/main/java/de/slikey/effectlib/effect/SphereEffect.java b/src/main/java/de/slikey/effectlib/effect/SphereEffect.java index b5fd0d57..956844ca 100644 --- a/src/main/java/de/slikey/effectlib/effect/SphereEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/SphereEffect.java @@ -1,13 +1,14 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; import org.bukkit.Particle; -import de.slikey.effectlib.util.RandomUtils; import org.bukkit.Location; import org.bukkit.util.Vector; +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.RandomUtils; + public class SphereEffect extends Effect { /** @@ -35,6 +36,9 @@ public class SphereEffect extends Effect { */ public double radiusIncrease = 0; + // Amount to increase the particles per tick + public int particleIncrease = 0; + public SphereEffect(EffectManager effectManager) { super(effectManager); type = EffectType.REPEATING; @@ -44,9 +48,8 @@ public SphereEffect(EffectManager effectManager) { @Override public void onRun() { - if (radiusIncrease != 0) { - radius += radiusIncrease; - } + if (radiusIncrease != 0) radius += radiusIncrease; + if (particleIncrease != 0) particles += particleIncrease; Location location = getLocation(); location.add(0, yOffset, 0); diff --git a/src/main/java/de/slikey/effectlib/effect/TornadoEffect.java b/src/main/java/de/slikey/effectlib/effect/TornadoEffect.java index c6be35e6..67a190b0 100644 --- a/src/main/java/de/slikey/effectlib/effect/TornadoEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/TornadoEffect.java @@ -1,15 +1,18 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; -import org.bukkit.Particle; -import de.slikey.effectlib.util.RandomUtils; +import java.util.List; import java.util.ArrayList; + import org.bukkit.Color; import org.bukkit.Location; +import org.bukkit.Particle; import org.bukkit.util.Vector; +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.RandomUtils; + public class TornadoEffect extends Effect { /* @@ -23,6 +26,7 @@ public class TornadoEffect extends Effect { */ public Particle cloudParticle = Particle.CLOUD; public Color cloudColor = null; + public float cloudSpeed = 0; /* * Size of the cloud @@ -82,7 +86,7 @@ public void onRun() { for (int i = 0; i < (100 * cloudSize); i++) { Vector v = RandomUtils.getRandomCircleVector().multiply(RandomUtils.random.nextDouble() * cloudSize); if (showCloud) { - display(cloudParticle, l.add(v), cloudColor, 0, 7); + display(cloudParticle, l.add(v), cloudColor, cloudSpeed, 1); l.subtract(v); } } @@ -104,10 +108,10 @@ public void onRun() { l.subtract(0, yOffset, 0); } - public ArrayList createCircle(double y, double radius) { + public List createCircle(double y, double radius) { double amount = radius * 64; double inc = (2 * Math.PI) / amount; - ArrayList vecs = new ArrayList(); + List vecs = new ArrayList(); for (int i = 0; i < amount; i++) { double angle = i * inc; double x = radius * Math.cos(angle); diff --git a/src/main/java/de/slikey/effectlib/util/BaseImageEffect.java b/src/main/java/de/slikey/effectlib/util/BaseImageEffect.java index 2886ba7a..2557c91d 100644 --- a/src/main/java/de/slikey/effectlib/util/BaseImageEffect.java +++ b/src/main/java/de/slikey/effectlib/util/BaseImageEffect.java @@ -1,15 +1,16 @@ package de.slikey.effectlib.util; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; -import de.slikey.effectlib.effect.ColoredImageEffect; +import java.io.File; +import java.awt.image.BufferedImage; + import org.bukkit.Location; import org.bukkit.Particle; import org.bukkit.util.Vector; -import java.awt.image.BufferedImage; -import java.io.File; +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.effect.ColoredImageEffect; public abstract class BaseImageEffect extends Effect { @@ -170,12 +171,10 @@ public void onRun() { if (rotation != null) { VectorUtils.rotateVector(v, rotation.getX() * MathUtils.degreesToRadians, rotation.getY() * MathUtils.degreesToRadians, rotation.getZ() * MathUtils.degreesToRadians); } - if (orient) { - VectorUtils.rotateAroundAxisY(v, -location.getYaw() * MathUtils.degreesToRadians); - } - if (orientPitch) { - VectorUtils.rotateVector(v, location); - } + + if (orientPitch) VectorUtils.rotateAroundAxisX(v, Math.toRadians(location.getPitch())); + if (orient) VectorUtils.rotateAroundAxisY(v, -location.getYaw() * MathUtils.degreesToRadians); + if (enableRotation) { double rotX = 0; double rotY = 0; @@ -228,4 +227,5 @@ public enum Plane { } protected abstract void display(BufferedImage image, Vector v, Location location, int pixel); + } From 9646fc1019ff7607630879f9245c7dfd6b16fa0b Mon Sep 17 00:00:00 2001 From: Chronoken Date: Wed, 15 Apr 2020 18:35:01 +0200 Subject: [PATCH 03/44] CircleEffect is now rotating properly --- src/main/java/de/slikey/effectlib/effect/CircleEffect.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/de/slikey/effectlib/effect/CircleEffect.java b/src/main/java/de/slikey/effectlib/effect/CircleEffect.java index 7f1aa3ce..08191130 100644 --- a/src/main/java/de/slikey/effectlib/effect/CircleEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/CircleEffect.java @@ -7,6 +7,7 @@ import de.slikey.effectlib.Effect; import de.slikey.effectlib.EffectType; import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.MathUtils; import de.slikey.effectlib.util.VectorUtils; public class CircleEffect extends Effect { @@ -90,6 +91,8 @@ public void onRun() { v.setX(Math.cos(angle) * radius); v.setZ(Math.sin(angle) * radius); VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); + VectorUtils.rotateAroundAxisX(v, (location.getPitch() + 90) * MathUtils.degreesToRadians); + VectorUtils.rotateAroundAxisY(v, -location.getYaw() * MathUtils.degreesToRadians); if (enableRotation) VectorUtils.rotateVector(v, angularVelocityX * step, angularVelocityY * step, angularVelocityZ * step); display(particle, location.clone().add(v)); step++; From 7503a6ef37c636527f79ad73f45eaf1b3b757266 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Wed, 15 Apr 2020 18:42:22 +0200 Subject: [PATCH 04/44] Fixed pitch amount --- src/main/java/de/slikey/effectlib/effect/CircleEffect.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/slikey/effectlib/effect/CircleEffect.java b/src/main/java/de/slikey/effectlib/effect/CircleEffect.java index 08191130..1a99ff24 100644 --- a/src/main/java/de/slikey/effectlib/effect/CircleEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/CircleEffect.java @@ -91,7 +91,7 @@ public void onRun() { v.setX(Math.cos(angle) * radius); v.setZ(Math.sin(angle) * radius); VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); - VectorUtils.rotateAroundAxisX(v, (location.getPitch() + 90) * MathUtils.degreesToRadians); + VectorUtils.rotateAroundAxisX(v, location.getPitch() * MathUtils.degreesToRadians); VectorUtils.rotateAroundAxisY(v, -location.getYaw() * MathUtils.degreesToRadians); if (enableRotation) VectorUtils.rotateVector(v, angularVelocityX * step, angularVelocityY * step, angularVelocityZ * step); display(particle, location.clone().add(v)); From 0fa75a2db5d5ed2e184c0b935714e9c305ec4340 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Wed, 15 Apr 2020 18:50:05 +0200 Subject: [PATCH 05/44] DonutEffect now rotates properly --- .../de/slikey/effectlib/effect/DonutEffect.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/slikey/effectlib/effect/DonutEffect.java b/src/main/java/de/slikey/effectlib/effect/DonutEffect.java index ae33bda2..686ba330 100644 --- a/src/main/java/de/slikey/effectlib/effect/DonutEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/DonutEffect.java @@ -1,13 +1,15 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; import org.bukkit.Particle; -import de.slikey.effectlib.util.VectorUtils; import org.bukkit.Location; import org.bukkit.util.Vector; +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.MathUtils; +import de.slikey.effectlib.util.VectorUtils; + public class DonutEffect extends Effect { /** @@ -31,7 +33,7 @@ public class DonutEffect extends Effect { public float radiusDonut = 2; /** - * Radius of the tube (the circles on the outside. + * Radius of the tube (the circles on the outside). */ public float radiusTube = .5f; @@ -61,6 +63,8 @@ public void onRun() { v.setZ(radiusTube * Math.sin(phi)); VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); + VectorUtils.rotateAroundAxisX(v, location.getPitch() * MathUtils.degreesToRadians); + VectorUtils.rotateAroundAxisY(v, -location.getYaw() * MathUtils.degreesToRadians); display(particle, location.add(v)); location.subtract(v); From 75e6386b86ace35bf24d1908ed4cd09ae75fb724 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Wed, 15 Apr 2020 18:57:54 +0200 Subject: [PATCH 06/44] Fixed pitch amount --- src/main/java/de/slikey/effectlib/effect/DonutEffect.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/slikey/effectlib/effect/DonutEffect.java b/src/main/java/de/slikey/effectlib/effect/DonutEffect.java index 686ba330..52ba1f71 100644 --- a/src/main/java/de/slikey/effectlib/effect/DonutEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/DonutEffect.java @@ -63,7 +63,7 @@ public void onRun() { v.setZ(radiusTube * Math.sin(phi)); VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); - VectorUtils.rotateAroundAxisX(v, location.getPitch() * MathUtils.degreesToRadians); + VectorUtils.rotateAroundAxisX(v, (location.getPitch() + 90) * MathUtils.degreesToRadians); VectorUtils.rotateAroundAxisY(v, -location.getYaw() * MathUtils.degreesToRadians); display(particle, location.add(v)); From 14fcf3e3a8e592fc9fec322645c0c040deef2d10 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Thu, 7 May 2020 01:53:04 +0200 Subject: [PATCH 07/44] Reflection Fix --- src/main/java/de/slikey/effectlib/EffectManager.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slikey/effectlib/EffectManager.java b/src/main/java/de/slikey/effectlib/EffectManager.java index d69ec7e5..f2bb0bf8 100644 --- a/src/main/java/de/slikey/effectlib/EffectManager.java +++ b/src/main/java/de/slikey/effectlib/EffectManager.java @@ -360,7 +360,17 @@ protected boolean setField(Object effect, String key, ConfigurationSection secti fieldKey = stringValue; fieldSection = parameterMap; } - Field field = effect.getClass().getField(key); + + Field field = null; + + try { + field = effect.getClass().getField(key); + } catch (NoSuchFieldException exception) { + + } + + if (field == null) return false; + if (field.getType().equals(Integer.TYPE) || field.getType().equals(Integer.class)) { field.set(effect, fieldSection.getInt(fieldKey)); } else if (field.getType().equals(Float.TYPE) || field.getType().equals(Float.class)) { From b2ce57acc9521d38b909943d63ffa10c029b57f9 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Sun, 10 May 2020 15:26:36 +0200 Subject: [PATCH 08/44] Added getEffects function --- src/main/java/de/slikey/effectlib/EffectManager.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/de/slikey/effectlib/EffectManager.java b/src/main/java/de/slikey/effectlib/EffectManager.java index f2bb0bf8..68c61b25 100644 --- a/src/main/java/de/slikey/effectlib/EffectManager.java +++ b/src/main/java/de/slikey/effectlib/EffectManager.java @@ -330,6 +330,10 @@ public void onError(String message, Throwable ex) { } } + public Map getEffects() { + return effects; + } + public int getParticleRange() { return visibleRange; } From 0052dfe0dec332be540043595e57c8f05c1d489c Mon Sep 17 00:00:00 2001 From: Chronoken Date: Sun, 10 May 2020 22:53:16 +0200 Subject: [PATCH 09/44] Cleanup --- pom.xml | 4 +- src/main/java/de/slikey/effectlib/Effect.java | 76 +++---- .../de/slikey/effectlib/EffectManager.java | 186 +++++++----------- .../de/slikey/effectlib/math/Transforms.java | 80 ++++---- .../de/slikey/effectlib/util/ConfigUtils.java | 70 +++---- .../effectlib/util/DynamicLocation.java | 113 ++++------- .../effectlib/util/ParticleDisplay.java | 21 +- .../util/versions/ParticleDisplay_12.java | 6 +- .../util/versions/ParticleDisplay_13.java | 14 +- 9 files changed, 215 insertions(+), 355 deletions(-) diff --git a/pom.xml b/pom.xml index ed969656..83d70da3 100644 --- a/pom.xml +++ b/pom.xml @@ -77,8 +77,8 @@ maven-compiler-plugin 3.3 - 1.6 - 1.6 + 7 + 7 diff --git a/src/main/java/de/slikey/effectlib/Effect.java b/src/main/java/de/slikey/effectlib/Effect.java index 455e1af7..8ba1a568 100644 --- a/src/main/java/de/slikey/effectlib/Effect.java +++ b/src/main/java/de/slikey/effectlib/Effect.java @@ -197,7 +197,7 @@ public Effect(EffectManager effectManager) { throw new IllegalArgumentException("EffectManager cannot be null!"); } this.effectManager = effectManager; - this.visibleRange = effectManager.getParticleRange(); + visibleRange = effectManager.getParticleRange(); } public final void cancel() { @@ -205,11 +205,8 @@ public final void cancel() { } public final void cancel(boolean callback) { - if (callback) { - done(); - } else { - done = true; - } + if (callback) done(); + else done = true; } public final boolean isDone() { @@ -230,23 +227,19 @@ public final void run() { cancel(); return; } - if (done) { - return; - } + if (done) return; + try { onRun(); } catch (Exception ex) { done(); effectManager.onError(ex); } + if (type == EffectType.REPEATING) { - if (iterations == -1) { - return; - } + if (iterations == -1) return; iterations--; - if (iterations < 1) { - done(); - } + if (iterations < 1) done(); } else { done(); } @@ -257,7 +250,7 @@ public final void run() { * state can be reset. */ protected void reset() { - this.done = false; + done = false; } public void prepare() { @@ -323,17 +316,13 @@ public final Location getTarget() { * Set the Location this Effect is centered on. */ public void setDynamicOrigin(DynamicLocation location) { - if (location == null) { - throw new IllegalArgumentException("Origin Location cannot be null!"); - } + if (location == null) throw new IllegalArgumentException("Origin Location cannot be null!"); origin = location; - if (offset != null) { - origin.addOffset(offset); - } - if (relativeOffset != null) { - origin.addRelativeOffset(relativeOffset); - } + if (offset != null) origin.addOffset(offset); + + if (relativeOffset != null) origin.addRelativeOffset(relativeOffset); + origin.setDirectionOffset(yawOffset, pitchOffset); origin.setYaw(yaw); origin.setPitch(pitch); @@ -347,9 +336,7 @@ public void setDynamicOrigin(DynamicLocation location) { */ public void setDynamicTarget(DynamicLocation location) { target = location; - if (target != null && targetOffset != null) { - target.addOffset(targetOffset); - } + if (target != null && targetOffset != null) target.addOffset(targetOffset); if (target != null) { target.setUpdateLocation(updateLocations); target.setUpdateDirection(updateDirections); @@ -358,21 +345,14 @@ public void setDynamicTarget(DynamicLocation location) { protected final boolean validate() { // Check if the origin and target entities are present - if (disappearWithOriginEntity && (origin != null && !origin.hasValidEntity())) { - return false; - } - - if (disappearWithTargetEntity && (target != null && !target.hasValidEntity())) { - return false; - } - + if (disappearWithOriginEntity && (origin != null && !origin.hasValidEntity())) return false; + if (disappearWithTargetEntity && (target != null && !target.hasValidEntity())) return false; + // Check for a valid Location updateLocation(); updateTarget(); Location location = getLocation(); - if (location == null) { - return false; - } + if (location == null) return false; if (autoOrient) { Location targetLocation = target == null ? null : target.getLocation(); if (targetLocation != null) { @@ -387,24 +367,18 @@ protected final boolean validate() { protected void updateDuration() { if (duration != null) { - if (period < 1) { - period = 1; - } + if (period < 1) period = 1; iterations = duration / period / 50; } maxIterations = iterations; } protected void updateLocation() { - if (origin != null) { - origin.update(); - } + if (origin != null) origin.update(); } protected void updateTarget() { - if (target != null) { - target.update(); - } + if (target != null) target.update(); } protected void display(Particle effect, Location location) { @@ -421,7 +395,7 @@ protected void display(Particle particle, Location location, float speed, int am protected void display(Particle particle, Location location, Color color, float speed, int amount) { if (targetPlayers == null && targetPlayer != null) { - targetPlayers = new ArrayList(); + targetPlayers = new ArrayList<>(); targetPlayers.add(targetPlayer); } effectManager.display(particle, location, particleOffsetX, particleOffsetY, particleOffsetZ, speed, amount, @@ -467,11 +441,11 @@ public void setTargetLocation(Location location) { } public Player getTargetPlayer() { - return this.targetPlayer; + return targetPlayer; } public void setTargetPlayer(Player p) { - this.targetPlayer = p; + targetPlayer = p; } } diff --git a/src/main/java/de/slikey/effectlib/EffectManager.java b/src/main/java/de/slikey/effectlib/EffectManager.java index 68c61b25..8f69e1e9 100644 --- a/src/main/java/de/slikey/effectlib/EffectManager.java +++ b/src/main/java/de/slikey/effectlib/EffectManager.java @@ -1,40 +1,39 @@ package de.slikey.effectlib; -import de.slikey.effectlib.math.Transforms; -import de.slikey.effectlib.util.ConfigUtils; +import java.io.File; +import java.util.Map; +import java.util.Set; +import java.awt.Font; +import java.util.List; +import java.util.HashMap; +import java.util.Iterator; +import java.util.ArrayList; +import java.util.Collection; +import java.lang.reflect.Field; +import java.util.logging.Level; +import java.awt.image.BufferedImage; +import java.lang.reflect.Constructor; + import de.slikey.effectlib.util.Disposable; -import de.slikey.effectlib.util.DynamicLocation; -import de.slikey.effectlib.util.ImageLoadCallback; +import de.slikey.effectlib.util.ConfigUtils; import de.slikey.effectlib.util.ImageLoadTask; import de.slikey.effectlib.util.ParticleDisplay; +import de.slikey.effectlib.util.DynamicLocation; +import de.slikey.effectlib.util.ImageLoadCallback; -import org.bukkit.Bukkit; import org.bukkit.Color; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.MemoryConfiguration; +import org.bukkit.util.Vector; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; import org.bukkit.plugin.Plugin; -import org.bukkit.scheduler.BukkitScheduler; import org.bukkit.scheduler.BukkitTask; -import org.bukkit.util.Vector; - -import java.awt.Font; -import java.awt.image.BufferedImage; -import java.io.File; -import java.lang.reflect.Constructor; -import java.lang.reflect.Field; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.logging.Level; +import org.bukkit.scheduler.BukkitScheduler; +import org.bukkit.configuration.MemoryConfiguration; +import org.bukkit.configuration.ConfigurationSection; import com.google.common.base.CaseFormat; @@ -47,7 +46,7 @@ public class EffectManager implements Disposable { private static List effectManagers; - private static Map> effectClasses = new HashMap>(); + private static Map> effectClasses = new HashMap<>(); private final Plugin owningPlugin; private final Map effects; private ParticleDisplay display; @@ -56,21 +55,19 @@ public class EffectManager implements Disposable { private boolean debug = false; private int visibleRange = 32; private File imageCacheFolder; - private Map imageCache = new HashMap(); + private Map imageCache = new HashMap<>(); public EffectManager(Plugin owningPlugin) { imageCacheFolder = owningPlugin == null ? null : new File(owningPlugin.getDataFolder(), "imagecache"); this.owningPlugin = owningPlugin; - Transforms.setEffectManager(this); - effects = new HashMap(); + effects = new HashMap<>(); disposed = false; disposeOnTermination = false; } private ParticleDisplay getDisplay() { - if (display == null) { - display = ParticleDisplay.newInstance(); - } + if (display == null) display = ParticleDisplay.newInstance(); + display.setManager(this); return display; @@ -81,42 +78,25 @@ public void display(Particle particle, Location center, float offsetX, float off } public void start(Effect effect) { - if (disposed) { - throw new IllegalStateException("EffectManager is disposed and not able to accept any effects."); - } - if (disposeOnTermination) { - throw new IllegalStateException("EffectManager is awaiting termination to dispose and not able to accept any effects."); - } - - if (effects.containsKey(effect)) { - effect.cancel(false); - } - + if (disposed) throw new IllegalStateException("EffectManager is disposed and not able to accept any effects."); + if (disposeOnTermination) throw new IllegalStateException("EffectManager is awaiting termination to dispose and not able to accept any effects."); + if (effects.containsKey(effect)) effect.cancel(false); if (!owningPlugin.isEnabled()) return; BukkitScheduler s = Bukkit.getScheduler(); BukkitTask task = null; switch (effect.getType()) { case INSTANT: - if(effect.isAsynchronous()) { - task = s.runTaskAsynchronously(owningPlugin, effect); - } else { - task = s.runTask(owningPlugin, effect); - } + if (effect.isAsynchronous()) task = s.runTaskAsynchronously(owningPlugin, effect); + else task = s.runTask(owningPlugin, effect); break; case DELAYED: - if (effect.isAsynchronous()) { - task = s.runTaskLaterAsynchronously(owningPlugin, effect, effect.getDelay()); - } else { - task = s.runTaskLater(owningPlugin, effect, effect.getDelay()); - } + if (effect.isAsynchronous()) task = s.runTaskLaterAsynchronously(owningPlugin, effect, effect.getDelay()); + else task = s.runTaskLater(owningPlugin, effect, effect.getDelay()); break; case REPEATING: - if (effect.isAsynchronous()) { - task = s.runTaskTimerAsynchronously(owningPlugin, effect, effect.getDelay(), effect.getPeriod()); - } else { - task = s.runTaskTimer(owningPlugin, effect, effect.getDelay(), effect.getPeriod()); - } + if (effect.isAsynchronous()) task = s.runTaskTimerAsynchronously(owningPlugin, effect, effect.getDelay(), effect.getPeriod()); + else task = s.runTaskTimer(owningPlugin, effect, effect.getDelay(), effect.getPeriod()); break; } synchronized (this) { @@ -181,9 +161,7 @@ public Effect getEffectByClassName(String effectClass) { // A shaded manager may provide a fully-qualified path. if (effectLibClass == null && !effectClass.contains(".")) { effectClass = "de.slikey.effectlib.effect." + effectClass; - if (!effectClass.endsWith("Effect")) { - effectClass = effectClass + "Effect"; - } + if (!effectClass.endsWith("Effect")) effectClass = effectClass + "Effect"; effectLibClass = effectClasses.get(effectClass); } if (effectLibClass == null) { @@ -208,15 +186,11 @@ public Effect getEffectByClassName(String effectClass) { public Effect getEffect(String effectClass, ConfigurationSection parameters, DynamicLocation origin, DynamicLocation target, ConfigurationSection parameterMap, Player targetPlayer) { Effect effect = getEffectByClassName(effectClass); - if (effect == null) { - return null; - } + if (effect == null) return null; Collection keys = parameters.getKeys(false); for (String key : keys) { - if (key.equals("class")) { - continue; - } + if (key.equals("class")) continue; if (!setField(effect, key, parameters, parameterMap) && debug) { owningPlugin.getLogger().warning("Unable to assign EffectLib property " + key + " of class " + effect.getClass().getName()); @@ -226,8 +200,7 @@ public Effect getEffect(String effectClass, ConfigurationSection parameters, Dyn effect.setDynamicOrigin(origin); effect.setDynamicTarget(target); - if (targetPlayer != null) - effect.setTargetPlayer(targetPlayer); + if (targetPlayer != null) effect.setTargetPlayer(targetPlayer); return effect; } @@ -235,9 +208,7 @@ public Effect getEffect(String effectClass, ConfigurationSection parameters, Dyn @Deprecated public Effect start(String effectClass, ConfigurationSection parameters, DynamicLocation origin, DynamicLocation target, Map parameterMap, Player targetPlayer) { ConfigurationSection configMap = null; - if (parameterMap != null) { - configMap = ConfigUtils.toStringConfiguration(parameterMap); - } + if (parameterMap != null) configMap = ConfigUtils.toStringConfiguration(parameterMap); return start(effectClass, parameters, origin, target, configMap, targetPlayer); } @@ -255,15 +226,13 @@ public Effect start(String effectClass, ConfigurationSection parameters, Dynamic */ public Effect start(String effectClass, ConfigurationSection parameters, DynamicLocation origin, DynamicLocation target, ConfigurationSection parameterMap, Player targetPlayer) { Effect effect = getEffect(effectClass, parameters, origin, target, parameterMap, targetPlayer); - if (effect == null) { - return null; - } + if (effect == null) return null; effect.start(); return effect; } public void cancel(boolean callback) { - List allEffects = new ArrayList(effects.keySet()); + List allEffects = new ArrayList<>(effects.keySet()); for (Effect effect : allEffects) { effect.cancel(callback); } @@ -272,36 +241,24 @@ public void cancel(boolean callback) { public void done(Effect effect) { synchronized (this) { BukkitTask existingTask = effects.get(effect); - if (existingTask != null) { - existingTask.cancel(); - } + if (existingTask != null) existingTask.cancel(); effects.remove(effect); } - if (effect.callback != null && owningPlugin.isEnabled()) { - Bukkit.getScheduler().runTask(owningPlugin, effect.callback); - } - if (disposeOnTermination && effects.isEmpty()) { - dispose(); - } + if (effect.callback != null && owningPlugin.isEnabled()) Bukkit.getScheduler().runTask(owningPlugin, effect.callback); + if (disposeOnTermination && effects.isEmpty()) dispose(); } @Override public void dispose() { - if (disposed) { - return; - } + if (disposed) return; disposed = true; cancel(false); - if (effectManagers != null) { - effectManagers.remove(this); - } + if (effectManagers != null) effectManagers.remove(this); } public void disposeOnTermination() { disposeOnTermination = true; - if (effects.isEmpty()) { - dispose(); - } + if (effects.isEmpty()) dispose(); } public void enableDebug(boolean enable) { @@ -313,21 +270,15 @@ public boolean isDebugEnabled() { } public void onError(Throwable ex) { - if (debug) { - owningPlugin.getLogger().log(Level.WARNING, "Particle Effect error", ex); - } + if (debug) owningPlugin.getLogger().log(Level.WARNING, "Particle Effect error", ex); } public void onError(String message) { - if (debug) { - owningPlugin.getLogger().log(Level.WARNING, message); - } + if (debug) owningPlugin.getLogger().log(Level.WARNING, message); } public void onError(String message, Throwable ex) { - if (debug) { - owningPlugin.getLogger().log(Level.WARNING, message, ex); - } + if (debug) owningPlugin.getLogger().log(Level.WARNING, message, ex); } public Map getEffects() { @@ -352,12 +303,9 @@ protected boolean setField(Object effect, String key, ConfigurationSection secti String fieldKey = key; // Allow underscore_style and dash_style parameters - if (key.contains("-")) { - key = key.replace("-", "_"); - } - if (key.contains("_")) { - key = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, key); - } + if (key.contains("-")) key = key.replace("-", "_"); + + if (key.contains("_")) key = CaseFormat.LOWER_UNDERSCORE.to(CaseFormat.LOWER_CAMEL, key); ConfigurationSection fieldSection = section; if (parameterMap != null && stringValue.startsWith("$") && parameterMap.contains(stringValue)) { @@ -378,7 +326,7 @@ protected boolean setField(Object effect, String key, ConfigurationSection secti if (field.getType().equals(Integer.TYPE) || field.getType().equals(Integer.class)) { field.set(effect, fieldSection.getInt(fieldKey)); } else if (field.getType().equals(Float.TYPE) || field.getType().equals(Float.class)) { - field.set(effect, (float)fieldSection.getDouble(fieldKey)); + field.set(effect, (float) fieldSection.getDouble(fieldKey)); } else if (field.getType().equals(Double.TYPE) || field.getType().equals(Double.class)) { field.set(effect, fieldSection.getDouble(fieldKey)); } else if (field.getType().equals(Boolean.TYPE) || field.getType().equals(Boolean.class)) { @@ -386,9 +334,9 @@ protected boolean setField(Object effect, String key, ConfigurationSection secti } else if (field.getType().equals(Long.TYPE) || field.getType().equals(Long.class)) { field.set(effect, fieldSection.getLong(fieldKey)); } else if (field.getType().equals(Short.TYPE) || field.getType().equals(Short.class)) { - field.set(effect, (short)fieldSection.getInt(fieldKey)); + field.set(effect, (short) fieldSection.getInt(fieldKey)); } else if (field.getType().equals(Byte.TYPE) || field.getType().equals(Byte.class)) { - field.set(effect, (byte)fieldSection.getInt(fieldKey)); + field.set(effect, (byte) fieldSection.getInt(fieldKey)); } else if (field.getType().equals(String.class)) { String value = fieldSection.getString(fieldKey); field.set(effect, value); @@ -474,23 +422,20 @@ protected boolean setField(Object effect, String key, ConfigurationSection secti } public static void initialize() { - effectManagers = new ArrayList(); + effectManagers = new ArrayList<>(); } public static List getManagers() { - if (effectManagers == null) { - initialize(); - } + if (effectManagers == null) initialize(); return effectManagers; } public static void disposeAll() { - if (effectManagers != null) { - for (Iterator i = effectManagers.iterator(); i.hasNext();) { - EffectManager em = i.next(); - i.remove(); - em.dispose(); - } + if (effectManagers == null) return; + for (Iterator i = effectManagers.iterator(); i.hasNext();) { + EffectManager em = i.next(); + i.remove(); + em.dispose(); } } @@ -526,4 +471,5 @@ public void run() { public void registerEffectClass(String key, Class effectClass) { effectClasses.put(key, effectClass); } + } diff --git a/src/main/java/de/slikey/effectlib/math/Transforms.java b/src/main/java/de/slikey/effectlib/math/Transforms.java index 5a84c867..f843a19e 100644 --- a/src/main/java/de/slikey/effectlib/math/Transforms.java +++ b/src/main/java/de/slikey/effectlib/math/Transforms.java @@ -1,52 +1,49 @@ package de.slikey.effectlib.math; +import java.util.Map; +import java.util.List; +import java.util.HashMap; +import java.util.ArrayList; +import java.util.Collection; + +import de.slikey.effectlib.EffectLib; import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.ConfigUtils; import org.bukkit.configuration.ConfigurationSection; -import java.util.ArrayList; -import java.util.Collection; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - public class Transforms { + private static final String TRANSFORM_BUILTIN_CLASSPATH = "de.slikey.effectlib.math"; - private static Map> transformClasses = new HashMap>(); - private static EffectManager effectManager; + private static Map> transformClasses = new HashMap<>(); + private static List effectManagers = EffectLib.instance().getEffectManagers(); public static Transform loadTransform(ConfigurationSection base, String value) { - if (base.isConfigurationSection(value)) { - return loadTransform(ConfigUtils.getConfigurationSection(base, value)); - } - if (base.isDouble(value) || base.isInt(value)) { - return new ConstantTransform(base.getDouble(value)); - } + if (base.isConfigurationSection(value)) return loadTransform(ConfigUtils.getConfigurationSection(base, value)); + if (base.isDouble(value) || base.isInt(value)) return new ConstantTransform(base.getDouble(value)); if (base.isString(value)) { String equation = base.getString(value); - if (equation.equalsIgnoreCase("t") || equation.equalsIgnoreCase("time")) { - return new EchoTransform(); - } + if (equation.equalsIgnoreCase("t") || equation.equalsIgnoreCase("time")) return new EchoTransform(); EquationTransform transform = EquationStore.getInstance().getTransform(equation, "t"); Exception ex = transform.getException(); - if (ex != null && effectManager != null) { - effectManager.onError("Error parsing equation: " + equation, ex); + if (ex != null && !effectManagers.isEmpty()) { + for (EffectManager effectManager : effectManagers) { + if (effectManager == null) continue; + effectManager.onError("Error parsing equation: " + equation, ex); + break; + } } return transform; } return new ConstantTransform(0); } - public static Collection loadTransformList(ConfigurationSection base, String value) - { + public static Collection loadTransformList(ConfigurationSection base, String value) { Collection transformConfigs = ConfigUtils.getNodeList(base, value); - List transforms = new ArrayList(); - if (transformConfigs != null) - { - for (ConfigurationSection transformConfig : transformConfigs) - { - transforms.add(loadTransform(transformConfig)); - } + List transforms = new ArrayList<>(); + if (transformConfigs == null) return transforms; + + for (ConfigurationSection transformConfig : transformConfigs) { + transforms.add(loadTransform(transformConfig)); } return transforms; @@ -54,15 +51,11 @@ public static Collection loadTransformList(ConfigurationSection base, public static Transform loadTransform(ConfigurationSection parameters) { Transform transform = null; - if (parameters != null && parameters.contains("class")) - { + if (parameters != null && parameters.contains("class")) { String className = parameters.getString("class"); - try - { - if (!className.contains(".")) - { - className = TRANSFORM_BUILTIN_CLASSPATH + "." + className; - } + try { + if (!className.contains(".")) className = TRANSFORM_BUILTIN_CLASSPATH + "." + className; + Class genericClass = transformClasses.get(className); if (genericClass == null) { try { @@ -71,9 +64,7 @@ public static Transform loadTransform(ConfigurationSection parameters) { genericClass = Class.forName(className); } - if (!Transform.class.isAssignableFrom(genericClass)) { - throw new Exception("Must extend Transform"); - } + if (!Transform.class.isAssignableFrom(genericClass)) throw new Exception("Must extend Transform"); transformClasses.put(className, genericClass); } @@ -83,8 +74,12 @@ public static Transform loadTransform(ConfigurationSection parameters) { parameters.set("class", null); transform.load(parameters); } catch (Exception ex) { - if (effectManager != null) { - effectManager.onError("Error loading class " + className, ex); + if (!effectManagers.isEmpty()) { + for (EffectManager effectManager : effectManagers) { + if (effectManager == null) continue; + effectManager.onError("Error loading class " + className, ex); + break; + } } } } @@ -92,7 +87,4 @@ public static Transform loadTransform(ConfigurationSection parameters) { return transform == null ? new ConstantTransform(0) : transform; } - public static void setEffectManager(EffectManager manager) { - effectManager = manager; - } } diff --git a/src/main/java/de/slikey/effectlib/util/ConfigUtils.java b/src/main/java/de/slikey/effectlib/util/ConfigUtils.java index 99914154..6dffffbc 100644 --- a/src/main/java/de/slikey/effectlib/util/ConfigUtils.java +++ b/src/main/java/de/slikey/effectlib/util/ConfigUtils.java @@ -1,16 +1,16 @@ package de.slikey.effectlib.util; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.configuration.MemoryConfiguration; - +import java.util.Map; +import java.util.List; import java.util.ArrayList; import java.util.Collection; -import java.util.List; -import java.util.Map; + +import org.bukkit.configuration.MemoryConfiguration; +import org.bukkit.configuration.ConfigurationSection; public class ConfigUtils { public static Collection getNodeList(ConfigurationSection node, String path) { - Collection results = new ArrayList(); + Collection results = new ArrayList<>(); List> mapList = node.getMapList(path); for (Map map : mapList) { results.add(toConfigurationSection(map)); @@ -34,9 +34,8 @@ public static ConfigurationSection toConfigurationSection(Map nodeMap) { } public static ConfigurationSection toStringConfiguration(Map stringMap) { - if (stringMap == null) { - return null; - } + if (stringMap == null) return null; + ConfigurationSection configMap = new MemoryConfiguration(); for (Map.Entry entry : stringMap.entrySet()) { configMap.set(entry.getKey(), entry.getValue()); @@ -46,8 +45,7 @@ public static ConfigurationSection toStringConfiguration(Map str } - public static void set(ConfigurationSection node, String path, Object value) - { + public static void set(ConfigurationSection node, String path, Object value) { if (value == null) { node.set(path, null); return; @@ -57,49 +55,38 @@ public static void set(ConfigurationSection node, String path, Object value) boolean isFalse = value.equals("false"); if (isTrue || isFalse) { node.set(path, isTrue); - } else { + return; + } + try { + Integer i = (value instanceof Integer) ? (Integer) value : Integer.parseInt(value.toString()); + node.set(path, i); + } catch (Exception ex) { try { - Integer i = (value instanceof Integer) ? (Integer)value : Integer.parseInt(value.toString()); - node.set(path, i); - } catch (Exception ex) { - try { - Double d; - if (value instanceof Double) { - d = (Double)value; - } else if (value instanceof Float) { - d = (double)(Float)value; - } else { - d = Double.parseDouble(value.toString()); - } - node.set(path, d); - } catch (Exception ex2) { - node.set(path, value); - } + Double d; + if (value instanceof Double) d = (Double) value; + else if (value instanceof Float) d = (double) (Float) value; + else d = Double.parseDouble(value.toString()); + node.set(path, d); + } catch (Exception ex2) { + node.set(path, value); } } } - public static ConfigurationSection getConfigurationSection(ConfigurationSection base, String key) - { + public static ConfigurationSection getConfigurationSection(ConfigurationSection base, String key) { ConfigurationSection section = base.getConfigurationSection(key); - if (section != null) { - return section; - } + if (section != null) return section; + Object value = base.get(key); if (value == null) return null; - if (value instanceof ConfigurationSection) - { - return (ConfigurationSection)value; - } + if (value instanceof ConfigurationSection) return (ConfigurationSection)value; - if (value instanceof Map) - { + if (value instanceof Map) { ConfigurationSection newChild = base.createSection(key); @SuppressWarnings("unchecked") Map map = (Map)value; - for (Map.Entry entry : map.entrySet()) - { + for (Map.Entry entry : map.entrySet()) { newChild.set(entry.getKey(), entry.getValue()); } base.set(key, newChild); @@ -108,4 +95,5 @@ public static ConfigurationSection getConfigurationSection(ConfigurationSection return null; } + } diff --git a/src/main/java/de/slikey/effectlib/util/DynamicLocation.java b/src/main/java/de/slikey/effectlib/util/DynamicLocation.java index 6ffeac1c..42fdd4aa 100644 --- a/src/main/java/de/slikey/effectlib/util/DynamicLocation.java +++ b/src/main/java/de/slikey/effectlib/util/DynamicLocation.java @@ -1,15 +1,17 @@ package de.slikey.effectlib.util; import java.lang.ref.WeakReference; + import org.bukkit.Location; +import org.bukkit.util.Vector; import org.bukkit.entity.Entity; import org.bukkit.entity.LivingEntity; -import org.bukkit.util.Vector; /** * Represents a Location that can move, possibly bound to an Entity. */ public class DynamicLocation { + private final Location location; private final Location originalLocation; private final WeakReference entity; @@ -24,59 +26,48 @@ public class DynamicLocation { private Float pitch = null; public DynamicLocation(Location location) { - if (location != null) { - this.location = location.clone(); - } else { - this.location = null; - } - this.originalLocation = location; - this.entity = null; + if (location != null) this.location = location.clone(); + else this.location = null; + originalLocation = location; + entity = null; } public DynamicLocation(Entity entity) { if (entity != null) { - this.entity = new WeakReference(entity); - this.location = getEntityLocation(entity); + this.entity = new WeakReference<>(entity); + location = getEntityLocation(entity); } else { this.entity = null; - this.location = null; + location = null; } - this.originalLocation = location; + originalLocation = location; } public DynamicLocation(Location location, Entity entity) { - if (location != null) { - this.location = location.clone(); - } else if (entity != null) { - this.location = getEntityLocation(entity); - } else { - this.location = null; - } + if (location != null) this.location = location.clone(); + else if (entity != null) this.location = getEntityLocation(entity); + else this.location = null; + if (entity != null) { - this.entity = new WeakReference(entity); - this.entityOffset = this.location.toVector().subtract(getEntityLocation(entity).toVector()); + this.entity = new WeakReference<>(entity); + entityOffset = this.location.toVector().subtract(getEntityLocation(entity).toVector()); } else { this.entity = null; } - this.originalLocation = this.location == null ? null : this.location.clone(); + + originalLocation = this.location == null ? null : this.location.clone(); } public void addOffset(Vector offset) { - if (this.offset == null) { - this.offset = offset.clone(); - } else { - this.offset.add(offset); - } - this.updateOffsets(); + if (this.offset == null) this.offset = offset.clone(); + else this.offset.add(offset); + updateOffsets(); } public void addRelativeOffset(Vector offset) { - if (this.relativeOffset == null) { - this.relativeOffset = offset.clone(); - } else { - this.relativeOffset.add(offset); - } - this.updateOffsets(); + if (relativeOffset == null) relativeOffset = offset.clone(); + else relativeOffset.add(offset); + updateOffsets(); } public Entity getEntity() { @@ -88,9 +79,7 @@ public Location getLocation() { } protected Location getEntityLocation(Entity entity) { - if (entity instanceof LivingEntity) { - return ((LivingEntity) entity).getEyeLocation(); - } + if (entity instanceof LivingEntity) return ((LivingEntity) entity).getEyeLocation(); return entity.getLocation(); } @@ -100,18 +89,10 @@ public void setDirection(Vector direction) { } public void updateDirection() { - if (yaw != null) { - location.setYaw(yaw); - } - if (pitch != null) { - location.setPitch(pitch); - } - if (yawOffset != 0) { - location.setYaw(location.getYaw() + yawOffset); - } - if (pitchOffset != 0) { - location.setPitch(location.getPitch() + pitchOffset); - } + if (yaw != null) location.setYaw(yaw); + if (pitch != null) location.setPitch(pitch); + if (yawOffset != 0) location.setYaw(location.getYaw() + yawOffset); + if (pitchOffset != 0) location.setPitch(location.getPitch() + pitchOffset); } public void updateFrom(Location newLocation) { @@ -128,15 +109,10 @@ public void updateOffsets() { location.setX(originalLocation.getX()); location.setY(originalLocation.getY()); location.setZ(originalLocation.getZ()); - if (offset != null) { - location.add(offset); - } - if (relativeOffset != null) { - location.add(VectorUtils.rotateVector(relativeOffset, location)); - } - if (entityOffset != null) { - location.add(entityOffset); - } + + if (offset != null) location.add(offset); + if (relativeOffset != null) location.add(VectorUtils.rotateVector(relativeOffset, location)); + if (entityOffset != null) location.add(entityOffset); } public void setUpdateLocation(boolean update) { @@ -144,22 +120,14 @@ public void setUpdateLocation(boolean update) { } public void update() { - if (location == null || (!updateLocation && !updateDirection)) { - return; - } + if (location == null || (!updateLocation && !updateDirection)) return; Entity entityReference = entity == null ? null : entity.get(); - if (entityReference != null) { - Location currentLocation = getEntityLocation(entityReference); - if (updateDirection) - { - setDirection(currentLocation.getDirection()); - } - if (updateLocation) - { - updateFrom(currentLocation); - } - } + if (entityReference == null) return; + + Location currentLocation = getEntityLocation(entityReference); + if (updateDirection) setDirection(currentLocation.getDirection()); + if (updateLocation) updateFrom(currentLocation); } public void setUpdateDirection(boolean updateDirection) { @@ -183,4 +151,5 @@ public boolean hasValidEntity() { Entity entity = this.getEntity(); return entity != null && entity.isValid(); } + } diff --git a/src/main/java/de/slikey/effectlib/util/ParticleDisplay.java b/src/main/java/de/slikey/effectlib/util/ParticleDisplay.java index 79f5732b..fc675c1f 100644 --- a/src/main/java/de/slikey/effectlib/util/ParticleDisplay.java +++ b/src/main/java/de/slikey/effectlib/util/ParticleDisplay.java @@ -2,8 +2,8 @@ import java.util.List; -import org.bukkit.Bukkit; import org.bukkit.Color; +import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; @@ -15,6 +15,7 @@ import de.slikey.effectlib.util.versions.ParticleDisplay_13; public abstract class ParticleDisplay { + private EffectManager manager; public abstract void display(Particle particle, Location center, float offsetX, float offsetY, float offsetZ, float speed, int amount, float size, Color color, Material material, byte materialData, double range, List targetPlayers); @@ -36,16 +37,12 @@ protected void display(Particle particle, Location center, float offsetX, float } } } catch (Exception ex) { - if (manager != null) { - manager.onError(ex); - } + if (manager != null) manager.onError(ex); } } protected void displayItem(Particle particle, Location center, float offsetX, float offsetY, float offsetZ, float speed, int amount, Material material, byte materialData, double range, List targetPlayers) { - if (material == null || material == Material.AIR) { - return; - } + if (material == null || material == Material.AIR) return; ItemStack item = new ItemStack(material); item.setDurability(materialData); @@ -55,17 +52,14 @@ protected void displayItem(Particle particle, Location center, float offsetX, fl protected void displayLegacyColored(Particle particle, Location center, float speed, Color color, double range, List targetPlayers) { int amount = 0; // Colored particles can't have a speed of 0. - if (speed == 0) { - speed = 1; - } + if (speed == 0) speed = 1; + float offsetX = (float) color.getRed() / 255; float offsetY = (float) color.getGreen() / 255; float offsetZ = (float) color.getBlue() / 255; // The redstone particle reverts to red if R is 0! - if (offsetX < Float.MIN_NORMAL) { - offsetX = Float.MIN_NORMAL; - } + if (offsetX < Float.MIN_NORMAL) offsetX = Float.MIN_NORMAL; display(particle, center, offsetX, offsetY, offsetZ, speed, amount, null, range, targetPlayers); } @@ -84,4 +78,5 @@ public static ParticleDisplay newInstance() { } return display; } + } diff --git a/src/main/java/de/slikey/effectlib/util/versions/ParticleDisplay_12.java b/src/main/java/de/slikey/effectlib/util/versions/ParticleDisplay_12.java index eb504db2..6d7755e9 100644 --- a/src/main/java/de/slikey/effectlib/util/versions/ParticleDisplay_12.java +++ b/src/main/java/de/slikey/effectlib/util/versions/ParticleDisplay_12.java @@ -12,6 +12,7 @@ import de.slikey.effectlib.util.ParticleDisplay; public class ParticleDisplay_12 extends ParticleDisplay { + @Override @SuppressWarnings("deprecation") public void display(Particle particle, Location center, float offsetX, float offsetY, float offsetZ, float speed, int amount, float size, Color color, Material material, byte materialData, double range, List targetPlayers) { @@ -28,12 +29,11 @@ public void display(Particle particle, Location center, float offsetX, float off Object data = null; if (particle == Particle.BLOCK_CRACK || particle == Particle.BLOCK_DUST || particle.name().equals("FALLING_DUST")) { - if (material == null || material == Material.AIR) { - return; - } + if (material == null || material == Material.AIR) return; data = new MaterialData(material, materialData); } display(particle, center, offsetX, offsetY, offsetZ, speed, amount, data, range, targetPlayers); } + } diff --git a/src/main/java/de/slikey/effectlib/util/versions/ParticleDisplay_13.java b/src/main/java/de/slikey/effectlib/util/versions/ParticleDisplay_13.java index 00624b51..f6d1da46 100644 --- a/src/main/java/de/slikey/effectlib/util/versions/ParticleDisplay_13.java +++ b/src/main/java/de/slikey/effectlib/util/versions/ParticleDisplay_13.java @@ -11,6 +11,7 @@ import de.slikey.effectlib.util.ParticleDisplay; public class ParticleDisplay_13 extends ParticleDisplay { + @Override public void display(Particle particle, Location center, float offsetX, float offsetY, float offsetZ, float speed, int amount, float size, Color color, Material material, byte materialData, double range, List targetPlayers) { // Legacy colorizeable particles @@ -26,23 +27,18 @@ public void display(Particle particle, Location center, float offsetX, float off Object data = null; if (particle == Particle.BLOCK_CRACK || particle == Particle.BLOCK_DUST || particle == Particle.FALLING_DUST) { - if (material == null || material == Material.AIR) { - return; - } + if (material == null || material.toString().contains("AIR")) return; data = material.createBlockData(); - if (data == null) { - return; - } + if (data == null) return; } if (particle == Particle.REDSTONE) { // color is required for 1.13 - if (color == null) { - color = Color.RED; - } + if (color == null) color = Color.RED; data = new Particle.DustOptions(color, size); } display(particle, center, offsetX, offsetY, offsetZ, speed, amount, data, range, targetPlayers); } + } From ae19b40eef816284a19d9a2f73ba1b992d08a84c Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 12 May 2020 14:37:09 +0200 Subject: [PATCH 10/44] More cleanup --- src/main/java/de/slikey/effectlib/math/Transforms.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/java/de/slikey/effectlib/math/Transforms.java b/src/main/java/de/slikey/effectlib/math/Transforms.java index f843a19e..7e4c490a 100644 --- a/src/main/java/de/slikey/effectlib/math/Transforms.java +++ b/src/main/java/de/slikey/effectlib/math/Transforms.java @@ -6,7 +6,6 @@ import java.util.ArrayList; import java.util.Collection; -import de.slikey.effectlib.EffectLib; import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.ConfigUtils; import org.bukkit.configuration.ConfigurationSection; @@ -15,7 +14,7 @@ public class Transforms { private static final String TRANSFORM_BUILTIN_CLASSPATH = "de.slikey.effectlib.math"; private static Map> transformClasses = new HashMap<>(); - private static List effectManagers = EffectLib.instance().getEffectManagers(); + private static List effectManagers = EffectManager.getManagers(); public static Transform loadTransform(ConfigurationSection base, String value) { if (base.isConfigurationSection(value)) return loadTransform(ConfigUtils.getConfigurationSection(base, value)); From 1e0989b1f905ff39a51d90468ab802698a29cc9f Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 12 May 2020 14:50:41 +0200 Subject: [PATCH 11/44] Make use of EffectManager List --- src/main/java/de/slikey/effectlib/EffectManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/de/slikey/effectlib/EffectManager.java b/src/main/java/de/slikey/effectlib/EffectManager.java index 8f69e1e9..ab2291e3 100644 --- a/src/main/java/de/slikey/effectlib/EffectManager.java +++ b/src/main/java/de/slikey/effectlib/EffectManager.java @@ -63,6 +63,7 @@ public EffectManager(Plugin owningPlugin) { effects = new HashMap<>(); disposed = false; disposeOnTermination = false; + effectManagers.add(this); } private ParticleDisplay getDisplay() { From a7fed9985c4b58f2e1e6c8140e701afdf97f7b0f Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 12 May 2020 15:05:56 +0200 Subject: [PATCH 12/44] Cleanup --- src/main/java/de/slikey/effectlib/EffectManager.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slikey/effectlib/EffectManager.java b/src/main/java/de/slikey/effectlib/EffectManager.java index ab2291e3..92f5e457 100644 --- a/src/main/java/de/slikey/effectlib/EffectManager.java +++ b/src/main/java/de/slikey/effectlib/EffectManager.java @@ -254,6 +254,9 @@ public void dispose() { if (disposed) return; disposed = true; cancel(false); + display = null; + imageCache = null; + imageCacheFolder = null; if (effectManagers != null) effectManagers.remove(this); } @@ -416,7 +419,7 @@ protected boolean setField(Object effect, String key, ConfigurationSection secti return true; } catch (Exception ex) { - this.onError(ex); + onError(ex); } return false; From 32a9740cf56741358d27ba396f8ba161daa88d71 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 12 May 2020 15:16:48 +0200 Subject: [PATCH 13/44] Possible bugfix for dispose --- src/main/java/de/slikey/effectlib/EffectManager.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/slikey/effectlib/EffectManager.java b/src/main/java/de/slikey/effectlib/EffectManager.java index 92f5e457..70659e9d 100644 --- a/src/main/java/de/slikey/effectlib/EffectManager.java +++ b/src/main/java/de/slikey/effectlib/EffectManager.java @@ -47,18 +47,19 @@ public class EffectManager implements Disposable { private static List effectManagers; private static Map> effectClasses = new HashMap<>(); - private final Plugin owningPlugin; - private final Map effects; + private Plugin owningPlugin; + private Map effects; private ParticleDisplay display; private boolean disposed; private boolean disposeOnTermination; private boolean debug = false; private int visibleRange = 32; private File imageCacheFolder; - private Map imageCache = new HashMap<>(); + private Map imageCache; public EffectManager(Plugin owningPlugin) { imageCacheFolder = owningPlugin == null ? null : new File(owningPlugin.getDataFolder(), "imagecache"); + imageCache = new HashMap<>(); this.owningPlugin = owningPlugin; effects = new HashMap<>(); disposed = false; @@ -254,8 +255,10 @@ public void dispose() { if (disposed) return; disposed = true; cancel(false); + effects = null; display = null; imageCache = null; + owningPlugin = null; imageCacheFolder = null; if (effectManagers != null) effectManagers.remove(this); } From ab10060b050f85d34341b3669eab8be7e1d10d44 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 12 May 2020 15:52:06 +0200 Subject: [PATCH 14/44] Api additions --- src/main/java/de/slikey/effectlib/EffectManager.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/main/java/de/slikey/effectlib/EffectManager.java b/src/main/java/de/slikey/effectlib/EffectManager.java index 70659e9d..cd8c1fa2 100644 --- a/src/main/java/de/slikey/effectlib/EffectManager.java +++ b/src/main/java/de/slikey/effectlib/EffectManager.java @@ -268,6 +268,14 @@ public void disposeOnTermination() { if (effects.isEmpty()) dispose(); } + public boolean isDisposed() { + return disposed; + } + + public boolean isDisposedOnTermination() { + return disposeOnTermination; + } + public void enableDebug(boolean enable) { debug = enable; } From 4a395349913c3e950ecf2402b78bcb5f619ba6b3 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 12 May 2020 16:15:29 +0200 Subject: [PATCH 15/44] More Cleanup --- src/main/java/de/slikey/effectlib/EffectLib.java | 2 +- src/main/java/de/slikey/effectlib/EffectManager.java | 11 +++-------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/slikey/effectlib/EffectLib.java b/src/main/java/de/slikey/effectlib/EffectLib.java index afe78adb..dba02d1d 100644 --- a/src/main/java/de/slikey/effectlib/EffectLib.java +++ b/src/main/java/de/slikey/effectlib/EffectLib.java @@ -128,7 +128,7 @@ public EffectLib() { @Override public void onEnable() { - EffectManager.initialize(); + } @Override diff --git a/src/main/java/de/slikey/effectlib/EffectManager.java b/src/main/java/de/slikey/effectlib/EffectManager.java index cd8c1fa2..3ce79638 100644 --- a/src/main/java/de/slikey/effectlib/EffectManager.java +++ b/src/main/java/de/slikey/effectlib/EffectManager.java @@ -45,7 +45,7 @@ */ public class EffectManager implements Disposable { - private static List effectManagers; + private static List effectManagers = new ArrayList<>(); private static Map> effectClasses = new HashMap<>(); private Plugin owningPlugin; private Map effects; @@ -260,7 +260,7 @@ public void dispose() { imageCache = null; owningPlugin = null; imageCacheFolder = null; - if (effectManagers != null) effectManagers.remove(this); + effectManagers.remove(this); } public void disposeOnTermination() { @@ -435,13 +435,8 @@ protected boolean setField(Object effect, String key, ConfigurationSection secti return false; } - - public static void initialize() { - effectManagers = new ArrayList<>(); - } - + public static List getManagers() { - if (effectManagers == null) initialize(); return effectManagers; } From 0738342fe680e2eb2c2c07a73ab0021460000f32 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 12 May 2020 22:04:55 +0200 Subject: [PATCH 16/44] Big Cleanup and new options for effects CircleEffect now rotates properly DonutEffect now rotates properly Added cloudParticles to CloudEffect Added mainParticles to CloudEffect Added orient to CubeEffect Added colorLand to EarthEffect Added colorOcean to EarthEffect Added particlesLand to EarthEffect Added particlesOcean to EarthEffect Added speedLand to EarthEffect Added speedOcean to EarthEffect Added particles to FlameEffect Renamed compilaction to compilation in HeartEffect Renamed particle1 to particleLand in EarthEffect Renamed particle2 to particleOcean in EarthEffect Added changes from the main repo such as: - Add orient parameter to Cylinder effect - Add parameters to TornadoEffect to reduce lag - Add particle count parameter to Smoke effect --- src/main/java/de/slikey/effectlib/Effect.java | 17 ++--- .../java/de/slikey/effectlib/EffectLib.java | 1 + .../java/de/slikey/effectlib/EffectType.java | 2 +- .../effectlib/effect/AnimatedBallEffect.java | 17 ++--- .../de/slikey/effectlib/effect/ArcEffect.java | 12 ++-- .../slikey/effectlib/effect/AtomEffect.java | 14 ++-- .../effectlib/effect/BigBangEffect.java | 22 +++--- .../slikey/effectlib/effect/BleedEffect.java | 16 ++--- .../slikey/effectlib/effect/CircleEffect.java | 4 +- .../slikey/effectlib/effect/CloudEffect.java | 9 ++- .../slikey/effectlib/effect/ConeEffect.java | 22 +++--- .../slikey/effectlib/effect/CubeEffect.java | 53 ++++++++------ .../effectlib/effect/CylinderEffect.java | 37 ++++++---- .../effectlib/effect/DiscoBallEffect.java | 32 +++++---- .../de/slikey/effectlib/effect/DnaEffect.java | 23 +++--- .../slikey/effectlib/effect/DonutEffect.java | 1 + .../slikey/effectlib/effect/DragonEffect.java | 21 +++--- .../slikey/effectlib/effect/EarthEffect.java | 64 +++++++++-------- .../effectlib/effect/EquationEffect.java | 62 ++++++++-------- .../effectlib/effect/ExplodeEffect.java | 10 +-- .../slikey/effectlib/effect/FlameEffect.java | 13 ++-- .../effectlib/effect/FountainEffect.java | 9 +-- .../slikey/effectlib/effect/GridEffect.java | 9 +-- .../slikey/effectlib/effect/HeartEffect.java | 13 ++-- .../slikey/effectlib/effect/HelixEffect.java | 7 +- .../slikey/effectlib/effect/HillEffect.java | 11 +-- .../slikey/effectlib/effect/IconEffect.java | 8 ++- .../slikey/effectlib/effect/ImageEffect.java | 8 +-- .../slikey/effectlib/effect/JumpEffect.java | 7 +- .../slikey/effectlib/effect/LineEffect.java | 33 ++++----- .../slikey/effectlib/effect/LoveEffect.java | 7 +- .../effectlib/effect/ModifiedEffect.java | 72 +++++++++---------- .../slikey/effectlib/effect/MusicEffect.java | 10 +-- .../slikey/effectlib/effect/PlotEffect.java | 23 +++--- .../effectlib/effect/SkyRocketEffect.java | 1 - .../slikey/effectlib/effect/SmokeEffect.java | 14 ++-- .../slikey/effectlib/effect/SphereEffect.java | 4 +- .../slikey/effectlib/effect/StarEffect.java | 12 ++-- .../slikey/effectlib/effect/TextEffect.java | 38 +++++----- .../effectlib/effect/TornadoEffect.java | 20 +++++- .../slikey/effectlib/effect/TraceEffect.java | 32 ++++----- .../slikey/effectlib/effect/TurnEffect.java | 8 +-- .../slikey/effectlib/effect/VortexEffect.java | 11 +-- .../slikey/effectlib/effect/WarpEffect.java | 14 ++-- .../slikey/effectlib/effect/WaveEffect.java | 45 +++++------- .../slikey/effectlib/math/EchoTransform.java | 2 + .../slikey/effectlib/math/EquationStore.java | 14 ++-- .../effectlib/math/EquationTransform.java | 33 ++++----- .../effectlib/math/MultiplyTransform.java | 6 +- .../effectlib/math/SequenceTransform.java | 25 ++++--- .../slikey/effectlib/math/SumTransform.java | 6 +- .../de/slikey/effectlib/math/Transform.java | 3 + .../de/slikey/effectlib/math/Transforms.java | 1 + .../effectlib/math/VectorTransform.java | 19 ++--- .../effectlib/math/dQuadraticTransform.java | 2 + .../slikey/effectlib/math/dSinTransform.java | 2 + .../effectlib/particle/ReflectionHandler.java | 20 ++++-- .../effectlib/util/BaseImageEffect.java | 23 +++--- .../de/slikey/effectlib/util/ConfigUtils.java | 3 +- .../effectlib/util/ImageLoadCallback.java | 2 + .../slikey/effectlib/util/ImageLoadTask.java | 30 ++++---- .../de/slikey/effectlib/util/MathUtils.java | 37 ++++------ .../slikey/effectlib/util/ParticleEffect.java | 51 ++++++------- .../de/slikey/effectlib/util/RandomUtils.java | 1 + .../slikey/effectlib/util/StringParser.java | 6 +- .../de/slikey/effectlib/util/VectorUtils.java | 1 + 66 files changed, 604 insertions(+), 551 deletions(-) diff --git a/src/main/java/de/slikey/effectlib/Effect.java b/src/main/java/de/slikey/effectlib/Effect.java index 8ba1a568..e36c02c7 100644 --- a/src/main/java/de/slikey/effectlib/Effect.java +++ b/src/main/java/de/slikey/effectlib/Effect.java @@ -193,9 +193,8 @@ public abstract class Effect implements Runnable { private boolean done = false; public Effect(EffectManager effectManager) { - if (effectManager == null) { - throw new IllegalArgumentException("EffectManager cannot be null!"); - } + if (effectManager == null) throw new IllegalArgumentException("EffectManager cannot be null!"); + this.effectManager = effectManager; visibleRange = effectManager.getParticleRange(); } @@ -320,7 +319,6 @@ public void setDynamicOrigin(DynamicLocation location) { origin = location; if (offset != null) origin.addOffset(offset); - if (relativeOffset != null) origin.addRelativeOffset(relativeOffset); origin.setDirectionOffset(yawOffset, pitchOffset); @@ -337,10 +335,9 @@ public void setDynamicOrigin(DynamicLocation location) { public void setDynamicTarget(DynamicLocation location) { target = location; if (target != null && targetOffset != null) target.addOffset(targetOffset); - if (target != null) { - target.setUpdateLocation(updateLocations); - target.setUpdateDirection(updateDirections); - } + if (target == null) return; + target.setUpdateLocation(updateLocations); + target.setUpdateDirection(updateDirections); } protected final boolean validate() { @@ -382,7 +379,7 @@ protected void updateTarget() { } protected void display(Particle effect, Location location) { - display(effect, location, this.color); + display(effect, location, color); } protected void display(Particle particle, Location location, Color color) { @@ -390,7 +387,7 @@ protected void display(Particle particle, Location location, Color color) { } protected void display(Particle particle, Location location, float speed, int amount) { - display(particle, location, this.color, speed, amount); + display(particle, location, color, speed, amount); } protected void display(Particle particle, Location location, Color color, float speed, int amount) { diff --git a/src/main/java/de/slikey/effectlib/EffectLib.java b/src/main/java/de/slikey/effectlib/EffectLib.java index dba02d1d..fc982846 100644 --- a/src/main/java/de/slikey/effectlib/EffectLib.java +++ b/src/main/java/de/slikey/effectlib/EffectLib.java @@ -1,6 +1,7 @@ package de.slikey.effectlib; import java.util.List; + import org.bukkit.event.HandlerList; import org.bukkit.plugin.java.JavaPlugin; diff --git a/src/main/java/de/slikey/effectlib/EffectType.java b/src/main/java/de/slikey/effectlib/EffectType.java index 453c3ee0..bc130d13 100644 --- a/src/main/java/de/slikey/effectlib/EffectType.java +++ b/src/main/java/de/slikey/effectlib/EffectType.java @@ -13,6 +13,6 @@ public enum EffectType { /** * Effect is once delayed played. Set delay with {@link Effect.delay}. */ - DELAYED; + DELAYED } diff --git a/src/main/java/de/slikey/effectlib/effect/AnimatedBallEffect.java b/src/main/java/de/slikey/effectlib/effect/AnimatedBallEffect.java index c2abe0da..0e22b2c5 100644 --- a/src/main/java/de/slikey/effectlib/effect/AnimatedBallEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/AnimatedBallEffect.java @@ -1,13 +1,14 @@ package de.slikey.effectlib.effect; +import org.bukkit.Particle; +import org.bukkit.Location; +import org.bukkit.util.Vector; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.MathUtils; -import org.bukkit.Particle; import de.slikey.effectlib.util.VectorUtils; -import org.bukkit.Location; -import org.bukkit.util.Vector; /** * Creates an animated Sphere.. Thanks to the author for sharing it! @@ -59,14 +60,14 @@ public class AnimatedBallEffect extends Effect { public AnimatedBallEffect(EffectManager effectManager) { super(effectManager); - this.type = EffectType.REPEATING; - this.iterations = 500; - this.period = 1; + type = EffectType.REPEATING; + iterations = 500; + period = 1; } @Override public void reset() { - this.step = 0; + step = 0; } @Override diff --git a/src/main/java/de/slikey/effectlib/effect/ArcEffect.java b/src/main/java/de/slikey/effectlib/effect/ArcEffect.java index bd434ac1..f19b3f68 100644 --- a/src/main/java/de/slikey/effectlib/effect/ArcEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/ArcEffect.java @@ -1,12 +1,13 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; import org.bukkit.Particle; import org.bukkit.Location; import org.bukkit.util.Vector; +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; + public class ArcEffect extends Effect { /** @@ -38,20 +39,23 @@ public ArcEffect(EffectManager effectManager) { @Override public void reset() { - this.step = 0; + step = 0; } @Override public void onRun() { Location location = getLocation(); Location target = getTarget(); + if (target == null) { cancel(); return; } + Vector link = target.toVector().subtract(location.toVector()); float length = (float) link.length(); float pitch = (float) (4 * height / Math.pow(length, 2)); + for (int i = 0; i < particles; i++) { Vector v = link.clone().normalize().multiply((float) length * i / particles); float x = ((float) i / particles) * length - length / 2; diff --git a/src/main/java/de/slikey/effectlib/effect/AtomEffect.java b/src/main/java/de/slikey/effectlib/effect/AtomEffect.java index 13afa2ea..6ce1e57a 100644 --- a/src/main/java/de/slikey/effectlib/effect/AtomEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/AtomEffect.java @@ -1,14 +1,15 @@ package de.slikey.effectlib.effect; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.util.Vector; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; -import org.bukkit.Particle; +import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.RandomUtils; import de.slikey.effectlib.util.VectorUtils; -import org.bukkit.Color; -import org.bukkit.Location; -import org.bukkit.util.Vector; public class AtomEffect extends Effect { @@ -73,7 +74,7 @@ public AtomEffect(EffectManager effectManager) { @Override public void reset() { - this.step = 0; + step = 0; } @Override @@ -85,6 +86,7 @@ public void onRun() { display(particleNucleus, location, colorNucleus); location.subtract(v); } + for (int i = 0; i < particlesOrbital; i++) { double angle = step * angularVelocity; for (int j = 0; j < orbitals; j++) { diff --git a/src/main/java/de/slikey/effectlib/effect/BigBangEffect.java b/src/main/java/de/slikey/effectlib/effect/BigBangEffect.java index c59545cf..b658e52d 100644 --- a/src/main/java/de/slikey/effectlib/effect/BigBangEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/BigBangEffect.java @@ -1,18 +1,19 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; -import de.slikey.effectlib.util.RandomUtils; import org.bukkit.Color; -import org.bukkit.FireworkEffect; -import org.bukkit.FireworkEffect.Builder; -import org.bukkit.Location; import org.bukkit.Sound; -import org.bukkit.entity.EntityType; +import org.bukkit.Location; +import org.bukkit.util.Vector; +import org.bukkit.FireworkEffect; import org.bukkit.entity.Firework; +import org.bukkit.entity.EntityType; +import org.bukkit.FireworkEffect.Builder; import org.bukkit.inventory.meta.FireworkMeta; -import org.bukkit.util.Vector; + +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.RandomUtils; public class BigBangEffect extends Effect { @@ -42,7 +43,7 @@ public BigBangEffect(EffectManager effectManager) { @Override public void reset() { - this.step = 0; + step = 0; } @Override @@ -76,4 +77,5 @@ protected void detonate(Location location, Vector v) { fw.setFireworkMeta(meta); fw.detonate(); } + } diff --git a/src/main/java/de/slikey/effectlib/effect/BleedEffect.java b/src/main/java/de/slikey/effectlib/effect/BleedEffect.java index 460350a4..d3caaa8d 100644 --- a/src/main/java/de/slikey/effectlib/effect/BleedEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/BleedEffect.java @@ -1,12 +1,14 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; -import de.slikey.effectlib.util.RandomUtils; import org.bukkit.Effect; import org.bukkit.Location; +import org.bukkit.Material; import org.bukkit.entity.Entity; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.RandomUtils; + public class BleedEffect extends de.slikey.effectlib.Effect { /** @@ -22,7 +24,7 @@ public class BleedEffect extends de.slikey.effectlib.Effect { /** * Color of blood. Default is red (152) */ - public int color = 152; + public Material material = Material.REDSTONE_BLOCK; public BleedEffect(EffectManager effectManager) { super(effectManager); @@ -36,11 +38,9 @@ public void onRun() { // Location to spawn the blood-item. Location location = getLocation(); location.add(0, RandomUtils.random.nextFloat() * height, 0); - location.getWorld().playEffect(location, Effect.STEP_SOUND, color); + location.getWorld().playEffect(location, Effect.STEP_SOUND, material); Entity entity = getEntity(); - if (hurt && entity != null) { - entity.playEffect(org.bukkit.EntityEffect.HURT); - } + if (hurt && entity != null) entity.playEffect(org.bukkit.EntityEffect.HURT); } } diff --git a/src/main/java/de/slikey/effectlib/effect/CircleEffect.java b/src/main/java/de/slikey/effectlib/effect/CircleEffect.java index 1a99ff24..fb322866 100644 --- a/src/main/java/de/slikey/effectlib/effect/CircleEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/CircleEffect.java @@ -76,15 +76,17 @@ public CircleEffect(EffectManager effectManager) { @Override public void reset() { - this.step = 0; + step = 0; } @Override public void onRun() { Location location = getLocation(); location.subtract(xSubtract, ySubtract, zSubtract); + double inc = (2 * Math.PI) / particles; int steps = wholeCircle ? particles : 1; + for (int i = 0; i < steps; i++) { double angle = step * inc; Vector v = new Vector(); diff --git a/src/main/java/de/slikey/effectlib/effect/CloudEffect.java b/src/main/java/de/slikey/effectlib/effect/CloudEffect.java index be701807..2561dd2d 100644 --- a/src/main/java/de/slikey/effectlib/effect/CloudEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/CloudEffect.java @@ -18,11 +18,13 @@ public class CloudEffect extends Effect { public Particle cloudParticle = Particle.CLOUD; public Color cloudColor = null; public float cloudSpeed = 0; + public int cloudParticles = 50; /* * Particle of the rain/snow */ public Particle mainParticle = Particle.DRIP_WATER; + public int mainParticles = 15; /* * Size of the cloud @@ -53,15 +55,18 @@ public CloudEffect(EffectManager manager) { public void onRun() { Location location = getLocation(); location.add(0, yOffset, 0); - for (int i = 0; i < 50; i++) { + + for (int i = 0; i < cloudParticles; i++) { Vector v = RandomUtils.getRandomCircleVector().multiply(RandomUtils.random.nextDouble() * cloudSize); display(cloudParticle, location.add(v), cloudColor, cloudSpeed, 1); location.subtract(v); } + Location l; if (increaseHeight) l = location.add(0, 0.2, 0); else l = location; - for (int i = 0; i < 15; i++) { + + for (int i = 0; i < mainParticles; i++) { int r = RandomUtils.random.nextInt(2); double x = RandomUtils.random.nextDouble() * particleRadius; double z = RandomUtils.random.nextDouble() * particleRadius; diff --git a/src/main/java/de/slikey/effectlib/effect/ConeEffect.java b/src/main/java/de/slikey/effectlib/effect/ConeEffect.java index ad73deb5..b1f5a1ea 100644 --- a/src/main/java/de/slikey/effectlib/effect/ConeEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/ConeEffect.java @@ -1,14 +1,15 @@ package de.slikey.effectlib.effect; +import org.bukkit.Particle; +import org.bukkit.Location; +import org.bukkit.util.Vector; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.MathUtils; -import org.bukkit.Particle; import de.slikey.effectlib.util.RandomUtils; import de.slikey.effectlib.util.VectorUtils; -import org.bukkit.Location; -import org.bukkit.util.Vector; public class ConeEffect extends Effect { @@ -66,19 +67,17 @@ public ConeEffect(EffectManager effectManager) { @Override public void reset() { - this.step = 0; + step = 0; } @Override public void onRun() { Location location = getLocation(); for (int x = 0; x < particles; x++) { - if (step > particlesCone) { - step = 0; - } - if (randomize && step == 0) { - rotation = RandomUtils.getRandomAngle(); - } + + if (step > particlesCone) step = 0; + if (randomize && step == 0) rotation = RandomUtils.getRandomAngle(); + double angle = step * angularVelocity + rotation; float radius = step * radiusGrow; float length = step * lengthGrow; @@ -92,4 +91,5 @@ public void onRun() { step++; } } + } diff --git a/src/main/java/de/slikey/effectlib/effect/CubeEffect.java b/src/main/java/de/slikey/effectlib/effect/CubeEffect.java index a45e5d85..e65a820f 100644 --- a/src/main/java/de/slikey/effectlib/effect/CubeEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/CubeEffect.java @@ -1,13 +1,15 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; import org.bukkit.Particle; -import de.slikey.effectlib.util.VectorUtils; import org.bukkit.Location; import org.bukkit.util.Vector; +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.MathUtils; +import de.slikey.effectlib.util.VectorUtils; + public class CubeEffect extends Effect { /** @@ -50,6 +52,11 @@ public class CubeEffect extends Effect { */ public boolean outlineOnly = true; + /** + * Should it orient pitch and yaw? + */ + public boolean orient = false; + /** * Current step. Works as counter */ @@ -64,17 +71,16 @@ public CubeEffect(EffectManager effectManager) { @Override public void reset() { - this.step = 0; + step = 0; } @Override public void onRun() { Location location = getLocation(); - if (outlineOnly) { - drawCubeOutline(location); - } else { - drawCubeWalls(location); - } + + if (outlineOnly) drawCubeOutline(location); + else drawCubeWalls(location); + step++; } @@ -99,9 +105,8 @@ private void drawCubeOutline(Location location) { VectorUtils.rotateAroundAxisX(v, angleX); VectorUtils.rotateAroundAxisY(v, angleY); - if (enableRotation) { - VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); - } + if (enableRotation) VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); + if (orient) rotateLocation(location, v); display(particle, location.add(v)); location.subtract(v); } @@ -112,9 +117,8 @@ private void drawCubeOutline(Location location) { v.setY(edgeLength * p / particles - a); VectorUtils.rotateAroundAxisY(v, angleY); - if (enableRotation) { - VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); - } + if (enableRotation) VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); + if (orient) rotateLocation(location, v); display(particle, location.add(v)); location.subtract(v); } @@ -134,18 +138,23 @@ private void drawCubeWalls(Location location) { for (int y = 0; y <= particles; y++) { float posY = edgeLength * ((float) y / particles) - a; for (int z = 0; z <= particles; z++) { - if (x != 0 && x != particles && y != 0 && y != particles && z != 0 && z != particles) { - continue; - } + if (x != 0 && x != particles && y != 0 && y != particles && z != 0 && z != particles) continue; + float posZ = edgeLength * ((float) z / particles) - a; Vector v = new Vector(posX, posY, posZ); - if (enableRotation) { - VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); - } + if (enableRotation) VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); + if (orient) rotateLocation(location, v); + display(particle, location.add(v)); location.subtract(v); } } } } + + private void rotateLocation(Location location, Vector v) { + VectorUtils.rotateAroundAxisX(v, location.getPitch() * MathUtils.degreesToRadians); + VectorUtils.rotateAroundAxisY(v, -location.getYaw() * MathUtils.degreesToRadians); + } + } diff --git a/src/main/java/de/slikey/effectlib/effect/CylinderEffect.java b/src/main/java/de/slikey/effectlib/effect/CylinderEffect.java index c7d28f39..47ac915e 100644 --- a/src/main/java/de/slikey/effectlib/effect/CylinderEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/CylinderEffect.java @@ -1,15 +1,17 @@ package de.slikey.effectlib.effect; +import java.util.Random; + +import org.bukkit.Particle; +import org.bukkit.Location; +import org.bukkit.util.Vector; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.MathUtils; -import org.bukkit.Particle; import de.slikey.effectlib.util.RandomUtils; import de.slikey.effectlib.util.VectorUtils; -import java.util.Random; -import org.bukkit.Location; -import org.bukkit.util.Vector; public class CylinderEffect extends Effect { @@ -73,6 +75,12 @@ public class CylinderEffect extends Effect { */ protected float sideRatio = 0; + /** + * Whether or not to orient the effect in the direction + * of the source Location + */ + public boolean orient = false; + public CylinderEffect(EffectManager effectManager) { super(effectManager); type = EffectType.REPEATING; @@ -82,18 +90,21 @@ public CylinderEffect(EffectManager effectManager) { @Override public void reset() { - this.step = 0; + step = 0; } @Override public void onRun() { Location location = getLocation(); - if (sideRatio == 0) { - calculateSideRatio(); - } + if (sideRatio == 0) calculateSideRatio(); + Random r = RandomUtils.random; double xRotation = rotationX, yRotation = rotationY, zRotation = rotationZ; - if (enableRotation) { + if (orient) { + xRotation = Math.toRadians(90 - location.getPitch()) + rotationX; + yRotation = Math.toRadians(180 - location.getYaw()) + rotationY; + } + if (enableRotation || orient) { xRotation += step * angularVelocityX; yRotation += step * angularVelocityY; zRotation += step * angularVelocityZ; @@ -116,9 +127,8 @@ public void onRun() { v.setY(-multi * (height / 2)); } } - if (enableRotation) { - VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); - } + if (enableRotation) VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); + display(particle, location.add(v)); location.subtract(v); } @@ -132,4 +142,5 @@ protected void calculateSideRatio() { side = 2 * MathUtils.PI * radius * height; sideRatio = side / (side + grounds); } + } diff --git a/src/main/java/de/slikey/effectlib/effect/DiscoBallEffect.java b/src/main/java/de/slikey/effectlib/effect/DiscoBallEffect.java index a5f79459..7a4bbbf1 100644 --- a/src/main/java/de/slikey/effectlib/effect/DiscoBallEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/DiscoBallEffect.java @@ -3,15 +3,17 @@ /* * Idea by coco5843 */ -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; -import org.bukkit.Particle; -import de.slikey.effectlib.util.RandomUtils; + import org.bukkit.Color; import org.bukkit.Location; +import org.bukkit.Particle; import org.bukkit.util.Vector; +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.RandomUtils; + public class DiscoBallEffect extends Effect { /** @@ -27,8 +29,11 @@ public class DiscoBallEffect extends Effect { /** * Particle of the sphere and of the lines */ - public Particle sphereParticle = Particle.FLAME, lineParticle = Particle.REDSTONE; - public Color sphereColor = null, lineColor = null; + public Particle sphereParticle = Particle.FLAME; + public Particle lineParticle = Particle.REDSTONE; + + public Color sphereColor = null; + public Color lineColor = null; /** * Max number of lines @@ -38,7 +43,8 @@ public class DiscoBallEffect extends Effect { /** * Max number of particles per line */ - public int lineParticles = 100, sphereParticles = 50; + public int lineParticles = 100; + public int sphereParticles = 50; /** * Direction of the lines @@ -60,16 +66,16 @@ public void onRun() { double x = RandomUtils.random.nextInt(max - max * (-1)) + max * (-1); double y = RandomUtils.random.nextInt(max - max * (-1)) + max * (-1); double z = RandomUtils.random.nextInt(max - max * (-1)) + max * (-1); - if (direction == Direction.DOWN) { - y = RandomUtils.random.nextInt(max * 2 - max) + max; - } else if (direction == Direction.UP) { - y = RandomUtils.random.nextInt(max * (-1) - max * (-2)) + max * (-2); - } + + if (direction == Direction.DOWN) y = RandomUtils.random.nextInt(max * 2 - max) + max; + else if (direction == Direction.UP) y = RandomUtils.random.nextInt(max * (-1) - max * (-2)) + max * (-2); + Location target = location.clone().subtract(x, y, z); if (target == null) { cancel(); return; } + Vector link = target.toVector().subtract(location.toVector()); float length = (float) link.length(); link.normalize(); diff --git a/src/main/java/de/slikey/effectlib/effect/DnaEffect.java b/src/main/java/de/slikey/effectlib/effect/DnaEffect.java index 00cf9ea9..542a80a3 100644 --- a/src/main/java/de/slikey/effectlib/effect/DnaEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/DnaEffect.java @@ -1,14 +1,15 @@ package de.slikey.effectlib.effect; +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.util.Vector; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.MathUtils; -import org.bukkit.Particle; import de.slikey.effectlib.util.VectorUtils; -import org.bukkit.Color; -import org.bukkit.Location; -import org.bukkit.util.Vector; public class DnaEffect extends Effect { @@ -79,16 +80,15 @@ public DnaEffect(EffectManager effectManager) { @Override public void reset() { - this.step = 0; + step = 0; } @Override public void onRun() { Location location = getLocation(); for (int j = 0; j < particlesHelix; j++) { - if (step * grow > length) { - step = 0; - } + if (step * grow > length) step = 0; + for (int i = 0; i < 2; i++) { double angle = step * radials + Math.PI * i; Vector v = new Vector(Math.cos(angle) * radius, step * grow, Math.sin(angle) * radius); @@ -96,9 +96,8 @@ public void onRun() { } if (step % baseInterval == 0) { for (int i = -particlesBase; i <= particlesBase; i++) { - if (i == 0) { - continue; - } + if (i == 0) continue; + Particle particle = particleBase1; Color color = colorBase1; if (i < 0) { diff --git a/src/main/java/de/slikey/effectlib/effect/DonutEffect.java b/src/main/java/de/slikey/effectlib/effect/DonutEffect.java index 52ba1f71..6df63187 100644 --- a/src/main/java/de/slikey/effectlib/effect/DonutEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/DonutEffect.java @@ -71,4 +71,5 @@ public void onRun() { } } } + } diff --git a/src/main/java/de/slikey/effectlib/effect/DragonEffect.java b/src/main/java/de/slikey/effectlib/effect/DragonEffect.java index 252a7bb8..70a241ce 100644 --- a/src/main/java/de/slikey/effectlib/effect/DragonEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/DragonEffect.java @@ -1,16 +1,18 @@ package de.slikey.effectlib.effect; +import java.util.List; +import java.util.ArrayList; + +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.util.Vector; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.MathUtils; -import org.bukkit.Particle; import de.slikey.effectlib.util.RandomUtils; import de.slikey.effectlib.util.VectorUtils; -import java.util.ArrayList; -import java.util.List; -import org.bukkit.Location; -import org.bukkit.util.Vector; public class DragonEffect extends Effect { @@ -50,13 +52,13 @@ public DragonEffect(EffectManager effectManager) { type = EffectType.REPEATING; period = 2; iterations = 200; - rndF = new ArrayList(arcs); - rndAngle = new ArrayList(arcs); + rndF = new ArrayList<>(arcs); + rndAngle = new ArrayList<>(arcs); } @Override public void reset() { - this.step = 0; + step = 0; } @Override @@ -87,4 +89,5 @@ public void onRun() { step++; } } + } diff --git a/src/main/java/de/slikey/effectlib/effect/EarthEffect.java b/src/main/java/de/slikey/effectlib/effect/EarthEffect.java index d33ff0ce..1384ec1d 100644 --- a/src/main/java/de/slikey/effectlib/effect/EarthEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/EarthEffect.java @@ -1,20 +1,33 @@ package de.slikey.effectlib.effect; +import java.util.Set; +import java.util.HashSet; + +import org.bukkit.Color; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.util.Vector; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.MathUtils; -import org.bukkit.Particle; import de.slikey.effectlib.util.RandomUtils; import de.slikey.effectlib.util.VectorUtils; -import java.util.HashSet; -import java.util.Set; -import org.bukkit.Location; -import org.bukkit.util.Vector; public class EarthEffect extends Effect { - public Particle particle1 = Particle.VILLAGER_HAPPY; - public Particle particle2 = Particle.DRIP_WATER; + + public Particle particleLand = Particle.VILLAGER_HAPPY; + public Particle particleOcean = Particle.DRIP_WATER; + + public Color colorLand = null; + public Color colorOcean = null; + + public int particlesLand = 3; + public int particlesOcean = 1; + + public float speedLand = 0F; + public float speedOcean = 0F; /** * Precision of generation. Higher numbers have better results, but increase the time of generation. Don't pick Number above 10.000 @@ -51,13 +64,13 @@ public EarthEffect(EffectManager effectManager) { type = EffectType.REPEATING; period = 5; iterations = 200; - cacheGreen = new HashSet(); - cacheBlue = new HashSet(); + cacheGreen = new HashSet<>(); + cacheBlue = new HashSet<>(); } @Override public void reset() { - this.firstStep = true; + firstStep = true; } public void invalidate() { @@ -65,7 +78,7 @@ public void invalidate() { cacheGreen.clear(); cacheBlue.clear(); - Set cache = new HashSet(); + Set cache = new HashSet<>(); int sqrtParticles = (int) Math.sqrt(particles); float theta = 0, phi, thetaStep = MathUtils.PI / sqrtParticles, phiStep = MathUtils.PI2 / sqrtParticles; for (int i = 0; i < sqrtParticles; i++) { @@ -98,39 +111,34 @@ public void invalidate() { float minSquared = Float.POSITIVE_INFINITY, maxSquared = Float.NEGATIVE_INFINITY; for (Vector current : cache) { float lengthSquared = (float) current.lengthSquared(); - if (minSquared > lengthSquared) { - minSquared = lengthSquared; - } - if (maxSquared < lengthSquared) { - maxSquared = lengthSquared; - } + + if (minSquared > lengthSquared) minSquared = lengthSquared; + if (maxSquared < lengthSquared) maxSquared = lengthSquared; } // COLOR PARTICLES float average = (minSquared + maxSquared) / 2; for (Vector v : cache) { float lengthSquared = (float) v.lengthSquared(); - if (lengthSquared >= average) { - cacheGreen.add(v); - } else { - cacheBlue.add(v); - } + + if (lengthSquared >= average) cacheGreen.add(v); + else cacheBlue.add(v); } } @Override public void onRun() { Location location = getLocation(); - if (firstStep) { - invalidate(); - } + if (firstStep) invalidate(); + for (Vector v : cacheGreen) { - display(particle1, location.add(v), 0, 3); + display(particleLand, location.add(v), colorLand, speedLand, particlesLand); location.subtract(v); } for (Vector v : cacheBlue) { - display(particle2, location.add(v)); + display(particleOcean, location.add(v), colorOcean, speedOcean, particlesOcean); location.subtract(v); } } + } diff --git a/src/main/java/de/slikey/effectlib/effect/EquationEffect.java b/src/main/java/de/slikey/effectlib/effect/EquationEffect.java index bf38cd68..e06e07f2 100644 --- a/src/main/java/de/slikey/effectlib/effect/EquationEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/EquationEffect.java @@ -1,14 +1,15 @@ package de.slikey.effectlib.effect; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.util.Vector; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.VectorUtils; import de.slikey.effectlib.math.EquationStore; import de.slikey.effectlib.math.EquationTransform; -import org.bukkit.Particle; -import de.slikey.effectlib.util.VectorUtils; -import org.bukkit.Location; -import org.bukkit.util.Vector; public class EquationEffect extends Effect { @@ -104,8 +105,8 @@ public EquationEffect(EffectManager effectManager) { @Override public void reset() { - this.step = 0; - this.miniStep = 0; + step = 0; + miniStep = 0; } @Override @@ -125,44 +126,38 @@ public void onRun() { boolean hasInnerEquation = (x2Transform != null && y2Transform != null && z2Transform != null); for (int i = 0; i < particles; i++) { - Double xValue = xTransform.get(step); - Double yValue = yTransform.get(step); - Double zValue = zTransform.get(step); + double xValue = xTransform.get(step); + double yValue = yTransform.get(step); + double zValue = zTransform.get(step); Vector result = new Vector(xValue, yValue, zValue); - if (orient && orientPitch) { - result = VectorUtils.rotateVector(result, location); - } else if (orient) { - result = VectorUtils.rotateVector(result, location.getYaw(), 0); - } + if (orient && orientPitch) result = VectorUtils.rotateVector(result, location); + else if (orient) result = VectorUtils.rotateVector(result, location.getYaw(), 0); Location targetLocation = location.clone(); targetLocation.add(result); - if (!hasInnerEquation) { - display(particle, targetLocation); - } else { + + if (hasInnerEquation) { for (int j = 0; j < particles2; j++) { - Double x2Value = x2Transform.get(step, miniStep); - Double y2Value = y2Transform.get(step, miniStep); - Double z2Value = z2Transform.get(step, miniStep); - + double x2Value = x2Transform.get(step, miniStep); + double y2Value = y2Transform.get(step, miniStep); + double z2Value = z2Transform.get(step, miniStep); + Vector result2 = new Vector(x2Value, y2Value, z2Value); - if (orient && orientPitch) { - result2 = VectorUtils.rotateVector(result2, location); - } else if (orient) { - result2 = VectorUtils.rotateVector(result2, location.getYaw(), 0); - } - + if (orient && orientPitch) result2 = VectorUtils.rotateVector(result2, location); + else if (orient) result2 = VectorUtils.rotateVector(result2, location.getYaw(), 0); + Location target2Location = targetLocation.clone().add(result2); display(particle, target2Location); - + miniStep++; } - - if (cycleMiniStep) { - miniStep = 0; - } + + if (cycleMiniStep) miniStep = 0; + } else { + display(particle, targetLocation); } + if (maxSteps != 0 && step > maxSteps) { step = 0; break; @@ -171,4 +166,5 @@ public void onRun() { } } } + } diff --git a/src/main/java/de/slikey/effectlib/effect/ExplodeEffect.java b/src/main/java/de/slikey/effectlib/effect/ExplodeEffect.java index 2dfa7f10..c031d3df 100644 --- a/src/main/java/de/slikey/effectlib/effect/ExplodeEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/ExplodeEffect.java @@ -1,14 +1,16 @@ package de.slikey.effectlib.effect; +import org.bukkit.Sound; +import org.bukkit.Location; +import org.bukkit.Particle; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; -import org.bukkit.Particle; +import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.RandomUtils; -import org.bukkit.Location; -import org.bukkit.Sound; public class ExplodeEffect extends Effect { + public Particle particle1 = Particle.EXPLOSION_NORMAL; public Particle particle2 = Particle.EXPLOSION_HUGE; diff --git a/src/main/java/de/slikey/effectlib/effect/FlameEffect.java b/src/main/java/de/slikey/effectlib/effect/FlameEffect.java index 25473754..38a8d109 100644 --- a/src/main/java/de/slikey/effectlib/effect/FlameEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/FlameEffect.java @@ -1,17 +1,20 @@ package de.slikey.effectlib.effect; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.util.Vector; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; -import org.bukkit.Particle; +import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.RandomUtils; -import org.bukkit.Location; -import org.bukkit.util.Vector; public class FlameEffect extends Effect { public Particle particle = Particle.FLAME; + public int particles = 10; + public FlameEffect(EffectManager effectManager) { super(effectManager); type = EffectType.REPEATING; @@ -22,7 +25,7 @@ public FlameEffect(EffectManager effectManager) { @Override public void onRun() { Location location = getLocation(); - for (int i = 0; i < 10; i++) { + for (int i = 0; i < particles; i++) { Vector v = RandomUtils.getRandomCircleVector().multiply(RandomUtils.random.nextDouble() * 0.6d); v.setY(RandomUtils.random.nextFloat() * 1.8); location.add(v); diff --git a/src/main/java/de/slikey/effectlib/effect/FountainEffect.java b/src/main/java/de/slikey/effectlib/effect/FountainEffect.java index 74d4add3..5c01bbcc 100644 --- a/src/main/java/de/slikey/effectlib/effect/FountainEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/FountainEffect.java @@ -1,12 +1,13 @@ package de.slikey.effectlib.effect; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.util.Vector; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; -import org.bukkit.Particle; +import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.RandomUtils; -import org.bukkit.Location; -import org.bukkit.util.Vector; public class FountainEffect extends Effect { diff --git a/src/main/java/de/slikey/effectlib/effect/GridEffect.java b/src/main/java/de/slikey/effectlib/effect/GridEffect.java index 4cf3813b..c46ef8e8 100644 --- a/src/main/java/de/slikey/effectlib/effect/GridEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/GridEffect.java @@ -1,12 +1,13 @@ package de.slikey.effectlib.effect; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.util.Vector; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; -import org.bukkit.Particle; +import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.VectorUtils; -import org.bukkit.Location; -import org.bukkit.util.Vector; public class GridEffect extends Effect { diff --git a/src/main/java/de/slikey/effectlib/effect/HeartEffect.java b/src/main/java/de/slikey/effectlib/effect/HeartEffect.java index 843a98d7..95ce39e3 100644 --- a/src/main/java/de/slikey/effectlib/effect/HeartEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/HeartEffect.java @@ -1,12 +1,13 @@ package de.slikey.effectlib.effect; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.util.Vector; + import de.slikey.effectlib.Effect; import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.MathUtils; -import org.bukkit.Particle; import de.slikey.effectlib.util.VectorUtils; -import org.bukkit.Location; -import org.bukkit.util.Vector; /** * Creates a 2D Heart in 3D space. Thanks to the author for sharing it! @@ -48,7 +49,7 @@ public class HeartEffect extends Effect { /** * Compilation of the heart. (2) */ - public float compilaction = 2F; + public float compilation = 2F; public HeartEffect(EffectManager effectManager) { super(effectManager); @@ -59,8 +60,8 @@ public void onRun() { Location location = getLocation(); Vector vector = new Vector(); for (int i = 0; i < particles; i++) { - float alpha = ((MathUtils.PI / compilaction) / particles) * i; - double phi = Math.pow(Math.abs(MathUtils.sin(2 * compilaction * alpha)) + factorInnerSpike * Math.abs(MathUtils.sin(compilaction * alpha)), 1 / compressYFactorTotal); + float alpha = ((MathUtils.PI / compilation) / particles) * i; + double phi = Math.pow(Math.abs(MathUtils.sin(2 * compilation * alpha)) + factorInnerSpike * Math.abs(MathUtils.sin(compilation * alpha)), 1 / compressYFactorTotal); vector.setY(phi * (MathUtils.sin(alpha) + MathUtils.cos(alpha)) * yFactor); vector.setZ(phi * (MathUtils.cos(alpha) - MathUtils.sin(alpha)) * xFactor); diff --git a/src/main/java/de/slikey/effectlib/effect/HelixEffect.java b/src/main/java/de/slikey/effectlib/effect/HelixEffect.java index d4c98362..a950ecb1 100644 --- a/src/main/java/de/slikey/effectlib/effect/HelixEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/HelixEffect.java @@ -1,11 +1,12 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; import org.bukkit.Particle; import org.bukkit.Location; +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; + public class HelixEffect extends Effect { /** diff --git a/src/main/java/de/slikey/effectlib/effect/HillEffect.java b/src/main/java/de/slikey/effectlib/effect/HillEffect.java index 3d7702e1..51640601 100644 --- a/src/main/java/de/slikey/effectlib/effect/HillEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/HillEffect.java @@ -1,13 +1,13 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; -import org.bukkit.Particle; -import de.slikey.effectlib.util.VectorUtils; import org.bukkit.Location; +import org.bukkit.Particle; import org.bukkit.util.Vector; +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.VectorUtils; /** * Taken from http://en.wikipedia.org/wiki/Torus * @@ -64,4 +64,5 @@ public void onRun() { } } } + } diff --git a/src/main/java/de/slikey/effectlib/effect/IconEffect.java b/src/main/java/de/slikey/effectlib/effect/IconEffect.java index d3bc7d9d..91a71cf1 100644 --- a/src/main/java/de/slikey/effectlib/effect/IconEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/IconEffect.java @@ -1,11 +1,12 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; import org.bukkit.Particle; import org.bukkit.Location; +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; + public class IconEffect extends Effect { /** @@ -28,4 +29,5 @@ public void onRun() { location.add(0, yOffset, 0); display(particle, location); } + } diff --git a/src/main/java/de/slikey/effectlib/effect/ImageEffect.java b/src/main/java/de/slikey/effectlib/effect/ImageEffect.java index 96ff2061..d6c5321a 100644 --- a/src/main/java/de/slikey/effectlib/effect/ImageEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/ImageEffect.java @@ -21,11 +21,9 @@ public ImageEffect(EffectManager effectManager) { } protected void display(BufferedImage image, Vector v, Location location, int pixel) { - if (!invert && Color.black.getRGB() != pixel) { - return; - } else if (invert && Color.black.getRGB() == pixel) { - return; - } + if (!invert && Color.black.getRGB() != pixel) return; + else if (invert && Color.black.getRGB() == pixel) return; + display(particle, location.add(v)); location.subtract(v); } diff --git a/src/main/java/de/slikey/effectlib/effect/JumpEffect.java b/src/main/java/de/slikey/effectlib/effect/JumpEffect.java index 892191ab..c8142ef9 100644 --- a/src/main/java/de/slikey/effectlib/effect/JumpEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/JumpEffect.java @@ -1,10 +1,11 @@ package de.slikey.effectlib.effect; +import org.bukkit.util.Vector; +import org.bukkit.entity.Entity; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; -import org.bukkit.entity.Entity; -import org.bukkit.util.Vector; +import de.slikey.effectlib.EffectManager; public class JumpEffect extends Effect { diff --git a/src/main/java/de/slikey/effectlib/effect/LineEffect.java b/src/main/java/de/slikey/effectlib/effect/LineEffect.java index b8550cbe..43888423 100644 --- a/src/main/java/de/slikey/effectlib/effect/LineEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/LineEffect.java @@ -1,12 +1,13 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; import org.bukkit.Particle; import org.bukkit.Location; import org.bukkit.util.Vector; +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; + public class LineEffect extends Effect { /** @@ -59,18 +60,17 @@ public LineEffect(EffectManager effectManager) { @Override public void reset() { - this.step = 0; + step = 0; } @Override public void onRun() { Location location = getLocation(); - Location target = null; - if (length > 0) { - target = location.clone().add(location.getDirection().normalize().multiply(length)); - } else { - target = getTarget(); - } + Location target; + + if (length > 0) target = location.clone().add(location.getDirection().normalize().multiply(length)); + else target = getTarget(); + int amount = particles / zigZags; if (target == null) { cancel(); @@ -85,18 +85,11 @@ public void onRun() { Location loc = location.clone().subtract(v); for (int i = 0; i < particles; i++) { if (isZigZag) { - if (zag) { - loc.add(zigZagOffset); - } else { - loc.subtract(zigZagOffset); - } + if (zag) loc.add(zigZagOffset); + else loc.subtract(zigZagOffset); } if (step >= amount) { - if (zag) { - zag = false; - } else { - zag = true; - } + zag = !zag; step = 0; } step++; diff --git a/src/main/java/de/slikey/effectlib/effect/LoveEffect.java b/src/main/java/de/slikey/effectlib/effect/LoveEffect.java index c8c3f7e2..027a7427 100644 --- a/src/main/java/de/slikey/effectlib/effect/LoveEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/LoveEffect.java @@ -1,11 +1,12 @@ package de.slikey.effectlib.effect; +import org.bukkit.Location; +import org.bukkit.Particle; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; -import org.bukkit.Particle; +import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.RandomUtils; -import org.bukkit.Location; public class LoveEffect extends Effect { diff --git a/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java b/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java index 330ace57..35a54ad9 100644 --- a/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java @@ -1,27 +1,29 @@ package de.slikey.effectlib.effect; +import java.util.Map; +import java.util.Set; +import java.util.Arrays; +import java.util.HashMap; +import java.util.HashSet; +import java.lang.reflect.Field; + +import org.bukkit.Location; +import org.bukkit.util.Vector; +import org.bukkit.configuration.ConfigurationSection; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.VectorUtils; import de.slikey.effectlib.math.EquationStore; import de.slikey.effectlib.math.EquationTransform; -import de.slikey.effectlib.util.VectorUtils; -import org.bukkit.Location; -import org.bukkit.configuration.ConfigurationSection; -import org.bukkit.util.Vector; - -import java.lang.reflect.Field; -import java.util.Arrays; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; import com.google.common.base.CaseFormat; public class ModifiedEffect extends Effect { + private final static String[] _variables = {"t", "i"}; - private final static Set variables = new HashSet(Arrays.asList(_variables)); + private final static Set variables = new HashSet<>(Arrays.asList(_variables)); /** * The base configuration of the inner effect. @@ -68,11 +70,11 @@ public class ModifiedEffect extends Effect { /** * Effect parameters to modify each tick, paired with an equation used to modify them. */ - public Map parameters = new HashMap(); + public Map parameters = new HashMap<>(); private boolean initialized = false; private Effect innerEffect; - private Map parameterTransforms = new HashMap(); + private Map parameterTransforms = new HashMap<>(); private int step = 0; private EquationTransform xTransform; @@ -89,17 +91,13 @@ public ModifiedEffect(EffectManager effectManager) { @Override public void reset() { - this.step = 0; - if (innerEffect != null) { - innerEffect.prepare(); - } + step = 0; + if (innerEffect != null) innerEffect.prepare(); } @Override public void onDone() { - if (innerEffect != null) { - innerEffect.onDone(); - } + if (innerEffect != null) innerEffect.onDone(); } @Override @@ -112,9 +110,8 @@ public void onRun() { return; } - if (effectClass == null) { - effectClass = effect.getString("class"); - } + if (effectClass == null) effectClass = effect.getString("class"); + if (effectClass == null) { effectManager.onError("ModifiedEffect missing inner effect class property"); cancel(); @@ -172,18 +169,12 @@ public void onRun() { zTransform == null ? 0 : zTransform.get(step, maxIterations) ); - if (previousOffset != null) { - offset.subtract(previousOffset); - } else { - previousOffset = new Vector(); - } + if (previousOffset != null) offset.subtract(previousOffset); + else previousOffset = new Vector(); Location location = getLocation(); - if (orient && orientPitch) { - offset = VectorUtils.rotateVector(offset, location); - } else if (orient) { - offset = VectorUtils.rotateVector(offset, location.getYaw(), 0); - } + if (orient && orientPitch) offset = VectorUtils.rotateVector(offset, location); + else if (orient) offset = VectorUtils.rotateVector(offset, location.getYaw(), 0); origin.addOffset(offset); previousOffset.add(offset); @@ -194,15 +185,15 @@ public void onRun() { try { Field field = entry.getKey(); if (field.getType().equals(Double.class) || field.getType().equals(Double.TYPE)) { - entry.getKey().set(innerEffect,value); + entry.getKey().set(innerEffect, value); } else if (field.getType().equals(Integer.class) || field.getType().equals(Integer.TYPE)) { - entry.getKey().set(innerEffect, (int)value); + entry.getKey().set(innerEffect, (int) value); } else if (field.getType().equals(Float.class) || field.getType().equals(Float.TYPE)) { - entry.getKey().set(innerEffect, (float)value); + entry.getKey().set(innerEffect, (float) value); } else if (field.getType().equals(Short.class) || field.getType().equals(Short.TYPE)) { - entry.getKey().set(innerEffect, (short)value); + entry.getKey().set(innerEffect, (short) value); } else if (field.getType().equals(Byte.class) || field.getType().equals(Byte.TYPE)) { - entry.getKey().set(innerEffect, (byte)value); + entry.getKey().set(innerEffect, (byte) value); } else { effectManager.onError("Can't assign property " + entry.getKey().getName() + " of effect class " + effectClass + " of type " + field.getType().getName()); cancel(); @@ -223,4 +214,5 @@ public void onRun() { } step++; } + } diff --git a/src/main/java/de/slikey/effectlib/effect/MusicEffect.java b/src/main/java/de/slikey/effectlib/effect/MusicEffect.java index e520eeaa..c2717041 100644 --- a/src/main/java/de/slikey/effectlib/effect/MusicEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/MusicEffect.java @@ -1,12 +1,14 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; import org.bukkit.Particle; import org.bukkit.Location; +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; + public class MusicEffect extends Effect { + public Particle particle = Particle.NOTE; /** @@ -33,7 +35,7 @@ public MusicEffect(EffectManager effectManager) { @Override public void reset() { - this.step = 0; + step = 0; } @Override diff --git a/src/main/java/de/slikey/effectlib/effect/PlotEffect.java b/src/main/java/de/slikey/effectlib/effect/PlotEffect.java index 6c0a7d40..db63b5d8 100644 --- a/src/main/java/de/slikey/effectlib/effect/PlotEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/PlotEffect.java @@ -1,20 +1,22 @@ package de.slikey.effectlib.effect; +import java.util.Set; +import java.util.Arrays; +import java.util.HashSet; + +import org.bukkit.Particle; +import org.bukkit.Location; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.math.EquationStore; import de.slikey.effectlib.math.EquationTransform; -import org.bukkit.Particle; -import org.bukkit.Location; - -import java.util.Arrays; -import java.util.HashSet; -import java.util.Set; public class PlotEffect extends Effect { + private final static String[] _variables = {"t", "i"}; - private final static Set variables = new HashSet(Arrays.asList(_variables)); + private final static Set variables = new HashSet<>(Arrays.asList(_variables)); /** * ParticleType of spawned particle @@ -56,6 +58,8 @@ public class PlotEffect extends Effect { */ public boolean persistent = true; + private int step = 0; + public PlotEffect(EffectManager effectManager) { super(effectManager); type = EffectType.REPEATING; @@ -63,8 +67,6 @@ public PlotEffect(EffectManager effectManager) { iterations = 100; } - private int step = 0; - @Override public void onRun() { int base = persistent ? 0 : step; @@ -95,4 +97,5 @@ public void onRun() { step++; } + } diff --git a/src/main/java/de/slikey/effectlib/effect/SkyRocketEffect.java b/src/main/java/de/slikey/effectlib/effect/SkyRocketEffect.java index 8f66954f..60e30e3d 100644 --- a/src/main/java/de/slikey/effectlib/effect/SkyRocketEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/SkyRocketEffect.java @@ -1,7 +1,6 @@ package de.slikey.effectlib.effect; import de.slikey.effectlib.EffectManager; -import org.bukkit.entity.Entity; public class SkyRocketEffect extends JumpEffect { diff --git a/src/main/java/de/slikey/effectlib/effect/SmokeEffect.java b/src/main/java/de/slikey/effectlib/effect/SmokeEffect.java index 32757b91..3f18bab0 100644 --- a/src/main/java/de/slikey/effectlib/effect/SmokeEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/SmokeEffect.java @@ -1,11 +1,12 @@ package de.slikey.effectlib.effect; +import org.bukkit.Location; +import org.bukkit.Particle; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; -import org.bukkit.Particle; +import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.RandomUtils; -import org.bukkit.Location; public class SmokeEffect extends Effect { @@ -14,6 +15,11 @@ public class SmokeEffect extends Effect { */ public Particle particle = Particle.SMOKE_NORMAL; + /** + * Number of particles to display + */ + public int particles = 20; + public SmokeEffect(EffectManager effectManager) { super(effectManager); type = EffectType.REPEATING; @@ -24,7 +30,7 @@ public SmokeEffect(EffectManager effectManager) { @Override public void onRun() { Location location = getLocation(); - for (int i = 0; i < 20; i++) { + for (int i = 0; i < particles; i++) { location.add(RandomUtils.getRandomCircleVector().multiply(RandomUtils.random.nextDouble() * 0.6d)); location.add(0, RandomUtils.random.nextFloat() * 2, 0); display(particle, location); diff --git a/src/main/java/de/slikey/effectlib/effect/SphereEffect.java b/src/main/java/de/slikey/effectlib/effect/SphereEffect.java index 956844ca..a09a90b3 100644 --- a/src/main/java/de/slikey/effectlib/effect/SphereEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/SphereEffect.java @@ -30,7 +30,7 @@ public class SphereEffect extends Effect { * Particles to display */ public int particles = 50; - + /** * Amount to increase the radius per tick */ @@ -49,7 +49,7 @@ public SphereEffect(EffectManager effectManager) { @Override public void onRun() { if (radiusIncrease != 0) radius += radiusIncrease; - if (particleIncrease != 0) particles += particleIncrease; + if (particleIncrease != 0) particles += particleIncrease; Location location = getLocation(); location.add(0, yOffset, 0); diff --git a/src/main/java/de/slikey/effectlib/effect/StarEffect.java b/src/main/java/de/slikey/effectlib/effect/StarEffect.java index 41b14dde..7381a09b 100644 --- a/src/main/java/de/slikey/effectlib/effect/StarEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/StarEffect.java @@ -1,14 +1,15 @@ package de.slikey.effectlib.effect; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.util.Vector; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.MathUtils; -import org.bukkit.Particle; import de.slikey.effectlib.util.RandomUtils; import de.slikey.effectlib.util.VectorUtils; -import org.bukkit.Location; -import org.bukkit.util.Vector; public class StarEffect extends Effect { @@ -56,12 +57,15 @@ public void onRun() { Vector v = new Vector(Math.cos(angle), 0, Math.sin(angle)); v.multiply((spikeHeight - height) * radius / spikeHeight); v.setY(innerRadius + height); + VectorUtils.rotateAroundAxisX(v, xRotation); location.add(v); display(particle, location); location.subtract(v); + VectorUtils.rotateAroundAxisX(v, Math.PI); VectorUtils.rotateAroundAxisY(v, Math.PI / 2); + location.add(v); display(particle, location); location.subtract(v); diff --git a/src/main/java/de/slikey/effectlib/effect/TextEffect.java b/src/main/java/de/slikey/effectlib/effect/TextEffect.java index 554a13af..3af2e6f1 100644 --- a/src/main/java/de/slikey/effectlib/effect/TextEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/TextEffect.java @@ -1,19 +1,21 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; -import de.slikey.effectlib.util.MathUtils; -import org.bukkit.Particle; -import de.slikey.effectlib.util.StringParser; -import de.slikey.effectlib.util.VectorUtils; -import java.awt.Color; import java.awt.Font; +import java.awt.Color; +import java.util.Objects; import java.awt.image.BufferedImage; import org.bukkit.Location; +import org.bukkit.Particle; import org.bukkit.util.Vector; +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.MathUtils; +import de.slikey.effectlib.util.VectorUtils; +import de.slikey.effectlib.util.StringParser; + public class TextEffect extends Effect { /** @@ -75,7 +77,7 @@ public class TextEffect extends Effect { public TextEffect(EffectManager effectManager) { super(effectManager); - this.font = new Font("Tahoma", Font.PLAIN, 16); + font = new Font("Tahoma", Font.PLAIN, 16); type = EffectType.REPEATING; period = 40; iterations = 20; @@ -92,7 +94,7 @@ public void onRun() { return; } Location location = getLocation(); - int clr = 0; + int clr; try { if (image == null || shouldRecalculateImage()) { lastParsedText = text; @@ -103,11 +105,9 @@ public void onRun() { for (int y = 0; y < image.getHeight(); y += stepY) { for (int x = 0; x < image.getWidth(); x += stepX) { clr = image.getRGB(x, y); - if (!invert && Color.black.getRGB() != clr) { - continue; - } else if (invert && Color.black.getRGB() == clr) { - continue; - } + if (!invert && Color.black.getRGB() != clr) continue; + else if (invert && Color.black.getRGB() == clr) continue; + Vector v = new Vector((float) image.getWidth() / 2 - x, (float) image.getHeight() / 2 - y, 0).multiply(size); VectorUtils.rotateAroundAxisY(v, -location.getYaw() * MathUtils.degreesToRadians); display(particle, location.add(v)); @@ -120,17 +120,13 @@ public void onRun() { cancel(true); } } - - // Replacement for Java 1.7 Objects.equals - public static boolean objectsEquals(Object a, Object b) { - return (a == b) || (a != null && a.equals(b)); - } private boolean shouldRecalculateImage() { // Don't bother if we don't use real time updates if (!realtime) return false; // Text content or font is different, recalculate - return !objectsEquals(lastParsedText, text) || !objectsEquals(lastParsedFont, font); + return !Objects.equals(lastParsedText, text) || !Objects.equals(lastParsedFont, font); } + } diff --git a/src/main/java/de/slikey/effectlib/effect/TornadoEffect.java b/src/main/java/de/slikey/effectlib/effect/TornadoEffect.java index 67a190b0..03842e58 100644 --- a/src/main/java/de/slikey/effectlib/effect/TornadoEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/TornadoEffect.java @@ -63,6 +63,21 @@ public class TornadoEffect extends Effect { */ public double distance = .375d; + /* + * Number of particles per circle + */ + public int circleParticles = 64; + + /* + * Number of particles in the cloud + */ + public int cloudParticles = 100; + + /* + * Amount of y-jitter between circle particles + */ + public double circleHeight = 0; + /* * Internal counter */ @@ -83,7 +98,7 @@ public void reset() { @Override public void onRun() { Location l = getLocation().add(0, yOffset, 0); - for (int i = 0; i < (100 * cloudSize); i++) { + for (int i = 0; i < (cloudParticles * cloudSize); i++) { Vector v = RandomUtils.getRandomCircleVector().multiply(RandomUtils.random.nextDouble() * cloudSize); if (showCloud) { display(cloudParticle, l.add(v), cloudColor, cloudSpeed, 1); @@ -99,6 +114,7 @@ public void onRun() { } for (Vector v : createCircle(y, fr)) { if (showTornado) { + if (circleHeight > 0) v.setY(v.getY() + RandomUtils.random.nextDouble() * circleHeight / 2 - circleHeight / 2); display(tornadoParticle, t.add(v), tornadoColor); t.subtract(v); step++; @@ -109,7 +125,7 @@ public void onRun() { } public List createCircle(double y, double radius) { - double amount = radius * 64; + double amount = radius * circleParticles; double inc = (2 * Math.PI) / amount; List vecs = new ArrayList(); for (int i = 0; i < amount; i++) { diff --git a/src/main/java/de/slikey/effectlib/effect/TraceEffect.java b/src/main/java/de/slikey/effectlib/effect/TraceEffect.java index 0b87fe61..a4b13ee6 100644 --- a/src/main/java/de/slikey/effectlib/effect/TraceEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/TraceEffect.java @@ -1,15 +1,17 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; -import org.bukkit.Particle; -import java.util.ArrayList; import java.util.List; -import org.bukkit.Location; +import java.util.ArrayList; + import org.bukkit.World; +import org.bukkit.Location; +import org.bukkit.Particle; import org.bukkit.util.Vector; +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; + public class TraceEffect extends Effect { /** @@ -30,7 +32,7 @@ public class TraceEffect extends Effect { /** * Waypoints of the trace */ - protected final List wayPoints = new ArrayList(); + protected final List wayPoints = new ArrayList<>(); /** * Internal counter @@ -51,7 +53,7 @@ public TraceEffect(EffectManager effectManager) { @Override public void reset() { - this.step = 0; + step = 0; } @Override @@ -64,21 +66,15 @@ public void onRun() { return; } - synchronized(wayPoints) - { - if (wayPoints.size() >= maxWayPoints) { - wayPoints.remove(0); - } + synchronized(wayPoints) { + if (wayPoints.size() >= maxWayPoints) wayPoints.remove(0); } wayPoints.add(location.toVector()); step++; - if (step % refresh != 0) { - return; - } + if (step % refresh != 0) return; - synchronized(wayPoints) - { + synchronized(wayPoints) { for (Vector position : wayPoints) { Location particleLocation = new Location(world, position.getX(), position.getY(), position.getZ()); display(particle, particleLocation); diff --git a/src/main/java/de/slikey/effectlib/effect/TurnEffect.java b/src/main/java/de/slikey/effectlib/effect/TurnEffect.java index bb200fcc..240b4bad 100644 --- a/src/main/java/de/slikey/effectlib/effect/TurnEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/TurnEffect.java @@ -1,11 +1,11 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; import org.bukkit.Location; import org.bukkit.entity.Entity; -import org.bukkit.entity.Player; + +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; public class TurnEffect extends Effect { diff --git a/src/main/java/de/slikey/effectlib/effect/VortexEffect.java b/src/main/java/de/slikey/effectlib/effect/VortexEffect.java index 65f8628b..ead3f1be 100644 --- a/src/main/java/de/slikey/effectlib/effect/VortexEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/VortexEffect.java @@ -1,13 +1,14 @@ package de.slikey.effectlib.effect; +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.util.Vector; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.MathUtils; -import org.bukkit.Particle; import de.slikey.effectlib.util.VectorUtils; -import org.bukkit.Location; -import org.bukkit.util.Vector; public class VortexEffect extends Effect { @@ -56,7 +57,7 @@ public VortexEffect(EffectManager effectManager) { @Override public void reset() { - this.step = 0; + step = 0; } @Override diff --git a/src/main/java/de/slikey/effectlib/effect/WarpEffect.java b/src/main/java/de/slikey/effectlib/effect/WarpEffect.java index ee99f291..151b225d 100644 --- a/src/main/java/de/slikey/effectlib/effect/WarpEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/WarpEffect.java @@ -1,10 +1,11 @@ package de.slikey.effectlib.effect; +import org.bukkit.Location; +import org.bukkit.Particle; + import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.EffectType; -import org.bukkit.Particle; -import org.bukkit.Location; +import de.slikey.effectlib.EffectManager; public class WarpEffect extends Effect { @@ -47,15 +48,14 @@ public WarpEffect(EffectManager effectManager) { @Override public void reset() { - this.step = 0; + step = 0; } @Override public void onRun() { Location location = getLocation(); - if (step > rings) { - step = 0; - } + if (step > rings) step = 0; + double x, y, z; y = step * grow; location.add(0, y, 0); diff --git a/src/main/java/de/slikey/effectlib/effect/WaveEffect.java b/src/main/java/de/slikey/effectlib/effect/WaveEffect.java index be1344d8..3365b508 100644 --- a/src/main/java/de/slikey/effectlib/effect/WaveEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/WaveEffect.java @@ -1,17 +1,19 @@ package de.slikey.effectlib.effect; -import de.slikey.effectlib.Effect; -import de.slikey.effectlib.EffectManager; -import de.slikey.effectlib.EffectType; -import de.slikey.effectlib.util.MathUtils; -import org.bukkit.Particle; -import de.slikey.effectlib.util.VectorUtils; -import java.util.Collection; import java.util.HashSet; +import java.util.Collection; + import org.bukkit.Color; import org.bukkit.Location; +import org.bukkit.Particle; import org.bukkit.util.Vector; +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.MathUtils; +import de.slikey.effectlib.util.VectorUtils; + public class WaveEffect extends Effect { public Particle particle = Particle.DRIP_WATER; @@ -85,13 +87,13 @@ public WaveEffect(EffectManager effectManager) { type = EffectType.REPEATING; period = 5; iterations = 50; - waterCache = new HashSet(); - cloudCache = new HashSet(); + waterCache = new HashSet<>(); + cloudCache = new HashSet<>(); } @Override public void reset() { - this.firstStep = true; + firstStep = true; } /** @@ -114,18 +116,14 @@ public void invalidate(Location location) { len_s1ToH = (float) s1ToH.length(); n_s1ToH = s1ToH.clone().multiply(1f / len_s1ToH); n1 = new Vector(s1ToH.getY(), -s1ToH.getX(), 0).normalize(); - if (n1.getX() < 0) { - n1.multiply(-1); - } + if (n1.getX() < 0) n1.multiply(-1); s2ToH = h.clone().subtract(s2); c2 = s2.clone().add(s2ToH.clone().multiply(0.5)); len_s2ToH = (float) s2ToH.length(); n_s2ToH = s2ToH.clone().multiply(1f / len_s2ToH); n2 = new Vector(s2ToH.getY(), -s2ToH.getX(), 0).normalize(); - if (n2.getX() < 0) { - n2.multiply(-1); - } + if (n2.getX() < 0) n2.multiply(-1); yaw = (-location.getYaw() + 90) * MathUtils.degreesToRadians; @@ -140,11 +138,8 @@ public void invalidate(Location location) { float z = ((float) j / rows - .5f) * width; Vector vec = v.clone().setZ(v.getZ() + z); VectorUtils.rotateAroundAxisY(vec, yaw); - if (i == 0 || i == particlesFront - 1) { - cloudCache.add(vec); - } else { - waterCache.add(vec); - } + if (i == 0 || i == particlesFront - 1) cloudCache.add(vec); + else waterCache.add(vec); } } for (int i = 0; i < particlesBack; i++) { @@ -158,11 +153,8 @@ public void invalidate(Location location) { float z = ((float) j / rows - .5f) * width; Vector vec = v.clone().setZ(v.getZ() + z); VectorUtils.rotateAroundAxisY(vec, yaw); - if (i == particlesFront - 1) { - cloudCache.add(vec); - } else { - waterCache.add(vec); - } + if (i == particlesFront - 1) cloudCache.add(vec); + else waterCache.add(vec); } } } @@ -187,4 +179,5 @@ public void onRun() { location.subtract(v); } } + } diff --git a/src/main/java/de/slikey/effectlib/math/EchoTransform.java b/src/main/java/de/slikey/effectlib/math/EchoTransform.java index 160e7926..c53bad1e 100644 --- a/src/main/java/de/slikey/effectlib/math/EchoTransform.java +++ b/src/main/java/de/slikey/effectlib/math/EchoTransform.java @@ -3,6 +3,7 @@ import org.bukkit.configuration.ConfigurationSection; public class EchoTransform implements Transform { + @Override public void load(ConfigurationSection parameters) { } @@ -11,4 +12,5 @@ public void load(ConfigurationSection parameters) { public double get(double t) { return t; } + } diff --git a/src/main/java/de/slikey/effectlib/math/EquationStore.java b/src/main/java/de/slikey/effectlib/math/EquationStore.java index 2b46478b..7e126e02 100644 --- a/src/main/java/de/slikey/effectlib/math/EquationStore.java +++ b/src/main/java/de/slikey/effectlib/math/EquationStore.java @@ -1,13 +1,14 @@ package de.slikey.effectlib.math; -import java.util.HashMap; import java.util.Map; import java.util.Set; +import java.util.HashMap; public class EquationStore { + private static final String DEFAULT_VARIABLE = "x"; private static EquationStore instance; - private Map transforms = new HashMap(); + private Map transforms = new HashMap<>(); public EquationTransform getTransform(String equation) { return getTransform(equation, DEFAULT_VARIABLE); @@ -44,16 +45,13 @@ public EquationTransform getTransform(String equation, Set variables) { } public static void clear() { - if (instance != null) { - instance.transforms.clear(); - } + if (instance != null) instance.transforms.clear(); } public static EquationStore getInstance() { - if (instance == null) { - instance = new EquationStore(); - } + if (instance == null) instance = new EquationStore(); return instance; } + } diff --git a/src/main/java/de/slikey/effectlib/math/EquationTransform.java b/src/main/java/de/slikey/effectlib/math/EquationTransform.java index 485cdaa0..e8dc3d7a 100644 --- a/src/main/java/de/slikey/effectlib/math/EquationTransform.java +++ b/src/main/java/de/slikey/effectlib/math/EquationTransform.java @@ -1,15 +1,17 @@ package de.slikey.effectlib.math; +import java.util.Set; +import java.util.Random; +import java.util.HashSet; + import net.objecthunter.exp4j.Expression; import net.objecthunter.exp4j.ExpressionBuilder; import net.objecthunter.exp4j.function.Function; -import org.bukkit.configuration.ConfigurationSection; -import java.util.HashSet; -import java.util.Random; -import java.util.Set; +import org.bukkit.configuration.ConfigurationSection; public class EquationTransform implements Transform { + private Expression expression; private static Function randFunction; private static Function minFunction; @@ -24,7 +26,7 @@ public void load(ConfigurationSection parameters) { } public EquationTransform() { - inputVariables = new HashSet(); + inputVariables = new HashSet<>(); } public EquationTransform(String equation) { @@ -32,13 +34,13 @@ public EquationTransform(String equation) { } public EquationTransform(String equation, String inputVariable) { - inputVariables = new HashSet(); + inputVariables = new HashSet<>(); inputVariables.add(inputVariable); setEquation(equation); } public EquationTransform(String equation, String... inputVariables) { - this.inputVariables = new HashSet(); + this.inputVariables = new HashSet<>(); for (String inputVariable : inputVariables) { this.inputVariables.add(inputVariable); } @@ -110,9 +112,7 @@ public boolean setEquation(String equation) { @Override public double get(double t) { - if (expression == null) { - return 0; - } + if (expression == null) return 0; for (String inputVariable : inputVariables) { expression.setVariable(inputVariable, t); } @@ -120,9 +120,7 @@ public double get(double t) { } public double get(double... t) { - if (expression == null) { - return 0; - } + if (expression == null) return 0; int index = 0; for (String inputVariable : inputVariables) { expression.setVariable(inputVariable, t[index]); @@ -136,15 +134,11 @@ public void addVariable(String key) { } public void setVariable(String key, double value) { - if (expression != null) { - expression.setVariable(key, value); - } + if (expression != null) expression.setVariable(key, value); } public double get() { - if (expression == null) { - return Double.NaN; - } + if (expression == null) return Double.NaN; double value = Double.NaN; try { exception = null; @@ -166,4 +160,5 @@ public boolean isValid() { public Set getParameters() { return inputVariables; } + } diff --git a/src/main/java/de/slikey/effectlib/math/MultiplyTransform.java b/src/main/java/de/slikey/effectlib/math/MultiplyTransform.java index 4b5f9d78..7b4ca027 100644 --- a/src/main/java/de/slikey/effectlib/math/MultiplyTransform.java +++ b/src/main/java/de/slikey/effectlib/math/MultiplyTransform.java @@ -1,10 +1,11 @@ package de.slikey.effectlib.math; -import org.bukkit.configuration.ConfigurationSection; - import java.util.Collection; +import org.bukkit.configuration.ConfigurationSection; + public class MultiplyTransform implements Transform { + private Collection inputs; @Override @@ -20,4 +21,5 @@ public double get(double t) { } return value; } + } diff --git a/src/main/java/de/slikey/effectlib/math/SequenceTransform.java b/src/main/java/de/slikey/effectlib/math/SequenceTransform.java index f7afee1c..ab826466 100644 --- a/src/main/java/de/slikey/effectlib/math/SequenceTransform.java +++ b/src/main/java/de/slikey/effectlib/math/SequenceTransform.java @@ -1,23 +1,26 @@ package de.slikey.effectlib.math; -import de.slikey.effectlib.util.ConfigUtils; -import org.bukkit.configuration.ConfigurationSection; - +import java.util.List; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.List; + +import de.slikey.effectlib.util.ConfigUtils; + +import org.bukkit.configuration.ConfigurationSection; public class SequenceTransform implements Transform { + private List steps; private static class Sequence { + private final Transform transform; private final double start; public Sequence(ConfigurationSection configuration) { - this.transform = Transforms.loadTransform(configuration, "transform"); - this.start = configuration.getDouble("start", 0); + transform = Transforms.loadTransform(configuration, "transform"); + start = configuration.getDouble("start", 0); } public double getStart() { @@ -27,11 +30,12 @@ public double getStart() { public double get(double t) { return transform.get(t); } - }; + + } @Override public void load(ConfigurationSection parameters) { - steps = new ArrayList(); + steps = new ArrayList<>(); Collection stepConfigurations = ConfigUtils.getNodeList(parameters, "steps"); if (stepConfigurations != null) { for (ConfigurationSection stepConfig : stepConfigurations) { @@ -45,10 +49,9 @@ public void load(ConfigurationSection parameters) { public double get(double t) { double value = 0; for (Sequence step : steps) { - if (step.getStart() <= t) { - return step.get(t); - } + if (step.getStart() <= t) return step.get(t); } return value; } + } diff --git a/src/main/java/de/slikey/effectlib/math/SumTransform.java b/src/main/java/de/slikey/effectlib/math/SumTransform.java index 9aaef40e..5b40ee6a 100644 --- a/src/main/java/de/slikey/effectlib/math/SumTransform.java +++ b/src/main/java/de/slikey/effectlib/math/SumTransform.java @@ -1,10 +1,11 @@ package de.slikey.effectlib.math; -import org.bukkit.configuration.ConfigurationSection; - import java.util.Collection; +import org.bukkit.configuration.ConfigurationSection; + public class SumTransform implements Transform { + private Collection inputs; @Override @@ -20,4 +21,5 @@ public double get(double t) { } return value; } + } diff --git a/src/main/java/de/slikey/effectlib/math/Transform.java b/src/main/java/de/slikey/effectlib/math/Transform.java index 2b076767..18e0298c 100644 --- a/src/main/java/de/slikey/effectlib/math/Transform.java +++ b/src/main/java/de/slikey/effectlib/math/Transform.java @@ -3,6 +3,9 @@ import org.bukkit.configuration.ConfigurationSection; public interface Transform { + public void load(ConfigurationSection parameters); + public double get(double t); + } diff --git a/src/main/java/de/slikey/effectlib/math/Transforms.java b/src/main/java/de/slikey/effectlib/math/Transforms.java index 7e4c490a..7cd9e5a1 100644 --- a/src/main/java/de/slikey/effectlib/math/Transforms.java +++ b/src/main/java/de/slikey/effectlib/math/Transforms.java @@ -8,6 +8,7 @@ import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.ConfigUtils; + import org.bukkit.configuration.ConfigurationSection; public class Transforms { diff --git a/src/main/java/de/slikey/effectlib/math/VectorTransform.java b/src/main/java/de/slikey/effectlib/math/VectorTransform.java index a295ad87..230a7957 100644 --- a/src/main/java/de/slikey/effectlib/math/VectorTransform.java +++ b/src/main/java/de/slikey/effectlib/math/VectorTransform.java @@ -1,14 +1,17 @@ package de.slikey.effectlib.math; -import de.slikey.effectlib.util.VectorUtils; import org.bukkit.Location; -import org.bukkit.configuration.ConfigurationSection; import org.bukkit.util.Vector; +import org.bukkit.configuration.ConfigurationSection; + +import de.slikey.effectlib.util.VectorUtils; public class VectorTransform { + private Transform xTransform; private Transform yTransform; private Transform zTransform; + private boolean orient; public VectorTransform(ConfigurationSection configuration) { @@ -20,18 +23,16 @@ public VectorTransform(ConfigurationSection configuration) { public Vector get(Location source, double t) { // This returns a unit vector with the new direction calculated via the equations - Double xValue = xTransform.get(t); - Double yValue = yTransform.get(t); - Double zValue = zTransform.get(t); + double xValue = xTransform.get(t); + double yValue = yTransform.get(t); + double zValue = zTransform.get(t); Vector result = new Vector(xValue, yValue, zValue); // Rotates to player's direction - if (orient && source != null) - { - result = VectorUtils.rotateVector(result, source); - } + if (orient && source != null) result = VectorUtils.rotateVector(result, source); return result; } + } diff --git a/src/main/java/de/slikey/effectlib/math/dQuadraticTransform.java b/src/main/java/de/slikey/effectlib/math/dQuadraticTransform.java index f013c6c1..c6ad8a8c 100644 --- a/src/main/java/de/slikey/effectlib/math/dQuadraticTransform.java +++ b/src/main/java/de/slikey/effectlib/math/dQuadraticTransform.java @@ -3,6 +3,7 @@ import org.bukkit.configuration.ConfigurationSection; public class dQuadraticTransform implements Transform { + private Transform a; private Transform b; private Transform c; @@ -26,4 +27,5 @@ public void load(ConfigurationSection parameters) { public double get(double t) { return 2 * a.get(t) * (t + b.get(t)) + c.get(t); } + } diff --git a/src/main/java/de/slikey/effectlib/math/dSinTransform.java b/src/main/java/de/slikey/effectlib/math/dSinTransform.java index 9b6708c1..86e9f0d0 100644 --- a/src/main/java/de/slikey/effectlib/math/dSinTransform.java +++ b/src/main/java/de/slikey/effectlib/math/dSinTransform.java @@ -3,6 +3,7 @@ import org.bukkit.configuration.ConfigurationSection; public class dSinTransform implements Transform { + private Transform a; private Transform b; private Transform c; @@ -27,4 +28,5 @@ public double get(double t) { double bValue = b.get(t); return a.get(t) * bValue * Math.cos(bValue * (t + c.get(t))); } + } diff --git a/src/main/java/de/slikey/effectlib/particle/ReflectionHandler.java b/src/main/java/de/slikey/effectlib/particle/ReflectionHandler.java index d0c70483..c7c7d061 100644 --- a/src/main/java/de/slikey/effectlib/particle/ReflectionHandler.java +++ b/src/main/java/de/slikey/effectlib/particle/ReflectionHandler.java @@ -1,10 +1,12 @@ package de.slikey.effectlib.particle; -import java.lang.reflect.Constructor; +import java.util.Map; +import java.util.HashMap; + import java.lang.reflect.Field; import java.lang.reflect.Method; -import java.util.HashMap; -import java.util.Map; +import java.lang.reflect.Constructor; + import org.bukkit.Bukkit; // TODO: This is out of date, but still used by ParticlePacket @@ -286,7 +288,7 @@ public enum DataType { DOUBLE(double.class, Double.class), BOOLEAN(boolean.class, Boolean.class); - private static final Map, DataType> CLASS_MAP = new HashMap, DataType>(); + private static final Map, DataType> CLASS_MAP = new HashMap<>(); private final Class primitive; private final Class reference; @@ -343,9 +345,8 @@ public static Class[] convertToPrimitive(Object[] objects) { } public static boolean equalsArray(Class[] a1, Class[] a2) { - if (a1 == null || a2 == null || a1.length != a2.length) { - return false; - } + if (a1 == null || a2 == null || a1.length != a2.length) return false; + for (int i = 0; i < a1.length; i++) { if (!a1[i].equals(a2[i]) && !a1[i].isAssignableFrom(a2[i])) { return false; @@ -353,6 +354,7 @@ public static boolean equalsArray(Class[] a1, Class[] a2) { } return true; } + } /** @@ -378,6 +380,7 @@ public String getName() { public Object getValue() { return this.value; } + } /** @@ -405,6 +408,7 @@ public String getName() { public String toString() { return name; } + } /** @@ -448,6 +452,7 @@ public String getName() { public String toString() { return name; } + } /** @@ -589,6 +594,7 @@ public Class getPacket() throws Exception { } return packet; } + } } diff --git a/src/main/java/de/slikey/effectlib/util/BaseImageEffect.java b/src/main/java/de/slikey/effectlib/util/BaseImageEffect.java index 2557c91d..ddcfb0b2 100644 --- a/src/main/java/de/slikey/effectlib/util/BaseImageEffect.java +++ b/src/main/java/de/slikey/effectlib/util/BaseImageEffect.java @@ -120,8 +120,8 @@ public BaseImageEffect(EffectManager effectManager) { @Override public void reset() { - this.step = 0; - this.rotationStep = 0; + step = 0; + rotationStep = 0; } public void load(String fileName) { @@ -141,9 +141,8 @@ public void loadFile(File file) { @Override public void onRun() { - if (images == null && imageLoadCallback != null) { - return; - } + if (images == null && imageLoadCallback != null) return; + if (images == null && fileName != null) { load(fileName); return; @@ -159,9 +158,8 @@ public void onRun() { } stepDelay++; - if (step >= images.length) { - step = 0; - } + if (step >= images.length) step = 0; + BufferedImage image = images[step]; Location location = getLocation(); @@ -172,7 +170,7 @@ public void onRun() { VectorUtils.rotateVector(v, rotation.getX() * MathUtils.degreesToRadians, rotation.getY() * MathUtils.degreesToRadians, rotation.getZ() * MathUtils.degreesToRadians); } - if (orientPitch) VectorUtils.rotateAroundAxisX(v, Math.toRadians(location.getPitch())); + if (orientPitch) VectorUtils.rotateAroundAxisX(v, Math.toRadians(location.getPitch())); if (orient) VectorUtils.rotateAroundAxisY(v, -location.getYaw() * MathUtils.degreesToRadians); if (enableRotation) { @@ -211,9 +209,7 @@ public void onRun() { } int pixel = image.getRGB(x, y); - if (transparency && (pixel >> 24) == 0) { - continue; - } + if (transparency && (pixel >> 24) == 0) continue; display(image, v, location, pixel); } @@ -222,8 +218,7 @@ public void onRun() { } public enum Plane { - - X, Y, Z, XY, XZ, XYZ, YZ; + X, Y, Z, XY, XZ, XYZ, YZ } protected abstract void display(BufferedImage image, Vector v, Location location, int pixel); diff --git a/src/main/java/de/slikey/effectlib/util/ConfigUtils.java b/src/main/java/de/slikey/effectlib/util/ConfigUtils.java index 6dffffbc..b2e14f55 100644 --- a/src/main/java/de/slikey/effectlib/util/ConfigUtils.java +++ b/src/main/java/de/slikey/effectlib/util/ConfigUtils.java @@ -9,6 +9,7 @@ import org.bukkit.configuration.ConfigurationSection; public class ConfigUtils { + public static Collection getNodeList(ConfigurationSection node, String path) { Collection results = new ArrayList<>(); List> mapList = node.getMapList(path); @@ -62,7 +63,7 @@ public static void set(ConfigurationSection node, String path, Object value) { node.set(path, i); } catch (Exception ex) { try { - Double d; + double d; if (value instanceof Double) d = (Double) value; else if (value instanceof Float) d = (double) (Float) value; else d = Double.parseDouble(value.toString()); diff --git a/src/main/java/de/slikey/effectlib/util/ImageLoadCallback.java b/src/main/java/de/slikey/effectlib/util/ImageLoadCallback.java index 19b2f9a4..df4a997e 100644 --- a/src/main/java/de/slikey/effectlib/util/ImageLoadCallback.java +++ b/src/main/java/de/slikey/effectlib/util/ImageLoadCallback.java @@ -3,5 +3,7 @@ import java.awt.image.BufferedImage; public interface ImageLoadCallback { + void loaded(final BufferedImage[] images); + } diff --git a/src/main/java/de/slikey/effectlib/util/ImageLoadTask.java b/src/main/java/de/slikey/effectlib/util/ImageLoadTask.java index 15126b26..0077db7e 100644 --- a/src/main/java/de/slikey/effectlib/util/ImageLoadTask.java +++ b/src/main/java/de/slikey/effectlib/util/ImageLoadTask.java @@ -1,21 +1,22 @@ package de.slikey.effectlib.util; -import de.slikey.effectlib.EffectManager; - -import javax.imageio.ImageIO; -import javax.imageio.ImageReader; -import javax.imageio.stream.ImageInputStream; -import java.awt.image.BufferedImage; +import java.net.URL; import java.io.File; -import java.io.FileOutputStream; import java.io.InputStream; -import java.io.OutputStream; -import java.net.HttpURLConnection; -import java.net.URL; import java.net.URLEncoder; +import java.io.OutputStream; +import javax.imageio.ImageIO; import java.util.logging.Level; +import java.io.FileOutputStream; +import javax.imageio.ImageReader; +import java.net.HttpURLConnection; +import java.awt.image.BufferedImage; +import javax.imageio.stream.ImageInputStream; + +import de.slikey.effectlib.EffectManager; public class ImageLoadTask implements Runnable { + private static final int REQUEST_TIMEOUT = 30000; private static final int BUFFER_SIZE = 10 * 1024; private static boolean dirsMade = false; @@ -45,9 +46,7 @@ public void run() { if (!dirsMade) { dirsMade = true; - if (!cacheFolder.mkdirs()) { - effectManager.onError("Could not create cache folder: " + cacheFolder.getAbsolutePath()); - } + if (!cacheFolder.mkdirs()) effectManager.onError("Could not create cache folder: " + cacheFolder.getAbsolutePath()); } String cacheFileName = URLEncoder.encode(fileName, "UTF-8"); @@ -75,9 +74,7 @@ public void run() { } } else if (!fileName.startsWith(File.pathSeparator)) { imageFile = new File(effectManager.getOwningPlugin().getDataFolder(), fileName); - if (!imageFile.exists()) { - imageFile = new File(fileName); - } + if (!imageFile.exists()) imageFile = new File(fileName); } else { imageFile = new File(fileName); } @@ -108,4 +105,5 @@ public void run() { callback.loaded(images); } + } diff --git a/src/main/java/de/slikey/effectlib/util/MathUtils.java b/src/main/java/de/slikey/effectlib/util/MathUtils.java index 3f576aa6..29f1fbaf 100644 --- a/src/main/java/de/slikey/effectlib/util/MathUtils.java +++ b/src/main/java/de/slikey/effectlib/util/MathUtils.java @@ -149,9 +149,7 @@ static public final float atan2(float y, float x) { } float invDiv = 1 / ((x < y ? y : x) * INV_ATAN2_DIM_MINUS_1); - if (invDiv == Float.POSITIVE_INFINITY) { - return ((float) Math.atan2(y, x) + add) * mul; - } + if (invDiv == Float.POSITIVE_INFINITY) return ((float) Math.atan2(y, x) + add) * mul; int xi = (int) (x * invDiv); int yi = (int) (y * invDiv); @@ -215,9 +213,8 @@ static public final float random(float start, float end) { * Returns the next power of two. Returns the specified value if the value is already a power of two. */ static public int nextPowerOfTwo(int value) { - if (value == 0) { - return 1; - } + if (value == 0) return 1; + value--; value |= value >> 1; value |= value >> 2; @@ -233,32 +230,23 @@ static public boolean isPowerOfTwo(int value) { // --- static public int clamp(int value, int min, int max) { - if (value < min) { - return min; - } - if (value > max) { - return max; - } + if (value < min) return min; + if (value > max) return max; + return value; } static public short clamp(short value, short min, short max) { - if (value < min) { - return min; - } - if (value > max) { - return max; - } + if (value < min) return min; + if (value > max) return max; + return value; } static public float clamp(float value, float min, float max) { - if (value < min) { - return min; - } - if (value > max) { - return max; - } + if (value < min) return min; + if (value > max) return max; + return value; } @@ -361,4 +349,5 @@ static public boolean isEqual(float a, float b, float tolerance) { static public boolean isFinite(double value) { return !Double.isNaN(value) && !Double.isInfinite(value); } + } diff --git a/src/main/java/de/slikey/effectlib/util/ParticleEffect.java b/src/main/java/de/slikey/effectlib/util/ParticleEffect.java index e4b91a7e..c24c4bdc 100755 --- a/src/main/java/de/slikey/effectlib/util/ParticleEffect.java +++ b/src/main/java/de/slikey/effectlib/util/ParticleEffect.java @@ -1,16 +1,16 @@ package de.slikey.effectlib.util; +import java.util.Map; +import java.util.List; import java.util.Arrays; import java.util.HashMap; -import java.util.List; -import java.util.Map; import org.bukkit.Color; import org.bukkit.Location; import org.bukkit.Material; import org.bukkit.Particle; -import org.bukkit.entity.Player; import org.bukkit.util.Vector; +import org.bukkit.entity.Player; /** * ParticleEffect Enum @@ -506,7 +506,7 @@ public enum ParticleEffect { private final String name; private static ParticleDisplay display; - private static final Map NAME_MAP = new HashMap(); + private static final Map NAME_MAP = new HashMap<>(); // Initialize map for quick name and id lookup static { @@ -533,9 +533,7 @@ public enum ParticleEffect { */ public static ParticleEffect fromName(String name) { for (Map.Entry entry : NAME_MAP.entrySet()) { - if (!entry.getKey().equalsIgnoreCase(name)) { - continue; - } + if (!entry.getKey().equalsIgnoreCase(name)) continue; return entry.getValue(); } return null; @@ -564,9 +562,7 @@ public boolean isSupported() { * @throws ParticleVersionException If the particle effect is not supported by the server version */ public void display(float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center, double range, List targetPlayers) throws ParticleVersionException { - if (!isSupported()) { - throw new ParticleVersionException("The " + this + " particle effect is not supported by your server version."); - } + if (!isSupported()) throw new ParticleVersionException("The " + this + " particle effect is not supported by your server version."); display(particle, center, offsetX, offsetY, offsetZ, speed, amount, 1, null, null, (byte)0, range, targetPlayers); } @@ -588,9 +584,8 @@ public void display(float offsetX, float offsetY, float offsetZ, float speed, in * @throws ParticleVersionException If the particle effect is not supported by the server version */ public void display(float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center, List players) throws ParticleVersionException { - if (!isSupported()) { - throw new ParticleVersionException("The " + this + " particle effect is not supported by your server version."); - } + if (!isSupported()) throw new ParticleVersionException("The " + this + " particle effect is not supported by your server version."); + display(particle, center, offsetX, offsetY, offsetZ, speed, amount, 1, null, null, (byte)0, 0, players); } @@ -621,9 +616,7 @@ public void display(float offsetX, float offsetY, float offsetZ, float speed, in * @throws ParticleVersionException If the particle effect is not supported by the server version */ public void display(Vector direction, float speed, Location center, double range) throws ParticleVersionException { - if (!isSupported()) { - throw new ParticleVersionException("The " + this + " particle effect is not supported by your server version."); - } + if (!isSupported()) throw new ParticleVersionException("The " + this + " particle effect is not supported by your server version."); display(particle, center, (float)direction.getX(), (float)direction.getY(), (float)direction.getZ(), speed, 1, 1, null, null, (byte)0, range, null); @@ -639,9 +632,7 @@ public void display(Vector direction, float speed, Location center, double range * @throws ParticleVersionException If the particle effect is not supported by the server version */ public void display(Vector direction, float speed, Location center, List players) throws ParticleVersionException { - if (!isSupported()) { - throw new ParticleVersionException("The " + this + " particle effect is not supported by your server version."); - } + if (!isSupported()) throw new ParticleVersionException("The " + this + " particle effect is not supported by your server version."); display(particle, center, (float)direction.getX(), (float)direction.getY(), (float)direction.getZ(), speed, 1, 1, null, null, (byte)0, 0, players); @@ -676,9 +667,7 @@ public void display(Vector direction, float speed, Location center, Player... pl * @throws ParticleVersionException If the particle effect is not supported by the server version */ public void display(ParticleData data, float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center, double range, List targetPlayers) throws ParticleVersionException, ParticleDataException { - if (!isSupported()) { - throw new ParticleVersionException("The " + this + " particle effect is not supported by your server version."); - } + if (!isSupported()) throw new ParticleVersionException("The " + this + " particle effect is not supported by your server version."); Material material = null; byte materialData = 0; @@ -708,9 +697,7 @@ public void display(ParticleData data, float offsetX, float offsetY, float offse * @throws ParticleVersionException If the particle effect is not supported by the server version */ public void display(ParticleData data, float offsetX, float offsetY, float offsetZ, float speed, int amount, Location center, List players) throws ParticleVersionException, ParticleDataException { - if (!isSupported()) { - throw new ParticleVersionException("The " + this + " particle effect is not supported by your server version."); - } + if (!isSupported()) throw new ParticleVersionException("The " + this + " particle effect is not supported by your server version."); Material material = null; byte materialData = 0; @@ -749,9 +736,7 @@ public void display(ParticleData data, float offsetX, float offsetY, float offse * @throws ParticleVersionException If the particle effect is not supported by the server version */ public void display(ParticleData data, Vector direction, float speed, Location center, double range) throws ParticleVersionException, ParticleDataException { - if (!isSupported()) { - throw new ParticleVersionException("The " + this + " particle effect is not supported by your server version."); - } + if (!isSupported()) throw new ParticleVersionException("The " + this + " particle effect is not supported by your server version."); Material material = null; byte materialData = 0; @@ -774,9 +759,7 @@ public void display(ParticleData data, Vector direction, float speed, Location c * @throws ParticleVersionException If the particle effect is not supported by the server version */ public void display(ParticleData data, Vector direction, float speed, Location center, List players) throws ParticleVersionException, ParticleDataException { - if (!isSupported()) { - throw new ParticleVersionException("The " + this + " particle effect is not supported by your server version."); - } + if (!isSupported()) throw new ParticleVersionException("The " + this + " particle effect is not supported by your server version."); Material material = null; byte materialData = 0; @@ -864,6 +847,7 @@ public Material getMaterial() { public byte getData() { return data; } + } /** @@ -888,6 +872,7 @@ public static final class ItemData extends ParticleData { public ItemData(Material material, byte data) { super(material, data); } + } /** @@ -916,6 +901,7 @@ public BlockData(Material material, byte data) throws IllegalArgumentException { throw new IllegalArgumentException("The material is not a block"); } } + } /** @@ -939,6 +925,7 @@ private static final class ParticleDataException extends RuntimeException { public ParticleDataException(String message) { super(message); } + } /** @@ -962,5 +949,7 @@ private static final class ParticleVersionException extends RuntimeException { public ParticleVersionException(String message) { super(message); } + } + } diff --git a/src/main/java/de/slikey/effectlib/util/RandomUtils.java b/src/main/java/de/slikey/effectlib/util/RandomUtils.java index 43a57e64..c04ca4f3 100644 --- a/src/main/java/de/slikey/effectlib/util/RandomUtils.java +++ b/src/main/java/de/slikey/effectlib/util/RandomUtils.java @@ -1,6 +1,7 @@ package de.slikey.effectlib.util; import java.util.Random; + import org.bukkit.Material; import org.bukkit.util.Vector; diff --git a/src/main/java/de/slikey/effectlib/util/StringParser.java b/src/main/java/de/slikey/effectlib/util/StringParser.java index 62abde15..ad95657c 100644 --- a/src/main/java/de/slikey/effectlib/util/StringParser.java +++ b/src/main/java/de/slikey/effectlib/util/StringParser.java @@ -1,12 +1,12 @@ package de.slikey.effectlib.util; -import java.awt.Color; import java.awt.Font; -import java.awt.FontMetrics; +import java.awt.Color; import java.awt.Graphics; -import java.awt.font.FontRenderContext; +import java.awt.FontMetrics; import java.awt.geom.Rectangle2D; import java.awt.image.BufferedImage; +import java.awt.font.FontRenderContext; /** * Based on answer at StackOverflow diff --git a/src/main/java/de/slikey/effectlib/util/VectorUtils.java b/src/main/java/de/slikey/effectlib/util/VectorUtils.java index ef7adb60..91eb0cb6 100644 --- a/src/main/java/de/slikey/effectlib/util/VectorUtils.java +++ b/src/main/java/de/slikey/effectlib/util/VectorUtils.java @@ -103,4 +103,5 @@ public static final Vector rotateVector(Vector v, float yawDegrees, float pitchD public static final double angleToXAxis(Vector vector) { return Math.atan2(vector.getX(), vector.getY()); } + } From eb7e25335e40395c540c4098255798c44212c2cc Mon Sep 17 00:00:00 2001 From: Chronoken Date: Wed, 13 May 2020 10:58:04 +0200 Subject: [PATCH 17/44] HeartEffect now rotates properly --- .../de/slikey/effectlib/effect/HeartEffect.java | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/main/java/de/slikey/effectlib/effect/HeartEffect.java b/src/main/java/de/slikey/effectlib/effect/HeartEffect.java index 95ce39e3..baead65a 100644 --- a/src/main/java/de/slikey/effectlib/effect/HeartEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/HeartEffect.java @@ -58,18 +58,19 @@ public HeartEffect(EffectManager effectManager) { @Override public void onRun() { Location location = getLocation(); - Vector vector = new Vector(); + Vector v = new Vector(); for (int i = 0; i < particles; i++) { float alpha = ((MathUtils.PI / compilation) / particles) * i; double phi = Math.pow(Math.abs(MathUtils.sin(2 * compilation * alpha)) + factorInnerSpike * Math.abs(MathUtils.sin(compilation * alpha)), 1 / compressYFactorTotal); - vector.setY(phi * (MathUtils.sin(alpha) + MathUtils.cos(alpha)) * yFactor); - vector.setZ(phi * (MathUtils.cos(alpha) - MathUtils.sin(alpha)) * xFactor); + v.setY(phi * (MathUtils.sin(alpha) + MathUtils.cos(alpha)) * yFactor); + v.setZ(phi * (MathUtils.cos(alpha) - MathUtils.sin(alpha)) * xFactor); - VectorUtils.rotateVector(vector, xRotation, yRotation, zRotation); - - display(particle, location.add(vector)); - location.subtract(vector); + VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); + VectorUtils.rotateAroundAxisX(v, location.getPitch() * MathUtils.degreesToRadians); + VectorUtils.rotateAroundAxisY(v, -location.getYaw() * MathUtils.degreesToRadians); + display(particle, location.add(v)); + location.subtract(v); } } From 497266601291e86498a6c72311fa1c03a65f1341 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Wed, 13 May 2020 12:10:39 +0200 Subject: [PATCH 18/44] Revert HeartEffect fix --- src/main/java/de/slikey/effectlib/effect/HeartEffect.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/slikey/effectlib/effect/HeartEffect.java b/src/main/java/de/slikey/effectlib/effect/HeartEffect.java index baead65a..c8b87c81 100644 --- a/src/main/java/de/slikey/effectlib/effect/HeartEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/HeartEffect.java @@ -5,6 +5,7 @@ import org.bukkit.util.Vector; import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; import de.slikey.effectlib.EffectManager; import de.slikey.effectlib.util.MathUtils; import de.slikey.effectlib.util.VectorUtils; @@ -53,6 +54,9 @@ public class HeartEffect extends Effect { public HeartEffect(EffectManager effectManager) { super(effectManager); + type = EffectType.REPEATING; + iterations = 200; + period = 5; } @Override @@ -67,8 +71,6 @@ public void onRun() { v.setZ(phi * (MathUtils.cos(alpha) - MathUtils.sin(alpha)) * xFactor); VectorUtils.rotateVector(v, xRotation, yRotation, zRotation); - VectorUtils.rotateAroundAxisX(v, location.getPitch() * MathUtils.degreesToRadians); - VectorUtils.rotateAroundAxisY(v, -location.getYaw() * MathUtils.degreesToRadians); display(particle, location.add(v)); location.subtract(v); } From 9f5260a6dbf4e9c34da257a6908f5c9a2b16b169 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Sat, 26 Sep 2020 18:10:08 +0200 Subject: [PATCH 19/44] Added SquareEffect --- .../slikey/effectlib/effect/SquareEffect.java | 55 +++++++++++++++++++ .../effectlib/util/DynamicLocation.java | 12 ++++ .../de/slikey/effectlib/util/RandomUtils.java | 8 +++ 3 files changed, 75 insertions(+) create mode 100644 src/main/java/de/slikey/effectlib/effect/SquareEffect.java diff --git a/src/main/java/de/slikey/effectlib/effect/SquareEffect.java b/src/main/java/de/slikey/effectlib/effect/SquareEffect.java new file mode 100644 index 00000000..4864473a --- /dev/null +++ b/src/main/java/de/slikey/effectlib/effect/SquareEffect.java @@ -0,0 +1,55 @@ +package de.slikey.effectlib.effect; + +import org.bukkit.Particle; +import org.bukkit.Location; +import org.bukkit.util.Vector; + +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.RandomUtils; + +public class SquareEffect extends Effect { + + // Type of the spawned particles + public Particle particle = Particle.SPELL_MOB; + + // Radius of the square + public double radius = 0.6; + + // y-offset of the square + public double yOffset = 0; + + // Amount of particles to display + public int particles = 50; + + // Amount to increase the radius per tick + public double radiusIncrease = 0; + + // Amount to increase the particles per tick + public int particleIncrease = 0; + + public SquareEffect(EffectManager effectManager) { + super(effectManager); + type = EffectType.REPEATING; + iterations = 500; + period = 1; + } + + @Override + public void onRun() { + if (radiusIncrease != 0) radius += radiusIncrease; + if (particleIncrease != 0) particles += particleIncrease; + + Location location = getLocation(); + location.add(0, yOffset, 0); + for (int i = 0; i < particles; i++) { + Vector vector = RandomUtils.getRandomFlatVector().multiply(radius); + location.add(vector); + display(particle, location); + location.subtract(vector); + } + location.subtract(0, yOffset, 0); + } + +} diff --git a/src/main/java/de/slikey/effectlib/util/DynamicLocation.java b/src/main/java/de/slikey/effectlib/util/DynamicLocation.java index 42fdd4aa..6f2dd547 100644 --- a/src/main/java/de/slikey/effectlib/util/DynamicLocation.java +++ b/src/main/java/de/slikey/effectlib/util/DynamicLocation.java @@ -64,12 +64,24 @@ public void addOffset(Vector offset) { updateOffsets(); } + public void subtractOffset(Vector offset) { + if (this.offset == null) this.offset = offset.clone(); + else this.offset.subtract(offset); + updateOffsets(); + } + public void addRelativeOffset(Vector offset) { if (relativeOffset == null) relativeOffset = offset.clone(); else relativeOffset.add(offset); updateOffsets(); } + public void subtractRelativeOffset(Vector offset) { + if (relativeOffset == null) relativeOffset = offset.clone(); + else relativeOffset.subtract(offset); + updateOffsets(); + } + public Entity getEntity() { return entity == null ? null : entity.get(); } diff --git a/src/main/java/de/slikey/effectlib/util/RandomUtils.java b/src/main/java/de/slikey/effectlib/util/RandomUtils.java index c04ca4f3..b4dc790f 100644 --- a/src/main/java/de/slikey/effectlib/util/RandomUtils.java +++ b/src/main/java/de/slikey/effectlib/util/RandomUtils.java @@ -22,6 +22,14 @@ public static Vector getRandomVector() { return new Vector(x, y, z).normalize(); } + public static Vector getRandomFlatVector() { + double x, z; + x = random.nextDouble() * 2 - 1; + z = random.nextDouble() * 2 - 1; + + return new Vector(x, 0, z); + } + public static Vector getRandomCircleVector() { double rnd, x, z; rnd = random.nextDouble() * 2 * Math.PI; From b8f6091d4f9f7ed82339eca5a22c81c82d133517 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 6 Oct 2020 20:15:56 +0200 Subject: [PATCH 20/44] Added orient parameter to the AtomEffect --- src/main/java/de/slikey/effectlib/effect/AtomEffect.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/de/slikey/effectlib/effect/AtomEffect.java b/src/main/java/de/slikey/effectlib/effect/AtomEffect.java index 6ce1e57a..bbdbcf94 100644 --- a/src/main/java/de/slikey/effectlib/effect/AtomEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/AtomEffect.java @@ -60,6 +60,8 @@ public class AtomEffect extends Effect { */ public double angularVelocity = Math.PI / 80d; + public boolean orient = false; + /** * Internal counter */ @@ -82,6 +84,7 @@ public void onRun() { Location location = getLocation(); for (int i = 0; i < particlesNucleus; i++) { Vector v = RandomUtils.getRandomVector().multiply(radius * radiusNucleus); + if (orient) v = VectorUtils.rotateVector(v, location); location.add(v); display(particleNucleus, location, colorNucleus); location.subtract(v); @@ -94,6 +97,7 @@ public void onRun() { Vector v = new Vector(Math.cos(angle), Math.sin(angle), 0).multiply(radius); VectorUtils.rotateAroundAxisX(v, xRotation); VectorUtils.rotateAroundAxisY(v, rotation); + if (orient) v = VectorUtils.rotateVector(v, location); location.add(v); display(particleOrbital, location, colorOrbital); location.subtract(v); From 9ba31b18603cbb0462d3db1d3a5aced02da1688d Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 6 Oct 2020 20:22:39 +0200 Subject: [PATCH 21/44] Add probability parameter to all effects Add simple Particle effect, for repeating particle spawns --- src/main/java/de/slikey/effectlib/Effect.java | 10 ++++++- .../effectlib/effect/ParticleEffect.java | 28 +++++++++++++++++++ .../de/slikey/effectlib/util/RandomUtils.java | 4 +++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/slikey/effectlib/effect/ParticleEffect.java diff --git a/src/main/java/de/slikey/effectlib/Effect.java b/src/main/java/de/slikey/effectlib/Effect.java index e36c02c7..7818aa25 100644 --- a/src/main/java/de/slikey/effectlib/Effect.java +++ b/src/main/java/de/slikey/effectlib/Effect.java @@ -11,6 +11,7 @@ import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import de.slikey.effectlib.util.RandomUtils; import de.slikey.effectlib.util.DynamicLocation; public abstract class Effect implements Runnable { @@ -74,6 +75,11 @@ public abstract class Effect implements Runnable { */ public Integer duration = null; + /** + * Probability that this effect will play on each iteration + */ + public double probability = 1; + /** * Callback to run, after effect is done. * @@ -229,7 +235,9 @@ public final void run() { if (done) return; try { - onRun(); + if (RandomUtils.checkProbability(probability)) { + onRun(); + } } catch (Exception ex) { done(); effectManager.onError(ex); diff --git a/src/main/java/de/slikey/effectlib/effect/ParticleEffect.java b/src/main/java/de/slikey/effectlib/effect/ParticleEffect.java new file mode 100644 index 00000000..29d27150 --- /dev/null +++ b/src/main/java/de/slikey/effectlib/effect/ParticleEffect.java @@ -0,0 +1,28 @@ +package de.slikey.effectlib.effect; + +import org.bukkit.Particle; + +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; + +public class ParticleEffect extends Effect { + + /** + * ParticleType of spawned particle + */ + public Particle particle = Particle.VILLAGER_ANGRY; + + public ParticleEffect(EffectManager effectManager) { + super(effectManager); + type = EffectType.REPEATING; + period = 1; + iterations = 1; + } + + @Override + public void onRun() { + display(particle, getLocation()); + } + +} \ No newline at end of file diff --git a/src/main/java/de/slikey/effectlib/util/RandomUtils.java b/src/main/java/de/slikey/effectlib/util/RandomUtils.java index b4dc790f..affc724d 100644 --- a/src/main/java/de/slikey/effectlib/util/RandomUtils.java +++ b/src/main/java/de/slikey/effectlib/util/RandomUtils.java @@ -47,4 +47,8 @@ public static double getRandomAngle() { return random.nextDouble() * 2 * Math.PI; } + public static boolean checkProbability(double probability) { + return probability >= 1 || random.nextDouble() < probability; + } + } From 732d157de5b1ca66a9923f4bcd1cac00cbfb1ff5 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 6 Oct 2020 20:23:36 +0200 Subject: [PATCH 22/44] Bump version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 83d70da3..8537db9a 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 de.slikey EffectLib - 6.2-SNAPSHOT + 6.4 EffectLib http://www.kevin-carstens.de/ From 77b33f55620d13fe77b34553e3de280b692710a2 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 6 Oct 2020 20:31:13 +0200 Subject: [PATCH 23/44] Added SoundEffect --- .../de/slikey/effectlib/EffectManager.java | 16 +- .../slikey/effectlib/effect/SoundEffect.java | 28 ++ .../de/slikey/effectlib/util/CustomSound.java | 272 ++++++++++++++++++ 3 files changed, 309 insertions(+), 7 deletions(-) create mode 100644 src/main/java/de/slikey/effectlib/effect/SoundEffect.java create mode 100644 src/main/java/de/slikey/effectlib/util/CustomSound.java diff --git a/src/main/java/de/slikey/effectlib/EffectManager.java b/src/main/java/de/slikey/effectlib/EffectManager.java index 3ce79638..71f1fe02 100644 --- a/src/main/java/de/slikey/effectlib/EffectManager.java +++ b/src/main/java/de/slikey/effectlib/EffectManager.java @@ -14,13 +14,6 @@ import java.awt.image.BufferedImage; import java.lang.reflect.Constructor; -import de.slikey.effectlib.util.Disposable; -import de.slikey.effectlib.util.ConfigUtils; -import de.slikey.effectlib.util.ImageLoadTask; -import de.slikey.effectlib.util.ParticleDisplay; -import de.slikey.effectlib.util.DynamicLocation; -import de.slikey.effectlib.util.ImageLoadCallback; - import org.bukkit.Color; import org.bukkit.Bukkit; import org.bukkit.Location; @@ -37,6 +30,8 @@ import com.google.common.base.CaseFormat; +import de.slikey.effectlib.util.*; + /** * Dispose the EffectManager if you don't need him anymore. * @@ -424,6 +419,13 @@ protected boolean setField(Object effect, String key, ConfigurationSection secti } catch (Exception ex) { onError(ex); } + } else if (field.getType().equals(CustomSound.class)) { + try { + String value = fieldSection.getString(fieldKey); + field.set(effect, new CustomSound(value)); + } catch (Exception ex) { + onError(ex); + } } else { return false; } diff --git a/src/main/java/de/slikey/effectlib/effect/SoundEffect.java b/src/main/java/de/slikey/effectlib/effect/SoundEffect.java new file mode 100644 index 00000000..5e0f2389 --- /dev/null +++ b/src/main/java/de/slikey/effectlib/effect/SoundEffect.java @@ -0,0 +1,28 @@ +package de.slikey.effectlib.effect; + +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.CustomSound; + +public class SoundEffect extends Effect { + + /** + * Sound effect to play + */ + public CustomSound sound; + + public SoundEffect(EffectManager effectManager) { + super(effectManager); + type = EffectType.REPEATING; + period = 1; + iterations = 1; + } + + @Override + public void onRun() { + if (sound == null) return; + sound.play(effectManager.getOwningPlugin(), getLocation()); + } + +} diff --git a/src/main/java/de/slikey/effectlib/util/CustomSound.java b/src/main/java/de/slikey/effectlib/util/CustomSound.java new file mode 100644 index 00000000..770308cf --- /dev/null +++ b/src/main/java/de/slikey/effectlib/util/CustomSound.java @@ -0,0 +1,272 @@ +package de.slikey.effectlib.util; + +import java.util.Collection; +import java.util.logging.Level; +import java.lang.reflect.Method; + +import org.bukkit.Sound; +import org.bukkit.Location; +import org.bukkit.entity.Entity; +import org.bukkit.entity.Player; +import org.bukkit.plugin.Plugin; + +import org.apache.commons.lang.StringUtils; + +public class CustomSound { + + private static boolean initializedReflection; + + private static Method player_playCustomSoundMethod; + private static Method player_stopSoundMethod; + private static Method player_stopCustomSoundMethod; + + private Sound sound; + private String customSound; + private float volume = 1.0f; + private float pitch = 1.0f; + private int range = 0; + + public CustomSound(Sound sound) { + this.sound = sound; + customSound = null; + } + + public CustomSound(String key) { + if (key != null && key.length() > 0) { + String[] pieces = StringUtils.split(key, ','); + String soundName = pieces[0]; + + if (soundName.indexOf('.') < 0) { + try { + sound = Sound.valueOf(soundName.toUpperCase()); + } catch (Exception ex) { + sound = null; + customSound = soundName; + } + } else { + customSound = soundName; + } + + if (pieces.length > 1) { + try { + volume = Float.parseFloat(pieces[1]); + } catch (Exception ex) { + volume = 1; + } + } + + if (pieces.length > 2) { + try { + pitch = Float.parseFloat(pieces[2]); + } catch (Exception ex) { + pitch = 1; + } + } + + if (pieces.length > 3) { + try { + range = Integer.parseInt(pieces[3]); + } catch (Exception ex) { + range = 0; + } + } + } + } + + public void stop(Player player) { + if (sound != null) stopSound(null, player, sound); + if (customSound != null && !customSound.isEmpty()) stopSound(null, player, customSound); + } + + public boolean isCustom() { + return sound == null; + } + + public String getCustomSound() { + return customSound; + } + + public Sound getSound() { + return sound; + } + + public float getVolume() { + return volume; + } + + public float getPitch() { + return pitch; + } + + public void setVolume(float volume) { + this.volume = volume; + } + + public void setPitch(float pitch) { + this.pitch = pitch; + } + + public String toString() { + String soundName = sound == null ? customSound : sound.name(); + if (soundName == null) return ""; + return soundName + "," + volume + "," + pitch + "," + range; + } + + public int hashCode() { + return (sound == null ? 0 : sound.hashCode()) + + 31 * (Float.floatToIntBits(pitch) + + 31 * Float.floatToIntBits(volume)); + } + + public boolean equals(Object other) { + if (!(other instanceof CustomSound)) return false; + + CustomSound otherEffect = (CustomSound)other; + return sound != otherEffect.sound || pitch != otherEffect.pitch || volume != otherEffect.volume; + } + + public int getRange() { + return range; + } + + public void play(Plugin plugin, Location sourceLocation) { + if (sourceLocation == null || plugin == null) return; + + if (customSound != null) { + try { + int range = this.range; + if (range <= 0) { + range = (int) (volume > 1.0 ? (16.0 * volume) : 16.0); + } + int rangeSquared = range * range; + Collection players = plugin.getServer().getOnlinePlayers(); + for (Player player : players) { + Location location = player.getLocation(); + if (location.getWorld().equals(sourceLocation.getWorld()) && location.distanceSquared(sourceLocation) <= rangeSquared) { + // player.playSound(sourceLocation, customSound, volume, pitch); + playCustomSound(plugin, player, sourceLocation, customSound, volume, pitch); + } + } + } catch (Exception ex) { + plugin.getLogger().warning("Failed to play custom sound: " + customSound); + } + } + + if (sound != null) { + try { + sourceLocation.getWorld().playSound(sourceLocation, sound, volume, pitch); + } catch (Exception ex) { + plugin.getLogger().warning("Failed to play sound: " + sound); + } + } + } + + public void play(Plugin plugin, Entity entity) { + if (entity == null || plugin == null) return; + + Location sourceLocation = entity.getLocation(); + if (customSound != null) { + try { + if (range > 0) { + int rangeSquared = range * range; + Collection players = plugin.getServer().getOnlinePlayers(); + for (Player player : players) { + Location location = player.getLocation(); + if (location.getWorld().equals(sourceLocation.getWorld()) && location.distanceSquared(sourceLocation) <= rangeSquared) { + // player.playSound(sourceLocation, customSound, volume, pitch); + playCustomSound(plugin, player, sourceLocation, customSound, volume, pitch); + } + } + } else if (entity instanceof Player) { + Player player = (Player)entity; + // player.playSound(sourceLocation, customSound, volume, pitch); + playCustomSound(plugin, player, sourceLocation, customSound, volume, pitch); + + } + } catch (Exception ex) { + plugin.getLogger().warning("Failed to play custom sound: " + customSound); + } + } + + if (sound != null) { + try { + if (entity instanceof Player && range <= 0) { + Player player = (Player)entity; + player.playSound(sourceLocation, sound, volume, pitch); + } else if (range > 0) { + sourceLocation.getWorld().playSound(sourceLocation, sound, volume, pitch); + } + } catch (Exception ex) { + plugin.getLogger().warning("Failed to play sound: " + sound); + } + } + } + + public void setRange(int range) { + this.range = range; + } + + private static void initializeReflection(Plugin plugin) { + if (!initializedReflection) { + initializedReflection = true; + try { + player_playCustomSoundMethod = Player.class.getMethod("playSound", Location.class, String.class, Float.TYPE, Float.TYPE); + } catch (Exception ex) { + if (plugin != null) { + plugin.getLogger().warning("Failed to bind to custom sound method"); + } + } + try { + player_stopCustomSoundMethod = Player.class.getMethod("stopSound", String.class); + } catch (Exception ex) { + if (plugin != null) { + plugin.getLogger().warning("Failed to bind to stop custom sound method"); + } + } + try { + player_stopSoundMethod = Player.class.getMethod("stopSound", Sound.class); + } catch (Exception ex) { + if (plugin != null) { + plugin.getLogger().warning("Failed to bind to stop sound method"); + } + } + } + } + + public static void stopSound(Plugin plugin, Player player, String sound) { + initializeReflection(plugin); + if (player_stopCustomSoundMethod == null) return; + try { + player_stopCustomSoundMethod.invoke(player, sound); + } catch (Exception ex) { + if (plugin != null) { + plugin.getLogger().log(Level.WARNING, "Failed to stop custom sound: " + sound, ex); + } + } + } + + public static void stopSound(Plugin plugin, Player player, Sound sound) { + initializeReflection(plugin); + if (player_stopSoundMethod == null) return; + try { + player_stopSoundMethod.invoke(player, sound); + } catch (Exception ex) { + if (plugin != null) { + plugin.getLogger().log(Level.WARNING, "Failed to stop sound: " + sound, ex); + } + } + } + + public static void playCustomSound(Plugin plugin, Player player, Location location, String sound, float volume, float pitch) { + initializeReflection(plugin); + if (player_playCustomSoundMethod == null) return; + try { + player_playCustomSoundMethod.invoke(player, location, sound, volume, pitch); + } catch (Exception ex) { + if (plugin != null) { + plugin.getLogger().log(Level.WARNING, "Failed to play custom sound: " + sound, ex); + } + } + } + +} From d41f576c1857345dd7a1b463dcc080aacd9ea792 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 6 Oct 2020 20:32:54 +0200 Subject: [PATCH 24/44] Get rid of ReflectionHandler --- .../effectlib/particle/ReflectionHandler.java | 600 ------------------ 1 file changed, 600 deletions(-) delete mode 100644 src/main/java/de/slikey/effectlib/particle/ReflectionHandler.java diff --git a/src/main/java/de/slikey/effectlib/particle/ReflectionHandler.java b/src/main/java/de/slikey/effectlib/particle/ReflectionHandler.java deleted file mode 100644 index c7c7d061..00000000 --- a/src/main/java/de/slikey/effectlib/particle/ReflectionHandler.java +++ /dev/null @@ -1,600 +0,0 @@ -package de.slikey.effectlib.particle; - -import java.util.Map; -import java.util.HashMap; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.lang.reflect.Constructor; - -import org.bukkit.Bukkit; - -// TODO: This is out of date, but still used by ParticlePacket -// Since this looked experimental I didn't want to mess with it. -// If ParticlePacket doesn't work out, this file could be removed as it -// has been replaced by ReflectionUtils. -/** - * ReflectionHandler v1.0 - * - * This class makes dealing with reflection much easier, especially when working - * with Bukkit - * - * You are welcome to use it, modify it and redistribute it under the following - * conditions: 1. Don't claim this class as your own 2. Don't remove this text - * - * (Would be nice if you provide credit to me) - * - * @author DarkBlade12 - */ -public final class ReflectionHandler { - - private ReflectionHandler() { - } - - public static Class getClass(String name, PackageType type) throws Exception { - return Class.forName(type + "." + name); - } - - public static Class getClass(String name, SubPackageType type) throws Exception { - return Class.forName(type + "." + name); - } - - public static Constructor getConstructor(Class clazz, Class... parameterTypes) { - Class[] p = DataType.convertToPrimitive(parameterTypes); - for (Constructor c : clazz.getConstructors()) { - if (DataType.equalsArray(DataType.convertToPrimitive(c.getParameterTypes()), p)) { - return c; - } - } - return null; - } - - public static Constructor getConstructor(String className, PackageType type, Class... parameterTypes) throws Exception { - return getConstructor(getClass(className, type), parameterTypes); - } - - public static Constructor getConstructor(String className, SubPackageType type, Class... parameterTypes) throws Exception { - return getConstructor(getClass(className, type), parameterTypes); - } - - public static Object newInstance(Class clazz, Object... args) throws Exception { - return getConstructor(clazz, DataType.convertToPrimitive(args)).newInstance(args); - } - - public static Object newInstance(String className, PackageType type, Object... args) throws Exception { - return newInstance(getClass(className, type), args); - } - - public static Object newInstance(String className, SubPackageType type, Object... args) throws Exception { - return newInstance(getClass(className, type), args); - } - - public static Method getMethod(Class clazz, String name, Class... parameterTypes) { - Class[] p = DataType.convertToPrimitive(parameterTypes); - for (Method m : clazz.getMethods()) { - if (m.getName().equals(name) && DataType.equalsArray(DataType.convertToPrimitive(m.getParameterTypes()), p)) { - return m; - } - } - return null; - } - - public static Method getMethod(String className, PackageType type, String name, Class... parameterTypes) throws Exception { - return getMethod(getClass(className, type), name, parameterTypes); - } - - public static Method getMethod(String className, SubPackageType type, String name, Class... parameterTypes) throws Exception { - return getMethod(getClass(className, type), name, parameterTypes); - } - - public static Object invokeMethod(String name, Object instance, Object... args) throws Exception { - return getMethod(instance.getClass(), name, DataType.convertToPrimitive(args)).invoke(instance, args); - } - - public static Object invokeMethod(Class clazz, String name, Object instance, Object... args) throws Exception { - return getMethod(clazz, name, DataType.convertToPrimitive(args)).invoke(instance, args); - } - - public static Object invokeMethod(String className, PackageType type, String name, Object instance, Object... args) throws Exception { - return invokeMethod(getClass(className, type), name, instance, args); - } - - public static Object invokeMethod(String className, SubPackageType type, String name, Object instance, Object... args) throws Exception { - return invokeMethod(getClass(className, type), name, instance, args); - } - - public static Field getField(Class clazz, String name) throws Exception { - Field f = clazz.getField(name); - f.setAccessible(true); - return f; - } - - public static Field getField(String className, PackageType type, String name) throws Exception { - return getField(getClass(className, type), name); - } - - public static Field getField(String className, SubPackageType type, String name) throws Exception { - return getField(getClass(className, type), name); - } - - public static Field getDeclaredField(Class clazz, String name) throws Exception { - Field f = clazz.getDeclaredField(name); - f.setAccessible(true); - return f; - } - - public static Field getDeclaredField(String className, PackageType type, String name) throws Exception { - return getDeclaredField(getClass(className, type), name); - } - - public static Field getDeclaredField(String className, SubPackageType type, String name) throws Exception { - return getDeclaredField(getClass(className, type), name); - } - - public static Object getValue(Object instance, String fieldName) throws Exception { - return getField(instance.getClass(), fieldName).get(instance); - } - - public static Object getValue(Class clazz, Object instance, String fieldName) throws Exception { - return getField(clazz, fieldName).get(instance); - } - - public static Object getValue(String className, PackageType type, Object instance, String fieldName) throws Exception { - return getValue(getClass(className, type), instance, fieldName); - } - - public static Object getValue(String className, SubPackageType type, Object instance, String fieldName) throws Exception { - return getValue(getClass(className, type), instance, fieldName); - } - - public static Object getDeclaredValue(Object instance, String fieldName) throws Exception { - return getDeclaredField(instance.getClass(), fieldName).get(instance); - } - - public static Object getDeclaredValue(Class clazz, Object instance, String fieldName) throws Exception { - return getDeclaredField(clazz, fieldName).get(instance); - } - - public static Object getDeclaredValue(String className, PackageType type, Object instance, String fieldName) throws Exception { - return getDeclaredValue(getClass(className, type), instance, fieldName); - } - - public static Object getDeclaredValue(String className, SubPackageType type, Object instance, String fieldName) throws Exception { - return getDeclaredValue(getClass(className, type), instance, fieldName); - } - - public static void setValue(Object instance, String fieldName, Object fieldValue) throws Exception { - Field f = getField(instance.getClass(), fieldName); - f.set(instance, fieldValue); - } - - public static void setValue(Object instance, FieldPair pair) throws Exception { - setValue(instance, pair.getName(), pair.getValue()); - } - - public static void setValue(Class clazz, Object instance, String fieldName, Object fieldValue) throws Exception { - Field f = getField(clazz, fieldName); - f.set(instance, fieldValue); - } - - public static void setValue(Class clazz, Object instance, FieldPair pair) throws Exception { - setValue(clazz, instance, pair.getName(), pair.getValue()); - } - - public static void setValue(String className, PackageType type, Object instance, String fieldName, Object fieldValue) throws Exception { - setValue(getClass(className, type), instance, fieldName, fieldValue); - } - - public static void setValue(String className, PackageType type, Object instance, FieldPair pair) throws Exception { - setValue(className, type, instance, pair.getName(), pair.getValue()); - } - - public static void setValue(String className, SubPackageType type, Object instance, String fieldName, Object fieldValue) throws Exception { - setValue(getClass(className, type), instance, fieldName, fieldValue); - } - - public static void setValue(String className, SubPackageType type, Object instance, FieldPair pair) throws Exception { - setValue(className, type, instance, pair.getName(), pair.getValue()); - } - - public static void setValues(Object instance, FieldPair... pairs) throws Exception { - for (FieldPair pair : pairs) { - setValue(instance, pair); - } - } - - public static void setValues(Class clazz, Object instance, FieldPair... pairs) throws Exception { - for (FieldPair pair : pairs) { - setValue(clazz, instance, pair); - } - } - - public static void setValues(String className, PackageType type, Object instance, FieldPair... pairs) throws Exception { - setValues(getClass(className, type), instance, pairs); - } - - public static void setValues(String className, SubPackageType type, Object instance, FieldPair... pairs) throws Exception { - setValues(getClass(className, type), instance, pairs); - } - - public static void setDeclaredValue(Object instance, String fieldName, Object fieldValue) throws Exception { - Field f = getDeclaredField(instance.getClass(), fieldName); - f.set(instance, fieldValue); - } - - public static void setDeclaredValue(Object instance, FieldPair pair) throws Exception { - setDeclaredValue(instance, pair.getName(), pair.getValue()); - } - - public static void setDeclaredValue(Class clazz, Object instance, String fieldName, Object fieldValue) throws Exception { - Field f = getDeclaredField(clazz, fieldName); - f.set(instance, fieldValue); - } - - public static void setDeclaredValue(Class clazz, Object instance, FieldPair pair) throws Exception { - setDeclaredValue(clazz, instance, pair.getName(), pair.getValue()); - } - - public static void setDeclaredValue(String className, PackageType type, Object instance, String fieldName, Object fieldValue) throws Exception { - setDeclaredValue(getClass(className, type), instance, fieldName, fieldValue); - } - - public static void setDeclaredValue(String className, PackageType type, Object instance, FieldPair pair) throws Exception { - setDeclaredValue(className, type, instance, pair.getName(), pair.getValue()); - } - - public static void setDeclaredValue(String className, SubPackageType type, Object instance, String fieldName, Object fieldValue) throws Exception { - setDeclaredValue(getClass(className, type), instance, fieldName, fieldValue); - } - - public static void setDeclaredValue(String className, SubPackageType type, Object instance, FieldPair pair) throws Exception { - setDeclaredValue(className, type, instance, pair.getName(), pair.getValue()); - } - - public static void setDeclaredValues(Object instance, FieldPair... pairs) throws Exception { - for (FieldPair pair : pairs) { - setDeclaredValue(instance, pair); - } - } - - public static void setDeclaredValues(Class clazz, Object instance, FieldPair... pairs) throws Exception { - for (FieldPair pair : pairs) { - setDeclaredValue(clazz, instance, pair); - } - } - - public static void setDeclaredValues(String className, PackageType type, Object instance, FieldPair... pairs) throws Exception { - setDeclaredValues(getClass(className, type), instance, pairs); - } - - public static void setDeclaredValues(String className, SubPackageType type, Object instance, FieldPair... pairs) throws Exception { - setDeclaredValues(getClass(className, type), instance, pairs); - } - - /** - * This class is part of the ReflectionHandler and follows the same usage - * conditions - * - * @author DarkBlade12 - */ - public enum DataType { - - BYTE(byte.class, Byte.class), - SHORT(short.class, Short.class), - INTEGER(int.class, Integer.class), - LONG(long.class, Long.class), - CHARACTER(char.class, Character.class), - FLOAT(float.class, Float.class), - DOUBLE(double.class, Double.class), - BOOLEAN(boolean.class, Boolean.class); - - private static final Map, DataType> CLASS_MAP = new HashMap<>(); - private final Class primitive; - private final Class reference; - - static { - for (DataType t : values()) { - CLASS_MAP.put(t.primitive, t); - CLASS_MAP.put(t.reference, t); - } - } - - private DataType(Class primitive, Class reference) { - this.primitive = primitive; - this.reference = reference; - } - - public Class getPrimitive() { - return this.primitive; - } - - public Class getReference() { - return this.reference; - } - - public static DataType fromClass(Class c) { - return CLASS_MAP.get(c); - } - - public static Class getPrimitive(Class c) { - DataType t = fromClass(c); - return t == null ? c : t.getPrimitive(); - } - - public static Class getReference(Class c) { - DataType t = fromClass(c); - return t == null ? c : t.getReference(); - } - - public static Class[] convertToPrimitive(Class[] classes) { - int length = classes == null ? 0 : classes.length; - Class[] types = new Class[length]; - for (int i = 0; i < length; i++) { - types[i] = getPrimitive(classes[i]); - } - return types; - } - - public static Class[] convertToPrimitive(Object[] objects) { - int length = objects == null ? 0 : objects.length; - Class[] types = new Class[length]; - for (int i = 0; i < length; i++) { - types[i] = getPrimitive(objects[i].getClass()); - } - return types; - } - - public static boolean equalsArray(Class[] a1, Class[] a2) { - if (a1 == null || a2 == null || a1.length != a2.length) return false; - - for (int i = 0; i < a1.length; i++) { - if (!a1[i].equals(a2[i]) && !a1[i].isAssignableFrom(a2[i])) { - return false; - } - } - return true; - } - - } - - /** - * This class is part of the ReflectionHandler and follows the same usage - * conditions - * - * @author DarkBlade12 - */ - public final static class FieldPair { - - private final String name; - private final Object value; - - public FieldPair(String name, Object value) { - this.name = name; - this.value = value; - } - - public String getName() { - return this.name; - } - - public Object getValue() { - return this.value; - } - - } - - /** - * This class is part of the ReflectionHandler and follows the same usage - * conditions - * - * @author DarkBlade12 - */ - public enum PackageType { - - MINECRAFT_SERVER("net.minecraft.server." + Bukkit.getServer().getClass().getPackage().getName().substring(23)), - CRAFTBUKKIT(Bukkit.getServer().getClass().getPackage().getName()); - - private final String name; - - private PackageType(String name) { - this.name = name; - } - - public String getName() { - return this.name; - } - - @Override - public String toString() { - return name; - } - - } - - /** - * This class is part of the ReflectionHandler and follows the same usage - * conditions - * - * @author DarkBlade12 - */ - public enum SubPackageType { - - BLOCK, - CHUNKIO, - COMMAND, - CONVERSATIONS, - ENCHANTMENS, - ENTITY, - EVENT, - GENERATOR, - HELP, - INVENTORY, - MAP, - METADATA, - POTION, - PROJECTILES, - SCHEDULER, - SCOREBOARD, - UPDATER, - UTIL; - - private final String name; - - private SubPackageType() { - name = PackageType.CRAFTBUKKIT + "." + name().toLowerCase(); - } - - public String getName() { - return this.name; - } - - @Override - public String toString() { - return name; - } - - } - - /** - * This class is part of the ReflectionHandler and follows the same usage - * conditions - * - * @author DarkBlade12 - */ - public enum PacketType { - - HANDSHAKING_IN_SET_PROTOCOL("PacketHandshakingInSetProtocol"), - LOGIN_IN_ENCRYPTION_BEGIN("PacketLoginInEncryptionBegin"), - LOGIN_IN_START("PacketLoginInStart"), - LOGIN_OUT_DISCONNECT("PacketLoginOutDisconnect"), - LOGIN_OUT_ENCRYPTION_BEGIN("PacketLoginOutEncryptionBegin"), - LOGIN_OUT_SUCCESS("PacketLoginOutSuccess"), - PLAY_IN_ABILITIES("PacketPlayInAbilities"), - PLAY_IN_ARM_ANIMATION("PacketPlayInArmAnimation"), - PLAY_IN_BLOCK_DIG("PacketPlayInBlockDig"), - PLAY_IN_BLOCK_PLACE("PacketPlayInBlockPlace"), - PLAY_IN_CHAT("PacketPlayInChat"), - PLAY_IN_CLIENT_COMMAND("PacketPlayInClientCommand"), - PLAY_IN_CLOSE_WINDOW("PacketPlayInCloseWindow"), - PLAY_IN_CUSTOM_PAYLOAD("PacketPlayInCustomPayload"), - PLAY_IN_ENCHANT_ITEM("PacketPlayInEnchantItem"), - PLAY_IN_ENTITY_ACTION("PacketPlayInEntityAction"), - PLAY_IN_FLYING("PacketPlayInFlying"), - PLAY_IN_HELD_ITEM_SLOT("PacketPlayInHeldItemSlot"), - PLAY_IN_KEEP_ALIVE("PacketPlayInKeepAlive"), - PLAY_IN_LOOK("PacketPlayInLook"), - PLAY_IN_POSITION("PacketPlayInPosition"), - PLAY_IN_POSITION_LOOK("PacketPlayInPositionLook"), - PLAY_IN_SET_CREATIVE_SLOT("PacketPlayInSetCreativeSlot "), - PLAY_IN_SETTINGS("PacketPlayInSettings"), - PLAY_IN_STEER_VEHICLE("PacketPlayInSteerVehicle"), - PLAY_IN_TAB_COMPLETE("PacketPlayInTabComplete"), - PLAY_IN_TRANSACTION("PacketPlayInTransaction"), - PLAY_IN_UPDATE_SIGN("PacketPlayInUpdateSign"), - PLAY_IN_USE_ENTITY("PacketPlayInUseEntity"), - PLAY_IN_WINDOW_CLICK("PacketPlayInWindowClick"), - PLAY_OUT_ABILITIES("PacketPlayOutAbilities"), - PLAY_OUT_ANIMATION("PacketPlayOutAnimation"), - PLAY_OUT_ATTACH_ENTITY("PacketPlayOutAttachEntity"), - PLAY_OUT_BED("PacketPlayOutBed"), - PLAY_OUT_BLOCK_ACTION("PacketPlayOutBlockAction"), - PLAY_OUT_BLOCK_BREAK_ANIMATION("PacketPlayOutBlockBreakAnimation"), - PLAY_OUT_BLOCK_CHANGE("PacketPlayOutBlockChange"), - PLAY_OUT_CHAT("PacketPlayOutChat"), - PLAY_OUT_CLOSE_WINDOW("PacketPlayOutCloseWindow"), - PLAY_OUT_COLLECT("PacketPlayOutCollect"), - PLAY_OUT_CRAFT_PROGRESS_BAR("PacketPlayOutCraftProgressBar"), - PLAY_OUT_CUSTOM_PAYLOAD("PacketPlayOutCustomPayload"), - PLAY_OUT_ENTITY("PacketPlayOutEntity"), - PLAY_OUT_ENTITY_DESTROY("PacketPlayOutEntityDestroy"), - PLAY_OUT_ENTITY_EFFECT("PacketPlayOutEntityEffect"), - PLAY_OUT_ENTITY_EQUIPMENT("PacketPlayOutEntityEquipment"), - PLAY_OUT_ENTITY_HEAD_ROTATION("PacketPlayOutEntityHeadRotation"), - PLAY_OUT_ENTITY_LOOK("PacketPlayOutEntityLook"), - PLAY_OUT_ENTITY_METADATA("PacketPlayOutEntityMetadata"), - PLAY_OUT_ENTITY_STATUS("PacketPlayOutEntityStatus"), - PLAY_OUT_ENTITY_TELEPORT("PacketPlayOutEntityTeleport"), - PLAY_OUT_ENTITY_VELOCITY("PacketPlayOutEntityVelocity"), - PLAY_OUT_EXPERIENCE("PacketPlayOutExperience"), - PLAY_OUT_EXPLOSION("PacketPlayOutExplosion"), - PLAY_OUT_GAME_STATE_CHANGE("PacketPlayOutGameStateChange"), - PLAY_OUT_HELD_ITEM_SLOT("PacketPlayOutHeldItemSlot"), - PLAY_OUT_KEEP_ALIVE("PacketPlayOutKeepAlive"), - PLAY_OUT_KICK_DISCONNECT("PacketPlayOutKickDisconnect"), - PLAY_OUT_LOGIN("PacketPlayOutLogin"), - PLAY_OUT_MAP("PacketPlayOutMap"), - PLAY_OUT_MAP_CHUNK("PacketPlayOutMapChunk"), - PLAY_OUT_MAP_CHUNK_BULK("PacketPlayOutMapChunkBulk"), - PLAY_OUT_MULTI_BLOCK_CHANGE("PacketPlayOutMultiBlockChange"), - PLAY_OUT_NAMED_ENTITY_SPAWN("PacketPlayOutNamedEntitySpawn"), - PLAY_OUT_NAMED_SOUND_EFFECT("PacketPlayOutNamedSoundEffect"), - PLAY_OUT_OPEN_SIGN_EDITOR("PacketPlayOutOpenSignEditor"), - PLAY_OUT_OPEN_WINDOW("PacketPlayOutOpenWindow"), - PLAY_OUT_PLAYER_INFO("PacketPlayOutPlayerInfo"), - PLAY_OUT_POSITION("PacketPlayOutPosition"), - PLAY_OUT_REL_ENTITY_MOVE("PacketPlayOutRelEntityMove"), - PLAY_OUT_REL_ENTITY_MOVE_LOOK("PacketPlayOutRelEntityMoveLook"), - PLAY_OUT_REMOVE_ENTITY_EFFECT("PacketPlayOutRemoveEntityEffect"), - PLAY_OUT_RESPAWN("PacketPlayOutRespawn"), - PLAY_OUT_SCOREBOARD_DISPLAY_OBJECTIVE("PacketPlayOutScoreboardDisplayObjective"), - PLAY_OUT_SCOREBOARD_OBJECTIVE("PacketPlayOutScoreboardObjective"), - PLAY_OUT_SCOREBOARD_SCORE("PacketPlayOutScoreboardScore"), - PLAY_OUT_SCOREBOARD_TEAM("PacketPlayOutScoreboardTeam"), - PLAY_OUT_SET_SLOT("PacketPlayOutSetSlot"), - PLAY_OUT_SPAWN_ENTITY("PacketPlayOutSpawnEntity"), - PLAY_OUT_SPAWN_ENTITY_EXPERIENCE_ORB("PacketPlayOutSpawnEntityExperienceOrb"), - PLAY_OUT_SPAWN_ENTITY_LIVING("PacketPlayOutSpawnEntityLiving"), - PLAY_OUT_SPAWN_ENTITY_PAINTING("PacketPlayOutSpawnEntityPainting"), - PLAY_OUT_SPAWN_ENTITY_WEATHER("PacketPlayOutSpawnEntityWeather"), - PLAY_OUT_SPAWN_POSITION("PacketPlayOutSpawnPosition"), - PLAY_OUT_STATISTIC("PacketPlayOutStatistic"), - PLAY_OUT_TAB_COMPLETE("PacketPlayOutTabComplete"), - PLAY_OUT_TILE_ENTITY_DATA("PacketPlayOutTileEntityData"), - PLAY_OUT_TRANSACTION("PacketPlayOutTransaction"), - PLAY_OUT_UPDATE_ATTRIBUTES("PacketPlayOutUpdateAttributes"), - PLAY_OUT_UPDATE_HEALTH("PacketPlayOutUpdateHealth"), - PLAY_OUT_UPDATE_SIGN("PacketPlayOutUpdateSign"), - PLAY_OUT_UPDATE_TIME("PacketPlayOutUpdateTime"), - PLAY_OUT_WINDOW_ITEMS("PacketPlayOutWindowItems"), - PLAY_OUT_WORLD_EVENT("PacketPlayOutWorldEvent"), - PLAY_OUT_WORLD_PARTICLES("PacketPlayOutWorldParticles", "Packet63WorldParticles"), - STATUS_IN_PING("PacketStatusInPing"), - STATUS_IN_START("PacketStatusInStart"), - STATUS_OUT_PONG("PacketStatusOutPong"), - STATUS_OUT_SERVER_INFO("PacketStatusOutServerInfo"); - - private final String name; - private final String legacy; - private Class packet; - - private PacketType(String name) { - this.name = name; - this.legacy = null; - } - - private PacketType(String name, String legacy) { - this.name = name; - this.legacy = legacy; - } - - public String getName() { - return this.name; - } - - public Class getPacket() throws Exception { - if (packet == null) { - try { - packet = ReflectionHandler.getClass(name, PackageType.MINECRAFT_SERVER); - } catch (Exception ex) { - if (legacy == null) { - throw ex; - } - packet = ReflectionHandler.getClass(legacy, PackageType.MINECRAFT_SERVER); - } - } - return packet; - } - - } - -} From e4c320c93c35d80ccd1ab697ab3b85c1d058c626 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 6 Oct 2020 20:38:19 +0200 Subject: [PATCH 25/44] Allow "forever" durations --- .../de/slikey/effectlib/EffectManager.java | 24 ++++++++++++++----- .../de/slikey/effectlib/util/ConfigUtils.java | 7 ++++++ 2 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/slikey/effectlib/EffectManager.java b/src/main/java/de/slikey/effectlib/EffectManager.java index 71f1fe02..2fac5860 100644 --- a/src/main/java/de/slikey/effectlib/EffectManager.java +++ b/src/main/java/de/slikey/effectlib/EffectManager.java @@ -334,19 +334,31 @@ protected boolean setField(Object effect, String key, ConfigurationSection secti if (field == null) return false; if (field.getType().equals(Integer.TYPE) || field.getType().equals(Integer.class)) { - field.set(effect, fieldSection.getInt(fieldKey)); + int intValue = Integer.MAX_VALUE; + if (!ConfigUtils.isMaxValue(stringValue)) intValue = fieldSection.getInt(fieldKey); + field.set(effect, intValue); } else if (field.getType().equals(Float.TYPE) || field.getType().equals(Float.class)) { - field.set(effect, (float) fieldSection.getDouble(fieldKey)); + float floatValue = Float.MAX_VALUE; + if (!ConfigUtils.isMaxValue(stringValue)) floatValue = (float) fieldSection.getDouble(fieldKey); + field.set(effect,floatValue); } else if (field.getType().equals(Double.TYPE) || field.getType().equals(Double.class)) { - field.set(effect, fieldSection.getDouble(fieldKey)); + double doubleValue = Double.MAX_VALUE; + if (!ConfigUtils.isMaxValue(stringValue)) doubleValue = fieldSection.getDouble(fieldKey); + field.set(effect, doubleValue); } else if (field.getType().equals(Boolean.TYPE) || field.getType().equals(Boolean.class)) { field.set(effect, fieldSection.getBoolean(fieldKey)); } else if (field.getType().equals(Long.TYPE) || field.getType().equals(Long.class)) { - field.set(effect, fieldSection.getLong(fieldKey)); + long longValue = Long.MAX_VALUE; + if (!ConfigUtils.isMaxValue(stringValue)) longValue = fieldSection.getLong(fieldKey); + field.set(effect, longValue); } else if (field.getType().equals(Short.TYPE) || field.getType().equals(Short.class)) { - field.set(effect, (short) fieldSection.getInt(fieldKey)); + short shortValue = Short.MAX_VALUE; + if (!ConfigUtils.isMaxValue(stringValue)) shortValue = (short) fieldSection.getInt(fieldKey); + field.set(effect, shortValue); } else if (field.getType().equals(Byte.TYPE) || field.getType().equals(Byte.class)) { - field.set(effect, (byte) fieldSection.getInt(fieldKey)); + byte byteValue = Byte.MAX_VALUE; + if (!ConfigUtils.isMaxValue(stringValue)) byteValue = (byte) fieldSection.getInt(fieldKey); + field.set(effect, byteValue); } else if (field.getType().equals(String.class)) { String value = fieldSection.getString(fieldKey); field.set(effect, value); diff --git a/src/main/java/de/slikey/effectlib/util/ConfigUtils.java b/src/main/java/de/slikey/effectlib/util/ConfigUtils.java index b2e14f55..ac4b4dfa 100644 --- a/src/main/java/de/slikey/effectlib/util/ConfigUtils.java +++ b/src/main/java/de/slikey/effectlib/util/ConfigUtils.java @@ -97,4 +97,11 @@ public static ConfigurationSection getConfigurationSection(ConfigurationSection return null; } + public static boolean isMaxValue(String stringValue) { + return stringValue.equalsIgnoreCase("infinite") + || stringValue.equalsIgnoreCase("forever") + || stringValue.equalsIgnoreCase("infinity") + || stringValue.equalsIgnoreCase("max"); + } + } From a37bed64dc4aedc66f357a59d3281437cdd3e6cc Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 6 Oct 2020 20:41:03 +0200 Subject: [PATCH 26/44] Add support for "random" in a color parameter --- src/main/java/de/slikey/effectlib/EffectManager.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slikey/effectlib/EffectManager.java b/src/main/java/de/slikey/effectlib/EffectManager.java index 2fac5860..d8c801b9 100644 --- a/src/main/java/de/slikey/effectlib/EffectManager.java +++ b/src/main/java/de/slikey/effectlib/EffectManager.java @@ -365,7 +365,15 @@ protected boolean setField(Object effect, String key, ConfigurationSection secti } else if (field.getType().equals(Color.class)) { try { String value = fieldSection.getString(fieldKey); - Integer rgb = Integer.parseInt(value, 16); + Integer rgb; + if (value.equalsIgnoreCase("random")) { + byte red = (byte) (Math.random() * 255); + byte green = (byte) (Math.random() * 255); + byte blue = (byte) (Math.random() * 255); + rgb = (red << 16) | (green << 8) | blue; + } else { + rgb = Integer.parseInt(value, 16); + } Color color = Color.fromRGB(rgb); field.set(effect, color); } catch (Exception ex) { From f94fbf0c445f7561f93ec81bcf10353fa051d17c Mon Sep 17 00:00:00 2001 From: Chronoken Date: Sat, 14 Nov 2020 19:28:10 +0100 Subject: [PATCH 27/44] null checks --- src/main/java/de/slikey/effectlib/util/DynamicLocation.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/de/slikey/effectlib/util/DynamicLocation.java b/src/main/java/de/slikey/effectlib/util/DynamicLocation.java index 6f2dd547..2dc54220 100644 --- a/src/main/java/de/slikey/effectlib/util/DynamicLocation.java +++ b/src/main/java/de/slikey/effectlib/util/DynamicLocation.java @@ -96,11 +96,13 @@ protected Location getEntityLocation(Entity entity) { } public void setDirection(Vector direction) { + if (location == null || direction == null) return; location.setDirection(direction); updateDirection(); } public void updateDirection() { + if (location == null) return; if (yaw != null) location.setYaw(yaw); if (pitch != null) location.setPitch(pitch); if (yawOffset != 0) location.setYaw(location.getYaw() + yawOffset); From e3ba478aa2f1653ab59cedd6b28d43d950dd0ec2 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Sat, 28 Nov 2020 11:18:36 +0100 Subject: [PATCH 28/44] Use faster random --- pom.xml | 9 +++------ src/main/java/de/slikey/effectlib/util/RandomUtils.java | 3 ++- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/pom.xml b/pom.xml index 8537db9a..22e2c030 100644 --- a/pom.xml +++ b/pom.xml @@ -46,12 +46,9 @@ - org.bukkit - bukkit - 1.13-R0.1-SNAPSHOT - + org.spigotmc + spigot-api + 1.16.4-R0.1-SNAPSHOT provided diff --git a/src/main/java/de/slikey/effectlib/util/RandomUtils.java b/src/main/java/de/slikey/effectlib/util/RandomUtils.java index affc724d..b9d094d2 100644 --- a/src/main/java/de/slikey/effectlib/util/RandomUtils.java +++ b/src/main/java/de/slikey/effectlib/util/RandomUtils.java @@ -1,13 +1,14 @@ package de.slikey.effectlib.util; import java.util.Random; +import java.util.concurrent.ThreadLocalRandom; import org.bukkit.Material; import org.bukkit.util.Vector; public final class RandomUtils { - public static final Random random = new Random(System.nanoTime()); + public static final Random random = ThreadLocalRandom.current(); private RandomUtils() { // No instance allowed From 342e532e7f3869d3635003a77be7affdd6fcd1e4 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Fri, 18 Dec 2020 16:39:45 +0100 Subject: [PATCH 29/44] Added colors parameter to all effects, separated with a comma, lets you define your own random color list --- src/main/java/de/slikey/effectlib/Effect.java | 26 ++++++++++++++++++- .../de/slikey/effectlib/EffectManager.java | 2 ++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slikey/effectlib/Effect.java b/src/main/java/de/slikey/effectlib/Effect.java index 7818aa25..02f7e5af 100644 --- a/src/main/java/de/slikey/effectlib/Effect.java +++ b/src/main/java/de/slikey/effectlib/Effect.java @@ -2,6 +2,7 @@ import java.util.List; import java.util.ArrayList; +import java.util.concurrent.ThreadLocalRandom; import org.bukkit.Color; import org.bukkit.Particle; @@ -29,6 +30,9 @@ public abstract class Effect implements Runnable { */ public Color color = null; + public List colorList = null; + public String colors = null; + /** * This can be used to give particles a set speed when spawned. * This will not work with colored particles. @@ -205,6 +209,22 @@ public Effect(EffectManager effectManager) { visibleRange = effectManager.getParticleRange(); } + protected void initialize() { + if (colors != null) { + colorList = new ArrayList<>(); + String[] args = colors.split(","); + if (args.length >= 1) { + for (String str : args) { + try { + int rgb = Integer.parseInt(str, 16); + colorList.add(Color.fromRGB(rgb)); + } catch (NumberFormatException ignored) { + } + } + } + } + } + public final void cancel() { cancel(true); } @@ -403,8 +423,12 @@ protected void display(Particle particle, Location location, Color color, float targetPlayers = new ArrayList<>(); targetPlayers.add(targetPlayer); } + + Color currentColor = color; + if (colorList != null && !colorList.isEmpty()) currentColor = colorList.get(ThreadLocalRandom.current().nextInt(colorList.size())); + effectManager.display(particle, location, particleOffsetX, particleOffsetY, particleOffsetZ, speed, amount, - particleSize, color, material, materialData, visibleRange, targetPlayers); + particleSize, currentColor, material, materialData, visibleRange, targetPlayers); } private void done() { diff --git a/src/main/java/de/slikey/effectlib/EffectManager.java b/src/main/java/de/slikey/effectlib/EffectManager.java index d8c801b9..ba9c0baa 100644 --- a/src/main/java/de/slikey/effectlib/EffectManager.java +++ b/src/main/java/de/slikey/effectlib/EffectManager.java @@ -194,6 +194,8 @@ public Effect getEffect(String effectClass, ConfigurationSection parameters, Dyn } } + effect.initialize(); + effect.setDynamicOrigin(origin); effect.setDynamicTarget(target); From fdd144ae6bcd32456172ccf88f27a3ae649a019d Mon Sep 17 00:00:00 2001 From: Chronoken Date: Fri, 18 Dec 2020 16:46:30 +0100 Subject: [PATCH 30/44] get colors more lenient --- src/main/java/de/slikey/effectlib/Effect.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/de/slikey/effectlib/Effect.java b/src/main/java/de/slikey/effectlib/Effect.java index 02f7e5af..119e8862 100644 --- a/src/main/java/de/slikey/effectlib/Effect.java +++ b/src/main/java/de/slikey/effectlib/Effect.java @@ -216,7 +216,7 @@ protected void initialize() { if (args.length >= 1) { for (String str : args) { try { - int rgb = Integer.parseInt(str, 16); + int rgb = Integer.parseInt(str.trim().replace("#", ""), 16); colorList.add(Color.fromRGB(rgb)); } catch (NumberFormatException ignored) { } From 87c5878a743f743fb833b7059307214272f42531 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Fri, 15 Jan 2021 15:49:54 +0100 Subject: [PATCH 31/44] upstream changes --- CHANGELOG.md | 4 ++++ EffectLib.doxyfile | 2 +- pom.xml | 13 ++++++++----- .../de/slikey/effectlib/util/ParticleDisplay.java | 3 +-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08de9039..3f3196ee 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # CHANGELOG +# 7.0 + +- Plugin cleanup and additional code changes + # 6.2 - Some specific internal FX fixes (please let me know if any effects look weird now) diff --git a/EffectLib.doxyfile b/EffectLib.doxyfile index 8c3048e8..3a56906a 100644 --- a/EffectLib.doxyfile +++ b/EffectLib.doxyfile @@ -38,7 +38,7 @@ PROJECT_NAME = EffectLib # could be handy for archiving the generated documentation or if some version # control system is used. -PROJECT_NUMBER = 5.0 +PROJECT_NUMBER = 7.0 # Using the PROJECT_BRIEF tag one can provide an optional one line description # for a project that appears at the top of each page and should give viewer a diff --git a/pom.xml b/pom.xml index 22e2c030..ada2784b 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 de.slikey EffectLib - 6.4 + 7.0 EffectLib http://www.kevin-carstens.de/ @@ -29,11 +29,12 @@ maven.elmakers.com - http://maven.elmakers.com/repository/ + https://maven.elmakers.com/repository/ + maven.elmakers.com - http://maven.elmakers.com/repository/ + https://maven.elmakers.com/repository/ @@ -51,6 +52,7 @@ 1.16.4-R0.1-SNAPSHOT provided + net.objecthunter exp4j @@ -72,16 +74,17 @@ org.apache.maven.plugins maven-compiler-plugin - 3.3 + 3.8.1 7 7 + org.apache.maven.plugins maven-shade-plugin - 1.5 + 3.2.4 package diff --git a/src/main/java/de/slikey/effectlib/util/ParticleDisplay.java b/src/main/java/de/slikey/effectlib/util/ParticleDisplay.java index fc675c1f..13927487 100644 --- a/src/main/java/de/slikey/effectlib/util/ParticleDisplay.java +++ b/src/main/java/de/slikey/effectlib/util/ParticleDisplay.java @@ -23,10 +23,9 @@ public abstract class ParticleDisplay { protected void display(Particle particle, Location center, float offsetX, float offsetY, float offsetZ, float speed, int amount, Object data, double range, List targetPlayers) { try { if (targetPlayers == null) { - String worldName = center.getWorld().getName(); double squared = range * range; for (Player player : Bukkit.getOnlinePlayers()) { - if (!player.getWorld().getName().equals(worldName) || player.getLocation().distanceSquared(center) > squared) { + if (player.getWorld() != center.getWorld() || player.getLocation().distanceSquared(center) > squared) { continue; } player.spawnParticle(particle, center, amount, offsetX, offsetY, offsetZ, speed, data); From 7d3dfcf612139517f8ab7c25e1c1e8d4567a7d4f Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 26 Jan 2021 13:02:11 +0100 Subject: [PATCH 32/44] Fix typos --- src/main/java/de/slikey/effectlib/effect/CircleEffect.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/slikey/effectlib/effect/CircleEffect.java b/src/main/java/de/slikey/effectlib/effect/CircleEffect.java index fb322866..6e257090 100644 --- a/src/main/java/de/slikey/effectlib/effect/CircleEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/CircleEffect.java @@ -23,17 +23,17 @@ public class CircleEffect extends Effect { public double xRotation, yRotation, zRotation = 0; /* - * Turns the cube by this angle each iteration around the x-axis + * Turns the circle by this angle each iteration around the x-axis */ public double angularVelocityX = Math.PI / 200; /* - * Turns the cube by this angle each iteration around the y-axis + * Turns the circle by this angle each iteration around the y-axis */ public double angularVelocityY = Math.PI / 170; /* - * Turns the cube by this angle each iteration around the z-axis + * Turns the circle by this angle each iteration around the z-axis */ public double angularVelocityZ = Math.PI / 155; From 1aa473787ff3121b4724c234559abfb4baabb8b8 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 26 Jan 2021 13:07:06 +0100 Subject: [PATCH 33/44] upstream changes --- src/main/java/de/slikey/effectlib/EffectManager.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/de/slikey/effectlib/EffectManager.java b/src/main/java/de/slikey/effectlib/EffectManager.java index ba9c0baa..ce9b0082 100644 --- a/src/main/java/de/slikey/effectlib/EffectManager.java +++ b/src/main/java/de/slikey/effectlib/EffectManager.java @@ -374,6 +374,7 @@ protected boolean setField(Object effect, String key, ConfigurationSection secti byte blue = (byte) (Math.random() * 255); rgb = (red << 16) | (green << 8) | blue; } else { + if (value.startsWith("#")) value = value.substring(1); rgb = Integer.parseInt(value, 16); } Color color = Color.fromRGB(rgb); From 48ff9306ba463be317876e0a04cbc97078f2ba60 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 26 Jan 2021 13:32:38 +0100 Subject: [PATCH 34/44] Display particles only when particleCount is equal or more than 0 Added subeffects that play on the effect particle location --- src/main/java/de/slikey/effectlib/Effect.java | 38 ++++++++++++++----- 1 file changed, 29 insertions(+), 9 deletions(-) diff --git a/src/main/java/de/slikey/effectlib/Effect.java b/src/main/java/de/slikey/effectlib/Effect.java index 119e8862..97120e0c 100644 --- a/src/main/java/de/slikey/effectlib/Effect.java +++ b/src/main/java/de/slikey/effectlib/Effect.java @@ -5,18 +5,27 @@ import java.util.concurrent.ThreadLocalRandom; import org.bukkit.Color; +import org.bukkit.Material; import org.bukkit.Particle; import org.bukkit.Location; -import org.bukkit.Material; import org.bukkit.util.Vector; import org.bukkit.entity.Entity; import org.bukkit.entity.Player; +import org.bukkit.configuration.ConfigurationSection; import de.slikey.effectlib.util.RandomUtils; import de.slikey.effectlib.util.DynamicLocation; public abstract class Effect implements Runnable { + /** + * Sub effect + * This will play a subeffect on the effect location + */ + private String subEffectClass = null; + public ConfigurationSection subEffect = null; + + /** * Handles the type, the effect is played. * @@ -223,6 +232,10 @@ protected void initialize() { } } } + + if (subEffect != null) { + subEffectClass = subEffect.getString("subEffectClass"); + } } public final void cancel() { @@ -419,16 +432,23 @@ protected void display(Particle particle, Location location, float speed, int am } protected void display(Particle particle, Location location, Color color, float speed, int amount) { - if (targetPlayers == null && targetPlayer != null) { - targetPlayers = new ArrayList<>(); - targetPlayers.add(targetPlayer); - } + // display particles only when particleCount is equal or more than 0 + if (particleCount >= 0) { + if (targetPlayers == null && targetPlayer != null) { + targetPlayers = new ArrayList<>(); + targetPlayers.add(targetPlayer); + } - Color currentColor = color; - if (colorList != null && !colorList.isEmpty()) currentColor = colorList.get(ThreadLocalRandom.current().nextInt(colorList.size())); + Color currentColor = color; + if (colorList != null && !colorList.isEmpty()) { + currentColor = colorList.get(ThreadLocalRandom.current().nextInt(colorList.size())); + } + + effectManager.display(particle, location, particleOffsetX, particleOffsetY, particleOffsetZ, speed, amount, + particleSize, currentColor, material, materialData, visibleRange, targetPlayers); + } - effectManager.display(particle, location, particleOffsetX, particleOffsetY, particleOffsetZ, speed, amount, - particleSize, currentColor, material, materialData, visibleRange, targetPlayers); + if (subEffectClass != null) effectManager.start(subEffectClass, subEffect, location); } private void done() { From 93549588d805448fd473451b8c3146d5acf96143 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 9 Feb 2021 20:26:11 +0100 Subject: [PATCH 35/44] Added zigZagRelativeOffset for LineEffect --- .../slikey/effectlib/effect/LineEffect.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/slikey/effectlib/effect/LineEffect.java b/src/main/java/de/slikey/effectlib/effect/LineEffect.java index 43888423..bbeffa71 100644 --- a/src/main/java/de/slikey/effectlib/effect/LineEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/LineEffect.java @@ -7,6 +7,7 @@ import de.slikey.effectlib.Effect; import de.slikey.effectlib.EffectType; import de.slikey.effectlib.EffectManager; +import de.slikey.effectlib.util.VectorUtils; public class LineEffect extends Effect { @@ -28,7 +29,12 @@ public class LineEffect extends Effect { /** * Direction of zig-zags */ - public Vector zigZagOffset = new Vector(0,0.1,0); + public Vector zigZagOffset = new Vector(0, 0.1, 0); + + /** + * Relative direction of zig-zags + */ + public Vector zigZagRelativeOffset = new Vector(0, 0, 0); /** * Particles per arc @@ -83,10 +89,17 @@ public void onRun() { float ratio = length / particles; Vector v = link.multiply(ratio); Location loc = location.clone().subtract(v); + Vector rel; for (int i = 0; i < particles; i++) { if (isZigZag) { - if (zag) loc.add(zigZagOffset); - else loc.subtract(zigZagOffset); + rel = VectorUtils.rotateVector(zigZagRelativeOffset, loc); + if (zag) { + loc.add(rel); + loc.add(zigZagOffset); + } else { + loc.subtract(zigZagOffset); + loc.subtract(rel); + } } if (step >= amount) { zag = !zag; From 9a0e49d7b7caff637b8b171dd2292fbc2ba9b74d Mon Sep 17 00:00:00 2001 From: Chronoken Date: Tue, 9 Feb 2021 20:43:14 +0100 Subject: [PATCH 36/44] Upstream changes --- .../de/slikey/effectlib/EffectManager.java | 14 ++ .../slikey/effectlib/effect/CuboidEffect.java | 134 ++++++++++++++++++ .../slikey/effectlib/effect/GridEffect.java | 21 +++ .../effectlib/effect/ModifiedEffect.java | 25 ++-- .../effectlib/effect/PyramidEffect.java | 90 ++++++++++++ .../slikey/effectlib/math/EquationStore.java | 22 +-- .../effectlib/math/EquationTransform.java | 118 +++++++-------- .../de/slikey/effectlib/util/CustomSound.java | 90 +++++++----- 8 files changed, 405 insertions(+), 109 deletions(-) create mode 100644 src/main/java/de/slikey/effectlib/effect/CuboidEffect.java create mode 100644 src/main/java/de/slikey/effectlib/effect/PyramidEffect.java diff --git a/src/main/java/de/slikey/effectlib/EffectManager.java b/src/main/java/de/slikey/effectlib/EffectManager.java index ce9b0082..53192fad 100644 --- a/src/main/java/de/slikey/effectlib/EffectManager.java +++ b/src/main/java/de/slikey/effectlib/EffectManager.java @@ -185,6 +185,20 @@ public Effect getEffect(String effectClass, ConfigurationSection parameters, Dyn Effect effect = getEffectByClassName(effectClass); if (effect == null) return null; + // Some specific shortcuts + if (parameters.contains("particle_offset")) { + parameters.set("particle_offset_x", parameters.get("particle_offset")); + parameters.set("particle_offset_y", parameters.get("particle_offset")); + parameters.set("particle_offset_z", parameters.get("particle_offset")); + parameters.set("particle_offset", null); + } + if (parameters.contains("particleOffset")) { + parameters.set("particleOffsetX", parameters.get("particleOffset")); + parameters.set("particleOffsetY", parameters.get("particleOffset")); + parameters.set("particleOffsetZ", parameters.get("particleOffset")); + parameters.set("particleOffset", null); + } + Collection keys = parameters.getKeys(false); for (String key : keys) { if (key.equals("class")) continue; diff --git a/src/main/java/de/slikey/effectlib/effect/CuboidEffect.java b/src/main/java/de/slikey/effectlib/effect/CuboidEffect.java new file mode 100644 index 00000000..937c0935 --- /dev/null +++ b/src/main/java/de/slikey/effectlib/effect/CuboidEffect.java @@ -0,0 +1,134 @@ +package de.slikey.effectlib.effect; + +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.util.Vector; + +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; + +public class CuboidEffect extends Effect { + + /** + * Particle of the cube + */ + public Particle particle = Particle.FLAME; + + /** + * Particles in each row + */ + public int particles = 8; + + /** + * Length of x component of cuboid + */ + public double xLength = 0; + + /** + * Length of y component of cuboid + */ + public double yLength = 0; + + /** + * Length of z component of cuboid + */ + public double zLength = 0; + + /** + * Amount of padding to add around the cube + */ + public double padding = 0; + + /** + * Use corners of blocks + */ + public boolean blockSnap = false; + + /** + * State variables + */ + protected Location minCorner; + protected boolean initialized; + + public CuboidEffect(EffectManager effectManager) { + super(effectManager); + type = EffectType.REPEATING; + period = 5; + iterations = 200; + } + + @Override + public void onRun() { + Location target = getTarget(); + Location location = getLocation(); + if (target == null || location == null) return; + if (!initialized) { + if (blockSnap) { + target = target.getBlock().getLocation(); + minCorner = location.getBlock().getLocation(); + } else { + minCorner = location.clone(); + } + if (xLength == 0 && yLength == 0 && zLength == 0) { + if (target == null || !target.getWorld().equals(location.getWorld())) { + cancel(); + return; + } + if (target.getX() < minCorner.getX()) minCorner.setX(target.getX()); + + if (target.getY() < minCorner.getY()) minCorner.setY(target.getY()); + + if (target.getZ() < minCorner.getZ()) minCorner.setZ(target.getZ()); + + if (padding != 0) minCorner.add(-padding, -padding, -padding); + + double extra = padding * 2; + if (blockSnap) extra++; + xLength = Math.abs(location.getX() - target.getX()) + extra; + yLength = Math.abs(location.getY() - target.getY()) + extra; + zLength = Math.abs(location.getZ() - target.getZ()) + extra; + } + initialized = true; + } + drawOutline(location, target); + } + + private void drawOutline(Location location, Location target) { + Vector v = new Vector(); + for (int i = 0; i < particles; i++) { + // X edges + drawEdge(v, i, 0, 2, 2); + drawEdge(v, i, 0, 1, 2); + drawEdge(v, i, 0, 1, 1); + drawEdge(v, i, 0, 2, 1); + + // Y edges + drawEdge(v, i, 2, 0, 2); + drawEdge(v, i, 1, 0, 2); + drawEdge(v, i, 1, 0, 1); + drawEdge(v, i, 2, 0, 1); + + // Z edges + drawEdge(v, i, 2, 2, 0); + drawEdge(v, i, 1, 2, 0); + drawEdge(v, i, 1, 1, 0); + drawEdge(v, i, 2, 1, 0); + } + } + + private void drawEdge(Vector v, int i, int dx, int dy, int dz) { + if (dx == 0) v.setX(xLength * i / particles); + else v.setX(xLength * (dx - 1)); + + if (dy == 0) v.setY(yLength * i / particles); + else v.setY(yLength * (dy - 1)); + + if (dz == 0) v.setZ(zLength * i / particles); + else v.setZ(zLength * (dz - 1)); + + display(particle, minCorner.add(v)); + minCorner.subtract(v); + } + +} diff --git a/src/main/java/de/slikey/effectlib/effect/GridEffect.java b/src/main/java/de/slikey/effectlib/effect/GridEffect.java index c46ef8e8..8e9dbab2 100644 --- a/src/main/java/de/slikey/effectlib/effect/GridEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/GridEffect.java @@ -51,6 +51,21 @@ public class GridEffect extends Effect { */ public double rotation = 0; + /** + * Rotation around the X-axis + */ + public double rotationX = 0; + + /** + * Rotation around the Z-axis + */ + public double rotationZ = 0; + + /** + * To center the grid on the location + */ + public boolean center = false; + public GridEffect(EffectManager effectManager) { super(effectManager); type = EffectType.INSTANT; @@ -82,7 +97,13 @@ public void onRun() { protected void addParticle(Location location, Vector v) { v.setZ(0); + if (center) { + v.setY(v.getY() + heightCell * -(rows + 1) / 2); + v.setX(v.getX() + widthCell * -(columns + 1) / 2); + } VectorUtils.rotateAroundAxisY(v, rotation); + if (rotationX != 0) VectorUtils.rotateAroundAxisX(v, rotationX); + if (rotationZ != 0) VectorUtils.rotateAroundAxisZ(v, rotationZ); location.add(v); display(particle, location); location.subtract(v); diff --git a/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java b/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java index 35a54ad9..c7fbb7d9 100644 --- a/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java @@ -1,10 +1,9 @@ package de.slikey.effectlib.effect; import java.util.Map; -import java.util.Set; +import java.util.List; import java.util.Arrays; import java.util.HashMap; -import java.util.HashSet; import java.lang.reflect.Field; import org.bukkit.Location; @@ -22,8 +21,8 @@ public class ModifiedEffect extends Effect { - private final static String[] _variables = {"t", "i"}; - private final static Set variables = new HashSet<>(Arrays.asList(_variables)); + private final static String[] _variables = {"t", "i", "a", "b"}; + private final static List variables = Arrays.asList(_variables); /** * The base configuration of the inner effect. @@ -52,6 +51,16 @@ public class ModifiedEffect extends Effect { */ public String zEquation = null; + /** + * The starting value of variable a + */ + public double variableA; + + /** + * The starting value of variable b + */ + public double variableB; + /** * Whether or not to orient the effect in the direction * of the source Location @@ -164,9 +173,9 @@ public void onRun() { if (origin != null && xTransform != null || yTransform != null || zTransform != null) { Vector offset = new Vector( - xTransform == null ? 0 : xTransform.get(step, maxIterations), - yTransform == null ? 0 : yTransform.get(step, maxIterations), - zTransform == null ? 0 : zTransform.get(step, maxIterations) + xTransform == null ? 0 : xTransform.get(step, maxIterations, variableA, variableB), + yTransform == null ? 0 : yTransform.get(step, maxIterations, variableA, variableB), + zTransform == null ? 0 : zTransform.get(step, maxIterations, variableA, variableB) ); if (previousOffset != null) offset.subtract(previousOffset); @@ -181,7 +190,7 @@ public void onRun() { } for (Map.Entry entry : parameterTransforms.entrySet()) { - double value = entry.getValue().get(step, maxIterations); + double value = entry.getValue().get(step, maxIterations, variableA, variableB); try { Field field = entry.getKey(); if (field.getType().equals(Double.class) || field.getType().equals(Double.TYPE)) { diff --git a/src/main/java/de/slikey/effectlib/effect/PyramidEffect.java b/src/main/java/de/slikey/effectlib/effect/PyramidEffect.java new file mode 100644 index 00000000..d891d240 --- /dev/null +++ b/src/main/java/de/slikey/effectlib/effect/PyramidEffect.java @@ -0,0 +1,90 @@ +package de.slikey.effectlib.effect; + +import org.bukkit.Location; +import org.bukkit.Particle; +import org.bukkit.util.Vector; + +import de.slikey.effectlib.Effect; +import de.slikey.effectlib.EffectType; +import de.slikey.effectlib.EffectManager; + +public class PyramidEffect extends Effect { + + /** + * Particle of the cube + */ + public Particle particle = Particle.FLAME; + + /** + * Particles in each row + */ + public int particles = 8; + + /** + * Center to edge distance + */ + public double radius = 0; + + /** + * Use corners of blocks + */ + public boolean blockSnap = false; + + public PyramidEffect(EffectManager effectManager) { + super(effectManager); + type = EffectType.REPEATING; + period = 5; + iterations = 200; + } + + @Override + public void onRun() { + Location location = getLocation(); + drawOutline(location); + } + + private void drawOutline(Location location) { + Vector v = new Vector(); + for (int i = 0; i < particles; i++) { + // X base + drawEdge(location, v, i, 0, 0, -1); + drawEdge(location, v, i, 0, 0, 1); + + // Z base + drawEdge(location, v, i, -1, 0, 0); + drawEdge(location, v, i, 1, 0, 0); + + // diagonals + drawEdge(location, v, i, -1, 1, -1); + drawEdge(location, v, i, -1, 1, 1); + drawEdge(location, v, i, 1, 1, -1); + drawEdge(location, v, i, 1, 1, 1); + } + } + + private void drawEdge(Location center, Vector v, int i, int dx, int dy, int dz) { + // Y goes from 0 to 1 + // X and Z go from -1 to 1 + double ratio = (double) i / particles; + if (dy == 1) { + v.setY(ratio); + + if (dx < 0) v.setX(ratio - 1); + else v.setX(1 - ratio); + + if (dz < 0) v.setZ(ratio - 1); + else v.setZ(1 - ratio); + } else { + v.setY(0); + + if (dx == 0) v.setX(ratio * 2 - 1); + else v.setX(dx); + + if (dz == 0) v.setZ(ratio * 2 - 1); + else v.setZ(dz); + } + display(particle, center.add(v.multiply(radius))); + center.subtract(v); + } + +} diff --git a/src/main/java/de/slikey/effectlib/math/EquationStore.java b/src/main/java/de/slikey/effectlib/math/EquationStore.java index 7e126e02..0d01e31f 100644 --- a/src/main/java/de/slikey/effectlib/math/EquationStore.java +++ b/src/main/java/de/slikey/effectlib/math/EquationStore.java @@ -1,8 +1,10 @@ package de.slikey.effectlib.math; import java.util.Map; -import java.util.Set; import java.util.HashMap; +import java.util.Collection; + +import org.apache.commons.lang.StringUtils; public class EquationStore { @@ -25,32 +27,34 @@ public EquationTransform getTransform(String equation, String variable) { } public EquationTransform getTransform(String equation, String... variables) { - EquationTransform transform = transforms.get(equation); + String equationKey = equation + ":" + StringUtils.join(variables, ","); + EquationTransform transform = transforms.get(equationKey); if (transform == null) { transform = new EquationTransform(equation, variables); - transforms.put(equation, transform); + transforms.put(equationKey, transform); } return transform; } - public EquationTransform getTransform(String equation, Set variables) { - EquationTransform transform = transforms.get(equation); + public EquationTransform getTransform(String equation, Collection variables) { + String equationKey = equation + ":" + StringUtils.join(variables, ","); + EquationTransform transform = transforms.get(equationKey); if (transform == null) { transform = new EquationTransform(equation, variables); - transforms.put(equation, transform); + transforms.put(equationKey, transform); } - + return transform; } public static void clear() { if (instance != null) instance.transforms.clear(); } - + public static EquationStore getInstance() { if (instance == null) instance = new EquationStore(); - + return instance; } diff --git a/src/main/java/de/slikey/effectlib/math/EquationTransform.java b/src/main/java/de/slikey/effectlib/math/EquationTransform.java index e8dc3d7a..864d9c41 100644 --- a/src/main/java/de/slikey/effectlib/math/EquationTransform.java +++ b/src/main/java/de/slikey/effectlib/math/EquationTransform.java @@ -1,8 +1,9 @@ package de.slikey.effectlib.math; -import java.util.Set; import java.util.Random; import java.util.HashSet; +import java.util.ArrayList; +import java.util.Collection; import net.objecthunter.exp4j.Expression; import net.objecthunter.exp4j.ExpressionBuilder; @@ -17,7 +18,7 @@ public class EquationTransform implements Transform { private static Function minFunction; private static Function maxFunction; private static Function selectFunction; - private final Set inputVariables; + private final Collection inputVariables; private Exception exception; @Override @@ -26,69 +27,69 @@ public void load(ConfigurationSection parameters) { } public EquationTransform() { - inputVariables = new HashSet<>(); + inputVariables = new ArrayList<>(); } - + public EquationTransform(String equation) { this(equation, "t"); } public EquationTransform(String equation, String inputVariable) { - inputVariables = new HashSet<>(); + inputVariables = new ArrayList<>(); inputVariables.add(inputVariable); setEquation(equation); } public EquationTransform(String equation, String... inputVariables) { - this.inputVariables = new HashSet<>(); + this.inputVariables = new ArrayList<>(); for (String inputVariable : inputVariables) { this.inputVariables.add(inputVariable); } setEquation(equation); } - public EquationTransform(String equation, Set inputVariables) { + public EquationTransform(String equation, Collection inputVariables) { this.inputVariables = inputVariables; setEquation(equation); } private void checkCustomFunctions() { - if (randFunction == null) { - randFunction = new Function("rand", 2) { - private Random random = new Random(); - - @Override - public double apply(double... args) { - return random.nextDouble() * (args[1] - args[0]) + args[0]; - } - }; - } - if (minFunction == null) { - minFunction = new Function("min", 2) { - @Override - public double apply(double... args) { - return Math.min(args[0], args[1]); - } - }; - } - if (maxFunction == null) { - maxFunction = new Function("max", 2) { - @Override - public double apply(double... args) { - return Math.max(args[0], args[1]); - } - }; - } - if (selectFunction == null) { - selectFunction = new Function("select", 4) { - @Override - public double apply(double... args) { - if (args[0] < 0) return args[1]; - else if (args[0] == 0) return args[2]; - return args[3]; - } - }; - } + if (randFunction == null) { + randFunction = new Function("rand", 2) { + private Random random = new Random(); + + @Override + public double apply(double... args) { + return random.nextDouble() * (args[1] - args[0]) + args[0]; + } + }; + } + if (minFunction == null) { + minFunction = new Function("min", 2) { + @Override + public double apply(double... args) { + return Math.min(args[0], args[1]); + } + }; + } + if (maxFunction == null) { + maxFunction = new Function("max", 2) { + @Override + public double apply(double... args) { + return Math.max(args[0], args[1]); + } + }; + } + if (selectFunction == null) { + selectFunction = new Function("select", 4) { + @Override + public double apply(double... args) { + if (args[0] < 0) return args[1]; + else if (args[0] == 0) return args[2]; + return args[3]; + } + }; + } } public boolean setEquation(String equation) { @@ -96,31 +97,33 @@ public boolean setEquation(String equation) { checkCustomFunctions(); exception = null; expression = new ExpressionBuilder(equation) - .function(randFunction) - .function(minFunction) - .function(maxFunction) - .function(selectFunction) - .variables(inputVariables) - .build(); + .function(randFunction) + .function(minFunction) + .function(maxFunction) + .function(selectFunction) + .variables(new HashSet(inputVariables)) + .build(); } catch (Exception ex) { expression = null; exception = ex; } - + return exception == null; } @Override public double get(double t) { if (expression == null) return 0; + for (String inputVariable : inputVariables) { expression.setVariable(inputVariable, t); } return get(); } - + public double get(double... t) { if (expression == null) return 0; + int index = 0; for (String inputVariable : inputVariables) { expression.setVariable(inputVariable, t[index]); @@ -128,17 +131,20 @@ public double get(double... t) { } return get(); } - + public void addVariable(String key) { inputVariables.add(key); } public void setVariable(String key, double value) { - if (expression != null) expression.setVariable(key, value); + if (expression != null) { + expression.setVariable(key, value); + } } public double get() { if (expression == null) return Double.NaN; + double value = Double.NaN; try { exception = null; @@ -148,7 +154,7 @@ public double get() { } return value; } - + public Exception getException() { return exception; } @@ -156,8 +162,8 @@ public Exception getException() { public boolean isValid() { return exception == null; } - - public Set getParameters() { + + public Collection getParameters() { return inputVariables; } diff --git a/src/main/java/de/slikey/effectlib/util/CustomSound.java b/src/main/java/de/slikey/effectlib/util/CustomSound.java index 770308cf..919be9c9 100644 --- a/src/main/java/de/slikey/effectlib/util/CustomSound.java +++ b/src/main/java/de/slikey/effectlib/util/CustomSound.java @@ -2,6 +2,7 @@ import java.util.Collection; import java.util.logging.Level; +import java.util.logging.Logger; import java.lang.reflect.Method; import org.bukkit.Sound; @@ -15,7 +16,6 @@ public class CustomSound { private static boolean initializedReflection; - private static Method player_playCustomSoundMethod; private static Method player_stopSoundMethod; private static Method player_stopCustomSoundMethod; @@ -28,7 +28,7 @@ public class CustomSound { public CustomSound(Sound sound) { this.sound = sound; - customSound = null; + this.customSound = null; } public CustomSound(String key) { @@ -46,7 +46,6 @@ public CustomSound(String key) { } else { customSound = soundName; } - if (pieces.length > 1) { try { volume = Float.parseFloat(pieces[1]); @@ -54,7 +53,6 @@ public CustomSound(String key) { volume = 1; } } - if (pieces.length > 2) { try { pitch = Float.parseFloat(pieces[2]); @@ -62,7 +60,6 @@ public CustomSound(String key) { pitch = 1; } } - if (pieces.length > 3) { try { range = Integer.parseInt(pieces[3]); @@ -130,13 +127,17 @@ public int getRange() { } public void play(Plugin plugin, Location sourceLocation) { + play(plugin, plugin == null ? null : plugin.getLogger(), sourceLocation); + } + + public void play(Plugin plugin, Logger logger, Location sourceLocation) { if (sourceLocation == null || plugin == null) return; if (customSound != null) { try { int range = this.range; if (range <= 0) { - range = (int) (volume > 1.0 ? (16.0 * volume) : 16.0); + range = (int)(volume > 1.0 ? (16.0 * volume) : 16.0); } int rangeSquared = range * range; Collection players = plugin.getServer().getOnlinePlayers(); @@ -144,24 +145,43 @@ public void play(Plugin plugin, Location sourceLocation) { Location location = player.getLocation(); if (location.getWorld().equals(sourceLocation.getWorld()) && location.distanceSquared(sourceLocation) <= rangeSquared) { // player.playSound(sourceLocation, customSound, volume, pitch); - playCustomSound(plugin, player, sourceLocation, customSound, volume, pitch); + playCustomSound(logger, player, sourceLocation, customSound, volume, pitch); } } } catch (Exception ex) { - plugin.getLogger().warning("Failed to play custom sound: " + customSound); + if (logger != null) { + logger.warning("Failed to play custom sound: " + customSound); + } } } if (sound != null) { try { - sourceLocation.getWorld().playSound(sourceLocation, sound, volume, pitch); + if (range > 0) { + int rangeSquared = range * range; + Collection players = plugin.getServer().getOnlinePlayers(); + for (Player player : players) { + Location location = player.getLocation(); + if (location.getWorld().equals(sourceLocation.getWorld()) && location.distanceSquared(sourceLocation) <= rangeSquared) { + player.playSound(sourceLocation, sound, volume, pitch); + } + } + } else { + sourceLocation.getWorld().playSound(sourceLocation, sound, volume, pitch); + } } catch (Exception ex) { - plugin.getLogger().warning("Failed to play sound: " + sound); + if (logger != null) { + logger.warning("Failed to play sound: " + sound); + } } } } public void play(Plugin plugin, Entity entity) { + play(plugin, plugin == null ? null : plugin.getLogger(), entity); + } + + public void play(Plugin plugin, Logger logger, Entity entity) { if (entity == null || plugin == null) return; Location sourceLocation = entity.getLocation(); @@ -174,17 +194,19 @@ public void play(Plugin plugin, Entity entity) { Location location = player.getLocation(); if (location.getWorld().equals(sourceLocation.getWorld()) && location.distanceSquared(sourceLocation) <= rangeSquared) { // player.playSound(sourceLocation, customSound, volume, pitch); - playCustomSound(plugin, player, sourceLocation, customSound, volume, pitch); + playCustomSound(logger, player, sourceLocation, customSound, volume, pitch); } } } else if (entity instanceof Player) { Player player = (Player)entity; // player.playSound(sourceLocation, customSound, volume, pitch); - playCustomSound(plugin, player, sourceLocation, customSound, volume, pitch); + playCustomSound(logger, player, sourceLocation, customSound, volume, pitch); } } catch (Exception ex) { - plugin.getLogger().warning("Failed to play custom sound: " + customSound); + if (logger != null) { + logger.warning("Failed to play custom sound: " + customSound); + } } } @@ -197,7 +219,9 @@ public void play(Plugin plugin, Entity entity) { sourceLocation.getWorld().playSound(sourceLocation, sound, volume, pitch); } } catch (Exception ex) { - plugin.getLogger().warning("Failed to play sound: " + sound); + if (logger != null) { + logger.warning("Failed to play sound: " + sound); + } } } } @@ -206,65 +230,59 @@ public void setRange(int range) { this.range = range; } - private static void initializeReflection(Plugin plugin) { + private static void initializeReflection(Logger logger) { if (!initializedReflection) { initializedReflection = true; try { player_playCustomSoundMethod = Player.class.getMethod("playSound", Location.class, String.class, Float.TYPE, Float.TYPE); } catch (Exception ex) { - if (plugin != null) { - plugin.getLogger().warning("Failed to bind to custom sound method"); - } + if (logger != null) logger.warning("Failed to bind to custom sound method"); } try { player_stopCustomSoundMethod = Player.class.getMethod("stopSound", String.class); } catch (Exception ex) { - if (plugin != null) { - plugin.getLogger().warning("Failed to bind to stop custom sound method"); - } + if (logger != null) logger.warning("Failed to bind to stop custom sound method"); } try { player_stopSoundMethod = Player.class.getMethod("stopSound", Sound.class); } catch (Exception ex) { - if (plugin != null) { - plugin.getLogger().warning("Failed to bind to stop sound method"); - } + if (logger != null) logger.warning("Failed to bind to stop sound method"); } } } - public static void stopSound(Plugin plugin, Player player, String sound) { - initializeReflection(plugin); + public static void stopSound(Logger logger, Player player, String sound) { + initializeReflection(logger); if (player_stopCustomSoundMethod == null) return; try { player_stopCustomSoundMethod.invoke(player, sound); } catch (Exception ex) { - if (plugin != null) { - plugin.getLogger().log(Level.WARNING, "Failed to stop custom sound: " + sound, ex); + if (logger != null) { + logger.log(Level.WARNING, "Failed to stop custom sound: " + sound, ex); } } } - public static void stopSound(Plugin plugin, Player player, Sound sound) { - initializeReflection(plugin); + public static void stopSound(Logger logger, Player player, Sound sound) { + initializeReflection(logger); if (player_stopSoundMethod == null) return; try { player_stopSoundMethod.invoke(player, sound); } catch (Exception ex) { - if (plugin != null) { - plugin.getLogger().log(Level.WARNING, "Failed to stop sound: " + sound, ex); + if (logger != null) { + logger.log(Level.WARNING, "Failed to stop sound: " + sound, ex); } } } - public static void playCustomSound(Plugin plugin, Player player, Location location, String sound, float volume, float pitch) { - initializeReflection(plugin); + public static void playCustomSound(Logger logger, Player player, Location location, String sound, float volume, float pitch) { + initializeReflection(logger); if (player_playCustomSoundMethod == null) return; try { player_playCustomSoundMethod.invoke(player, location, sound, volume, pitch); } catch (Exception ex) { - if (plugin != null) { - plugin.getLogger().log(Level.WARNING, "Failed to play custom sound: " + sound, ex); + if (logger != null) { + logger.log(Level.WARNING, "Failed to play custom sound: " + sound, ex); } } } From 4913d526c81202fa1f4b757f0bd8ee33a452cdca Mon Sep 17 00:00:00 2001 From: Chronoken Date: Wed, 10 Feb 2021 13:22:54 +0100 Subject: [PATCH 37/44] Added subEffectAtEnd for LineEffect --- .../slikey/effectlib/effect/LineEffect.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slikey/effectlib/effect/LineEffect.java b/src/main/java/de/slikey/effectlib/effect/LineEffect.java index bbeffa71..6dd84909 100644 --- a/src/main/java/de/slikey/effectlib/effect/LineEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/LineEffect.java @@ -3,6 +3,7 @@ import org.bukkit.Particle; import org.bukkit.Location; import org.bukkit.util.Vector; +import org.bukkit.configuration.ConfigurationSection; import de.slikey.effectlib.Effect; import de.slikey.effectlib.EffectType; @@ -47,6 +48,13 @@ public class LineEffect extends Effect { */ public double length = 0; + /** + * Sub effect at end. + * This will play a subeffect at the end location of the line + */ + private String subEffectAtEndClass = null; + public ConfigurationSection subEffectAtEnd = null; + /** * Internal boolean */ @@ -97,8 +105,8 @@ public void onRun() { loc.add(rel); loc.add(zigZagOffset); } else { - loc.subtract(zigZagOffset); loc.subtract(rel); + loc.subtract(zigZagOffset); } } if (step >= amount) { @@ -109,6 +117,17 @@ public void onRun() { loc.add(v); display(particle, loc); } + + if (subEffectAtEndClass != null) effectManager.start(subEffectAtEndClass, subEffectAtEnd, loc); + } + + @Override + protected void initialize() { + super.initialize(); + + if (subEffectAtEnd != null) { + subEffectAtEndClass = subEffectAtEnd.getString("subEffectAtEndClass"); + } } } From 9a0e1be5f2a9fa5e2cb84aa3046f40e1886f6dc5 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Wed, 10 Feb 2021 15:00:13 +0100 Subject: [PATCH 38/44] Cache effectAtEnd in LineEffect --- .../java/de/slikey/effectlib/effect/LineEffect.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slikey/effectlib/effect/LineEffect.java b/src/main/java/de/slikey/effectlib/effect/LineEffect.java index 6dd84909..69817f38 100644 --- a/src/main/java/de/slikey/effectlib/effect/LineEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/LineEffect.java @@ -65,6 +65,11 @@ public class LineEffect extends Effect { */ protected int step = 0; + /** + * Internal effectAtEnd instance + */ + protected Effect effectAtEnd = null; + public LineEffect(EffectManager effectManager) { super(effectManager); type = EffectType.REPEATING; @@ -75,6 +80,10 @@ public LineEffect(EffectManager effectManager) { @Override public void reset() { step = 0; + if (effectAtEnd != null) { + effectAtEnd.cancel(); + effectAtEnd = null; + } } @Override @@ -118,7 +127,7 @@ public void onRun() { display(particle, loc); } - if (subEffectAtEndClass != null) effectManager.start(subEffectAtEndClass, subEffectAtEnd, loc); + if (subEffectAtEndClass != null && effectAtEnd == null) effectAtEnd = effectManager.start(subEffectAtEndClass, subEffectAtEnd, loc); } @Override From 56678531c16fc9d1097f07ea07b69109516c2f02 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Wed, 10 Feb 2021 17:51:32 +0100 Subject: [PATCH 39/44] Split cached and normal subEffectAtEnd --- .../slikey/effectlib/effect/LineEffect.java | 23 +++++++++++++++---- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/slikey/effectlib/effect/LineEffect.java b/src/main/java/de/slikey/effectlib/effect/LineEffect.java index 69817f38..55e4c3b1 100644 --- a/src/main/java/de/slikey/effectlib/effect/LineEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/LineEffect.java @@ -55,6 +55,14 @@ public class LineEffect extends Effect { private String subEffectAtEndClass = null; public ConfigurationSection subEffectAtEnd = null; + /** + * Sub effect at end. + * This will play a subeffect at the end location of the line + * This effect will also be cached + */ + private String subEffectAtEndCachedClass = null; + public ConfigurationSection subEffectAtEndCached = null; + /** * Internal boolean */ @@ -68,7 +76,7 @@ public class LineEffect extends Effect { /** * Internal effectAtEnd instance */ - protected Effect effectAtEnd = null; + protected Effect effectAtEndCached = null; public LineEffect(EffectManager effectManager) { super(effectManager); @@ -80,9 +88,9 @@ public LineEffect(EffectManager effectManager) { @Override public void reset() { step = 0; - if (effectAtEnd != null) { - effectAtEnd.cancel(); - effectAtEnd = null; + if (effectAtEndCached != null) { + effectAtEndCached.cancel(); + effectAtEndCached = null; } } @@ -127,7 +135,8 @@ public void onRun() { display(particle, loc); } - if (subEffectAtEndClass != null && effectAtEnd == null) effectAtEnd = effectManager.start(subEffectAtEndClass, subEffectAtEnd, loc); + if (subEffectAtEndClass != null) effectManager.start(subEffectAtEndClass, subEffectAtEnd, loc); + if (subEffectAtEndCachedClass != null && effectAtEndCached == null) effectAtEndCached = effectManager.start(subEffectAtEndCachedClass, subEffectAtEndCached, loc); } @Override @@ -137,6 +146,10 @@ protected void initialize() { if (subEffectAtEnd != null) { subEffectAtEndClass = subEffectAtEnd.getString("subEffectAtEndClass"); } + + if (subEffectAtEndCached != null) { + subEffectAtEndCachedClass = subEffectAtEndCached.getString("subEffectAtEndCachedClass"); + } } } From 70965f2fd60ab695d069e6c1fd98a64d08fe8e0b Mon Sep 17 00:00:00 2001 From: Chronoken Date: Thu, 11 Feb 2021 15:37:15 +0100 Subject: [PATCH 40/44] get inner effect from ModifiedEffect --- src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java b/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java index c7fbb7d9..7b9ee1e0 100644 --- a/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java @@ -224,4 +224,8 @@ public void onRun() { step++; } + public Effect getInnerEffect() { + return innerEffect; + } + } From c3091ec3517c3e31bed16c83497f9dddaade09fd Mon Sep 17 00:00:00 2001 From: Chronoken Date: Wed, 3 Mar 2021 17:18:38 +0100 Subject: [PATCH 41/44] Added start time to effects --- src/main/java/de/slikey/effectlib/Effect.java | 13 +++++++++++-- .../java/de/slikey/effectlib/EffectManager.java | 1 + .../de/slikey/effectlib/effect/ModifiedEffect.java | 5 +++++ .../java/de/slikey/effectlib/effect/TextEffect.java | 2 +- .../de/slikey/effectlib/effect/TraceEffect.java | 2 +- 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/slikey/effectlib/Effect.java b/src/main/java/de/slikey/effectlib/Effect.java index 97120e0c..e016ff7a 100644 --- a/src/main/java/de/slikey/effectlib/Effect.java +++ b/src/main/java/de/slikey/effectlib/Effect.java @@ -211,6 +211,8 @@ public abstract class Effect implements Runnable { private boolean done = false; + private long startTime; + public Effect(EffectManager effectManager) { if (effectManager == null) throw new IllegalArgumentException("EffectManager cannot be null!"); @@ -227,8 +229,7 @@ protected void initialize() { try { int rgb = Integer.parseInt(str.trim().replace("#", ""), 16); colorList.add(Color.fromRGB(rgb)); - } catch (NumberFormatException ignored) { - } + } catch (NumberFormatException ignored) {} } } } @@ -497,4 +498,12 @@ public void setTargetPlayer(Player p) { targetPlayer = p; } + public long getStartTime() { + return startTime; + } + + public void setStartTime(long startTime) { + this.startTime = startTime; + } + } diff --git a/src/main/java/de/slikey/effectlib/EffectManager.java b/src/main/java/de/slikey/effectlib/EffectManager.java index 53192fad..df619d56 100644 --- a/src/main/java/de/slikey/effectlib/EffectManager.java +++ b/src/main/java/de/slikey/effectlib/EffectManager.java @@ -97,6 +97,7 @@ public void start(Effect effect) { break; } synchronized (this) { + effect.setStartTime(System.currentTimeMillis()); effects.put(effect, task); } } diff --git a/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java b/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java index 7b9ee1e0..506119e4 100644 --- a/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java @@ -132,8 +132,10 @@ public void onRun() { cancel(); return; } + innerEffect.material = material; innerEffect.materialData = materialData; + for (Map.Entry entry : parameters.entrySet()) { String equation = entry.getValue(); String fieldName = entry.getKey(); @@ -152,6 +154,7 @@ public void onRun() { effectManager.onError("Error parsing equation: " + equation, ex); continue; } + try { Field field = innerEffect.getClass().getField(fieldName); parameterTransforms.put(field, transform); @@ -160,12 +163,14 @@ public void onRun() { continue; } } + innerEffect.prepare(); if (xEquation != null) xTransform = EquationStore.getInstance().getTransform(xEquation, _variables); if (yEquation != null) yTransform = EquationStore.getInstance().getTransform(yEquation, _variables); if (zEquation != null) zTransform = EquationStore.getInstance().getTransform(zEquation, _variables); } + if (innerEffect == null) { cancel(); return; diff --git a/src/main/java/de/slikey/effectlib/effect/TextEffect.java b/src/main/java/de/slikey/effectlib/effect/TextEffect.java index 3af2e6f1..aed9e817 100644 --- a/src/main/java/de/slikey/effectlib/effect/TextEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/TextEffect.java @@ -117,7 +117,7 @@ public void onRun() { } catch (Exception ex) { // This seems to happen on bad characters in strings, // I'm choosing to ignore the exception and cancel the effect for now. - cancel(true); + cancel(); } } diff --git a/src/main/java/de/slikey/effectlib/effect/TraceEffect.java b/src/main/java/de/slikey/effectlib/effect/TraceEffect.java index a4b13ee6..baff9dd7 100644 --- a/src/main/java/de/slikey/effectlib/effect/TraceEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/TraceEffect.java @@ -62,7 +62,7 @@ public void onRun() { if (world == null) { world = location.getWorld(); } else if (!location.getWorld().equals(world)) { - cancel(true); + cancel(); return; } From dc29fdde1621f572ec02d80e3d21564c523dc4ec Mon Sep 17 00:00:00 2001 From: Chronoken Date: Thu, 4 Mar 2021 12:55:21 +0100 Subject: [PATCH 42/44] Fixed a memory leak --- src/main/java/de/slikey/effectlib/Effect.java | 5 ++++- src/main/java/de/slikey/effectlib/EffectManager.java | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/slikey/effectlib/Effect.java b/src/main/java/de/slikey/effectlib/Effect.java index e016ff7a..b211d077 100644 --- a/src/main/java/de/slikey/effectlib/Effect.java +++ b/src/main/java/de/slikey/effectlib/Effect.java @@ -266,7 +266,10 @@ public final void run() { cancel(); return; } - if (done) return; + if (done) { + effectManager.removeEffect(this); + return; + } try { if (RandomUtils.checkProbability(probability)) { diff --git a/src/main/java/de/slikey/effectlib/EffectManager.java b/src/main/java/de/slikey/effectlib/EffectManager.java index df619d56..7526285c 100644 --- a/src/main/java/de/slikey/effectlib/EffectManager.java +++ b/src/main/java/de/slikey/effectlib/EffectManager.java @@ -253,13 +253,17 @@ public void cancel(boolean callback) { } public void done(Effect effect) { + removeEffect(effect); + if (effect.callback != null && owningPlugin.isEnabled()) Bukkit.getScheduler().runTask(owningPlugin, effect.callback); + if (disposeOnTermination && effects.isEmpty()) dispose(); + } + + public void removeEffect(Effect effect) { synchronized (this) { BukkitTask existingTask = effects.get(effect); if (existingTask != null) existingTask.cancel(); effects.remove(effect); } - if (effect.callback != null && owningPlugin.isEnabled()) Bukkit.getScheduler().runTask(owningPlugin, effect.callback); - if (disposeOnTermination && effects.isEmpty()) dispose(); } @Override From 0f2248f6a9568bd88363a50f1c2f6e10b4fca417 Mon Sep 17 00:00:00 2001 From: Chronoken Date: Fri, 5 Mar 2021 15:37:23 +0100 Subject: [PATCH 43/44] Set a minimum period value if its below 1. --- src/main/java/de/slikey/effectlib/Effect.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main/java/de/slikey/effectlib/Effect.java b/src/main/java/de/slikey/effectlib/Effect.java index b211d077..0d4bf0f5 100644 --- a/src/main/java/de/slikey/effectlib/Effect.java +++ b/src/main/java/de/slikey/effectlib/Effect.java @@ -221,6 +221,8 @@ public Effect(EffectManager effectManager) { } protected void initialize() { + if (period < 1) period = 1; + if (colors != null) { colorList = new ArrayList<>(); String[] args = colors.split(","); From 83f992ab9c2db50b9ba2986459ee3480cd3f1e7a Mon Sep 17 00:00:00 2001 From: BuildTools Date: Mon, 15 Mar 2021 15:48:23 +0100 Subject: [PATCH 44/44] Upstream changes --- .../slikey/effectlib/effect/CircleEffect.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/slikey/effectlib/effect/CircleEffect.java b/src/main/java/de/slikey/effectlib/effect/CircleEffect.java index 6e257090..6826f4af 100644 --- a/src/main/java/de/slikey/effectlib/effect/CircleEffect.java +++ b/src/main/java/de/slikey/effectlib/effect/CircleEffect.java @@ -42,6 +42,17 @@ public class CircleEffect extends Effect { */ public float radius = .4f; + /** + * Used to make a partial circle + */ + public double maxAngle = Math.PI * 2; + + /** + * Start at the same location each step, use this + * along with maxAngle and wholeCircle to form persistent semicircles + */ + public boolean resetCircle = false; + /* * Current step. Works as a counter */ @@ -84,7 +95,7 @@ public void onRun() { Location location = getLocation(); location.subtract(xSubtract, ySubtract, zSubtract); - double inc = (2 * Math.PI) / particles; + double inc = maxAngle / particles; int steps = wholeCircle ? particles : 1; for (int i = 0; i < steps; i++) { @@ -99,6 +110,10 @@ public void onRun() { display(particle, location.clone().add(v)); step++; } + + if (resetCircle) { + step = 0; + } } }