package de.iani.cubequest.commands;

import de.iani.cubequest.CubeQuest;
import de.iani.cubequest.quests.InteractorQuest;
import de.iani.cubequest.quests.Quest;
import de.iani.cubequest.quests.QuestType;
import de.iani.cubequest.util.ChatAndTextUtil;
import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;

public class CreateQuestCommand extends SubCommand {
    
    public static final String COMMAND_PATH = "create";
    public static final String FULL_COMMAND = "quest " + COMMAND_PATH;
    
    @Override
    public boolean onCommand(CommandSender sender, Command command, String alias,
            String commandString, ArgsParser args) {
        
        if (!args.hasNext()) {
            ChatAndTextUtil.sendWarningMessage(sender, "Bitte gib einen Quest-Typ an.");
            return true;
        }
        
        String typeString = args.getNext();
        QuestType type;
        try {
            type = QuestType.valueOf(typeString);
        } catch (IllegalArgumentException e) {
            ChatAndTextUtil.sendWarningMessage(sender, "Unbekannter Quest-Typ " + typeString + ".");
            return true;
        }
        
        Class<? extends Quest> questClass = type.questClass;
        if (InteractorQuest.class.isAssignableFrom(questClass)
                && !CubeQuest.getInstance().hasCitizensPlugin()) {
            ChatAndTextUtil.sendErrorMessage(sender,
                    "NPC-Quests können nur auf Servern ertellt werden, auf denen das Citizens-Plugin installiert ist.");
            return true;
        }
        
        Quest quest = CubeQuest.getInstance().getQuestCreator().createQuest(questClass);
        
        int id = quest.getId();
        ChatAndTextUtil.sendNormalMessage(sender,
                type + " mit Quest-ID " + id + " erfolgreich erstellt.");
        CubeQuest.getInstance().getQuestEditor().startEdit(sender, quest);
        
        return true;
    }
    
    @Override
    public String getRequiredPermission() {
        return CubeQuest.EDIT_QUESTS_PERMISSION;
    }
    
    @Override
    public List<String> onTabComplete(CommandSender sender, Command command, String alias,
            ArgsParser args) {
        List<String> result = new ArrayList<>();
        
        for (QuestType type : QuestType.values()) {
            result.add(type.name());
        }
        
        return ChatAndTextUtil.polishTabCompleteList(result, args.getNext(""));
    }
    
    @Override
    public String getUsage() {
        return "<QuestType>";
    }
    
}

@@ -73,58 +73,8 @@
 t;%0D%0A
-import de.iani.cubequest.quests.InteractorQuest;%0D%0A
 impo
@@ -1259,363 +1259,8 @@
 s;%0D%0A
-        if (InteractorQuest.class.isAssignableFrom(questClass)%0D%0A                && !CubeQuest.getInstance().hasCitizensPlugin()) %7B%0D%0A            ChatAndTextUtil.sendErrorMessage(sender,%0D%0A                    %22NPC-Quests k%C3%B6nnen nur auf Servern ertellt werden, auf denen das Citizens-Plugin installiert ist.%22);%0D%0A            return true;%0D%0A        %7D%0D%0A        %0D%0A
     

Remove error message when creating InteractInteractorQuest on server without citizens.