Navigation Menu

Skip to content
This repository has been archived by the owner on Jul 27, 2019. It is now read-only.

Commit

Permalink
Add custom tab-complete for /irc commands. #98
Browse files Browse the repository at this point in the history
  • Loading branch information
cnaude committed Dec 24, 2014
1 parent 59dd74a commit ca0d324
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/main/java/com/cnaude/purpleirc/CommandHandlers.java
Expand Up @@ -35,7 +35,7 @@ public class CommandHandlers implements CommandExecutor {
public HashMap<String, IRCCommandInterface> commands = new HashMap<>();
public ArrayList<String> sortedCommands = new ArrayList<>();
private final PurpleIRC plugin;

/**
*
* @param plugin
Expand Down
Expand Up @@ -19,7 +19,6 @@
import com.cnaude.purpleirc.Events.IRCCommandEvent;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import org.bukkit.command.CommandSender;

/**
*
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/cnaude/purpleirc/Commands/Msg.java
Expand Up @@ -54,7 +54,7 @@ public void dispatch(CommandSender sender, String[] args) {
plugin.logDebug("Dispatching msg command...");
int msgIdx = 2;
String nick;
java.util.List<PurpleBot> myBots = new ArrayList<PurpleBot>();
java.util.List<PurpleBot> myBots = new ArrayList<>();
if (plugin.ircBots.containsKey(args[1])) {
myBots.add(plugin.ircBots.get(args[1]));
msgIdx = 3;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/cnaude/purpleirc/PurpleIRC.java
Expand Up @@ -174,6 +174,7 @@ public class PurpleIRC extends JavaPlugin {
public ReportRTSHook reportRTSHook;
public NetPackets netPackets;
public CommandHandlers commandHandlers;
public PurpleTabCompleter ircTabCompleter;
private BotWatcher botWatcher;
public IRCMessageHandler ircMessageHandler;

Expand Down Expand Up @@ -378,7 +379,9 @@ public void onEnable() {
logInfo("Essentials not detected.");
}
commandHandlers = new CommandHandlers(this);
ircTabCompleter = new PurpleTabCompleter(this);
getCommand("irc").setExecutor(commandHandlers);
getCommand("irc").setTabCompleter(ircTabCompleter);
regexGlobber = new RegexGlobber();
tokenizer = new ChatTokenizer(this);
loadBots();
Expand Down
88 changes: 88 additions & 0 deletions src/main/java/com/cnaude/purpleirc/PurpleTabCompleter.java
@@ -0,0 +1,88 @@
/*
* Copyright (C) 2014 cnaude
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.cnaude.purpleirc;

import java.util.ArrayList;
import java.util.List;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.command.TabCompleter;
import org.bukkit.entity.Player;
import org.pircbotx.Channel;
import org.pircbotx.User;

/**
*
* @author cnaude
*/
public class PurpleTabCompleter implements TabCompleter {

private final PurpleIRC plugin;

/**
*
* @param plugin
*/
public PurpleTabCompleter(final PurpleIRC plugin) {
this.plugin = plugin;
}

@Override
public List<String> onTabComplete(CommandSender cs, Command cmnd, String string, String[] strings) {

List<String> list = new ArrayList<>();

plugin.logDebug("S: " + string);
for (String s : strings) {
plugin.logDebug("S1: " + s);
}
if (strings.length == 1) {
for (String c : plugin.commandHandlers.sortedCommands) {
if (cs.hasPermission("irc." + c)) {
if (c.startsWith(strings[0])) {
list.add(c);
}
}
}
}

if (strings.length == 2) {
for (PurpleBot ircBot : plugin.ircBots.values()) {
for (Channel channel : ircBot.getChannels()) {
for (User user : channel.getUsers()) {
if (user.getNick().startsWith(strings[1])) {
list.add(user.getNick());
}
}
}
}
for (Player player : plugin.getServer().getOnlinePlayers()) {
if (plugin.vanishHook != null) {
if (plugin.vanishHook.isVanished(player)) {
continue;
}
}
if (player.getDisplayName().startsWith(strings[1])) {
list.add(player.getDisplayName());
}
}
}

return list;
}

}

0 comments on commit ca0d324

Please sign in to comment.