Skip to content

Commit 4398b5b

Browse files
committed
update: 新增播放功能, 目前可播放的特效对象将会实现 Playable 接口
1 parent e09c8e1 commit 4398b5b

9 files changed

Lines changed: 342 additions & 72 deletions

File tree

src/top/zoyn/particlelib/ParticleLib.java

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
import org.bukkit.entity.Player;
1212
import org.bukkit.plugin.java.JavaPlugin;
1313
import org.bukkit.util.Vector;
14+
import top.zoyn.particlelib.pobject.Arc;
15+
import top.zoyn.particlelib.pobject.Astroid;
1416
import top.zoyn.particlelib.pobject.Circle;
1517
import top.zoyn.particlelib.pobject.Grid;
1618
import top.zoyn.particlelib.utils.projector.ThreeDProjector;
@@ -67,10 +69,10 @@ public static void showBorderAndGridAboutBlock(Block block, Particle particle) {
6769
high.clone().add(0, 0, 5));
6870

6971
Grid grid = new Grid(low, lowers.get(2), 1.4D);
70-
grid.setParticle(Particle.FLAME);
72+
grid.setParticle(Particle.FIREWORKS_SPARK);
7173
grid.show();
7274
Grid grid2 = new Grid(high, highers.get(2), 1.4D);
73-
grid2.setParticle(Particle.FLAME);
75+
grid2.setParticle(Particle.FIREWORKS_SPARK);
7476
grid2.show();
7577
for (int i = 0; i < lowers.size(); i++) {
7678
Location origin = lowers.get(i);
@@ -97,7 +99,7 @@ public static void showBorderAndGridAboutBlock(Block block, Particle particle) {
9799
}
98100
// 绘制网格面
99101
Grid grid3 = new Grid(origin, topNext, 1.4D);
100-
grid3.setParticle(Particle.FLAME);
102+
grid3.setParticle(Particle.FIREWORKS_SPARK);
101103
grid3.show();
102104
}
103105
}
@@ -117,8 +119,29 @@ public void onDisable() {
117119
public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
118120
Player player = (Player) sender;
119121

120-
Location location = player.getLocation().clone();
121-
Bukkit.getScheduler().runTaskTimer(this, () -> showBorderAndGridAboutBlock(location.getBlock(), Particle.VILLAGER_HAPPY), 0L, 10L);
122+
// Location location = player.getLocation().clone();
123+
// Bukkit.getScheduler().runTaskTimer(this, () -> showBorderAndGridAboutBlock(location.getBlock(), Particle.FIREWORKS_SPARK), 0L, 10L);
124+
125+
126+
// Circle circle = new Circle(player.getLocation());
127+
// circle.setStep(10D);
128+
// circle.setRadius(3D);
129+
// circle.setPeriod(2);
130+
// circle.play();
131+
// circle.alwaysPlayAsync();
132+
133+
// Astroid astroid = new Astroid(player.getLocation());
134+
// astroid.setParticle(Particle.FIREWORKS_SPARK);
135+
// astroid.setRadius(1.3D);
136+
// astroid.setStep(10D);
137+
// astroid.setPeriod(1L);
138+
// astroid.alwaysPlayAsync();
139+
140+
// Arc arc = new Arc(player.getLocation());
141+
// arc.setAngle(360D);
142+
// arc.setStep(15D);
143+
// arc.setPeriod(2L);
144+
// arc.alwaysPlayAsync();
122145

123146
// Grid grid = new Grid(player.getLocation(), player.getLocation().add(5, 0, 5), 1.2D);
124147
//

src/top/zoyn/particlelib/pobject/Arc.java

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package top.zoyn.particlelib.pobject;
22

33
import org.bukkit.Location;
4+
import org.bukkit.scheduler.BukkitRunnable;
5+
import top.zoyn.particlelib.ParticleLib;
46

57
/**
68
* 表示一个弧
79
*
810
* @author Zoyn
911
*/
10-
public class Arc extends ParticleObject {
12+
public class Arc extends ParticleObject implements Playable {
1113

14+
private final boolean isDone = true;
1215
private double angle;
1316
private double radius;
1417
private double step;
18+
private double currentAngle = 0D;
1519

1620
public Arc(Location origin) {
1721
this(origin, 30D);
@@ -65,6 +69,41 @@ public void show() {
6569
}
6670
}
6771

72+
@Override
73+
public void play() {
74+
new BukkitRunnable() {
75+
@Override
76+
public void run() {
77+
// 进行关闭
78+
if (currentAngle > angle) {
79+
cancel();
80+
return;
81+
}
82+
currentAngle += step;
83+
double radians = Math.toRadians(currentAngle);
84+
double x = radius * Math.cos(radians);
85+
double z = radius * Math.sin(radians);
86+
87+
spawnParticle(getOrigin().clone().add(x, 0, z));
88+
}
89+
}.runTaskTimer(ParticleLib.getInstance(), 0, getPeriod());
90+
}
91+
92+
@Override
93+
public void playNextPoint() {
94+
currentAngle += step;
95+
double radians = Math.toRadians(currentAngle);
96+
double x = radius * Math.cos(radians);
97+
double z = radius * Math.sin(radians);
98+
99+
spawnParticle(getOrigin().clone().add(x, 0, z));
100+
101+
// 进行重置
102+
if (currentAngle > angle) {
103+
currentAngle = 0D;
104+
}
105+
}
106+
68107
public double getAngle() {
69108
return angle;
70109
}

src/top/zoyn/particlelib/pobject/Astroid.java

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,20 @@
11
package top.zoyn.particlelib.pobject;
22

33
import org.bukkit.Location;
4+
import org.bukkit.scheduler.BukkitRunnable;
5+
import top.zoyn.particlelib.ParticleLib;
46

57
/**
68
* 表示一个星形线
79
*
810
* @author Zoyn
911
*/
10-
public class Astroid extends ParticleObject {
12+
public class Astroid extends ParticleObject implements Playable {
1113

1214
private double radius;
15+
private double step;
16+
17+
private double currentT = 0D;
1318

1419
/**
1520
* 构造一个星形线
@@ -27,21 +32,18 @@ public Astroid(Location origin) {
2732
* @param origin 原点
2833
*/
2934
public Astroid(double radius, Location origin) {
30-
this.radius = radius;
31-
setOrigin(origin);
32-
}
33-
34-
public double getRadius() {
35-
return radius;
35+
this(1D, origin, 10);
3636
}
3737

38-
public void setRadius(double radius) {
38+
public Astroid(double radius, Location origin, double step) {
3939
this.radius = radius;
40+
this.step = step;
41+
setOrigin(origin);
4042
}
4143

4244
@Override
4345
public void show() {
44-
for (double t = 0.0D; t < 360.0D; t++) {
46+
for (double t = 0.0D; t < 360.0D; t += step) {
4547
double radians = Math.toRadians(t);
4648
// 计算公式
4749
double x = Math.pow(this.radius * Math.cos(radians), 3.0D);
@@ -51,4 +53,56 @@ public void show() {
5153
}
5254
}
5355

56+
@Override
57+
public void play() {
58+
new BukkitRunnable() {
59+
@Override
60+
public void run() {
61+
// 重置
62+
if (currentT > 360D) {
63+
cancel();
64+
return;
65+
}
66+
currentT += step;
67+
double radians = Math.toRadians(currentT);
68+
// 计算公式
69+
double x = Math.pow(getRadius() * Math.cos(radians), 3.0D);
70+
double z = Math.pow(getRadius() * Math.sin(radians), 3.0D);
71+
72+
spawnParticle(getOrigin().clone().add(x, 0, z));
73+
}
74+
}.runTaskTimer(ParticleLib.getInstance(), 0, getPeriod());
75+
}
76+
77+
@Override
78+
public void playNextPoint() {
79+
currentT += step;
80+
double radians = Math.toRadians(currentT);
81+
// 计算公式
82+
double x = Math.pow(this.radius * Math.cos(radians), 3.0D);
83+
double z = Math.pow(this.radius * Math.sin(radians), 3.0D);
84+
85+
spawnParticle(getOrigin().clone().add(x, 0, z));
86+
87+
// 重置
88+
if (currentT > 360D) {
89+
currentT = 0D;
90+
}
91+
}
92+
93+
public double getRadius() {
94+
return radius;
95+
}
96+
97+
public void setRadius(double radius) {
98+
this.radius = radius;
99+
}
100+
101+
public double getStep() {
102+
return step;
103+
}
104+
105+
public void setStep(double step) {
106+
this.step = step;
107+
}
54108
}

src/top/zoyn/particlelib/pobject/Circle.java

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
*
88
* @author Zoyn
99
*/
10-
public class Circle extends ParticleObject {
10+
public class Circle extends ParticleObject implements Playable {
1111

1212
private final Arc fullArc;
1313

@@ -52,6 +52,16 @@ public void show() {
5252
fullArc.show();
5353
}
5454

55+
@Override
56+
public void play() {
57+
fullArc.play();
58+
}
59+
60+
@Override
61+
public void playNextPoint() {
62+
fullArc.playNextPoint();
63+
}
64+
5565
@Override
5666
public void alwaysShow() {
5767
fullArc.alwaysShow();
@@ -66,6 +76,20 @@ public void alwaysShowAsync() {
6676
setShowType(ShowType.ALWAYS_SHOW_ASYNC);
6777
}
6878

79+
@Override
80+
public void alwaysPlay() {
81+
fullArc.alwaysPlay();
82+
// 再设置Circle自身的ShowType
83+
setShowType(ShowType.ALWAYS_PLAY);
84+
}
85+
86+
@Override
87+
public void alwaysPlayAsync() {
88+
fullArc.alwaysPlayAsync();
89+
// 再设置Circle自身的ShowType
90+
setShowType(ShowType.ALWAYS_PLAY_ASYNC);
91+
}
92+
6993
@Override
7094
public void turnOffTask() {
7195
fullArc.turnOffTask();

src/top/zoyn/particlelib/pobject/Heart.java

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,21 @@
11
package top.zoyn.particlelib.pobject;
22

3-
import org.bukkit.Color;
43
import org.bukkit.Location;
5-
import org.bukkit.Particle;
4+
import org.bukkit.scheduler.BukkitRunnable;
5+
import top.zoyn.particlelib.ParticleLib;
66

77
/**
88
* 表示一颗心
99
*
1010
* @author Zoyn
1111
*/
12-
public class Heart extends ParticleObject {
12+
public class Heart extends ParticleObject implements Playable {
1313

1414
private double xScaleRate;
1515
private double yScaleRate;
1616

17+
private double currentT = -1.0D;
18+
1719
/**
1820
* 构造一个小心心
1921
*
@@ -28,7 +30,7 @@ public Heart(Location origin) {
2830
*
2931
* @param xScaleRate X轴缩放比率
3032
* @param yScaleRate Y轴缩放比率
31-
* @param origin 原点
33+
* @param origin 原点
3234
*/
3335
public Heart(double xScaleRate, double yScaleRate, Location origin) {
3436
this.xScaleRate = xScaleRate;
@@ -60,12 +62,36 @@ public void show() {
6062

6163
spawnParticle(getOrigin().clone().add(x, 0, y));
6264
}
63-
// for (double t = 0.0D; t < 360.0D; t++) {
64-
// double x = xScaleRate * 16 * Math.pow(Math.sin(t), 3);
65-
// double z = yScaleRate * 13 * Math.cos(t) - 5 * Math.cos(2 * t) - 2 * Math.cos(3 * t) - Math.cos(4 * t);
66-
//
67-
// spawnParticle(getOrigin().clone().add(x, 0, z));
68-
// }
6965
}
7066

71-
}
67+
@Override
68+
public void play() {
69+
new BukkitRunnable() {
70+
@Override
71+
public void run() {
72+
if (currentT > 1.0D) {
73+
cancel();
74+
return;
75+
}
76+
currentT += 0.001D;
77+
double x = xScaleRate * Math.sin(currentT) * Math.cos(currentT) * Math.log(Math.abs(currentT));
78+
double y = yScaleRate * Math.sqrt(Math.abs(currentT)) * Math.cos(currentT);
79+
80+
spawnParticle(getOrigin().clone().add(x, 0, y));
81+
}
82+
}.runTaskTimer(ParticleLib.getInstance(), 0, getPeriod());
83+
}
84+
85+
@Override
86+
public void playNextPoint() {
87+
currentT += 0.001D;
88+
double x = xScaleRate * Math.sin(currentT) * Math.cos(currentT) * Math.log(Math.abs(currentT));
89+
double y = yScaleRate * Math.sqrt(Math.abs(currentT)) * Math.cos(currentT);
90+
91+
spawnParticle(getOrigin().clone().add(x, 0, y));
92+
93+
if (currentT > 1.0D) {
94+
currentT = -1.0D;
95+
}
96+
}
97+
}

0 commit comments

Comments
 (0)