Skip to content

Commit

Permalink
- Add optional teleport warmup particle effect, which looks similar to
Browse files Browse the repository at this point in the history
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
LlmDl committed Mar 9, 2024
1 parent 15e8dd6 commit 7b270e1
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,11 @@ public enum ConfigNodes {
"",
"# When set to true, players get a large Title message showing how long until their teleport will happen,",
"# as well as a message telling them not to move if movement_cancels_spawn_warmup is true."),
SPAWNING_WARMUP_SHOWS_PARTICLE(
"spawning.spawning_warmups.uses_particle_effect",
"true",
"",
"# When set to true, players get a particle effect matching the towny spawn particles, which appears around them for the warmup duration."),

SPAWNING_TOWN_SPAWN_ROOT("spawning.town_spawn","",""),
SPAWNING_ALLOW_TOWN_SPAWN(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2976,6 +2976,10 @@ public static boolean isTeleportWarmupUsingTitleMessage() {
return getBoolean(ConfigNodes.SPAWNING_WARMUP_USES_TITLE_MESSAGE);
}

public static boolean isTeleportWarmupShowingParticleEffect() {
return getBoolean(ConfigNodes.SPAWNING_WARMUP_SHOWS_PARTICLE);
}

public static int getSpawnCooldownTime() {

return getInt(ConfigNodes.SPAWNING_TOWN_SPAWN_COOLDOWN_TIMER);
Expand Down
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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.palmergames.bukkit.towny.TownySettings;
import com.palmergames.bukkit.towny.TownyTimerHandler;
import com.palmergames.bukkit.towny.object.Resident;
import com.palmergames.bukkit.towny.object.TeleportWarmupParticle;
import com.palmergames.bukkit.towny.object.TeleportRequest;
import com.palmergames.bukkit.towny.object.Translatable;
import com.palmergames.bukkit.towny.object.Translation;
Expand Down Expand Up @@ -43,13 +44,14 @@ public TeleportWarmupTimerTask(Towny plugin) {
public void run() {

long currentTime = System.currentTimeMillis();
int teleportWarmupTime = TownySettings.getTeleportWarmupTime();
Iterator<Map.Entry<Resident, TeleportRequest>> iterator = TELEPORT_QUEUE.entrySet().iterator();

while (iterator.hasNext()) {
Map.Entry<Resident, TeleportRequest> next = iterator.next();
final Resident resident = next.getKey();
final TeleportRequest request = next.getValue();
long teleportTime = request.requestTime() + (TownySettings.getTeleportWarmupTime() * 1000L);
long teleportTime = request.requestTime() + (teleportWarmupTime * 1000L);

if (currentTime > teleportTime) {
iterator.remove();
Expand All @@ -65,17 +67,21 @@ public void run() {
CooldownTimerTask.addCooldownTimer(resident.getName(), "teleport", request.cooldown());
continue;
}


long millis = teleportTime - currentTime;
int seconds = (int) Math.max(1, millis/1000);
// Send a title message.
if (TownySettings.isTeleportWarmupUsingTitleMessage()) {
if (TownySettings.isTeleportWarmupUsingTitleMessage() && millis >= 1000) {
String title = TownySettings.isMovementCancellingSpawnWarmup() ? Translatable.of("teleport_warmup_title_dont_move").forLocale(resident) : "";
long millis = teleportTime - currentTime;
if (millis < 1000)
continue;
int seconds = (int) Math.max(1, millis/1000);
String subtitle = Translatable.of("teleport_warmup_subtitle_seconds_remaining", seconds).forLocale(resident);
resident.getPlayer().sendTitle(title, subtitle, 0, 25, (seconds == 1 ? 15 : 0));
}
// Send a particle that drops from above the player to their feet over the course of the warmup.
if (TownySettings.isTeleportWarmupShowingParticleEffect()) {
double progress = (double) (teleportWarmupTime - seconds) / teleportWarmupTime;
double offset = 2.0 + (progress * -2.0);
new TeleportWarmupParticle(resident.getPlayer().getLocation().add(0.0, offset, 0.0));
}
}
}

Expand Down
7 changes: 6 additions & 1 deletion Towny/src/main/resources/ChangeLog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9593,4 +9593,9 @@ v0.92.0.11:
- New Config Option: spawning.spawning_warmups.uses_title_message
- Default: false
- When set to true, players get a large Title message showing how long until their teleport will happen,
as well as a message telling them not to move if movement_cancels_spawn_warmup is true.
as well as a message telling them not to move if movement_cancels_spawn_warmup is true.
- 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.

0 comments on commit 7b270e1

Please sign in to comment.