From 5b2334c60f78d82bbd2a9ca49a17b5a997cddb45 Mon Sep 17 00:00:00 2001 From: ZeroEpoch1969 <13510767+ZeroEpoch1969@users.noreply.github.com> Date: Mon, 28 Jan 2019 21:57:41 -0700 Subject: [PATCH] Tab completion --- .../totalfreedommod/admin/AdminList.java | 12 +++ .../command/Command_adminmode.java | 14 ++++ .../command/Command_adminworld.java | 49 +++++++++++- .../command/Command_attributelist.java | 2 +- .../totalfreedommod/command/Command_cage.java | 43 ++++++++++- .../command/Command_entitywipe.java | 2 +- .../totalfreedommod/command/Command_gtfo.java | 17 +++++ .../command/Command_invis.java | 13 ++++ .../command/Command_jumppads.java | 34 +++++++++ .../command/Command_masterbuilderworld.java | 31 +++++++- .../command/Command_mbconfig.java | 43 +++++++++++ .../command/Command_mobpurge.java | 25 +++++++ .../command/Command_onlinemode.java | 14 ++++ .../command/Command_playerverify.java | 13 ++++ .../command/Command_plugincontrol.java | 37 ++++++++++ .../command/Command_potion.java | 74 ++++++++++++++++++- .../command/Command_saconfig.java | 49 ++++++++++-- .../totalfreedommod/command/Command_stfu.java | 23 ++++++ .../command/Command_toggle.java | 16 ++++ .../command/Command_trail.java | 14 ++++ .../command/Command_whitelist.java | 46 ++++++++++++ .../command/Command_wiperegions.java | 28 ++++++- .../command/FreedomCommand.java | 24 ++++-- .../totalfreedommod/util/FUtil.java | 21 ++++++ .../totalfreedommod/world/AdminWorld.java | 10 +++ 25 files changed, 632 insertions(+), 22 deletions(-) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java index e125d744..e4e3c343 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/admin/AdminList.java @@ -3,7 +3,9 @@ package me.totalfreedom.totalfreedommod.admin; import com.google.common.base.Function; import com.google.common.collect.Maps; import com.google.common.collect.Sets; +import java.util.ArrayList; import java.util.Date; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.concurrent.TimeUnit; @@ -129,6 +131,16 @@ public class AdminList extends FreedomService return isAdmin(sender); } + public List getActiveAdminNames() + { + List names = new ArrayList(); + for (Admin admin : activeAdmins) + { + names.add(admin.getName()); + } + return names; + } + public boolean isAdmin(CommandSender sender) { if (!(sender instanceof Player)) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminmode.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminmode.java index d8e6c950..83fc7046 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminmode.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminmode.java @@ -1,5 +1,8 @@ package me.totalfreedom.totalfreedommod.command; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -42,4 +45,15 @@ public class Command_adminmode extends FreedomCommand return false; } + + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (args.length == 1 && plugin.al.isAdmin(sender) && !(sender instanceof Player)) + { + return Arrays.asList("on", "off"); + } + + return Collections.emptyList(); + } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java index 0f2b552e..a13e82d2 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_adminworld.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.world.WorldTime; @@ -11,7 +15,7 @@ import org.bukkit.entity.Player; @CommandPermissions(level = Rank.OP, source = SourceType.BOTH) @CommandParameters(description = "Go to the AdminWorld.", - usage = "/ [guest < list | purge | add | remove > | time | weather ]", + usage = "/ [guest < list | purge | add | remove > | time | weather ]", aliases = "aw") public class Command_adminworld extends FreedomCommand { @@ -245,4 +249,47 @@ public class Command_adminworld extends FreedomCommand } } + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (!plugin.al.isAdmin(sender)) + { + return Collections.emptyList(); + } + if (args.length == 1) + { + return Arrays.asList("guest", "time", "weather"); + } + else if (args.length == 2) + { + if (args[0].equals("guest")) + { + return Arrays.asList("add", "remove", "list", "purge"); + } + else if (args[0].equals("time")) + { + return Arrays.asList("morning", "noon", "evening", "night"); + } + else if (args[0].equals("weather")) + { + return Arrays.asList("off", "rain", "storm"); + } + } + else if (args.length == 3) + { + if (args[0].equals("guest")) + { + if (args[1].equals("add")) + { + return FUtil.getPlayerList(); + } + else if (args[1].equals("remove")) + { + return plugin.wm.adminworld.getGuestList(); + } + } + } + return Collections.emptyList(); + } + } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_attributelist.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_attributelist.java index f7dd3bd9..8cb9a189 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_attributelist.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_attributelist.java @@ -7,7 +7,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(level = Rank.OP, source = SourceType.BOTH) -@CommandParameters(description = "Lists all possible enchantments.", usage = "/") +@CommandParameters(description = "Lists all possible attributes.", usage = "/") public class Command_attributelist extends FreedomCommand { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java index 4715d2ae..e3cc3d09 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_cage.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -12,7 +16,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) -@CommandParameters(description = "Place a cage around someone.", usage = "/ [skull | block] [blockname | playername]") +@CommandParameters(description = "Place a cage around someone.", usage = "/ [skull | block] [playername | blockname]") public class Command_cage extends FreedomCommand { @@ -106,4 +110,41 @@ public class Command_cage extends FreedomCommand } return true; } + + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (!plugin.al.isAdmin(sender)) + { + return null; + } + + if (args.length == 1) + { + List arguments = new ArrayList<>(); + arguments.add("purge"); + arguments.addAll(FUtil.getPlayerList()); + return arguments; + } + else if (args.length == 2) + { + if (!args[0].equals("purge")) + { + return Arrays.asList("off", "skull", "block"); + } + } + else if (args.length == 3) + { + if (args[1].equals("block")) + { + return FUtil.getAllMaterialNames(); + } + else if (args[1].equals("skull")) + { + return FUtil.getPlayerList(); + } + } + + return Collections.emptyList(); + } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_entitywipe.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_entitywipe.java index 5fb012b1..2d834163 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_entitywipe.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_entitywipe.java @@ -7,7 +7,7 @@ import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; @CommandPermissions(level = Rank.SUPER_ADMIN, source = SourceType.BOTH) -@CommandParameters(description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/ ", aliases = "ew,rd") +@CommandParameters(description = "Remove various server entities that may cause lag, such as dropped items, minecarts, and boats.", usage = "/", aliases = "ew,rd") public class Command_entitywipe extends FreedomCommand { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gtfo.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gtfo.java index a7b98971..71bbc044 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gtfo.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_gtfo.java @@ -1,6 +1,8 @@ package me.totalfreedom.totalfreedommod.command; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import me.totalfreedom.totalfreedommod.banning.Ban; import me.totalfreedom.totalfreedommod.player.PlayerData; @@ -157,4 +159,19 @@ public class Command_gtfo extends FreedomCommand return true; } + + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (!plugin.al.isAdmin(sender)) + { + return null; + } + + if (args.length == 1) + { + return FUtil.getPlayerList(); + } + return Collections.emptyList(); + } } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invis.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invis.java index fcfa338e..efec2233 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invis.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_invis.java @@ -1,6 +1,8 @@ package me.totalfreedom.totalfreedommod.command; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -63,4 +65,15 @@ public class Command_invis extends FreedomCommand } return true; } + + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (args.length == 1 && plugin.al.isAdmin(sender)) + { + return Arrays.asList("clear"); + } + + return Collections.emptyList(); + } } \ No newline at end of file diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_jumppads.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_jumppads.java index 1fa32024..10ba810c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_jumppads.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_jumppads.java @@ -1,5 +1,13 @@ package me.totalfreedom.totalfreedommod.command; +import com.google.common.collect.ContiguousSet; +import com.google.common.collect.DiscreteDomain; +import com.google.common.collect.Range; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; +import java.util.Set; +import java.util.stream.DoubleStream; import me.totalfreedom.totalfreedommod.fun.Jumppads; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -93,4 +101,30 @@ public class Command_jumppads extends FreedomCommand return true; } + + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (!plugin.al.isAdmin(sender)) + { + return Collections.emptyList(); + } + if (args.length == 1) + { + return Arrays.asList("on", "off", "info", "sideways", "strength"); + } + else if (args.length == 2) + { + if (args[0].equals("sideways")) + { + return Arrays.asList("on", "off"); + } + else if (args[0].equals("strength")) + { + return Arrays.asList("1", "2", "3", "4", "5", "6", "7", "8", "9", "10"); + } + } + + return Collections.emptyList(); + } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderworld.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderworld.java index ef99d575..facbdf3f 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderworld.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_masterbuilderworld.java @@ -1,6 +1,10 @@ package me.totalfreedom.totalfreedommod.command; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import me.totalfreedom.totalfreedommod.rank.Rank; +import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.world.WorldTime; import me.totalfreedom.totalfreedommod.world.WorldWeather; import org.bukkit.World; @@ -10,7 +14,7 @@ import org.bukkit.entity.Player; @CommandPermissions(level = Rank.OP, source = SourceType.BOTH) @CommandParameters(description = "Go to the MasterBuilderWorld.", - usage = "/ [time | weather ]", + usage = "/ [time | weather ]", aliases = "mbw,mbworld") public class Command_masterbuilderworld extends FreedomCommand { @@ -146,6 +150,31 @@ public class Command_masterbuilderworld extends FreedomCommand return true; } + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (!plugin.al.isAdmin(sender)) + { + return Collections.emptyList(); + } + if (args.length == 1) + { + return Arrays.asList("time", "weather"); + } + else if (args.length == 2) + { + if (args[0].equals("time")) + { + return Arrays.asList("morning", "noon", "evening", "night"); + } + else if (args[0].equals("weather")) + { + return Arrays.asList("off", "rain", "storm"); + } + } + return Collections.emptyList(); + } + // TODO: Redo this properly private void assertCommandPerms(CommandSender sender, Player playerSender) throws PermissionDeniedException { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java index 4c93d2b8..b74f2dd6 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mbconfig.java @@ -1,6 +1,10 @@ package me.totalfreedom.totalfreedommod.command; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.Date; +import java.util.List; import me.totalfreedom.totalfreedommod.masterbuilder.MasterBuilder; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; @@ -204,5 +208,44 @@ public class Command_mbconfig extends FreedomCommand } } } + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (sender instanceof Player) + { + if (args.length == 1) + { + List arguments = new ArrayList<>(); + arguments.add("list"); + if (plugin.al.isAdmin(sender)) + { + arguments.add("info"); + } + return arguments; + } + else if (args.length == 2 && args[0].equals("info") && plugin.al.isAdmin(sender)) + { + return plugin.al.getActiveAdminNames(); + } + return Collections.emptyList(); + } + else + { + if (args.length == 1) + { + return Arrays.asList("add", "remove", "reload", "list", "info"); + } + else if (args.length == 2) + { + if (args[0].equals("add") || args[0].equals("remove") || args[0].equals("setrank") || args[0].equals("info")) + { + return FUtil.getPlayerList(); + } + } + } + + return Collections.emptyList(); + } + } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mobpurge.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mobpurge.java index 2e7add6a..6d792349 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mobpurge.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_mobpurge.java @@ -1,6 +1,10 @@ package me.totalfreedom.totalfreedommod.command; import com.sk89q.worldedit.blocks.metadata.MobType; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; import me.totalfreedom.totalfreedommod.util.Groups; @@ -80,4 +84,25 @@ public class Command_mobpurge extends FreedomCommand return removed; } + + public static List getAllMobNames() + { + List names = new ArrayList<>(); + for (EntityType entityType : Groups.MOB_TYPES) + { + names.add(entityType.name()); + } + return names; + } + + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (args.length == 1) + { + return getAllMobNames(); + } + + return Collections.emptyList(); + } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_onlinemode.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_onlinemode.java index 4fe7c321..4b9171dd 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_onlinemode.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_onlinemode.java @@ -1,5 +1,8 @@ package me.totalfreedom.totalfreedommod.command; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FLog; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -67,4 +70,15 @@ public class Command_onlinemode extends FreedomCommand } return true; } + + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (args.length == 1 && plugin.al.isAdmin(sender) && !(sender instanceof Player)) + { + return Arrays.asList("on", "off"); + } + + return Collections.emptyList(); + } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_playerverify.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_playerverify.java index 93d92e7a..9dcfc018 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_playerverify.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_playerverify.java @@ -1,5 +1,8 @@ package me.totalfreedom.totalfreedommod.command; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import me.totalfreedom.totalfreedommod.playerverification.VPlayer; import me.totalfreedom.totalfreedommod.rank.Rank; import net.pravian.aero.util.Ips; @@ -97,4 +100,14 @@ public class Command_playerverify extends FreedomCommand return false; } } + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (args.length == 1) + { + return Arrays.asList("enable", "disable", "status", "clearips"); + } + + return Collections.emptyList(); + } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plugincontrol.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plugincontrol.java index 5e280560..4f9f6d3d 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plugincontrol.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_plugincontrol.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import me.totalfreedom.totalfreedommod.rank.Rank; import org.apache.commons.lang3.StringUtils; import org.bukkit.ChatColor; @@ -126,6 +130,39 @@ public class Command_plugincontrol extends FreedomCommand return false; } + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (!plugin.al.isAdmin(sender)) + { + return Collections.emptyList(); + } + if (args.length == 1) + { + return Arrays.asList("enable", "disable", "reload", "list"); + } + else if (args.length == 2) + { + if (!args[0].equals("list")) + { + return getAllPluginNames(); + } + } + + return Collections.emptyList(); + } + + public List getAllPluginNames() + { + List names = new ArrayList<>(); + for (Plugin plugin : server.getPluginManager().getPlugins()) + { + names.add(plugin.getName()); + } + names.remove(plugin.getName()); + return names; + } + public Plugin getPlugin(String name) { for (Plugin serverPlugin : server.getPluginManager().getPlugins()) diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_potion.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_potion.java index 24e0bb61..f1bf6066 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_potion.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_potion.java @@ -1,6 +1,8 @@ package me.totalfreedom.totalfreedommod.command; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; import java.util.List; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -71,7 +73,7 @@ public class Command_potion extends FreedomCommand { if (!plugin.al.isAdmin(sender)) { - msg("Only superadmins can clear potion effects from other players."); + msg(ChatColor.RED + "Only admins can clear potion effects from other players."); return true; } } @@ -115,7 +117,7 @@ public class Command_potion extends FreedomCommand { if (!plugin.al.isAdmin(sender)) { - sender.sendMessage("Only superadmins can apply potion effects to other players."); + sender.sendMessage(ChatColor.RED + "Only admins can apply potion effects to other players."); return true; } } @@ -177,4 +179,72 @@ public class Command_potion extends FreedomCommand } return true; } + + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (args.length == 1) + { + List arguments = new ArrayList<>(); + arguments.addAll(Arrays.asList("list", "clear", "add")); + if (plugin.al.isAdmin(sender)) + { + arguments.add("clearall"); + } + return arguments; + } + else if (args.length == 2) + { + if (args[0].equals("clear")) + { + if (plugin.al.isAdmin(sender)) + { + return FUtil.getPlayerList(); + } + } + else if (args[0].equals("add")) + { + return getAllPotionTypes(); + } + } + else if (args.length == 3) + { + if (args[0].equals("add")) + { + return Arrays.asList(""); + } + } + else if (args.length == 4) + { + if (args[0].equals("add")) + { + return Arrays.asList(""); + } + } + else if (args.length == 5 && plugin.al.isAdmin(sender)) + { + if (args[0].equals("add")) + { + return FUtil.getPlayerList(); + } + } + + + + return Collections.emptyList(); + } + + public List getAllPotionTypes() + { + List types = new ArrayList<>(); + for (PotionEffectType potionEffectType : PotionEffectType.values()) + { + if (potionEffectType != null) + { + types.add(potionEffectType.getName()); + } + } + return types; + } + } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java index 0f88d3e6..0eaa8b4b 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_saconfig.java @@ -1,6 +1,8 @@ package me.totalfreedom.totalfreedommod.command; +import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.Date; import java.util.List; import me.totalfreedom.totalfreedommod.admin.Admin; @@ -84,7 +86,7 @@ public class Command_saconfig extends FreedomCommand if (!rank.isAtLeast(Rank.SUPER_ADMIN)) { - msg("Rank must be superadmin or higher.", ChatColor.RED); + msg("Rank must be Super Admin or higher.", ChatColor.RED); return true; } @@ -304,9 +306,46 @@ public class Command_saconfig extends FreedomCommand } } - /*@Override - public List tabComplete(CommandSender sender, Command command, String alias, String[] args) + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) { - return Arrays.asList("list", "clean", "reload", "setrank", "add", "remove", "info"); - }*/ + if (sender instanceof Player) + { + if (args.length == 1) + { + List arguments = new ArrayList<>(); + arguments.add("list"); + if (plugin.al.isAdmin(sender)) + { + arguments.add("info"); + } + return arguments; + } + else if (args.length == 2 && args[0].equals("info") && plugin.al.isAdmin(sender)) + { + return plugin.al.getActiveAdminNames(); + } + return Collections.emptyList(); + } + else + { + if (args.length == 1) + { + return Arrays.asList("add", "remove", "clean", "reload", "setrank", "info", "list"); + } + else if (args.length == 2) + { + if (args[0].equals("add") || args[0].equals("remove") || args[0].equals("setrank") || args[0].equals("info")) + { + return FUtil.getPlayerList(); + } + } + else if (args.length == 3 && args[0].equals("setrank")) + { + return Arrays.asList("super_admin", "telnet_admin", "senior_admin"); + } + } + + return Collections.emptyList(); + } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stfu.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stfu.java index fb1f6cc9..647bb011 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stfu.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_stfu.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import me.totalfreedom.totalfreedommod.player.FPlayer; import me.totalfreedom.totalfreedommod.punishments.Punishment; import me.totalfreedom.totalfreedommod.punishments.PunishmentType; @@ -150,4 +154,23 @@ public class Command_stfu extends FreedomCommand return true; } + + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (!plugin.al.isAdmin(sender)) + { + return null; + } + + if (args.length == 1) + { + List arguments = new ArrayList<>(); + arguments.addAll(FUtil.getPlayerList()); + arguments.addAll(Arrays.asList("list", "purge", "all")); + return arguments; + } + + return Collections.emptyList(); + } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java index f37da7f1..5079f342 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_toggle.java @@ -1,5 +1,8 @@ package me.totalfreedom.totalfreedommod.command; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import me.totalfreedom.totalfreedommod.GameRuleHandler; import me.totalfreedom.totalfreedommod.config.ConfigEntry; import me.totalfreedom.totalfreedommod.rank.Rank; @@ -160,5 +163,18 @@ public class Command_toggle extends FreedomCommand { msg(name + " now " + (entry.setBoolean(!entry.getBoolean()) ? "enabled." : "disabled.")); } + + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (args.length == 1) + { + return Arrays.asList( + "waterplace", "fireplace", "lavaplace", "fluidspread", "lavadmg", "firespread", "frostwalk", + "firework", "prelog", "lockdown", "petprotect", "entitywipe", "nonuke", "explosives"); + } + + return Collections.emptyList(); + } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_trail.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_trail.java index d6cd07c5..a723133c 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_trail.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_trail.java @@ -1,5 +1,8 @@ package me.totalfreedom.totalfreedommod.command; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import me.totalfreedom.totalfreedommod.rank.Rank; import org.bukkit.command.Command; import org.bukkit.command.CommandSender; @@ -27,4 +30,15 @@ public class Command_trail extends FreedomCommand return true; } + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (args.length == 1 && plugin.al.isAdmin(sender)) + { + return Arrays.asList("off"); + } + + return Collections.emptyList(); + } + } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whitelist.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whitelist.java index ecef19c6..9ae7d418 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whitelist.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_whitelist.java @@ -1,5 +1,9 @@ package me.totalfreedom.totalfreedommod.command; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.DepreciationAggregator; import me.totalfreedom.totalfreedommod.util.FUtil; @@ -160,4 +164,46 @@ public class Command_whitelist extends FreedomCommand } return false; } + + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (args.length == 1) + { + List arguments = new ArrayList<>(); + arguments.addAll(Arrays.asList("list", "count")); + if (plugin.al.isAdmin(sender)) + { + arguments.addAll(Arrays.asList("on", "off", "add", "remove", "addall")); + if (!(sender instanceof Player)) + { + arguments.add("purge"); + } + } + return arguments; + } + else if (args.length == 2 && plugin.al.isAdmin(sender)) + { + if (args[0].equals("add")) + { + return FUtil.getPlayerList(); + } + else if (args[0].equals("remove")) + { + return getWhitelistedNames(); + } + } + + return Collections.emptyList(); + } + + public List getWhitelistedNames() + { + List names = new ArrayList<>(); + for (Object name : plugin.si.getWhitelisted()) + { + names.add(String.valueOf(name)); + } + return names; + } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wiperegions.java b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wiperegions.java index 0cb3a15f..bf6be296 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wiperegions.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/Command_wiperegions.java @@ -1,5 +1,8 @@ package me.totalfreedom.totalfreedommod.command; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import me.totalfreedom.totalfreedommod.rank.Rank; import me.totalfreedom.totalfreedommod.util.FUtil; import org.bukkit.ChatColor; @@ -32,10 +35,6 @@ public class Command_wiperegions extends FreedomCommand msg("There is no world named \"" + args[0] + "\"", ChatColor.RED); return true; } - if (world.equals(plugin.wm.adminworld.getWorld())) - { - checkRank(Rank.SENIOR_ADMIN); - } int regionsWiped = plugin.wgb.wipeRegions(world); @@ -51,4 +50,25 @@ public class Command_wiperegions extends FreedomCommand return true; } } + + public List getAllWorldNames() + { + List names = new ArrayList<>(); + for (World world : server.getWorlds()) + { + names.add(world.getName()); + } + return names; + } + + @Override + public List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) + { + if (args.length == 1) + { + return getAllWorldNames(); + } + + return Collections.emptyList(); + } } diff --git a/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java b/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java index 5e304115..bc3347ce 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/command/FreedomCommand.java @@ -1,9 +1,8 @@ package me.totalfreedom.totalfreedommod.command; import com.earth2me.essentials.CommandSource; +import com.earth2me.essentials.User; import com.google.common.collect.Lists; -import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import lombok.Getter; @@ -28,7 +27,6 @@ public abstract class FreedomCommand extends AbstractCommandBase tabComplete(CommandSender sender, Command command, String alias, String[] args) { - return Arrays.asList("x", "d"); + return null; }*/ + // Doesn't need to do any starts-with checks + protected List getTabCompleteOptions(CommandSender sender, Command command, String alias, String[] args) { + return null; + } + + @Override + public List tabComplete(CommandSender sender, Command command, String alias, String[] args) + { + List options = getTabCompleteOptions(sender, command, alias, args); + if (options == null) { + return null; + } + return StringUtil.copyPartialMatches(args[args.length - 1], options, Lists.newArrayList()); + } + + protected abstract boolean run(final CommandSender sender, final Player playerSender, final Command cmd, final String commandLabel, final String[] args, final boolean senderIsConsole); protected void checkConsole() { diff --git a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java index 2f3544b5..92ae1a49 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/util/FUtil.java @@ -29,6 +29,7 @@ import org.bukkit.OfflinePlayer; import org.bukkit.command.CommandSender; import org.bukkit.entity.Player; import org.bukkit.scheduler.BukkitTask; +import org.bukkit.Material; public class FUtil { @@ -84,6 +85,26 @@ public class FUtil return ConfigEntry.SERVER_OWNERS.getStringList().contains(name) || ConfigEntry.SERVER_EXECUTIVES.getStringList().contains(name); } + public static List getPlayerList() + { + List names = new ArrayList<>(); + for (Player player : Bukkit.getOnlinePlayers()) + { + names.add(player.getName()); + } + return names; + } + + public static List getAllMaterialNames() + { + List names = new ArrayList<>(); + for (Material material : Material.values()) + { + names.add(material.name()); + } + return names; + } + public static void bcastMsg(String message, ChatColor color) { FLog.info(message, true); diff --git a/src/main/java/me/totalfreedom/totalfreedommod/world/AdminWorld.java b/src/main/java/me/totalfreedom/totalfreedommod/world/AdminWorld.java index 5d1bf292..2d478563 100644 --- a/src/main/java/me/totalfreedom/totalfreedommod/world/AdminWorld.java +++ b/src/main/java/me/totalfreedom/totalfreedommod/world/AdminWorld.java @@ -107,6 +107,16 @@ public final class AdminWorld extends CustomWorld return player; } + public List getGuestList() + { + List guests = new ArrayList<>(); + for (Player guest : guestList.keySet()) + { + guests.add(guest.getName()); + } + return guests; + } + public Player removeGuest(String partialName) { partialName = partialName.toLowerCase();