Add customizable flag material for Capture the Flag

Introduced a configurable `Material` property for flags to enhance flexibility. Updated relevant classes and methods to support dynamic flag material. Default material is set to `RED_BANNER`, with the option to override via configuration or team settings.
This commit is contained in:
Teriuihi 2025-02-15 02:42:27 +01:00
parent 56455b4c50
commit 7ae91bcf06
5 changed files with 29 additions and 19 deletions

View File

@ -12,6 +12,7 @@ import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.Material;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
@ -75,7 +76,7 @@ public class CreateTeam extends SubCommand {
int highestId = gameManager.getMaxTeamId();
Team team = new Team(MiniMessage.miniMessage().deserialize(String.format("<color:%s>%s</color>", color, name)),
highestId + 1, player.getLocation(), player.getLocation(), player.getLocation(), teamColor);
highestId + 1, player.getLocation(), player.getLocation(), player.getLocation(), teamColor, Material.RED_BANNER);
return consumer.apply(team);
}

View File

@ -3,6 +3,9 @@ package com.alttd.ctf.config;
import com.alttd.ctf.Main;
import com.alttd.ctf.game.GamePhase;
import lombok.extern.slf4j.Slf4j;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.time.Duration;
import java.util.HashMap;
@ -88,6 +91,7 @@ public class GameConfig extends AbstractConfig {
public static double CAPTURE_RADIUS = 5;
public static int CAPTURE_SCORE = 50;
public static double TURN_IN_RADIUS = 3;
public static @NotNull Material MATERIAL = Material.RED_BANNER;
@SuppressWarnings("unused")
private static void load() {
@ -98,6 +102,7 @@ public class GameConfig extends AbstractConfig {
CAPTURE_RADIUS = config.getDouble(prefix, "capture-radius", CAPTURE_RADIUS);
CAPTURE_SCORE = config.getInt(prefix, "capture-score", CAPTURE_SCORE);
TURN_IN_RADIUS = config.getDouble(prefix, "turn-in-radius", TURN_IN_RADIUS);
MATERIAL = Material.valueOf(config.getString(prefix, "material", MATERIAL.toString()));
}
}

View File

@ -33,7 +33,6 @@ public class Flag implements Runnable {
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
private final HashMap<Integer, Integer> teamFlagPointCount = new HashMap<>();
private final ItemStack flagItem = new ItemStack(Material.BLACK_BANNER);
private final BossBar bossBar = createBossBar();
private final HashMap<Integer, Integer> wins = new HashMap<>();
private int lastWinningTeamId = -1;
@ -80,15 +79,15 @@ public class Flag implements Runnable {
}
//TODO knockback enemies from flag location to create space for person who captured mayb short speed boost and heal?
//TODO add de-buffs and enable buffs for others?
player.getInventory().setItem(EquipmentSlot.HEAD, flagItem);
player.getInventory().setItem(EquipmentSlot.HEAD, new ItemStack(teamPlayer.getTeam().getFlagMaterial()));
Bukkit.getScheduler().runTask(main, () -> flagLocation.getBlock().setType(Material.AIR));
flagCarrier = player;
notifyAboutCapture();
resetFlag();
}
public void spawnFlag() {
Bukkit.getScheduler().runTask(main, () -> flagLocation.getBlock().setType(flagItem.getType()));
public void spawnFlag(Material material) {
Bukkit.getScheduler().runTask(main, () -> flagLocation.getBlock().setType(material));
}
private void spawnFlagParticleRing() {
@ -141,7 +140,7 @@ public class Flag implements Runnable {
updateDisplay();
} else {
winningTeam = optionalTeam.get();
resetFlag();
spawnFlag(winningTeam.getFlagMaterial());
//TODO stop capture and let ppl know they can now capture the flag
}
}
@ -194,9 +193,10 @@ public class Flag implements Runnable {
private void checkFlagCarrier() {
if (flagCarrier.isDead() || !flagCarrier.isOnline()) {
resetFlagCarrier();
spawnFlag();
spawnFlag(GameConfig.FLAG.MATERIAL);
return;
}
double distance = winningTeam.getFlagTurnInLocation().distance(flagCarrier.getLocation());
if (distance > GameConfig.FLAG.TURN_IN_RADIUS) {
Location location = flagCarrier.getLocation();
@ -206,18 +206,16 @@ public class Flag implements Runnable {
spawnParticlesOnSquareBorder(winningTeam.getFlagTurnInLocation(), GameConfig.FLAG.TURN_IN_RADIUS);
return;
}
notifyAboutTurnIn();
spawnFlag();
spawnFlag(GameConfig.FLAG.MATERIAL);
wins.merge(winningTeam.getId(), 1, Integer::sum);
winningTeam = null;
Optional<TeamPlayer> optionalTeamPlayer = gameManager.getTeamPlayer(flagCarrier.getUniqueId());
if (optionalTeamPlayer.isEmpty()) {
flagCarrier.getInventory().setItem(EquipmentSlot.HEAD, null);
} else {
TeamPlayer teamPlayer = optionalTeamPlayer.get();
teamPlayer.getGameClass().setArmor(flagCarrier, teamPlayer);
flagCarrier.getInventory().setItem(EquipmentSlot.HEAD, null);
}
flagCarrier.getInventory().setItem(EquipmentSlot.HEAD, null);
gameManager.getTeamPlayer(flagCarrier.getUniqueId())
.ifPresent(teamPlayer -> teamPlayer.getGameClass().setArmor(flagCarrier, teamPlayer));
resetFlagCarrier();
}
@ -377,7 +375,7 @@ public class Flag implements Runnable {
return;
}
resetFlagCarrier();
spawnFlag();
spawnFlag(GameConfig.FLAG.MATERIAL);
gameManager.getTeam(player.getUniqueId())
.ifPresentOrElse(team -> Bukkit.broadcast(MiniMessage.miniMessage()
.deserialize("<red><team>'s flag carrier died! The flag has respawned",

View File

@ -1,5 +1,6 @@
package com.alttd.ctf.game.phases;
import com.alttd.ctf.config.GameConfig;
import com.alttd.ctf.flag.Flag;
import com.alttd.ctf.game.GamePhase;
import com.alttd.ctf.game.GamePhaseExecutor;
@ -17,7 +18,7 @@ public class CombatPhase implements GamePhaseExecutor {
@Override
public synchronized void start(Flag flag) {
Bukkit.broadcast(MiniMessage.miniMessage().deserialize("<green>CAPTURE THE FLAG</green>"));
flag.spawnFlag();
flag.spawnFlag(GameConfig.FLAG.MATERIAL);
if (executorService == null) {
executorService = Executors.newSingleThreadScheduledExecutor();
} else if (executorService.isTerminated() || executorService.isShutdown()) {

View File

@ -8,6 +8,7 @@ import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import net.kyori.adventure.text.Component;
import org.bukkit.Location;
import org.bukkit.Material;
import org.jetbrains.annotations.NotNull;
import java.util.*;
@ -42,6 +43,10 @@ public class Team {
@NotNull
@Getter
private TeamColor color;
@JsonProperty("flagMaterial")
@NotNull
@Getter
private Material flagMaterial;
public TeamPlayer addPlayer(UUID uuid) {
TeamPlayer teamPlayer = new TeamPlayer(uuid, this);