From 0a78fbfead1b081bb6a5c61aedb895c0838b5ffd Mon Sep 17 00:00:00 2001 From: iron431 <34083081+iron431@users.noreply.github.com> Date: Mon, 20 Nov 2023 00:02:59 -0600 Subject: [PATCH] cancel cast on player disconnect --- .../player/ServerPlayerEvents.java | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/main/java/io/redspace/ironsspellbooks/player/ServerPlayerEvents.java b/src/main/java/io/redspace/ironsspellbooks/player/ServerPlayerEvents.java index c39d651fd..fafe3447b 100644 --- a/src/main/java/io/redspace/ironsspellbooks/player/ServerPlayerEvents.java +++ b/src/main/java/io/redspace/ironsspellbooks/player/ServerPlayerEvents.java @@ -1,10 +1,10 @@ package io.redspace.ironsspellbooks.player; -import io.redspace.ironsspellbooks.api.events.SpellDamageEvent; -import io.redspace.ironsspellbooks.api.events.ChangeManaEvent; import io.redspace.ironsspellbooks.api.magic.MagicData; -import io.redspace.ironsspellbooks.IronsSpellbooks; +import io.redspace.ironsspellbooks.api.registry.AttributeRegistry; +import io.redspace.ironsspellbooks.api.spells.CastType; import io.redspace.ironsspellbooks.api.util.CameraShakeManager; +import io.redspace.ironsspellbooks.api.util.Utils; import io.redspace.ironsspellbooks.block.BloodCauldronBlock; import io.redspace.ironsspellbooks.capabilities.magic.SyncedSpellData; import io.redspace.ironsspellbooks.capabilities.magic.UpgradeData; @@ -19,15 +19,12 @@ import io.redspace.ironsspellbooks.entity.mobs.abstract_spell_casting_mob.AbstractSpellCastingMob; import io.redspace.ironsspellbooks.entity.spells.root.PreventDismount; import io.redspace.ironsspellbooks.item.SpellBook; -import io.redspace.ironsspellbooks.api.registry.AttributeRegistry; import io.redspace.ironsspellbooks.item.curios.LurkerRing; import io.redspace.ironsspellbooks.registries.BlockRegistry; import io.redspace.ironsspellbooks.registries.ItemRegistry; import io.redspace.ironsspellbooks.registries.MobEffectRegistry; -import io.redspace.ironsspellbooks.api.spells.CastType; import io.redspace.ironsspellbooks.util.ModTags; import io.redspace.ironsspellbooks.util.UpgradeUtils; -import io.redspace.ironsspellbooks.api.util.Utils; import net.minecraft.core.BlockPos; import net.minecraft.network.protocol.game.ClientboundSetEntityDataPacket; import net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket; @@ -39,7 +36,6 @@ import net.minecraft.world.damagesource.IndirectEntityDamageSource; import net.minecraft.world.effect.MobEffects; import net.minecraft.world.entity.Entity; -import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.monster.Creeper; import net.minecraft.world.entity.player.Player; @@ -102,6 +98,12 @@ public static void onLivingEquipmentChangeEvent(LivingEquipmentChangeEvent event } } + @SubscribeEvent + public static void onPlayerLogOut(PlayerEvent.PlayerLoggedOutEvent event) { + if (event.getEntity() instanceof ServerPlayer serverPlayer) { + Utils.serverSideCancelCast(serverPlayer); + } + } @SubscribeEvent public static void onPlayerOpenContainer(PlayerContainerEvent.Open event) { if (event.getEntity().level.isClientSide) {