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

package com.hypixel.hytale.builtin.parkour.commands;

import com.hypixel.hytale.component.Ref;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import com.hypixel.hytale.component.RemoveReason;
import java.util.UUID;
import com.hypixel.hytale.builtin.parkour.ParkourPlugin;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgumentType;
import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractWorldCommand;

public class CheckpointRemoveCommand extends AbstractWorldCommand
{
    @Nonnull
    private static final Message MESSAGE_COMMANDS_CHECKPOINT_REMOVE_FAILED;
    @Nonnull
    private static final Message MESSAGE_COMMANDS_CHECKPOINT_REMOVE_SUCCESS;
    @Nonnull
    private final RequiredArg<Integer> indexArg;
    
    public CheckpointRemoveCommand() {
        super("remove", "server.commands.checkpoint.remove.desc");
        this.indexArg = this.withRequiredArg("index", "server.commands.checkpoint.remove.index.desc", ArgTypes.INTEGER);
    }
    
    @Override
    protected void execute(@Nonnull final CommandContext context, @Nonnull final World world, @Nonnull final Store<EntityStore> store) {
        final int index = this.indexArg.get(context);
        final Int2ObjectMap<UUID> checkpointUUIDMap = ParkourPlugin.get().getCheckpointUUIDMap();
        final UUID uuid = checkpointUUIDMap.get(index);
        if (uuid == null) {
            context.sendMessage(CheckpointRemoveCommand.MESSAGE_COMMANDS_CHECKPOINT_REMOVE_FAILED);
            return;
        }
        final Ref<EntityStore> ref = store.getExternalData().getRefFromUUID(uuid);
        if (ref == null || !ref.isValid()) {
            context.sendMessage(CheckpointRemoveCommand.MESSAGE_COMMANDS_CHECKPOINT_REMOVE_FAILED);
            return;
        }
        store.removeEntity(ref, RemoveReason.REMOVE);
        checkpointUUIDMap.remove(index);
        ParkourPlugin.get().updateLastIndex();
        context.sendMessage(CheckpointRemoveCommand.MESSAGE_COMMANDS_CHECKPOINT_REMOVE_SUCCESS);
    }
    
    static {
        MESSAGE_COMMANDS_CHECKPOINT_REMOVE_FAILED = Message.translation("server.commands.checkpoint.remove.failed");
        MESSAGE_COMMANDS_CHECKPOINT_REMOVE_SUCCESS = Message.translation("server.commands.checkpoint.remove.success");
    }
}
