// 
// Decompiled by Procyon v0.6.0
// 

package com.hypixel.hytale.builtin.buildertools;

import com.hypixel.hytale.builtin.buildertools.tooloperations.ToolOperation;
import com.hypixel.hytale.server.core.entity.UUIDComponent;
import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Ref;
import java.util.Iterator;
import com.hypixel.hytale.math.block.BlockUtil;
import com.hypixel.hytale.math.vector.Vector3i;
import javax.annotation.Nullable;
import com.hypixel.hytale.protocol.packets.interface_.BlockChange;
import com.hypixel.hytale.builtin.buildertools.scriptedbrushes.BrushConfigCommandExecutor;
import com.hypixel.hytale.builtin.buildertools.scriptedbrushes.BrushConfig;
import it.unimi.dsi.fastutil.longs.LongOpenHashSet;
import java.util.LinkedList;
import java.util.UUID;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.Message;

public class PrototypePlayerBuilderToolSettings
{
    @Nonnull
    private static final Message MESSAGE_BUILDER_TOOLS_CANNOT_PERFORM_COMMAND_IN_TRANSFORMATION_MODE;
    private final UUID player;
    private final LinkedList<LongOpenHashSet> ignoredPaintOperations;
    private int maxLengthOfIgnoredPaintOperations;
    private boolean shouldShowEditorSettings;
    private boolean isLoadingBrush;
    private boolean usePrototypeBrushConfigurations;
    private String currentlyLoadedBrushConfigName;
    private BrushConfig brushConfig;
    private BrushConfigCommandExecutor brushConfigCommandExecutor;
    private boolean isInSelectionTransformationMode;
    @Nullable
    private BlockChange[] blockChangesForPlaySelectionToolPasteMode;
    @Nullable
    private FluidChange[] fluidChangesForPlaySelectionToolPasteMode;
    @Nullable
    private Vector3i lastBrushPosition;
    @Nullable
    private Vector3i blockChangeOffsetOrigin;
    
    public PrototypePlayerBuilderToolSettings(final UUID player) {
        this.ignoredPaintOperations = new LinkedList<LongOpenHashSet>();
        this.currentlyLoadedBrushConfigName = "";
        this.brushConfig = new BrushConfig();
        this.isInSelectionTransformationMode = false;
        this.blockChangesForPlaySelectionToolPasteMode = null;
        this.fluidChangesForPlaySelectionToolPasteMode = null;
        this.lastBrushPosition = null;
        this.blockChangeOffsetOrigin = null;
        this.player = player;
        this.brushConfigCommandExecutor = new BrushConfigCommandExecutor(this.brushConfig);
    }
    
    public UUID getPlayer() {
        return this.player;
    }
    
    public boolean isInSelectionTransformationMode() {
        return this.isInSelectionTransformationMode;
    }
    
    public void setInSelectionTransformationMode(final boolean inSelectionTransformationMode) {
        if (!(this.isInSelectionTransformationMode = inSelectionTransformationMode)) {
            this.blockChangesForPlaySelectionToolPasteMode = null;
            this.fluidChangesForPlaySelectionToolPasteMode = null;
            this.blockChangeOffsetOrigin = null;
        }
    }
    
    public void setBlockChangesForPlaySelectionToolPasteMode(@Nullable final BlockChange[] blockChangesForPlaySelectionToolPasteMode) {
        this.blockChangesForPlaySelectionToolPasteMode = blockChangesForPlaySelectionToolPasteMode;
    }
    
    public String getCurrentlyLoadedBrushConfigName() {
        return this.currentlyLoadedBrushConfigName;
    }
    
    public void setCurrentlyLoadedBrushConfigName(final String currentlyLoadedBrushConfigName) {
        this.currentlyLoadedBrushConfigName = currentlyLoadedBrushConfigName;
    }
    
    public boolean isLoadingBrush() {
        return this.isLoadingBrush;
    }
    
    public void setLoadingBrush(final boolean loadingBrush) {
        this.isLoadingBrush = loadingBrush;
    }
    
    @Nullable
    public BlockChange[] getBlockChangesForPlaySelectionToolPasteMode() {
        return this.blockChangesForPlaySelectionToolPasteMode;
    }
    
    public void setFluidChangesForPlaySelectionToolPasteMode(@Nullable final FluidChange[] fluidChanges) {
        this.fluidChangesForPlaySelectionToolPasteMode = fluidChanges;
    }
    
    @Nullable
    public FluidChange[] getFluidChangesForPlaySelectionToolPasteMode() {
        return this.fluidChangesForPlaySelectionToolPasteMode;
    }
    
    public void setBlockChangeOffsetOrigin(@Nullable final Vector3i blockChangeOffsetOrigin) {
        this.blockChangeOffsetOrigin = blockChangeOffsetOrigin;
    }
    
    @Nullable
    public Vector3i getBlockChangeOffsetOrigin() {
        return this.blockChangeOffsetOrigin;
    }
    
    @Nonnull
    public LongOpenHashSet addIgnoredPaintOperation() {
        final LongOpenHashSet longs = new LongOpenHashSet();
        this.ignoredPaintOperations.add(longs);
        this.clearHistoryUntilFitMaxLength();
        return longs;
    }
    
    public void clearHistoryUntilFitMaxLength() {
        while (this.ignoredPaintOperations.size() > this.maxLengthOfIgnoredPaintOperations) {
            this.ignoredPaintOperations.removeFirst();
        }
    }
    
    public boolean containsLocation(final int x, final int y, final int z) {
        final long packedBlockLocation = BlockUtil.pack(x, y, z);
        for (final LongOpenHashSet locations : this.ignoredPaintOperations) {
            if (locations.contains(packedBlockLocation)) {
                return true;
            }
        }
        return false;
    }
    
    @Nonnull
    public LinkedList<LongOpenHashSet> getIgnoredPaintOperations() {
        return this.ignoredPaintOperations;
    }
    
    public int getMaxLengthOfIgnoredPaintOperations() {
        return this.maxLengthOfIgnoredPaintOperations;
    }
    
    public void setMaxLengthOfIgnoredPaintOperations(final int maxLengthOfIgnoredPaintOperations) {
        this.maxLengthOfIgnoredPaintOperations = maxLengthOfIgnoredPaintOperations;
        this.clearHistoryUntilFitMaxLength();
    }
    
    public boolean usePrototypeBrushConfigurations() {
        return this.usePrototypeBrushConfigurations;
    }
    
    public void setUsePrototypeBrushConfigurations(final boolean usePrototypeBrushConfigurations) {
        this.usePrototypeBrushConfigurations = usePrototypeBrushConfigurations;
    }
    
    public BrushConfig getBrushConfig() {
        return this.brushConfig;
    }
    
    public BrushConfigCommandExecutor getBrushConfigCommandExecutor() {
        return this.brushConfigCommandExecutor;
    }
    
    public void setBrushConfig(final BrushConfig brushConfig) {
        this.brushConfig = brushConfig;
    }
    
    public boolean isShouldShowEditorSettings() {
        return this.shouldShowEditorSettings;
    }
    
    public void setShouldShowEditorSettings(final boolean shouldShowEditorSettings) {
        this.shouldShowEditorSettings = shouldShowEditorSettings;
    }
    
    @Nullable
    public Vector3i getLastBrushPosition() {
        return this.lastBrushPosition;
    }
    
    public void setLastBrushPosition(@Nullable final Vector3i lastBrushPosition) {
        this.lastBrushPosition = lastBrushPosition;
    }
    
    public void clearLastBrushPosition() {
        this.lastBrushPosition = null;
    }
    
    public static boolean isOkayToDoCommandsOnSelection(final Ref<EntityStore> ref, @Nonnull final Player player, final ComponentAccessor<EntityStore> componentAccessor) {
        final UUIDComponent uuidComponent = componentAccessor.getComponent(ref, UUIDComponent.getComponentType());
        assert uuidComponent != null;
        final PrototypePlayerBuilderToolSettings prototypeSettings = ToolOperation.getOrCreatePrototypeSettings(uuidComponent.getUuid());
        if (prototypeSettings.isInSelectionTransformationMode()) {
            player.sendMessage(PrototypePlayerBuilderToolSettings.MESSAGE_BUILDER_TOOLS_CANNOT_PERFORM_COMMAND_IN_TRANSFORMATION_MODE);
            return false;
        }
        return true;
    }
    
    static {
        MESSAGE_BUILDER_TOOLS_CANNOT_PERFORM_COMMAND_IN_TRANSFORMATION_MODE = Message.translation("server.builderTools.cannotPerformCommandInTransformationMode");
    }
    
    record FluidChange(int x, int y, int z, int fluidId, byte fluidLevel) {}
}
