/*
 * This file is a part of the SteamWar software.
 *
 * Copyright (C) 2020  SteamWar.de-Serverteam
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

package de.steamwar.bausystem.commands;

import de.steamwar.bausystem.BauSystem;
import de.steamwar.bausystem.Permission;
import de.steamwar.bausystem.SWUtils;
import de.steamwar.bausystem.world.Detonator;
import de.steamwar.bausystem.world.Welt;
import de.steamwar.command.SWCommand;
import org.bukkit.entity.Player;

public class CommandDetonator extends SWCommand {

    public CommandDetonator() {
        super ("detonator", "dt");
    }

    @Register(help = true)
    public void genericHelp(Player p, String... args) {
        p.sendMessage("§8/§edetonator wand §8- §7Legt den Fernzünder ins Inventar");
        p.sendMessage("§8/§edetonator detonate §8- §7Benutzt den nächst besten Fernzünder");
        p.sendMessage("§8/§edetonator reset §8- §7Löscht alle markierten Positionen");
        p.sendMessage("§8/§edetonator remove §8- §7Entfernt den Fernzünder");
    }

    @Register("wand")
    public void wandCommand(Player p) {
        if (!permissionCheck(p)) return;
        SWUtils.giveItemToPlayer(p, Detonator.WAND);
    }

    @Register("detonator")
    public void detonatorCommand(Player p) {
        if (!permissionCheck(p)) return;
        SWUtils.giveItemToPlayer(p, Detonator.WAND);
    }

    @Register("item")
    public void itemCommand(Player p) {
        if (!permissionCheck(p)) return;
        SWUtils.giveItemToPlayer(p, Detonator.WAND);
    }


    @Register("remove")
    public void removeCommand(Player p) {
        if (!permissionCheck(p)) return;
        p.getInventory().removeItem(Detonator.WAND);
    }


    @Register("detonate")
    public void detonateCommand(Player p) {
        if (!permissionCheck(p)) return;
        Detonator.execute(p);
    }

    @Register("click")
    public void clickCommand(Player p) {
        if (!permissionCheck(p)) return;
        Detonator.execute(p);
    }

    @Register("use")
    public void useCommand(Player p) {
        if (!permissionCheck(p)) return;
        Detonator.execute(p);
    }


    @Register("clear")
    public void clearCommand(Player p) {
        if (!permissionCheck(p)) return;
        Detonator.clear(p);
    }

    @Register("delete")
    public void deleteCommand(Player p) {
        if (!permissionCheck(p)) return;
        Detonator.clear(p);
    }

    @Register("reset")
    public void resetCommand(Player p) {
        if (!permissionCheck(p)) return;
        Detonator.clear(p);
    }

    private boolean permissionCheck(Player player) {
        if (Welt.noPermission(player, Permission.WORLD)) {
            player.sendMessage(BauSystem.PREFIX + "§cDu darfst hier nicht den Detonator nutzen");
            return false;
        }
        return true;
    }
}