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:
parent
56455b4c50
commit
7ae91bcf06
|
|
@ -12,6 +12,7 @@ import lombok.AllArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.kyori.adventure.text.minimessage.MiniMessage;
|
import net.kyori.adventure.text.minimessage.MiniMessage;
|
||||||
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.bukkit.command.CommandSender;
|
import org.bukkit.command.CommandSender;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
|
|
||||||
|
|
@ -75,7 +76,7 @@ public class CreateTeam extends SubCommand {
|
||||||
|
|
||||||
int highestId = gameManager.getMaxTeamId();
|
int highestId = gameManager.getMaxTeamId();
|
||||||
Team team = new Team(MiniMessage.miniMessage().deserialize(String.format("<color:%s>%s</color>", color, name)),
|
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);
|
return consumer.apply(team);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,9 @@ package com.alttd.ctf.config;
|
||||||
import com.alttd.ctf.Main;
|
import com.alttd.ctf.Main;
|
||||||
import com.alttd.ctf.game.GamePhase;
|
import com.alttd.ctf.game.GamePhase;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
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.time.Duration;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
@ -88,6 +91,7 @@ public class GameConfig extends AbstractConfig {
|
||||||
public static double CAPTURE_RADIUS = 5;
|
public static double CAPTURE_RADIUS = 5;
|
||||||
public static int CAPTURE_SCORE = 50;
|
public static int CAPTURE_SCORE = 50;
|
||||||
public static double TURN_IN_RADIUS = 3;
|
public static double TURN_IN_RADIUS = 3;
|
||||||
|
public static @NotNull Material MATERIAL = Material.RED_BANNER;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static void load() {
|
private static void load() {
|
||||||
|
|
@ -98,6 +102,7 @@ public class GameConfig extends AbstractConfig {
|
||||||
CAPTURE_RADIUS = config.getDouble(prefix, "capture-radius", CAPTURE_RADIUS);
|
CAPTURE_RADIUS = config.getDouble(prefix, "capture-radius", CAPTURE_RADIUS);
|
||||||
CAPTURE_SCORE = config.getInt(prefix, "capture-score", CAPTURE_SCORE);
|
CAPTURE_SCORE = config.getInt(prefix, "capture-score", CAPTURE_SCORE);
|
||||||
TURN_IN_RADIUS = config.getDouble(prefix, "turn-in-radius", TURN_IN_RADIUS);
|
TURN_IN_RADIUS = config.getDouble(prefix, "turn-in-radius", TURN_IN_RADIUS);
|
||||||
|
MATERIAL = Material.valueOf(config.getString(prefix, "material", MATERIAL.toString()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -33,7 +33,6 @@ public class Flag implements Runnable {
|
||||||
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
|
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
|
||||||
|
|
||||||
private final HashMap<Integer, Integer> teamFlagPointCount = new HashMap<>();
|
private final HashMap<Integer, Integer> teamFlagPointCount = new HashMap<>();
|
||||||
private final ItemStack flagItem = new ItemStack(Material.BLACK_BANNER);
|
|
||||||
private final BossBar bossBar = createBossBar();
|
private final BossBar bossBar = createBossBar();
|
||||||
private final HashMap<Integer, Integer> wins = new HashMap<>();
|
private final HashMap<Integer, Integer> wins = new HashMap<>();
|
||||||
private int lastWinningTeamId = -1;
|
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 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?
|
//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));
|
Bukkit.getScheduler().runTask(main, () -> flagLocation.getBlock().setType(Material.AIR));
|
||||||
flagCarrier = player;
|
flagCarrier = player;
|
||||||
notifyAboutCapture();
|
notifyAboutCapture();
|
||||||
resetFlag();
|
resetFlag();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void spawnFlag() {
|
public void spawnFlag(Material material) {
|
||||||
Bukkit.getScheduler().runTask(main, () -> flagLocation.getBlock().setType(flagItem.getType()));
|
Bukkit.getScheduler().runTask(main, () -> flagLocation.getBlock().setType(material));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void spawnFlagParticleRing() {
|
private void spawnFlagParticleRing() {
|
||||||
|
|
@ -141,7 +140,7 @@ public class Flag implements Runnable {
|
||||||
updateDisplay();
|
updateDisplay();
|
||||||
} else {
|
} else {
|
||||||
winningTeam = optionalTeam.get();
|
winningTeam = optionalTeam.get();
|
||||||
resetFlag();
|
spawnFlag(winningTeam.getFlagMaterial());
|
||||||
//TODO stop capture and let ppl know they can now capture the flag
|
//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() {
|
private void checkFlagCarrier() {
|
||||||
if (flagCarrier.isDead() || !flagCarrier.isOnline()) {
|
if (flagCarrier.isDead() || !flagCarrier.isOnline()) {
|
||||||
resetFlagCarrier();
|
resetFlagCarrier();
|
||||||
spawnFlag();
|
spawnFlag(GameConfig.FLAG.MATERIAL);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
double distance = winningTeam.getFlagTurnInLocation().distance(flagCarrier.getLocation());
|
double distance = winningTeam.getFlagTurnInLocation().distance(flagCarrier.getLocation());
|
||||||
if (distance > GameConfig.FLAG.TURN_IN_RADIUS) {
|
if (distance > GameConfig.FLAG.TURN_IN_RADIUS) {
|
||||||
Location location = flagCarrier.getLocation();
|
Location location = flagCarrier.getLocation();
|
||||||
|
|
@ -206,18 +206,16 @@ public class Flag implements Runnable {
|
||||||
spawnParticlesOnSquareBorder(winningTeam.getFlagTurnInLocation(), GameConfig.FLAG.TURN_IN_RADIUS);
|
spawnParticlesOnSquareBorder(winningTeam.getFlagTurnInLocation(), GameConfig.FLAG.TURN_IN_RADIUS);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyAboutTurnIn();
|
notifyAboutTurnIn();
|
||||||
spawnFlag();
|
spawnFlag(GameConfig.FLAG.MATERIAL);
|
||||||
|
|
||||||
wins.merge(winningTeam.getId(), 1, Integer::sum);
|
wins.merge(winningTeam.getId(), 1, Integer::sum);
|
||||||
winningTeam = null;
|
|
||||||
Optional<TeamPlayer> optionalTeamPlayer = gameManager.getTeamPlayer(flagCarrier.getUniqueId());
|
flagCarrier.getInventory().setItem(EquipmentSlot.HEAD, null);
|
||||||
if (optionalTeamPlayer.isEmpty()) {
|
gameManager.getTeamPlayer(flagCarrier.getUniqueId())
|
||||||
flagCarrier.getInventory().setItem(EquipmentSlot.HEAD, null);
|
.ifPresent(teamPlayer -> teamPlayer.getGameClass().setArmor(flagCarrier, teamPlayer));
|
||||||
} else {
|
|
||||||
TeamPlayer teamPlayer = optionalTeamPlayer.get();
|
|
||||||
teamPlayer.getGameClass().setArmor(flagCarrier, teamPlayer);
|
|
||||||
flagCarrier.getInventory().setItem(EquipmentSlot.HEAD, null);
|
|
||||||
}
|
|
||||||
resetFlagCarrier();
|
resetFlagCarrier();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -377,7 +375,7 @@ public class Flag implements Runnable {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
resetFlagCarrier();
|
resetFlagCarrier();
|
||||||
spawnFlag();
|
spawnFlag(GameConfig.FLAG.MATERIAL);
|
||||||
gameManager.getTeam(player.getUniqueId())
|
gameManager.getTeam(player.getUniqueId())
|
||||||
.ifPresentOrElse(team -> Bukkit.broadcast(MiniMessage.miniMessage()
|
.ifPresentOrElse(team -> Bukkit.broadcast(MiniMessage.miniMessage()
|
||||||
.deserialize("<red><team>'s flag carrier died! The flag has respawned",
|
.deserialize("<red><team>'s flag carrier died! The flag has respawned",
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
package com.alttd.ctf.game.phases;
|
package com.alttd.ctf.game.phases;
|
||||||
|
|
||||||
|
import com.alttd.ctf.config.GameConfig;
|
||||||
import com.alttd.ctf.flag.Flag;
|
import com.alttd.ctf.flag.Flag;
|
||||||
import com.alttd.ctf.game.GamePhase;
|
import com.alttd.ctf.game.GamePhase;
|
||||||
import com.alttd.ctf.game.GamePhaseExecutor;
|
import com.alttd.ctf.game.GamePhaseExecutor;
|
||||||
|
|
@ -17,7 +18,7 @@ public class CombatPhase implements GamePhaseExecutor {
|
||||||
@Override
|
@Override
|
||||||
public synchronized void start(Flag flag) {
|
public synchronized void start(Flag flag) {
|
||||||
Bukkit.broadcast(MiniMessage.miniMessage().deserialize("<green>CAPTURE THE FLAG</green>"));
|
Bukkit.broadcast(MiniMessage.miniMessage().deserialize("<green>CAPTURE THE FLAG</green>"));
|
||||||
flag.spawnFlag();
|
flag.spawnFlag(GameConfig.FLAG.MATERIAL);
|
||||||
if (executorService == null) {
|
if (executorService == null) {
|
||||||
executorService = Executors.newSingleThreadScheduledExecutor();
|
executorService = Executors.newSingleThreadScheduledExecutor();
|
||||||
} else if (executorService.isTerminated() || executorService.isShutdown()) {
|
} else if (executorService.isTerminated() || executorService.isShutdown()) {
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ import lombok.NoArgsConstructor;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import net.kyori.adventure.text.Component;
|
import net.kyori.adventure.text.Component;
|
||||||
import org.bukkit.Location;
|
import org.bukkit.Location;
|
||||||
|
import org.bukkit.Material;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
@ -42,6 +43,10 @@ public class Team {
|
||||||
@NotNull
|
@NotNull
|
||||||
@Getter
|
@Getter
|
||||||
private TeamColor color;
|
private TeamColor color;
|
||||||
|
@JsonProperty("flagMaterial")
|
||||||
|
@NotNull
|
||||||
|
@Getter
|
||||||
|
private Material flagMaterial;
|
||||||
|
|
||||||
public TeamPlayer addPlayer(UUID uuid) {
|
public TeamPlayer addPlayer(UUID uuid) {
|
||||||
TeamPlayer teamPlayer = new TeamPlayer(uuid, this);
|
TeamPlayer teamPlayer = new TeamPlayer(uuid, this);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user