Implement tab completion for all commands. (#1282)

List of supported commands:
```
/afk
/balance
/balancetop
/ban
/banip
/bigtree
/book
/broadcastworld
/burn
/clearinventory
/condense
/delhome
/deljail
/delwarp
/eco
/enchant
/enderchest
/essentials
/exp
/ext
/feed
/fireball
/firework
/gamemode
/getpos
/give
/hat
/heal
/help
/helpop
/home
/ignore
/invsee
/item
/itemdb
/jump
/kick
/kill
/kit
/lightning
/list
/mail
/me
/msg
/mute
/near
/nick
/nuke
/pay
/potion
/powertool
/ptime
/pweather
/recipe
/remove
/repair
/sell
/showkit
/skull
/speed
/tempban
/thunder
/time
/togglejail
/tp
/tpa
/tpaall
/tpahere
/tpall
/tphere
/tpo
/tpohere
/tppos
/tree
/warp
/weather
/world
/worth```
This commit is contained in:
Ali 'SupaHam' M 2017-06-11 01:17:43 +01:00 committed by GitHub
parent e572788a8c
commit bbe0ca9302
82 changed files with 1783 additions and 118 deletions

View File

@ -218,4 +218,8 @@ public class Enchantments {
public static Set<Entry<String, Enchantment>> entrySet() {
return ENCHANTMENTS.entrySet();
}
public static Set<String> keySet() {
return ENCHANTMENTS.keySet();
}
}

View File

@ -371,6 +371,10 @@ public class ItemDb implements IConf, net.ess3.api.IItemDb {
return sb.toString().trim().replaceAll("§", "&");
}
@Override
public Collection<String> listNames() {
return primaryName.values();
}
static class ItemData {
final private int itemNo;

View File

@ -3,6 +3,7 @@ package com.earth2me.essentials.api;
import com.earth2me.essentials.User;
import org.bukkit.inventory.ItemStack;
import java.util.Collection;
import java.util.List;
@ -18,4 +19,6 @@ public interface IItemDb {
List<ItemStack> getMatching(User user, String[] args) throws Exception;
String serialize(ItemStack is);
Collection<String> listNames();
}

View File

@ -4,6 +4,9 @@ import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import org.bukkit.Server;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -77,5 +80,23 @@ public class Commandafk extends EssentialsCommand {
ess.broadcastMessage(user, msg);
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1 && user.isAuthorized("essentials.afk.others")) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -6,6 +6,8 @@ import com.earth2me.essentials.utils.NumberUtil;
import org.bukkit.Server;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -38,4 +40,22 @@ public class Commandbalance extends EssentialsCommand {
throw new NotEnoughArgumentsException();
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1 && user.isAuthorized("essentials.balance.others")) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -5,6 +5,7 @@ import com.earth2me.essentials.User;
import com.earth2me.essentials.textreader.SimpleTextInput;
import com.earth2me.essentials.textreader.TextPager;
import com.earth2me.essentials.utils.NumberUtil;
import com.google.common.collect.Lists;
import org.bukkit.Server;
import java.math.BigDecimal;
@ -161,4 +162,17 @@ public class Commandbalancetop extends EssentialsCommand {
ess.runTaskAsynchronously(new Calculator(new Viewer(sender, commandLabel, page, false), force));
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
List<String> options = Lists.newArrayList("1");
if (!sender.isPlayer() || ess.getUser(sender.getPlayer()).isAuthorized("essentials.balancetop.force")) {
options.add("force");
}
return options;
} else {
return Collections.emptyList();
}
}
}

View File

@ -8,6 +8,8 @@ import com.earth2me.essentials.utils.FormatUtil;
import org.bukkit.BanList;
import org.bukkit.Server;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import static com.earth2me.essentials.I18n.tl;
@ -62,4 +64,13 @@ public class Commandban extends EssentialsCommand {
ess.broadcastMessage("essentials.ban.notify", tl("playerBanned", senderName, user.getName(), banReason));
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -7,6 +7,8 @@ import com.earth2me.essentials.utils.FormatUtil;
import org.bukkit.BanList;
import org.bukkit.Server;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import static com.earth2me.essentials.I18n.tl;
@ -54,4 +56,14 @@ public class Commandbanip extends EssentialsCommand {
ess.broadcastMessage("essentials.banip.notify", tl("playerBanIpAddress", senderName, ipAddress, banReason));
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
// TODO: Also list IP addresses?
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -2,10 +2,14 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.LocationUtil;
import com.google.common.collect.Lists;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.TreeType;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -36,4 +40,13 @@ public class Commandbigtree extends EssentialsCommand {
throw new Exception(tl("bigTreeFailure"));
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
return Lists.newArrayList("redwood", "tree", "jungle");
} else {
return Collections.emptyList();
}
}
}

View File

@ -2,11 +2,15 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
import com.google.common.collect.Lists;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.BookMeta;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -67,4 +71,25 @@ public class Commandbook extends EssentialsCommand {
String author = bmeta.getAuthor();
return author != null && author.equalsIgnoreCase(player);
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
// Right now, we aren't testing what's held in the player's hand - we could, but it's not necessarily worth it
if (args.length == 1) {
List<String> options = Lists.newArrayList("sign", "unsign"); // sign and unsign aren't real, but work
if (user.isAuthorized("essentials.book.author")) {
options.add("author");
}
if (user.isAuthorized("essentials.book.title")) {
options.add("title");
}
return options;
} else if (args.length == 2 && args[0].equalsIgnoreCase("author") && user.isAuthorized("essentials.book.author")) {
List<String> options = getPlayers(server, user);
options.add("Herobrine"); // #EasterEgg
return options;
} else {
return Collections.emptyList();
}
}
}

View File

@ -8,12 +8,15 @@ import com.earth2me.essentials.textreader.IText;
import com.earth2me.essentials.textreader.KeywordReplacer;
import com.earth2me.essentials.textreader.SimpleTextInput;
import com.earth2me.essentials.utils.FormatUtil;
import com.google.common.collect.Lists;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
public class Commandbroadcastworld extends EssentialsCommand {
@ -57,4 +60,22 @@ public class Commandbroadcastworld extends EssentialsCommand {
}
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
return Collections.emptyList(); // The argument is only for non-players
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
List<String> worlds = Lists.newArrayList();
for (World world : server.getWorlds()) {
worlds.add(world.getName());
}
return worlds;
} else {
return Collections.emptyList();
}
}
}

View File

@ -4,6 +4,9 @@ import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import org.bukkit.Server;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -26,4 +29,15 @@ public class Commandburn extends EssentialsCommand {
user.getBase().setFireTicks(Integer.parseInt(args[1]) * 20);
sender.sendMessage(tl("burnMsg", user.getDisplayName(), Integer.parseInt(args[1])));
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else if (args.length == 2) {
return COMMON_DURATIONS;
} else {
return Collections.emptyList();
}
}
}

View File

@ -10,6 +10,8 @@ import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import static com.earth2me.essentials.I18n.tl;
@ -127,4 +129,50 @@ public class Commandclearinventory extends EssentialsCommand {
}
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (user.isAuthorized("essentials.clearinventory.others")) {
if (args.length == 1) {
List<String> options = getPlayers(server, user);
if (user.isAuthorized("essentials.clearinventory.all") || user.isAuthorized("essentials.clearinventory.multiple")) {
// Assume that nobody will have the 'all' permission without the 'others' permission
options.add("*");
}
return options;
} else if (args.length == 2) {
List<String> items = new ArrayList<>(getItems());
items.add("*");
items.add("**");
return items;
} else {
return Collections.emptyList();
}
} else {
if (args.length == 1) {
List<String> items = new ArrayList<>(getItems());
items.add("*");
items.add("**");
return items;
} else {
return Collections.emptyList();
}
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
List<String> options = getPlayers(server, sender);
options.add("*");
return options;
} else if (args.length == 2) {
List<String> items = new ArrayList<>(getItems());
items.add("*");
items.add("**");
return items;
} else {
return Collections.emptyList();
}
}
}

View File

@ -178,4 +178,13 @@ public class Commandcondense extends EssentialsCommand {
return input.clone();
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
return getMatchingItems(args[0]);
} else {
return Collections.emptyList();
}
}
}

View File

@ -4,6 +4,9 @@ import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import org.bukkit.Server;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import static com.earth2me.essentials.I18n.tl;
@ -48,4 +51,28 @@ public class Commanddelhome extends EssentialsCommand {
user.delHome(name.toLowerCase(Locale.ENGLISH));
sender.sendMessage(tl("deleteHome", name));
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
User user = ess.getUser(sender.getPlayer());
boolean canDelOthers = (user == null || user.isAuthorized("essentials.delhome.others"));
if (args.length == 1) {
if (canDelOthers) {
return getPlayers(server, sender);
} else {
return user.getHomes();
}
} else if (args.length == 2 && canDelOthers) {
try {
user = getPlayer(server, args, 0, true, true);
return user.getHomes();
} catch (Exception ex) {
// No such user
return Collections.emptyList();
}
} else {
return Collections.emptyList();
}
}
}

View File

@ -2,7 +2,9 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import org.bukkit.Server;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -20,4 +22,17 @@ public class Commanddeljail extends EssentialsCommand {
ess.getJails().removeJail(args[0]);
sender.sendMessage(tl("deleteJail", args[0]));
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
if (args.length == 1) {
try {
return new ArrayList<>(ess.getJails().getList());
} catch (Exception e) {
return Collections.emptyList();
}
} else {
return Collections.emptyList();
}
}
}

View File

@ -3,6 +3,10 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import org.bukkit.Server;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -20,4 +24,13 @@ public class Commanddelwarp extends EssentialsCommand {
ess.getWarps().removeWarp(args[0]);
sender.sendMessage(tl("deleteWarp", args[0]));
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
if (args.length == 1) {
return new ArrayList<>(ess.getWarps().getList());
} else {
return Collections.emptyList();
}
}
}

View File

@ -4,10 +4,13 @@ import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.NumberUtil;
import com.google.common.collect.Lists;
import net.ess3.api.MaxMoneyException;
import org.bukkit.Server;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import static com.earth2me.essentials.I18n.tl;
@ -98,4 +101,25 @@ public class Commandeco extends EssentialsLoopCommand {
private enum EcoCommands {
GIVE, TAKE, SET, RESET
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, final CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
List<String> options = Lists.newArrayList();
for (EcoCommands command : EcoCommands.values()) {
options.add(command.name().toLowerCase(Locale.ENGLISH));
}
return options;
} else if (args.length == 2) {
return getPlayers(server, sender);
} else if (args.length == 3 && !args[0].equalsIgnoreCase(EcoCommands.RESET.name())) {
if (args[0].equalsIgnoreCase(EcoCommands.SET.name())) {
return Lists.newArrayList("0", ess.getSettings().getStartingBalance().toString());
} else {
return Lists.newArrayList("1", "10", "100", "1000");
}
} else {
return Collections.emptyList();
}
}
}

View File

@ -5,11 +5,15 @@ import com.earth2me.essentials.MetaItemStack;
import com.earth2me.essentials.User;
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
import com.earth2me.essentials.utils.StringUtil;
import com.google.common.collect.Lists;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.enchantments.Enchantment;
import org.bukkit.inventory.ItemStack;
import java.util.Collections;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@ -66,4 +70,25 @@ public class Commandenchant extends EssentialsCommand {
user.sendMessage(tl("enchantmentApplied", enchantmentName.replace('_', ' ')));
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
if (args.length == 1) {
return new ArrayList<>(Enchantments.keySet());
} else if (args.length == 2) {
Enchantment enchantment = Enchantments.getByName(args[0]);
if (enchantment == null) {
return Collections.emptyList();
}
int min = enchantment.getStartLevel();
int max = enchantment.getMaxLevel();
List<String> options = Lists.newArrayList();
for (int i = min; i <= max; i++) {
options.add(Integer.toString(i));
}
return options;
} else {
return Collections.emptyList();
}
}
}

View File

@ -3,6 +3,8 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import org.bukkit.Server;
import java.util.Collections;
import java.util.List;
public class Commandenderchest extends EssentialsCommand {
public Commandenderchest() {
@ -23,4 +25,13 @@ public class Commandenderchest extends EssentialsCommand {
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1 && user.isAuthorized("essentials.enderchest.others")) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
}

View File

@ -9,6 +9,7 @@ import com.earth2me.essentials.utils.DateUtil;
import com.earth2me.essentials.utils.FloatUtil;
import com.earth2me.essentials.utils.NumberUtil;
import com.google.common.base.Charsets;
import com.google.common.collect.Lists;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.Sound;
@ -16,7 +17,9 @@ import org.bukkit.block.Block;
import org.bukkit.entity.Player;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
@ -303,4 +306,52 @@ public class Commandessentials extends EssentialsCommand {
UUID offlineuuid = UUID.nameUUIDFromBytes(("OfflinePlayer:" + name).getBytes(Charsets.UTF_8));
sender.sendMessage("Offline Mode UUID: " + offlineuuid.toString());
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
if (args.length == 1) {
List<String> options = Lists.newArrayList();
options.add("reload");
options.add("debug");
//options.add("nya");
//options.add("moo");
options.add("reset");
options.add("opt-out");
options.add("cleanup");
//options.add("uuidconvert");
//options.add("uuidtest");
return options;
} else if (args[0].equalsIgnoreCase("debug")) {
// No args
} else if (args[0].equalsIgnoreCase("nya")) {
// No args
} else if (args[0].equalsIgnoreCase("moo")) {
if (args.length == 2) {
return Lists.newArrayList("moo");
}
} else if (args[0].equalsIgnoreCase("reset")) {
if (args.length == 2) {
return getPlayers(server, sender);
}
} else if (args[0].equalsIgnoreCase("opt-out")) {
// No args
} else if (args[0].equalsIgnoreCase("cleanup")) {
if (args.length == 2) {
return COMMON_DURATIONS;
} else if (args.length == 3 || args.length == 4) {
return Lists.newArrayList("-1", "0");
}
} else if (args[0].equalsIgnoreCase("uuidconvert")) {
if (args.length == 2) {
return Lists.newArrayList("ignoreUFCache");
}
} else if (args[0].equalsIgnoreCase("uuidtest")) {
if (args.length == 2) {
return getPlayers(server, sender);
}
} else {
// No args
}
return Collections.emptyList();
}
}

View File

@ -4,9 +4,11 @@ import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.craftbukkit.SetExpFix;
import com.earth2me.essentials.utils.NumberUtil;
import com.google.common.collect.Lists;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
@ -146,4 +148,58 @@ public class Commandexp extends EssentialsCommand {
SetExpFix.setTotalExperience(target.getBase(), (int) amount);
sender.sendMessage(tl("expSet", target.getDisplayName(), amount));
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
if (args.length == 1) {
List<String> options = Lists.newArrayList("show");
if (user.isAuthorized("essentials.exp.set")) {
options.add("set");
}
if (user.isAuthorized("essentials.exp.give")) {
options.add("give");
}
return options;
} else if (args.length == 2) {
if ((args[0].equalsIgnoreCase("set") && user.isAuthorized("essentials.exp.set")) || (args[0].equalsIgnoreCase("give") && user.isAuthorized("essentials.exp.give"))) {
String levellessArg = args[1].toLowerCase(Locale.ENGLISH).replace("l", "");
if (NumberUtil.isInt(levellessArg)) {
return Lists.newArrayList(levellessArg, args[1] + "l");
} else {
return Collections.emptyList();
}
} else if (args[0].equalsIgnoreCase("show") && user.isAuthorized("essentials.exp.others")) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
} else if (args.length == 3 && (args[0].equalsIgnoreCase("set") && user.isAuthorized("essentials.exp.set.others")) || (args[0].equalsIgnoreCase("give") && user.isAuthorized("essentials.exp.give.others"))) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
if (args.length == 1) {
// TODO: This seems somewhat buggy, both setting and showing - right now, ignoring that
return Lists.newArrayList("set", "give", "show");
} else if (args.length == 2) {
if (args[0].equalsIgnoreCase("set") || args[0].equalsIgnoreCase("give")) {
String levellessArg = args[1].toLowerCase(Locale.ENGLISH).replace("l", "");
if (NumberUtil.isInt(levellessArg)) {
return Lists.newArrayList(levellessArg, args[1] + "l");
} else {
return Collections.emptyList();
}
} else { // even without 'show'
return getPlayers(server, sender);
}
} else if (args.length == 3 && (args[0].equalsIgnoreCase("set") || args[0].equalsIgnoreCase("give"))) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -5,6 +5,9 @@ import com.earth2me.essentials.User;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -42,4 +45,13 @@ public class Commandext extends EssentialsLoopCommand {
private void extPlayer(final Player player) {
player.setFireTicks(0);
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -6,6 +6,9 @@ import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.FoodLevelChangeEvent;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -61,4 +64,22 @@ public class Commandfeed extends EssentialsLoopCommand {
player.setSaturation(10);
player.setExhaustion(0F);
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1 && user.isAuthorized("essentials.feed.others")) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -1,10 +1,13 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import com.google.common.collect.Lists;
import org.bukkit.Server;
import org.bukkit.entity.*;
import org.bukkit.util.Vector;
import java.util.Collections;
import java.util.List;
public class Commandfireball extends EssentialsCommand {
public Commandfireball() {
@ -38,4 +41,13 @@ public class Commandfireball extends EssentialsCommand {
projectile.setShooter(user.getBase());
projectile.setVelocity(direction);
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
if (args.length == 1) {
return Lists.newArrayList("small", "arrow", "skull", "egg", "snowball", "expbottle", "large");
} else {
return Collections.emptyList();
}
}
}

View File

@ -1,116 +1,177 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.MetaItemStack;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.NumberUtil;
import org.bukkit.FireworkEffect;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.util.Vector;
import static com.earth2me.essentials.I18n.tl;
//This command has quite a complicated syntax, in theory it has 4 seperate syntaxes which are all variable:
//
//1: /firework clear - This clears all of the effects on a firework stack
//
//2: /firework power <int> - This changes the base power of a firework
//
//3: /firework fire - This 'fires' a copy of the firework held.
//3: /firework fire <int> - This 'fires' a number of copies of the firework held.
//3: /firework fire <other> - This 'fires' a copy of the firework held, in the direction you are looking, #easteregg
//
//4: /firework [meta] - This will add an effect to the firework stack held
//4: /firework color:<color> - The minimum you need to set an effect is 'color'
//4: Full Syntax: color:<color[,color,..]> [fade:<color[,color,..]>] [shape:<shape>] [effect:<effect[,effect]>]
//4: Possible Shapes: star, ball, large, creeper, burst
//4: Possible Effects trail, twinkle
public class Commandfirework extends EssentialsCommand {
public Commandfirework() {
super("firework");
}
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
final ItemStack stack = user.getBase().getItemInHand();
if (stack.getType() == Material.FIREWORK) {
if (args.length > 0) {
if (args[0].equalsIgnoreCase("clear")) {
FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
fmeta.clearEffects();
stack.setItemMeta(fmeta);
user.sendMessage(tl("fireworkEffectsCleared"));
} else if (args.length > 1 && (args[0].equalsIgnoreCase("power") || (args[0].equalsIgnoreCase("p")))) {
FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
try {
int power = Integer.parseInt(args[1]);
fmeta.setPower(power > 3 ? 4 : power);
} catch (NumberFormatException e) {
throw new Exception(tl("invalidFireworkFormat", args[1], args[0]));
}
stack.setItemMeta(fmeta);
} else if ((args[0].equalsIgnoreCase("fire") || (args[0].equalsIgnoreCase("f"))) && user.isAuthorized("essentials.firework.fire")) {
int amount = 1;
boolean direction = false;
if (args.length > 1) {
if (NumberUtil.isInt(args[1])) {
final int serverLimit = ess.getSettings().getSpawnMobLimit();
amount = Integer.parseInt(args[1]);
if (amount > serverLimit) {
amount = serverLimit;
user.sendMessage(tl("mobSpawnLimit"));
}
} else {
direction = true;
}
}
for (int i = 0; i < amount; i++) {
Firework firework = (Firework) user.getWorld().spawnEntity(user.getLocation(), EntityType.FIREWORK);
FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
if (direction) {
final Vector vector = user.getBase().getEyeLocation().getDirection().multiply(0.070);
if (fmeta.getPower() > 1) {
fmeta.setPower(1);
}
firework.setVelocity(vector);
}
firework.setFireworkMeta(fmeta);
}
} else {
final MetaItemStack mStack = new MetaItemStack(stack);
for (String arg : args) {
try {
mStack.addFireworkMeta(user.getSource(), true, arg, ess);
} catch (Exception e) {
user.sendMessage(tl("fireworkSyntax"));
throw e;
}
}
if (mStack.isValidFirework()) {
FireworkMeta fmeta = (FireworkMeta) mStack.getItemStack().getItemMeta();
FireworkEffect effect = mStack.getFireworkBuilder().build();
if (fmeta.getEffects().size() > 0 && !user.isAuthorized("essentials.firework.multiple")) {
throw new Exception(tl("multipleCharges"));
}
fmeta.addEffect(effect);
stack.setItemMeta(fmeta);
} else {
user.sendMessage(tl("fireworkSyntax"));
throw new Exception(tl("fireworkColor"));
}
}
} else {
throw new NotEnoughArgumentsException();
}
} else {
throw new Exception(tl("holdFirework"));
}
}
}
package com.earth2me.essentials.commands;
import com.earth2me.essentials.MetaItemStack;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.NumberUtil;
import com.google.common.collect.Lists;
import org.bukkit.DyeColor;
import org.bukkit.FireworkEffect;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.entity.EntityType;
import org.bukkit.entity.Firework;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.FireworkMeta;
import org.bukkit.util.Vector;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
//This command has quite a complicated syntax, in theory it has 4 seperate syntaxes which are all variable:
//
//1: /firework clear - This clears all of the effects on a firework stack
//
//2: /firework power <int> - This changes the base power of a firework
//
//3: /firework fire - This 'fires' a copy of the firework held.
//3: /firework fire <int> - This 'fires' a number of copies of the firework held.
//3: /firework fire <other> - This 'fires' a copy of the firework held, in the direction you are looking, #easteregg
//
//4: /firework [meta] - This will add an effect to the firework stack held
//4: /firework color:<color> - The minimum you need to set an effect is 'color'
//4: Full Syntax: color:<color[,color,..]> [fade:<color[,color,..]>] [shape:<shape>] [effect:<effect[,effect]>]
//4: Possible Shapes: star, ball, large, creeper, burst
//4: Possible Effects trail, twinkle
public class Commandfirework extends EssentialsCommand {
public Commandfirework() {
super("firework");
}
@Override
protected void run(final Server server, final User user, final String commandLabel, final String[] args) throws Exception {
final ItemStack stack = user.getBase().getItemInHand();
if (stack.getType() == Material.FIREWORK) {
if (args.length > 0) {
if (args[0].equalsIgnoreCase("clear")) {
FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
fmeta.clearEffects();
stack.setItemMeta(fmeta);
user.sendMessage(tl("fireworkEffectsCleared"));
} else if (args.length > 1 && (args[0].equalsIgnoreCase("power") || (args[0].equalsIgnoreCase("p")))) {
FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
try {
int power = Integer.parseInt(args[1]);
fmeta.setPower(power > 3 ? 4 : power);
} catch (NumberFormatException e) {
throw new Exception(tl("invalidFireworkFormat", args[1], args[0]));
}
stack.setItemMeta(fmeta);
} else if ((args[0].equalsIgnoreCase("fire") || (args[0].equalsIgnoreCase("f"))) && user.isAuthorized("essentials.firework.fire")) {
int amount = 1;
boolean direction = false;
if (args.length > 1) {
if (NumberUtil.isInt(args[1])) {
final int serverLimit = ess.getSettings().getSpawnMobLimit();
amount = Integer.parseInt(args[1]);
if (amount > serverLimit) {
amount = serverLimit;
user.sendMessage(tl("mobSpawnLimit"));
}
} else {
direction = true;
}
}
for (int i = 0; i < amount; i++) {
Firework firework = (Firework) user.getWorld().spawnEntity(user.getLocation(), EntityType.FIREWORK);
FireworkMeta fmeta = (FireworkMeta) stack.getItemMeta();
if (direction) {
final Vector vector = user.getBase().getEyeLocation().getDirection().multiply(0.070);
if (fmeta.getPower() > 1) {
fmeta.setPower(1);
}
firework.setVelocity(vector);
}
firework.setFireworkMeta(fmeta);
}
} else {
final MetaItemStack mStack = new MetaItemStack(stack);
for (String arg : args) {
try {
mStack.addFireworkMeta(user.getSource(), true, arg, ess);
} catch (Exception e) {
user.sendMessage(tl("fireworkSyntax"));
throw e;
}
}
if (mStack.isValidFirework()) {
FireworkMeta fmeta = (FireworkMeta) mStack.getItemStack().getItemMeta();
FireworkEffect effect = mStack.getFireworkBuilder().build();
if (fmeta.getEffects().size() > 0 && !user.isAuthorized("essentials.firework.multiple")) {
throw new Exception(tl("multipleCharges"));
}
fmeta.addEffect(effect);
stack.setItemMeta(fmeta);
} else {
user.sendMessage(tl("fireworkSyntax"));
throw new Exception(tl("fireworkColor"));
}
}
} else {
throw new NotEnoughArgumentsException();
}
} else {
throw new Exception(tl("holdFirework"));
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
// Note: this enforces an order of color fade shape effect, which the actual command doesn't have. But that's fine.
if (args.length == 1) {
List<String> options = Lists.newArrayList();
if (args[0].startsWith("color:")) {
String prefix;
if (args[0].contains(",")) {
prefix = args[0].substring(0, args[0].lastIndexOf(',') + 1);
} else {
prefix = "color:";
}
for (DyeColor color : DyeColor.values()) {
options.add(prefix + color.name().toLowerCase() + ",");
}
return options;
}
options.add("clear");
options.add("power");
options.add("color:");
if (user.isAuthorized("essentials.firework.fire")) {
options.add("fire");
}
return options;
} else if (args.length == 2) {
if (args[0].equals("power")) {
return Lists.newArrayList("1", "2", "3", "4");
} else if (args[0].equals("fire")) {
return Lists.newArrayList("1");
} else if (args[0].startsWith("color:")) {
List<String> options = Lists.newArrayList();
if (!args[1].startsWith("fade:")) {
args[1] = "fade:";
}
String prefix;
if (args[1].contains(",")) {
prefix = args[1].substring(0, args[1].lastIndexOf(',') + 1);
} else {
prefix = "fade:";
}
for (DyeColor color : DyeColor.values()) {
options.add(prefix + color.name().toLowerCase() + ",");
}
return options;
} else {
return Collections.emptyList();
}
} else if (args.length == 3 && args[0].startsWith("color:")) {
return Lists.newArrayList("shape:star", "shape:ball", "shape:large", "shape:creeper", "shape:burst");
} else if (args.length == 4 && args[0].startsWith("color:")) {
return Lists.newArrayList("effect:trail", "effect:twinkle", "effect:trail,twinkle", "effect:twinkle,trail");
} else {
return Collections.emptyList();
}
}
}

View File

@ -2,10 +2,12 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.google.common.collect.ImmutableList;
import org.bukkit.GameMode;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
@ -116,4 +118,45 @@ public class Commandgamemode extends EssentialsCommand {
}
return mode;
}
private List<String> STANDARD_OPTIONS = ImmutableList.of("creative", "survival", "adventure", "spectator", "toggle");
@Override
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
if (args.length == 1) {
try {
// Direct command? Don't ask for the mode
matchGameMode(commandLabel);
return getPlayers(server, sender);
} catch (NotEnoughArgumentsException e) {
return STANDARD_OPTIONS;
}
} else if (args.length == 2) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
boolean isDirectGamemodeCommand;
try {
// Direct command?
matchGameMode(commandLabel);
isDirectGamemodeCommand = true;
} catch (NotEnoughArgumentsException ex) {
isDirectGamemodeCommand = false;
}
if (args.length == 1) {
if (user.isAuthorized("essentials.gamemode.others") && isDirectGamemodeCommand) {
return getPlayers(server, user);
} else {
return STANDARD_OPTIONS;
}
} else if (args.length == 2 && user.isAuthorized("essentials.gamemode.others") && !isDirectGamemodeCommand) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
}

View File

@ -5,6 +5,9 @@ import com.earth2me.essentials.User;
import org.bukkit.Location;
import org.bukkit.Server;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -43,4 +46,22 @@ public class Commandgetpos extends EssentialsCommand {
sender.sendMessage(tl("distance", coords.distance(distance)));
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1 && user.isAuthorized("essentials.getpos.others")) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -5,11 +5,14 @@ import com.earth2me.essentials.MetaItemStack;
import com.earth2me.essentials.User;
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
import com.earth2me.essentials.utils.NumberUtil;
import com.google.common.collect.Lists;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.inventory.ItemStack;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -99,4 +102,19 @@ public class Commandgive extends EssentialsCommand {
giveTo.getBase().updateInventory();
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else if (args.length == 2) {
return getItems();
} else if (args.length == 3) {
return Lists.newArrayList("1", "64"); // TODO: get actual max size
} else if (args.length == 4) {
return Lists.newArrayList("0");
} else {
return Collections.emptyList();
}
}
}

View File

@ -2,11 +2,15 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
import com.google.common.collect.Lists;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -45,4 +49,13 @@ public class Commandhat extends EssentialsCommand {
}
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
if (args.length == 1) {
return Lists.newArrayList("remove", "wear"); // "wear" isn't real
} else {
return Collections.emptyList();
}
}
}

View File

@ -8,6 +8,9 @@ import org.bukkit.event.entity.EntityRegainHealthEvent;
import org.bukkit.event.entity.EntityRegainHealthEvent.RegainReason;
import org.bukkit.potion.PotionEffect;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -76,4 +79,22 @@ public class Commandheal extends EssentialsLoopCommand {
player.removePotionEffect(effect.getType());
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1 && user.isAuthorized("essentials.heal.others")) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -6,6 +6,8 @@ import com.earth2me.essentials.textreader.*;
import com.earth2me.essentials.utils.NumberUtil;
import org.bukkit.Server;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import static com.earth2me.essentials.I18n.tl;
@ -48,4 +50,13 @@ public class Commandhelp extends EssentialsCommand {
protected void run(final Server server, final CommandSource sender, final String commandLabel, final String[] args) throws Exception {
sender.sendMessage(tl("helpConsole"));
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getCommands(server);
} else {
return Collections.emptyList();
}
}
}

View File

@ -6,6 +6,7 @@ import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.FormatUtil;
import org.bukkit.Server;
import java.util.List;
import java.util.logging.Level;
import static com.earth2me.essentials.I18n.tl;
@ -39,4 +40,9 @@ public class Commandhelpop extends EssentialsCommand {
ess.broadcastMessage("essentials.helpop.receive", message);
return message;
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
return null; // Use vanilla handler for message
}
}

View File

@ -7,6 +7,8 @@ import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
@ -94,4 +96,35 @@ public class Commandhome extends EssentialsCommand {
}
user.getTeleport().teleport(loc, charge, TeleportCause.COMMAND);
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
boolean canVisitOthers = user.isAuthorized("essentials.home.others");
if (args.length == 1) {
if (canVisitOthers) {
return getPlayers(server, user);
} else {
List<String> homes = user.getHomes();
if (user.isAuthorized("essentials.home.bed")) {
homes.add("bed");
}
return homes;
}
} else if (args.length == 2 && canVisitOthers) {
try {
User otherUser = getPlayer(server, args, 0, true, true);
List<String> homes = otherUser.getHomes();
if (user.isAuthorized("essentials.home.bed")) {
homes.add("bed");
}
return homes;
} catch (Exception ex) {
// No such user
return Collections.emptyList();
}
} else {
return Collections.emptyList();
}
}
}

View File

@ -3,6 +3,9 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import org.bukkit.Server;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -41,4 +44,13 @@ public class Commandignore extends EssentialsCommand {
}
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
}

View File

@ -4,6 +4,8 @@ import com.earth2me.essentials.User;
import org.bukkit.Server;
import org.bukkit.inventory.Inventory;
import java.util.Collections;
import java.util.List;
public class Commandinvsee extends EssentialsCommand {
public Commandinvsee() {
@ -30,4 +32,16 @@ public class Commandinvsee extends EssentialsCommand {
user.getBase().openInventory(inv);
user.setInvSee(true);
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, user);
} else {
//if (args.length == 2) {
// return Lists.newArrayList("equipped");
//}
return Collections.emptyList();
}
}
}

View File

@ -3,10 +3,13 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.MetaItemStack;
import com.earth2me.essentials.User;
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
import com.google.common.collect.Lists;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import static com.earth2me.essentials.I18n.tl;
@ -67,4 +70,17 @@ public class Commanditem extends EssentialsCommand {
}
user.getBase().updateInventory();
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
if (args.length == 1) {
return getItems();
} else if (args.length == 2) {
return Lists.newArrayList("1", "64"); // TODO: get actual max size
} else if (args.length == 3) {
return Lists.newArrayList("0");
} else {
return Collections.emptyList();
}
}
}

View File

@ -5,6 +5,9 @@ import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -42,4 +45,13 @@ public class Commanditemdb extends EssentialsCommand {
sender.sendMessage(tl("itemNames", ess.getItemDb().names(itemStack)));
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getItems();
} else {
return Collections.emptyList();
}
}
}

View File

@ -3,10 +3,14 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.LocationUtil;
import com.google.common.collect.Lists;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
// This method contains an undocumented sub command #EasterEgg
@ -45,4 +49,14 @@ public class Commandjump extends EssentialsCommand {
user.getTeleport().teleport(loc, charge, TeleportCause.COMMAND);
throw new NoChargeException();
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1 && user.isAuthorized("essentials.jump.lock")) {
// XXX these actually do the same thing
return Lists.newArrayList("lock", "unlock");
} else {
return Collections.emptyList();
}
}
}

View File

@ -6,6 +6,8 @@ import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.FormatUtil;
import org.bukkit.Server;
import java.util.Collections;
import java.util.List;
import java.util.logging.Level;
import static com.earth2me.essentials.I18n.tl;
@ -43,4 +45,13 @@ public class Commandkick extends EssentialsCommand {
server.getLogger().log(Level.INFO, tl("playerKicked", senderName, target.getName(), kickReason));
ess.broadcastMessage("essentials.kick.notify", tl("playerKicked", senderName, target.getName(), kickReason));
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -6,6 +6,9 @@ import org.bukkit.Server;
import org.bukkit.entity.Player;
import org.bukkit.event.entity.EntityDamageEvent;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -43,4 +46,13 @@ public class Commandkill extends EssentialsLoopCommand {
sender.sendMessage(tl("kill", matchPlayer.getDisplayName()));
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -7,6 +7,7 @@ import com.earth2me.essentials.utils.StringUtil;
import org.bukkit.Server;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
@ -99,4 +100,34 @@ public class Commandkit extends EssentialsCommand {
}
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
if (args.length == 1) {
List<String> options = new ArrayList<>();
// TODO: Move all of this to its own method
for (String kitName : ess.getSettings().getKits().getKeys(false)) {
if (!user.isAuthorized("essentials.kits." + kitName)) { // Only check perm, not time or money
continue;
}
options.add(kitName);
}
return options;
} else if (args.length == 2 && user.isAuthorized("essentials.kit.others")) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
if (args.length == 1) {
return new ArrayList<>(ess.getSettings().getKits().getKeys(false)); // TODO: Move this to its own method
} else if (args.length == 2) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -2,9 +2,12 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.google.common.collect.Lists;
import org.bukkit.Server;
import org.bukkit.entity.LightningStrike;
import java.util.Collections;
import java.util.List;
import java.util.HashSet;
import static com.earth2me.essentials.I18n.tl;
@ -49,4 +52,24 @@ public class Commandlightning extends EssentialsLoopCommand {
matchUser.sendMessage(tl("lightningSmited"));
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
if (!user.isAuthorized("essentials.lightning.others")) {
// Can't use any params, including power
return Collections.emptyList();
} else {
return super.getTabCompleteOptions(server, user, commandLabel, args);
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else if (args.length == 2) {
return Lists.newArrayList(Integer.toString(this.power));
} else {
return Collections.emptyList();
}
}
}

View File

@ -116,4 +116,13 @@ public class Commandlist extends EssentialsCommand {
sender.sendMessage(PlayerList.outputFormat(groupName, PlayerList.listUsers(ess, users, ", ")));
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
if (args.length == 1) {
return getGroups();
} else {
return Collections.emptyList();
}
}
}

View File

@ -7,8 +7,10 @@ import com.earth2me.essentials.textreader.SimpleTextInput;
import com.earth2me.essentials.textreader.TextPager;
import com.earth2me.essentials.utils.FormatUtil;
import com.earth2me.essentials.utils.StringUtil;
import com.google.common.collect.Lists;
import org.bukkit.Server;
import java.util.Collections;
import java.util.List;
import java.util.UUID;
@ -140,4 +142,49 @@ public class Commandmail extends EssentialsCommand {
}
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
if (args.length == 1) {
List<String> options = Lists.newArrayList("read", "clear");
if (user.isAuthorized("essentials.mail.send")) {
options.add("send");
}
if (user.isAuthorized("essentials.mail.sendall")) {
options.add("sendall");
}
return options;
} else if (args.length == 2 && args[0].equalsIgnoreCase("send") && user.isAuthorized("essentials.mail.send")) {
return getPlayers(server, user);
} else if (args.length == 2 && args[0].equalsIgnoreCase("read")) {
final List<String> mail = user.getMails();
int pages = mail.size() / 9 + (mail.size() % 9 > 0 ? 1 : 0);
if (pages == 0) {
return Lists.newArrayList("0");
} else {
List<String> options = Lists.newArrayList("1");
if (pages > 1) {
options.add(String.valueOf(pages));
}
return options;
}
} else if ((args.length > 2 && args[0].equalsIgnoreCase("send") && user.isAuthorized("essentials.mail.send")) || (args.length > 1 && args[0].equalsIgnoreCase("sendall") && user.isAuthorized("essentials.mail.sendall"))) {
return null; // Use vanilla handler
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
if (args.length == 1) {
return Lists.newArrayList("send", "sendall");
} else if (args.length == 2 && args[0].equalsIgnoreCase("send")) {
return getPlayers(server, sender);
} else if ((args.length > 2 && args[0].equalsIgnoreCase("send")) || (args.length > 1 && args[0].equalsIgnoreCase("sendall"))) {
return null; // Use vanilla handler
} else {
return Collections.emptyList();
}
}
}

View File

@ -10,6 +10,7 @@ import org.bukkit.World;
import org.bukkit.entity.Player;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import static com.earth2me.essentials.I18n.tl;
@ -90,4 +91,9 @@ public class Commandme extends EssentialsCommand {
ess.getServer().broadcastMessage(tl("action", "@", message));
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
return null; // It's a chat message, use the default chat handler
}
}

View File

@ -10,6 +10,7 @@ import com.earth2me.essentials.utils.FormatUtil;
import org.bukkit.Server;
import java.util.List;
public class Commandmsg extends EssentialsLoopCommand {
@ -52,4 +53,13 @@ public class Commandmsg extends EssentialsLoopCommand {
IMessageRecipient messageSender = sender.isPlayer() ? ess.getUser(sender.getPlayer()) : Console.getInstance();
messageSender.sendMessage(messageReceiver, args[0]); // args[0] is the message.
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else {
return null; // It's a chat message, use the default chat handler
}
}
}

View File

@ -7,6 +7,7 @@ import com.earth2me.essentials.utils.DateUtil;
import net.ess3.api.events.MuteStatusChangeEvent;
import org.bukkit.Server;
import java.util.List;
import java.util.logging.Level;
import static com.earth2me.essentials.I18n.tl;
@ -85,4 +86,13 @@ public class Commandmute extends EssentialsCommand {
}
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else {
return COMMON_DATE_DIFFS; // Date diff can span multiple words
}
}
}

View File

@ -2,10 +2,14 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.google.common.collect.Lists;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -97,4 +101,34 @@ public class Commandnear extends EssentialsCommand {
}
return output.length() > 1 ? output.toString() : tl("none");
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (user.isAuthorized("essentials.near.others")) {
if (args.length == 1) {
return getPlayers(server, user);
} else if (args.length == 2) {
return Lists.newArrayList(Integer.toString(ess.getSettings().getNearRadius()));
} else {
return Collections.emptyList();
}
} else {
if (args.length == 1) {
return Lists.newArrayList(Integer.toString(ess.getSettings().getNearRadius()));
} else {
return Collections.emptyList();
}
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else if (args.length == 2) {
return Lists.newArrayList(Integer.toString(ess.getSettings().getNearRadius()));
} else {
return Collections.emptyList();
}
}
}

View File

@ -8,6 +8,8 @@ import org.bukkit.ChatColor;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import static com.earth2me.essentials.I18n.tl;
@ -112,4 +114,22 @@ public class Commandnick extends EssentialsLoopCommand {
target.setDisplayNick();
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
if (args.length == 1 && user.isAuthorized("essentials.nick.others")) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -9,6 +9,8 @@ import org.bukkit.entity.TNTPrimed;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -47,4 +49,13 @@ public class Commandnuke extends EssentialsCommand {
}
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -7,10 +7,13 @@ import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.NumberUtil;
import com.earth2me.essentials.utils.StringUtil;
import com.google.common.collect.Lists;
import net.ess3.api.MaxMoneyException;
import org.bukkit.Server;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -84,4 +87,15 @@ public class Commandpay extends EssentialsLoopCommand {
sender.sendMessage(e.getMessage());
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else if (args.length == 2) {
return Lists.newArrayList(ess.getSettings().getMinimumPayAmount().toString());
} else {
return Collections.emptyList();
}
}
}

View File

@ -1,5 +1,8 @@
package com.earth2me.essentials.commands;
import org.bukkit.DyeColor;
import com.google.common.collect.Lists;
import com.earth2me.essentials.MetaItemStack;
import com.earth2me.essentials.Potions;
import com.earth2me.essentials.User;
@ -11,6 +14,8 @@ import org.bukkit.inventory.meta.PotionMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.potion.PotionEffectType;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@ -70,4 +75,35 @@ public class Commandpotion extends EssentialsCommand {
throw new Exception(tl("holdPotion"));
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
// Note: this enforces an order of effect power duration splash, which the actual command doesn't have. But that's fine.
if (args.length == 1) {
List<String> options = Lists.newArrayList();
options.add("clear");
if (user.isAuthorized("essentials.potion.apply")) {
options.add("apply");
}
for (Map.Entry<String, PotionEffectType> entry : Potions.entrySet()) {
final String potionName = entry.getValue().getName().toLowerCase(Locale.ENGLISH);
if (user.isAuthorized("essentials.potion." + potionName)) {
options.add("effect:" + entry.getKey());
}
}
return options;
} else if (args.length == 2 && args[0].startsWith("effect:")) {
return Lists.newArrayList("power:1", "power:2", "power:3", "power:4");
} else if (args.length == 3 && args[0].startsWith("effect:")) {
List<String> options = Lists.newArrayList();
for (String duration : COMMON_DURATIONS) {
options.add("duration:" + duration);
}
return options;
} else if (args.length == 4 && args[0].startsWith("effect:")) {
return Lists.newArrayList("splash:true", "splash:false");
} else {
return Collections.emptyList();
}
}
}

View File

@ -3,11 +3,13 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.StringUtil;
import com.google.common.collect.Lists;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
@ -102,4 +104,59 @@ public class Commandpowertool extends EssentialsCommand {
}
user.setPowertool(itemStack, powertools);
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
List<String> options = Lists.newArrayList("d:", "c:", "l:");
if (user.isAuthorized("essentials.powertool.append")) {
for (String command : getCommands(server)) {
options.add("a:" + command);
}
}
try {
final ItemStack itemStack = user.getBase().getItemInHand();
List<String> powertools = user.getPowertool(itemStack);
for (String tool : powertools) {
options.add("r:" + tool);
}
} catch (Exception e) {}
return options;
} else if (args[0].startsWith("a:")) {
return tabCompleteCommand(user.getSource(), server, args[0].substring(2), args, 1);
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else if (args.length == 2) {
return getItems();
} else if (args.length == 3) {
List<String> options = Lists.newArrayList("d:", "c:", "l:");
for (String command : getCommands(server)) {
options.add("a:" + command);
}
try {
final User user = getPlayer(server, args, 0, true, true);
final ItemStack itemStack = ess.getItemDb().get(args[1]);
List<String> powertools = user.getPowertool(itemStack);
for (String tool : powertools) {
options.add("r:" + tool);
}
} catch (Exception e) {}
return options;
} else if (args[2].startsWith("a:")) {
return tabCompleteCommand(sender, server, args[2].substring(2), args, 3);
} else {
return Collections.emptyList();
}
}
}

View File

@ -1,5 +1,7 @@
package com.earth2me.essentials.commands;
import com.google.common.collect.Lists;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.DescParseTickFormat;
@ -183,6 +185,19 @@ public class Commandptime extends EssentialsCommand {
return users;
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
final User user = ess.getUser(sender.getPlayer());
if (args.length == 1) {
return Lists.newArrayList("get", "reset", "sunrise", "day", "morning", "noon", "afternoon", "sunset", "night", "midnight");
} else if (args.length == 2 && (getAliases.contains(args[0]) || user == null || user.isAuthorized("essentials.ptime.others"))) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -1,5 +1,7 @@
package com.earth2me.essentials.commands;
import com.google.common.collect.Lists;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import org.bukkit.Server;
@ -150,4 +152,15 @@ public class Commandpweather extends EssentialsCommand {
return users;
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
return Lists.newArrayList("get", "reset", "storm", "sun");
} else if (args.length == 2 && (getAliases.contains(args[0]) || user == null || user.isAuthorized("essentials.pweather.others"))) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
}

View File

@ -8,6 +8,7 @@ import org.bukkit.Server;
import org.bukkit.inventory.*;
import java.util.HashMap;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
@ -173,4 +174,13 @@ public class Commandrecipe extends EssentialsCommand {
}
return type.toString().replace("_", " ").toLowerCase(Locale.ENGLISH);
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
if (args.length == 1) {
return getItems();
} else {
return Collections.emptyList();
}
}
}

View File

@ -1,5 +1,7 @@
package com.earth2me.essentials.commands;
import com.google.common.collect.Lists;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.Mob;
import com.earth2me.essentials.User;
@ -9,6 +11,7 @@ import org.bukkit.World;
import org.bukkit.entity.*;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
@ -242,6 +245,24 @@ public class Commandremove extends EssentialsCommand {
sender.sendMessage(tl("removed", removed));
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
List<String> options = Lists.newArrayList();
for (ToRemove toRemove : ToRemove.values()) {
options.add(toRemove.name().toLowerCase(Locale.ENGLISH));
}
return options;
} else if (args.length == 2) {
List<String> worlds = Lists.newArrayList();
for (World world : server.getWorlds()) {
worlds.add(world.getName());
}
return worlds;
} else {
return Collections.emptyList();
}
}
private enum ToRemove {
DROPS,

View File

@ -4,12 +4,14 @@ import com.earth2me.essentials.ChargeException;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.StringUtil;
import com.google.common.collect.Lists;
import net.ess3.api.IUser;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
@ -116,4 +118,17 @@ public class Commandrepair extends EssentialsCommand {
repaired.add(itemName.replace('_', ' '));
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
List<String> options = Lists.newArrayList("hand");
if (user.isAuthorized("essentials.repair.all")) {
options.add("all");
}
return options;
} else {
return Collections.emptyList();
}
}
}

View File

@ -3,10 +3,12 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.NumberUtil;
import com.google.common.collect.Lists;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.logging.Level;
@ -97,4 +99,15 @@ public class Commandsell extends EssentialsCommand {
logger.log(Level.INFO, tl("itemSoldConsole", user.getDisplayName(), is.getType().toString().toLowerCase(Locale.ENGLISH), NumberUtil.displayCurrency(result, ess), amount, NumberUtil.displayCurrency(worth, ess)));
return result;
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
return getMatchingItems(args[0]);
} else if (args.length == 2) {
return Lists.newArrayList("1", "64");
} else {
return Collections.emptyList();
}
}
}

View File

@ -2,8 +2,12 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.Kit;
import com.earth2me.essentials.User;
import com.earth2me.essentials.Settings;
import org.bukkit.Server;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import static com.earth2me.essentials.I18n.tl;
@ -29,4 +33,13 @@ public class Commandshowkit extends EssentialsCommand {
}
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
if (args.length == 1) {
return new ArrayList<>(ess.getSettings().getKits().getKeys(false)); // TODO: Move this to its own method
} else {
return Collections.emptyList();
}
}
}

View File

@ -2,11 +2,15 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import com.earth2me.essentials.craftbukkit.InventoryWorkaround;
import com.google.common.collect.Lists;
import org.bukkit.Material;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.meta.SkullMeta;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
public class Commandskull extends EssentialsCommand {
@ -58,4 +62,17 @@ public class Commandskull extends EssentialsCommand {
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
if (user.isAuthorized("essentials.skull.others")) {
return getPlayers(server, user);
} else {
return Lists.newArrayList(user.getName());
}
} else {
return Collections.emptyList();
}
}
}

View File

@ -6,6 +6,7 @@ import com.earth2me.essentials.utils.FloatUtil;
import org.bukkit.Server;
import org.bukkit.entity.Player;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -134,4 +135,22 @@ public class Commandspeed extends EssentialsCommand {
return ratio + defaultSpeed;
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 3 && user.isAuthorized("essentials.speed.others")) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 3) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -7,8 +7,10 @@ import com.earth2me.essentials.utils.DateUtil;
import org.bukkit.BanList;
import org.bukkit.Server;
import java.util.Collections;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.List;
import java.util.logging.Level;
import static com.earth2me.essentials.I18n.tl;
@ -61,4 +63,14 @@ public class Commandtempban extends EssentialsCommand {
server.getLogger().log(Level.INFO, message);
ess.broadcastMessage("essentials.ban.notify", message);
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else {
// Note: following args are both date diffs _and_ messages; ideally we'd mix with the vanilla handler
return COMMON_DATE_DIFFS;
}
}
}

View File

@ -1,9 +1,13 @@
package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import com.google.common.collect.Lists;
import org.bukkit.Server;
import org.bukkit.World;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -30,6 +34,16 @@ public class Commandthunder extends EssentialsCommand {
world.setThundering(setThunder);
user.sendMessage(tl("thunder", setThunder ? tl("enabled") : tl("disabled")));
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
return Lists.newArrayList("true", "false");
} else if (args.length == 2) {
return COMMON_DATE_DIFFS;
} else {
return Collections.emptyList();
}
}
}

View File

@ -4,6 +4,7 @@ import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.DescParseTickFormat;
import com.earth2me.essentials.utils.NumberUtil;
import com.google.common.collect.Lists;
import org.bukkit.Server;
import org.bukkit.World;
@ -162,6 +163,35 @@ public class Commandtime extends EssentialsCommand {
private String normalizeWorldName(World world) {
return world.getName().toLowerCase().replaceAll("\\s+", "_");
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
final User user = ess.getUser(sender.getPlayer());
if (args.length == 1) {
if (user == null || user.isAuthorized("essentials.time.set")) {
return Lists.newArrayList("set", "add");
} else {
return Collections.emptyList();
}
} else if (args.length == 2 && args[0].equalsIgnoreCase("set")) {
return Lists.newArrayList("sunrise", "day", "morning", "noon", "afternoon", "sunset", "night", "midnight");
// TODO: handle tab completion for add
} else if (args.length == 3 && (args[0].equalsIgnoreCase("set") || args[0].equalsIgnoreCase("add"))) {
List<String> worlds = Lists.newArrayList();
for (World world : server.getWorlds()) {
if (user == null || user.isAuthorized("essentials.time.world." + normalizeWorldName(world))) {
worlds.add(world.getName());
}
}
if (user == null || user.isAuthorized("essentials.time.world.all")) {
worlds.add("*");
}
return worlds;
} else {
return Collections.emptyList();
}
}
}

View File

@ -6,6 +6,10 @@ import com.earth2me.essentials.utils.DateUtil;
import net.ess3.api.events.JailStatusChangeEvent;
import org.bukkit.Server;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -93,4 +97,19 @@ public class Commandtogglejail extends EssentialsCommand {
}
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else if (args.length == 2) {
try {
return new ArrayList<>(ess.getJails().getList());
} catch (Exception e) {
return Collections.emptyList();
}
} else {
return COMMON_DATE_DIFFS;
}
}
}

View File

@ -8,6 +8,9 @@ import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -118,4 +121,24 @@ public class Commandtp extends EssentialsCommand {
throw new NotEnoughArgumentsException();
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
// Don't handle coords
if (args.length == 1 || (args.length == 2 && user.isAuthorized("essentials.tp.others"))) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
// Don't handle coords
if (args.length == 1 || args.length == 2) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -3,6 +3,9 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import org.bukkit.Server;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -45,4 +48,13 @@ public class Commandtpa extends EssentialsCommand {
user.sendMessage(tl("requestSent", player.getDisplayName()));
user.sendMessage(tl("typeTpacancel"));
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
}

View File

@ -4,6 +4,9 @@ import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import org.bukkit.Server;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -50,4 +53,13 @@ public class Commandtpaall extends EssentialsCommand {
}
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -3,6 +3,9 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import org.bukkit.Server;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -44,4 +47,13 @@ public class Commandtpahere extends EssentialsCommand {
user.sendMessage(tl("requestSent", player.getDisplayName()));
user.sendMessage(tl("typeTpacancel"));
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
}

View File

@ -6,6 +6,9 @@ import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -45,4 +48,13 @@ public class Commandtpall extends EssentialsCommand {
}
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -5,6 +5,9 @@ import com.earth2me.essentials.User;
import org.bukkit.Server;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -25,4 +28,13 @@ public class Commandtphere extends EssentialsCommand {
user.getTeleport().teleportPlayer(player, user.getBase(), new Trade(this.getName(), ess), TeleportCause.COMMAND);
throw new NoChargeException();
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
}

View File

@ -4,6 +4,9 @@ import com.earth2me.essentials.User;
import org.bukkit.Server;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -42,4 +45,14 @@ public class Commandtpo extends EssentialsCommand {
break;
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
// Don't handle coords
if (args.length == 1 || (args.length == 2 && user.isAuthorized("essentials.tp.others"))) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
}

View File

@ -4,6 +4,9 @@ import com.earth2me.essentials.User;
import org.bukkit.Server;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -28,4 +31,13 @@ public class Commandtpohere extends EssentialsCommand {
// Verify permission
player.getTeleport().now(user.getBase(), false, TeleportCause.COMMAND);
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
}

View File

@ -4,10 +4,15 @@ import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.FloatUtil;
import com.google.common.collect.Lists;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -75,4 +80,40 @@ public class Commandtppos extends EssentialsCommand {
user.getTeleport().teleport(loc, null, TeleportCause.COMMAND);
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1 || args.length == 2 || args.length == 3) {
return Lists.newArrayList("~0");
} else if (args.length == 4 || args.length == 5) {
return Lists.newArrayList("0");
} else if (args.length == 6) {
List<String> worlds = Lists.newArrayList();
for (World world : server.getWorlds()) {
worlds.add(world.getName());
}
return worlds;
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getPlayers(server, sender);
} else if (args.length == 2 || args.length == 3 || args.length == 4) {
return Lists.newArrayList("~0");
} else if (args.length == 5 || args.length == 6) {
return Lists.newArrayList("0");
} else if (args.length == 7) {
List<String> worlds = Lists.newArrayList();
for (World world : server.getWorlds()) {
worlds.add(world.getName());
}
return worlds;
} else {
return Collections.emptyList();
}
}
}

View File

@ -2,10 +2,15 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.LocationUtil;
import com.google.common.collect.Lists;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.TreeType;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import static com.earth2me.essentials.I18n.tl;
public class Commandtree extends EssentialsCommand {
@ -42,4 +47,17 @@ public class Commandtree extends EssentialsCommand {
user.sendMessage(tl("treeFailure"));
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
List<String> options = Lists.newArrayList();
for (TreeType type : TreeType.values()) {
options.add(type.name().toLowerCase(Locale.ENGLISH).replace("_", ""));
}
return options;
} else {
return Collections.emptyList();
}
}
}

View File

@ -12,6 +12,7 @@ import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@ -110,4 +111,28 @@ public class Commandwarp extends EssentialsCommand {
}
owner.getTeleport().warp(user, name, charge, TeleportCause.COMMAND);
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final User user, final String commandLabel, final String[] args) {
if (args.length == 1) {
// Should we be checking "essentials.warp.list" here?
return new ArrayList<>(ess.getWarps().getList());
} else if (args.length == 2 && (user.isAuthorized("essentials.warp.otherplayers") || user.isAuthorized("essentials.warp.others"))) {
//TODO: Remove 'otherplayers' permission.
return getPlayers(server, user);
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(final Server server, final CommandSource sender, final String commandLabel, final String[] args) {
if (args.length == 1) {
return new ArrayList<>(ess.getWarps().getList());
} else if (args.length == 2) {
return getPlayers(server, sender);
} else {
return Collections.emptyList();
}
}
}

View File

@ -2,9 +2,13 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.google.common.collect.Lists;
import org.bukkit.Server;
import org.bukkit.World;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -62,4 +66,32 @@ public class Commandweather extends EssentialsCommand {
sender.sendMessage(isStorm ? tl("weatherStorm", world.getName()) : tl("weatherSun", world.getName()));
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
return Lists.newArrayList("storm", "sun");
} else if (args.length == 2) {
return COMMON_DURATIONS;
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
List<String> worlds = Lists.newArrayList();
for (World world : server.getWorlds()) {
worlds.add(world.getName());
}
return worlds;
} else if (args.length == 2) {
return Lists.newArrayList("storm", "sun");
} else if (args.length == 3) {
return COMMON_DURATIONS;
} else {
return Collections.emptyList();
}
}
}

View File

@ -2,11 +2,13 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
import com.google.common.collect.Lists;
import org.bukkit.Location;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.event.player.PlayerTeleportEvent.TeleportCause;
import java.util.Collections;
import java.util.List;
import static com.earth2me.essentials.I18n.tl;
@ -67,4 +69,20 @@ public class Commandworld extends EssentialsCommand {
user.getTeleport().teleport(target, charge, TeleportCause.COMMAND);
throw new NoChargeException();
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
List<String> worlds = Lists.newArrayList();
for (World world : server.getWorlds()) {
if (ess.getSettings().isWorldTeleportPermissions() && !user.isAuthorized("essentials.worlds." + world.getName())) {
continue;
}
worlds.add(world.getName());
}
return worlds;
} else {
return Collections.emptyList();
}
}
}

View File

@ -3,10 +3,12 @@ package com.earth2me.essentials.commands;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.User;
import com.earth2me.essentials.utils.NumberUtil;
import com.google.common.collect.Lists;
import org.bukkit.Server;
import org.bukkit.inventory.ItemStack;
import java.math.BigDecimal;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
@ -98,4 +100,26 @@ public class Commandworth extends EssentialsCommand {
return result;
}
@Override
protected List<String> getTabCompleteOptions(Server server, User user, String commandLabel, String[] args) {
if (args.length == 1) {
return getMatchingItems(args[0]);
} else if (args.length == 2) {
return Lists.newArrayList("1", "64");
} else {
return Collections.emptyList();
}
}
@Override
protected List<String> getTabCompleteOptions(Server server, CommandSource sender, String commandLabel, String[] args) {
if (args.length == 1) {
return getItems();
} else if (args.length == 2) {
return Lists.newArrayList("1", "64");
} else {
return Collections.emptyList();
}
}
}

View File

@ -1,6 +1,9 @@
package com.earth2me.essentials.commands;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginDescriptionFile;
import com.earth2me.essentials.CommandSource;
import com.earth2me.essentials.PlayerList;
import com.earth2me.essentials.IEssentialsModule;
import com.earth2me.essentials.Trade;
import com.earth2me.essentials.User;
@ -13,9 +16,13 @@ import org.bukkit.command.Command;
import org.bukkit.entity.Player;
import org.bukkit.util.StringUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.UUID;
import java.util.logging.Logger;
@ -264,6 +271,75 @@ public abstract class EssentialsCommand implements IEssentialsCommand {
return players;
}
/**
* Returns a list of all online groups.
*/
protected List<String> getGroups() {
// TODO: A better way to do this
return new ArrayList<>(PlayerList.getPlayerLists(ess, null, true).keySet());
}
/**
* Gets a list of tab-completable items that start with the given name.
* Due to the number of items, this may not return the entire list.
*/
protected List<String> getItems() {
return new ArrayList<>(ess.getItemDb().listNames());
}
/**
* Gets a list of tab-completable items usable for "getMatching".
*/
protected List<String> getMatchingItems(String arg) {
List<String> items = Lists.newArrayList("hand", "inventory", "blocks");
if (!arg.isEmpty()) {
// Emphasize the other items if they haven't entered anything yet.
items.addAll(getItems());
}
return items;
}
/**
* Lists all commands.
*
* TODO: Use the real commandmap to do this automatically.
*/
protected final List<String> getCommands(Server server) {
List<String> commands = Lists.newArrayList();
for (Plugin p : server.getPluginManager().getPlugins()) {
final PluginDescriptionFile desc = p.getDescription();
final Map<String, Map<String, Object>> cmds = desc.getCommands();
if (cmds != null) {
commands.addAll(cmds.keySet());
}
}
return commands;
}
/**
* Attempts to tab-complete a command or its arguments.
*/
protected final List<String> tabCompleteCommand(CommandSource sender, Server server, String label, String[] args, int index) {
// TODO: Pass this to the real commandmap
Command command = server.getPluginCommand(label);
if (command == null) {
return Collections.emptyList();
}
int numArgs = args.length - index - 1;
ess.getLogger().info(numArgs + " " + index + " " + Arrays.toString(args));
String[] effectiveArgs = new String[numArgs];
for (int i = 0; i < numArgs; i++) {
effectiveArgs[i] = args[i + index];
}
if (effectiveArgs.length == 0) {
effectiveArgs = new String[] { "" };
}
ess.getLogger().info(command + " -- " + Arrays.toString(effectiveArgs));
return command.tabComplete(sender.getSender(), label, effectiveArgs);
}
/**
* Common time durations (in seconds), for use in tab completion.
*/