Skip to content

Commit

Permalink
Merge pull request #82 from MineInAbyss/quick_fix
Browse files Browse the repository at this point in the history
Disabling epearls on top and bottom of section
  • Loading branch information
Boy0000 authored Aug 17, 2021
2 parents bedd89b + b50c918 commit f1bb9a8
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -93,59 +93,55 @@ object MovementListener : Listener {

fun tpIfAbleTo(
key: SectionKey,
tpFun: (Player, Location, Section, Section) -> Unit,
boundaryCheck: (y: Double, shared: Int) -> Boolean,
tpFun: (Player, Location, Section, Section) -> Unit
) {
val toSection = key.section ?: return
val overlap = current.overlapWith(toSection) ?: return
val correspondingPos = to.getCorrespondingLocation(current, toSection) ?: return

if (boundaryCheck(to.y, overlap)) {
if (!toSection.region.contains(correspondingPos.blockX, correspondingPos.blockZ)
|| !inSpectator && correspondingPos.block.type.isSolid
) {
if(current.isOnTopOf(toSection)){
from.block.type = Material.BEDROCK
val spawnedBedrock = from.block
temporaryBedrock.add(spawnedBedrock)

// Keep bedrock spawned if there are players within a 1.5 radius (regular jump height).
// If no players are in this radius, destroy the bedrock.
deeperWorld.schedule{
this.repeating(1)
while(spawnedBedrock.location.up(1).getNearbyPlayers(1.5).isNotEmpty()){
yield()
}
spawnedBedrock.type = Material.AIR
temporaryBedrock.remove(spawnedBedrock)
if (!to.inSectionTransition) return
if (!toSection.region.contains(correspondingPos.blockX, correspondingPos.blockZ)
|| !inSpectator && correspondingPos.block.type.isSolid
) {
if (current.isOnTopOf(toSection)) {
from.block.type = Material.BEDROCK
val spawnedBedrock = from.block
temporaryBedrock.add(spawnedBedrock)

// Keep bedrock spawned if there are players within a 1.5 radius (regular jump height).
// If no players are in this radius, destroy the bedrock.
deeperWorld.schedule {
this.repeating(1)
while (spawnedBedrock.location.up(1).getNearbyPlayers(1.5).isNotEmpty()) {
yield()
}
spawnedBedrock.type = Material.AIR
temporaryBedrock.remove(spawnedBedrock)
}

val oldFallDistance = player.fallDistance
val oldVelocity = player.velocity
val oldFallDistance = player.fallDistance
val oldVelocity = player.velocity

player.teleport(from.up(1))
player.teleport(from.up(1))

player.fallDistance = oldFallDistance
player.velocity = oldVelocity
}else{
player.teleport(from)
}
player.sendMessage("&cThere is no where for you to teleport".color())
player.fallDistance = oldFallDistance
player.velocity = oldVelocity
} else {
player.teleport(from)
}
else
tpFun(player, to, current, toSection)
}
player.sendMessage("&cThere is no where for you to teleport".color())
} else
tpFun(player, to, current, toSection)
}

when {
changeY > 0.0 -> tpIfAbleTo(
current.aboveKey,
MovementListener::ascend,
) { y, shared -> y > player.world.maxHeight - .3 * shared }
)
changeY < 0.0 -> tpIfAbleTo(
current.belowKey,
MovementListener::descend,
) { y, shared -> y < player.world.minHeight + .3 * shared }
)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
package com.derongan.minecraft.deeperworld.listeners

import com.derongan.minecraft.deeperworld.services.canMoveSections
import com.derongan.minecraft.deeperworld.world.section.inSectionTransition
import com.derongan.minecraft.deeperworld.world.section.section
import com.mineinabyss.idofront.destructure.component1
import com.mineinabyss.idofront.destructure.component2
import com.mineinabyss.idofront.destructure.component3
import com.mineinabyss.idofront.messaging.error
import org.bukkit.GameMode.ADVENTURE
import org.bukkit.GameMode.SURVIVAL
import org.bukkit.GameMode.CREATIVE
import org.bukkit.event.EventHandler
import org.bukkit.event.Listener
import org.bukkit.event.player.PlayerTeleportEvent
Expand All @@ -16,19 +13,21 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause.ENDER_PEARL

object PlayerListener : Listener {
@EventHandler
fun onPlayerTeleport(event: PlayerTeleportEvent) {
val (player, _, to, cause) = event
fun PlayerTeleportEvent.onPlayerTeleport() {
if (player.gameMode == CREATIVE) return
if (cause != ENDER_PEARL && cause != CHORUS_FRUIT) return
if (!player.canMoveSections) return

if (
(player.gameMode == SURVIVAL || player.gameMode == ADVENTURE)
&& (cause == ENDER_PEARL || cause == CHORUS_FRUIT)
&& (to.section != player.location.section || to.section == null)
&& player.canMoveSections
to.section == null ||
to.section != player.location.section ||
to.inSectionTransition
) {
player.error("Teleportation is disabled between Layers and Sections.")
event.isCancelled = true
isCancelled = true
}
}
}

//TODO move into idofront
private operator fun PlayerTeleportEvent.component4() = cause
private operator fun PlayerTeleportEvent.component4() = cause
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ import org.bukkit.block.data.Waterlogged
import org.bukkit.block.data.type.Bed
import org.bukkit.block.data.type.Stairs
import org.bukkit.block.data.type.TrapDoor
import org.bukkit.entity.EntityType
import org.bukkit.event.EventHandler
import org.bukkit.event.EventPriority
import org.bukkit.event.Listener
import org.bukkit.event.block.*
import org.bukkit.event.entity.EntityExplodeEvent
import org.bukkit.event.entity.EntitySpawnEvent
import org.bukkit.event.player.PlayerBucketEmptyEvent
import org.bukkit.event.player.PlayerBucketFillEvent

Expand Down Expand Up @@ -174,4 +176,16 @@ object SectionSyncListener : Listener {
fun SignChangeEvent.syncSignText() {
block.sync(signUpdater(lines))
}

/** Disables Iron Golem and Wither summons in section transitions due to duping **/
@EventHandler
fun EntitySpawnEvent.onEntitySummon() {
if (entity.location.inSectionOverlap &&
(entityType == EntityType.WITHER || entityType == EntityType.IRON_GOLEM)) {
isCancelled = true
entity.location.getNearbyPlayers(5.0).forEach {
it.error("Spawning of $entityType is disabled in section overlaps.")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,13 @@ val Location.inSectionOverlap: Boolean
return sharedBetween(section ?: return false, correspondingSection ?: return false)
}

val Location.inSectionTransition: Boolean
get() {
// Get overlap of this section and corresponding section
val shared = section?.overlapWith(correspondingSection ?: return false) ?: return false
return blockY >= world.maxHeight - .3 * shared || blockY <= world.minHeight + .3 * shared
}

fun Location.sharedBetween(section: Section, otherSection: Section): Boolean {
val overlap = section.overlapWith(otherSection) ?: return false
return when {
Expand Down

0 comments on commit f1bb9a8

Please sign in to comment.