Added a way to load extra data for particles and added a boolean to determine if all frames should spawn at the same location
This commit is contained in:
parent
be97b45833
commit
d416ec80e1
|
|
@ -73,6 +73,7 @@ public class ParticleConfig {
|
||||||
int repeat = (int) (long) jsonObject.get("repeat");
|
int repeat = (int) (long) jsonObject.get("repeat");
|
||||||
int repeatDelay = (int) (long) jsonObject.get("repeat_delay");
|
int repeatDelay = (int) (long) jsonObject.get("repeat_delay");
|
||||||
double randomOffset = (double) jsonObject.get("random_offset");
|
double randomOffset = (double) jsonObject.get("random_offset");
|
||||||
|
boolean stationary = (boolean) jsonObject.get("stationary");
|
||||||
JSONObject frames = (JSONObject) jsonObject.get("frames");
|
JSONObject frames = (JSONObject) jsonObject.get("frames");
|
||||||
List<Frame> loadedFrames = new ArrayList<>();
|
List<Frame> loadedFrames = new ArrayList<>();
|
||||||
for (Object key : frames.keySet()) {
|
for (Object key : frames.keySet()) {
|
||||||
|
|
@ -101,12 +102,15 @@ public class ParticleConfig {
|
||||||
//TODO implement
|
//TODO implement
|
||||||
} else if (particleType.getDataType().equals(ItemStack.class)) {
|
} else if (particleType.getDataType().equals(ItemStack.class)) {
|
||||||
//TODO implement
|
//TODO implement
|
||||||
|
} else {
|
||||||
|
double data = (double) pData.get("extra");
|
||||||
|
particleBuilder.extra(data);
|
||||||
}
|
}
|
||||||
aParticleList.add(new AParticle(x, y, z, randomOffset, particleBuilder));
|
aParticleList.add(new AParticle(x, y, z, randomOffset, particleBuilder));
|
||||||
}
|
}
|
||||||
loadedFrames.add(new Frame(aParticleList));
|
loadedFrames.add(new Frame(aParticleList));
|
||||||
}
|
}
|
||||||
return new ParticleSet(loadedFrames, displayName, List.of(lore.split("\n")), frameDelay, repeat, repeatDelay, aPartType, particleName, permission, packagePermission, displayItem);
|
return new ParticleSet(loadedFrames, displayName, List.of(lore.split("\n")), frameDelay, repeat, repeatDelay, stationary, aPartType, particleName, permission, packagePermission, displayItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void reload() {
|
public static void reload() {
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import com.alttd.objects.Frame;
|
||||||
import com.alttd.objects.ParticleSet;
|
import com.alttd.objects.ParticleSet;
|
||||||
import com.alttd.storage.PlayerSettings;
|
import com.alttd.storage.PlayerSettings;
|
||||||
import com.alttd.util.Logger;
|
import com.alttd.util.Logger;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
|
|
@ -23,7 +24,8 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
|
||||||
private final APartType aPartType;
|
private final APartType aPartType;
|
||||||
private final String uniqueId;
|
private final String uniqueId;
|
||||||
private final int frameDelay;
|
private final int frameDelay;
|
||||||
public FrameSpawnerPlayer(int amount, List<Frame> frames, int frameDelay, Player player, PlayerSettings playerSettings, APartType aPartType, String uniqueId) {
|
private final boolean stationary;
|
||||||
|
public FrameSpawnerPlayer(int amount, List<Frame> frames, int frameDelay, Player player, PlayerSettings playerSettings, APartType aPartType, String uniqueId, boolean stationary) {
|
||||||
this.amount = amount;
|
this.amount = amount;
|
||||||
this.frames = frames;
|
this.frames = frames;
|
||||||
this.iterator = frames.iterator();
|
this.iterator = frames.iterator();
|
||||||
|
|
@ -32,6 +34,7 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
|
||||||
this.aPartType = aPartType;
|
this.aPartType = aPartType;
|
||||||
this.uniqueId = uniqueId;
|
this.uniqueId = uniqueId;
|
||||||
this.frameDelay = frameDelay;
|
this.frameDelay = frameDelay;
|
||||||
|
this.stationary = stationary;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -42,6 +45,8 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
|
||||||
Logger.info("Stopped repeating task due to player offline.");
|
Logger.info("Stopped repeating task due to player offline.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
Location location = player.getLocation();
|
||||||
|
float yaw = location.getYaw();
|
||||||
ParticleSet activeParticleSet = playerSettings.getParticles(aPartType);
|
ParticleSet activeParticleSet = playerSettings.getParticles(aPartType);
|
||||||
if (activeParticleSet == null || !activeParticleSet.getParticleId().equalsIgnoreCase(uniqueId) || !playerSettings.hasActiveParticles()) {
|
if (activeParticleSet == null || !activeParticleSet.getParticleId().equalsIgnoreCase(uniqueId) || !playerSettings.hasActiveParticles()) {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
|
|
@ -57,9 +62,15 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
|
||||||
new BukkitRunnable() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
if (!iterator.hasNext())
|
if (!iterator.hasNext()) {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
iterator.next().spawn(player.getLocation(), player.getLocation().getYaw());
|
return;
|
||||||
|
}
|
||||||
|
Frame next = iterator.next();
|
||||||
|
if (stationary)
|
||||||
|
next.spawn(location, yaw);
|
||||||
|
else
|
||||||
|
next.spawn(player.getLocation(), player.getLocation().getYaw());
|
||||||
}
|
}
|
||||||
}.runTaskTimerAsynchronously(AltitudeParticles.getInstance(), 0, frameDelay);
|
}.runTaskTimerAsynchronously(AltitudeParticles.getInstance(), 0, frameDelay);
|
||||||
iterator = frames.iterator();
|
iterator = frames.iterator();
|
||||||
|
|
|
||||||
|
|
@ -27,8 +27,9 @@ public class ParticleSet {
|
||||||
private final String permission;
|
private final String permission;
|
||||||
private final String packPermission;
|
private final String packPermission;
|
||||||
private final ItemStack itemStack;
|
private final ItemStack itemStack;
|
||||||
|
private final boolean stationary;
|
||||||
|
|
||||||
public ParticleSet(List<Frame> frames, String name, List<String> lore, int frameDelay, int repeat, int repeatDelay, APartType aPartType, String uniqueId, String permission, String packPermission,ItemStack itemStack) {
|
public ParticleSet(List<Frame> frames, String name, List<String> lore, int frameDelay, int repeat, int repeatDelay, boolean stationary, APartType aPartType, String uniqueId, String permission, String packPermission, ItemStack itemStack) {
|
||||||
MiniMessage miniMessage = MiniMessage.miniMessage();
|
MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
this.frames = frames;
|
this.frames = frames;
|
||||||
this.frameDelay = frameDelay;
|
this.frameDelay = frameDelay;
|
||||||
|
|
@ -38,6 +39,7 @@ public class ParticleSet {
|
||||||
this.uniqueId = uniqueId;
|
this.uniqueId = uniqueId;
|
||||||
this.permission = permission;
|
this.permission = permission;
|
||||||
this.packPermission = packPermission;
|
this.packPermission = packPermission;
|
||||||
|
this.stationary = stationary;
|
||||||
ItemMeta itemMeta = itemStack.getItemMeta();
|
ItemMeta itemMeta = itemStack.getItemMeta();
|
||||||
itemMeta.displayName(miniMessage.deserialize(name));
|
itemMeta.displayName(miniMessage.deserialize(name));
|
||||||
itemMeta.lore(lore.stream().map(miniMessage::deserialize).collect(Collectors.toList()));
|
itemMeta.lore(lore.stream().map(miniMessage::deserialize).collect(Collectors.toList()));
|
||||||
|
|
@ -57,7 +59,7 @@ public class ParticleSet {
|
||||||
return;
|
return;
|
||||||
if (Config.DEBUG)
|
if (Config.DEBUG)
|
||||||
Logger.info("Starting particle set % for %.", uniqueId, player.getName());
|
Logger.info("Starting particle set % for %.", uniqueId, player.getName());
|
||||||
FrameSpawnerPlayer frameSpawnerPlayer = new FrameSpawnerPlayer(repeat, frames, frameDelay, player, playerSettings, aPartType, uniqueId);
|
FrameSpawnerPlayer frameSpawnerPlayer = new FrameSpawnerPlayer(repeat, frames, frameDelay, player, playerSettings, aPartType, uniqueId, stationary);
|
||||||
frameSpawnerPlayer.runTaskTimerAsynchronously(AltitudeParticles.getInstance(), 0, repeatDelay);
|
frameSpawnerPlayer.runTaskTimerAsynchronously(AltitudeParticles.getInstance(), 0, repeatDelay);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user