PrefabPasteEventSystem class

Пакет: com.hypixel.hytale.builtin.path

Файл: com/hypixel/hytale/builtin/path/PathPlugin.java

extends: WorldEventSystem<EntityStore, PrefabPasteEvent>

Поля (3)

МодификаторыТипИмя
private final Set<Dependency<EntityStore>> dependencies
ConcurrentHashMap var4
WorldPathData var5

Методы (4)

МодификаторыВозвратСигнатура
public Set<Dependency<EntityStore>> getDependenciespublic Set<Dependency<EntityStore>> getDependencies()
public void handlepublic void handle(@Nonnull Store<EntityStore> var1, @Nonnull CommandBuffer<EntityStore> var2, @Nonnull PrefabPasteEvent var3)
if if(var4 != null)
abstract super super(PrefabPasteEvent.class)

Исходный код

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

class="kw">import com.hypixel.hytale.assetstore.event.LoadedAssetsEvent;
class="kw">import com.hypixel.hytale.assetstore.map.DefaultAssetMap;
class="kw">import com.hypixel.hytale.builtin.buildertools.BuilderToolsPlugin;
class="kw">import com.hypixel.hytale.builtin.path.commands.PrefabPathCommand;
class="kw">import com.hypixel.hytale.builtin.path.commands.WorldPathCommand;
class="kw">import com.hypixel.hytale.builtin.path.entities.PatrolPathMarkerEntity;
class="kw">import com.hypixel.hytale.codec.Codec;
class="kw">import com.hypixel.hytale.codec.KeyedCodec;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.ComponentRegistryProxy;
class="kw">import com.hypixel.hytale.component.ComponentType;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.ResourceType;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.component.dependency.Dependency;
class="kw">import com.hypixel.hytale.component.dependency.Order;
class="kw">import com.hypixel.hytale.component.dependency.OrderPriority;
class="kw">import com.hypixel.hytale.component.dependency.SystemDependency;
class="kw">import com.hypixel.hytale.component.spatial.KDTree;
class="kw">import com.hypixel.hytale.component.spatial.SpatialResource;
class="kw">import com.hypixel.hytale.component.system.WorldEventSystem;
class="kw">import com.hypixel.hytale.event.EventRegistry;
class="kw">import com.hypixel.hytale.server.core.HytaleServer;
class="kw">import com.hypixel.hytale.server.core.HytaleServerConfig;
class="kw">import com.hypixel.hytale.server.core.asset.type.model.config.Model;
class="kw">import com.hypixel.hytale.server.core.asset.type.model.config.ModelAsset;
class="kw">import com.hypixel.hytale.server.core.command.system.CommandRegistry;
class="kw">import com.hypixel.hytale.server.core.plugin.JavaPlugin;
class="kw">import com.hypixel.hytale.server.core.plugin.JavaPluginInit;
class="kw">import com.hypixel.hytale.server.core.prefab.event.PrefabPasteEvent;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import java.util.Set;
class="kw">import java.util.UUID;
class="kw">import java.util.concurrent.ConcurrentHashMap;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;

class="kw">public class PathPlugin class="kw">extends JavaPlugin {
   class="kw">public class="kw">static class="kw">final KeyedCodec<String> PATH_MARKER_MODEL = new KeyedCodec<>("PathMarkerModel", Codec.STRING);
   class="kw">public class="kw">static class="kw">final String DEFAULT_PATH_MARKER_MODEL = "NPC_Path_Marker";
   class="kw">private class="kw">static PathPlugin instance;
   class="kw">private ResourceType<EntityStore, WorldPathData> worldPathDataResourceType;
   class="kw">private ResourceType<EntityStore, SpatialResource<Ref<EntityStore>, EntityStore>> prefabPathSpatialResource;
   class="kw">private ComponentType<EntityStore, WorldPathBuilder> worldPathBuilderComponentType;
   class="kw">private Model pathMarkerModel;

   class="kw">public class="kw">static PathPlugin get() {
      class="kw">return instance;
   }

   class="kw">public PathPlugin(@Nonnull JavaPluginInit var1) {
      super(var1);
   }

   @Override
   class="kw">protected void setup() {
      instance = this;
      CommandRegistry var1 = this.getCommandRegistry();
      EventRegistry var2 = this.getEventRegistry();
      ComponentRegistryProxy var3 = this.getEntityStoreRegistry();
      if (BuilderToolsPlugin.get().isEnabled()) {
         var1.registerCommand(new PrefabPathCommand());
      }

      var1.registerCommand(new WorldPathCommand());
      var2.register(LoadedAssetsEvent.class, ModelAsset.class, this::onModelsChanged);
      var3.registerSystem(new PathPlugin.PrefabPasteEventSystem());
      this.getEntityRegistry().registerEntity("PatrolPathMarker", PatrolPathMarkerEntity.class, PatrolPathMarkerEntity::new, PatrolPathMarkerEntity.CODEC);
      this.worldPathDataResourceType = var3.registerResource(WorldPathData.class, WorldPathData::new);
      this.prefabPathSpatialResource = var3.registerSpatialResource(() -> new KDTree<>(Ref::isValid));
      this.worldPathBuilderComponentType = var3.registerComponent(WorldPathBuilder.class, () -> {
         throw new UnsupportedOperationException("Not implemented");
      });
      var3.registerSystem(new PrefabPathSystems.AddOrRemove());
      var3.registerSystem(new PrefabPathSystems.AddedFromWorldGen());
      var3.registerSystem(new PathSpatialSystem(this.prefabPathSpatialResource));
      var3.registerSystem(new PrefabPathSystems.NameplateHolderSystem());
      var3.registerSystem(new PrefabPathSystems.NameplateRefChangeSystem());
      var3.registerSystem(new PrefabPathSystems.WorldGenChangeSystem());
      var3.registerSystem(new PrefabPathSystems.PrefabPlaceEntityEventSystem());
   }

   @Override
   class="kw">protected void start() {
      HytaleServerConfig.Module var1 = HytaleServer.get().getConfig().getModule("PathPlugin");
      String var2 = var1.getData(PATH_MARKER_MODEL).orElse("NPC_Path_Marker");
      DefaultAssetMap var3 = ModelAsset.getAssetMap();
      ModelAsset var4 = var3.getAsset(var2);
      if (var4 == null) {
         this.getLogger().at(Level.SEVERE).log("Path marker model %s does not exist", var2);
         var4 = var3.getAsset("NPC_Path_Marker");
         if (var4 == null) {
            throw new IllegalStateException(String.format("Default path marker '%s' not found", "NPC_Path_Marker"));
         }
      }

      this.pathMarkerModel = Model.createUnitScaleModel(var4);
   }

   class="kw">public ResourceType<EntityStore, WorldPathData> getWorldPathDataResourceType() {
      class="kw">return this.worldPathDataResourceType;
   }

   class="kw">public ResourceType<EntityStore, SpatialResource<Ref<EntityStore>, EntityStore>> getPrefabPathSpatialResource() {
      class="kw">return this.prefabPathSpatialResource;
   }

   class="kw">public ComponentType<EntityStore, WorldPathBuilder> getWorldPathBuilderComponentType() {
      class="kw">return this.worldPathBuilderComponentType;
   }

   class="kw">public Model getPathMarkerModel() {
      class="kw">return this.pathMarkerModel;
   }

   class="kw">protected void onModelsChanged(@Nonnull LoadedAssetsEvent<String, ModelAsset, DefaultAssetMap<String, ModelAsset>> var1) {
      if (this.pathMarkerModel != null) {
         ModelAsset var2 = var1.getLoadedAssets().get(this.pathMarkerModel.getModelAssetId());
         if (var2 != null) {
            this.pathMarkerModel = Model.createUnitScaleModel(var2);
         }
      }
   }

   class="kw">private class="kw">static class PrefabPasteEventSystem class="kw">extends WorldEventSystem<EntityStore, PrefabPasteEvent> {
      @Nonnull
      class="kw">private class="kw">final Set<Dependency<EntityStore>> dependencies = Set.of(
         new SystemDependency<>(Order.AFTER, BuilderToolsPlugin.PrefabPasteEventSystem.class, OrderPriority.CLOSEST)
      );

      class="kw">protected PrefabPasteEventSystem() {
         super(PrefabPasteEvent.class);
      }

      class="kw">public void handle(@Nonnull Store<EntityStore> var1, @Nonnull CommandBuffer<EntityStore> var2, @Nonnull PrefabPasteEvent var3) {
         if (!var3.isPasteStart()) {
            ConcurrentHashMap var4 = BuilderToolsPlugin.get().getPastedPrefabPathUUIDMap().get(var3.getPrefabId());
            if (var4 != null) {
               WorldPathData var5 = var1.getResource(WorldPathData.getResourceType());

               for (UUID var7 : var4.values()) {
                  var5.compactPrefabPath(0, var7);
               }
            }
         }
      }

      @Nonnull
      @Override
      class="kw">public Set<Dependency<EntityStore>> getDependencies() {
         class="kw">return this.dependencies;
      }
   }
}