Java 类net.minecraft.command.CommandBase 实例源码

项目:CustomWorldGen    文件:CommandTreeBase.java   
/**
 * 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));
        }
    }
}
项目:ShearMadness    文件:ShearMadnessCommand.java   
@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);
}
项目:ShearMadness    文件:ShearMadnessCommand.java   
@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);
}
项目:blockbuster    文件:SubCommandBase.java   
/**
 * Execute the command
 *
 * This method basically delegates the execution to the matched sub-command,
 * if the command was found, otherwise it shows usage message. */
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
    {
        throw new WrongUsageException(this.getCommandUsage(sender));
    }

    CommandBase command = this.subcommands.get(args[0]);

    if (args.length == 2 && args[1].equals("-h"))
    {
        throw new WrongUsageException(command.getCommandUsage(sender));
    }

    if (command != null)
    {
        command.execute(server, sender, dropFirstArgument(args));

        return;
    }

    throw new WrongUsageException(this.getCommandUsage(sender));
}
项目:blockbuster    文件:CommandAction.java   
/**
 * Create an actor from command line arguments (i.e. String array).
 * Description of every element in array:
 *
 * 1. Ignored (since it's filename)
 * 2. Name tag
 * 3. Model name
 * 4. Skin resource location
 * 5. Invincible flag (boolean)
 *
 * And of course, all of those arguments are optional (i.e. have default
 * values).
 */
public static EntityActor actorFromArgs(String[] args, World world) throws CommandException
{
    EntityActor actor = null;

    String name = args.length >= 2 ? args[1] : "";
    String model = args.length >= 3 ? args[2] : "";
    String skin = args.length >= 4 ? args[3] : "";
    boolean invincible = args.length >= 5 ? CommandBase.parseBoolean(args[4]) : false;

    actor = new EntityActor(world);
    actor.modify(MorphUtils.morphFromModel(model, skin), false, false, true);
    actor.setEntityInvulnerable(invincible);
    actor.setCustomNameTag(name);

    return actor;
}
项目:blockbuster    文件:SubCommandActionRecord.java   
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 1)
    {
        throw new WrongUsageException(this.getCommandUsage(sender));
    }

    EntityPlayer player = getCommandSenderAsPlayer(sender);

    if (args.length >= 4)
    {
        BlockPos pos = CommandBase.parseBlockPos(sender, args, 1, false);
        TileEntity tile = sender.getEntityWorld().getTileEntity(pos);

        if (tile instanceof TileEntityDirector)
        {
            ((TileEntityDirector) tile).startRecording(args[0], player);
        }
    }
    else
    {
        CommonProxy.manager.startRecording(args[0], player, Mode.ACTIONS, true, null);
    }
}
项目:TaleCraft    文件:RenameCommand.java   
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    EntityPlayerMP player = CommandBase.getCommandSenderAsPlayer(sender);

    if(args.length == 0) {
        throw new WrongUsageException("No parameters given!");
    }

    String newName = Strings.join(args, " ").trim();

    if(newName.isEmpty()) {
        return;
    }

    ItemStack itemStack = player.getHeldItemMainhand();

    if(itemStack != null) {
        itemStack.setStackDisplayName(newName);
    }
}
项目:TaleCraft    文件:WandCommand.java   
private void execute_expand(String[] args, EntityPlayerMP player, ICommandSender sender) throws CommandException {
    if(args.length == 2) {
        int value = CommandBase.parseInt(args[1]);

        int[] bounds = WandItem.getBoundsFromPlayerOrNull(player);
        if(bounds == null) {
            throw new WrongUsageException("You didn't select a region with your wand.");
        }

        int ix = bounds[0] - value;
        int iy = bounds[1] - value;
        int iz = bounds[2] - value;
        int ax = bounds[3] + value;
        int ay = bounds[4] + value;
        int az = bounds[5] + value;

        WandItem.setBounds(player, ix, iy, iz, ax, ay, az);
        return;
    } else {
        throw new WrongUsageException("Missing parameters! /tc_wand expand <val>");
    }
}
项目:TaleCraft    文件:WandCommand.java   
private void execute_expand_h(String[] args, EntityPlayerMP player, ICommandSender sender) throws CommandException {
    if(args.length == 2) {
        int value = CommandBase.parseInt(args[1]);

        int[] bounds = WandItem.getBoundsFromPlayerOrNull(player);
        if(bounds == null) {
            throw new WrongUsageException("You didn't select a region with your wand.");
        }

        int ix = bounds[0] - value;
        int iy = bounds[1];
        int iz = bounds[2] - value;
        int ax = bounds[3] + value;
        int ay = bounds[4];
        int az = bounds[5] + value;

        WandItem.setBounds(player, ix, iy, iz, ax, ay, az);
        return;
    } else {
        throw new WrongUsageException("Missing parameters! /tc_wand expand <val>");
    }
}
项目:TaleCraft    文件:WandCommand.java   
private void execute_expand_v(String[] args, EntityPlayerMP player, ICommandSender sender) throws CommandException {
    if(args.length == 2) {
        int value = CommandBase.parseInt(args[1], 0, 128);

        int[] bounds = WandItem.getBoundsFromPlayerOrNull(player);
        if(bounds == null) {
            throw new WrongUsageException("You didn't select a region with your wand.");
        }

        int ix = bounds[0];
        int iy = bounds[1] - value;
        int iz = bounds[2];
        int ax = bounds[3];
        int ay = bounds[4] + value;
        int az = bounds[5];

        WandItem.setBounds(player, ix, iy, iz, ax, ay, az);
        return;
    } else {
        throw new WrongUsageException("Missing parameters! /tc_wand expand <val>");
    }
}
项目:TaleCraft    文件:ExplosionCommand.java   
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    // Pattern Matching?
    // 0 1 -> [strength]
    // 1 2 -> <entity> [strength]
    // 3 4 -> <x> <y> <z> [strength]


    // entities = PlayerSelector.matchEntities(sender, args[0], Entity.class);

    //      if(args.length != 3) {
    //          throw new CommandException("Wrong number of parameters: " + args.length + " given, 3 needed.");
    //      }

    {
        BlockPos originPos = sender.getPosition();
        CoordinateArg posX = CommandBase.parseCoordinate(originPos.getX(), args[0], false);
        CoordinateArg posY = CommandBase.parseCoordinate(originPos.getY(), args[1], false);
        CoordinateArg posZ = CommandBase.parseCoordinate(originPos.getZ(), args[2], false);
        BlockPos pos = new BlockPos(posX.getAmount(), posY.getAmount(), posZ.getAmount());

        sender.getEntityWorld().createExplosion(null, pos.getX(), pos.getY(), pos.getZ(), 10f, false);
    }
}
项目:TaleCraft    文件:RegionTriggerCommand.java   
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if(args.length != 6) {
        throw new CommandException("Wrong number of parameters: " + args.length + " given, 6 needed.");
    }

    BlockPos originPos = sender.getPosition();

    CoordinateArg minX = CommandBase.parseCoordinate(originPos.getX(), args[0], false);
    CoordinateArg minY = CommandBase.parseCoordinate(originPos.getY(), args[1], false);
    CoordinateArg minZ = CommandBase.parseCoordinate(originPos.getZ(), args[2], false);
    CoordinateArg maxX = CommandBase.parseCoordinate(originPos.getX(), args[3], false);
    CoordinateArg maxY = CommandBase.parseCoordinate(originPos.getY(), args[4], false);
    CoordinateArg maxZ = CommandBase.parseCoordinate(originPos.getZ(), args[5], false);

    int ix = Math.min((int)minX.getAmount(), (int)maxX.getAmount());
    int iy = Math.min((int)minY.getAmount(), (int)maxY.getAmount());
    int iz = Math.min((int)minZ.getAmount(), (int)maxZ.getAmount());
    int ax = Math.max((int)minX.getAmount(), (int)maxX.getAmount());
    int ay = Math.max((int)minY.getAmount(), (int)maxY.getAmount());
    int az = Math.max((int)minZ.getAmount(), (int)maxZ.getAmount());

    Invoke.trigger(new CommandSenderInvokeSource(sender), ix, iy, iz, ax, ay, az, EnumTriggerState.ON);
}
项目:EE3Helper    文件:CommandEE3H.java   
@Override
public List addTabCompletionOptions(ICommandSender commandSender, String[] args)
{
    if (args.length == 1)
    {
        return getListOfStringsFromIterableMatchingLastWord(args, commands);
    } else if (args.length >= 2)
    {
        for (CommandBase command : subCommands)
        {
            if (command.getCommandName().equalsIgnoreCase(args[0]))
            {
                return command.addTabCompletionOptions(commandSender, args);
            }
        }
    }

    return null;
}
项目:ZeldaSwordSkills    文件:CommandSetMagic.java   
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
    if (args.length != 4 || (!("add").equals(args[1]) && !("set").equals(args[1])) || (!("current").equals(args[2]) && !("max").equals(args[2]))) {
        throw new WrongUsageException(getCommandUsage(sender));
    }
    EntityPlayerMP commandSender = CommandBase.getCommandSenderAsPlayer(sender);
    EntityPlayerMP player = CommandBase.getPlayer(sender, args[0]);
    ZSSPlayerInfo info = ZSSPlayerInfo.get(player);
    boolean max = ("max").equals(args[2]);
    boolean add = ("add").equals(args[1]);
    int mp = CommandBase.parseInt(args[3]);
    if (mp < 0 && !add) {
        throw new CommandException("commands.zssmagic.negative", args[2]);
    }
    if (add) {
        mp += (max ? info.getMaxMagic() : info.getCurrentMagic());
    }
    if (max) {
        info.setMaxMagic(mp);
        mp = Math.round(info.getMaxMagic());
    } else {
        info.setCurrentMagic(mp);
        mp = Math.round(info.getCurrentMagic());
    }
    PlayerUtils.sendTranslatedChat(commandSender, "commands.zssmagic.success", player.getName(), args[2], mp);
}
项目:RuneCraftery    文件:CommandHandler.java   
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;
   }
}
项目:GriefGuardian    文件:ActionLogEventHandler.java   
@SubscribeEvent
public void onServerCommand(CommandEvent event){
    EntityPlayerMP player;
    try {
        player = CommandBase.getCommandSenderAsPlayer(event.sender);
    } catch (PlayerNotFoundException e) {
        e.printStackTrace();
        return;
    }
    String cmd = event.command.getCommandName();
    for (String s : event.parameters)
        cmd += " " + s;
    GriefGuardian._dal.logAction(
            player, 
            Actions.COMMAND, 
            (int)Math.floor(player.posX), 
            (int)Math.floor(player.posY), 
            (int)Math.floor(player.posZ), 
            null, 
            cmd
            );
}
项目:OpenBlocks    文件:CommandFlimFlam.java   
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] params) throws CommandException {
    if (params.length != 1 && params.length != 2) throw error("openblocks.misc.command.invalid");

    String playerName = params[0];
    EntityPlayerMP player = CommandBase.getPlayer(server, sender, playerName);

    String effectName = (params.length > 1)? params[1] : null;

    IFlimFlamDescription meta;
    if (effectName == null) {
        meta = CollectionUtils.getRandom(FlimFlamRegistry.instance.getFlimFlams());
        effectName = meta.name();
    } else {
        meta = FlimFlamRegistry.instance.getFlimFlamByName(effectName);
        if (meta == null) throw error("openblocks.misc.command.no_flim_flam");
    }

    if (meta.action().execute(player)) {
        respond(sender, "openblocks.misc.command.flim_flam_source", playerName, effectName);
        if (!player.equals(sender)) respond(player, "openblocks.misc.command.flim_flam_target");
    } else throw error("openblocks.misc.command.flim_flam_failed");
}
项目:OpenBlocks    文件:ElevatorBlockRules.java   
private static List<IBlockState> parseBlockDesc(String blockDesc) throws Exception {
    final List<String> blockDescParts = Splitter.on('#').splitToList(blockDesc);

    final String blockId = blockDescParts.get(0);
    Block block = Block.REGISTRY.getObject(new ResourceLocation(blockId));
    if (block == Blocks.AIR) {
        Log.warn("Can't find block %s", blockId);
        return Collections.emptyList();
    }

    if (blockDescParts.size() == 1) {
        return block.getBlockState().getValidStates();
    } else {
        final String stateDesc = blockDescParts.get(1);
        return ImmutableList.of(CommandBase.convertArgToBlockState(block, stateDesc));
    }
}
项目:minecraft-roguelike    文件:CommandRouteDungeon.java   
public static Coord getLocation(ICommandContext context, List<String> args) throws NumberInvalidException, PlayerNotFoundException{
    ArgumentParser ap = new ArgumentParser(args);

    Coord pos = context.getPos();

    if(ap.match(0, "here") || ap.match(0, "nearby")){
        return new Coord((int) pos.getX(), 0, (int) pos.getZ());
    } else {
        try {
            int x = CommandBase.parseInt(ap.get(0));
            int z = CommandBase.parseInt(ap.get(1));
            return new Coord(x, 0, z);
        } catch (NumberInvalidException e) {
            context.sendMessage("Failure: Invalid Coords: X Z", MessageType.ERROR);
            throw(e);
        }
    }
}
项目:harshencastle    文件:HarshenCastleCommands.java   
@HarshenCommand
public static void pontuslevel(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    EntityPlayer player = args.length == 1 ? CommandBase.getCommandSenderAsPlayer(sender) : CommandBase.getPlayer(server, sender, args[0]);
    String rawInt = args[args.length == 1 ? 0 : 1];
    int i = CommandBase.parseInt(rawInt);
    player.getEntityData().setInteger("PontusBiomeLevel", i);
    HarshenNetwork.sendToPlayer(player, new MessagePacketPlayerHasAccess(player));
    HandlerPontusAllowed.setAllowed(player, i);
    message(sender, "success", player.getName(), i);
}
项目:harshencastle    文件:HarshenCastleCommands.java   
@HarshenCommandTabList
public static List<String> loadstructure_tabList(MinecraftServer server, ICommandSender sender, String[] args,
        BlockPos targetPos)
{
    ArrayList<String> stringList = new ArrayList<>();
    if(args.length == 1)
        for(ICommandStructure structure : ICommandStructure.ALL_STRUCTURES)
            stringList.add(structure.structureName());
    else if(args.length < 5)
         stringList.addAll(CommandBase.getTabCompletionCoordinate(args, 1, targetPos));
    return stringList;
}
项目:harshencastle    文件:GuiXrayPendantScreen.java   
@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException {
    if(keyCode == Keyboard.KEY_TAB)
    {           this.textInput.setMaxStringLength(60);

        ArrayList<String> stringList = new ArrayList<>();
        if(dictonaryList.isEmpty())
        {
            stringList.addAll(CommandBase.getListOfStringsMatchingLastWord(HarshenUtils.listOf(this.textInput.getText()), Block.REGISTRY.getKeys()));
            for(String s : HarshenUtils.getAllOreDictionaryList())
                for(ItemStack stack : OreDictionary.getOres(s))
                    if(Block.getBlockFromItem(stack.getItem()) != Blocks.AIR)
                        stringList.add(s);
            dictonaryList = CommandBase.getListOfStringsMatchingLastWord(HarshenUtils.listOf(this.textInput.getText()), stringList);
        }
        if(!dictonaryList.isEmpty())
            this.textInput.setText(dictonaryList.get(timeOver++%dictonaryList.size()));
    }
    else
    {
        timeOver = 0;
        dictonaryList.clear();
    }

    if(keyCode == Keyboard.KEY_RETURN)
        closeGui();
    this.textInput.textboxKeyTyped(typedChar, keyCode);
    super.keyTyped(typedChar, keyCode);
}
项目:Backmemed    文件:CommandTeleport.java   
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 4)
    {
        throw new WrongUsageException("commands.teleport.usage", new Object[0]);
    }
    else
    {
        Entity entity = getEntity(server, sender, args[0]);

        if (entity.world != null)
        {
            int i = 4096;
            Vec3d vec3d = sender.getPositionVector();
            int j = 1;
            CommandBase.CoordinateArg commandbase$coordinatearg = parseCoordinate(vec3d.xCoord, args[j++], true);
            CommandBase.CoordinateArg commandbase$coordinatearg1 = parseCoordinate(vec3d.yCoord, args[j++], -4096, 4096, false);
            CommandBase.CoordinateArg commandbase$coordinatearg2 = parseCoordinate(vec3d.zCoord, args[j++], true);
            Entity entity1 = sender.getCommandSenderEntity() == null ? entity : sender.getCommandSenderEntity();
            CommandBase.CoordinateArg commandbase$coordinatearg3 = parseCoordinate(args.length > j ? (double)entity1.rotationYaw : (double)entity.rotationYaw, args.length > j ? args[j] : "~", false);
            ++j;
            CommandBase.CoordinateArg commandbase$coordinatearg4 = parseCoordinate(args.length > j ? (double)entity1.rotationPitch : (double)entity.rotationPitch, args.length > j ? args[j] : "~", false);
            doTeleport(entity, commandbase$coordinatearg, commandbase$coordinatearg1, commandbase$coordinatearg2, commandbase$coordinatearg3, commandbase$coordinatearg4);
            notifyCommandListener(sender, this, "commands.teleport.success.coordinates", new Object[] {entity.getName(), Double.valueOf(commandbase$coordinatearg.getResult()), Double.valueOf(commandbase$coordinatearg1.getResult()), Double.valueOf(commandbase$coordinatearg2.getResult())});
        }
    }
}
项目:World-Border    文件:WBCommand.java   
@Override
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, @Nullable BlockPos pos) {
    if (args.length <= 1)
        return CommandBase.getListOfStringsMatchingLastWord(args, getCommandNames());

    String[] players = WorldBorder.SERVER.getAllUsernames();
    return CommandBase.getListOfStringsMatchingLastWord(args, players);
}
项目:CustomWorldGen    文件:CommandTeleport.java   
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 4)
    {
        throw new WrongUsageException("commands.teleport.usage", new Object[0]);
    }
    else
    {
        Entity entity = getEntity(server, sender, args[0]);

        if (entity.worldObj != null)
        {
            int i = 4096;
            Vec3d vec3d = sender.getPositionVector();
            int j = 1;
            CommandBase.CoordinateArg commandbase$coordinatearg = parseCoordinate(vec3d.xCoord, args[j++], true);
            CommandBase.CoordinateArg commandbase$coordinatearg1 = parseCoordinate(vec3d.yCoord, args[j++], -4096, 4096, false);
            CommandBase.CoordinateArg commandbase$coordinatearg2 = parseCoordinate(vec3d.zCoord, args[j++], true);
            Entity entity1 = sender.getCommandSenderEntity() == null ? entity : sender.getCommandSenderEntity();
            CommandBase.CoordinateArg commandbase$coordinatearg3 = parseCoordinate(args.length > j ? (double)entity1.rotationYaw : (double)entity.rotationYaw, args.length > j ? args[j] : "~", false);
            ++j;
            CommandBase.CoordinateArg commandbase$coordinatearg4 = parseCoordinate(args.length > j ? (double)entity1.rotationPitch : (double)entity.rotationPitch, args.length > j ? args[j] : "~", false);
            doTeleport(entity, commandbase$coordinatearg, commandbase$coordinatearg1, commandbase$coordinatearg2, commandbase$coordinatearg3, commandbase$coordinatearg4);
            notifyCommandListener(sender, this, "commands.teleport.success.coordinates", new Object[] {entity.getName(), Double.valueOf(commandbase$coordinatearg.getResult()), Double.valueOf(commandbase$coordinatearg1.getResult()), Double.valueOf(commandbase$coordinatearg2.getResult())});
        }
    }
}
项目:CrystalMod    文件:StringUtils.java   
public static String makeListReadable(Collection<?> list){
    List<String> strings = Lists.newArrayList();
    for(Object obj : list){
        strings.add(""+obj.toString());
    }
    return CommandBase.joinNiceStringFromCollection(strings);
}
项目:TombManyGraves    文件:CommandRemoveFriend.java   
@Override
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) {
    if (sender instanceof EntityPlayer)
    {
        return args.length == 1 ? CommandBase.getListOfStringsMatchingLastWord(args,FriendHandler.getFriendStringListFor(server, ((EntityPlayer)sender).getUniqueID())) : null;
    }
    return args.length == 1 ? CommandBase.getListOfStringsMatchingLastWord(args, server.getAllUsernames()) : null;
}
项目:SignPicture    文件:CommandImage.java   
@Override
public void processSubCommand(final @Nonnull ICommandSender sender, final @Nonnull String[] args) {
    final String joint = CommandBase.func_82360_a(sender, args, 0);
    GuiMain.setContentId(joint);
    CurrentMode.instance.setState(CurrentMode.State.PREVIEW, false);
    if (!(WFrame.getCurrent() instanceof GuiMain))
        Client.openEditor();
}
项目:TombManyGraves-NOT-FOR-1.9.4-    文件:CommandRemoveFriend.java   
@Override
public List<String> getTabCompletionOptions(MinecraftServer server, ICommandSender sender, String[] args, BlockPos pos) {
    if (sender instanceof EntityPlayer)
    {
        return args.length == 1 ? CommandBase.getListOfStringsMatchingLastWord(args,FriendHandler.getFriendStringListFor(server, ((EntityPlayer)sender).getUniqueID())) : null;
    }
    return args.length == 1 ? CommandBase.getListOfStringsMatchingLastWord(args, server.getAllUsernames()) : null;
}
项目:ShearMadness    文件:ShearMadnessMod.java   
@EventHandler
public void onServerStarting(FMLServerStartingEvent event) {
    List<CommandBase> childCommands = Lists.newArrayList();

    MinecraftForge.EVENT_BUS.post(new RegisterShearMadnessCommandEvent(childCommands));

    event.registerServerCommand(new ShearMadnessCommand(childCommands));
}
项目:Aether-Legacy    文件:PlayerAetherEvents.java   
@SubscribeEvent
public void onCommandSentEvent(CommandEvent event)
{
    if (event.getCommand() instanceof CommandClearInventory)
    {
        if (event.getParameters().length <= 1)
        {
            EntityPlayerMP entityplayermp = null;

            try
            {
                entityplayermp = event.getParameters().length == 0 ? CommandBase.getCommandSenderAsPlayer(event.getSender()) : CommandBase.getPlayer(FMLCommonHandler.instance().getMinecraftServerInstance(), event.getSender(), event.getParameters()[0]);
            } 
            catch (Throwable var9)
            {
                return;
            }

            PlayerAether playerAether = PlayerAether.get(entityplayermp);

            if (playerAether != null)
            {
                if (playerAether.accessories.getFieldCount() != 0)
                {
                    playerAether.accessories.clear();

                    CommandBase.notifyCommandListener(entityplayermp, event.getCommand(), "Cleared the accessories of " + entityplayermp.getName(), new Object[] {});
                }
            }
        }
    }
}
项目:blockbuster    文件:SubCommandBase.java   
/**
 * Automated way to output command's and sub-commands' usage messages.
 *
 */
@Override
public String getCommandUsage(ICommandSender sender)
{
    String message = I18n.format(this.getHelp()) + "\n\n";

    for (CommandBase command : this.subcommands.values())
    {
        message += I18n.format(command.getCommandUsage(sender)).split("\n")[0] + "\n";
    }

    return message.trim();
}
项目:blockbuster    文件:SubCommandRecordRemove.java   
@Override
public void executeCommand(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    String filename = args[0];
    int tick = CommandBase.parseInt(args[1], 0);
    Record record = CommandRecord.getRecord(filename);

    if (tick < 0 || tick >= record.actions.size())
    {
        throw new CommandException("record.tick_out_range", tick, record.actions.size() - 1);
    }

    this.removeActions(args, record, tick);
}
项目:blockbuster    文件:SubCommandRecordRemove.java   
/**
 * Remove action(s) from given record at given tick
 */
private void removeActions(String[] args, Record record, int tick) throws CommandException
{
    if (args.length > 2)
    {
        int index = CommandBase.parseInt(args[2]);
        List<Action> actions = record.actions.get(tick);

        if (actions == null)
        {
            throw new CommandException("record.already_empty", args[1], args[0]);
        }

        if (index < 0 && index >= actions.size())
        {
            throw new CommandException("record.index_out_range", index, actions.size() - 1);
        }

        /* Remove action at given tick */
        if (actions.size() <= 1)
        {
            record.actions.set(tick, null);
        }
        else
        {
            actions.remove(index);
        }
    }
    else
    {
        /* Remove all actions at tick */
        record.actions.set(tick, null);
    }

    record.dirty = true;
}
项目:blockbuster    文件:SubCommandRecordAdd.java   
@Override
public void executeCommand(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    String filename = args[0];
    int tick = CommandBase.parseInt(args[1], 0);
    Record record = CommandRecord.getRecord(filename);

    if (tick < 0 || tick >= record.actions.size())
    {
        throw new CommandException("record.tick_out_range", tick);
    }

    if (!Action.TYPES.containsKey(args[2]))
    {
        throw new CommandException("record.wrong_action", args[2]);
    }

    try
    {
        Action action = Action.fromType(Action.TYPES.get(args[2]).byteValue());

        if (args.length > 3)
        {
            action.fromNBT(JsonToNBT.getTagFromJson(CommandMorph.mergeArgs(args, 3)));
        }

        record.addAction(tick, action);
        record.dirty = true;
    }
    catch (Exception e)
    {
        throw new CommandException("record.add", args[2], e.getMessage());
    }
}
项目:Coreder    文件:Coreder.java   
/**
 * Register a command to be automatically be registered on server startup
 *
 * @param command
 *        the {@link CommandBase} to be registered
 */
public static void registerCommand(CommandBase command) {
    if (!commands.contains(command)) {
        echo("Registering chat command: " + command.getCommandName());
        commands.add(command);
    }
    else {
        echo("Chat command already registered: " + command.getCommandName());
    }
}
项目:Coreder    文件:Coreder.java   
/**
 * Unregister a command so it isn't added on server startup
 *
 * @param command
 *        the {@link CommandBase} to be removed
 */
public static void unregisterCommand(CommandBase command) {
    if (commands.contains(command)) {
        echo("Unegistering chat command: " + command.getCommandName());
        commands.remove(command);
    }
    else {
        echo("Chat command already unregistered: " + command.getCommandName());
    }
}
项目:Coreder    文件:Coreder.java   
@SuppressWarnings("javadoc")
@EventHandler
public static final void addCommandsToServer(FMLServerStartingEvent evt) {
    echo("Loading server commands");
    for (CommandBase command : commands) {
        evt.registerServerCommand(command);
        debug("Command registered to server: " + command.getCommandName());
    }
}
项目:WorldBorder-Forge    文件:WBCommand.java   
@Override
public List addTabCompletionOptions(ICommandSender sender, String[] args)
{
    if (args.length <= 1)
        return CommandBase.getListOfStringsFromIterableMatchingLastWord(args, getCommandNames());

    String[] players = WorldBorder.SERVER.getAllUsernames();
    return CommandBase.getListOfStringsMatchingLastWord(args, players);
}
项目:justenoughdimensions    文件:CommandJEDDifficulty.java   
static EnumDifficulty getDifficultyFromCommand(String str) throws CommandException
{
    if (str.equalsIgnoreCase("peaceful") || str.equalsIgnoreCase("p")) { return EnumDifficulty.PEACEFUL; }
    if (str.equalsIgnoreCase("easy")     || str.equalsIgnoreCase("e")) { return EnumDifficulty.EASY;     }
    if (str.equalsIgnoreCase("normal")   || str.equalsIgnoreCase("n")) { return EnumDifficulty.NORMAL;   }
    if (str.equalsIgnoreCase("hard")     || str.equalsIgnoreCase("h")) { return EnumDifficulty.HARD;     }

    return EnumDifficulty.getDifficultyEnum(CommandBase.parseInt(str, 0, 3));
}