use of net.minecraft.command.CommandException in project BuildCraft by BuildCraft.
the class CommandHelpers method getWorld.
public static World getWorld(ICommandSender sender, IModCommand command, String[] args, int worldArgIndex) throws CommandException {
// Handle passed in world argument
if (worldArgIndex < args.length) {
try {
int dim = Integer.parseInt(args[worldArgIndex]);
World world = sender.getServer().worldServerForDimension(dim);
if (world != null) {
return world;
}
} catch (Exception ex) {
throwWrongUsage(sender, command);
}
}
return getWorld(sender, command);
}
use of net.minecraft.command.CommandException in project ImmersiveEngineering by BluSunrize.
the class CommandHandler method execute.
@Override
public void execute(@Nonnull MinecraftServer server, @Nonnull ICommandSender sender, String[] args) throws CommandException {
List<String> argsCleaned = new ArrayList<>(args.length);
String currentPart = null;
for (String s : args) {
if (s.startsWith(start)) {
if (currentPart != null)
throw new CommandException("String opens twice (once \"" + currentPart + "\", once \"" + s + "\")");
currentPart = s;
} else if (currentPart != null)
currentPart += " " + s;
else
argsCleaned.add(s);
if (s.endsWith(end)) {
if (currentPart == null)
throw new CommandException("String closed without being openeed first! (\"" + s + "\")");
if (currentPart.length() >= 2)
argsCleaned.add(currentPart.substring(1, currentPart.length() - 1));
currentPart = null;
}
}
if (currentPart != null)
throw new CommandException("Unclosed string (" + currentPart + ")");
super.execute(server, sender, argsCleaned.toArray(new String[0]));
}
use of net.minecraft.command.CommandException in project ICBM-Classic by BuiltBrokenModding.
the class CommandBlastTriggerTest method command_badInput.
@ParameterizedTest
@MethodSource("provideBadCommandInputs")
void command_badInput(String[] commandArgs, String errorMessage, boolean player) {
final ICommandSender sender = player ? testManager.getPlayer() : testManager.getServer();
// Validate we throw the right error
final CommandException exception = Assertions.assertThrows(CommandException.class, () -> command.handleCommand(testManager.getServer(), sender, commandArgs));
// validate the error contains the right message
Assertions.assertEquals(errorMessage, exception.getMessage());
}
use of net.minecraft.command.CommandException in project RecurrentComplex by Ivorforce.
the class CommandEditStructure method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
EntityPlayerMP entityPlayerMP = getCommandSenderAsPlayer(commandSender);
Parameters parameters = Parameters.of(args, expect()::declare);
ResourceDirectory directory = parameters.get("directory").to(RCP::resourceDirectory).optional().orElse(null);
String structureID = parameters.get("id").optional().orElse(parameters.get(0).require());
GenericStructure base = parameters.get(0).to(p -> RCP.genericStructure(p, false)).require();
GenericStructure from = parameters.get("from").to(p -> RCP.genericStructure(p, false)).optional().orElse(base);
if (base != from) {
from = from.copyAsGenericStructure();
from.worldDataCompound = base.worldDataCompound.copy();
}
PacketEditStructureHandler.openEditStructure(entityPlayerMP, from, entityPlayerMP.getPosition(), structureID, directory);
}
use of net.minecraft.command.CommandException in project RecurrentComplex by Ivorforce.
the class CommandLookupStructure method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
String id = parameters.get(0).require();
GenericStructure structure = parameters.get(0).to(p -> RCP.genericStructure(p, false)).require();
Metadata metadata = structure.metadata;
boolean hasWeblink = !metadata.weblink.trim().isEmpty();
ITextComponent weblink = hasWeblink ? new TextComponentString(RCStrings.abbreviateFormatted(metadata.weblink, 30)) : RecurrentComplex.translations.format("commands.rclookup.reply.nolink");
if (hasWeblink) {
weblink.getStyle().setClickEvent(new ClickEvent(ClickEvent.Action.OPEN_URL, metadata.weblink));
weblink.getStyle().setHoverEvent(new HoverEvent(HoverEvent.Action.SHOW_TEXT, new TextComponentString(metadata.weblink)));
}
ITextComponent level = new TextComponentString(StructureRegistry.INSTANCE.status(id).getLevel().toString());
level.getStyle().setColor(TextFormatting.YELLOW);
commandSender.sendMessage(RecurrentComplex.translations.format(StructureRegistry.INSTANCE.hasActive(id) ? "commands.rclookup.reply.generates" : "commands.rclookup.reply.silent", id, RCTextStyle.users(metadata.authors), level, weblink));
if (!metadata.comment.trim().isEmpty())
commandSender.sendMessage(RecurrentComplex.translations.format("commands.rclookup.reply.comment", metadata.comment));
}
Aggregations