Skip to content

Commit a0c4686

Browse files
committed
Respawning at home after death added.
Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
1 parent 05d0830 commit a0c4686

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

src/main/kotlin/com/mairwunnx/projectessentials/home/GlobalScope.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.mairwunnx.projectessentials.home
22

3-
import com.mairwunnx.projectessentials.core.api.v1.commands.back.BackLocationAPI
43
import com.mairwunnx.projectessentials.core.api.v1.configuration.ConfigurationAPI
54
import com.mairwunnx.projectessentials.core.api.v1.extensions.playSound
65
import com.mairwunnx.projectessentials.home.configurations.HomeConfiguration
@@ -24,7 +23,6 @@ val homeSettingsConfiguration by lazy {
2423
}
2524

2625
fun teleportToHome(player: ServerPlayerEntity, home: HomeConfigurationModel.User.Home) {
27-
BackLocationAPI.commit(player)
2826
val world = player.server.getWorld(
2927
DimensionType.getById(home.dimensionId) ?: DimensionType.OVERWORLD
3028
)

src/main/kotlin/com/mairwunnx/projectessentials/home/ModuleObject.kt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,12 @@ import com.mairwunnx.projectessentials.home.commands.HomeCommand
1313
import com.mairwunnx.projectessentials.home.commands.SetHomeCommand
1414
import com.mairwunnx.projectessentials.home.configurations.HomeConfiguration
1515
import com.mairwunnx.projectessentials.home.configurations.HomeSettingsConfiguration
16+
import com.mairwunnx.projectessentials.home.enums.HomeSelectStrategy.First
17+
import com.mairwunnx.projectessentials.home.enums.HomeSelectStrategy.Last
18+
import net.minecraft.entity.player.ServerPlayerEntity
1619
import net.minecraftforge.common.MinecraftForge.EVENT_BUS
20+
import net.minecraftforge.event.entity.player.PlayerEvent
21+
import net.minecraftforge.eventbus.api.SubscribeEvent
1722
import net.minecraftforge.fml.InterModComms
1823
import net.minecraftforge.fml.common.Mod
1924

@@ -34,6 +39,20 @@ class ModuleObject : IModule {
3439
}
3540
}
3641

42+
@SubscribeEvent
43+
fun onPlayerRespawn(event: PlayerEvent.PlayerRespawnEvent) {
44+
val player = event.player as ServerPlayerEntity
45+
homeConfiguration.users.asSequence().find {
46+
it.name == player.name.string || it.uuid == player.uniqueID.toString()
47+
}?.let {
48+
if (it.homes.isEmpty()) return
49+
when (homeSettingsConfiguration.respawnHomeSelectStrategy) {
50+
Last -> teleportToHome(player, it.homes.last())
51+
First -> teleportToHome(player, it.homes.first())
52+
}
53+
}
54+
}
55+
3756
private fun sendLocalizationRequest() {
3857
InterModComms.sendTo(
3958
"project_essentials_core",

src/main/kotlin/com/mairwunnx/projectessentials/home/commands/HomeCommand.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.mairwunnx.projectessentials.home.commands
33
import com.mairwunnx.projectessentials.core.api.v1.MESSAGE_MODULE_PREFIX
44
import com.mairwunnx.projectessentials.core.api.v1.commands.CommandAPI
55
import com.mairwunnx.projectessentials.core.api.v1.commands.CommandBase
6+
import com.mairwunnx.projectessentials.core.api.v1.commands.back.BackLocationAPI
67
import com.mairwunnx.projectessentials.core.api.v1.extensions.getPlayer
78
import com.mairwunnx.projectessentials.core.api.v1.messaging.MessagingAPI
89
import com.mairwunnx.projectessentials.core.api.v1.messaging.ServerMessagingAPI
@@ -35,6 +36,7 @@ object HomeCommand : CommandBase(homeLiteral, false) {
3536
it.home == name
3637
}?.let {
3738
teleportToHome(player, it).also {
39+
BackLocationAPI.commit(player)
3840
out("success", name).also { super.process(context) }
3941
}
4042
} ?: run { out("not_found", name) }

0 commit comments

Comments
 (0)