<commit_before>/**
 * 
 */
package com.elmakers.mine.bukkit.magic.command;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import com.elmakers.mine.bukkit.block.MaterialAndData;
import com.elmakers.mine.bukkit.utility.NMSUtils;
import de.slikey.effectlib.util.ParticleEffect;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import com.elmakers.mine.bukkit.api.magic.Mage;
import com.elmakers.mine.bukkit.api.magic.MagicAPI;
import com.elmakers.mine.bukkit.api.spell.Spell;
import com.elmakers.mine.bukkit.api.spell.SpellTemplate;
import com.elmakers.mine.bukkit.api.wand.Wand;
import com.elmakers.mine.bukkit.block.MaterialBrush;
import com.elmakers.mine.bukkit.api.magic.Messages;

public class WandCommandExecutor extends MagicTabExecutor {
	
	public WandCommandExecutor(MagicAPI api) {
		super(api);
	}
	
	@Override
	public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
		String commandName = command.getName();
        if (commandName.equalsIgnoreCase("wandp"))
		{
			if (args.length == 0) {
				sender.sendMessage("Usage: /wandp [player] [wand name/command]");
				return true;
			}
			Player player = Bukkit.getPlayer(args[0]);
			if (player == null) {
				sender.sendMessage("Can't find player " + args[0]);
				return true;
			}
			if (!player.isOnline()) {
				sender.sendMessage("Player " + args[0] + " is not online");
				return true;
			}
			String[] args2 = Arrays.copyOfRange(args, 1, args.length);
			return processWandCommand("wandp", sender, player, args2);
		}

		if (commandName.equalsIgnoreCase("wand") && args.length > 0 && args[0].equalsIgnoreCase("list"))
		{
			if (!api.hasPermission(sender, "Magic.commands.wand.list")) {
				sendNoPermission(sender);
				return true;
			}
			onWandList(sender);
			return true;
		}

		// Everything beyond this point is is-game only

		if (!(sender instanceof Player)) {
			return false;
		}
		
		Player player = (Player)sender;
		if (commandName.equalsIgnoreCase("wand"))
		{
			return processWandCommand("wand", sender, player, args);
		}
		
		return false;
	}

	@Override
	public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) {
		List<String> options = new ArrayList<String>();
		
		Player player = (sender instanceof Player) ? (Player)sender : null;

        String permissionKey = "wand";
		if (commandName.contains("wandp"))
		{
            permissionKey = "wandp";
			if (args.length > 0) {
				player = Bukkit.getPlayer(args[0]);
			}
			if (args.length == 1) {
				options.addAll(api.getPlayerNames());
				return options;
			} else if (args.length > 1) {
				args = Arrays.copyOfRange(args, 1, args.length);
			}
		}
		
		if (args.length == 1) {
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "add");
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "remove");
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "name");
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "fill");
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "configure");
            addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "override");
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "organize");
            addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "alphabetize");
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "combine");
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "upgrade");
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "describe");
            addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "enchant");
            addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "unenchant");
            addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "duplicate");
            addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "restore");
            addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "unlock");

            Collection<String> allWands = api.getWandKeys();
			for (String wandKey : allWands) {
				addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".wand.", wandKey, true);
			}
		}
		
		if (args.length == 2) {
			String subCommand = args[0];
			String subCommandPNode = "Magic.commands." + permissionKey + "." + subCommand;
			
			if (!api.hasPermission(sender, subCommandPNode)) {
				return options;
			}
			
			subCommandPNode += ".";
			
			if (subCommand.equalsIgnoreCase("add")) {
				Collection<SpellTemplate> spellList = api.getSpellTemplates();
				for (SpellTemplate spell : spellList) {
					addIfPermissible(sender, options, subCommandPNode, spell.getKey(), true);
				}
				addIfPermissible(sender, options, subCommandPNode, "material", true);
			}
			
			if (subCommand.equalsIgnoreCase("configure")) {
				for (String key : com.elmakers.mine.bukkit.wand.Wand.PROPERTY_KEYS) {
					options.add(key);
				}
			}<commit_msg>Remove wand names from /wand tab-completion (use /mgive instead!)<commit_after>/**
 * 
 */
package com.elmakers.mine.bukkit.magic.command;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import com.elmakers.mine.bukkit.block.MaterialAndData;
import com.elmakers.mine.bukkit.utility.NMSUtils;
import de.slikey.effectlib.util.ParticleEffect;
import org.apache.commons.lang.StringUtils;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.Sound;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemStack;

import com.elmakers.mine.bukkit.api.magic.Mage;
import com.elmakers.mine.bukkit.api.magic.MagicAPI;
import com.elmakers.mine.bukkit.api.spell.Spell;
import com.elmakers.mine.bukkit.api.spell.SpellTemplate;
import com.elmakers.mine.bukkit.api.wand.Wand;
import com.elmakers.mine.bukkit.block.MaterialBrush;
import com.elmakers.mine.bukkit.api.magic.Messages;

public class WandCommandExecutor extends MagicTabExecutor {
	
	public WandCommandExecutor(MagicAPI api) {
		super(api);
	}
	
	@Override
	public boolean onCommand(CommandSender sender, Command command, String commandLabel, String[] args) {
		String commandName = command.getName();
        if (commandName.equalsIgnoreCase("wandp"))
		{
			if (args.length == 0) {
				sender.sendMessage("Usage: /wandp [player] [wand name/command]");
				return true;
			}
			Player player = Bukkit.getPlayer(args[0]);
			if (player == null) {
				sender.sendMessage("Can't find player " + args[0]);
				return true;
			}
			if (!player.isOnline()) {
				sender.sendMessage("Player " + args[0] + " is not online");
				return true;
			}
			String[] args2 = Arrays.copyOfRange(args, 1, args.length);
			return processWandCommand("wandp", sender, player, args2);
		}

		if (commandName.equalsIgnoreCase("wand") && args.length > 0 && args[0].equalsIgnoreCase("list"))
		{
			if (!api.hasPermission(sender, "Magic.commands.wand.list")) {
				sendNoPermission(sender);
				return true;
			}
			onWandList(sender);
			return true;
		}

		// Everything beyond this point is is-game only

		if (!(sender instanceof Player)) {
			return false;
		}
		
		Player player = (Player)sender;
		if (commandName.equalsIgnoreCase("wand"))
		{
			return processWandCommand("wand", sender, player, args);
		}
		
		return false;
	}

	@Override
	public Collection<String> onTabComplete(CommandSender sender, String commandName, String[] args) {
		List<String> options = new ArrayList<String>();
		
		Player player = (sender instanceof Player) ? (Player)sender : null;

        String permissionKey = "wand";
		if (commandName.contains("wandp"))
		{
            permissionKey = "wandp";
			if (args.length > 0) {
				player = Bukkit.getPlayer(args[0]);
			}
			if (args.length == 1) {
				options.addAll(api.getPlayerNames());
				return options;
			} else if (args.length > 1) {
				args = Arrays.copyOfRange(args, 1, args.length);
			}
		}
		
		if (args.length == 1) {
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "add");
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "remove");
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "name");
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "fill");
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "configure");
            addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "override");
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "organize");
            addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "alphabetize");
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "combine");
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "upgrade");
			addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "describe");
            addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "enchant");
            addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "unenchant");
            addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "duplicate");
            addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "restore");
            addIfPermissible(sender, options, "Magic.commands." + permissionKey + ".", "unlock");
		}
		
		if (args.length == 2) {
			String subCommand = args[0];
			String subCommandPNode = "Magic.commands." + permissionKey + "." + subCommand;
			
			if (!api.hasPermission(sender, subCommandPNode)) {
				return options;
			}
			
			subCommandPNode += ".";
			
			if (subCommand.equalsIgnoreCase("add")) {
				Collection<SpellTemplate> spellList = api.getSpellTemplates();
				for (SpellTemplate spell : spellList) {
					addIfPermissible(sender, options, subCommandPNode, spell.getKey(), true);
				}
				addIfPermissible(sender, options, subCommandPNode, "material", true);
			}
			
			if (subCommand.equalsIgnoreCase("configure")) {
				for (String key : com.elmakers.mine.bukkit.wand.Wand.PROPERTY_KEYS) {
					options.add(key);
				}
			}
{'fraction_non_alphanumeric': 0.14668939529876188, 'fraction_numerical': 0.003050421675937556, 'mean_word_length': 4.007637017070979, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5328300', 'n_tokens_mistral': 3964, 'n_tokens_neox': 3482, 'n_words': 694}