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

package com.hypixel.hytale.server.core.modules.prefabspawner.commands;

import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.prefab.PrefabWeights;
import com.hypixel.hytale.server.core.modules.prefabspawner.PrefabSpawnerState;
import com.hypixel.hytale.server.core.universe.world.chunk.WorldChunk;
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 javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;

public class PrefabSpawnerWeightCommand extends TargetPrefabSpawnerCommand
{
    @Nonnull
    private final RequiredArg<String> prefabArg;
    @Nonnull
    private final RequiredArg<Float> weightArg;
    
    public PrefabSpawnerWeightCommand() {
        super("weight", "server.commands.prefabspawner.weight.desc");
        this.prefabArg = this.withRequiredArg("prefab", "server.commands.prefabspawner.weight.prefab.desc", ArgTypes.STRING);
        this.weightArg = this.withRequiredArg("weight", "server.commands.prefabspawner.weight.weight.desc", ArgTypes.FLOAT);
    }
    
    @Override
    protected void execute(@Nonnull final CommandContext context, @Nonnull final WorldChunk chunk, @Nonnull final PrefabSpawnerState prefabSpawner) {
        final String prefab = this.prefabArg.get(context);
        final Float weight = this.weightArg.get(context);
        PrefabWeights prefabWeights = prefabSpawner.getPrefabWeights();
        if (prefabWeights == PrefabWeights.NONE) {
            prefabWeights = new PrefabWeights();
        }
        if (weight < 0.0f) {
            prefabWeights.removeWeight(prefab);
            context.sendMessage(Message.translation("server.commands.prefabspawner.weight.remove").param("prefab", prefab));
        }
        else {
            prefabWeights.setWeight(prefab, weight);
            context.sendMessage(Message.translation("server.commands.prefabspawner.weight.set").param("prefab", prefab).param("weight", weight));
        }
        prefabSpawner.setPrefabWeights(prefabWeights);
        chunk.markNeedsSaving();
    }
}
