Integrate WorldBorderAPI and enhance game phase functionality
Added WorldBorderAPI dependency to manage player boundaries dynamically during game phases. Updated game phases, respawn mechanics, and class selection to utilize the WorldBorderAPI. Reworked related components to improve boundary handling, ensuring consistent gameplay flow and preparation for future enhancements.
This commit is contained in:
@@ -1,12 +1,21 @@
|
||||
package com.alttd.ctf.team;
|
||||
|
||||
import com.alttd.ctf.game.GamePhase;
|
||||
import com.alttd.ctf.game_class.GameClass;
|
||||
import com.github.yannicklamprecht.worldborder.api.IWorldBorder;
|
||||
import com.github.yannicklamprecht.worldborder.api.Position;
|
||||
import com.github.yannicklamprecht.worldborder.api.WorldBorderApi;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
|
||||
@Slf4j
|
||||
@Getter
|
||||
public class TeamPlayer {
|
||||
|
||||
@@ -20,6 +29,35 @@ public class TeamPlayer {
|
||||
this.team = team;
|
||||
}
|
||||
|
||||
public void respawn(@NotNull Player player, @NotNull WorldBorderApi worldBorderApi, @NotNull GamePhase gamePhase) {
|
||||
respawn(player, worldBorderApi, gamePhase, true);
|
||||
}
|
||||
|
||||
public void respawn(Player player, WorldBorderApi worldBorderApi, GamePhase gamePhase, boolean teleport) {
|
||||
Location spawnLocation = team.getSpawnLocation();
|
||||
Location worldBorderCenter = team.getWorldBorderCenter();
|
||||
if (!teleport) {
|
||||
resetWorldBorder(player, worldBorderApi, gamePhase, worldBorderCenter);
|
||||
return;
|
||||
}
|
||||
player.teleportAsync(spawnLocation).thenAcceptAsync(unused ->
|
||||
resetWorldBorder(player, worldBorderApi, gamePhase, worldBorderCenter));
|
||||
}
|
||||
|
||||
public void resetWorldBorder(Player player, WorldBorderApi worldBorderApi, GamePhase gamePhase, Location worldBorderCenter) {
|
||||
log.info("Resetting world border for {}", player.getName());
|
||||
double worldBorderSize = gamePhase.getWorldBorderSize();
|
||||
log.info("Resetting world border to {} for {}", worldBorderSize, player.getName());
|
||||
IWorldBorder worldBorder = worldBorderApi.getWorldBorder(player);
|
||||
if (worldBorderSize <= 0) {
|
||||
log.info("Resetting world border to global for {}", player.getName());
|
||||
worldBorderApi.resetWorldBorderToGlobal(player);
|
||||
return;
|
||||
}
|
||||
log.info("Resetting world border to {} for {}", worldBorderCenter.toString(), player.getName());
|
||||
worldBorderApi.setBorder(player, worldBorderSize, worldBorderCenter);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
|
||||
Reference in New Issue
Block a user