Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.21.2 #24

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,7 @@ repositories {
mavenLocal()
mavenCentral()
maven(url = "https://jitpack.io")
}

subprojects {
repositories {
mavenLocal()
mavenCentral()
maven(url = "https://jitpack.io")
}
maven("https://reposilite.worldseed.online/public")
}

dependencies {
Expand Down
3 changes: 3 additions & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ group = "com.bluedragonmc.server"
version = "1.0-SNAPSHOT"

repositories {
mavenLocal()
mavenCentral()
maven(url = "https://jitpack.io")
maven("https://reposilite.worldseed.online/public")
}

dependencies {
implementation(libs.minestom)
implementation(libs.atlas.projectiles)
implementation(libs.kmongo)
implementation(libs.caffeine)
implementation(libs.minimessage)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ import net.minestom.server.entity.Player
import net.minestom.server.entity.metadata.PlayerMeta
import net.minestom.server.instance.Instance
import net.minestom.server.instance.block.Block
import net.minestom.server.network.player.GameProfile
import net.minestom.server.network.player.PlayerConnection
import net.minestom.server.potion.PotionEffect
import net.minestom.server.utils.async.AsyncUtils
import java.util.*
import java.util.concurrent.CompletableFuture

open class CustomPlayer(uuid: UUID, username: String, playerConnection: PlayerConnection) :
Player(uuid, username, playerConnection) {
open class CustomPlayer(playerConnection: PlayerConnection, gameProfile: GameProfile) :
Player(playerConnection, gameProfile) {

internal var isSpectating = false
internal var lastNPCInteractionTime = 0L
Expand Down Expand Up @@ -106,7 +106,7 @@ open class CustomPlayer(uuid: UUID, username: String, playerConnection: PlayerCo

override fun getAdditionalHearts(): Float {
return if (entityMeta !is PlayerMeta) 0f
else super.getAdditionalHearts()
else super.additionalHearts
}

fun isOnLadder() = listOf(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlin.reflect.KMutableProperty

interface DatabaseConnection {

fun loadDataDocument(player: CustomPlayer)
suspend fun loadDataDocument(player: CustomPlayer)

suspend fun getPlayerDocument(username: String): PlayerDocument?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import net.minestom.server.command.builder.suggestion.SuggestionEntry
import net.minestom.server.instance.Instance
import net.minestom.server.instance.block.Block
import net.minestom.server.item.ItemStack
import net.minestom.server.utils.binary.BinaryWriter
import net.minestom.server.network.NetworkBuffer
import net.minestom.server.utils.entity.EntityFinder
import net.minestom.server.utils.location.RelativeVec
import java.util.UUID
Expand Down Expand Up @@ -92,8 +92,8 @@ class ArgumentGameId(id: String) : Argument<Game>(id) {
}

override fun nodeProperties(): ByteArray {
return BinaryWriter.makeArray { packetWriter: BinaryWriter ->
packetWriter.writeVarInt(0) // Single word
return NetworkBuffer.makeArray { packetWriter: NetworkBuffer ->
packetWriter.write(NetworkBuffer.VAR_INT, 0) // Single word
}
}

Expand Down Expand Up @@ -132,8 +132,8 @@ class ArgumentOfflinePlayer(id: String) : Argument<PlayerDocument>(id) {
}

override fun nodeProperties(): ByteArray {
return BinaryWriter.makeArray { packetWriter: BinaryWriter ->
packetWriter.writeVarInt(0) // Single word
return NetworkBuffer.makeArray { packetWriter: NetworkBuffer ->
packetWriter.write(NetworkBuffer.VAR_INT, 0) // Single word
}
}
}
Expand All @@ -159,8 +159,8 @@ class ArgumentOptionalPlayer(id: String) : Argument<String>(id) {
}

override fun nodeProperties(): ByteArray {
return BinaryWriter.makeArray { packetWriter: BinaryWriter ->
packetWriter.writeVarInt(0) // Single word
return NetworkBuffer.makeArray { packetWriter: NetworkBuffer ->
packetWriter.write(NetworkBuffer.VAR_INT, 0) // Single word
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,14 +96,14 @@ class OldCombatModule(var allowDamage: Boolean = true, var allowKnockback: Boole

eventNode.addListener(PlayerSpawnEvent::class.java) { event ->
// Hint to client that there is no attack cooldown
event.player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).baseValue = 100.0
event.player.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).baseValue = 1.0
event.player.getAttribute(Attribute.ATTACK_SPEED).baseValue = 100.0
event.player.getAttribute(Attribute.ATTACK_DAMAGE).baseValue = 1.0
}

eventNode.addListener(PlayerLeaveGameEvent::class.java) { event ->
// Reset attributes to default
event.player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).baseValue = event.player.getAttribute(Attribute.GENERIC_ATTACK_SPEED).attribute.defaultValue()
event.player.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).baseValue = event.player.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE).attribute.defaultValue()
event.player.getAttribute(Attribute.ATTACK_SPEED).baseValue = event.player.getAttribute(Attribute.ATTACK_SPEED).attribute().defaultValue()
event.player.getAttribute(Attribute.ATTACK_DAMAGE).baseValue = event.player.getAttribute(Attribute.ATTACK_DAMAGE).attribute().defaultValue()
event.player.additionalHearts = 0.0f
}

Expand Down Expand Up @@ -154,7 +154,7 @@ class OldCombatModule(var allowDamage: Boolean = true, var allowKnockback: Boole
if (player.gameMode == GameMode.SPECTATOR || (target is Player && (target.gameMode == GameMode.SPECTATOR || target.gameMode == GameMode.CREATIVE))) return@addListener

// The base attack damage according to the item they're holding
var dmgAttribute = player.getAttributeValue(Attribute.GENERIC_ATTACK_DAMAGE)
var dmgAttribute = player.getAttributeValue(Attribute.ATTACK_DAMAGE)

val heldEnchantments = player.inventory.itemInMainHand.get(ItemComponent.ENCHANTMENTS)?.enchantments ?: emptyMap<DynamicRegistry.Key<Enchantment>, Int>()
// Extra damage provided by enchants like sharpness or smite
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.bluedragonmc.server.module.combat

import ca.atlasengine.projectiles.entities.ArrowProjectile
import ca.atlasengine.projectiles.entities.FireballProjectile
import ca.atlasengine.projectiles.entities.ThrownItemProjectile
import com.bluedragonmc.server.Game
import com.bluedragonmc.server.event.ProjectileBreakBlockEvent
import com.bluedragonmc.server.module.GameModule
Expand All @@ -10,7 +13,6 @@ import net.minestom.server.ServerFlag
import net.minestom.server.coordinate.Point
import net.minestom.server.coordinate.Pos
import net.minestom.server.entity.*
import net.minestom.server.entity.Player.Hand
import net.minestom.server.entity.attribute.Attribute
import net.minestom.server.entity.damage.Damage
import net.minestom.server.entity.damage.DamageType
Expand Down Expand Up @@ -40,13 +42,11 @@ import kotlin.math.abs
import kotlin.math.ceil
import kotlin.random.Random


class ProjectileModule : GameModule() {

/**
* A subclass of [PlayerProjectile] that exposes the [shooter] publicly
*/
class Projectile(val shooter: Entity?, type: EntityType?) : PlayerProjectile(shooter, type)
class CustomArrowProjectile(val shooter: Entity?, entityType: EntityType) : ArrowProjectile(entityType, shooter)
class CustomItemProjectile(val shooter: Entity?, entityType: EntityType) : ThrownItemProjectile(entityType, shooter)
class CustomFireballProjectile(val shooter: Entity?, entityType: EntityType) : FireballProjectile(entityType, shooter)

private lateinit var parent: Game

Expand Down Expand Up @@ -95,7 +95,7 @@ class ProjectileModule : GameModule() {
val power = ((secondsCharged * secondsCharged + 2 * secondsCharged) / 2.0).coerceIn(0.0, 1.0)

if (power > 0.2) {
val projectile = Projectile(event.player, EntityType.ARROW)
val projectile = CustomArrowProjectile(event.player, EntityType.ARROW)
if (power > 0.9) (projectile.entityMeta as ArrowMeta).isCritical = true
projectile.scheduleRemove(Duration.ofSeconds(30))
val eyePos = getEyePos(event.player)
Expand All @@ -117,9 +117,7 @@ class ProjectileModule : GameModule() {
}
eventNode.addListener(ProjectileCollideWithEntityEvent::class.java) { event ->
val target = event.target as? LivingEntity ?: return@addListener
val projectile = event.entity as Projectile

if (projectile.entityType != EntityType.ARROW) return@addListener
val projectile = event.entity as? CustomArrowProjectile ?: return@addListener

val arrowMeta = projectile.entityMeta as? ArrowMeta ?: return@addListener
val shooter = projectile.shooter
Expand All @@ -138,7 +136,7 @@ class ProjectileModule : GameModule() {
)

val damageModifier =
(projectile.shooter as? LivingEntity)?.getAttribute(Attribute.GENERIC_ATTACK_DAMAGE)?.value ?: 1.0
(projectile.shooter as? LivingEntity)?.getAttribute(Attribute.ATTACK_DAMAGE)?.value ?: 1.0

var originalDamage = damageModifier * 2.0f + Random.nextFloat() * 0.25 + 0.15f
if (projectile.getTag(ARROW_DAMAGE_TAG) > 0) {
Expand Down Expand Up @@ -186,7 +184,7 @@ class ProjectileModule : GameModule() {
}

// Shoot a snowball from the player's position
val snowball = Projectile(event.player, EntityType.SNOWBALL)
val snowball = CustomItemProjectile(event.player, EntityType.SNOWBALL)
snowball.setInstance(event.instance, getEyePos(event.player))
snowball.shoot(getLaunchPos(event.player), 3.0, 1.0)
event.player.instance?.playSound(
Expand All @@ -202,7 +200,7 @@ class ProjectileModule : GameModule() {
}
eventNode.addListener(ProjectileCollideWithEntityEvent::class.java) { event ->
val target = event.target as? LivingEntity ?: return@addListener
val projectile = event.entity as Projectile
val projectile = event.entity as? CustomItemProjectile ?: return@addListener

if (projectile.entityType != EntityType.SNOWBALL) return@addListener

Expand Down Expand Up @@ -239,7 +237,7 @@ class ProjectileModule : GameModule() {
}
}

private fun shootFireball(player: Player, hand: Hand, instance: Instance) {
private fun shootFireball(player: Player, hand: PlayerHand, instance: Instance) {
val itemStack = player.getItemInHand(hand)
if (itemStack.material() == Material.FIRE_CHARGE) {
if (player.isOnCooldown()) return
Expand All @@ -249,7 +247,7 @@ class ProjectileModule : GameModule() {
}

// Shoot a fireball from the player's position
val fireball = Projectile(player, EntityType.FIREBALL)
val fireball = CustomFireballProjectile(player, EntityType.FIREBALL)
fireball.setInstance(instance, getEyePos(player))
fireball.shoot(getLaunchPos(player), 3.0, 1.0)
player.instance?.playSound(
Expand All @@ -261,7 +259,7 @@ class ProjectileModule : GameModule() {
}

private fun explodeFireball(projectile: Entity) {
projectile as Projectile
projectile as? CustomFireballProjectile ?: return
projectile.remove()
val pos = projectile.position

Expand Down Expand Up @@ -294,7 +292,7 @@ class ProjectileModule : GameModule() {
centerY: Float,
centerZ: Float,
strength: Float,
projectile: Projectile,
projectile: CustomFireballProjectile,
) = object : Explosion(centerX, centerY, centerZ, strength) {

override fun prepare(instance: Instance): List<Point> {
Expand Down Expand Up @@ -338,7 +336,7 @@ class ProjectileModule : GameModule() {
}
eventNode.addListener(ProjectileCollideWithEntityEvent::class.java) { event ->
val target = event.target as? LivingEntity ?: return@addListener
val projectile = event.entity as Projectile
val projectile = event.entity as? CustomItemProjectile ?: return@addListener

if (projectile.entityType != EntityType.EGG) return@addListener

Expand All @@ -356,7 +354,7 @@ class ProjectileModule : GameModule() {
}
}

private fun throwEgg(player: Player, hand: Hand, instance: Instance) {
private fun throwEgg(player: Player, hand: PlayerHand, instance: Instance) {
val itemStack = player.getItemInHand(hand)
if (itemStack.material() == Material.EGG) {
if (player.isOnCooldown()) return
Expand All @@ -366,7 +364,7 @@ class ProjectileModule : GameModule() {
}

// Shoot an egg from the player's position
val egg = Projectile(player, EntityType.EGG)
val egg = CustomItemProjectile(player, EntityType.EGG)
egg.setInstance(instance, getEyePos(player))
egg.shoot(getLaunchPos(player), 3.0, 1.0)
instance.playSound(
Expand All @@ -389,7 +387,7 @@ class ProjectileModule : GameModule() {
val itemStack = event.player.getItemInHand(event.hand)
if (itemStack.material() == Material.ENDER_PEARL) {
if (event.player.isOnCooldown()) return@addListener
val pearl = Projectile(event.player, EntityType.ENDER_PEARL)
val pearl = CustomItemProjectile(event.player, EntityType.ENDER_PEARL)
pearl.setTag(PEARL_OWNER_TAG, event.player.uuid)
pearl.setInstance(event.instance, getEyePos(event.player))
pearl.shoot(getLaunchPos(event.player), 2.5, 1.0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.bluedragonmc.server.Game
import com.bluedragonmc.server.module.GameModule
import net.minestom.server.MinecraftServer
import net.minestom.server.coordinate.Vec
import net.minestom.server.entity.Entity
import net.minestom.server.entity.EntityPose
import net.minestom.server.entity.Player
import net.minestom.server.event.Event
import net.minestom.server.event.EventDispatcher
Expand Down Expand Up @@ -37,7 +37,7 @@ class InstantRespawnModule : GameModule() {

isDead = true
fireTicks = 0
pose = Entity.Pose.STANDING
pose = EntityPose.STANDING
velocity = Vec.ZERO

val respawnEvent = PlayerRespawnEvent(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class MaxHealthModule(private val maxHealth: Double) : GameModule() {

override fun initialize(parent: Game, eventNode: EventNode<Event>) {
eventNode.addListener(PlayerSpawnEvent::class.java) { event ->
event.player.getAttribute(Attribute.GENERIC_MAX_HEALTH).baseValue = maxHealth
event.player.getAttribute(Attribute.MAX_HEALTH).baseValue = maxHealth
}
eventNode.addListener(PlayerLeaveGameEvent::class.java) { event ->
event.player.getAttribute(Attribute.GENERIC_MAX_HEALTH).baseValue = 20.0
event.player.getAttribute(Attribute.MAX_HEALTH).baseValue = 20.0
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,8 @@ class NPCModule : GameModule() {
0,
GameMode.CREATIVE,
Component.text("[NPC] $randomName", NamedTextColor.DARK_GRAY, TextDecoration.ITALIC),
null
null,
0
)
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@ class PlayerResetModule(val defaultGameMode: GameMode? = null) : GameModule() {
player.gameMode = gameMode ?: player.gameMode
player.inventory.clear()
Attribute.values().forEach { attribute ->
player.getAttribute(attribute).modifiers.forEach { modifier ->
player.getAttribute(attribute).modifiers().forEach { modifier ->
player.getAttribute(attribute).removeModifier(modifier)
}
}
player.health = player.getAttribute(Attribute.GENERIC_MAX_HEALTH).value.toFloat()
player.health = player.getAttribute(Attribute.MAX_HEALTH).value.toFloat()
player.food = 20
player.clearEffects()
player.fireTicks = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import net.kyori.adventure.title.Title
import net.kyori.adventure.title.TitlePart
import net.minestom.server.MinecraftServer
import net.minestom.server.entity.Player
import net.minestom.server.entity.PlayerHand
import net.minestom.server.event.Event
import net.minestom.server.event.EventNode
import net.minestom.server.event.player.PlayerSpawnEvent
Expand Down Expand Up @@ -53,7 +54,7 @@ class VoteStartModule(
fill(event.player, voteStartItem)
}
eventNode.addListener(PlayerUseItemEvent::class.java) { event ->
if (event.hand != Player.Hand.MAIN) return@addListener
if (event.hand != PlayerHand.MAIN) return@addListener

when (event.itemStack) {
voteStartItem -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import net.minestom.server.instance.EntityTracker
import net.minestom.server.instance.Instance
import net.minestom.server.instance.block.Block
import net.minestom.server.network.packet.server.play.EffectPacket
import net.minestom.server.utils.PacketUtils
import net.minestom.server.utils.PacketSendingUtils

/**
* Adapted from BasicRedstone by TogAr2 under the MIT License
Expand Down Expand Up @@ -78,7 +78,7 @@ class DoorsModule : GameModule() {
player
)
}
PacketUtils.sendGroupedPacket(
PacketSendingUtils.sendGroupedPacket(
audience, EffectPacket(effect.id, position, 0, false)
) { player -> player != source }
}
Expand Down
Loading
Loading