Skip to content

Commit

Permalink
Add more cases EventPreventionPatch
Browse files Browse the repository at this point in the history
  • Loading branch information
NichtStudioCode committed Sep 16, 2024
1 parent 9bc686a commit 2f78283
Showing 1 changed file with 45 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
package xyz.xenondevs.nova.patch.impl.misc

import com.destroystokyo.paper.event.entity.EntityKnockbackByEntityEvent
import io.papermc.paper.event.entity.EntityPushedByEntityAttackEvent
import io.papermc.paper.plugin.manager.PaperPluginManagerImpl
import org.bukkit.event.Event
import org.bukkit.event.entity.EntityCombustByEntityEvent
import org.bukkit.event.entity.EntityDamageByEntityEvent
import org.bukkit.event.entity.EntityEvent
import org.bukkit.event.hanging.HangingBreakByEntityEvent
import org.bukkit.event.player.PlayerEvent
import org.objectweb.asm.tree.LabelNode
import xyz.xenondevs.bytebase.asm.buildInsnList
import xyz.xenondevs.nova.patch.MethodTransformer
import xyz.xenondevs.nova.util.FakePlayer
import xyz.xenondevs.nova.util.nmsEntity
import xyz.xenondevs.nova.util.serverPlayer

/**
Expand All @@ -31,13 +38,49 @@ internal object EventPreventionPatch : MethodTransformer(PaperPluginManagerImpl:
})
}

@Suppress("UNNECESSARY_SAFE_CALL") // some plugins might set the player to null
@Suppress("UNNECESSARY_SAFE_CALL", "removal", "DEPRECATION") // some plugins might set the player to null
@JvmStatic
fun shouldPreventEvent(event: Event): Boolean {
// prevent all events of fake players
if (event is PlayerEvent) {
val player = event.player?.serverPlayer
return player is FakePlayer && !player.hasEvents
if (player is FakePlayer && !player.hasEvents)
return false
}
if (event is EntityEvent) {
val entity = event.entity?.nmsEntity
if (entity is FakePlayer && !entity.hasEvents)
return false
}
if (event is EntityDamageByEntityEvent) {
val damager = event.damager?.nmsEntity
if (damager is FakePlayer && !damager.hasEvents)
return false
}
if (event is EntityKnockbackByEntityEvent) {
val pushedBy = event.pushedBy?.nmsEntity
if (pushedBy is FakePlayer && !pushedBy.hasEvents)
return false
}
if (event is org.bukkit.event.entity.EntityKnockbackByEntityEvent) {
val source = event.sourceEntity?.nmsEntity
if (source is FakePlayer && !source.hasEvents)
return false
}
if (event is EntityCombustByEntityEvent) {
val combuster = event.combuster?.nmsEntity
if (combuster is FakePlayer && !combuster.hasEvents)
return false
}
if (event is EntityPushedByEntityAttackEvent) {
val pushedBy = event.pushedBy?.nmsEntity
if (pushedBy is FakePlayer && !pushedBy.hasEvents)
return false
}
if (event is HangingBreakByEntityEvent) {
val remover = event.remover?.nmsEntity
if (remover is FakePlayer && !remover.hasEvents)
return false
}

// only sync events are dropped in event prevention scope
Expand Down

0 comments on commit 2f78283

Please sign in to comment.