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

Commit

Permalink
Fix visitors being able to destroy blocks, hanging entities etc.
Browse files Browse the repository at this point in the history
  • Loading branch information
OliwerXi committed Jun 18, 2021
1 parent a1010ac commit f5ba19a
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 11 deletions.
2 changes: 1 addition & 1 deletion SavagePluginX
1 change: 1 addition & 0 deletions src/main/kotlin/net/savagelabs/skyblockx/SkyblockX.kt
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ class SkyblockX : SavagePluginX() {
World.Environment.NORMAL -> Config.instance.skyblockWorldName
World.Environment.NETHER -> Config.instance.skyblockWorldNameNether
World.Environment.THE_END -> Config.instance.skyblockWorldNameEnd
else -> continue
})

shop.location.world = world
Expand Down
12 changes: 9 additions & 3 deletions src/main/kotlin/net/savagelabs/skyblockx/core/IPlayer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,15 @@ fun createIPlayer(player: Player): IPlayer {


fun canUseBlockAtLocation(iPlayer: IPlayer, location: Location): Boolean {
// If the world is not the skyblock world, we will not interfere.
if (location.world!!.name != Config.instance.skyblockWorldName) return true
if (iPlayer.inBypass) return true
// If the world is not the skyblock world or player in bypass
val worldName = location.world!!.name
if (
iPlayer.inBypass || (
worldName != Config.instance.skyblockWorldName
&& worldName != Config.instance.skyblockWorldNameNether
&& worldName != Config.instance.skyblockWorldNameEnd
)
) return true
// if there is a shop, they we allowed to right click
with (getIslandFromLocation(location)) {
if (this == null) return@with
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/net/savagelabs/skyblockx/core/Island.kt
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ data class Island(


fun containsBlock(v: Location): Boolean {
if (v.world !== minLocation.getLocation().world) return false
//if (v.world !== minLocation.getLocation().world) return false
val x = v.x
val y = v.y
val z = v.z
Expand Down
31 changes: 31 additions & 0 deletions src/main/kotlin/net/savagelabs/skyblockx/listener/BlockListener.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,16 @@ import net.savagelabs.skyblockx.persist.Config
import net.savagelabs.skyblockx.persist.Message
import net.savagelabs.skyblockx.persist.Quests
import net.savagelabs.skyblockx.quest.QuestGoal
import org.bukkit.entity.EntityType
import org.bukkit.entity.Player
import org.bukkit.event.Cancellable
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
import org.bukkit.event.block.BlockBreakEvent
import org.bukkit.event.block.BlockPlaceEvent
import org.bukkit.event.hanging.HangingBreakByEntityEvent
import org.bukkit.event.hanging.HangingBreakEvent
import org.bukkit.metadata.FixedMetadataValue

object BlockListener : Listener {
Expand Down Expand Up @@ -150,6 +154,33 @@ object BlockListener : Listener {
}
}

@EventHandler
private fun HangingBreakByEntityEvent.onHangingBreak() {
if (this.remover?.type != EntityType.PLAYER) {
return
}

val player = this.remover as Player
val iPlayer = player.getIPlayer()

if (this.isCancelled || isNotInSkyblockWorld(this.entity.world)) {
return
}

// Check if they have an island or co-op island, if not, deny.
if (!iPlayer.hasCoopIsland() && !iPlayer.hasIsland() && !iPlayer.inBypass) {
iPlayer.message(Message.instance.listenerActionDeniedCreateAnIslandFirst)
this.isCancelled = true
return
}

// Check if they can use the block on the island, or co-op island.
if (!canUseBlockAtLocation(iPlayer, this.entity.location)) {
iPlayer.message(Message.instance.listenerBlockPlacementDenied)
this.isCancelled = true
}
}

internal fun workPlacement(material: XMaterial, island: Island?, islandPlayer: IPlayer, event: Cancellable) {
// Necessity.
val placementLimit = Config.instance.blockPlacementLimit.getOrDefault(material, -1)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
package net.savagelabs.skyblockx.listener

import net.savagelabs.skyblockx.SkyblockX
import net.savagelabs.skyblockx.core.color
import net.savagelabs.skyblockx.core.getIPlayer
import net.savagelabs.skyblockx.core.isNotInSkyblockWorld
import net.savagelabs.skyblockx.core.teleportAsync
import net.savagelabs.skyblockx.core.*
import net.savagelabs.skyblockx.persist.Config
import net.savagelabs.skyblockx.persist.Message
import net.savagelabs.skyblockx.persist.Quests
Expand Down Expand Up @@ -61,9 +58,34 @@ object EntityListener : Listener {

@EventHandler
fun onPlayerTakingDamage(event: EntityDamageByEntityEvent) {
// If they're not a player or if the entity is not in the skyblock world, we do not care.
if (event.isCancelled || isNotInSkyblockWorld(event.entity.world)) {
return
}

val type = event.entityType
if (type != EntityType.PLAYER || event.damager.type == EntityType.PLAYER || isNotInSkyblockWorld(event.entity.world)) {
val damager = event.damager
val isDamagerPlayer = damager.type == EntityType.PLAYER

if (type == EntityType.ARMOR_STAND && isDamagerPlayer) {
val iPlayer = (damager as Player).getIPlayer()

// Check if they have an island or co-op island, if not, deny.
if (!iPlayer.hasCoopIsland() && !iPlayer.hasIsland() && !iPlayer.inBypass) {
iPlayer.message(Message.instance.listenerActionDeniedCreateAnIslandFirst)
event.isCancelled = true
return
}

// Check if they can use the block on the island, or co-op island.
if (!canUseBlockAtLocation(iPlayer, event.entity.location)) {
iPlayer.message(Message.instance.listenerBlockPlacementDenied)
event.isCancelled = true
return
}
}

// If they're not a player or if the entity is not in the skyblock world, we do not care.
if (type != EntityType.PLAYER || isDamagerPlayer) {
return
}

Expand Down

0 comments on commit f5ba19a

Please sign in to comment.