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:
Teriuihi 2022-09-07 22:39:48 +02:00
parent be97b45833
commit d416ec80e1
3 changed files with 23 additions and 6 deletions

View File

@ -73,6 +73,7 @@ public class ParticleConfig {
int repeat = (int) (long) jsonObject.get("repeat");
int repeatDelay = (int) (long) jsonObject.get("repeat_delay");
double randomOffset = (double) jsonObject.get("random_offset");
boolean stationary = (boolean) jsonObject.get("stationary");
JSONObject frames = (JSONObject) jsonObject.get("frames");
List<Frame> loadedFrames = new ArrayList<>();
for (Object key : frames.keySet()) {
@ -101,12 +102,15 @@ public class ParticleConfig {
//TODO implement
} else if (particleType.getDataType().equals(ItemStack.class)) {
//TODO implement
} else {
double data = (double) pData.get("extra");
particleBuilder.extra(data);
}
aParticleList.add(new AParticle(x, y, z, randomOffset, particleBuilder));
}
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() {

View File

@ -7,6 +7,7 @@ import com.alttd.objects.Frame;
import com.alttd.objects.ParticleSet;
import com.alttd.storage.PlayerSettings;
import com.alttd.util.Logger;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitRunnable;
@ -23,7 +24,8 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
private final APartType aPartType;
private final String uniqueId;
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.frames = frames;
this.iterator = frames.iterator();
@ -32,6 +34,7 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
this.aPartType = aPartType;
this.uniqueId = uniqueId;
this.frameDelay = frameDelay;
this.stationary = stationary;
}
@Override
@ -42,6 +45,8 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
Logger.info("Stopped repeating task due to player offline.");
return;
}
Location location = player.getLocation();
float yaw = location.getYaw();
ParticleSet activeParticleSet = playerSettings.getParticles(aPartType);
if (activeParticleSet == null || !activeParticleSet.getParticleId().equalsIgnoreCase(uniqueId) || !playerSettings.hasActiveParticles()) {
this.cancel();
@ -57,9 +62,15 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
new BukkitRunnable() {
@Override
public void run() {
if (!iterator.hasNext())
if (!iterator.hasNext()) {
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);
iterator = frames.iterator();

View File

@ -27,8 +27,9 @@ public class ParticleSet {
private final String permission;
private final String packPermission;
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();
this.frames = frames;
this.frameDelay = frameDelay;
@ -38,6 +39,7 @@ public class ParticleSet {
this.uniqueId = uniqueId;
this.permission = permission;
this.packPermission = packPermission;
this.stationary = stationary;
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.displayName(miniMessage.deserialize(name));
itemMeta.lore(lore.stream().map(miniMessage::deserialize).collect(Collectors.toList()));
@ -57,7 +59,7 @@ public class ParticleSet {
return;
if (Config.DEBUG)
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);
}