Java Code Examples for org.bukkit.command.PluginCommand#setTabCompleter()

The following examples show how to use org.bukkit.command.PluginCommand#setTabCompleter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CombatLogX.java    From CombatLogX with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void registerCommand(String commandName, CommandExecutor executor, String description, String usage, String... aliases) {
    PluginCommand command = getCommand(commandName);
    if(command == null) {
        forceRegisterCommand(commandName, executor, description, usage, aliases);
        return;
    }
    command.setExecutor(executor);

    if(executor instanceof TabCompleter) {
        TabCompleter completer = (TabCompleter) executor;
        command.setTabCompleter(completer);
    }

    if(executor instanceof Listener) {
        Listener listener = (Listener) executor;
        PluginManager manager = Bukkit.getPluginManager();
        manager.registerEvents(listener, this);
    }
}
 
Example 2
Source File: ShopCommand.java    From ShopChest with MIT License 6 votes vote down vote up
private PluginCommand createPluginCommand() {
    plugin.debug("Creating plugin command");
    try {
        Constructor<PluginCommand> c = PluginCommand.class.getDeclaredConstructor(String.class, Plugin.class);
        c.setAccessible(true);

        PluginCommand cmd = c.newInstance(name, plugin);
        cmd.setDescription("Manage players' shops or this plugin.");
        cmd.setUsage("/" + name);
        cmd.setExecutor(new ShopBaseCommandExecutor());
        cmd.setTabCompleter(new ShopBaseTabCompleter());

        return cmd;
    } catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException | InstantiationException e) {
        plugin.getLogger().severe("Failed to create command");
        plugin.debug("Failed to create plugin command");
        plugin.debug(e);
    }

    return null;
}
 
Example 3
Source File: CommandMapUtil.java    From helper with MIT License 5 votes vote down vote up
/**
 * Registers a CommandExecutor with the server
 *
 * @param plugin the plugin instance
 * @param command the command instance
 * @param permission the command permission
 * @param permissionMessage the message sent when the sender doesn't the required permission
 * @param description the command description
 * @param aliases the command aliases
 * @param <T> the command executor class type
 * @return the command executor
 */
@Nonnull
public static <T extends CommandExecutor> T registerCommand(@Nonnull Plugin plugin, @Nonnull T command, String permission, String permissionMessage, String description, @Nonnull String... aliases) {
    Preconditions.checkArgument(aliases.length != 0, "No aliases");
    for (String alias : aliases) {
        try {
            PluginCommand cmd = COMMAND_CONSTRUCTOR.newInstance(alias, plugin);

            getCommandMap().register(plugin.getDescription().getName(), cmd);
            getKnownCommandMap().put(plugin.getDescription().getName().toLowerCase() + ":" + alias.toLowerCase(), cmd);
            getKnownCommandMap().put(alias.toLowerCase(), cmd);
            cmd.setLabel(alias.toLowerCase());
            if (permission != null) {
               cmd.setPermission(permission);
               if (permissionMessage != null) {
                   cmd.setPermissionMessage(permissionMessage);
               }
            }
            if (description != null) {
                cmd.setDescription(description);
            }

            cmd.setExecutor(command);
            if (command instanceof TabCompleter) {
                cmd.setTabCompleter((TabCompleter) command);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    return command;
}
 
Example 4
Source File: ClaimChunk.java    From ClaimChunk with MIT License 5 votes vote down vote up
private void setupCommands() {
    // Register all the commands
    Commands.register(cmd);

    // Get the Spigot command
    PluginCommand command = getCommand("chunk");
    if (command != null) {
        // Use our custom plugin executor
        command.setExecutor(cmd);

        // Set the tab completer so tab complete works with all the sub commands
        command.setTabCompleter(new AutoTabCompletion(this));
    }
}
 
Example 5
Source File: SpleefCommandManager.java    From HeavySpleef with GNU General Public License v3.0 5 votes vote down vote up
public SpleefCommandManager(final HeavySpleef plugin) {
	service = new CommandManagerService(plugin.getPlugin(), plugin.getLogger(), new MessageBundle.MessageProvider() {
		
		@Override
		public String provide(String key, String[] args) {
			String message = null;
			
			switch (key) {
			case "message-player_only":
				message = i18n.getString(Messages.Command.PLAYER_ONLY);
				break;
			case "message-no_permission":
				message = i18n.getString(Messages.Command.NO_PERMISSION);
				break;
			case "message-description_format":
				message = i18n.getVarString(Messages.Command.DESCRIPTION_FORMAT)
					.setVariable("description", args[0])
					.toString();
				break;
			case "message-usage_format":
				message = i18n.getVarString(Messages.Command.USAGE_FORMAT)
					.setVariable("usage", args[0])
					.toString();
				break;
			case "message-unknown_command":
				message = i18n.getString(Messages.Command.UNKNOWN_COMMAND);
				break;
			default:
				//Get the message by i18n
				message = i18n.getString(key);
			}
			
			return message;
		}
	}, new BukkitPermissionChecker(), plugin);
	
	PluginCommand spleefCommand = plugin.getPlugin().getCommand("spleef");
	spleefCommand.setExecutor(service);
	spleefCommand.setTabCompleter(service);
}
 
Example 6
Source File: RadiationCommandHandler.java    From CraftserveRadiation with Apache License 2.0 4 votes vote down vote up
public void register(PluginCommand command) {
    Objects.requireNonNull(command, "command");
    command.setExecutor(this);
    command.setTabCompleter(this);
}
 
Example 7
Source File: AdditionsAPI.java    From AdditionsAPI with MIT License 4 votes vote down vote up
public void onEnable() {

		instance = this;

		// Initializing Config
		ConfigFile config = ConfigFile.getInstance();
		config.setup();
		if (config.getConfig().getBoolean("resource-pack.force-on-join"))
			ResourcePackManager.setForceResourcePack();

		// Initializing Data File
		DataFile.getInstance().setup();

		// Initializing Lang File and adding all entries
		LangFile lang = LangFile.getInstance();
		lang.setup();

		String pluginName = "more_minecraft";
		lang.addEntry(pluginName, "sword", "Sword");
		lang.addEntry(pluginName, "axe", "Axe");
		lang.addEntry(pluginName, "picakaxe", "Pickaxe");
		lang.addEntry(pluginName, "spade", "Shovel");
		lang.addEntry(pluginName, "hoe", "Hoe");
		lang.addEntry(pluginName, "helmet", "Helmet");
		lang.addEntry(pluginName, "chestplate", "Chestplate");
		lang.addEntry(pluginName, "leggings", "Leggings");
		lang.addEntry(pluginName, "boots", "Boots");
		lang.addEntry(pluginName, "leather_helmet", "Cap");
		lang.addEntry(pluginName, "leather_chestplate", "Tunic");
		lang.addEntry(pluginName, "leather_leggings", "Pants");
		lang.addEntry(pluginName, "leather_boots", "Boots");
		lang.addEntry(pluginName, "when_in_head", "When in head:");
		lang.addEntry(pluginName, "when_in_body", "When in body:");
		lang.addEntry(pluginName, "when_in_legs", "When in legs:");
		lang.addEntry(pluginName, "when_in_feet", "When in feet:");
		lang.addEntry(pluginName, "when_in_main_hand", "When in main hand:");
		lang.addEntry(pluginName, "when_in_off_hand", "When in off hand:");
		lang.addEntry(pluginName, "attribute_generic_attack_speed", "Attack Speed");
		lang.addEntry(pluginName, "attribute_generic_attack_damage", "Attack Damage");
		lang.addEntry(pluginName, "attribute_armor", "Armor");
		lang.addEntry(pluginName, "attribute_armor_toughness", "Armor Toughness");
		lang.addEntry(pluginName, "attribute_generic_follow_range", "Follow Range");
		lang.addEntry(pluginName, "attribute_generic_knockback_resistance", "Knockback Resistance");
		lang.addEntry(pluginName, "attribute_generic_luck", "Luck");
		lang.addEntry(pluginName, "attribute_generic_max_health", "Max Health");
		lang.addEntry(pluginName, "attribute_generic_movement_speed", "Speed");
		lang.addEntry(pluginName, "attribute_horse_jump_strength", "Horse Jump Strength");
		lang.addEntry(pluginName, "attribute_zombie_spawn_reinforcements", "Zombie Spawn Reinforcements");
		lang.addEntry(pluginName, "durability", "Durability:");
		lang.addEntry(pluginName, "death_message", " using [CustomItem]");
		lang.addEntry(pluginName, "resource_pack_kick",
				"You must accept the resource pack in order to join the server! Click on the server once, then click edit and change Server Resource pack to True.");
		lang.addEntry(pluginName, "item_durability_main_hand", "Item Durability in Main Hand: ");
		lang.addEntry(pluginName, "item_durability_off_hand", "Item Durability in Off Hand: ");

		lang.saveLang();

		// Initialize Metrics
		new Metrics(this);

		// Registering listeners
		for (Listener listener : Arrays.asList(new EnchantItem(), new Anvil(), new CraftingTable(), new BlockBreak(),
				new CustomItemBlockBreak(), new EntityDamage(), new EntityDamageByPlayerUsingCustomItem(),
				new PlayerCustomItemDamage(), new PlayerInteract(), new CustomItemPlayerInteract(),
				new PlayerShearEntity(), new CustomItemShearEntity(), new PlayerFish(), new CustomItemFish(),
				new BlockIgnite(), new CustomItemBlockIgnite(), new EntityShootBow(), new EntityShootCustomBow(),
				new CustomShieldEntityDamageByEntity(), new EntityToggleGlide(), new CustomElytraPlayerToggleGlide(),
				this, new ArrowFromCustomBowHit(), new PlayerDeath(), new DurabilityBar(), new FurnaceBurn(),
				new CustomItemFurnaceBurn(), new ResourcePackListener(), new Experience(), new ArmorListener(),
				new ArmorEquip(), new PlayerDropItem(), new PlayerDropCustomItem(), new PlayerPickupItem(),
				new PlayerPickupCustomItem())) {
			getServer().getPluginManager().registerEvents(listener, this);
		}

		// Commands
		PluginCommand additions = getCommand("additions");
		additions.setExecutor(new AdditionsCmd());
		additions.setTabCompleter(new AdditionsTab());
		
		// Check if the server has the methods I added to Spigot (anything newer than around the 6th of August 2018 should be good)
		try {
			Material.DIAMOND_BLOCK.isInteractable();
			Material.DIAMOND_BLOCK.getHardness();
			Material.DIAMOND_BLOCK.getBlastResistance();
		} catch (NoSuchMethodError e) {
			MaterialUtils.useNewMethods = false;
		}

		// Commented out - these are not ready yet. Works on Linux but still fighting
		// for the rest of the OSes.
		// Tools.loadAgentLibrary();
		// new RuntimeTransformer(ItemStackTransformer.class,
		// CraftItemStack_1_12_Transformer.class);

		// After all plugins have been enabled
		getServer().getScheduler().scheduleSyncDelayedTask(this, () -> load());
	}