-
-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add optional teleport warmup particle effect, which looks similar to
the spawn point particles, and will swirl downwards from head to toe while a teleport warmup is occuring. - Closes #7303. - New Config Option: spawning.spawning_warmups.uses_particle_effect - Default: true - When set to true, players get a particle effect matching the towny spawn particles, which appears around them for the warmup duration.
- Loading branch information
Showing
5 changed files
with
92 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
Towny/src/main/java/com/palmergames/bukkit/towny/object/TeleportWarmupParticle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package com.palmergames.bukkit.towny.object; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.bukkit.Location; | ||
import org.bukkit.Particle; | ||
import org.bukkit.World; | ||
|
||
import com.github.bsideup.jabel.Desugar; | ||
import com.palmergames.bukkit.towny.Towny; | ||
|
||
public class TeleportWarmupParticle { | ||
|
||
private static final List<RingCoord> RING_PATTERN = createRingOffsets(); | ||
public static final int RING_POINT_COUNT = 12; | ||
public static final int RING_DELAY_TICKS = 2; | ||
public final Location loc; | ||
|
||
public TeleportWarmupParticle(Location loc) { | ||
this.loc = loc; | ||
drawParticle(); | ||
} | ||
|
||
private void drawParticle() { | ||
final World world = loc.getWorld(); | ||
if (world == null) | ||
return; | ||
int i = 0; | ||
for (RingCoord ringPosition : RING_PATTERN) { | ||
Location point = loc.clone().add(ringPosition.x(), 0.0, ringPosition.z()); | ||
Towny.getPlugin().getScheduler().runAsyncLater(() -> { | ||
try { | ||
// This can potentially throw an exception if we're running this async and a player disconnects while it's sending particles. | ||
world.spawnParticle(Particle.CRIT_MAGIC, point, 1, 0.0, 0.0, 0.0, 0.0); | ||
} catch (Exception ignored) {} | ||
}, (long) i * RING_DELAY_TICKS); | ||
i++; | ||
} | ||
} | ||
|
||
private static List<RingCoord> createRingOffsets() { | ||
ArrayList<RingCoord> ring = new ArrayList<>(); | ||
|
||
final double radius = 0.45; | ||
final double angleIncrement = 2 * Math.PI / RING_POINT_COUNT; | ||
|
||
for (int i = 0; i < RING_POINT_COUNT; i++) { | ||
double angle = i * angleIncrement; | ||
double x = radius * Math.sin(angle); | ||
double y = radius * Math.cos(angle); | ||
ring.add(RingCoord.offset(x, y)); | ||
} | ||
|
||
return ring; | ||
} | ||
|
||
@Desugar | ||
private record RingCoord(double x, double z) { | ||
private static RingCoord offset(double a, double b) { | ||
return new RingCoord(a, b); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters