Search in sources :

Example 36 with CommandException

use of net.minecraft.command.CommandException in project RecurrentComplex by Ivorforce.

the class CommandContaining method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    BlockExpression matcher = parameters.rc().expression(new BlockExpression(RecurrentComplex.specialRegistry)).require();
    CommandSearchStructure.postResultMessage(commandSender, RCTextStyle::structure, CommandSearchStructure.search(StructureRegistry.INSTANCE.ids(), name -> containedBlocks(StructureRegistry.INSTANCE.get(name), matcher)));
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) IvBlockCollection(ivorius.ivtoolkit.blocks.IvBlockCollection) BlockExpression(ivorius.reccomplex.utils.expression.BlockExpression) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) ServerTranslations(ivorius.reccomplex.utils.ServerTranslations) CommandBase(net.minecraft.command.CommandBase) BlockPos(net.minecraft.util.math.BlockPos) RCTextStyle(ivorius.reccomplex.commands.RCTextStyle) RCConfig(ivorius.reccomplex.RCConfig) RCExpect(ivorius.reccomplex.commands.parameters.RCExpect) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) List(java.util.List) ICommandSender(net.minecraft.command.ICommandSender) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) Nullable(javax.annotation.Nullable) RCTextStyle(ivorius.reccomplex.commands.RCTextStyle) BlockExpression(ivorius.reccomplex.utils.expression.BlockExpression)

Example 37 with CommandException

use of net.minecraft.command.CommandException in project RecurrentComplex by Ivorforce.

the class CommandSelectFlood method execute.

@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
    RCCommands.assertSize(commandSender, selectionOwner);
    PreloadedBooleanExpression<EnumFacing> facingExpression = PreloadedBooleanExpression.with(exp -> {
        exp.addConstants(EnumFacing.values());
        exp.addEvaluators(axis -> facing -> facing.getAxis() == axis, EnumFacing.Axis.values());
        exp.addEvaluator("horizontal", f -> f.getHorizontalIndex() >= 0);
        exp.addEvaluator("vertical", f -> f.getHorizontalIndex() < 0);
    });
    facingExpression.setExpression(parameters.get().move(2).text().optional().orElse(""));
    List<EnumFacing> available = Arrays.stream(EnumFacing.values()).filter(facingExpression).collect(Collectors.toList());
    List<BlockPos> dirty = Lists.newArrayList(selectionOwner.getSelection());
    Set<BlockPos> visited = Sets.newHashSet(dirty);
    Block dstBlock = parameters.mc().block(commandSender).require();
    int[] dstMeta = parameters.rc().move(1).metadatas().optional().orElse(new int[1]);
    List<IBlockState> dst = IntStream.of(dstMeta).mapToObj(m -> BlockStates.fromMetadata(dstBlock, m)).collect(Collectors.toList());
    while (!dirty.isEmpty()) {
        BlockPos pos = dirty.remove(dirty.size() - 1);
        for (EnumFacing facing : available) {
            BlockPos offset = pos.offset(facing);
            if (RCBlockLogic.isAir(world, offset) && visited.add(offset))
                dirty.add(offset);
        }
        if (visited.size() > MAX_FLOOD)
            throw new CommandException("Area too big to flood!");
    }
    for (BlockPos pos : visited) {
        IBlockState state = dst.get(world.rand().nextInt(dst.size()));
        world.setBlockState(pos, state, 2);
    }
}
Also used : SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) PreloadedBooleanExpression(ivorius.reccomplex.utils.expression.PreloadedBooleanExpression) IntStream(java.util.stream.IntStream) java.util(java.util) RCCommands(ivorius.reccomplex.commands.RCCommands) EnumFacing(net.minecraft.util.EnumFacing) BlockStates(ivorius.ivtoolkit.blocks.BlockStates) ServerTranslations(ivorius.reccomplex.utils.ServerTranslations) BlockPos(net.minecraft.util.math.BlockPos) MockWorld(ivorius.ivtoolkit.world.MockWorld) CommandVirtual(ivorius.reccomplex.commands.CommandVirtual) RCConfig(ivorius.reccomplex.RCConfig) Collectors(java.util.stream.Collectors) Sets(com.google.common.collect.Sets) RCExpect(ivorius.reccomplex.commands.parameters.RCExpect) IBlockState(net.minecraft.block.state.IBlockState) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) Lists(com.google.common.collect.Lists) Block(net.minecraft.block.Block) RCBlockLogic(ivorius.reccomplex.utils.RCBlockLogic) ICommandSender(net.minecraft.command.ICommandSender) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) Nullable(javax.annotation.Nullable) SelectionOwner(ivorius.reccomplex.capability.SelectionOwner) IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) CommandException(net.minecraft.command.CommandException) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos)

Example 38 with CommandException

use of net.minecraft.command.CommandException in project RecurrentComplex by Ivorforce.

the class CommandWriteAll method execute.

@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
    RCParameters parameters = RCParameters.of(args);
    String adapterID = parameters.get().first().require();
    if (!RecurrentComplex.saver.has(adapterID))
        throw ServerTranslations.commandException("commands.rcsaveall.noregistry");
    ResourceDirectory directory = parameters.rc("dir").resourceDirectory().optional().orElse(ResourceDirectory.ACTIVE);
    Optional<FileSaverAdapter<?>> adapterOptional = Optional.ofNullable(RecurrentComplex.saver.get(adapterID));
    Set<String> ids = adapterOptional.map(a -> a.getRegistry().ids()).orElse(Collections.emptySet());
    ResourceExpression resourceExpression = ExpressionCache.of(new ResourceExpression(id -> adapterOptional.map(a -> a.getRegistry().has(id)).orElse(false)), parameters.get().at(1).require());
    int saved = 0, failed = 0;
    for (String id : ids) {
        if (!resourceExpression.test(new RawResourceLocation(adapterOptional.map(a -> a.getRegistry().status(id).getDomain()).orElseThrow(IllegalStateException::new), id)))
            continue;
        boolean success = RecurrentComplex.saver.trySave(directory.toPath(), adapterID, id);
        if (success)
            saved++;
        else
            failed++;
    }
    commandSender.sendMessage(ServerTranslations.format("commands.rcsaveall.result", saved, directory, failed));
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
    RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
}
Also used : RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) ExpressionCache(ivorius.reccomplex.utils.algebra.ExpressionCache) LeveledRegistry(ivorius.reccomplex.files.loading.LeveledRegistry) RCCommands(ivorius.reccomplex.commands.RCCommands) Set(java.util.Set) ServerTranslations(ivorius.reccomplex.utils.ServerTranslations) CommandBase(net.minecraft.command.CommandBase) BlockPos(net.minecraft.util.math.BlockPos) FileSaverAdapter(ivorius.reccomplex.files.saving.FileSaverAdapter) RCConfig(ivorius.reccomplex.RCConfig) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation) RCExpect(ivorius.reccomplex.commands.parameters.RCExpect) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) List(java.util.List) ICommandSender(net.minecraft.command.ICommandSender) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) Optional(java.util.Optional) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) RCParameters(ivorius.reccomplex.commands.parameters.RCParameters) Collections(java.util.Collections) Nullable(javax.annotation.Nullable) ResourceDirectory(ivorius.reccomplex.files.loading.ResourceDirectory) FileSaverAdapter(ivorius.reccomplex.files.saving.FileSaverAdapter) ResourceExpression(ivorius.reccomplex.utils.expression.ResourceExpression) RawResourceLocation(ivorius.reccomplex.utils.RawResourceLocation)

Example 39 with CommandException

use of net.minecraft.command.CommandException in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class PhysSettingsCommand method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    String key = args[0];
    if (key.equals("doSplitting")) {
        if (args.length == 1) {
            sender.addChatMessage(new TextComponentString("doSplitting=" + ValkyrienWarfareMod.doSplitting + " (Default: false)"));
            return;
        } else if (args.length == 2) {
            boolean value = Boolean.parseBoolean(args[1]);
            ValkyrienWarfareMod.doSplitting = value;
            sender.addChatMessage(new TextComponentString("Set physics splitting to " + value));
            return;
        }
    } else if (key.equals("maxShipSize")) {
        if (args.length == 1) {
            sender.addChatMessage(new TextComponentString("maxShipSize=" + ValkyrienWarfareMod.maxShipSize + " (Default: 15000)"));
            return;
        } else if (args.length == 2) {
            int value = Integer.parseInt(args[1]);
            ValkyrienWarfareMod.maxShipSize = value;
            sender.addChatMessage(new TextComponentString("Set maximum ship size to " + value));
            return;
        }
    } else if (key.equals("gravityVector")) {
        if (args.length == 1) {
            sender.addChatMessage(new TextComponentString("gravityVector=" + ValkyrienWarfareMod.gravity.toRoundedString() + " (Default: <0,-9.8,0>)"));
            return;
        } else if (args.length == 4) {
            Vector newVector = new Vector(0, -9.8, 0);
            try {
                if (args[1] != null && args[2] != null && args[3] != null) {
                    newVector.X = Double.parseDouble(args[1]);
                    newVector.Y = Double.parseDouble(args[2]);
                    newVector.Z = Double.parseDouble(args[3]);
                } else {
                    sender.addChatMessage(new TextComponentString("Usage: /physSettings gravityVector <x> <y> <z>"));
                    return;
                }
            } catch (Exception e) {
            }
            ValkyrienWarfareMod.gravity = newVector;
            sender.addChatMessage(new TextComponentString("Physics gravity set to " + newVector.toRoundedString() + " (Default: <0,-9.8,0>)"));
            return;
        } else {
            sender.addChatMessage(new TextComponentString("Usage: /physSettings gravityVector <x> <y> <z>"));
        }
    } else if (key.equals("physicsIterations")) {
        if (args.length == 1) {
            sender.addChatMessage(new TextComponentString("physicsIterations=" + ValkyrienWarfareMod.physIter + " (Default: 10)"));
            return;
        } else if (args.length == 2) {
            int value = Integer.parseInt(args[1]);
            if (value < 0 || value > 1000) {
                sender.addChatMessage(new TextComponentString("Please enter a value between 0 and 1000"));
                return;
            }
            ValkyrienWarfareMod.physIter = value;
            sender.addChatMessage(new TextComponentString("Set physicsIterations to " + value));
            return;
        }
    } else if (key.equals("physicsSpeed")) {
        if (args.length == 1) {
            sender.addChatMessage(new TextComponentString("physicsSpeed=" + ValkyrienWarfareMod.physSpeed + " (Default: 0.05)"));
            return;
        } else if (args.length == 2) {
            double value = Double.parseDouble(args[1]);
            if (value < 0 || value > 1000) {
                sender.addChatMessage(new TextComponentString("Please enter a value between 0 and 1000"));
                return;
            }
            ValkyrienWarfareMod.physSpeed = value;
            sender.addChatMessage(new TextComponentString("Set physicsSpeed to " + value));
            return;
        }
    } else if (key.equals("doGravity")) {
        if (args.length == 1) {
            sender.addChatMessage(new TextComponentString("doGravity=" + PhysicsSettings.doGravity + " (Default: true)"));
            return;
        } else if (args.length == 2) {
            boolean value = Boolean.parseBoolean(args[1]);
            PhysicsSettings.doGravity = value;
            sender.addChatMessage(new TextComponentString("Set doGravity to " + (PhysicsSettings.doGravity ? "enabled" : "disabled")));
            return;
        }
    } else if (key.equals("doPhysicsBlocks")) {
        if (args.length == 1) {
            sender.addChatMessage(new TextComponentString("doPhysicsBlocks=" + PhysicsSettings.doPhysicsBlocks + " (Default: true)"));
            return;
        } else if (args.length == 2) {
            boolean value = Boolean.parseBoolean(args[1]);
            PhysicsSettings.doPhysicsBlocks = value;
            sender.addChatMessage(new TextComponentString("Set doPhysicsBlocks to " + (PhysicsSettings.doPhysicsBlocks ? "enabled" : "disabled")));
            return;
        }
    } else if (key.equals("doBalloons")) {
        if (args.length == 1) {
            sender.addChatMessage(new TextComponentString("doBalloons=" + PhysicsSettings.doBalloons + " (Default: true)"));
            return;
        } else if (args.length == 2) {
            boolean value = Boolean.parseBoolean(args[1]);
            PhysicsSettings.doBalloons = value;
            sender.addChatMessage(new TextComponentString("Set doBalloons to " + (PhysicsSettings.doBalloons ? "enabled" : "disabled")));
            return;
        }
    } else if (key.equals("doAirshipRotation")) {
        if (args.length == 1) {
            sender.addChatMessage(new TextComponentString("doAirshipRotation=" + PhysicsSettings.doAirshipRotation + " (Default: true)"));
            return;
        } else if (args.length == 2) {
            boolean value = Boolean.parseBoolean(args[1]);
            PhysicsSettings.doAirshipRotation = value;
            sender.addChatMessage(new TextComponentString("Set doAirshipRotation to " + (PhysicsSettings.doAirshipRotation ? "enabled" : "disabled")));
            return;
        }
    } else if (key.equals("doAirshipMovement")) {
        if (args.length == 1) {
            sender.addChatMessage(new TextComponentString("doAirshipMovement=" + PhysicsSettings.doAirshipMovement + " (Default: true)"));
            return;
        } else if (args.length == 2) {
            boolean value = Boolean.parseBoolean(args[1]);
            PhysicsSettings.doAirshipMovement = value;
            sender.addChatMessage(new TextComponentString("Set doAirshipMovement to " + (PhysicsSettings.doAirshipMovement ? "enabled" : "disabled")));
            return;
        }
    } else if (key.equals("doEtheriumLifting")) {
        if (args.length == 1) {
            sender.addChatMessage(new TextComponentString("doEtheriumLifting=" + PhysicsSettings.doEtheriumLifting + " (Default: true)"));
            return;
        } else if (args.length == 2) {
            boolean value = Boolean.parseBoolean(args[1]);
            PhysicsSettings.doEtheriumLifting = value;
            sender.addChatMessage(new TextComponentString("Set doEtheriumLifting to " + (PhysicsSettings.doEtheriumLifting ? "enabled" : "disabled")));
            return;
        }
    } else if (key.equals("save")) {
        ValkyrienWarfareMod.instance.saveConfig();
        sender.addChatMessage(new TextComponentString("Saved phyisics settings"));
        return;
    } else if (key.equals("help")) {
        for (String command : completionOptions) {
            sender.addChatMessage(new TextComponentString(command));
        }
    }
    sender.addChatMessage(new TextComponentString(this.getCommandUsage(sender)));
}
Also used : TextComponentString(net.minecraft.util.text.TextComponentString) Vector(ValkyrienWarfareBase.API.Vector) CommandException(net.minecraft.command.CommandException) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 40 with CommandException

use of net.minecraft.command.CommandException in project Galacticraft by micdoodle8.

the class CommandGCHouston method processCommand.

@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
    EntityPlayerMP playerBase = null;
    MinecraftServer server = MinecraftServer.getServer();
    boolean isOp = false;
    Entity entitySender = sender.getCommandSenderEntity();
    if (entitySender == null) {
        isOp = true;
    } else if (entitySender instanceof EntityPlayer) {
        GameProfile prof = ((EntityPlayer) entitySender).getGameProfile();
        isOp = server.getConfigurationManager().canSendCommands(prof);
    }
    if (args.length < 2) {
        try {
            if (args.length == 0) {
                playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
                if (!playerBase.capabilities.isCreativeMode) {
                    if (ConfigManagerCore.challengeMode || !(playerBase.worldObj.provider instanceof IGalacticraftWorldProvider)) {
                        CommandBase.notifyOperators(sender, this, "commands.gchouston.fail");
                        return;
                    }
                }
                if (timerList.contains(playerBase)) {
                    timerList.remove(playerBase);
                } else {
                    timerList.add(playerBase);
                    TickHandlerServer.timerHoustonCommand = 250;
                    String msg = EnumColor.YELLOW + GCCoreUtil.translate("commands.gchouston.confirm.1") + " " + EnumColor.WHITE + GCCoreUtil.translate("commands.gchouston.confirm.2");
                    CommandBase.notifyOperators(sender, this, msg);
                    return;
                }
            } else {
                if (!isOp) {
                    CommandBase.notifyOperators(sender, this, "commands.gchouston.noop");
                    return;
                }
                playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[0], true);
            }
            if (playerBase != null) {
                int dimID = ConfigManagerCore.idDimensionOverworld;
                WorldServer worldserver = server.worldServerForDimension(dimID);
                if (worldserver == null) {
                    worldserver = server.worldServerForDimension(0);
                    if (worldserver == null) {
                        throw new Exception("/gchouston could not find Overworld.");
                    }
                    dimID = 0;
                }
                BlockPos spawnPoint = null;
                BlockPos bedPos = playerBase.getBedLocation(dimID);
                if (bedPos != null) {
                    spawnPoint = EntityPlayer.getBedSpawnLocation(worldserver, bedPos, false);
                }
                if (spawnPoint == null) {
                    spawnPoint = worldserver.getTopSolidOrLiquidBlock(worldserver.getSpawnPoint());
                }
                GCPlayerStats stats = GCPlayerStats.get(playerBase);
                stats.setRocketStacks(new ItemStack[0]);
                stats.setRocketType(IRocketType.EnumRocketType.DEFAULT.ordinal());
                stats.setRocketItem(null);
                stats.setFuelLevel(0);
                stats.setCoordsTeleportedFromX(spawnPoint.getX());
                stats.setCoordsTeleportedFromZ(spawnPoint.getZ());
                stats.setUsingPlanetSelectionGui(false);
                playerBase.closeScreen();
                Vector3 spawnPos = new Vector3(spawnPoint.getX() + 0.5D, spawnPoint.getY() + 0.25D, spawnPoint.getZ() + 0.5D);
                try {
                    WorldUtil.teleportEntitySimple(worldserver, dimID, playerBase, spawnPos);
                } catch (Exception e) {
                    e.printStackTrace();
                    throw e;
                }
                CommandBase.notifyOperators(sender, this, "commands.gchouston.success", new Object[] { String.valueOf(EnumColor.GREY + "" + playerBase.getName()) });
            } else {
                throw new Exception("Could not find player with name: " + args[0]);
            }
        } catch (final Exception var6) {
            throw new CommandException(var6.getMessage(), new Object[0]);
        }
    } else {
        throw new WrongUsageException(GCCoreUtil.translateWithFormat("commands.dimensiontp.too_many", this.getCommandUsage(sender)), new Object[0]);
    }
}
Also used : Entity(net.minecraft.entity.Entity) IGalacticraftWorldProvider(micdoodle8.mods.galacticraft.api.world.IGalacticraftWorldProvider) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) WorldServer(net.minecraft.world.WorldServer) Vector3(micdoodle8.mods.galacticraft.api.vector.Vector3) CommandException(net.minecraft.command.CommandException) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException) MinecraftServer(net.minecraft.server.MinecraftServer) WrongUsageException(net.minecraft.command.WrongUsageException) GameProfile(com.mojang.authlib.GameProfile) EntityPlayer(net.minecraft.entity.player.EntityPlayer) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.BlockPos)

Aggregations

CommandException (net.minecraft.command.CommandException)70 WrongUsageException (net.minecraft.command.WrongUsageException)22 MinecraftServer (net.minecraft.server.MinecraftServer)22 ICommandSender (net.minecraft.command.ICommandSender)18 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)18 RCConfig (ivorius.reccomplex.RCConfig)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)15 TextComponentString (net.minecraft.util.text.TextComponentString)15 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)12 BlockPos (net.minecraft.util.math.BlockPos)11 CommandExpecting (ivorius.mcopts.commands.CommandExpecting)10 Expect (ivorius.mcopts.commands.parameters.expect.Expect)10 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)10 RCCommands (ivorius.reccomplex.commands.RCCommands)9 RCP (ivorius.reccomplex.commands.parameters.RCP)8 List (java.util.List)8 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)8 RCE (ivorius.reccomplex.commands.parameters.expect.RCE)7 Collectors (java.util.stream.Collectors)7 Parameters (ivorius.mcopts.commands.parameters.Parameters)6