Skip to content

Commit 316cba3

Browse files
author
Slikey
committed
Update to 1.4
1 parent 3d90345 commit 316cba3

File tree

6 files changed

+95
-21
lines changed

6 files changed

+95
-21
lines changed

plugin.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: EffectLib
2-
version: v1.1
2+
version: v1.2
33
description: This library supports other plugins to perform cool effects.
44
author: Slikey
55
website: http://www.kevin-carstens.de/
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package de.slikey.effectlib.effect;
2+
3+
import org.bukkit.Location;
4+
import org.bukkit.util.Vector;
5+
6+
import de.slikey.effectlib.EffectManager;
7+
import de.slikey.effectlib.EffectType;
8+
import de.slikey.effectlib.util.ParticleEffect;
9+
import de.slikey.effectlib.util.VectorUtils;
10+
11+
public class CubeLocationEffect extends LocationEffect {
12+
13+
/**
14+
* Particle of the cube
15+
*/
16+
public ParticleEffect particle = ParticleEffect.FLAME;
17+
18+
/**
19+
* Lenght of the edges
20+
*/
21+
public float edgeLenght = 3;
22+
23+
/**
24+
* Turns the cube by this angle each iteration around the x-axis
25+
*/
26+
public double angularVelocityX = Math.PI / 200;
27+
28+
/**
29+
* Turns the cube by this angle each iteration around the y-axis
30+
*/
31+
public double angularVelocityY = Math.PI / 170;
32+
33+
/**
34+
* Turns the cube by this angle each iteration around the z-axis
35+
*/
36+
public double angularVelocityZ = Math.PI / 155;
37+
38+
/**
39+
* Particles in each row
40+
*/
41+
public int particles = 8;
42+
43+
/**
44+
* Current step. Works as counter
45+
*/
46+
protected int step = 0;
47+
48+
public CubeLocationEffect(EffectManager effectManager, Location location) {
49+
super(effectManager, location);
50+
type = EffectType.REPEATING;
51+
period = 5;
52+
iterations = 200;
53+
}
54+
55+
@Override
56+
public void onRun() {
57+
double xRotation, yRotation, zRotation;
58+
xRotation = step * angularVelocityX;
59+
yRotation = step * angularVelocityY;
60+
zRotation = step * angularVelocityZ;
61+
float a = edgeLenght / 2;
62+
for (int x = 0; x <= particles; x++) {
63+
float posX = edgeLenght * ((float) x / particles) - a;
64+
for (int y = 0; y <= particles; y++) {
65+
float posY = edgeLenght * ((float) y / particles) - a;
66+
for (int z = 0; z <= particles; z++) {
67+
if (x != 0 && x != particles && y != 0 && y != particles && z != 0 && z != particles)
68+
continue;
69+
float posZ = edgeLenght * ((float) z / particles) - a;
70+
Vector v = new Vector(posX, posY, posZ);
71+
VectorUtils.rotateVector(v, xRotation, yRotation, zRotation);
72+
particle.display(location.add(v), visibleRange);
73+
location.subtract(v);
74+
}
75+
}
76+
}
77+
step++;
78+
}
79+
}

src/de/slikey/effectlib/effect/StarLocationEffect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class StarLocationEffect extends LocationEffect {
2020
/**
2121
* Particles per spike
2222
*/
23-
public int particles = 70;
23+
public int particles = 50;
2424

2525
/**
2626
* Height of the spikes in blocks

src/de/slikey/effectlib/effect/TextLocationEffect.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@ public class TextLocationEffect extends LocationEffect {
3434
/**
3535
* Each stepX pixel will be shown. Saves packets for lower fontsizes.
3636
*/
37-
public int stepX = 2;
37+
public int stepX = 1;
3838

3939
/**
4040
* Each stepY pixel will be shown. Saves packets for lower fontsizes.
4141
*/
42-
public int stepY = 2;
42+
public int stepY = 1;
4343

4444
/**
4545
* Scale the font down
4646
*/
47-
public float size = (float) 1 / 15;
47+
public float size = (float) 1 / 5;
4848

4949
protected final StringParser parser;
5050

5151
public TextLocationEffect(EffectManager effectManager, Location location) {
52-
this(effectManager, location, new Font("Tahoma", Font.PLAIN, 48));
52+
this(effectManager, location, new Font("Tahoma", Font.PLAIN, 16));
5353
}
5454

5555
public TextLocationEffect(EffectManager effectManager, Location location, Font font) {

src/de/slikey/effectlib/util/StringParser.java

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,38 +22,26 @@ public StringParser(Font font) {
2222
}
2323

2424
public BufferedImage stringToBufferedImage(String s) {
25-
//First, we have to calculate the string's width and height
26-
2725
BufferedImage img = new BufferedImage(1, 1, BufferedImage.TYPE_4BYTE_ABGR);
2826
Graphics g = img.getGraphics();
29-
30-
//Set the font to be used when drawing the string
3127
g.setFont(font);
3228

33-
//Get the string visual bounds
3429
FontRenderContext frc = g.getFontMetrics().getFontRenderContext();
3530
Rectangle2D rect = font.getStringBounds(s, frc);
36-
//Release resources
3731
g.dispose();
3832

39-
//Then, we have to draw the string on the final image
40-
41-
//Create a new image where to print the character
4233
img = new BufferedImage((int) Math.ceil(rect.getWidth()), (int) Math.ceil(rect.getHeight()), BufferedImage.TYPE_4BYTE_ABGR);
4334
g = img.getGraphics();
44-
g.setColor(Color.black); //Otherwise the text would be white
35+
g.setColor(Color.black);
4536
g.setFont(font);
4637

47-
//Calculate x and y for that string
4838
FontMetrics fm = g.getFontMetrics();
4939
int x = 0;
50-
int y = fm.getAscent(); //getAscent() = baseline
40+
int y = fm.getAscent();
41+
5142
g.drawString(s, x, y);
52-
53-
//Release resources
5443
g.dispose();
5544

56-
//Return the image
5745
return img;
5846
}
5947

src/de/slikey/effectlib/util/VectorUtils.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,13 @@ public static final Vector rotateAroundAxisZ(Vector v, double angle) {
3333
y = v.getX() * sin + v.getY() * cos;
3434
return v.setX(x).setY(y);
3535
}
36+
37+
public static final Vector rotateVector(Vector v, double angleX, double angleY, double angleZ) {
38+
rotateAroundAxisX(v, angleX);
39+
rotateAroundAxisY(v, angleY);
40+
rotateAroundAxisZ(v, angleZ);
41+
return v;
42+
}
3643

3744
public static final double angleToXAxis(Vector vector) {
3845
return Math.atan2(vector.getX(), vector.getY());

0 commit comments

Comments
 (0)