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

package com.hypixel.hytale.builtin.portals.commands.player;

import com.hypixel.hytale.component.ComponentAccessor;
import com.hypixel.hytale.builtin.instances.InstancesPlugin;
import com.hypixel.hytale.server.core.inventory.container.ItemContainer;
import com.hypixel.hytale.builtin.portals.utils.CursedItems;
import com.hypixel.hytale.builtin.portals.resources.PortalWorld;
import com.hypixel.hytale.server.core.entity.entities.Player;
import com.hypixel.hytale.server.core.universe.world.World;
import com.hypixel.hytale.server.core.universe.PlayerRef;
import com.hypixel.hytale.component.Ref;
import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
import com.hypixel.hytale.component.Store;
import com.hypixel.hytale.server.core.command.system.CommandContext;
import javax.annotation.Nonnull;
import com.hypixel.hytale.server.core.Message;
import com.hypixel.hytale.server.core.command.system.basecommands.AbstractPlayerCommand;

public class LeaveCommand extends AbstractPlayerCommand
{
    @Nonnull
    private static final Message MESSAGE_COMMANDS_LEAVE_NOT_IN_PORTAL;
    @Nonnull
    private static final Message MESSAGE_COMMANDS_LEAVE_UNCURSED_TEMP;
    
    public LeaveCommand() {
        super("leave", "server.commands.leave.desc");
    }
    
    @Override
    protected void execute(@Nonnull final CommandContext context, @Nonnull final Store<EntityStore> store, @Nonnull final Ref<EntityStore> ref, @Nonnull final PlayerRef playerRef, @Nonnull final World world) {
        final Player playerComponent = store.getComponent(ref, Player.getComponentType());
        assert playerComponent != null;
        final PortalWorld portalWorldResource = store.getResource(PortalWorld.getResourceType());
        if (!portalWorldResource.exists()) {
            playerRef.sendMessage(LeaveCommand.MESSAGE_COMMANDS_LEAVE_NOT_IN_PORTAL);
            return;
        }
        final boolean uncursedAny = CursedItems.uncurseAll(playerComponent.getInventory().getCombinedEverything());
        if (uncursedAny) {
            playerRef.sendMessage(LeaveCommand.MESSAGE_COMMANDS_LEAVE_UNCURSED_TEMP);
        }
        InstancesPlugin.exitInstance(ref, store);
    }
    
    static {
        MESSAGE_COMMANDS_LEAVE_NOT_IN_PORTAL = Message.translation("server.commands.leave.notInPortal");
        MESSAGE_COMMANDS_LEAVE_UNCURSED_TEMP = Message.translation("server.commands.leave.uncursedTemp").color("#d955ef");
    }
}
