Target enum

Пакет: com.hypixel.hytale.builtin.triggervolumes.effect.builtin

Файл: com/hypixel/hytale/builtin/triggervolumes/effect/builtin/PlayAnimationEffect.java

Поля (1)

МодификаторыТипИмя
TRIGGERING_ENTITY, NPCS_IN_VOLUME

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.triggervolumes.effect.builtin;

class="kw">import com.hypixel.hytale.builtin.triggervolumes.TriggerVolumesPlugin;
class="kw">import com.hypixel.hytale.builtin.triggervolumes.effect.TriggerContext;
class="kw">import com.hypixel.hytale.builtin.triggervolumes.effect.TriggerEffect;
class="kw">import com.hypixel.hytale.builtin.triggervolumes.effect.TriggerEventType;
class="kw">import com.hypixel.hytale.builtin.triggervolumes.effect.TriggerVolumeEntityQuery;
class="kw">import com.hypixel.hytale.builtin.triggervolumes.manager.TriggerVolumeManager;
class="kw">import com.hypixel.hytale.builtin.triggervolumes.system.DelayedEffectScheduler;
class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.codec.builder.BuilderCodec;
class="kw">import com.hypixel.hytale.codec.codecs.EnumCodec;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.protocol.AnimationSlot;
class="kw">import com.hypixel.hytale.server.core.entity.AnimationUtils;
class="kw">import com.hypixel.hytale.server.core.entity.UUIDComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.ActiveAnimationComponent;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import com.hypixel.hytale.server.npc.entities.NPCEntity;
class="kw">import java.util.ArrayList;
class="kw">import java.util.List;
class="kw">import java.util.Objects;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;

class="kw">public class PlayAnimationEffect class="kw">extends TriggerEffect {
   class="kw">public class="kw">static class="kw">final String APPLY_ON_PLAYER = "Player";
   class="kw">public class="kw">static class="kw">final String APPLY_ON_EVERYONE = "Everyone";
   @Nonnull
   class="kw">public class="kw">static class="kw">final BuilderCodec<PlayAnimationEffect> CODEC = BuilderCodec.builder(PlayAnimationEffect.class, PlayAnimationEffect::new, BASE_CODEC)
      .append(new KeyedCodec<>("NpcType", Codec.STRING, false), (var0, var1) -> var0.npcType = var1 == null ? "" : var1, var0 -> var0.npcType)
      .add()
      .append(new KeyedCodec<>("Animation", Codec.STRING, false), (var0, var1) -> var0.animation = var1, var0 -> var0.animation)
      .add()
      .append(new KeyedCodec<>("Target", new EnumCodec<>(PlayAnimationEffect.Target.class), false), (var0, var1) -> var0.target = var1, var0 -> var0.target)
      .add()
      .append(new KeyedCodec<>("Duration", Codec.FLOAT, false), (var0, var1) -> var0.duration = var1, var0 -> var0.duration)
      .add()
      .append(new KeyedCodec<>("Stop", Codec.BOOLEAN, false), (var0, var1) -> var0.stop = var1, var0 -> var0.stop)
      .add()
      .build();
   @Nullable
   class="kw">private String animation;
   @Nonnull
   class="kw">private class="kw">static class="kw">final AnimationSlot SLOT = AnimationSlot.ServerAction;
   @Nonnull
   class="kw">private PlayAnimationEffect.Target target = PlayAnimationEffect.Target.NPCS_IN_VOLUME;
   @Nonnull
   class="kw">private String npcType = "";
   class="kw">private float duration;
   class="kw">private boolean stop;

   class="kw">public PlayAnimationEffect() {
   }

   @Override
   class="kw">public void execute(@Nonnull TriggerContext var1) {
      Store var2 = var1.getStore();
      if (this.stop || this.animation != null && !this.animation.isBlank()) {
         for (Ref var4 : this.resolveTargets(var1)) {
            if (this.stop) {
               this.stopOn(var2, var4);
            } else {
               boolean var5 = this.playOn(var2, var4);
               if (var5 && this.duration > 0.0F && Float.isFinite(this.duration)) {
                  this.scheduleStop(var1, var4);
               }
            }
         }
      }
   }

   @Nonnull
   class="kw">public String getNpcType() {
      class="kw">return this.npcType;
   }

   @Nullable
   class="kw">public String getAnimation() {
      class="kw">return this.animation;
   }

   @Nonnull
   class="kw">private List<Ref<EntityStore>> resolveTargets(@Nonnull TriggerContext var1) {
      Store var2 = var1.getStore();
      if (this.target == PlayAnimationEffect.Target.TRIGGERING_ENTITY) {
         Ref var6 = var1.getEntityRef();
         class="kw">return this.matchesApplyOn(var2, var6) ? List.of(var6) : List.of();
      } else {
         List var3 = TriggerVolumeEntityQuery.collectTargets(var2, var1.getSpatialVolumes(), this.includesNpcs(), this.includesPlayers(), this.roleFilter());
         Ref var4 = var1.getEntityRef();
         if (this.isEligibleTriggerTarget(var2, var4) && !containsEntity(var2, var3, var4)) {
            ArrayList var5 = new ArrayList<>(var3.size() + 1);
            var5.addAll(var3);
            var5.add(var4);
            class="kw">return var5;
         } else {
            class="kw">return var3;
         }
      }
   }

   class="kw">private boolean isEligibleTriggerTarget(@Nonnull Store<EntityStore> var1, @Nonnull Ref<EntityStore> var2) {
      if (!this.matchesApplyOn(var1, var2)) {
         class="kw">return false;
      } else if (var1.getComponent(var2, NPCEntity.getComponentType()) != null) {
         class="kw">return this.includesNpcs();
      } else {
         class="kw">return var1.getComponent(var2, PlayerRef.getComponentType()) != null ? this.includesPlayers() : false;
      }
   }

   class="kw">private class="kw">static boolean containsEntity(@Nonnull Store<EntityStore> var0, @Nonnull List<Ref<EntityStore>> var1, @Nonnull Ref<EntityStore> var2) {
      UUIDComponent var3 = var0.getComponent(var2, UUIDComponent.getComponentType());
      if (var3 == null) {
         class="kw">return var1.contains(var2);
      }

      for (Ref var5 : var1) {
         UUIDComponent var6 = var0.getComponent(var5, UUIDComponent.getComponentType());
         if (var6 != null && var6.getUuid().equals(var3.getUuid())) {
            class="kw">return true;
         }
      }

      class="kw">return false;
   }

   class="kw">private boolean includesPlayers() {
      class="kw">return "Player".equals(this.npcType) || "Everyone".equals(this.npcType);
   }

   class="kw">private boolean includesNpcs() {
      class="kw">return !"Player".equals(this.npcType);
   }

   @Nonnull
   class="kw">private String roleFilter() {
      class="kw">return !this.npcType.isBlank() && !"Player".equals(this.npcType) && !"Everyone".equals(this.npcType) ? this.npcType : "";
   }

   class="kw">private boolean matchesApplyOn(@Nonnull Store<EntityStore> var1, @Nonnull Ref<EntityStore> var2) {
      if (!var2.isValid()) {
         class="kw">return false;
      }

      if (this.npcType.isBlank() || "Everyone".equals(this.npcType)) {
         class="kw">return true;
      }

      if ("Player".equals(this.npcType)) {
         class="kw">return var1.getComponent(var2, PlayerRef.getComponentType()) != null;
      }

      NPCEntity var3 = var1.getComponent(var2, NPCEntity.getComponentType());
      if (var3 == null) {
         class="kw">return false;
      }

      String var4 = var3.getRoleName();
      class="kw">return var4 != null && var4.equalsIgnoreCase(this.npcType);
   }

   class="kw">private boolean playOn(@Nonnull Store<EntityStore> var1, @Nonnull Ref<EntityStore> var2) {
      if (var2.isValid() && this.animation != null) {
         boolean var3 = this.getEventType() == TriggerEventType.TICK;
         NPCEntity var4 = var1.getComponent(var2, NPCEntity.getComponentType());
         if (var4 != null) {
            if (var3) {
               ActiveAnimationComponent var5 = var1.getComponent(var2, ActiveAnimationComponent.getComponentType());
               if (var5 != null && this.animation.equals(var5.getActiveAnimations()[SLOT.ordinal()])) {
                  class="kw">return false;
               }
            }

            var4.playAnimation(var2, SLOT, this.animation, !var3, var1);
         } else {
            AnimationUtils.playAnimation(var2, SLOT, this.animation, true, var1);
         }

         class="kw">return true;
      } else {
         class="kw">return false;
      }
   }

   class="kw">private void stopOn(@Nonnull Store<EntityStore> var1, @Nonnull Ref<EntityStore> var2) {
      if (var2.isValid()) {
         NPCEntity var3 = var1.getComponent(var2, NPCEntity.getComponentType());
         if (var3 != null) {
            var3.playAnimation(var2, SLOT, null, var1);
         } else {
            AnimationUtils.stopAnimation(var2, SLOT, true, var1);
         }
      }
   }

   class="kw">private void scheduleStop(@Nonnull TriggerContext var1, @Nonnull Ref<EntityStore> var2) {
      Store var3 = var1.getStore();
      UUIDComponent var4 = var3.getComponent(var2, UUIDComponent.getComponentType());
      if (var4 != null) {
         TriggerVolumeManager var5 = var3.getResource(TriggerVolumesPlugin.get().getManagerResourceType());
         if (var5 != null) {
            AnimationSlot var6 = SLOT;
            String var7 = this.animation;
            String var8 = "PlayAnimation:" + SLOT.name();
            DelayedEffectScheduler var9 = var5.getDelayedEffectScheduler();
            var9.cancelGates(var4.getUuid(), var8);
            var9.scheduleGate(
               (var2x, var3x, var4x, var5x, var6x, var7x, var8x) -> stopAnimationIfMatching(var7x, var2x, var6, var7),
               var2,
               var4.getUuid(),
               TriggerEventType.EXIT,
               var1.getVolume(),
               System.nanoTime(),
               this.duration,
               var1.getSpatialVolumes(),
               var8
            );
         }
      }
   }

   class="kw">private class="kw">static void stopAnimationIfMatching(
      @Nonnull Store<EntityStore> var0, @Nonnull Ref<EntityStore> var1, @Nonnull AnimationSlot var2, @Nullable String var3
   ) {
      if (var1.isValid()) {
         NPCEntity var4 = var0.getComponent(var1, NPCEntity.getComponentType());
         if (var4 != null) {
            ActiveAnimationComponent var5 = var0.getComponent(var1, ActiveAnimationComponent.getComponentType());
            if (var5 != null && !Objects.equals(var5.getActiveAnimations()[var2.ordinal()], var3)) {
               class="kw">return;
            }

            var4.playAnimation(var1, var2, null, var0);
         } else {
            AnimationUtils.stopAnimation(var1, var2, true, var0);
         }
      }
   }

   class="kw">public enum Target {
      TRIGGERING_ENTITY,
      NPCS_IN_VOLUME;

      Target() {
      }
   }
}