Compare commits

..

No commits in common. "a4f96297c207449817bdf939cf39a36b643a7224" and "6f77135426d7bee29a466dcee284208539ee0402" have entirely different histories.

7 changed files with 10 additions and 148 deletions

View File

@ -3,10 +3,8 @@ 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;
@ -27,7 +25,6 @@ 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()));
});
}
@ -37,19 +34,17 @@ public class SelectClass extends SubCommand {
commandSender.sendRichMessage(Messages.GENERIC.PLAYER_ONLY);
return -1;
}
Optional<GamePhase> optionalGamePhase = gameManager.getGamePhase();
if (optionalGamePhase.isEmpty()) {
if (gameManager.getGamePhase().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 (!gamePhase.equals(GamePhase.CLASS_SELECTION) && teamPlayer.getTeam().getSpawnLocation().distance(player.getLocation()) > 5) {
if (teamPlayer.getTeam().getSpawnLocation().distance(player.getLocation()) > 15) {
commandSender.sendRichMessage("<red>You have to be near your spawn to change classes.</red>");
return 0;
}

View File

@ -1,14 +1,10 @@
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 {
@ -30,16 +26,4 @@ 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,7 +4,6 @@ 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;
@ -25,7 +24,6 @@ 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;
@ -40,7 +38,7 @@ public class Flag implements Runnable {
private int lastWinningTeamId = -1;
private Location flagLocation;
private Team winningTeam;
private Player flagCarrier;
private Player flagCarrier; //TODO check for player disconnects?
private final Main main;
private final GameManager gameManager;
@ -81,7 +79,6 @@ public class Flag implements Runnable {
Placeholder.component("team", teamPlayer.getTeam().getName())
)));
flagCarrier = player;
teamFlagPointCount.clear();
}
public void spawnFlag() {
@ -105,7 +102,6 @@ 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
}
@ -123,49 +119,14 @@ 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() || !flagCarrier.isOnline()) {
if (flagCarrier.isDead()) {
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;
}
@ -184,8 +145,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() {
@ -312,7 +273,6 @@ public class Flag implements Runnable {
bossBar.setProgress(0);
winningTeam = null;
flagCarrier = null;
particleTrail.clear();
wins.clear();
lastWinningTeamId = -1;
}

View File

@ -3,40 +3,27 @@ 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(teamColor), getDisplayItem(teamColor), 15, 3, 5);
return new Fighter(getArmor(), getTools(), 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(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 List<ItemStack> getTools() {
return (List.of());
}
private static ItemStack getDisplayItem(TeamColor teamColor) {

View File

@ -1,49 +0,0 @@
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

@ -1,15 +0,0 @@
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 @@
#Sat Feb 08 00:30:51 CET 2025
buildNumber=11
#Fri Feb 07 23:34:22 CET 2025
buildNumber=9
version=0.1