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 {
|
shadowJar {
|
||||||
archiveFileName.set("${project.name}-${project.version}.jar")
|
// archiveFileName.set("${project.name}-${project.version}.jar")
|
||||||
|
archiveFileName.set("${project.name}.jar")
|
||||||
minimize()
|
minimize()
|
||||||
configurations = listOf(project.configurations.shadow.get())
|
configurations = listOf(project.configurations.shadow.get())
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -150,6 +150,7 @@ public class ParticleConfig {
|
||||||
* @return A ParticleSet created from the ParticleData
|
* @return A ParticleSet created from the ParticleData
|
||||||
*/
|
*/
|
||||||
public ParticleSet convertToParticleSet(ParticleData particleData) {
|
public ParticleSet convertToParticleSet(ParticleData particleData) {
|
||||||
|
log.info("Converting ParticleData to ParticleSet for {}", particleData.getParticleName());
|
||||||
List<Frame> loadedFrames = new ArrayList<>();
|
List<Frame> loadedFrames = new ArrayList<>();
|
||||||
double randomOffset = particleData.getRandomOffset();
|
double randomOffset = particleData.getRandomOffset();
|
||||||
|
|
||||||
|
|
@ -168,35 +169,7 @@ public class ParticleConfig {
|
||||||
Class<?> dataType = particleType.getDataType();
|
Class<?> dataType = particleType.getDataType();
|
||||||
|
|
||||||
// Handle different particle data types
|
// Handle different particle data types
|
||||||
if (dataType.equals(Particle.DustOptions.class)) {
|
setParticleType(particleInfo, dataType, particleBuilder);
|
||||||
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());
|
|
||||||
}
|
|
||||||
|
|
||||||
//Add 0.2 to adjust for the player model being 1.6 blocks high
|
//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));
|
aParticleList.add(new AParticle(x, y + 0.2, z, randomOffset, particleBuilder));
|
||||||
|
|
@ -223,13 +196,58 @@ public class ParticleConfig {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color getColor(String hexColor) {
|
private void setParticleType(ParticleInfo particleInfo, Class<?> dataType, ParticleBuilder particleBuilder) {
|
||||||
int color = HexFormat.fromHexDigits(hexColor);
|
String color = particleInfo.getColor();
|
||||||
if (hexColor.length() == 6) {
|
if (dataType.equals(Particle.DustOptions.class)) {
|
||||||
return Color.fromARGB(color);
|
if (color != null) {
|
||||||
} else {
|
particleBuilder.color(getColor(color),
|
||||||
return Color.fromRGB(color);
|
particleInfo.getSize());
|
||||||
|
} else {
|
||||||
|
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() {
|
public static void reload() {
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,17 @@ 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 com.destroystokyo.paper.ParticleBuilder;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Particle;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.scheduler.BukkitRunnable;
|
import org.bukkit.scheduler.BukkitRunnable;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
public class FrameSpawnerPlayer extends BukkitRunnable {
|
public class FrameSpawnerPlayer extends BukkitRunnable {
|
||||||
|
|
||||||
private int amount;
|
private int amount;
|
||||||
|
|
@ -42,7 +46,7 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
|
||||||
if (!player.isOnline()) {
|
if (!player.isOnline()) {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
if (Config.DEBUG)
|
if (Config.DEBUG)
|
||||||
Logger.info("Stopped repeating task due to player offline.");
|
log.info("Stopped repeating task due to player offline.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Location location = player.getLocation();
|
Location location = player.getLocation();
|
||||||
|
|
@ -51,14 +55,15 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
|
||||||
if (activeParticleSet == null || !activeParticleSet.getParticleId().equalsIgnoreCase(uniqueId) || !playerSettings.hasActiveParticles()) {
|
if (activeParticleSet == null || !activeParticleSet.getParticleId().equalsIgnoreCase(uniqueId) || !playerSettings.hasActiveParticles()) {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
if (Config.DEBUG)
|
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;
|
return;
|
||||||
}
|
}
|
||||||
if (amount == 0) {
|
if (amount == 0) {
|
||||||
this.cancel();
|
this.cancel();
|
||||||
if (Config.DEBUG)
|
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() {
|
new BukkitRunnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
|
@ -73,7 +78,6 @@ public class FrameSpawnerPlayer extends BukkitRunnable {
|
||||||
next.spawn(player.getLocation(), player.getLocation().getYaw());
|
next.spawn(player.getLocation(), player.getLocation().getYaw());
|
||||||
}
|
}
|
||||||
}.runTaskTimerAsynchronously(AltitudeParticles.getInstance(), 0, frameDelay);
|
}.runTaskTimerAsynchronously(AltitudeParticles.getInstance(), 0, frameDelay);
|
||||||
iterator = frames.iterator();
|
|
||||||
if (amount != -1)
|
if (amount != -1)
|
||||||
amount--;
|
amount--;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ public class ParticleInfo {
|
||||||
// For DustOptions
|
// For DustOptions
|
||||||
|
|
||||||
@JsonProperty(value = "size", defaultValue = "1")
|
@JsonProperty(value = "size", defaultValue = "1")
|
||||||
private int size;
|
private int size = 1;
|
||||||
|
|
||||||
// For other particle types
|
// For other particle types
|
||||||
private Double extra;
|
private Double extra;
|
||||||
|
|
|
||||||
|
|
@ -3,16 +3,18 @@ package com.alttd.objects;
|
||||||
import com.alttd.storage.PlayerSettings;
|
import com.alttd.storage.PlayerSettings;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.entity.Player;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ThreadLocalRandom;
|
import java.util.concurrent.ThreadLocalRandom;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
public class Frame {
|
public class Frame {
|
||||||
List<AParticle> AParticles;
|
List<AParticle> aParticles;
|
||||||
|
|
||||||
public Frame(List<AParticle> AParticles) {
|
public Frame(List<AParticle> aParticles) {
|
||||||
this.AParticles = AParticles;
|
this.aParticles = aParticles;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -22,7 +24,7 @@ public class Frame {
|
||||||
*/
|
*/
|
||||||
public void spawn(Location location, float rotation) {
|
public void spawn(Location location, float rotation) {
|
||||||
Location tmpLocation = location.clone();
|
Location tmpLocation = location.clone();
|
||||||
AParticles.forEach(aParticle -> {
|
aParticles.forEach(aParticle -> {
|
||||||
ThreadLocalRandom current = ThreadLocalRandom.current();
|
ThreadLocalRandom current = ThreadLocalRandom.current();
|
||||||
double offsetX = ((aParticle.offset_range() == 0) ? 0 : current.nextDouble(-aParticle.offset_range(), aParticle.offset_range()));
|
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()));
|
double offsetZ = ((aParticle.offset_range() == 0) ? 0 : current.nextDouble(-aParticle.offset_range(), aParticle.offset_range()));
|
||||||
|
|
@ -30,25 +32,31 @@ public class Frame {
|
||||||
XZ xz = new XZ(location.getX(), location.getX() + aParticle.x() + offsetX,
|
XZ xz = new XZ(location.getX(), location.getX() + aParticle.x() + offsetX,
|
||||||
location.getZ(), location.getZ() + aParticle.z() + offsetZ,
|
location.getZ(), location.getZ() + aParticle.z() + offsetZ,
|
||||||
rotation);
|
rotation);
|
||||||
|
List<Player> receivers = getReceivers(location);
|
||||||
|
tmpLocation.set(
|
||||||
|
xz.getRotatedX(),
|
||||||
|
location.getY() + aParticle.y() + offsetY,
|
||||||
|
xz.getRotatedZ());
|
||||||
aParticle.particleBuilder()
|
aParticle.particleBuilder()
|
||||||
.location(tmpLocation.set(
|
.location(tmpLocation)
|
||||||
xz.getRotatedX(),
|
.receivers(receivers)
|
||||||
location.getY() + aParticle.y() + offsetY,
|
|
||||||
xz.getRotatedZ()))
|
|
||||||
.receivers(Bukkit.getOnlinePlayers().stream()
|
|
||||||
.filter(player -> {
|
|
||||||
PlayerSettings playerSettings = PlayerSettings.getPlayer(player.getUniqueId());
|
|
||||||
if (playerSettings == null)
|
|
||||||
return false;
|
|
||||||
if (!playerSettings.isSeeingParticles())
|
|
||||||
return false;
|
|
||||||
Location playerLocation = player.getLocation();
|
|
||||||
return location.getWorld().getUID().equals(playerLocation.getWorld().getUID()) && player.getLocation().distance(location) < 100;
|
|
||||||
}).collect(Collectors.toList()))
|
|
||||||
.spawn();
|
.spawn();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static @NotNull List<Player> getReceivers(Location location) {
|
||||||
|
return Bukkit.getOnlinePlayers().stream()
|
||||||
|
.filter(player -> {
|
||||||
|
PlayerSettings playerSettings = PlayerSettings.getPlayer(player.getUniqueId());
|
||||||
|
if (playerSettings == null)
|
||||||
|
return false;
|
||||||
|
if (!playerSettings.isSeeingParticles())
|
||||||
|
return false;
|
||||||
|
Location playerLocation = player.getLocation();
|
||||||
|
return location.getWorld().getUID().equals(playerLocation.getWorld().getUID()) && player.getLocation().distance(location) < 100;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
private static class XZ {
|
private static class XZ {
|
||||||
private final double cx, cz; //Coordinates to rotate around
|
private final double cx, cz; //Coordinates to rotate around
|
||||||
private double x, z; //Coordinated to rotate
|
private double x, z; //Coordinated to rotate
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user