001package net.tnemc.item.example.command;
002/*
003 * The New Economy
004 * Copyright (C) 2025 Daniel "creatorfromhell" Vidmar
005 *
006 * This program is free software: you can redistribute it and/or modify
007 * it under the terms of the GNU Affero General Public License as published by
008 * the Free Software Foundation, either version 3 of the License, or
009 * (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
014 * GNU Affero General Public License for more details.
015 *
016 * You should have received a copy of the GNU Affero General Public License
017 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
018 */
019
020import net.tnemc.item.example.Example;
021import org.bukkit.Bukkit;
022import org.bukkit.ChatColor;
023import org.bukkit.command.Command;
024import org.bukkit.command.CommandExecutor;
025import org.bukkit.command.CommandSender;
026import org.bukkit.entity.Player;
027
028import java.util.Collections;
029
030/**
031 * TNILTakeCommand
032 *
033 * @author creatorfromhell
034 * @since 1.0.0.0
035 */
036public class TNILTakeCommand implements CommandExecutor {
037
038  @Override
039  public boolean onCommand(final CommandSender sender, final Command command, final String label, final String[] args) {
040    if(args.length != 2) {
041      sender.sendMessage(ChatColor.RED + "Usage: /tniltake <player> <amount>");
042      return true;
043    }
044
045    final Player target = Bukkit.getPlayerExact(args[0]);
046    if(target == null) {
047      sender.sendMessage(ChatColor.RED + "Player not found.");
048      return true;
049    }
050
051    final int amount;
052    try {
053      amount = Integer.parseInt(args[1]);
054    } catch (final NumberFormatException e) {
055      sender.sendMessage(ChatColor.RED + "Invalid number.");
056      return true;
057    }
058
059    Example.instance().getPlatform().calculations().takeItems(Collections.singletonList(Example.instance().getItem().amount(2)), target.getInventory());
060    Example.instance().getPlatform().calculations().takeItems(Collections.singletonList(Example.instance().getItem().amount(2)), target.getEnderChest());
061
062    Example.instance().getPlatform().calculations().takeItems(Collections.singletonList(Example.instance().getNexoItem().amount(2)), target.getInventory());
063    Example.instance().getPlatform().calculations().takeItems(Collections.singletonList(Example.instance().getNexoItem().amount(2)), target.getEnderChest());
064    return true;
065  }
066}