9
0
mirror of https://github.com/HibiscusMC/HMCCosmetics.git synced 2026-01-04 15:41:45 +00:00

Add particle action

This commit is contained in:
LoJoSho
2023-01-22 19:04:42 -06:00
parent ea1b87c128
commit 5309c37902
5 changed files with 146 additions and 0 deletions

View File

@@ -54,6 +54,9 @@ allprojects {
// UpdateChecker
maven("https://hub.jeff-media.com/nexus/repository/jeff-media-public/")
// ParticleHelper
maven("https://repo.bytecode.space/repository/maven-public/")
}
dependencies {
@@ -86,6 +89,7 @@ dependencies {
implementation("org.spongepowered:configurate-yaml:4.1.2")
implementation("org.bstats:bstats-bukkit:3.0.0")
implementation("com.jeff_media:SpigotUpdateChecker:3.0.0")
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
}
tasks {
@@ -122,6 +126,7 @@ tasks {
relocate("com.zaxxer.hikaricp", "com.hisbiscusmc.hmccosmetics.hikaricp")
relocate("com.j256.ormlite", "com.hisbiscusmc.hmccosmetics.ormlite")
relocate("com.jeff_media.updatechecker", "com.hisbiscusmc.hmccosmetics.updatechecker")
relocate("com.woen1212055.particlehelper", "com.hisbiscusmc.hmccosmetics.particlehelper")
archiveFileName.set("HMCCosmeticsRemapped-${project.version}.jar")
dependencies {

View File

@@ -24,6 +24,7 @@ dependencies {
implementation("org.spongepowered:configurate-yaml:4.1.2")
implementation("org.bstats:bstats-bukkit:3.0.0")
implementation("com.jeff_media:SpigotUpdateChecker:3.0.0")
implementation("com.owen1212055:particlehelper:1.0.0-SNAPSHOT")
}
java {

View File

@@ -21,6 +21,7 @@ public class Actions {
private static ActionSound ACTION_SOUND = new ActionSound();
private static ActionEquip ACTION_EQUIP = new ActionEquip();
private static ActionUnequip ACTION_UNEQUIP = new ActionUnequip();
private static ActionParticle ACTION_PARTICLE = new ActionParticle();
public static Action getAction(String id) {

View File

@@ -0,0 +1,49 @@
package com.hibiscusmc.hmccosmetics.gui.action.actions;
import com.hibiscusmc.hmccosmetics.gui.action.Action;
import com.hibiscusmc.hmccosmetics.user.CosmeticUser;
import com.hibiscusmc.hmccosmetics.util.MessagesUtil;
import com.hibiscusmc.hmccosmetics.util.ServerUtils;
import com.hibiscusmc.hmccosmetics.util.packets.PacketManager;
import com.owen1212055.particlehelper.api.particle.Particle;
import com.owen1212055.particlehelper.api.particle.types.BlockDataParticle;
import com.owen1212055.particlehelper.api.particle.types.DestinationParticle;
import com.owen1212055.particlehelper.api.particle.types.velocity.VelocityParticle;
import com.owen1212055.particlehelper.api.particle.types.vibration.VibrationParticle;
import com.owen1212055.particlehelper.api.type.Particles;
import org.bukkit.Location;
import org.bukkit.NamespacedKey;
import org.bukkit.entity.Player;
public class ActionParticle extends Action {
public ActionParticle() {
super("particle");
}
@Override
public void run(CosmeticUser user, String raw) {
String[] rawString = raw.split(" ");
var particleType = Particles.fromKey(NamespacedKey.minecraft(rawString[0].toLowerCase()));
if (particleType == null) {
MessagesUtil.sendDebugMessages("The particle " + rawString[0] + " does not exist!");
return;
}
boolean multi = false;
if (particleType.multi() != null) {
multi = true; // Should work?
}
var particle = multi ? particleType.multi() : particleType.single();
if (particle instanceof DestinationParticle || particle instanceof BlockDataParticle
|| particle instanceof VibrationParticle || particle instanceof VelocityParticle) {
MessagesUtil.sendDebugMessages("The particle " + rawString[0] + " is not supported by this action!");
return;
}
Particle particle1 = ServerUtils.addParticleValues((Particle) particleType, rawString);
Location location = user.getPlayer().getLocation();
for (Player player : PacketManager.getViewers(location)) {
particle1.compile().send(player, location);
}
}
}

View File

@@ -1,8 +1,18 @@
package com.hibiscusmc.hmccosmetics.util;
import com.hibiscusmc.hmccosmetics.nms.NMSHandlers;
import com.owen1212055.particlehelper.api.particle.MultiParticle;
import com.owen1212055.particlehelper.api.particle.Particle;
import com.owen1212055.particlehelper.api.particle.types.*;
import com.owen1212055.particlehelper.api.particle.types.dust.transition.TransitionDustParticle;
import com.owen1212055.particlehelper.api.particle.types.note.MultiNoteParticle;
import org.bukkit.Color;
import org.bukkit.GameMode;
import org.bukkit.Material;
import org.jetbrains.annotations.Nullable;
import java.math.BigInteger;
import java.util.Arrays;
public class ServerUtils {
@@ -36,4 +46,84 @@ public class ServerUtils {
return null;
}
}
// particle amount offsetxyz
// Ex. HEART 10 0.1 0.1 0.1
public static Particle addParticleValues(Particle particle, String[] split) {
var counter = 1;
if (particle instanceof MultiParticle multiParticle) {
multiParticle.setCount(getBigInteger(split[counter]).intValue());
counter++;
multiParticle.setXOffset(getBigInteger(split[counter]).floatValue());
counter++;
multiParticle.setYOffset(getBigInteger(split[counter]).floatValue());
counter++;
multiParticle.setZOffset(getBigInteger(split[counter]).floatValue());
counter++;
if (multiParticle instanceof MultiNoteParticle multiNoteParticle) {
multiNoteParticle.setColorMultplier(getBigInteger(split[counter]).intValue());
counter++;
}
}
if (particle instanceof ColorableParticle colorableParticle && colorFromString(split[counter]) != null) {
colorableParticle.setColor(colorFromString(split[counter]));
counter++;
}
if (particle instanceof TransitionDustParticle transitionDustParticle && colorFromString(split[counter]) != null) {
transitionDustParticle.setFadeColor(colorFromString(split[counter]));
counter++;
}
if (particle instanceof MaterialParticle materialParticle && Material.getMaterial(split[counter]) != null) {
materialParticle.setMaterial(Material.getMaterial(split[counter]));
counter++;
}
if (particle instanceof SpeedModifiableParticle speedModifiableParticle) {
speedModifiableParticle.setSpeed(getBigInteger(split[counter]).floatValue());
counter++;
}
if (particle instanceof DelayableParticle delayableParticle) {
delayableParticle.setDelay(getBigInteger(split[counter]).intValue());
counter++;
}
if (particle instanceof SizeableParticle sizeableParticle) {
sizeableParticle.setSize(getBigInteger(split[counter]).floatValue());
counter++;
}
if (particle instanceof RollableParticle rollableParticle) {
rollableParticle.setRoll(getBigInteger(split[counter]).floatValue());
}
return particle;
}
private static BigInteger getBigInteger(String string) {
try {
return new BigInteger(string);
} catch (Exception e) {
return BigInteger.valueOf(1);
}
}
/**
* Parse a color from a string.
* Formats: #RRGGBB; R,G,B
*
* @param color The string
* @return The color, if the string can't be parsed, null is returned
*/
public static Color colorFromString(@Nullable String color) {
if (color == null) {
return null;
}
try {
var decodedColor = java.awt.Color.decode(color.startsWith("#") ? color : "#" + color);
return Color.fromRGB(decodedColor.getRed(), decodedColor.getGreen(), decodedColor.getBlue());
} catch (NumberFormatException invalidHex) {
try {
var rgbValues = Arrays.stream(color.split(",")).map(Integer::parseInt).toArray(Integer[]::new);
return Color.fromRGB(rgbValues[0], rgbValues[1], rgbValues[2]);
} catch (Exception invalidRgb) {
return null;
}
}
}
}