use of com.laytonsmith.abstraction.bukkit.events.BukkitMiscEvents.BukkitMCCommandTabCompleteEvent in project CommandHelper by EngineHub.
the class BukkitMCCommand method handleTabComplete.
// I may be able to move these to c.l.c.f.Commands.java
@Override
public List<String> handleTabComplete(MCCommandSender sender, String alias, String[] args) {
if (Commands.onTabComplete.containsKey(cmd.getName().toLowerCase())) {
Target t = Target.UNKNOWN;
CArray cargs = new CArray(t);
for (String arg : args) {
cargs.push(new CString(arg, t), t);
}
CClosure closure = Commands.onTabComplete.get(cmd.getName().toLowerCase());
try {
closure.execute(new CString(alias, t), new CString(sender.getName(), t), cargs, // reserved for an obgen style command array
new CArray(t));
} catch (FunctionReturnException e) {
Construct fret = e.getReturn();
if (fret instanceof CArray) {
List<String> ret = new ArrayList<>();
if (((CArray) fret).inAssociativeMode()) {
for (Construct key : ((CArray) fret).keySet()) {
ret.add(((CArray) fret).get(key, Target.UNKNOWN).val());
}
} else {
for (Construct value : ((CArray) fret).asList()) {
ret.add(value.val());
}
}
return ret;
}
} catch (ConfigRuntimeException cre) {
ConfigRuntimeException.HandleUncaughtException(cre, closure.getEnv());
return new ArrayList<>();
}
}
BukkitMCCommandTabCompleteEvent event = new BukkitMCCommandTabCompleteEvent(sender, cmd, alias, args);
EventUtils.TriggerListener(Driver.TAB_COMPLETE, "tab_complete_command", event);
return event.getCompletions();
}
Aggregations