diff --git a/gradle.properties b/gradle.properties index cd860c6..97c6a65 100644 --- a/gradle.properties +++ b/gradle.properties @@ -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.0+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) diff --git a/readme.md b/readme.md index e6edf2d..178a063 100644 --- a/readme.md +++ b/readme.md @@ -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) diff --git a/src/main/kotlin/com/mairwunnx/projectessentials/spawn/ModuleObject.kt b/src/main/kotlin/com/mairwunnx/projectessentials/spawn/ModuleObject.kt index a933bf9..eecb0c3 100644 --- a/src/main/kotlin/com/mairwunnx/projectessentials/spawn/ModuleObject.kt +++ b/src/main/kotlin/com/mairwunnx/projectessentials/spawn/ModuleObject.kt @@ -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 @@ -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) @@ -75,20 +78,33 @@ class ModuleObject : IModule { } } + private val handledForSpawn = mutableSetOf() + @SubscribeEvent(priority = EventPriority.HIGHEST) - fun onPlayerRespawn(event: PlayerEvent.PlayerRespawnEvent) { - val player = event.player as ServerPlayerEntity - if (player.bedPosition.isPresent) { - player.server.worlds.forEach { - val pos = player.getBedLocation(it.dimension.type) - if (pos != null) { + fun onPlayerRespawn(event: PlayerEvent.Clone) { + if (!event.isWasDeath) return + val player = event.original as ServerPlayerEntity + 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) } } diff --git a/src/main/resources/assets/projectessentialsspawn/lang/zh_cn.json b/src/main/resources/assets/projectessentialsspawn/lang/zh_cn.json index e3d3160..1583f96 100644 --- a/src/main/resources/assets/projectessentialsspawn/lang/zh_cn.json +++ b/src/main/resources/assets/projectessentialsspawn/lang/zh_cn.json @@ -1,4 +1,5 @@ { + "project_essentials_spawn.restricted": "§c你 §7没有权限 §c使用此命令。", "project_essentials_spawn.spawn.success": "§6传送到出生点。", "project_essentials_spawn.setspawn.success": "§6新 §7出生点 §6已保存。" } diff --git a/updatev2.json b/updatev2.json index a6f822f..ac31654 100644 --- a/updatev2.json +++ b/updatev2.json @@ -1,10 +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.0", - "1.14.4-recommended": "2.0.0" + "1.14.4-latest": "2.0.1", + "1.14.4-recommended": "2.0.1" } }