Skip to content

Commit

Permalink
Synced with 1.15.2.
Browse files Browse the repository at this point in the history
Signed-off-by: Pavel Erokhin (MairwunNx) <MairwunNx@gmail.com>
  • Loading branch information
MairwunNx committed Jun 20, 2020
1 parent 96a7271 commit 9bd0350
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 15 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ kotlin.code.style=official
kotlin_version=1.3.72
kotlinx_serialization_version=0.20.0
# Module informatation.
module_version=2.0.1-RC.1+MC-1.14.4
module_version=2.0.1+MC-1.14.4
module_name=Project Essentials Spawn
module_id=project_essentials_spawn
module_vendor=MairwunNx (Pavel Erokhin)
Expand Down
4 changes: 3 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[![MIT License](https://img.shields.io/apm/l/atomic-design-ui.svg?)](https://github.com/ProjectEssentials/ProjectEssentials-Spawn/blob/master/LICENSEs) [![GitHub Release](https://img.shields.io/github/release/ProjectEssentials/ProjectEssentials-Spawn.svg?style=flat)]() [![Donate](https://img.shields.io/badge/$-support-ff69b4.svg?style=flat)](https://paypal.me/mairwunnx) [![Discord Chat](https://img.shields.io/discord/308323056592486420.svg)](https://discord.gg/VU9XZAt)

### What is it

How we control spawn point! Adds literally two commands to configure players spawn point in the game world.

### Explore

#### [Download mod](https://github.com/ProjectEssentials/ProjectEssentials-Spawn/releases/download/2.0.0%2BMC-1.14.4/Project.Essentials.Spawn-2.0.0+MC-1.14.4.jar) · [User guide](https://mairwunnx.gitbook.io/project-essentials/project-essentials-spawn#how-to-install) · [Troubleshooting](https://github.com/ProjectEssentials/ProjectEssentials-Spawn/issues/new/choose) · [Telegram](https://t.me/minecraftforge) · [Discord](https://discord.gg/VU9XZAt) · [Change log](https://github.com/ProjectEssentials/ProjectEssentials-Spawn/blob/master/changelog.md)
#### [Download mod](https://github.com/ProjectEssentials/ProjectEssentials-Spawn/releases/download/2.0.1%2BMC-1.14.4/Project.Essentials.Spawn-2.0.1+MC-1.14.4.jar) · [Documentation and Guides](https://projectessentials.github.io/manual) · [Troubleshooting](https://github.com/ProjectEssentials/ProjectEssentials-Spawn/issues/new/choose) · [Telegram](https://t.me/minecraftforge) · [Discord](https://discord.gg/VU9XZAt) · [CurseForge](https://www.curseforge.com/minecraft/mc-mods/project-essentials-spawn) · [Change log](https://github.com/ProjectEssentials/ProjectEssentials-Spawn/blob/master/changelog.md)

[![](https://github.com/ProjectEssentials/ProjectEssentials-Assets/raw/ASSETS-20-Q2/assets/common/support.png)](https://gist.github.com/MairwunNx/fda95062618db6880ef8ee06e1bba54f)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
@file:Suppress("unused", "SENSELESS_COMPARISON")
@file:Suppress("unused", "SENSELESS_COMPARISON", "UNNECESSARY_SAFE_CALL")

package com.mairwunnx.projectessentials.spawn

import com.mairwunnx.projectessentials.core.api.v1.configuration.ConfigurationAPI.getConfigurationByName
import com.mairwunnx.projectessentials.core.api.v1.extensions.asPlayerEntity
import com.mairwunnx.projectessentials.core.api.v1.localization.LocalizationAPI
import com.mairwunnx.projectessentials.core.api.v1.module.IModule
import com.mairwunnx.projectessentials.core.api.v1.providers.ProviderAPI
import com.mairwunnx.projectessentials.spawn.commands.SetSpawnCommand
import com.mairwunnx.projectessentials.spawn.commands.SpawnCommand
import com.mairwunnx.projectessentials.spawn.configurations.SpawnConfiguration
import net.minecraft.entity.player.PlayerEntity
import net.minecraft.entity.player.ServerPlayerEntity
import net.minecraft.world.dimension.DimensionType
import net.minecraft.world.dimension.DimensionType.getById
import net.minecraftforge.common.MinecraftForge.EVENT_BUS
import net.minecraftforge.event.entity.player.PlayerEvent
import net.minecraftforge.eventbus.api.EventPriority
Expand All @@ -25,7 +28,7 @@ val spawnConfiguration by lazy {

fun forceTeleportToSpawn(player: ServerPlayerEntity) {
val targetWorld = player.server.getWorld(
DimensionType.getById(spawnConfiguration.take().dimensionId) ?: DimensionType.OVERWORLD
getById(spawnConfiguration.take().dimensionId) ?: DimensionType.OVERWORLD
)
with(spawnConfiguration.take()) {
player.teleport(targetWorld, xPos + 0.5, yPos + 0.5, zPos + 0.5, yaw, pitch)
Expand Down Expand Up @@ -75,20 +78,33 @@ class ModuleObject : IModule {
}
}

private val handledForSpawn = mutableSetOf<String>()

@SubscribeEvent(priority = EventPriority.HIGHEST)
fun onPlayerRespawn(event: PlayerEvent.Clone) {
if (!event.isWasDeath) return
val player = event.original as ServerPlayerEntity
if (player.bedPosition.isPresent) {
player.server.worlds.forEach {
val pos = player.getBedLocation(it.dimension.type)
if (pos != null) {
player.server.worlds.forEach {
player.getBedLocation(it.dimension.type)?.let { pos ->
if (
PlayerEntity.func_213822_a(
player.server.getWorld(player.dimension), pos, false
).isPresent
) {
player.teleport(
it,
pos.x.toDouble() + 0.5, pos.y.toDouble() + 0.5, pos.z.toDouble() + 0.5,
it, pos.x.toDouble() + 0.5, pos.y.toDouble() + 0.5, pos.z.toDouble() + 0.5,
player.rotationYaw, player.rotationPitch
)
}
).let { return }
} else handledForSpawn.add(player.name.string)
}
} else forceTeleportToSpawn(player)
}
handledForSpawn.add(player.name.string)
}

@SubscribeEvent(priority = EventPriority.HIGHEST)
fun onPlayerRespawnPost(event: PlayerEvent.PlayerRespawnEvent) {
if (event.player.name.string !in handledForSpawn) return
handledForSpawn.remove(event.player.name.string)
forceTeleportToSpawn(event.player.asPlayerEntity)
}
}
5 changes: 3 additions & 2 deletions updatev2.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
"homepage": "https://github.com/ProjectEssentials/ProjectEssentials-Spawn",
"1.14.4": {
"2.0.1": "change log -> https://github.com/ProjectEssentials/ProjectEssentials-Spawn/blob/master/changelog.md#201---2020-06-20",
"2.0.1-RC.1": "change log -> https://github.com/ProjectEssentials/ProjectEssentials-Spawn/blob/master/changelog.md#201-rc.1---2020-06-13",
"2.0.0": "change log -> https://github.com/ProjectEssentials/ProjectEssentials-Spawn/blob/master/changelog.md#200---2020-06-08"
},
"promos": {
"1.14.4-latest": "2.0.1-RC.1",
"1.14.4-recommended": "2.0.0"
"1.14.4-latest": "2.0.1",
"1.14.4-recommended": "2.0.1"
}
}

0 comments on commit 9bd0350

Please sign in to comment.