Search in sources :

Example 61 with CommandException

use of net.minecraft.command.CommandException in project Minestuck by mraof.

the class SburbHandler method predefineCheck.

private static PlayerIdentifier predefineCheck(MinecraftServer server, ICommandSender sender, String playerName, String sessionName) throws CommandException {
    PlayerIdentifier identifier = IdentifierHandler.getForCommand(server, sender, playerName);
    Session session = sessionsByName.get(sessionName), playerSession = getPlayerSession(identifier);
    if (session == null) {
        if (singleSession)
            throw new CommandException("Not allowed to create new sessions when global session is active. Use \"%s\" as session name for global session access.", GLOBAL_SESSION_NAME);
        if (sender.sendCommandFeedback())
            sender.sendMessage(new TextComponentString("Couldn't find session with that name, creating a new session..."));
        session = new Session();
        session.name = sessionName;
        sessions.add(session);
        sessionsByName.put(session.name, session);
    }
    /*if(session == null)
			throw new CommandException("Couldn't find session with the name %s", sessionName);*/
    if (playerSession != null && session != playerSession)
        throw new CommandException("The player is already in another session!");
    if (playerSession == null || !session.predefinedPlayers.containsKey(identifier)) {
        if (sender.sendCommandFeedback())
            sender.sendMessage(new TextComponentString("Couldn't find session for player or player isn't registered with this session yet. Adding player to session " + sessionName));
        session.predefinedPlayers.put(identifier, new PredefineData());
    }
    return identifier;
}
Also used : CommandException(net.minecraft.command.CommandException) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 62 with CommandException

use of net.minecraft.command.CommandException in project Minestuck by mraof.

the class SburbHandler method predefineTitleLandAspect.

public static void predefineTitleLandAspect(MinecraftServer server, ICommandSender sender, ICommand command, String playerName, String sessionName, TitleLandAspect aspect) throws CommandException {
    PlayerIdentifier identifier = predefineCheck(server, sender, playerName, sessionName);
    Session session = sessionsByName.get(sessionName);
    SburbConnection clientConnection = SkaianetHandler.getClientConnection(identifier);
    PredefineData data = session.predefinedPlayers.get(identifier);
    if (clientConnection != null && clientConnection.enteredGame())
        throw new CommandException("You can't change your land aspects after having entered the medium.");
    if (sender.sendCommandFeedback())
        if (data.title == null)
            sender.sendMessage(new TextComponentString("Beware that the title generated might not be suited for this land aspect.").setStyle(new Style().setColor(TextFormatting.YELLOW)));
        else if (!LandAspectRegistry.containsTitleLandAspect(data.title.getHeroAspect(), aspect))
            sender.sendMessage(new TextComponentString("Beware that the title predefined isn't suited for this land aspect.").setStyle(new Style().setColor(TextFormatting.YELLOW)));
    if (data.landTerrain != null && !aspect.isAspectCompatible(data.landTerrain)) {
        data.landTerrain = null;
        if (sender.sendCommandFeedback())
            sender.sendMessage(new TextComponentString("The terrain aspect previously chosen isn't compatible with this land aspect, and has therefore been removed.").setStyle(new Style().setColor(TextFormatting.YELLOW)));
    }
    data.landTitle = aspect;
    CommandBase.notifyCommandListener(sender, command, "commands.sburbSession.landTitleSuccess", playerName, aspect.getPrimaryName());
}
Also used : Style(net.minecraft.util.text.Style) CommandException(net.minecraft.command.CommandException) PlayerIdentifier(com.mraof.minestuck.util.IdentifierHandler.PlayerIdentifier) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 63 with CommandException

use of net.minecraft.command.CommandException in project minecolonies by Minecolonies.

the class CommandEntryPointNew method execute.

@Override
public void execute(@NotNull final MinecraftServer server, @NotNull final ICommandSender sender, @NotNull final String[] args) throws CommandException {
    final BlockPos pos = null;
    final ParsingResult parsingResult = getTabCompletionsAndParsingHolders(root, server, sender, args, pos);
    final TreeNode<IMenu> executionTreeNode = parsingResult.getExecutionTreeNode();
    if (null == executionTreeNode) {
        throw new CommandException(getCommandUsage(sender, root));
    }
    final IMenu executionMenu = executionTreeNode.getData();
    if (executionMenu.getMenuType().isNavigationMenu()) {
        throw new CommandException(getCommandUsage(sender, executionTreeNode));
    }
    final ActionMenu actionMenu = (ActionMenu) executionMenu;
    final List<ActionArgument> executionActionArgumentList = parsingResult.getExecutionActionArgumentList();
    final String badArgument = parsingResult.getBadArgument();
    throwCommandUsageExceptionIfRequiredArgumentsAreNotProvided(executionTreeNode, actionMenu, executionActionArgumentList, badArgument, sender);
    if (sender instanceof EntityPlayer) {
        final ForgePermissionNodes forgePermissionNode = actionMenu.getForgePermissionNode();
        final EntityPlayer player = (EntityPlayer) sender;
        if (!PermissionAPI.hasPermission(player.getGameProfile(), forgePermissionNode.getNodeName(), new PlayerContext(player))) {
        // TODO: Do something if permission check fails.
        // But we don't have permissions set up yet.
        }
    }
    for (final ActionArgument executionActionArgument : executionActionArgumentList) {
        if (!executionActionArgument.isValueSet()) {
            throw new CommandException(getCommandUsage(sender, executionTreeNode));
        }
    }
    final Class<? extends IActionCommand> clazz = actionMenu.getActionCommandClass();
    try {
        createInstanceAndExecute(server, sender, actionMenu, clazz);
    } catch (final InstantiationException | IllegalAccessException e) {
        final Logger log = LogManager.getLogger();
        log.error("Unable to instantiate class %s for command %s ", clazz.getName(), actionMenu.getDescription(), e);
        throw new CommandException("Unable to instantiate class " + clazz.getName() + " for command " + actionMenu.getDescription(), e);
    }
}
Also used : CommandException(net.minecraft.command.CommandException) Logger(org.apache.logging.log4j.Logger) ForgePermissionNodes(com.minecolonies.coremod.colony.permissions.ForgePermissionNodes) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PlayerContext(net.minecraftforge.server.permission.context.PlayerContext) BlockPos(net.minecraft.util.math.BlockPos)

Example 64 with CommandException

use of net.minecraft.command.CommandException in project OreSpawn by MinecraftModDevelopmentMods.

the class DumpBiomesCommand method execute.

@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    JsonArray array = new JsonArray();
    for (Biome biome : ForgeRegistries.BIOMES) {
        array.add(new JsonPrimitive(biome.getRegistryName().toString()));
    }
    Gson gson = new GsonBuilder().setPrettyPrinting().create();
    String json = gson.toJson(array);
    try {
        FileUtils.writeStringToFile(new File(".", "biome_dump.json"), StringEscapeUtils.unescapeJson(json), CharEncoding.UTF_8);
    } catch (IOException e) {
        throw new CommandException("Failed to save the json file");
    }
    sender.sendMessage(new TextComponentString("Done"));
}
Also used : JsonArray(com.google.gson.JsonArray) Biome(net.minecraft.world.biome.Biome) JsonPrimitive(com.google.gson.JsonPrimitive) GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) TextComponentString(net.minecraft.util.text.TextComponentString) IOException(java.io.IOException) CommandException(net.minecraft.command.CommandException) File(java.io.File) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 65 with CommandException

use of net.minecraft.command.CommandException 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)

Aggregations

CommandException (net.minecraft.command.CommandException)82 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)33 WrongUsageException (net.minecraft.command.WrongUsageException)31 MinecraftServer (net.minecraft.server.MinecraftServer)22 TextComponentString (net.minecraft.util.text.TextComponentString)19 ICommandSender (net.minecraft.command.ICommandSender)18 GCPlayerStats (micdoodle8.mods.galacticraft.core.entities.player.GCPlayerStats)16 RCConfig (ivorius.reccomplex.RCConfig)15 EntityPlayer (net.minecraft.entity.player.EntityPlayer)14 BlockPos (net.minecraft.util.math.BlockPos)13 RecurrentComplex (ivorius.reccomplex.RecurrentComplex)12 ItemStack (net.minecraft.item.ItemStack)12 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 RCE (ivorius.reccomplex.commands.parameters.expect.RCE)7 Collectors (java.util.stream.Collectors)7