Skip to content
This repository has been archived by the owner on Jun 1, 2024. It is now read-only.

Commit

Permalink
Update to v1.1.0 (#63)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gregory authored Jan 3, 2024
2 parents 129b46c + e025ce5 commit 3ab3a50
Show file tree
Hide file tree
Showing 103 changed files with 1,860 additions and 330 deletions.
26 changes: 26 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,32 @@ jobs:
- name: Build with Gradle
run: ./gradlew clean assemble publishToMavenLocal

upload:
runs-on: ubuntu-latest
needs: build
timeout-minutes: 30

name: Create Artifacts
steps:
- uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
cache: 'gradle'
- name: Change Permissions
run: chmod +x ./gradlew
- name: Build with Gradle
run: ./gradlew clean assemble
- name: Upload Artifacts
uses: actions/upload-artifact@v4
with:
name: battlecards
path: |
plugin/build/libs/*.jar
api/build/libs/*.jar
analyze:
runs-on: ubuntu-latest
needs: build
Expand Down
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,19 @@ This plugin is built in Kotlin. While the plugin will automatically download the

## 📓Changelog

📖 **v1.1.0** - January 2, 2024 | Generation II
- 3 new Generation II Cards
- New Card Equipment
- Turkish Translation
- **Card & Equipment Catalogue**
- View useful information & crafting recipes about all cards & card equipment
- Release of the [official guide](https://guide.battlecards.gamercoder215.me)
- Equipment Drops from Normal Entities
- Piglin Bartering for Equipment & Card Shards (1.16+)
- Decrease BASIC and COMMON Max Experience Requirements
- Minor Bug Fixes
- Added Missing Translations

🛠️ v1.0.2 - December 2, 2023
- Dependency Updates
- 10+ New Card Equipments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ enum class CardAttribute(
MAX_HEALTH(25_000_000.0),
ATTACK_DAMAGE(3_500_000.0),
DEFENSE(2_000_000.0),
SPEED(0.45),
SPEED(1.05),
KNOCKBACK_RESISTANCE,
FOLLOW_RANGE(1024.0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ class ICard(

override fun spawnCard(owner: Player): IBattleCard<*> = spawnCard(owner, itemStack)

override val isRideable: Boolean
get() = entityCardClass.isAnnotationPresent(Rideable::class.java)

fun spawnCard(owner: Player, itemUsed: ItemStack): IBattleCard<*> {
if (owner.spawnedCards.size >= BattleConfig.config.maxCardsSpawned) throw IllegalStateException("Player already has ${BattleConfig.config.maxCardsSpawned} spawned cards")

Expand Down Expand Up @@ -131,8 +134,9 @@ class ICard(

private const val serialVersionUID: Long = 193409138419023815L

@JvmStatic
fun fromByteArray(array: ByteArray): ICard {
fun fromByteArray(array: ByteArray): ICard? {
if (array.isEmpty()) return null

val bIs = ByteArrayInputStream(array)
val iS = BukkitObjectInputStream(BufferedInputStream(bIs))
val card = iS.readObject() as ICard
Expand All @@ -141,7 +145,6 @@ class ICard(
return card
}

@JvmStatic
fun deserialize(map: Map<String, Any>): ICard {
val clazz = Class.forName(map["clazz"] as String).asSubclass(BattleCard::class.java)
val type = BattleCardType.valueOf((map["type"] as String).uppercase())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import me.gamercoder215.battlecards.api.BattleConfig
import me.gamercoder215.battlecards.api.card.BattleCard
import me.gamercoder215.battlecards.api.card.item.CardEquipment.Potion
import me.gamercoder215.battlecards.api.events.entity.CardUseAbilityEvent
import me.gamercoder215.battlecards.impl.*
import me.gamercoder215.battlecards.impl.IBattleStatistics
import me.gamercoder215.battlecards.impl.ICard
import me.gamercoder215.battlecards.impl.Passive
import me.gamercoder215.battlecards.impl.UnlockedAt
import me.gamercoder215.battlecards.util.*
import me.gamercoder215.battlecards.wrapper.Wrapper.Companion.w
import me.gamercoder215.battlecards.wrapper.commands.CommandWrapper.Companion.getError
Expand All @@ -28,13 +31,10 @@ abstract class IBattleCard<T : Creature>(
) : BattleCard<T> {

companion object {
@JvmStatic
val spawned: MutableMap<UUID, IBattleCard<*>> = mutableMapOf()

@JvmStatic
fun byEntity(entity: Creature): IBattleCard<*>? = spawned[entity.uniqueId]

@JvmStatic
fun byMinion(minion: LivingEntity): IBattleCard<*>? {
spawned.forEach { (_, card) ->
if (card.minions.any { it.uniqueId == minion.uniqueId })
Expand Down Expand Up @@ -276,7 +276,10 @@ abstract class IBattleCard<T : Creature>(
get() = data.statistics

final override val isRideable: Boolean
get() = this::class.java.isAnnotationPresent(Rideable::class.java)
get() = this.data.isRideable

final override val owner: Player
get() = p

// Utilities

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class IBattleCardListener(plugin: Plugin) : org.bukkit.event.Listener {
init {
Bukkit.getPluginManager().registerEvents(this, plugin)

val reg = RegisteredListener(this, { _, e -> onEvent(e) }, EventPriority.NORMAL, plugin, false)
val reg = RegisteredListener(this, { _, e -> onEvent(e) }, EventPriority.HIGHEST, plugin, false)
HandlerList.getHandlerLists().forEach { it.register(reg) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ class IWitherKing(data: ICard) : IBattleCard<Wither>(data) {
}

private companion object {
@JvmStatic
private val types: List<EntityType> = listOf<Any>(
EntityType.BLAZE,
EntityType.SKELETON,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import org.bukkit.potion.PotionEffectType

@Type(BattleCardType.WITHERMAN)
@Attributes(650.0, 16.5, 25.5, 0.25, 0.15)
@AttributesModifier(CardAttribute.MAX_HEALTH, CardOperation.ADD, 8.0)
@AttributesModifier(CardAttribute.MAX_HEALTH, CardOperation.ADD, 7.6)
@AttributesModifier(CardAttribute.ATTACK_DAMAGE, CardOperation.ADD, 5.75)
@AttributesModifier(CardAttribute.DEFENSE, CardOperation.ADD, 4.5)
@AttributesModifier(CardAttribute.SPEED, CardOperation.MULTIPLY, 1.01)
@AttributesModifier(CardAttribute.SPEED, CardOperation.MULTIPLY, 1.015)
class IWitherman(data: ICard) : IBattleCard<Enderman>(data) {

@CardAbility("card.witherman.ability.wither", ChatColor.DARK_GRAY)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,10 @@ import kotlin.math.pow

object CardUtils {

@JvmStatic
val BLOCK_DATA: MutableMap<Location, BattleBlockData> = mutableMapOf()

// Entity Utils

@JvmStatic
fun createAttachments(card: IBattleCard<*>) {
val attachments = card.javaClass.getAnnotationsByType(BlockAttachment::class.java)
if (attachments.isEmpty()) return
Expand Down Expand Up @@ -73,7 +71,6 @@ object CardUtils {
}
}

@JvmStatic
fun createMinionAttachments(minion: LivingEntity, card: IBattleCard<*>) {
val attachments = card.javaClass.getAnnotationsByType(MinionBlockAttachment::class.java).filter { it.type == minion.type }
if (attachments.isEmpty()) return
Expand Down Expand Up @@ -124,12 +121,10 @@ object CardUtils {

// String Utils / Extensions

@JvmStatic
fun format(string: String, vararg args: Any): String {
return String.format(BattleConfig.config.locale, string, *args)
}

@JvmStatic
fun color(s: String): String {
val array = s.trim().split("\\s".toRegex()).toTypedArray()

Expand Down Expand Up @@ -159,7 +154,6 @@ object CardUtils {
return list.joinToString(" ")
}

@JvmStatic
fun dateFormat(date: Date?, time: Boolean = false): String? {
if (date == null || date.time == 0L) return null

Expand All @@ -169,7 +163,6 @@ object CardUtils {

// Other

@JvmStatic
fun local(reference: Location, local: Vector): Location {
val base = Vector(0, 0, 1)
val left: Vector = base.clone().rotateAroundY(Math.toRadians(-reference.yaw + 90.0))
Expand All @@ -185,7 +178,6 @@ object CardUtils {
return loc
}

@JvmStatic
fun createLine(card: Card): String {
val builder = StringBuilder()

Expand All @@ -205,11 +197,10 @@ object CardUtils {
val Card.power: Long
get() = (level.toDouble().pow(rarity.experienceModifier) * rarity.ordinal.plus(1)).toLong()

@JvmStatic
fun getCardPower(cards: Iterable<ItemStack>)
= cards.map { it to it.card!! }.sumOf { it.second.power * it.first.amount }
= cards.filter { it.isCard }.map { it to it.card!! }.sumOf { it.second.power * it.first.amount } +
cards.filter { it.id == "card_shard" }.sumOf { 3.0.pow(Rarity.valueOf(it.nbt.getString("rarity")).ordinal) * it.amount }

@JvmStatic
private val intervalCardChances = listOf(
250,
1250,
Expand All @@ -218,7 +209,6 @@ object CardUtils {
31475
)

@JvmStatic
fun calculateCardChances(cards: Iterable<ItemStack>): Map<Rarity, Double> {
val power = getCardPower(cards)
if (power < 50) return emptyMap()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ enum class BattleMaterial(
{ ItemStack(Material.matchMaterial("red_wool")) }
),

STONE_BRICKS(
{ ItemStack(Material.matchMaterial("smooth_brick")) },
{ ItemStack(Material.matchMaterial("stone_bricks")) }
),

SPIDER_SPAWN_EGG(
{ ItemStack(Material.matchMaterial("monster_egg"), 1, 52) },
{ ItemStack(Material.matchMaterial("spider_spawn_egg")) }
),

;

fun findStack(): ItemStack = if (Wrapper.legacy) onLegacy() else onModern()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package me.gamercoder215.battlecards.util

import me.gamercoder215.battlecards.api.BattleConfig
import me.gamercoder215.battlecards.api.card.BattleCardType
import me.gamercoder215.battlecards.api.card.item.CardEquipment
import me.gamercoder215.battlecards.impl.*
import me.gamercoder215.battlecards.impl.cards.IBattleCard
Expand Down Expand Up @@ -234,6 +235,9 @@ inline val Player.attackable: Boolean
inline val Player.gameName: String
get() = displayName ?: name

inline val BattleCardType.isDisabled: Boolean
get() = BattleConfig.config.disabledCards.contains(this)

fun Event.call() {
Bukkit.getPluginManager().callEvent(this)
}
Expand Down Expand Up @@ -279,6 +283,9 @@ inline val Chunk.blocks: Set<Block>
return blocks
}

inline val Material?.airOrNull: Boolean
get() = this == null || this == Material.AIR

val PotionEffectType.prefix: String
get() = when (this.name.lowercase()) {
"absorption", "fire_resistance" -> ChatColor.GOLD
Expand All @@ -292,7 +299,7 @@ val PotionEffectType.prefix: String
"dolphins_grace" -> "a5d1d3"
"harm", "increase_damage" -> ChatColor.DARK_RED
"hunger" -> "8b4513"
"levitation", "slow_digging" -> ChatColor.WHITE
"levitation", "slow_digging", "slow_falling" -> ChatColor.WHITE
"luck", "poison" -> ChatColor.DARK_GREEN
"night_vision" -> ChatColor.DARK_BLUE
"speed", "water_breathing" -> ChatColor.AQUA
Expand Down Expand Up @@ -533,4 +540,10 @@ fun String.replace(replacements: Map<String, String>): String =
fun String.capitalizeFully(): String =
split(" ").joinToString(" ") {
s -> s.lowercase(BattleConfig.config.locale).replaceFirstChar { it.uppercase(BattleConfig.config.locale) }
}
}

infix fun <T> Iterable<T>.except(other: Iterable<T>): List<T> =
filter { !other.contains(it) }

infix fun <T> Iterable<T>.except(other: T): List<T> =
filter { it != other }
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import org.bukkit.util.ChatPaginator

object CardGenerator {

@JvmStatic
fun toItem(card: Card): ItemStack {
val config = BattleConfig.configuration

Expand Down Expand Up @@ -49,25 +48,24 @@ object CardGenerator {
}.nbt { nbt -> nbt["card"] = card.toByteArray() }
}

@JvmStatic
fun createBasicCard(entity: Creature): ItemStack {
if (!BattleConfig.getValidBasicCards().contains(entity.type)) throw IllegalArgumentException("Invalid Entity Type: ${entity.type}")
val card = BattleCardType.BASIC.createCardData() as ICard
val card = BattleCardType.BASIC() as ICard
card.storedEntityType = entity.type
return toItem(card)
}

private val generationColors = listOf(
ChatColor.GREEN,
internal val generationColors = arrayOf(
ChatColor.RESET, // Generation 0
ChatColor.AQUA,
ChatColor.GREEN,
ChatColor.DARK_BLUE,
ChatColor.YELLOW,
ChatColor.DARK_PURPLE,
ChatColor.GOLD,
ChatColor.LIGHT_PURPLE
)

@JvmStatic
fun generateCardInfo(card: Card): ItemStack {
val config = BattleConfig.configuration

Expand Down Expand Up @@ -159,7 +157,6 @@ object CardGenerator {
}
}

@JvmStatic
fun generateCardStatistics(card: Card): ItemStack? {
if (!BattleConfig.configuration.getBoolean("Cards.Display.Info.ShowStatistics")) return null

Expand Down
Loading

0 comments on commit 3ab3a50

Please sign in to comment.