Stage 6-7: Hooks and UI systems
This commit is contained in:
parent
37e67ce97d
commit
1fd78e5421
2 changed files with 369 additions and 0 deletions
204
src/main/java/dev/loki/util/ParticleUtil.java
Normal file
204
src/main/java/dev/loki/util/ParticleUtil.java
Normal file
|
|
@ -0,0 +1,204 @@
|
|||
package dev.loki.util;
|
||||
|
||||
import org.bukkit.Color;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Particle;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.util.Vector;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public final class ParticleUtil {
|
||||
|
||||
private static final int DEFAULT_COUNT = 1;
|
||||
private static final double DEFAULT_SPREAD = 0.0;
|
||||
private static final float DEFAULT_SIZE = 1.0f;
|
||||
|
||||
private ParticleUtil() {}
|
||||
|
||||
public static void spawn(Particle particle, Location location) {
|
||||
spawn(particle, location, DEFAULT_COUNT);
|
||||
}
|
||||
|
||||
public static void spawn(Particle particle, Location location, int count) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
world.spawnParticle(particle, location, count);
|
||||
}
|
||||
|
||||
public static void spawn(Particle particle, Location location, int count, double spreadX, double spreadY, double spreadZ) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
world.spawnParticle(particle, location, count, spreadX, spreadY, spreadZ);
|
||||
}
|
||||
|
||||
public static void spawn(Particle particle, Location location, int count, double spreadX, double spreadY, double spreadZ, double speed) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
world.spawnParticle(particle, location, count, spreadX, spreadY, spreadZ, speed);
|
||||
}
|
||||
|
||||
public static void spawnDust(Location location, Color color, float size) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
Particle.DustOptions dustOptions = new Particle.DustOptions(color, size);
|
||||
world.spawnParticle(Particle.DUST, location, 1, dustOptions);
|
||||
}
|
||||
|
||||
public static void spawnDust(Location location, Color color, float size, int count) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
Particle.DustOptions dustOptions = new Particle.DustOptions(color, size);
|
||||
world.spawnParticle(Particle.DUST, location, count, 0.1, 0.1, 0.1, 0, dustOptions);
|
||||
}
|
||||
|
||||
public static void spawnToPlayer(Particle particle, Player player, Location location, int count) {
|
||||
player.spawnParticle(particle, location, count);
|
||||
}
|
||||
|
||||
public static void spawnToPlayer(Particle particle, Player player, Location location, int count, double spreadX, double spreadY, double spreadZ) {
|
||||
player.spawnParticle(particle, location, count, spreadX, spreadY, spreadZ);
|
||||
}
|
||||
|
||||
public static void drawLine(Particle particle, Location start, Location end, int points) {
|
||||
if (!start.getWorld().equals(end.getWorld())) return;
|
||||
|
||||
Vector direction = end.toVector().subtract(start.toVector());
|
||||
double distance = direction.length();
|
||||
direction.normalize();
|
||||
|
||||
double step = distance / points;
|
||||
Location current = start.clone();
|
||||
|
||||
for (int i = 0; i <= points; i++) {
|
||||
spawn(particle, current);
|
||||
current.add(direction.clone().multiply(step));
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawCircle(Particle particle, Location center, double radius, int points) {
|
||||
World world = center.getWorld();
|
||||
if (world == null) return;
|
||||
|
||||
for (int i = 0; i < points; i++) {
|
||||
double angle = 2 * Math.PI * i / points;
|
||||
double x = center.getX() + radius * Math.cos(angle);
|
||||
double z = center.getZ() + radius * Math.sin(angle);
|
||||
Location point = new Location(world, x, center.getY(), z);
|
||||
spawn(particle, point);
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawCircle(Particle particle, Location center, double radius, int points, Color color, float size) {
|
||||
World world = center.getWorld();
|
||||
if (world == null) return;
|
||||
|
||||
for (int i = 0; i < points; i++) {
|
||||
double angle = 2 * Math.PI * i / points;
|
||||
double x = center.getX() + radius * Math.cos(angle);
|
||||
double z = center.getZ() + radius * Math.sin(angle);
|
||||
Location point = new Location(world, x, center.getY(), z);
|
||||
spawnDust(point, color, size);
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawSphere(Particle particle, Location center, double radius, int points) {
|
||||
World world = center.getWorld();
|
||||
if (world == null) return;
|
||||
|
||||
for (int i = 0; i < points; i++) {
|
||||
double theta = Math.random() * 2 * Math.PI;
|
||||
double phi = Math.random() * Math.PI;
|
||||
double x = center.getX() + radius * Math.sin(phi) * Math.cos(theta);
|
||||
double y = center.getY() + radius * Math.cos(phi);
|
||||
double z = center.getZ() + radius * Math.sin(phi) * Math.sin(theta);
|
||||
Location point = new Location(world, x, y, z);
|
||||
spawn(particle, point);
|
||||
}
|
||||
}
|
||||
|
||||
public static void drawBox(Particle particle, Location min, Location max, double step) {
|
||||
if (!min.getWorld().equals(max.getWorld())) return;
|
||||
World world = min.getWorld();
|
||||
if (world == null) return;
|
||||
|
||||
for (double x = min.getX(); x <= max.getX(); x += step) {
|
||||
for (double y = min.getY(); y <= max.getY(); y += step) {
|
||||
for (double z = min.getZ(); z <= max.getZ(); z += step) {
|
||||
boolean edge = (x <= min.getX() + step || x >= max.getX() - step) ||
|
||||
(y <= min.getY() + step || y >= max.getY() - step) ||
|
||||
(z <= min.getZ() + step || z >= max.getZ() - step);
|
||||
if (edge) {
|
||||
spawn(particle, new Location(world, x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void burst(Particle particle, Location center, int count, double speed) {
|
||||
World world = center.getWorld();
|
||||
if (world == null) return;
|
||||
world.spawnParticle(particle, center, count, 0.5, 0.5, 0.5, speed);
|
||||
}
|
||||
|
||||
public static void burstToPlayers(Particle particle, List<Player> players, Location center, int count, double speed) {
|
||||
for (Player player : players) {
|
||||
player.spawnParticle(particle, center, count, 0.5, 0.5, 0.5, speed);
|
||||
}
|
||||
}
|
||||
|
||||
public static void trail(Particle particle, Location start, Vector direction, int length, double spacing) {
|
||||
Location current = start.clone();
|
||||
Vector step = direction.clone().normalize().multiply(spacing);
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
spawn(particle, current);
|
||||
current.add(step);
|
||||
}
|
||||
}
|
||||
|
||||
public static void shockwave(Particle particle, Location center, double maxRadius, int rings, double speed) {
|
||||
World world = center.getWorld();
|
||||
if (world == null) return;
|
||||
|
||||
for (int ring = 1; ring <= rings; ring++) {
|
||||
double radius = (maxRadius / rings) * ring;
|
||||
int points = (int) (16 * radius);
|
||||
drawCircle(particle, center, radius, points);
|
||||
}
|
||||
}
|
||||
|
||||
public static void damageIndicator(Location location) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
world.spawnParticle(Particle.DAMAGE_INDICATOR, location, 10, 0.3, 0.3, 0.3, 0);
|
||||
}
|
||||
|
||||
public static void blood(Location location) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
world.spawnParticle(Particle.BLOCK_CRUMBLE, location, 20, 0.2, 0.2, 0.2, 0,
|
||||
org.bukkit.Material.REDSTONE_BLOCK.createBlockData());
|
||||
}
|
||||
|
||||
public static void sparks(Location location) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
world.spawnParticle(Particle.ELECTRIC_SPARK, location, 5, 0.1, 0.1, 0.1, 0.1);
|
||||
}
|
||||
|
||||
public static void heal(Location location) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
spawnDust(location, Color.LIME, 1.0f, 10);
|
||||
}
|
||||
|
||||
public static void teleportEffect(Location location) {
|
||||
World world = location.getWorld();
|
||||
if (world == null) return;
|
||||
world.spawnParticle(Particle.PORTAL, location, 100, 0.5, 1.0, 0.5, 1.0);
|
||||
world.spawnParticle(Particle.REVERSE_PORTAL, location, 50, 0.3, 0.5, 0.3, 0.5);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue