Limit max tab completions

This commit is contained in:
Magnus Ulf 2015-05-14 10:21:48 +02:00 committed by Olof Larsson
parent 2a3f625e0e
commit 0bc46a0818
3 changed files with 20 additions and 1 deletions

View File

@ -13,4 +13,5 @@ public class Lang
public static final String COMMAND_NO_SUCH_SUB = "<b>Couldn't find the command <c>%s"; public static final String COMMAND_NO_SUCH_SUB = "<b>Couldn't find the command <c>%s";
public static final String COMMAND_SUGGEST_SUB = "<i>Maybe you could try %s"; public static final String COMMAND_SUGGEST_SUB = "<i>Maybe you could try %s";
public static final String COMMAND_GET_HELP = "<i>Use %s <i>to see commands."; public static final String COMMAND_GET_HELP = "<i>Use %s <i>to see commands.";
public static final String COMMAND_TOO_MANY_TAB_SUGGESTIONS = "<h>%d <b>tab completions available. Be more specific and try again.";
} }

View File

@ -24,6 +24,8 @@ public class MassiveCoreMConf extends Entity<MassiveCoreMConf>
// FIELDS // FIELDS
// -------------------------------------------- // // -------------------------------------------- //
public int maxTabCompletions = 100;
public List<String> aliasesOuterMassiveCore = MUtil.list("massivecore", "mcore"); public List<String> aliasesOuterMassiveCore = MUtil.list("massivecore", "mcore");
public List<String> aliasesOuterMassiveCoreUsys = MUtil.list("usys"); public List<String> aliasesOuterMassiveCoreUsys = MUtil.list("usys");

View File

@ -1,6 +1,7 @@
package com.massivecraft.massivecore.cmd; package com.massivecraft.massivecore.cmd;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections;
import java.util.List; import java.util.List;
import org.bukkit.command.Command; import org.bukkit.command.Command;
@ -8,7 +9,10 @@ import org.bukkit.command.CommandSender;
import org.bukkit.command.PluginIdentifiableCommand; import org.bukkit.command.PluginIdentifiableCommand;
import org.bukkit.plugin.Plugin; import org.bukkit.plugin.Plugin;
import com.massivecraft.massivecore.Lang;
import com.massivecraft.massivecore.MassiveCoreMConf;
import com.massivecraft.massivecore.collections.MassiveList; import com.massivecraft.massivecore.collections.MassiveList;
import com.massivecraft.massivecore.mixin.Mixin;
import com.massivecraft.massivecore.util.MUtil; import com.massivecraft.massivecore.util.MUtil;
import com.massivecraft.massivecore.util.Txt; import com.massivecraft.massivecore.util.Txt;
@ -125,6 +129,7 @@ public class MassiveCoreBukkitCommand extends Command implements PluginIdentifia
if (alias == null) throw new IllegalArgumentException("args must not be null"); if (alias == null) throw new IllegalArgumentException("args must not be null");
List<String> args = new MassiveList<String>(); List<String> args = new MassiveList<String>();
// When several spaces are next to each other, empty elements in the array will occur. // When several spaces are next to each other, empty elements in the array will occur.
// To avoid such whitespace we do the following // To avoid such whitespace we do the following
// NOTE: The last arg can be empty, and will be in many cases. // NOTE: The last arg can be empty, and will be in many cases.
@ -137,7 +142,18 @@ public class MassiveCoreBukkitCommand extends Command implements PluginIdentifia
} }
// Here we add the last element. // Here we add the last element.
args.add(rawArgs[rawArgs.length-1]); args.add(rawArgs[rawArgs.length-1]);
return this.getMassiveCommand().getTabCompletions(args, sender);
List<String> ret = this.getMassiveCommand().getTabCompletions(args, sender);
int retSize = ret.size();
int maxSize = MassiveCoreMConf.get().maxTabCompletions;
if (maxSize > 0 && retSize > maxSize)
{
Mixin.msgOne(sender, Lang.COMMAND_TOO_MANY_TAB_SUGGESTIONS, retSize);
return Collections.emptyList();
}
return ret;
} }
} }