本文整理匯總了Java中net.minecraft.command.ICommand類的典型用法代碼示例。如果您正苦於以下問題:Java ICommand類的具體用法?Java ICommand怎麽用?Java ICommand使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
ICommand類屬於net.minecraft.command包,在下文中一共展示了ICommand類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: execute
import net.minecraft.command.ICommand; //導入依賴的package包/類
/**
* Callback for when the command is executed
*/
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
if(args.length < 1)
{
sender.addChatMessage(new TextComponentString(CommandBase.joinNiceStringFromCollection(commandMap.keySet())));
}
else
{
ICommand cmd = getCommandMap().get(args[0]);
if(cmd == null)
{
throw new CommandException("commands.tree_base.invalid_cmd", args[0]);
}
else if(!cmd.checkPermission(server, sender))
{
throw new CommandException("commands.generic.permission");
}
else
{
cmd.execute(server, sender, shiftArgs(args));
}
}
}
示例2: execute
import net.minecraft.command.ICommand; //導入依賴的package包/類
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length == 0) {
throw new CommandException("nosubcommandspecified");
}
final Optional<CommandBase> first = childCommands
.stream()
.sorted(Comparator.comparing(ICommand::getCommandName))
.filter(command -> command.getCommandName().equals(args[0]))
.findFirst();
if (!first.isPresent()) {
throw new CommandException("nosuchsubcommand");
}
final CommandBase commandBase = first.get();
final String[] parameters = Arrays.copyOfRange(args, 1, args.length);
commandBase.execute(server, sender, parameters);
}
示例3: getTabCompletionOptions
import net.minecraft.command.ICommand; //導入依賴的package包/類
@Override
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos pos) {
if (args.length <= 1) {
return childCommands
.stream()
.map(ICommand::getCommandName)
.sorted()
.filter(command -> command.startsWith(args[0]))
.collect(Collectors.toList());
}
final Optional<CommandBase> first = childCommands
.stream()
.sorted(Comparator.comparing(ICommand::getCommandName))
.filter(command -> command.getCommandName() == args[0])
.findFirst();
if (!first.isPresent()) {
return Lists.newArrayList();
}
final String[] parameters = Arrays.copyOfRange(args, 1, args.length - 2);
return first.get().getTabCompletionOptions(server, sender, parameters, pos);
}
示例4: CommandHandler
import net.minecraft.command.ICommand; //導入依賴的package包/類
public CommandHandler(TickDynamicMod mod) {
this.mod = mod;
aliases = new ArrayList<String>();
aliases.add("tickdynamic");
aliases.add("td");
subCommandHandlers = new HashMap<String, ICommand>();
subCommandHandlers.put("reload", new CommandReload(mod));
subCommandHandlers.put("reloadgroups", new CommandReloadGroups(mod));
subCommandHandlers.put("listworlds", new CommandListWorlds(mod));
subCommandHandlers.put("world", new CommandWorld(mod));
subCommandHandlers.put("enabled", new CommandEnabled(mod));
StringBuilder builderSubCommands = new StringBuilder();
SubCommands[] subs = SubCommands.values();
for(SubCommands command : subs) {
builderSubCommands.append(command).append(", ");
}
builderSubCommands.delete(builderSubCommands.length()-2, builderSubCommands.length());
listSubCommands = builderSubCommands.toString();
}
示例5: addTabCompletionOptions
import net.minecraft.command.ICommand; //導入依賴的package包/類
@Override
public List addTabCompletionOptions(ICommandSender sender, String[] args) {
if(args.length == 1)
{
List listOut = new LinkedList();
String lastArg = args[args.length-1];
SubCommands[] subCommands = SubCommands.values();
for(SubCommands command : subCommands)
{
if(command.toString().contains(lastArg))
listOut.add(command.toString());
}
return listOut;
}
else
{
//Send it over to subCommand handler
ICommand subHandler = subCommandHandlers.get(args[0]);
if(subHandler == null)
return null;
return subHandler.addTabCompletionOptions(sender, args);
}
}
示例6: unregisterInForge
import net.minecraft.command.ICommand; //導入依賴的package包/類
public void unregisterInForge(ICommand command)
{
Map<String, ICommand> commandMap = this.manager.getCommands();
Set<ICommand> commandSet = this.manager.commandSet;
commandSet.remove(command);
ICommand otherCommand = commandMap.get(command.getCommandName());
if(otherCommand == command)
commandMap.remove(command.getCommandName());
else
for(Map.Entry<String, ICommand> entry: commandMap.entrySet())
{
if(entry.getValue() == command)
{
commandMap.remove(entry.getKey());
break;
}
}
}
示例7: addTabCompletionOptions
import net.minecraft.command.ICommand; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public List addTabCompletionOptions(ICommandSender sender, String[] strings) {
if (strings.length == 1) {
CommandHandler ch = (CommandHandler) MinecraftServer.getServer().getCommandManager();
List<String> ret = new ArrayList<>(ch.getCommands().size());
for (ICommand command : (Collection<ICommand>) ch.getCommands().values()) {
ret.add("cmd." + command.getCommandName());
}
return getListOfStringsFromIterableMatchingLastWord(strings, ret);
} else if (strings.length == 2) {
Collection<String> groupKeys = PermissionManager.getGroupNames();
return getListOfStringsMatchingLastWord(strings, groupKeys.toArray(new String[groupKeys.size()]));
} else {
return null;
}
}
示例8: isCommandInList
import net.minecraft.command.ICommand; //導入依賴的package包/類
/**
* Checks to see if a command is in the whole list.
* @param testedCommand The command to check to see if it exists.
* @return Whether or not the command exists.
*/
public boolean isCommandInList(ICommand testedCommand)
{
ICommand[] commands = getAllCommands();
if (commands != null)
{
for (ICommand command : commands)
{
if (command == testedCommand)
{
return true;
}
}
}
//Should be put in an else block, but that causes an error for some stupid reason.
return false;
}
示例9: func_71560_a
import net.minecraft.command.ICommand; //導入依賴的package包/類
public ICommand func_71560_a(ICommand p_71560_1_) {
List var2 = p_71560_1_.func_71514_a();
this.field_71562_a.put(p_71560_1_.func_71517_b(), p_71560_1_);
this.field_71561_b.add(p_71560_1_);
if(var2 != null) {
Iterator var3 = var2.iterator();
while(var3.hasNext()) {
String var4 = (String)var3.next();
ICommand var5 = (ICommand)this.field_71562_a.get(var4);
if(var5 == null || !var5.func_71517_b().equals(var4)) {
this.field_71562_a.put(var4, p_71560_1_);
}
}
}
return p_71560_1_;
}
示例10: func_71558_b
import net.minecraft.command.ICommand; //導入依賴的package包/類
public List func_71558_b(ICommandSender p_71558_1_, String p_71558_2_) {
String[] var3 = p_71558_2_.split(" ", -1);
String var4 = var3[0];
if(var3.length == 1) {
ArrayList var8 = new ArrayList();
Iterator var6 = this.field_71562_a.entrySet().iterator();
while(var6.hasNext()) {
Entry var7 = (Entry)var6.next();
if(CommandBase.func_71523_a(var4, (String)var7.getKey()) && ((ICommand)var7.getValue()).func_71519_b(p_71558_1_)) {
var8.add(var7.getKey());
}
}
return var8;
} else {
if(var3.length > 1) {
ICommand var5 = (ICommand)this.field_71562_a.get(var4);
if(var5 != null) {
return var5.func_71516_a(p_71558_1_, func_71559_a(var3));
}
}
return null;
}
}
示例11: getPermissionNodes
import net.minecraft.command.ICommand; //導入依賴的package包/類
@Override
public Collection<Node> getPermissionNodes()
{
HashSet<Node> nodes = new HashSet<>();
MinecraftServer server = MinecraftServer.getServer();
if (server != null)
{
for (Object o : server.getCommandManager().getCommands().values())
{
ICommand command = (ICommand) o;
commands.add(command.getCommandName());
nodes.add(new Node(NAME, command.getCommandName()));
}
}
else
{
nodes.add(new Node(NAME));
}
return nodes;
}
示例12: addCommands
import net.minecraft.command.ICommand; //導入依賴的package包/類
@Override
public void addCommands(Consumer<ICommand> registerCommand) {
registerCommand.accept(new PositionCommand("pos1", this::setPositionOne));
registerCommand.accept(new PositionCommand("pos2", this::setPositionTwo));
registerCommand.accept(new LookPositionCommand("hpos1", this::setPositionOne));
registerCommand.accept(new LookPositionCommand("hpos2", this::setPositionTwo));
registerCommand.accept(new ShiftCommand("shift"));
registerCommand.accept(new ExpandCommand("expand"));
registerCommand.accept(new ContractCommand("contract"));
registerCommand.accept(new SelectionWandCommand());
}
示例13: getTabCompletionOptions
import net.minecraft.command.ICommand; //導入依賴的package包/類
@Override
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos pos)
{
if(args.length == 1)
{
List<String> keys = new ArrayList<String>();
for(ICommand c : getCommandMap().values())
{
if(c.checkPermission(server, sender))
{
keys.add(c.getCommandName());
}
}
Collections.sort(keys, null);
return getListOfStringsMatchingLastWord(args, keys);
}
ICommand cmd = getCommandMap().get(args[0]);
if(cmd != null)
{
return cmd.getTabCompletionOptions(server, sender, shiftArgs(args), pos);
}
return super.getTabCompletionOptions(server, sender, args, pos);
}
示例14: isUsernameIndex
import net.minecraft.command.ICommand; //導入依賴的package包/類
/**
* Return whether the specified command parameter index is a username parameter.
*/
@Override
public boolean isUsernameIndex(String[] args, int index)
{
if(index > 0 && args.length > 1)
{
ICommand cmd = getCommandMap().get(args[0]);
if(cmd != null)
{
return cmd.isUsernameIndex(shiftArgs(args), index - 1);
}
}
return false;
}
示例15: commandArguments
import net.minecraft.command.ICommand; //導入依賴的package包/類
public static void commandArguments(Expect e, Function<Parameters, Parameter<String>> start)
{
e.nextRaw((server1, sender, params, pos1) ->
{
Parameter<String> commandParameter = start.apply(params);
Optional<ICommand> other = commandParameter.tryGet().map(server1.getCommandManager().getCommands()::get);
return other.map(c -> c.getTabCompletions(server1, sender, commandParameter.move(1).to(NaP::varargs).get(), pos1)).orElse(Collections.emptyList());
}).descriptionU("args...");
}