Add Engineer class and update Tank, Fighter, and GameClass

Introduced the Engineer class with unique tools, functionality, and creation logic. Updated the Tank class to make its constructor public and adjusted its creator to use the appropriate class. Enhanced GameClass to append health and damage details to display item lore dynamically.
This commit is contained in:
Teriuihi 2025-02-08 15:19:32 +01:00
parent a175d1829b
commit 6bb4673b08
8 changed files with 119 additions and 8 deletions

View File

@ -5,7 +5,6 @@
- [x] Stores all players
- [x] Allows starting, restarting, and ending game
- [ ] Limit playing area (x, y, and z) (could be done through WorldGuard)
- [ ] Stores location for ppl to watch/wait in or handles putting them in gmsp
- [ ] Team
- [x] Stores members
- [ ] Stores score
@ -28,8 +27,8 @@
- [x] Allows Team member to select class
- [ ] Classes
- [x] Fighter: lower health, higher dmg/throwing speed
- [ ] Tank: Has shield, invincibility effect, slower (short + long cooldown)?
- [ ] Engineer: Better shovel, lower health, lower dmg, (can drop snowballs to team members?) store snow at base, can build?
- [x] Tank: Has shield, invincibility effect, slower (short + long cooldown)?
- [x] Engineer: Better shovel, lower health, lower dmg, (can drop snowballs to team members?) store snow at base, can build?
- [ ] HARD Mage: Drops snowballs in area (casting cost)
- [ ] HARD Scout: low dmg, high speed, (invisible sometimes?) can see flag carrier through walls or maybe see their path in particles?
- [ ] Game events

View File

@ -5,6 +5,7 @@ import com.alttd.ctf.team.TeamPlayer;
import lombok.Getter;
import lombok.extern.slf4j.Slf4j;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import net.kyori.adventure.text.minimessage.tag.resolver.Placeholder;
import org.bukkit.Bukkit;
import org.bukkit.Color;
@ -17,10 +18,12 @@ import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.LeatherArmorMeta;
import org.jetbrains.annotations.NotNull;
import java.util.ArrayList;
import java.util.List;
@Slf4j
public abstract class GameClass {
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
private final List<Material> armor;
private final List<ItemStack> tools;
@ -36,7 +39,8 @@ public abstract class GameClass {
@Getter
private final int damage;
protected GameClass(@NotNull List<Material> armor, @NotNull List<ItemStack> tools, @NotNull ItemStack displayItem, double health, int throwTickSpeed, int damage) {
protected GameClass(@NotNull List<Material> armor, @NotNull List<ItemStack> tools, @NotNull ItemStack displayItem,
double health, int throwTickSpeed, int damage) {
if (armor.size() != 4) {
throw new IllegalArgumentException("Armor has to have 4 entries");
}
@ -51,6 +55,17 @@ public abstract class GameClass {
throw new IllegalArgumentException("Display item has no item meta");
}
this.className = itemMeta.displayName();
List<Component> lore = itemMeta.lore();
if (lore == null) {
throw new IllegalArgumentException("Display item has no lore");
}
ArrayList<Component> loreList = new ArrayList<>(lore);
loreList.add(miniMessage.deserialize("<gold>Health: <health>, Damage: <damage></gold>",
Placeholder.parsed("health", String.valueOf(health)),
Placeholder.parsed("damage", String.valueOf(damage))
));
itemMeta.lore(loreList);
displayItem.setItemMeta(itemMeta);
}
public void apply(TeamPlayer teamPlayer) {

View File

@ -0,0 +1,75 @@
package com.alttd.ctf.game_class.creation;
import com.alttd.ctf.game_class.GameClass;
import com.alttd.ctf.game_class.implementations.Engineer;
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.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.ItemMeta;
import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionType;
import org.jetbrains.annotations.Contract;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Unmodifiable;
import java.util.List;
@Slf4j
public class EngineerCreator {
private static final MiniMessage miniMessage = MiniMessage.miniMessage();
@Contract("_ -> new")
public static @NotNull GameClass createEngineer(@NotNull TeamColor teamColor) {
return new Engineer(getArmor(), getTools(teamColor), getDisplayItem(teamColor),
15, 5, 3);
}
@Contract(value = " -> new", pure = true)
private static @NotNull @Unmodifiable List<Material> getArmor() {
return (List.of(Material.AIR, Material.AIR, Material.LEATHER_CHESTPLATE, Material.AIR));
}
@Contract("_ -> new")
private static @NotNull @Unmodifiable List<ItemStack> getTools(@NotNull TeamColor teamColor) {
return (List.of(getShovel(teamColor), getPotion(teamColor)));
}
private static @NotNull ItemStack getPotion(@NotNull TeamColor teamColor) {
ItemStack healthPot = new ItemStack(Material.POTION);
if (!(healthPot.getItemMeta() instanceof PotionMeta potionMeta)) {
throw new IllegalStateException("No potion meta from a potion");
}
potionMeta.setBasePotionType(PotionType.STRONG_SWIFTNESS);
potionMeta.itemName(miniMessage.deserialize(
String.format("<color:%s>Emergency escape kit</color>", teamColor.hex())));
healthPot.setItemMeta(potionMeta);
healthPot.setAmount(3);
return healthPot;
}
private static @NotNull ItemStack getShovel(@NotNull TeamColor teamColor) {
ItemStack shovel = new ItemStack(Material.IRON_SHOVEL);
ItemMeta meta = shovel.getItemMeta();
meta.itemName(miniMessage.deserialize(String.format("<color:%s>Snow excavator</color>", teamColor.hex())));
meta.addEnchant(Enchantment.EFFICIENCY, 4, false);
shovel.setItemMeta(meta);
return shovel;
}
private static @NotNull ItemStack getDisplayItem(@NotNull TeamColor teamColor) {
ItemStack itemStack = new ItemStack(Material.IRON_SHOVEL);
ItemMeta itemMeta = itemStack.getItemMeta();
itemMeta.displayName(miniMessage.deserialize(String.format("<color:%s>Engineer</color>", teamColor.hex())));
itemMeta.lore(List.of(
miniMessage.deserialize("<gold>The Engineer can mine snow fast</gold>"),
miniMessage.deserialize("<gold>They can use speed potions to escape danger</gold>")
));
itemStack.setItemMeta(itemMeta);
return itemStack;
}
}

View File

@ -24,7 +24,8 @@ public class FighterCreator {
@Contract("_ -> new")
public static @NotNull GameClass createFighter(@NotNull TeamColor teamColor) {
return new Fighter(getArmor(), getTools(teamColor), getDisplayItem(teamColor), 15, 3, 5);
return new Fighter(getArmor(), getTools(teamColor), getDisplayItem(teamColor),
15, 3, 5);
}
@Contract(value = " -> new", pure = true)

View File

@ -2,6 +2,7 @@ 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.game_class.implementations.Tank;
import com.alttd.ctf.team.TeamColor;
import lombok.extern.slf4j.Slf4j;
import net.kyori.adventure.text.minimessage.MiniMessage;
@ -22,7 +23,8 @@ public class TankCreator {
@Contract("_ -> new")
public static @NotNull GameClass createTank(@NotNull 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);
return new Tank(getArmor(), getTools(teamColor), getDisplayItem(teamColor),
30, 7, 4);
}
@Contract(value = " -> new", pure = true)

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 Engineer extends GameClass {
public Engineer(@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,16 +1,19 @@
package com.alttd.ctf.game_class.implementations;
import com.alttd.ctf.game_class.GameClass;
import com.alttd.ctf.team.TeamColor;
import lombok.extern.slf4j.Slf4j;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.jetbrains.annotations.NotNull;
import java.util.List;
@Slf4j
public class Fighter extends GameClass {
public Fighter(List<Material> armor, List<ItemStack> tools, ItemStack displayItem, double health, int tickThrowSpeed, int damage) {
public Fighter(List<Material> armor, List<ItemStack> tools, ItemStack displayItem,
double health, int tickThrowSpeed, int damage) {
super(armor, tools, displayItem, health, tickThrowSpeed, damage);
}

View File

@ -9,7 +9,8 @@ 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) {
public 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);
}
}