Skip to content

Commit 27134cc

Browse files
committed
Merge branch 'development'
2 parents b9718cd + 0362a14 commit 27134cc

22 files changed

+431
-425
lines changed

src/main/java/com/sucy/skill/api/particle/EffectPlayer.java

+4-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public class EffectPlayer {
5050

5151
public static final String P_TYPE = "-particle-type";
5252
public static final String MAT = "-particle-material";
53+
public static final String DURABILITY = "-particle-durability";
5354
public static final String DATA = "-particle-data";
5455
public static final String AMOUNT = "-particle-amount";
5556
public static final String DX = "-particle-dx";
@@ -128,7 +129,9 @@ private void makeEffect(String key, boolean noPrefix) {
128129
(float) settings.getDouble(keyMod + SPEED, 1),
129130
settings.getInt(keyMod + AMOUNT, 1),
130131
Material.matchMaterial(settings.getString(keyMod + MAT, "DIRT")),
131-
settings.getInt(keyMod + DATA, 0)
132+
settings.getInt(keyMod + DATA, 0),
133+
settings.getInt(keyMod + DURABILITY, 0)
134+
132135
);
133136
} catch (Exception ex) {
134137
Logger.invalid("Bad material for particle effect - " + settings.getString(keyMod + MAT));

src/main/java/com/sucy/skill/api/particle/Particle.java

+9-10
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@
3535
import org.bukkit.Material;
3636
import org.bukkit.entity.Player;
3737
import org.bukkit.inventory.ItemStack;
38+
import org.bukkit.inventory.meta.Damageable;
3839
import org.bukkit.inventory.meta.ItemMeta;
39-
import org.bukkit.material.MaterialData;
4040

4141
import java.lang.reflect.Constructor;
4242
import java.lang.reflect.Method;
43-
import java.util.ArrayList;
4443
import java.util.Arrays;
4544
import java.util.HashMap;
4645
import java.util.List;
@@ -308,7 +307,7 @@ public static boolean usesData(org.bukkit.Particle particle) {
308307

309308
// Supported version for 1.13+
310309
public static void play(
311-
ArrayList<Player> players,
310+
List<Player> players,
312311
org.bukkit.Particle particle,
313312
double x,
314313
double y,
@@ -319,7 +318,8 @@ public static void play(
319318
double dz,
320319
double speed,
321320
Material material,
322-
int data) {
321+
int data,
322+
int durability) {
323323
Object object = null;
324324
switch (particle) {
325325
case REDSTONE:
@@ -331,13 +331,12 @@ public static void play(
331331
break;
332332
case ITEM_CRACK:
333333
ItemStack item = new ItemStack(material);
334-
if (SkillAPI.getSettings().useSkillModelData()) {
335-
ItemMeta meta = item.getItemMeta();
336-
meta.setCustomModelData(data);
337-
item.setItemMeta(meta);
338-
} else {
339-
item.setData(new MaterialData(material, (byte) data));
334+
ItemMeta meta = item.getItemMeta();
335+
meta.setCustomModelData(data);
336+
if (meta instanceof Damageable) {
337+
((Damageable) meta).setDamage(durability);
340338
}
339+
item.setItemMeta(meta);
341340
object = item;
342341
break;
343342
case BLOCK_CRACK:

src/main/java/com/sucy/skill/api/particle/ParticleEffect.java

+44-59
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
import com.sucy.skill.data.formula.Formula;
3636
import com.sucy.skill.data.formula.IValue;
3737
import com.sucy.skill.data.formula.value.CustomValue;
38-
import mc.promcteam.engine.mccore.util.VersionManager;
3938
import org.bukkit.Location;
4039
import org.bukkit.Material;
4140
import org.bukkit.entity.Player;
@@ -182,68 +181,54 @@ public void play(Location loc, int frame, int level) {
182181
double t = animation.getT(frame);
183182
double p = (double) frame / animation.getSteps();
184183

185-
int j = 0, k = 0;
184+
int j = 0;
186185

187-
if (VersionManager.isVersionAtLeast(11300)) {
188-
ArrayList<Player> players = new ArrayList<>();
189-
for (Player player : loc.getWorld().getPlayers()) {
190-
if (loc.distance(player.getLocation()) <= view) {
191-
players.add(player);
192-
}
193-
}
194-
org.bukkit.Particle effect = org.bukkit.Particle.valueOf(this.particle.type.name());
195-
int count = this.particle.amount;
196-
double dx = this.particle.dx;
197-
double dy = this.particle.dy;
198-
double dz = this.particle.dz;
199-
float speed = this.particle.speed;
200-
Material material = this.particle.material;
201-
int data = this.particle.data;
202-
203-
for (int i = frame * this.animation.getCopies(); i < next; ++i) {
204-
Point3D p1 = animPoints[i];
205-
double animSize = this.animSize.compute(t, p, cs.x, cs.y, p1.x, p1.y, p1.z, level);
206-
207-
for (Point3D p2 : shapePoints) {
208-
double size = this.size.compute(t, p, cs.x, cs.y, p2.x, p2.y, p2.z, level);
209-
if (initialRotation != 0) p2 = flatRot.rotateAboutY(p2, rotMatrix);
210-
if (withRotation) {
211-
double yaw = Math.toRadians(-loc.getYaw());
212-
p2 = flatRot.rotateAboutY(p2, yaw);
213-
}
214-
double x = p1.x * animSize + this.animDir.rotateX(p2, trig[j]) * size + loc.getX();
215-
double y = p1.y * animSize + this.animDir.rotateY(p2, trig[j]) * size + loc.getY();
216-
double z = p1.z * animSize + this.animDir.rotateZ(p2, trig[j]) * size + loc.getZ();
217-
Particle.play(
218-
players,
219-
effect,
220-
x,
221-
y,
222-
z,
223-
count,
224-
dx,
225-
dy,
226-
dz,
227-
speed,
228-
material,
229-
data);
230-
}
231-
++j;
186+
ArrayList<Player> players = new ArrayList<>();
187+
for (Player player : loc.getWorld().getPlayers()) {
188+
if (loc.distance(player.getLocation()) <= view) {
189+
players.add(player);
232190
}
233-
} else {
234-
for (int i = frame * animation.getCopies(); i < next; i++) {
235-
Point3D p1 = animPoints[i];
236-
double animSize = this.animSize.compute(t, p, cs.x, cs.y, p1.x, p1.y, p1.z, level);
237-
for (Point3D p2 : shapePoints) {
238-
double size = this.size.compute(t, p, cs.x, cs.y, p2.x, p2.y, p2.z, level);
239-
double x = p1.x * animSize + animDir.rotateX(p2, trig[j]) * size + loc.getX();
240-
double y = p1.y * animSize + animDir.rotateY(p2, trig[j]) * size + loc.getY();
241-
double z = p1.z * animSize + animDir.rotateZ(p2, trig[j]) * size + loc.getZ();
242-
packets[k++] = particle.instance(x, y, z);
191+
}
192+
org.bukkit.Particle effect = org.bukkit.Particle.valueOf(this.particle.type.name());
193+
int count = this.particle.amount;
194+
double dx = this.particle.dx;
195+
double dy = this.particle.dy;
196+
double dz = this.particle.dz;
197+
float speed = this.particle.speed;
198+
Material material = this.particle.material;
199+
int data = this.particle.data;
200+
int durability = this.particle.durability;
201+
202+
for (int i = frame * this.animation.getCopies(); i < next; ++i) {
203+
Point3D p1 = animPoints[i];
204+
double animSize = this.animSize.compute(t, p, cs.x, cs.y, p1.x, p1.y, p1.z, level);
205+
206+
for (Point3D p2 : shapePoints) {
207+
double size = this.size.compute(t, p, cs.x, cs.y, p2.x, p2.y, p2.z, level);
208+
if (initialRotation != 0) p2 = flatRot.rotateAboutY(p2, rotMatrix);
209+
if (withRotation) {
210+
double yaw = Math.toRadians(-loc.getYaw());
211+
p2 = flatRot.rotateAboutY(p2, yaw);
243212
}
244-
j++;
213+
double x = p1.x * animSize + this.animDir.rotateX(p2, trig[j]) * size + loc.getX();
214+
double y = p1.y * animSize + this.animDir.rotateY(p2, trig[j]) * size + loc.getY();
215+
double z = p1.z * animSize + this.animDir.rotateZ(p2, trig[j]) * size + loc.getZ();
216+
Particle.play(
217+
players,
218+
effect,
219+
x,
220+
y,
221+
z,
222+
count,
223+
dx,
224+
dy,
225+
dz,
226+
speed,
227+
material,
228+
data,
229+
durability);
245230
}
246-
Particle.send(loc, packets, view);
231+
++j;
247232
}
248233
} catch (Exception ex) {
249234
ex.printStackTrace();

src/main/java/com/sucy/skill/api/particle/ParticleSettings.java

+9-2
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ public class ParticleSettings {
3636
private static final String
3737
PARTICLE_KEY = "particle",
3838
MATERIAL_KEY = "material",
39+
DURABILITY_KEY = "durability",
3940
DATA_KEY = "type",
4041
AMOUNT_KEY = "amount",
4142
DX_KEY = "dx",
@@ -57,6 +58,7 @@ public class ParticleSettings {
5758

5859
// Particle extra data
5960
public Material material;
61+
public int durability;
6062
public int data;
6163

6264
/**
@@ -104,7 +106,8 @@ public ParticleSettings(
104106
float speed,
105107
int amount,
106108
Material material,
107-
int data) {
109+
int data,
110+
int durability) {
108111
this.type = type;
109112
this.dx = dx;
110113
this.dy = dy;
@@ -114,6 +117,7 @@ public ParticleSettings(
114117
if (Particle.usesData(type)) {
115118
this.material = material;
116119
this.data = data;
120+
this.durability = durability;
117121
}
118122
}
119123

@@ -134,12 +138,15 @@ public ParticleSettings(DataSection config) {
134138
if (Particle.usesData(this.type)) {
135139
Material mat = null;
136140
int data = 0;
141+
int durability = 0;
137142
try {
138143
mat = Material.valueOf(config.getString(MATERIAL_KEY).toUpperCase().replace(" ", "_"));
139-
data = config.getInt(DATA_KEY);
144+
durability = config.getInt(DURABILITY_KEY, 0);
145+
data = config.getInt(DATA_KEY, 0);
140146
} catch (Exception ex) { /* */ }
141147
this.material = mat;
142148
this.data = data;
149+
this.durability = durability;
143150
} else {
144151
this.material = null;
145152
this.data = 0;

src/main/java/com/sucy/skill/api/particle/SpigotParticles.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import org.bukkit.entity.Player;
1010

1111
import java.util.ArrayList;
12+
import java.util.List;
1213
import java.util.Map;
1314

1415
/**
@@ -70,7 +71,7 @@ public class SpigotParticles {
7071
.build();
7172
private static boolean error = true;
7273

73-
public static void play(final Location loc, final String particle, final float dx, final float dy, final float dz, final int count, final float speed, final double distance, final Material material, final int data) {
74+
public static void play(final Location loc, final String particle, final float dx, final float dy, final float dz, final int count, final float speed, final double distance, final Material material, final int customModelData, final int durability) {
7475
Particle effect;
7576
try {
7677
effect = Particle.valueOf(particle.toUpperCase().replace(' ','_'));
@@ -80,7 +81,7 @@ public static void play(final Location loc, final String particle, final float d
8081
if (effect == null) return;
8182
try {
8283
if (VersionManager.isVersionAtLeast(11300)) {
83-
ArrayList<Player> players = new ArrayList<>();
84+
List<Player> players = new ArrayList<>();
8485
for (Player player : loc.getWorld().getPlayers()) {
8586
if (loc.distance(player.getLocation()) <= distance) {
8687
players.add(player);
@@ -98,7 +99,8 @@ public static void play(final Location loc, final String particle, final float d
9899
dz,
99100
speed,
100101
material,
101-
data
102+
customModelData,
103+
durability
102104
);
103105
} else {
104106
final Object packet = com.sucy.skill.api.particle.Particle.make(

src/main/java/com/sucy/skill/api/util/Data.java

+9-30
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,13 @@
2626
*/
2727
package com.sucy.skill.api.util;
2828

29-
import com.sucy.skill.SkillAPI;
3029
import mc.promcteam.engine.mccore.config.parse.DataSection;
3130
import mc.promcteam.engine.mccore.util.TextFormatter;
3231
import org.bukkit.ChatColor;
3332
import org.bukkit.Material;
3433
import org.bukkit.inventory.ItemStack;
3534
import org.bukkit.inventory.meta.Damageable;
3635
import org.bukkit.inventory.meta.ItemMeta;
37-
import org.bukkit.material.MaterialData;
3836

3937
import java.util.ArrayList;
4038
import java.util.List;
@@ -48,7 +46,7 @@ public class Data {
4846
private static final String DURABILITY = "icon-durability";
4947
private static final String LORE = "icon-lore";
5048

51-
private static ItemStack parse(final String mat, final short dur, final int data, final List<String> lore) {
49+
private static ItemStack parse(final String mat, final int dur, final int data, final List<String> lore) {
5250
try {
5351
Material material = Material.matchMaterial(mat);
5452
if (material == null) {
@@ -57,27 +55,16 @@ private static ItemStack parse(final String mat, final short dur, final int data
5755

5856
final ItemStack item = new ItemStack(material);
5957
final ItemMeta meta = item.getItemMeta();
60-
if (SkillAPI.getSettings().useGUIModelData()) {
61-
if (data != 0) {
62-
meta.setCustomModelData(data);
63-
}
64-
} else {
65-
item.setData(new MaterialData(material, (byte) data));
66-
}
58+
if (data != 0) { meta.setCustomModelData(data); }
6759
if (lore != null && !lore.isEmpty()) {
6860
final List<String> colored = TextFormatter.colorStringList(lore);
6961
meta.setDisplayName(colored.remove(0));
7062
meta.setLore(colored);
7163
}
72-
if (SkillAPI.getSettings().useOldDurability()) {
73-
item.setItemMeta(meta);
74-
item.setDurability(dur);
75-
} else {
76-
if (meta instanceof Damageable) {
77-
((Damageable) meta).setDamage(dur);
78-
}
79-
item.setItemMeta(meta);
64+
if (meta instanceof Damageable) {
65+
((Damageable) meta).setDamage(dur);
8066
}
67+
item.setItemMeta(meta);
8168
return DamageLoreRemover.removeAttackDmg(item);
8269
} catch (final Exception ex) {
8370
return new ItemStack(Material.JACK_O_LANTERN);
@@ -94,18 +81,10 @@ public static void serializeIcon(ItemStack item, DataSection config) {
9481
config.set(MAT, item.getType().name());
9582

9683
ItemMeta meta = item.getItemMeta();
97-
if (SkillAPI.getSettings().useGUIModelData()) {
98-
config.set(DATA, meta.hasCustomModelData() ? meta.getCustomModelData() : 0);
99-
} else {
100-
config.set(DATA, item.getData().getData());
101-
}
84+
config.set(DATA, meta.hasCustomModelData() ? meta.getCustomModelData() : 0);
10285

103-
if (SkillAPI.getSettings().useOldDurability()) {
104-
config.set(DURABILITY, item.getDurability());
105-
} else {
106-
if (meta instanceof Damageable) config.set(DURABILITY, ((Damageable) meta).getDamage());
107-
else config.set(DURABILITY, 0);
108-
}
86+
if (meta instanceof Damageable) { config.set(DURABILITY, ((Damageable) meta).getDamage()); }
87+
else { config.set(DURABILITY, 0); }
10988

11089
if (meta.hasDisplayName()) {
11190
List<String> lore = item.getItemMeta().getLore();
@@ -133,7 +112,7 @@ public static ItemStack parseIcon(DataSection config) {
133112
final int data = config.getInt(DATA, 0);
134113
return parse(
135114
config.getString(MAT, "JACK_O_LANTERN"),
136-
(short) config.getInt(DURABILITY, data),
115+
config.getInt(DURABILITY, 0),
137116
data,
138117
config.getList(LORE, null));
139118
}

0 commit comments

Comments
 (0)