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

Commit

Permalink
Bump to 18, fix region collision
Browse files Browse the repository at this point in the history
  • Loading branch information
LeoDog896 committed Dec 20, 2021
1 parent 982ad4f commit 64a7d56
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
8 changes: 4 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

plugins {
// Apply the Kotlin JVM plugin to add support for Kotlin.
kotlin("jvm") version "1.5.31"
kotlin("jvm") version "1.6.0"
id("com.github.johnrengelman.shadow") version "7.1.0"
id("org.jetbrains.dokka") version "1.5.31"
kotlin("plugin.serialization") version "1.4.21"
Expand Down Expand Up @@ -73,11 +73,11 @@ tasks {
}

java {
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

tasks.withType<KotlinCompile> { kotlinOptions.jvmTarget = "16" }
tasks.withType<KotlinCompile> { kotlinOptions.jvmTarget = "17" }
val compileKotlin: KotlinCompile by tasks

compileKotlin.kotlinOptions {
Expand Down
7 changes: 5 additions & 2 deletions src/main/kotlin/world/cepi/region/api/Region.kt
Original file line number Diff line number Diff line change
Expand Up @@ -191,8 +191,11 @@ data class Region(
}
}

val Player.region: Region?
get() = this.getTag(regionTag)?.let { RegionProvider[it] }
var Player.region: Region?
get() = getTag(regionTag)?.let { RegionProvider[it] }
set(value) {
value?.name?.let { setTag(regionTag, it) } ?: removeTag(regionTag)
}

fun Player.refreshRegionBossBar() {
if (region == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@ object PlayerRegionHandler {
val newRegion = RegionProvider.regions.values
.filter { it.instance.uniqueId == player.instance?.uniqueId }
.filter { it.contains(newPosition) }
.maxByOrNull(Region::volume)
.minByOrNull(Region::volume)

if (oldRegion == newRegion)
return@with

val regionEvent = PlayerRegionUpdateEvent(player, oldRegion, newRegion, player.position)
Manager.globalEvent.call(regionEvent)

if (!regionEvent.isCancelled) {
player.region = newRegion
}

event.isCancelled = regionEvent.isCancelled
}
}

0 comments on commit 64a7d56

Please sign in to comment.