diff --git a/TODO.md b/TODO.md index d56494e..407fcfe 100644 --- a/TODO.md +++ b/TODO.md @@ -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 diff --git a/src/main/java/com/alttd/ctf/game_class/GameClass.java b/src/main/java/com/alttd/ctf/game_class/GameClass.java index d405129..0146c28 100644 --- a/src/main/java/com/alttd/ctf/game_class/GameClass.java +++ b/src/main/java/com/alttd/ctf/game_class/GameClass.java @@ -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 armor; private final List tools; @@ -36,7 +39,8 @@ public abstract class GameClass { @Getter private final int damage; - protected GameClass(@NotNull List armor, @NotNull List tools, @NotNull ItemStack displayItem, double health, int throwTickSpeed, int damage) { + protected GameClass(@NotNull List armor, @NotNull List 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 lore = itemMeta.lore(); + if (lore == null) { + throw new IllegalArgumentException("Display item has no lore"); + } + ArrayList loreList = new ArrayList<>(lore); + loreList.add(miniMessage.deserialize("Health: , Damage: ", + Placeholder.parsed("health", String.valueOf(health)), + Placeholder.parsed("damage", String.valueOf(damage)) + )); + itemMeta.lore(loreList); + displayItem.setItemMeta(itemMeta); } public void apply(TeamPlayer teamPlayer) { diff --git a/src/main/java/com/alttd/ctf/game_class/creation/EngineerCreator.java b/src/main/java/com/alttd/ctf/game_class/creation/EngineerCreator.java new file mode 100644 index 0000000..0aa94d5 --- /dev/null +++ b/src/main/java/com/alttd/ctf/game_class/creation/EngineerCreator.java @@ -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 getArmor() { + return (List.of(Material.AIR, Material.AIR, Material.LEATHER_CHESTPLATE, Material.AIR)); + } + + @Contract("_ -> new") + private static @NotNull @Unmodifiable List 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("Emergency escape kit", 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("Snow excavator", 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("Engineer", teamColor.hex()))); + itemMeta.lore(List.of( + miniMessage.deserialize("The Engineer can mine snow fast"), + miniMessage.deserialize("They can use speed potions to escape danger") + )); + itemStack.setItemMeta(itemMeta); + return itemStack; + } +} diff --git a/src/main/java/com/alttd/ctf/game_class/creation/FighterCreator.java b/src/main/java/com/alttd/ctf/game_class/creation/FighterCreator.java index 7173110..a13f1e5 100644 --- a/src/main/java/com/alttd/ctf/game_class/creation/FighterCreator.java +++ b/src/main/java/com/alttd/ctf/game_class/creation/FighterCreator.java @@ -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) diff --git a/src/main/java/com/alttd/ctf/game_class/creation/TankCreator.java b/src/main/java/com/alttd/ctf/game_class/creation/TankCreator.java index d2b7d89..cb13c01 100644 --- a/src/main/java/com/alttd/ctf/game_class/creation/TankCreator.java +++ b/src/main/java/com/alttd/ctf/game_class/creation/TankCreator.java @@ -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) diff --git a/src/main/java/com/alttd/ctf/game_class/implementations/Engineer.java b/src/main/java/com/alttd/ctf/game_class/implementations/Engineer.java new file mode 100644 index 0000000..934018c --- /dev/null +++ b/src/main/java/com/alttd/ctf/game_class/implementations/Engineer.java @@ -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 armor, @NotNull List tools, @NotNull ItemStack displayItem, + double health, int throwTickSpeed, int damage) { + super(armor, tools, displayItem, health, throwTickSpeed, damage); + } +} diff --git a/src/main/java/com/alttd/ctf/game_class/implementations/Fighter.java b/src/main/java/com/alttd/ctf/game_class/implementations/Fighter.java index c7262a0..2ecf3ec 100644 --- a/src/main/java/com/alttd/ctf/game_class/implementations/Fighter.java +++ b/src/main/java/com/alttd/ctf/game_class/implementations/Fighter.java @@ -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 armor, List tools, ItemStack displayItem, double health, int tickThrowSpeed, int damage) { + public Fighter(List armor, List tools, ItemStack displayItem, + double health, int tickThrowSpeed, int damage) { super(armor, tools, displayItem, health, tickThrowSpeed, damage); } diff --git a/src/main/java/com/alttd/ctf/game_class/implementations/Tank.java b/src/main/java/com/alttd/ctf/game_class/implementations/Tank.java index 979d826..1438191 100644 --- a/src/main/java/com/alttd/ctf/game_class/implementations/Tank.java +++ b/src/main/java/com/alttd/ctf/game_class/implementations/Tank.java @@ -9,7 +9,8 @@ import java.util.List; public class Tank extends GameClass { - protected Tank(@NotNull List armor, @NotNull List tools, @NotNull ItemStack displayItem, double health, int throwTickSpeed, int damage) { + public Tank(@NotNull List armor, @NotNull List tools, @NotNull ItemStack displayItem, + double health, int throwTickSpeed, int damage) { super(armor, tools, displayItem, health, throwTickSpeed, damage); } }