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 ed969656..ada2784b 100644
--- a/pom.xml
+++ b/pom.xml
@@ -3,7 +3,7 @@
4.0.0
de.slikey
EffectLib
- 6.2-SNAPSHOT
+ 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/
@@ -46,14 +47,12 @@
- org.bukkit
- bukkit
- 1.13-R0.1-SNAPSHOT
-
+ org.spigotmc
+ spigot-api
+ 1.16.4-R0.1-SNAPSHOT
provided
+
net.objecthunter
exp4j
@@ -75,16 +74,17 @@
org.apache.maven.plugins
maven-compiler-plugin
- 3.3
+ 3.8.1
- 1.6
- 1.6
+ 7
+ 7
+
org.apache.maven.plugins
maven-shade-plugin
- 1.5
+ 3.2.4
package
diff --git a/src/main/java/de/slikey/effectlib/Effect.java b/src/main/java/de/slikey/effectlib/Effect.java
index eb4fcf66..0d4bf0f5 100644
--- a/src/main/java/de/slikey/effectlib/Effect.java
+++ b/src/main/java/de/slikey/effectlib/Effect.java
@@ -1,20 +1,31 @@
package de.slikey.effectlib;
-import de.slikey.effectlib.util.DynamicLocation;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.concurrent.ThreadLocalRandom;
-import org.bukkit.Particle;
import org.bukkit.Color;
-import org.bukkit.Location;
import org.bukkit.Material;
+import org.bukkit.Particle;
+import org.bukkit.Location;
+import org.bukkit.util.Vector;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
-import org.bukkit.util.Vector;
+import org.bukkit.configuration.ConfigurationSection;
-import java.util.ArrayList;
-import java.util.List;
+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.
*
@@ -28,6 +39,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.
@@ -74,6 +88,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.
*
@@ -192,12 +211,34 @@ 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!");
- }
+ if (effectManager == null) throw new IllegalArgumentException("EffectManager cannot be null!");
+
this.effectManager = effectManager;
- this.visibleRange = effectManager.getParticleRange();
+ visibleRange = effectManager.getParticleRange();
+ }
+
+ protected void initialize() {
+ if (period < 1) period = 1;
+
+ if (colors != null) {
+ colorList = new ArrayList<>();
+ String[] args = colors.split(",");
+ if (args.length >= 1) {
+ for (String str : args) {
+ try {
+ int rgb = Integer.parseInt(str.trim().replace("#", ""), 16);
+ colorList.add(Color.fromRGB(rgb));
+ } catch (NumberFormatException ignored) {}
+ }
+ }
+ }
+
+ if (subEffect != null) {
+ subEffectClass = subEffect.getString("subEffectClass");
+ }
}
public final void cancel() {
@@ -205,11 +246,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() {
@@ -231,22 +269,23 @@ public final void run() {
return;
}
if (done) {
+ effectManager.removeEffect(this);
return;
}
+
try {
- onRun();
+ if (RandomUtils.checkProbability(probability)) {
+ 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 +296,7 @@ public final void run() {
* state can be reset.
*/
protected void reset() {
- this.done = false;
+ done = false;
}
public void prepare() {
@@ -323,17 +362,12 @@ 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,32 +381,22 @@ 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 && targetOffset != null) target.addOffset(targetOffset);
+ if (target == null) return;
+ target.setUpdateLocation(updateLocations);
+ target.setUpdateDirection(updateDirections);
}
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,28 +411,22 @@ 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) {
- display(effect, location, this.color);
+ display(effect, location, color);
}
protected void display(Particle particle, Location location, Color color) {
@@ -416,16 +434,27 @@ 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) {
- 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()));
+ }
+
+ 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, color, material, materialData, visibleRange, targetPlayers);
+
+ if (subEffectClass != null) effectManager.start(subEffectClass, subEffect, location);
}
private void done() {
@@ -466,6 +495,20 @@ 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 targetPlayer;
+ }
+
+ 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/EffectLib.java b/src/main/java/de/slikey/effectlib/EffectLib.java
index afe78adb..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;
@@ -128,7 +129,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 d69ec7e5..7526285c 100644
--- a/src/main/java/de/slikey/effectlib/EffectManager.java
+++ b/src/main/java/de/slikey/effectlib/EffectManager.java
@@ -1,43 +1,37 @@
package de.slikey.effectlib;
-import de.slikey.effectlib.math.Transforms;
-import de.slikey.effectlib.util.ConfigUtils;
-import de.slikey.effectlib.util.Disposable;
-import de.slikey.effectlib.util.DynamicLocation;
-import de.slikey.effectlib.util.ImageLoadCallback;
-import de.slikey.effectlib.util.ImageLoadTask;
-import de.slikey.effectlib.util.ParticleDisplay;
+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 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;
+import de.slikey.effectlib.util.*;
+
/**
* Dispose the EffectManager if you don't need him anymore.
*
@@ -46,31 +40,31 @@
*/
public class EffectManager implements Disposable {
- private static List effectManagers;
- private static Map> effectClasses = new HashMap>();
- private final Plugin owningPlugin;
- private final Map effects;
+ private static List effectManagers = new ArrayList<>();
+ private static Map> effectClasses = new HashMap<>();
+ 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;
- Transforms.setEffectManager(this);
- effects = new HashMap();
+ effects = new HashMap<>();
disposed = false;
disposeOnTermination = false;
+ effectManagers.add(this);
}
private ParticleDisplay getDisplay() {
- if (display == null) {
- display = ParticleDisplay.newInstance();
- }
+ if (display == null) display = ParticleDisplay.newInstance();
+
display.setManager(this);
return display;
@@ -81,45 +75,29 @@ 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) {
+ effect.setStartTime(System.currentTimeMillis());
effects.put(effect, task);
}
}
@@ -181,9 +159,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,26 +184,37 @@ 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;
+
+ // 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;
- }
+ 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());
}
}
+ effect.initialize();
+
effect.setDynamicOrigin(origin);
effect.setDynamicTarget(target);
- if (targetPlayer != null)
- effect.setTargetPlayer(targetPlayer);
+ if (targetPlayer != null) effect.setTargetPlayer(targetPlayer);
return effect;
}
@@ -235,9 +222,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,53 +240,56 @@ 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);
}
}
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();
- }
+ 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
public void dispose() {
- if (disposed) {
- return;
- }
+ if (disposed) return;
disposed = true;
cancel(false);
- if (effectManagers != null) {
- effectManagers.remove(this);
- }
+ effects = null;
+ display = null;
+ imageCache = null;
+ owningPlugin = null;
+ imageCacheFolder = null;
+ effectManagers.remove(this);
}
public void disposeOnTermination() {
disposeOnTermination = true;
- if (effects.isEmpty()) {
- dispose();
- }
+ if (effects.isEmpty()) dispose();
+ }
+
+ public boolean isDisposed() {
+ return disposed;
+ }
+
+ public boolean isDisposedOnTermination() {
+ return disposeOnTermination;
}
public void enableDebug(boolean enable) {
@@ -313,21 +301,19 @@ 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() {
+ return effects;
}
public int getParticleRange() {
@@ -348,40 +334,68 @@ 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)) {
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));
+ 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);
} 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 {
+ if (value.startsWith("#")) value = value.substring(1);
+ rgb = Integer.parseInt(value, 16);
+ }
Color color = Color.fromRGB(rgb);
field.set(effect, color);
} catch (Exception ex) {
@@ -447,36 +461,35 @@ 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;
}
return true;
} catch (Exception ex) {
- this.onError(ex);
+ onError(ex);
}
return false;
}
-
- public static void initialize() {
- effectManagers = new ArrayList();
- }
-
+
public static List getManagers() {
- 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();
}
}
@@ -512,4 +525,5 @@ public void run() {
public void registerEffectClass(String key, Class extends Effect> effectClass) {
effectClasses.put(key, effectClass);
}
+
}
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..bbdbcf94 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 {
@@ -59,6 +60,8 @@ public class AtomEffect extends Effect {
*/
public double angularVelocity = Math.PI / 80d;
+ public boolean orient = false;
+
/**
* Internal counter
*/
@@ -73,7 +76,7 @@ public AtomEffect(EffectManager effectManager) {
@Override
public void reset() {
- this.step = 0;
+ step = 0;
}
@Override
@@ -81,10 +84,12 @@ 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);
}
+
for (int i = 0; i < particlesOrbital; i++) {
double angle = step * angularVelocity;
for (int j = 0; j < orbitals; j++) {
@@ -92,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);
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 7a7ccd38..6826f4af 100644
--- a/src/main/java/de/slikey/effectlib/effect/CircleEffect.java
+++ b/src/main/java/de/slikey/effectlib/effect/CircleEffect.java
@@ -1,15 +1,16 @@
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.MathUtils;
+import de.slikey.effectlib.util.VectorUtils;
+public class CircleEffect extends Effect {
/*
* ParticleType of spawned particle
@@ -22,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;
@@ -41,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
*/
@@ -75,27 +87,33 @@ 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;
+
+ double inc = maxAngle / particles;
int steps = wholeCircle ? particles : 1;
+
for (int i = 0; i < steps; i++) {
double angle = step * inc;
Vector v = new Vector();
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);
+ 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));
step++;
}
+
+ if (resetCircle) {
+ step = 0;
+ }
}
}
diff --git a/src/main/java/de/slikey/effectlib/effect/CloudEffect.java b/src/main/java/de/slikey/effectlib/effect/CloudEffect.java
index 2c726ba1..2561dd2d 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,11 +17,14 @@ 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
@@ -37,6 +41,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;
@@ -48,25 +55,26 @@ 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, 0, 7);
+ display(cloudParticle, location.add(v), cloudColor, cloudSpeed, 1);
location.subtract(v);
}
- Location l = location.add(0, .2, 0);
- for (int i = 0; i < 15; i++) {
+
+ Location l;
+ if (increaseHeight) l = location.add(0, 0.2, 0);
+ else l = location;
+
+ 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;
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/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/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/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 ae33bda2..6df63187 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,10 +63,13 @@ public void onRun() {
v.setZ(radiusTube * Math.sin(phi));
VectorUtils.rotateVector(v, xRotation, yRotation, zRotation);
+ VectorUtils.rotateAroundAxisX(v, (location.getPitch() + 90) * MathUtils.degreesToRadians);
+ VectorUtils.rotateAroundAxisY(v, -location.getYaw() * MathUtils.degreesToRadians);
display(particle, location.add(v));
location.subtract(v);
}
}
}
+
}
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..8e9dbab2 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 {
@@ -50,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;
@@ -81,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/HeartEffect.java b/src/main/java/de/slikey/effectlib/effect/HeartEffect.java
index 843a98d7..c8b87c81 100644
--- a/src/main/java/de/slikey/effectlib/effect/HeartEffect.java
+++ b/src/main/java/de/slikey/effectlib/effect/HeartEffect.java
@@ -1,12 +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.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 a 2D Heart in 3D space. Thanks to the author for sharing it!
@@ -48,27 +50,29 @@ public class HeartEffect extends Effect {
/**
* Compilation of the heart. (2)
*/
- public float compilaction = 2F;
+ public float compilation = 2F;
public HeartEffect(EffectManager effectManager) {
super(effectManager);
+ type = EffectType.REPEATING;
+ iterations = 200;
+ period = 5;
}
@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 / compilaction) / particles) * i;
- double phi = Math.pow(Math.abs(MathUtils.sin(2 * compilaction * alpha)) + factorInnerSpike * Math.abs(MathUtils.sin(compilaction * alpha)), 1 / compressYFactorTotal);
-
- vector.setY(phi * (MathUtils.sin(alpha) + MathUtils.cos(alpha)) * yFactor);
- vector.setZ(phi * (MathUtils.cos(alpha) - MathUtils.sin(alpha)) * xFactor);
+ 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);
- VectorUtils.rotateVector(vector, xRotation, yRotation, zRotation);
+ v.setY(phi * (MathUtils.sin(alpha) + MathUtils.cos(alpha)) * yFactor);
+ v.setZ(phi * (MathUtils.cos(alpha) - MathUtils.sin(alpha)) * xFactor);
- display(particle, location.add(vector));
- location.subtract(vector);
+ VectorUtils.rotateVector(v, xRotation, yRotation, zRotation);
+ display(particle, location.add(v));
+ location.subtract(v);
}
}
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 cbd14607..d6c5321a 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 {
@@ -22,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..55e4c3b1 100644
--- a/src/main/java/de/slikey/effectlib/effect/LineEffect.java
+++ b/src/main/java/de/slikey/effectlib/effect/LineEffect.java
@@ -1,11 +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 org.bukkit.util.Vector;
+import org.bukkit.configuration.ConfigurationSection;
+
+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 {
@@ -27,7 +30,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
@@ -40,6 +48,21 @@ 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;
+
+ /**
+ * 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
*/
@@ -50,6 +73,11 @@ public class LineEffect extends Effect {
*/
protected int step = 0;
+ /**
+ * Internal effectAtEnd instance
+ */
+ protected Effect effectAtEndCached = null;
+
public LineEffect(EffectManager effectManager) {
super(effectManager);
type = EffectType.REPEATING;
@@ -59,18 +87,21 @@ public LineEffect(EffectManager effectManager) {
@Override
public void reset() {
- this.step = 0;
+ step = 0;
+ if (effectAtEndCached != null) {
+ effectAtEndCached.cancel();
+ effectAtEndCached = null;
+ }
}
@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();
@@ -83,26 +114,42 @@ 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) {
+ rel = VectorUtils.rotateVector(zigZagRelativeOffset, loc);
if (zag) {
+ loc.add(rel);
loc.add(zigZagOffset);
} else {
+ loc.subtract(rel);
loc.subtract(zigZagOffset);
}
}
if (step >= amount) {
- if (zag) {
- zag = false;
- } else {
- zag = true;
- }
+ zag = !zag;
step = 0;
}
step++;
loc.add(v);
display(particle, loc);
}
+
+ if (subEffectAtEndClass != null) effectManager.start(subEffectAtEndClass, subEffectAtEnd, loc);
+ if (subEffectAtEndCachedClass != null && effectAtEndCached == null) effectAtEndCached = effectManager.start(subEffectAtEndCachedClass, subEffectAtEndCached, loc);
+ }
+
+ @Override
+ protected void initialize() {
+ super.initialize();
+
+ if (subEffectAtEnd != null) {
+ subEffectAtEndClass = subEffectAtEnd.getString("subEffectAtEndClass");
+ }
+
+ if (subEffectAtEndCached != null) {
+ subEffectAtEndCachedClass = subEffectAtEndCached.getString("subEffectAtEndCachedClass");
+ }
}
}
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..506119e4 100644
--- a/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java
+++ b/src/main/java/de/slikey/effectlib/effect/ModifiedEffect.java
@@ -1,27 +1,28 @@
package de.slikey.effectlib.effect;
+import java.util.Map;
+import java.util.List;
+import java.util.Arrays;
+import java.util.HashMap;
+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 String[] _variables = {"t", "i", "a", "b"};
+ private final static List variables = Arrays.asList(_variables);
/**
* The base configuration of the inner effect.
@@ -50,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
@@ -68,11 +79,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 +100,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 +119,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();
@@ -126,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();
@@ -146,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);
@@ -154,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;
@@ -167,42 +178,36 @@ 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);
- } 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);
}
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)) {
- 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 +228,9 @@ public void onRun() {
}
step++;
}
+
+ public Effect getInnerEffect() {
+ return innerEffect;
+ }
+
}
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/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/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/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/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/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/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/effect/SphereEffect.java b/src/main/java/de/slikey/effectlib/effect/SphereEffect.java
index b5fd0d57..a09a90b3 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 {
/**
@@ -29,12 +30,15 @@ public class SphereEffect extends Effect {
* 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 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/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/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..aed9e817 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));
@@ -117,20 +117,16 @@ 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();
}
}
-
- // 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 c6be35e6..03842e58 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
@@ -59,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
*/
@@ -79,10 +98,10 @@ 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, 0, 7);
+ display(cloudParticle, l.add(v), cloudColor, cloudSpeed, 1);
l.subtract(v);
}
}
@@ -95,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++;
@@ -104,10 +124,10 @@ public void onRun() {
l.subtract(0, yOffset, 0);
}
- public ArrayList createCircle(double y, double radius) {
- double amount = radius * 64;
+ public List createCircle(double y, double radius) {
+ double amount = radius * circleParticles;
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/effect/TraceEffect.java b/src/main/java/de/slikey/effectlib/effect/TraceEffect.java
index 0b87fe61..baff9dd7 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
@@ -60,25 +62,19 @@ public void onRun() {
if (world == null) {
world = location.getWorld();
} else if (!location.getWorld().equals(world)) {
- cancel(true);
+ cancel();
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..0d01e31f 100644
--- a/src/main/java/de/slikey/effectlib/math/EquationStore.java
+++ b/src/main/java/de/slikey/effectlib/math/EquationStore.java
@@ -1,13 +1,16 @@
package de.slikey.effectlib.math;
-import java.util.HashMap;
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 {
+
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);
@@ -24,36 +27,35 @@ 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();
- }
+ 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..864d9c41 100644
--- a/src/main/java/de/slikey/effectlib/math/EquationTransform.java
+++ b/src/main/java/de/slikey/effectlib/math/EquationTransform.java
@@ -1,21 +1,24 @@
package de.slikey.effectlib.math;
+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;
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;
private static Function maxFunction;
private static Function selectFunction;
- private final Set inputVariables;
+ private final Collection inputVariables;
private Exception exception;
@Override
@@ -24,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) {
@@ -94,35 +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;
- }
+ 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;
- }
+ if (expression == null) return 0;
+
int index = 0;
for (String inputVariable : inputVariables) {
expression.setVariable(inputVariable, t[index]);
@@ -130,7 +131,7 @@ public double get(double... t) {
}
return get();
}
-
+
public void addVariable(String key) {
inputVariables.add(key);
}
@@ -142,9 +143,8 @@ public void setVariable(String key, double value) {
}
public double get() {
- if (expression == null) {
- return Double.NaN;
- }
+ if (expression == null) return Double.NaN;
+
double value = Double.NaN;
try {
exception = null;
@@ -154,7 +154,7 @@ public double get() {
}
return value;
}
-
+
public Exception getException() {
return exception;
}
@@ -162,8 +162,9 @@ 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/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 5a84c867..7cd9e5a1 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.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;
+import org.bukkit.configuration.ConfigurationSection;
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 = EffectManager.getManagers();
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/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
deleted file mode 100644
index d0c70483..00000000
--- a/src/main/java/de/slikey/effectlib/particle/ReflectionHandler.java
+++ /dev/null
@@ -1,594 +0,0 @@
-package de.slikey.effectlib.particle;
-
-import java.lang.reflect.Constructor;
-import java.lang.reflect.Field;
-import java.lang.reflect.Method;
-import java.util.HashMap;
-import java.util.Map;
-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, DataType>();
- 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;
- }
- }
-
-}
diff --git a/src/main/java/de/slikey/effectlib/util/BaseImageEffect.java b/src/main/java/de/slikey/effectlib/util/BaseImageEffect.java
index 2886ba7a..ddcfb0b2 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 {
@@ -119,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) {
@@ -140,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;
@@ -158,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();
@@ -170,12 +169,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;
@@ -212,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);
}
@@ -223,9 +218,9 @@ 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 99914154..ac4b4dfa 100644
--- a/src/main/java/de/slikey/effectlib/util/ConfigUtils.java
+++ b/src/main/java/de/slikey/effectlib/util/ConfigUtils.java
@@ -1,16 +1,17 @@
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