Search in sources :

Example 66 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project watson by totemo.

the class ClientCommandManager method executeCommand.

// --------------------------------------------------------------------------
/**
 * @see net.minecraft.src.ICommandManager#executeCommand(net.minecraft.src.ICommandSender,
 *      java.lang.String)
 *
 *      The JavaDocs for the interface don't currently describe the exact
 *      meaning of the return value. Looking at the code for
 *      {@link net.minecraft.src.CommandHandler} it contains a loop that
 *      applies a command for all players who match a particular name pattern.
 *      The returned value is the number of times that the command was
 *      successfully executed by that loop. Therefore in the case of this
 *      class, it returns 1 on success and 0 on error.
 */
@Override
public int executeCommand(ICommandSender sender, String commandLine) {
    try {
        String[] tokens = getTokens(commandLine);
        String verb = tokens[0];
        ICommand command = getCommand(verb);
        if (command == null) {
            throw new CommandNotFoundException();
        }
        tokens = Arrays.copyOfRange(tokens, 1, tokens.length);
        if (command.canCommandSenderUseCommand(sender)) {
            command.processCommand(sender, tokens);
            return 1;
        } else {
            sendError(sender, new ChatComponentTranslation("commands.generic.permission", new Object[0]));
        }
    } catch (WrongUsageException ex) {
        sendError(sender, new ChatComponentTranslation("commands.generic.usage", new Object[] { new ChatComponentTranslation(ex.getMessage(), ex.getErrorObjects()) }));
    } catch (CommandException ex) {
        sendError(sender, new ChatComponentTranslation(ex.getMessage(), ex.getErrorObjects()));
    } catch (Throwable throwable) {
        sendError(sender, new ChatComponentTranslation("commands.generic.exception", new Object[0]));
        Log.exception(Level.WARNING, "error processing command", throwable);
    }
    return 0;
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) ICommand(net.minecraft.command.ICommand) ChatComponentTranslation(net.minecraft.util.ChatComponentTranslation) CommandException(net.minecraft.command.CommandException) CommandNotFoundException(net.minecraft.command.CommandNotFoundException)

Example 67 with WrongUsageException

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

the class CommandSearchStructure method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    Parameters parameters = Parameters.of(args, expect()::declare);
    List<ToDoubleFunction<String>> ranks = new ArrayList<>();
    consider(ranks, parameters.get(0), Parameter::varargsList, (s, t) -> StructureSearch.searchRank(t, StructureSearch.keywords(StructureRegistry.INSTANCE.id(s), s)));
    consider(ranks, parameters.get("containing"), e -> RCP.expression(e, new BlockExpression(RecurrentComplex.specialRegistry)), StructureSearch::containedBlocks);
    consider(ranks, parameters.get("biome"), MCP::biome, StructureSearch::biome);
    consider(ranks, parameters.get("dimension"), MCP.dimension(server, sender), StructureSearch::dimension);
    consider(ranks, parameters.get("maze"), p -> p, StructureSearch::maze);
    consider(ranks, parameters.get("list"), p -> p, StructureSearch::list);
    consider(ranks, parameters.get("author"), p -> p, StructureSearch::author);
    boolean all = parameters.has("all");
    if (ranks.stream().noneMatch(Objects::nonNull))
        throw new WrongUsageException(getUsage(sender));
    postResultMessage("Results: ", sender, RCTextStyle::structure, search(all ? StructureRegistry.INSTANCE.ids() : StructureRegistry.INSTANCE.activeIDs(), name -> ranks.stream().filter(Objects::nonNull).mapToDouble(f -> f.applyAsDouble(name)).reduce(1, (a, b) -> a * b)));
}
Also used : BlockExpression(ivorius.reccomplex.utils.expression.BlockExpression) java.util(java.util) MCE(ivorius.mcopts.commands.parameters.expect.MCE) Structure(ivorius.reccomplex.world.gen.feature.structure.Structure) StructureRegistry(ivorius.reccomplex.world.gen.feature.structure.StructureRegistry) TextComponentBase(net.minecraft.util.text.TextComponentBase) RCConfig(ivorius.reccomplex.RCConfig) Function(java.util.function.Function) ServerTranslations(ivorius.mcopts.translation.ServerTranslations) ITextComponent(net.minecraft.util.text.ITextComponent) CommandException(net.minecraft.command.CommandException) MinecraftServer(net.minecraft.server.MinecraftServer) RecurrentComplex(ivorius.reccomplex.RecurrentComplex) Nonnull(javax.annotation.Nonnull) RCTextStyle(ivorius.reccomplex.commands.RCTextStyle) CommandExpecting(ivorius.mcopts.commands.CommandExpecting) Collectors(java.util.stream.Collectors) MCP(ivorius.mcopts.commands.parameters.MCP) TextComponentString(net.minecraft.util.text.TextComponentString) ToDoubleBiFunction(java.util.function.ToDoubleBiFunction) RCP(ivorius.reccomplex.commands.parameters.RCP) Expect(ivorius.mcopts.commands.parameters.expect.Expect) ICommandSender(net.minecraft.command.ICommandSender) WrongUsageException(net.minecraft.command.WrongUsageException) ToDoubleFunction(java.util.function.ToDoubleFunction) Doubles(com.google.common.primitives.Doubles) Parameter(ivorius.mcopts.commands.parameters.Parameter) Parameters(ivorius.mcopts.commands.parameters.Parameters) Parameters(ivorius.mcopts.commands.parameters.Parameters) BlockExpression(ivorius.reccomplex.utils.expression.BlockExpression) WrongUsageException(net.minecraft.command.WrongUsageException) RCTextStyle(ivorius.reccomplex.commands.RCTextStyle) Parameter(ivorius.mcopts.commands.parameters.Parameter) MCP(ivorius.mcopts.commands.parameters.MCP) ToDoubleFunction(java.util.function.ToDoubleFunction)

Example 68 with WrongUsageException

use of net.minecraft.command.WrongUsageException in project AppleCore by squeek502.

the class CommandHunger method execute.

@Override
public void execute(@Nonnull MinecraftServer server, @Nonnull ICommandSender commandSender, @Nonnull String[] args) throws CommandException {
    if (args.length > 0) {
        EntityPlayerMP playerToActOn = args.length >= 2 ? getPlayer(server, commandSender, args[0]) : getCommandSenderAsPlayer(commandSender);
        int maxHunger = AppleCoreAPI.accessor.getMaxHunger(playerToActOn);
        int newHunger = args.length >= 2 ? parseInt(args[1], 0, maxHunger) : parseInt(args[0], 0, maxHunger);
        AppleCoreAPI.mutator.setHunger(playerToActOn, newHunger);
        if (playerToActOn.getFoodStats().getSaturationLevel() > newHunger)
            AppleCoreAPI.mutator.setSaturation(playerToActOn, newHunger);
        notifyCommandListener(commandSender, this, 1, "applecore.commands.hunger.set.hunger.to", playerToActOn.getDisplayName(), newHunger);
    } else {
        throw new WrongUsageException(getUsage(commandSender));
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP)

Example 69 with WrongUsageException

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

the class CommandPlanetTeleport method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    EntityPlayerMP playerBase = null;
    if (args.length < 2) {
        try {
            if (args.length == 1) {
                playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[0], true);
            } else {
                playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
            }
            if (playerBase != null) {
                WorldServer worldserver = server.getWorld(GCCoreUtil.getDimensionID(server.worlds[0]));
                BlockPos spawnPoint = worldserver.getSpawnPoint();
                GCPlayerStats stats = GCPlayerStats.get(playerBase);
                stats.setRocketStacks(NonNullList.withSize(2, ItemStack.EMPTY));
                stats.setRocketType(IRocketType.EnumRocketType.DEFAULT.ordinal());
                stats.setRocketItem(GCItems.rocketTier1);
                stats.setFuelLevel(1000);
                stats.setCoordsTeleportedFromX(spawnPoint.getX());
                stats.setCoordsTeleportedFromZ(spawnPoint.getZ());
                try {
                    WorldUtil.toCelestialSelection(playerBase, stats, Integer.MAX_VALUE);
                } catch (Exception e) {
                    e.printStackTrace();
                    throw e;
                }
                CommandBase.notifyCommandListener(sender, this, "commands.dimensionteleport", 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.getUsage(sender)), new Object[0]);
    }
}
Also used : WrongUsageException(net.minecraft.command.WrongUsageException) GCPlayerStats(micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) WorldServer(net.minecraft.world.WorldServer) BlockPos(net.minecraft.util.math.BlockPos) CommandException(net.minecraft.command.CommandException) CommandException(net.minecraft.command.CommandException) WrongUsageException(net.minecraft.command.WrongUsageException)

Example 70 with WrongUsageException

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

the class CommandGCHouston method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    EntityPlayerMP playerBase = null;
    boolean isOp = this.isOp(server, sender);
    if (args.length < 2) {
        try {
            if (args.length == 0) {
                playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
                if (!playerBase.capabilities.isCreativeMode) {
                    if (ConfigManagerCore.challengeMode || !(playerBase.world.provider instanceof IGalacticraftWorldProvider)) {
                        CommandBase.notifyCommandListener(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.notifyCommandListener(sender, this, msg);
                    return;
                }
            } else {
                if (!isOp) {
                    CommandBase.notifyCommandListener(sender, this, "commands.gchouston.noop");
                    return;
                }
                playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[0], true);
            }
            if (playerBase != null) {
                int dimID = ConfigManagerCore.idDimensionOverworld;
                WorldServer worldserver = server.getWorld(dimID);
                if (worldserver == null) {
                    worldserver = server.getWorld(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(NonNullList.withSize(0, ItemStack.EMPTY));
                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.notifyCommandListener(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.getUsage(sender)), new Object[0]);
    }
}
Also used : 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) WrongUsageException(net.minecraft.command.WrongUsageException) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

WrongUsageException (net.minecraft.command.WrongUsageException)73 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)37 CommandException (net.minecraft.command.CommandException)30 EntityPlayer (net.minecraft.entity.player.EntityPlayer)21 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)16 ItemStack (net.minecraft.item.ItemStack)13 BlockPos (net.minecraft.util.math.BlockPos)8 ChatComponentText (net.minecraft.util.ChatComponentText)7 TextComponentString (net.minecraft.util.text.TextComponentString)7 SpaceStationWorldData (micdoodle8.mods.galacticraft.core.dimension.SpaceStationWorldData)6 MinecraftServer (net.minecraft.server.MinecraftServer)5 PacketSimple (micdoodle8.mods.galacticraft.core.network.PacketSimple)4 Entity (net.minecraft.entity.Entity)4 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)4 World (net.minecraft.world.World)4 WorldServer (net.minecraft.world.WorldServer)4 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 Affinity (am2.api.spell.enums.Affinity)2 PlayerIdentifier (com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier)2 AttributeModifier (com.teamwizardry.wizardry.api.spell.attribute.AttributeModifier)2