Fix color bug (argb <> rgb), fix particles defaulting to size 0
This commit is contained in:
parent
d7c744c20b
commit
5425b89b2b
|
|
@ -25,7 +25,8 @@ tasks {
|
|||
}
|
||||
|
||||
shadowJar {
|
||||
archiveFileName.set("${project.name}-${project.version}.jar")
|
||||
// archiveFileName.set("${project.name}-${project.version}.jar")
|
||||
archiveFileName.set("${project.name}.jar")
|
||||
minimize()
|
||||
configurations = listOf(project.configurations.shadow.get())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -150,6 +150,7 @@ public class ParticleConfig {
|
|||
* @return A ParticleSet created from the ParticleData
|
||||
*/
|
||||
public ParticleSet convertToParticleSet(ParticleData particleData) {
|
||||
log.info("Converting ParticleData to ParticleSet for {}", particleData.getParticleName());
|
||||
List<Frame> loadedFrames = new ArrayList<>();
|
||||
double randomOffset = particleData.getRandomOffset();
|
||||
|
||||
|
|
@ -168,35 +169,7 @@ public class ParticleConfig {
|
|||
Class<?> dataType = particleType.getDataType();
|
||||
|
||||
// Handle different particle data types
|
||||
if (dataType.equals(Particle.DustOptions.class)) {
|
||||
if (particleInfo.getColor() != null) {
|
||||
particleBuilder.color(getColor(particleInfo.getColor()),
|
||||
particleInfo.getSize());
|
||||
}
|
||||
} else if (dataType.equals(Particle.DustTransition.class)) {
|
||||
if (particleInfo.getColorGradientEnd() != null) {
|
||||
particleBuilder.colorTransition(getColor(particleInfo.getColor()),
|
||||
getColor(particleInfo.getColorGradientEnd()),
|
||||
particleInfo.getSize());
|
||||
}
|
||||
}
|
||||
else if (dataType.equals(Color.class)) {
|
||||
particleBuilder.color(getColor(particleInfo.getColor()));
|
||||
} else if (dataType.equals(BlockData.class)) {
|
||||
particleBuilder.data(Material.STONE.createBlockData());
|
||||
//TODO implement
|
||||
} else if (dataType.equals(Integer.class)) {
|
||||
particleBuilder.data(1);
|
||||
//TODO implement
|
||||
} else if (dataType.equals(Float.class)) {
|
||||
particleBuilder.data(1f);
|
||||
//TODO implement
|
||||
} else if (dataType.equals(ItemStack.class)) {
|
||||
particleBuilder.data(new ItemStack(Material.STONE));
|
||||
//TODO implement
|
||||
} else if (particleInfo.getExtra() != null) {
|
||||
particleBuilder.extra(particleInfo.getExtra());
|
||||
}
|
||||
setParticleType(particleInfo, dataType, particleBuilder);
|
||||
|
||||
//Add 0.2 to adjust for the player model being 1.6 blocks high
|
||||
aParticleList.add(new AParticle(x, y + 0.2, z, randomOffset, particleBuilder));
|
||||
|
|
@ -223,13 +196,58 @@ public class ParticleConfig {
|
|||
);
|
||||
}
|
||||
|
||||
private Color getColor(String hexColor) {
|
||||
int color = HexFormat.fromHexDigits(hexColor);
|
||||
if (hexColor.length() == 6) {
|
||||
return Color.fromARGB(color);
|
||||
private void setParticleType(ParticleInfo particleInfo, Class<?> dataType, ParticleBuilder particleBuilder) {
|
||||
String color = particleInfo.getColor();
|
||||
if (dataType.equals(Particle.DustOptions.class)) {
|
||||
if (color != null) {
|
||||
particleBuilder.color(getColor(color),
|
||||
particleInfo.getSize());
|
||||
} else {
|
||||
return Color.fromRGB(color);
|
||||
log.error("Dust particle must have a color");
|
||||
}
|
||||
} else if (dataType.equals(Particle.DustTransition.class)) {
|
||||
if (color == null || particleInfo.getColorGradientEnd() != null) {
|
||||
particleBuilder.colorTransition(getColor(color),
|
||||
getColor(particleInfo.getColorGradientEnd()),
|
||||
particleInfo.getSize());
|
||||
} else {
|
||||
log.error("Dust transition particle must have a color gradient start and end");
|
||||
}
|
||||
}
|
||||
else if (dataType.equals(Color.class)) {
|
||||
particleBuilder.color(getColor(color));
|
||||
} else if (dataType.equals(BlockData.class)) {
|
||||
particleBuilder.data(Material.STONE.createBlockData());
|
||||
log.warn("Block data particles are not yet supported");
|
||||
//TODO implement
|
||||
} else if (dataType.equals(Integer.class)) {
|
||||
particleBuilder.data(1);
|
||||
log.warn("Integer data particles are not yet supported");
|
||||
//TODO implement
|
||||
} else if (dataType.equals(Float.class)) {
|
||||
particleBuilder.data(1f);
|
||||
log.warn("Float data particles are not yet supported");
|
||||
//TODO implement
|
||||
} else if (dataType.equals(ItemStack.class)) {
|
||||
particleBuilder.data(new ItemStack(Material.STONE));
|
||||
log.warn("ItemStack data particles are not yet supported");
|
||||
//TODO implement
|
||||
} else if (particleInfo.getExtra() != null) {
|
||||
particleBuilder.extra(particleInfo.getExtra());
|
||||
} else {
|
||||
log.debug("No relevant data type: {}", dataType.getName());
|
||||
}
|
||||
}
|
||||
|
||||
private Color getColor(String hexColor) {
|
||||
int hexFormatColor = HexFormat.fromHexDigits(hexColor);
|
||||
Color color;
|
||||
if (hexColor.length() == 6) {
|
||||
color = Color.fromRGB(hexFormatColor);
|
||||
} else {
|
||||
color = Color.fromARGB(hexFormatColor);
|
||||
}
|
||||
return color;
|
||||
}
|
||||
|
||||
public static void reload() {
|
||||
|
|
|
|||
|
|
@ -7,13 +7,17 @@ import com.alttd.objects.Frame;
|
|||
import com.alttd.objects.ParticleSet;
|
||||
import com.alttd.storage.PlayerSettings;
|
||||
import com.alttd.util.Logger;
|
||||
import com.destroystokyo.paper.ParticleBuilder;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public class FrameSpawnerPlayer extends BukkitRunnable {
|
||||
|
||||
private int amount;
|
||||
|
|
@ -42,7 +46,7 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
|
|||
if (!player.isOnline()) {
|
||||
this.cancel();
|
||||
if (Config.DEBUG)
|
||||
Logger.info("Stopped repeating task due to player offline.");
|
||||
log.info("Stopped repeating task due to player offline.");
|
||||
return;
|
||||
}
|
||||
Location location = player.getLocation();
|
||||
|
|
@ -51,14 +55,15 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
|
|||
if (activeParticleSet == null || !activeParticleSet.getParticleId().equalsIgnoreCase(uniqueId) || !playerSettings.hasActiveParticles()) {
|
||||
this.cancel();
|
||||
if (Config.DEBUG)
|
||||
Logger.info("Stopped repeating task due to player switching/disabling particles.");
|
||||
log.info("Stopped repeating task due to player switching/disabling particles.");
|
||||
return;
|
||||
}
|
||||
if (amount == 0) {
|
||||
this.cancel();
|
||||
if (Config.DEBUG)
|
||||
Logger.info("Stopped repeating task due to end of frames.");
|
||||
log.info("Stopped repeating task due to end of frames.");
|
||||
}
|
||||
iterator = frames.iterator();
|
||||
new BukkitRunnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
@ -73,7 +78,6 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
|
|||
next.spawn(player.getLocation(), player.getLocation().getYaw());
|
||||
}
|
||||
}.runTaskTimerAsynchronously(AltitudeParticles.getInstance(), 0, frameDelay);
|
||||
iterator = frames.iterator();
|
||||
if (amount != -1)
|
||||
amount--;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ public class ParticleInfo {
|
|||
// For DustOptions
|
||||
|
||||
@JsonProperty(value = "size", defaultValue = "1")
|
||||
private int size;
|
||||
private int size = 1;
|
||||
|
||||
// For other particle types
|
||||
private Double extra;
|
||||
|
|
|
|||
|
|
@ -3,16 +3,18 @@ package com.alttd.objects;
|
|||
import com.alttd.storage.PlayerSettings;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Frame {
|
||||
List<AParticle> AParticles;
|
||||
List<AParticle> aParticles;
|
||||
|
||||
public Frame(List<AParticle> AParticles) {
|
||||
this.AParticles = AParticles;
|
||||
public Frame(List<AParticle> aParticles) {
|
||||
this.aParticles = aParticles;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -22,7 +24,7 @@ public class Frame {
|
|||
*/
|
||||
public void spawn(Location location, float rotation) {
|
||||
Location tmpLocation = location.clone();
|
||||
AParticles.forEach(aParticle -> {
|
||||
aParticles.forEach(aParticle -> {
|
||||
ThreadLocalRandom current = ThreadLocalRandom.current();
|
||||
double offsetX = ((aParticle.offset_range() == 0) ? 0 : current.nextDouble(-aParticle.offset_range(), aParticle.offset_range()));
|
||||
double offsetZ = ((aParticle.offset_range() == 0) ? 0 : current.nextDouble(-aParticle.offset_range(), aParticle.offset_range()));
|
||||
|
|
@ -30,12 +32,20 @@ public class Frame {
|
|||
XZ xz = new XZ(location.getX(), location.getX() + aParticle.x() + offsetX,
|
||||
location.getZ(), location.getZ() + aParticle.z() + offsetZ,
|
||||
rotation);
|
||||
aParticle.particleBuilder()
|
||||
.location(tmpLocation.set(
|
||||
List<Player> receivers = getReceivers(location);
|
||||
tmpLocation.set(
|
||||
xz.getRotatedX(),
|
||||
location.getY() + aParticle.y() + offsetY,
|
||||
xz.getRotatedZ()))
|
||||
.receivers(Bukkit.getOnlinePlayers().stream()
|
||||
xz.getRotatedZ());
|
||||
aParticle.particleBuilder()
|
||||
.location(tmpLocation)
|
||||
.receivers(receivers)
|
||||
.spawn();
|
||||
});
|
||||
}
|
||||
|
||||
private static @NotNull List<Player> getReceivers(Location location) {
|
||||
return Bukkit.getOnlinePlayers().stream()
|
||||
.filter(player -> {
|
||||
PlayerSettings playerSettings = PlayerSettings.getPlayer(player.getUniqueId());
|
||||
if (playerSettings == null)
|
||||
|
|
@ -44,9 +54,7 @@ public class Frame {
|
|||
return false;
|
||||
Location playerLocation = player.getLocation();
|
||||
return location.getWorld().getUID().equals(playerLocation.getWorld().getUID()) && player.getLocation().distance(location) < 100;
|
||||
}).collect(Collectors.toList()))
|
||||
.spawn();
|
||||
});
|
||||
}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static class XZ {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user