SnapshotType enum

Пакет: com.hypixel.hytale.builtin.points.snapshot

Файл: com/hypixel/hytale/builtin/points/snapshot/PointSnapshot.java

Поля (1)

МодификаторыТипИмя
CREATE, DELETE, MUTATE

Исходный код

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

class="kw">import com.hypixel.hytale.builtin.buildertools.snapshot.SelectionSnapshot;
class="kw">import com.hypixel.hytale.builtin.points.PointsPlugin;
class="kw">import com.hypixel.hytale.builtin.points.manager.PointEntry;
class="kw">import com.hypixel.hytale.builtin.points.manager.PointManager;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.protocol.packets.player.PointShapeType;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import java.util.Collections;
class="kw">import java.util.HashMap;
class="kw">import java.util.Map;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3d;
class="kw">import org.joml.Vector3f;

class="kw">public class PointSnapshot class="kw">implements SelectionSnapshot<PointSnapshot> {
   class="kw">private class="kw">final PointSnapshot.SnapshotType type;
   class="kw">private class="kw">final String pointId;
   class="kw">private class="kw">final String worldName;
   @Nullable
   class="kw">private class="kw">final Vector3d position;
   @Nullable
   class="kw">private class="kw">final Vector3f rotation;
   @Nullable
   class="kw">private class="kw">final String name;
   class="kw">private class="kw">final boolean enabled;
   @Nonnull
   class="kw">private class="kw">final PointShapeType shape;
   @Nullable
   class="kw">private class="kw">final Map<String, String> rawTags;

   class="kw">private PointSnapshot(
      @Nonnull PointSnapshot.SnapshotType var1,
      @Nonnull String var2,
      @Nonnull String var3,
      @Nullable Vector3d var4,
      @Nullable Vector3f var5,
      @Nullable String var6,
      boolean var7,
      @Nonnull PointShapeType var8,
      @Nullable Map<String, String> var9
   ) {
      this.type = var1;
      this.pointId = var2;
      this.worldName = var3;
      this.position = var4;
      this.rotation = var5;
      this.name = var6;
      this.enabled = var7;
      this.shape = var8;
      this.rawTags = var9;
   }

   class="kw">public class="kw">static PointSnapshot ofCreate(@Nonnull PointEntry var0) {
      class="kw">return new PointSnapshot(PointSnapshot.SnapshotType.CREATE, var0.getId(), var0.getWorldName(), null, null, null, true, PointShapeType.Block, null);
   }

   class="kw">public class="kw">static PointSnapshot ofDelete(@Nonnull PointEntry var0) {
      class="kw">return captureState(PointSnapshot.SnapshotType.DELETE, var0);
   }

   class="kw">public class="kw">static PointSnapshot ofMutate(@Nonnull PointEntry var0) {
      class="kw">return captureState(PointSnapshot.SnapshotType.MUTATE, var0);
   }

   class="kw">private class="kw">static PointSnapshot captureState(@Nonnull PointSnapshot.SnapshotType var0, @Nonnull PointEntry var1) {
      class="kw">return new PointSnapshot(
         var0,
         var1.getId(),
         var1.getWorldName(),
         new Vector3d(var1.getPosition()),
         new Vector3f(var1.getRotation()),
         var1.getName(),
         var1.isEnabled(),
         var1.getShape(),
         copyTags(var1.getRawTags())
      );
   }

   @Nonnull
   class="kw">private class="kw">static Map<String, String> copyTags(@Nonnull Map<String, String> var0) {
      class="kw">return var0.isEmpty() ? Collections.emptyMap() : new HashMap<>(var0);
   }

   @Nullable
   class="kw">public PointSnapshot restore(@Nonnull Ref<EntityStore> var1, PlayerRef var2, World var3, ComponentAccessor<EntityStore> var4) {
      PointManager var5 = PointsPlugin.get().getManagerForWorld(this.worldName);
      if (var5 == null) {
         class="kw">return null;
      }

      class="kw">return class="kw">switch (this.type) {
         case CREATE -> {
            PointEntry var9 = var5.getPoint(this.pointId);
            if (var9 == null) {
               yield null;
            } else {
               PointSnapshot var10 = ofDelete(var9);
               var5.unregister(this.pointId);
               var5.notifyViewersRemove(this.pointId);
               yield var10;
            }
         }
         case DELETE -> {
            if (this.position != null && this.rotation != null) {
               PointEntry var8 = new PointEntry(this.pointId, this.worldName, new Vector3d(this.position), new Vector3f(this.rotation), this.name, this.enabled);
               var8.setShape(this.shape);
               if (this.rawTags != null) {
                  var8.setTags(copyTags(this.rawTags));
               }

               var5.register(this.pointId, var8);
               var5.notifyViewersAdd(var8);
               yield ofCreate(var8);
            } else {
               yield null;
            }
         }
         case MUTATE -> {
            PointEntry var6 = var5.getPoint(this.pointId);
            if (var6 == null) {
               yield null;
            } else {
               PointSnapshot var7 = ofMutate(var6);
               if (this.position != null) {
                  var6.setPosition(new Vector3d(this.position));
               }

               if (this.rotation != null) {
                  var6.setRotation(new Vector3f(this.rotation));
               }

               var6.setName(this.name);
               var6.setEnabled(this.enabled);
               var6.setShape(this.shape);
               if (this.rawTags != null) {
                  var6.setTags(copyTags(this.rawTags));
               }

               var5.markSpatialDirty();
               var5.notifyViewersAdd(var6);
               yield var7;
            }
         }
      };
   }

   class="kw">public enum SnapshotType {
      CREATE,
      DELETE,
      MUTATE;

      SnapshotType() {
      }
   }
}