Skip to content
This repository was archived by the owner on Jan 30, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
2024414
1.13 support for BLOCK_CRACK, BLOCK_DUST, FALLING_DUST particles
Chronoken May 16, 2019
59ded33
Fixes and new features.
Chronoken Jul 21, 2019
9646fc1
CircleEffect is now rotating properly
Chronoken Apr 15, 2020
7503a6e
Fixed pitch amount
Chronoken Apr 15, 2020
0fa75a2
DonutEffect now rotates properly
Chronoken Apr 15, 2020
75e6386
Fixed pitch amount
Chronoken Apr 15, 2020
14fcf3e
Reflection Fix
Chronoken May 6, 2020
b2ce57a
Added getEffects function
Chronoken May 10, 2020
0052dfe
Cleanup
Chronoken May 10, 2020
ae19b40
More cleanup
Chronoken May 12, 2020
1e0989b
Make use of EffectManager List
Chronoken May 12, 2020
a7fed99
Cleanup
Chronoken May 12, 2020
32a9740
Possible bugfix for dispose
Chronoken May 12, 2020
ab10060
Api additions
Chronoken May 12, 2020
4a39534
More Cleanup
Chronoken May 12, 2020
0738342
Big Cleanup and new options for effects
Chronoken May 12, 2020
eb7e253
HeartEffect now rotates properly
Chronoken May 13, 2020
4972666
Revert HeartEffect fix
Chronoken May 13, 2020
9f5260a
Added SquareEffect
Chronoken Sep 26, 2020
b8f6091
Added orient parameter to the AtomEffect
Chronoken Oct 6, 2020
9ba31b1
Add probability parameter to all effects
Chronoken Oct 6, 2020
732d157
Bump version
Chronoken Oct 6, 2020
77b33f5
Added SoundEffect
Chronoken Oct 6, 2020
d41f576
Get rid of ReflectionHandler
Chronoken Oct 6, 2020
e4c320c
Allow "forever" durations
Chronoken Oct 6, 2020
a37bed6
Add support for "random" in a color parameter
Chronoken Oct 6, 2020
f94fbf0
null checks
Chronoken Nov 14, 2020
e3ba478
Use faster random
Chronoken Nov 28, 2020
342e532
Added colors parameter to all effects, separated with a comma, lets y…
Chronoken Dec 18, 2020
fdd144a
get colors more lenient
Chronoken Dec 18, 2020
87c5878
upstream changes
Chronoken Jan 15, 2021
7d3dfcf
Fix typos
Chronoken Jan 26, 2021
1aa4737
upstream changes
Chronoken Jan 26, 2021
48ff930
Display particles only when particleCount is equal or more than 0
Chronoken Jan 26, 2021
9354958
Added zigZagRelativeOffset for LineEffect
Chronoken Feb 9, 2021
9a0e49d
Upstream changes
Chronoken Feb 9, 2021
4913d52
Added subEffectAtEnd for LineEffect
Chronoken Feb 10, 2021
9a0e1be
Cache effectAtEnd in LineEffect
Chronoken Feb 10, 2021
5667853
Split cached and normal subEffectAtEnd
Chronoken Feb 10, 2021
70965f2
get inner effect from ModifiedEffect
Chronoken Feb 11, 2021
c3091ec
Added start time to effects
Chronoken Mar 3, 2021
dc29fdd
Fixed a memory leak
Chronoken Mar 4, 2021
0f2248f
Set a minimum period value if its below 1.
Chronoken Mar 5, 2021
83f992a
Upstream changes
invalid-email-address Mar 15, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion EffectLib.doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
26 changes: 13 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.slikey</groupId>
<artifactId>EffectLib</artifactId>
<version>6.2-SNAPSHOT</version>
<version>7.0</version>

<name>EffectLib</name>
<url>http://www.kevin-carstens.de/</url>
Expand All @@ -29,11 +29,12 @@
<distributionManagement>
<repository>
<id>maven.elmakers.com</id>
<url>http://maven.elmakers.com/repository/</url>
<url>https://maven.elmakers.com/repository/</url>
</repository>

<snapshotRepository>
<id>maven.elmakers.com</id>
<url>http://maven.elmakers.com/repository/</url>
<url>https://maven.elmakers.com/repository/</url>
</snapshotRepository>
</distributionManagement>

Expand All @@ -46,14 +47,12 @@

<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.13-R0.1-SNAPSHOT</version>
<!-- for testing backwards-compat
<version>1.9-R0.1-SNAPSHOT</version>
-->
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.16.4-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>net.objecthunter</groupId>
<artifactId>exp4j</artifactId>
Expand All @@ -75,16 +74,17 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<version>3.8.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
<source>7</source>
<target>7</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.5</version>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
Expand Down
179 changes: 111 additions & 68 deletions src/main/java/de/slikey/effectlib/Effect.java
Original file line number Diff line number Diff line change
@@ -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.
*
Expand All @@ -28,6 +39,9 @@ public abstract class Effect implements Runnable {
*/
public Color color = null;

public List<Color> 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.
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -192,24 +211,43 @@ 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() {
cancel(true);
}

public final void cancel(boolean callback) {
if (callback) {
done();
} else {
done = true;
}
if (callback) done();
else done = true;
}

public final boolean isDone() {
Expand All @@ -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();
}
Expand All @@ -257,7 +296,7 @@ public final void run() {
* state can be reset.
*/
protected void reset() {
this.done = false;
done = false;
}

public void prepare() {
Expand Down Expand Up @@ -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);
Expand All @@ -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) {
Expand All @@ -387,45 +411,50 @@ 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) {
display(particle, location, color, particleData != 0 ? particleData : speed, particleCount);
}

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<Player>();
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() {
Expand Down Expand Up @@ -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;
}

}
Loading