BrushConfigCommandExecutor class

Пакет: com.hypixel.hytale.builtin.buildertools.scriptedbrushes

Файл: com/hypixel/hytale/builtin/buildertools/scriptedbrushes/BrushConfigCommandExecutor.java

Поля (35)

МодификаторыТипИмя
Chat, Console, Both
final HytaleLogger LOGGER
var1
var1
var1
var1
var1
var1
UUIDComponent var10
PrototypePlayerBuilderToolSettings var11
BuilderToolsPlugin.BuilderState var12
BlockSelection var13
Vector3i var14
Vector3i var15
Player var3
Message var3
int var3
BrushConfig var3
SequenceBrushOperation var4
Player var4
PlayerRef var4
Set var4
var4x
PlayerRef var5
PlayerRef var5
BrushConfigEditStore var5
var5x
BrushConfigEditStore var6
var6x
PlayerRef var7
Player var8
int var8
Transform var8
PlayerRef var9
Vector3i var9

Методы (44)

МодификаторыВозвратСигнатура
DebugOutputTarget DebugOutputTarget()
public void clearAllPersistentVariablesvoid clearAllPersistentVariables()
public void clearPersistentVariablevoid clearPersistentVariable(String var1)
public void executevoid execute(@Nonnull Ref<EntityStore> var1, @Nonnull World var2, @Nonnull Vector3i var3, boolean var4, @Nonnull InteractionType var5, @Nullable Consumer<BrushConfig> var6, @Nonnull ComponentAccessor<EntityStore> var7)
public void executevoid execute(@Nonnull Ref<EntityStore> var1, World var2, Vector3i var3, boolean var4, InteractionType var5, ComponentAccessor<EntityStore> var6)
public void exitExecutionvoid exitExecution(Ref<EntityStore> var1, ComponentAccessor<EntityStore> var2)
for for(int var6 = 0; var6 < var8; var6++)
for for(BrushConfig.DataSettingFlags var7 : var2)
abstract for for(int var16 = 0; var16 < this.sequentialOperations.size()
public int getCurrentOperationIndexint getCurrentOperationIndex()
public BrushConfigCommandExecutor.DebugOutputTarget getDebugOutputTargetBrushConfigCommandExecutor.DebugOutputTarget getDebugOutputTarget()
public BrushConfigEditStore getEditBrushConfigEditStore getEdit()
public int getPersistentVariableOrDefaultint getPersistentVariableOrDefault(String var1, int var2)
if if(!var4)
if if(!this.ignoreExistingBrushData && var6 != null)
if if(!this.inDebugSteppingMode)
if if(this.printOperations)
if if(var5 != null)
if if(this.breakOnError)
if if(var7 != null)
if if(var2)
if if(this.currentOperationIndex != 0)
if if(!var2 && var3 > this.currentOperationIndex)
if if(var1 < 0)
public boolean isBreakOnErrorboolean isBreakOnError()
public boolean isEnableBreakpointsboolean isEnableBreakpoints()
public boolean isIgnoreExistingBrushDataboolean isIgnoreExistingBrushData()
public boolean isInDebugSteppingModeboolean isInDebugSteppingMode()
public void loadBrushConfigSnapshotvoid loadBrushConfigSnapshot(String var1, @Nonnull BrushConfig.DataSettingFlags... var2)
public void loadOperatingIndexvoid loadOperatingIndex(String var1)
public void loadOperatingIndexvoid loadOperatingIndex(String var1, boolean var2)
public void resetInternalStatevoid resetInternalState()
private void sendExecutionErrorMessagevoid sendExecutionErrorMessage(PlayerRef var1, @Nonnull SequenceBrushOperation var2)
public void setAllowOverwritingSavedSnapshotsvoid setAllowOverwritingSavedSnapshots(boolean var1)
public void setBreakOnErrorvoid setBreakOnError(boolean var1)
public void setCurrentlyExecutingActionIndexvoid setCurrentlyExecutingActionIndex(int var1)
public void setDebugOutputTargetvoid setDebugOutputTarget(BrushConfigCommandExecutor.DebugOutputTarget var1)
public void setEnableBreakpointsvoid setEnableBreakpoints(boolean var1)
public void setIgnoreExistingBrushDatavoid setIgnoreExistingBrushData(boolean var1)
public void setInDebugSteppingModevoid setInDebugSteppingMode(boolean var1)
public void setPersistentVariablevoid setPersistentVariable(String var1, int var2)
public void setPrintOperationsvoid setPrintOperations(boolean var1)
public void storeBrushConfigSnapshotvoid storeBrushConfigSnapshot(@Nonnull String var1)
public void storeOperatingIndexvoid storeOperatingIndex(String var1, int var2)

Исходный код

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

class="kw">import com.hypixel.hytale.builtin.buildertools.BuilderToolsPlugin;
class="kw">import com.hypixel.hytale.builtin.buildertools.PrototypePlayerBuilderToolSettings;
class="kw">import com.hypixel.hytale.builtin.buildertools.scriptedbrushes.operations.system.GlobalBrushOperation;
class="kw">import com.hypixel.hytale.builtin.buildertools.scriptedbrushes.operations.system.SequenceBrushOperation;
class="kw">import com.hypixel.hytale.builtin.buildertools.tooloperations.ToolOperation;
class="kw">import com.hypixel.hytale.builtin.buildertools.tooloperations.transform.Transform;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.protocol.InteractionType;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.entity.UUIDComponent;
class="kw">import com.hypixel.hytale.server.core.entity.entities.Player;
class="kw">import com.hypixel.hytale.server.core.prefab.selection.standard.BlockSelection;
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 com.hypixel.hytale.server.core.util.message.MessageFormat;
class="kw">import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
class="kw">import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
class="kw">import it.unimi.dsi.fastutil.objects.ObjectArrayList;
class="kw">import java.util.List;
class="kw">import java.util.Locale;
class="kw">import java.util.Map;
class="kw">import java.util.Set;
class="kw">import java.util.function.Consumer;
class="kw">import java.util.logging.Level;
class="kw">import java.util.stream.Collectors;
class="kw">import javax.annotation.Nonnull;
class="kw">import javax.annotation.Nullable;
class="kw">import org.joml.Vector3i;

class="kw">public class BrushConfigCommandExecutor {
   class="kw">private class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
   @Nonnull
   class="kw">private class="kw">final Map<String, Integer> persistentStoredVariables;
   class="kw">private class="kw">final BrushConfig brushConfig;
   @Nonnull
   class="kw">private class="kw">final Map<String, GlobalBrushOperation> globalOperations;
   class="kw">private int currentOperationIndex = 0;
   @Nonnull
   class="kw">private class="kw">final List<SequenceBrushOperation> sequentialOperations;
   class="kw">private boolean inDebugSteppingMode;
   class="kw">private boolean printOperations;
   class="kw">private boolean enableBreakpoints;
   class="kw">private BrushConfigCommandExecutor.DebugOutputTarget debugOutputTarget = BrushConfigCommandExecutor.DebugOutputTarget.Chat;
   class="kw">private boolean breakOnError;
   class="kw">private Vector3i transformVector = new Vector3i();
   @Nonnull
   class="kw">private class="kw">final Map<String, BrushConfig> brushConfigStoredSnapshots;
   class="kw">private boolean allowOverwritingSavedSnapshots = true;
   @Nonnull
   class="kw">private class="kw">final Map<String, Integer> storedIndexes;
   class="kw">private boolean ignoreExistingBrushData;
   class="kw">private BrushConfigEditStore edit;
   class="kw">private long startTime;

   class="kw">public BrushConfigCommandExecutor(BrushConfig var1) {
      this.persistentStoredVariables = new Object2IntOpenHashMap();
      this.sequentialOperations = new ObjectArrayList();
      this.globalOperations = new Object2ObjectOpenHashMap();
      this.brushConfigStoredSnapshots = new Object2ObjectOpenHashMap();
      this.storedIndexes = new Object2IntOpenHashMap();
      this.brushConfig = var1;
   }

   class="kw">public void resetInternalState() {
      this.currentOperationIndex = 0;
      this.brushConfigStoredSnapshots.clear();
      this.ignoreExistingBrushData = false;
      this.printOperations = false;
      this.inDebugSteppingMode = false;
      this.enableBreakpoints = false;
      this.debugOutputTarget = BrushConfigCommandExecutor.DebugOutputTarget.Chat;
      this.breakOnError = false;
      this.startTime = System.nanoTime();
      this.storedIndexes.clear();
   }

   class="kw">public void execute(
      @Nonnull Ref<EntityStore> var1,
      @Nonnull World var2,
      @Nonnull Vector3i var3,
      boolean var4,
      @Nonnull InteractionType var5,
      @Nullable Consumer<BrushConfig> var6,
      @Nonnull ComponentAccessor<EntityStore> var7
   ) {
      Player var8 = var7.getComponent(var1, Player.getComponentType());
      assert var8 != null;
      PlayerRef var9 = var7.getComponent(var1, PlayerRef.getComponentType());
      assert var9 != null;
      UUIDComponent var10 = var7.getComponent(var1, UUIDComponent.getComponentType());
      assert var10 != null;
      this.resetInternalState();
      this.brushConfig.resetToDefaultValues();
      this.brushConfig.beginExecution(var3, var4, var5);
      PrototypePlayerBuilderToolSettings var11 = ToolOperation.PROTOTYPE_TOOL_SETTINGS.get(var10.getUuid());
      if (!var4) {
         var11.getIgnoredPaintOperations().clear();
      }

      BuilderToolsPlugin.BuilderState var12 = BuilderToolsPlugin.getState(var8, var9);
      BlockSelection var13 = BuilderToolsPlugin.getMaskSelection(var12.getSelection());
      Vector3i var14 = var13 == null ? null : var13.getSelectionMin();
      Vector3i var15 = var13 == null ? null : var13.getSelectionMax();
      this.edit = new BrushConfigEditStore(var11.addIgnoredPaintOperation(), this.brushConfig, var2, var14, var15);

      for (int var16 = 0; var16 < this.sequentialOperations.size(); var16++) {
         this.sequentialOperations.get(var16).resetInternalState();
         this.sequentialOperations.get(var16).preExecutionModifyBrushConfig(this, var16);
      }

      for (GlobalBrushOperation var17 : this.globalOperations.values()) {
         var17.resetInternalState();
         var17.modifyBrushConfig(var1, this.brushConfig, this, var7);
      }

      if (!this.ignoreExistingBrushData && var6 != null) {
         var6.accept(this.brushConfig);
      }

      if (!this.inDebugSteppingMode) {
         while (
            this.brushConfig.isCurrentlyExecuting() && !this.inDebugSteppingMode && this.step(var1, false, var7).equals(BrushConfig.BCExecutionStatus.Continue)
         ) {
         }
      }
   }

   class="kw">public void execute(@Nonnull Ref<EntityStore> var1, World var2, Vector3i var3, boolean var4, InteractionType var5, ComponentAccessor<EntityStore> var6) {
      this.execute(var1, var2, var3, var4, var5, null, var6);
   }

   @Nonnull
   class="kw">public BrushConfig.BCExecutionStatus step(Ref<EntityStore> var1, boolean var2, ComponentAccessor<EntityStore> var3) {
      if (!this.brushConfig.isCurrentlyExecuting()) {
         class="kw">return BrushConfig.BCExecutionStatus.Error;
      }

      if (this.sequentialOperations.isEmpty()) {
         this.brushConfig.setErrorFlag("No operations to execute");
         class="kw">return this.completeStep(var1, var2, var3);
      }

      try {
         SequenceBrushOperation var4 = this.sequentialOperations.get(this.currentOperationIndex);
         if (this.printOperations) {
            LOGGER.at(Level.INFO).log("[%d] %s", this.currentOperationIndex, var4.getName());
            PlayerRef var5 = var3.getComponent(var1, PlayerRef.getComponentType());
            if (var5 != null) {
               var5.sendMessage(
                  Message.translation("server.builderTools.brushConfig.debug.operationExecuting")
                     .param("index", this.currentOperationIndex)
                     .param("name", var4.getName())
               );
            }
         }

         var4.modifyBrushConfig(var1, this.brushConfig, this, var3);
         if (this.brushConfig.isHasExecutionContextEncounteredError() || !var4.doesOperateOnBlocks()) {
            class="kw">return this.completeStep(var1, var2, var3);
         }

         int var8 = var4.getNumModifyBlockIterations();

         for (int var6 = 0; var6 < var8; var6++) {
            var4.beginIterationIndex(var6);
            ToolOperation.executeShapeOperation(
               this.brushConfig.getOriginAfterOffset().x,
               this.brushConfig.getOriginAfterOffset().y,
               this.brushConfig.getOriginAfterOffset().z,
               (var4x, var5x, var6x, var7x) -> {
                  Transform var8 = this.brushConfig.getTransform();
                  Vector3i var9 = this.brushConfig.getTransformOrigin();
                  this.transformVector.x = var4x - var9.x;
                  this.transformVector.y = var5x - var9.y;
                  this.transformVector.z = var6x - var9.z;
                  var8.apply(this.transformVector);
                  var4x = var9.x + this.transformVector.x;
                  var5x = var9.y + this.transformVector.y;
                  var6x = var9.z + this.transformVector.z;
                  class="kw">return var4.modifyBlocks(var1, this.brushConfig, this, this.edit, var4x, var5x, var6x, var3);
               },
               this.brushConfig.getShape(),
               this.brushConfig.getShapeWidth(),
               this.brushConfig.getShapeHeight(),
               this.brushConfig.getShapeThickness(),
               this.brushConfig.isCapped()
            );
            this.edit.flushCurrentEditsToPrevious();
         }
      } catch (Exception var7) {
         var7.printStackTrace();
         this.brushConfig.setErrorFlag(var7.getMessage());
      }

      class="kw">return this.completeStep(var1, var2, var3);
   }

   @Nonnull
   class="kw">private BrushConfig.BCExecutionStatus completeStep(Ref<EntityStore> var1, boolean var2, ComponentAccessor<EntityStore> var3) {
      if (this.brushConfig.isHasExecutionContextEncounteredError()) {
         if (this.breakOnError) {
            PlayerRef var7 = var3.getComponent(var1, PlayerRef.getComponentType());
            if (var7 != null) {
               var7.sendMessage(Message.translation("server.builderTools.brushConfig.debug.breakOnErrorTriggered").param("index", this.currentOperationIndex));
            }

            LOGGER.at(Level.INFO).log("[Breakpoint] Error at operation #%d - Entering step-through mode", this.currentOperationIndex);
            this.inDebugSteppingMode = true;
            this.brushConfig.clearError();
            class="kw">return BrushConfig.BCExecutionStatus.Continue;
         } else {
            this.exitExecution(var1, var3);
            class="kw">return BrushConfig.BCExecutionStatus.Error;
         }
      } else {
         this.currentOperationIndex++;
         if (this.currentOperationIndex >= this.sequentialOperations.size()) {
            this.exitExecution(var1, var3);
            class="kw">return BrushConfig.BCExecutionStatus.Complete;
         }

         Player var4 = var3.getComponent(var1, Player.getComponentType());
         assert var4 != null;
         PlayerRef var5 = var3.getComponent(var1, PlayerRef.getComponentType());
         assert var5 != null;
         if (var2) {
            BrushConfigEditStore var6 = this.edit;
            BuilderToolsPlugin.getState(var4, var5).addToQueue((var2x, var3x, var4x) -> var3x.placeBrushConfig(var2x, this.startTime, var6, var4x));
         }

         class="kw">return BrushConfig.BCExecutionStatus.Continue;
      }
   }

   class="kw">public void exitExecution(Ref<EntityStore> var1, ComponentAccessor<EntityStore> var2) {
      Player var3 = var2.getComponent(var1, Player.getComponentType());
      assert var3 != null;
      PlayerRef var4 = var2.getComponent(var1, PlayerRef.getComponentType());
      assert var4 != null;
      if (this.brushConfig.isHasExecutionContextEncounteredError() && this.currentOperationIndex < this.sequentialOperations.size()) {
         this.sendExecutionErrorMessage(var4, this.sequentialOperations.get(this.currentOperationIndex));
      }

      if (this.currentOperationIndex != 0) {
         BrushConfigEditStore var5 = this.edit;
         BuilderToolsPlugin.getState(var3, var4).addToQueue((var2x, var3x, var4x) -> var3x.placeBrushConfig(var2x, this.startTime, var5, var4x));
      }

      this.brushConfig.endExecution();
   }

   class="kw">private void sendExecutionErrorMessage(PlayerRef var1, @Nonnull SequenceBrushOperation var2) {
      var1.sendMessage(
         Message.translation("server.builderTools.brushConfig.executionError")
            .param("index", this.currentOperationIndex)
            .param("type", var2.getName())
            .param("error", this.brushConfig.getExecutionErrorMessage())
      );
      Message var3 = Message.translation("server.builderTools.brushConfig.settings.header");
      Set var4 = var2.getRegisteredOperationSettings()
         .values()
         .stream()
         .map(var0 -> Message.translation("server.builderTools.brushConfig.settings.item").param("name", var0.getName()).param("value", var0.getValueString()))
         .collect(Collectors.toSet());
      var1.sendMessage(MessageFormat.list(var3, var4));
   }

   class="kw">public void storeOperatingIndex(String var1, int var2) {
      var1 = var1.toLowerCase(Locale.ROOT);
      if (this.storedIndexes.containsKey(var1)) {
         this.brushConfig.setErrorFlag("You already have a stored index with the name: '" + var1 + "'.");
      } else if (var2 >= this.sequentialOperations.size()) {
         this.brushConfig
            .setErrorFlag("Tried to store an index greater than the total size of sequential operations. Name: '" + var1 + "', index: '" + var2 + "'.");
      } else {
         this.storedIndexes.put(var1, var2);
      }
   }

   class="kw">public void loadOperatingIndex(String var1) {
      this.loadOperatingIndex(var1, true);
   }

   class="kw">public void loadOperatingIndex(String var1, boolean var2) {
      var1 = var1.toLowerCase(Locale.ROOT);
      if (!this.storedIndexes.containsKey(var1)) {
         this.brushConfig.setErrorFlag("Could not find a stored index with the name: '" + var1 + "'.");
      } else {
         int var3 = this.storedIndexes.get(var1);
         if (!var2 && var3 > this.currentOperationIndex) {
            this.brushConfig.setErrorFlag("This operation does not allow you to jump to an operation in the future, only the past. Index name: " + var1 + "'.");
         } else {
            this.currentOperationIndex = var3;
         }
      }
   }

   class="kw">public void clearAllPersistentVariables() {
      this.persistentStoredVariables.clear();
   }

   class="kw">public void clearPersistentVariable(String var1) {
      var1 = var1.toLowerCase(Locale.ROOT);
      if (!this.persistentStoredVariables.containsKey(var1)) {
         this.brushConfig.setErrorFlag("Could not find a stored persistent variable with the name: '" + var1 + "'.");
      } else {
         this.persistentStoredVariables.remove(var1);
      }
   }

   class="kw">public void setPersistentVariable(String var1, int var2) {
      var1 = var1.toLowerCase(Locale.ROOT);
      this.persistentStoredVariables.put(var1, var2);
   }

   class="kw">public int getPersistentVariableOrDefault(String var1, int var2) {
      var1 = var1.toLowerCase(Locale.ROOT);
      class="kw">return !this.persistentStoredVariables.containsKey(var1) ? var2 : this.persistentStoredVariables.get(var1);
   }

   class="kw">public void storeBrushConfigSnapshot(@Nonnull String var1) {
      this.brushConfigStoredSnapshots.put(var1.toLowerCase(Locale.ROOT), new BrushConfig(this.brushConfig));
   }

   class="kw">public void loadBrushConfigSnapshot(String var1, @Nonnull BrushConfig.DataSettingFlags... var2) {
      var1 = var1.toLowerCase(Locale.ROOT);
      if (!this.brushConfigStoredSnapshots.containsKey(var1)) {
         this.brushConfig.setErrorFlag("Could not find a stored brush config snapshot with the name: '" + var1 + "'.");
      } else {
         BrushConfig var3 = this.brushConfigStoredSnapshots.get(var1);

         for (BrushConfig.DataSettingFlags var7 : var2) {
            var7.loadData(this.brushConfig, var3);
         }
      }
   }

   class="kw">public void setAllowOverwritingSavedSnapshots(boolean var1) {
      this.allowOverwritingSavedSnapshots = var1;
   }

   @Nonnull
   class="kw">public List<SequenceBrushOperation> getSequentialOperations() {
      class="kw">return this.sequentialOperations;
   }

   @Nonnull
   class="kw">public Map<String, GlobalBrushOperation> getGlobalOperations() {
      class="kw">return this.globalOperations;
   }

   class="kw">public boolean isIgnoreExistingBrushData() {
      class="kw">return this.ignoreExistingBrushData;
   }

   class="kw">public boolean isInDebugSteppingMode() {
      class="kw">return this.inDebugSteppingMode;
   }

   class="kw">public BrushConfigEditStore getEdit() {
      class="kw">return this.edit;
   }

   class="kw">public void setInDebugSteppingMode(boolean var1) {
      this.inDebugSteppingMode = var1;
   }

   class="kw">public void setPrintOperations(boolean var1) {
      this.printOperations = var1;
   }

   class="kw">public void setIgnoreExistingBrushData(boolean var1) {
      this.ignoreExistingBrushData = var1;
   }

   class="kw">public void setCurrentlyExecutingActionIndex(int var1) {
      if (var1 < 0) {
         this.brushConfig.setErrorFlag("Cannot set a negative operation index: " + var1);
      } else if (var1 >= this.sequentialOperations.size()) {
         this.brushConfig
            .setErrorFlag(
               "Cannot set an operation index higher than the highest operation index: "
                  + var1
                  + ". Highest operation index: "
                  + (this.sequentialOperations.size() - 1)
            );
      } else {
         this.currentOperationIndex = var1 - 1;
      }
   }

   class="kw">public int getCurrentOperationIndex() {
      class="kw">return this.currentOperationIndex;
   }

   class="kw">public boolean isEnableBreakpoints() {
      class="kw">return this.enableBreakpoints;
   }

   class="kw">public void setEnableBreakpoints(boolean var1) {
      this.enableBreakpoints = var1;
   }

   class="kw">public BrushConfigCommandExecutor.DebugOutputTarget getDebugOutputTarget() {
      class="kw">return this.debugOutputTarget;
   }

   class="kw">public void setDebugOutputTarget(BrushConfigCommandExecutor.DebugOutputTarget var1) {
      this.debugOutputTarget = var1;
   }

   class="kw">public boolean isBreakOnError() {
      class="kw">return this.breakOnError;
   }

   class="kw">public void setBreakOnError(boolean var1) {
      this.breakOnError = var1;
   }

   class="kw">public enum DebugOutputTarget {
      Chat,
      Console,
      Both;

      DebugOutputTarget() {
      }
   }
}