Compare commits

...

3 Commits

Author SHA1 Message Date
Teriuihi a4f96297c2 Improve CTF gameplay mechanics and particle effects
Updated class selection to restrict changes during non-selection phases and adjusted spawn radius. Added flag particle trails and square border effects, improving visual feedback. Enhanced flag handling, clearing trails when the carrier is lost or offline.
2025-02-08 00:39:05 +01:00
Teriuihi 9eccb130e5 Add Tank class and update Fighter tools in CTF game
Introduced a new Tank game class with specialized attributes and equipment, and added it to the class selection setup. Enhanced the Fighter class by introducing a healing potion tool to improve gameplay utility. These changes enhance gameplay diversity and team strategies.
2025-02-08 00:05:46 +01:00
Teriuihi 4aa6a0d512 Add player respawn handling with custom logic
Introduced a new event handler for player respawn to set custom spawn locations and apply game class attributes. This ensures players rejoin the game with the correct state after death.
2025-02-07 23:55:53 +01:00
7 changed files with 148 additions and 10 deletions

View File

@ -3,8 +3,10 @@ package com.alttd.ctf.commands.subcommands;
import com.alttd.ctf.commands.SubCommand;
import com.alttd.ctf.config.Messages;
import com.alttd.ctf.game.GameManager;
import com.alttd.ctf.game.GamePhase;
import com.alttd.ctf.game_class.GameClass;
import com.alttd.ctf.game_class.creation.FighterCreator;
import com.alttd.ctf.game_class.creation.TankCreator;
import com.alttd.ctf.gui.ClassSelectionGUI;
import com.alttd.ctf.team.TeamPlayer;
import org.bukkit.command.CommandSender;
@ -25,6 +27,7 @@ public class SelectClass extends SubCommand {
this.gameClasses = new HashMap<>();
gameManager.getTeams().forEach(team -> {
gameClasses.computeIfAbsent(team.getId(), teamId -> new ArrayList<>()).add(FighterCreator.createFighter(team.getColor()));
gameClasses.computeIfAbsent(team.getId(), teamId -> new ArrayList<>()).add(TankCreator.createTank(team.getColor()));
});
}
@ -34,17 +37,19 @@ public class SelectClass extends SubCommand {
commandSender.sendRichMessage(Messages.GENERIC.PLAYER_ONLY);
return -1;
}
if (gameManager.getGamePhase().isEmpty()) {
Optional<GamePhase> optionalGamePhase = gameManager.getGamePhase();
if (optionalGamePhase.isEmpty()) {
commandSender.sendRichMessage("<red>CTF has to be running to select a class.</red>");
return 0;
}
GamePhase gamePhase = optionalGamePhase.get();
Optional<TeamPlayer> optionalTeamPlayer = gameManager.getTeamPlayer(player.getUniqueId());
if (optionalTeamPlayer.isEmpty()) {
commandSender.sendRichMessage("<red>You have to be in a CTF team to select a class.</red>");
return 0;
}
TeamPlayer teamPlayer = optionalTeamPlayer.get();
if (teamPlayer.getTeam().getSpawnLocation().distance(player.getLocation()) > 15) {
if (!gamePhase.equals(GamePhase.CLASS_SELECTION) && teamPlayer.getTeam().getSpawnLocation().distance(player.getLocation()) > 5) {
commandSender.sendRichMessage("<red>You have to be near your spawn to change classes.</red>");
return 0;
}

View File

@ -1,10 +1,14 @@
package com.alttd.ctf.events;
import com.alttd.ctf.game.GameManager;
import com.alttd.ctf.team.TeamPlayer;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.entity.PlayerDeathEvent;
import org.bukkit.event.player.PlayerRespawnEvent;
import java.util.Optional;
public class OnPlayerDeath implements Listener {
@ -26,4 +30,16 @@ public class OnPlayerDeath implements Listener {
player.updateInventory();
}
@EventHandler
public void onPlayerRespawn(PlayerRespawnEvent event) {
Player player = event.getPlayer();
Optional<TeamPlayer> optionalTeamPlayer = gameManager.getTeamPlayer(player.getUniqueId());
if (optionalTeamPlayer.isEmpty()) {
return;
}
TeamPlayer teamPlayer = optionalTeamPlayer.get();
event.setRespawnLocation(teamPlayer.getTeam().getSpawnLocation());
teamPlayer.getGameClass().apply(teamPlayer);
}
}

View File

@ -4,6 +4,7 @@ import com.alttd.ctf.Main;
import com.alttd.ctf.config.Config;
import com.alttd.ctf.game.GameManager;
import com.alttd.ctf.team.Team;
import com.alttd.ctf.team.TeamColor;
import com.alttd.ctf.team.TeamPlayer;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@ -24,6 +25,7 @@ import org.bukkit.scheduler.BukkitScheduler;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.Future;
import java.util.stream.Collectors;
@ -38,7 +40,7 @@ public class Flag implements Runnable {
private int lastWinningTeamId = -1;
private Location flagLocation;
private Team winningTeam;
private Player flagCarrier; //TODO check for player disconnects?
private Player flagCarrier;
private final Main main;
private final GameManager gameManager;
@ -79,6 +81,7 @@ public class Flag implements Runnable {
Placeholder.component("team", teamPlayer.getTeam().getName())
)));
flagCarrier = player;
teamFlagPointCount.clear();
}
public void spawnFlag() {
@ -102,6 +105,7 @@ public class Flag implements Runnable {
log.warn("Tried to run Flag without a flag location, spawn it first");
return;
}
spawnParticlesOnSquareBorder(flagLocation.getWorld(), flagLocation);
if (!updateScoreBasedOnNearbyPlayers().join()) {
return; //Score didn't change
}
@ -119,14 +123,49 @@ public class Flag implements Runnable {
}
}
private void spawnParticlesOnSquareBorder(World world, Location center) {
double size = 10;
double step = 0.2;
center.add(0, 0.5, 0);
Bukkit.getScheduler().runTask(main, () -> {
// Top and Bottom (Z varies, X constant)
for (double z = -size; z <= size; z += step) {
world.spawnParticle(Particle.FLAME, center.getX() + size, center.getY(), center.getZ() + z, 1, 0, 0, 0, 0);
world.spawnParticle(Particle.FLAME, center.getX() - size, center.getY(), center.getZ() + z, 1, 0, 0, 0, 0);
}
// Left and Right (X varies, Z constant)
for (double x = -size; x <= size; x += step) {
world.spawnParticle(Particle.FLAME, center.getX() + x, center.getY(), center.getZ() + size, 1, 0, 0, 0, 0);
world.spawnParticle(Particle.FLAME, center.getX() + x, center.getY(), center.getZ() - size, 1, 0, 0, 0, 0);
}
});
}
LinkedList<Location> particleTrail = new LinkedList<>();
private void spawnTrail() {
TeamColor color = winningTeam.getColor();
particleTrail.forEach(location -> location.getWorld().spawnParticle(Particle.DUST, location, 1, 0, 0, 0,
new Particle.DustOptions(Color.fromRGB(color.r(), color.g(), color.b()), 1)));
if (particleTrail.size() > 15) {
particleTrail.removeFirst();
}
}
private void checkFlagCarrier() {
if (flagCarrier.isDead()) {
if (flagCarrier.isDead() || !flagCarrier.isOnline()) {
flagCarrier = null;
particleTrail.clear();
spawnFlag();
return;
}
double distance = winningTeam.getSpawnLocation().distance(flagCarrier.getLocation());
if (distance > 5) {
Location location = flagCarrier.getLocation();
location.setY(location.getY() + 1);
particleTrail.add(location);
spawnTrail();
//TODO spawn some particles or something so a trail is made for specific classes to follow?
return;
}
@ -145,8 +184,8 @@ public class Flag implements Runnable {
teamPlayer.getGameClass().setArmor(flagCarrier, teamPlayer);
flagCarrier.getInventory().setItem(EquipmentSlot.HEAD, null);
}
teamFlagPointCount.clear();
flagCarrier = null;
particleTrail.clear();
}
private Optional<Team> winnerExists() {
@ -273,6 +312,7 @@ public class Flag implements Runnable {
bossBar.setProgress(0);
winningTeam = null;
flagCarrier = null;
particleTrail.clear();
wins.clear();
lastWinningTeamId = -1;
}

View File

@ -3,27 +3,40 @@ package com.alttd.ctf.game_class.creation;
import com.alttd.ctf.game_class.GameClass;
import com.alttd.ctf.game_class.implementations.Fighter;
import com.alttd.ctf.team.TeamColor;
import lombok.extern.slf4j.Slf4j;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionType;
import java.util.List;
@Slf4j
public class FighterCreator {
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
public static GameClass createFighter(TeamColor teamColor) {
return new Fighter(getArmor(), getTools(), getDisplayItem(teamColor), 15, 3, 5);
return new Fighter(getArmor(), getTools(teamColor), getDisplayItem(teamColor), 15, 3, 5);
}
private static List<Material> getArmor() {
return (List.of(Material.AIR, Material.AIR, Material.LEATHER_CHESTPLATE, Material.AIR));
}
private static List<ItemStack> getTools() {
return (List.of());
private static List<ItemStack> getTools(TeamColor teamColor) {
ItemStack healthPot = new ItemStack(Material.SPLASH_POTION);
if (!(healthPot.getItemMeta() instanceof PotionMeta potionMeta)) {
throw new IllegalStateException("No potion meta from a splash potion");
}
potionMeta.setBasePotionType(PotionType.STRONG_HEALING);
potionMeta.itemName(MiniMessage.miniMessage().deserialize(
String.format("<color:%s>Emergency AOE med kit</color>", teamColor.hex())));
healthPot.setItemMeta(potionMeta);
healthPot.setAmount(3);
return (List.of(healthPot));
}
private static ItemStack getDisplayItem(TeamColor teamColor) {

View File

@ -0,0 +1,49 @@
package com.alttd.ctf.game_class.creation;
import com.alttd.ctf.game_class.GameClass;
import com.alttd.ctf.game_class.implementations.Fighter;
import com.alttd.ctf.team.TeamColor;
import lombok.extern.slf4j.Slf4j;
import net.kyori.adventure.text.minimessage.MiniMessage;
import org.bukkit.Material;
import org.bukkit.inventory.ItemFlag;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import java.util.List;
@Slf4j
public class TankCreator {
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
public static GameClass createTank(TeamColor teamColor) {//TODO add ability to become temp invulnerable (with some particle effects mayb?)
return new Fighter(getArmor(), getTools(teamColor), getDisplayItem(teamColor), 30, 7, 4);
}
private static List<Material> getArmor() {
return (List.of(Material.CHAINMAIL_BOOTS, Material.CHAINMAIL_LEGGINGS, Material.LEATHER_CHESTPLATE, Material.CHAINMAIL_HELMET));
}
private static List<ItemStack> getTools(TeamColor teamColor) {
ItemStack shield = new ItemStack(Material.SHIELD);
ItemMeta itemMeta = shield.getItemMeta();
itemMeta.addItemFlags(ItemFlag.HIDE_UNBREAKABLE);
itemMeta.itemName(MiniMessage.miniMessage().deserialize(
String.format("<color:%s>Shield</color>", teamColor.hex())));
shield.setItemMeta(itemMeta);
return (List.of(shield));
}
private static ItemStack getDisplayItem(TeamColor teamColor) {
ItemStack itemStack = new ItemStack(Material.SHIELD);
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.displayName(miniMessage.deserialize(String.format("<color:%s>Tank</color>", teamColor.hex())));
itemMeta.lore(List.of(
miniMessage.deserialize("<gold>The Tank is slow but has a lot of health</gold>"),
miniMessage.deserialize("<gold>They can protect themselves and their team with their shield.</gold>")
));
itemStack.setItemMeta(itemMeta);
return itemStack;
}
}

View File

@ -0,0 +1,15 @@
package com.alttd.ctf.game_class.implementations;
import com.alttd.ctf.game_class.GameClass;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.List;
public class Tank extends GameClass {
protected Tank(@NotNull List<Material> armor, @NotNull List<ItemStack> tools, @NotNull ItemStack displayItem, double health, int throwTickSpeed, int damage) {
super(armor, tools, displayItem, health, throwTickSpeed, damage);
}
}

View File

@ -1,3 +1,3 @@
#Fri Feb 07 23:34:22 CET 2025
buildNumber=9
#Sat Feb 08 00:30:51 CET 2025
buildNumber=11
version=0.1