use of net.minecraft.command.CommandException in project RecurrentComplex by Ivorforce.
the class CommandMapStructure method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
Parameters parameters = Parameters.of(args, expect()::declare);
ResourceExpression expression = parameters.get(0).to(RCP::expression, new ResourceExpression(StructureRegistry.INSTANCE::has)).require();
CommandVirtual virtual = parameters.get(1).to(RCP::virtualCommand, server).require();
String[] virtualArgs = parameters.get(2).to(NaP::varargs).require();
ResourceDirectory directory = parameters.has("nosave") ? null : parameters.get("directory").to(RCP::resourceDirectory).optional().orElse(ResourceDirectory.ACTIVE);
List<String> relevant = StructureRegistry.INSTANCE.ids().stream().filter(id -> expression.test(new RawResourceLocation(StructureRegistry.INSTANCE.status(id).getDomain(), id))).collect(Collectors.toList());
boolean inform = relevant.size() == 1;
int saved = 0, failed = 0, skipped = 0;
for (String id : relevant) {
switch(map(id, directory, commandSender, virtual, virtualArgs, inform)) {
case SKIPPED:
skipped++;
break;
case SUCCESS:
saved++;
break;
default:
failed++;
break;
}
}
if (!inform)
commandSender.sendMessage(RecurrentComplex.translations.format("commands.rcmapall.result", saved, RCTextStyle.path(directory), failed, skipped));
RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
}
use of net.minecraft.command.CommandException 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)));
}
use of net.minecraft.command.CommandException in project Railcraft by Railcraft.
the class TrackKitMessenger method sendMessage.
protected void sendMessage(EntityMinecart cart) {
cart.getRecursivePassengersByType(EntityPlayerMP.class).forEach(e -> {
try {
SPacketTitle pkt = new SPacketTitle(SPacketTitle.Type.ACTIONBAR, TextComponentUtils.processComponent(cart, getActionbar(), e));
e.connection.sendPacket(pkt);
pkt = new SPacketTitle(SPacketTitle.Type.SUBTITLE, TextComponentUtils.processComponent(cart, getSubtitle(), e));
e.connection.sendPacket(pkt);
pkt = new SPacketTitle(SPacketTitle.Type.TITLE, TextComponentUtils.processComponent(cart, getTitle(), e));
e.connection.sendPacket(pkt);
} catch (CommandException ignored) {
}
});
}
use of net.minecraft.command.CommandException in project BloodMagic by WayofTime.
the class CommandBind method processCommand.
public void processCommand(ICommandSender iCommandSender, String[] astring) {
EntityPlayerMP entityplayermp = getCommandSenderAsPlayer(iCommandSender);
ItemStack item = entityplayermp.getCurrentEquippedItem();
EntityPlayerMP targetPlayer = getPlayer(iCommandSender, astring[0]);
if (targetPlayer == null) {
throw new CommandException("commands.bind.failed.noPlayer");
}
if (item != null && item.getItem() instanceof IBindable) {
if (EnergyItems.getOwnerName(item).isEmpty()) {
EnergyItems.checkAndSetItemOwner(item, targetPlayer);
func_152373_a(iCommandSender, this, "commands.bind.success");
} else {
throw new CommandException("commands.bind.failed.alreadyBound");
}
} else if (!(item.getItem() instanceof IBindable)) {
throw new CommandException("commands.bind.failed.notBindable");
}
}
use of net.minecraft.command.CommandException in project BloodMagic by WayofTime.
the class CommandUnbind method processCommand.
public void processCommand(ICommandSender iCommandSender, String[] astring) {
EntityPlayerMP entityplayermp = getCommandSenderAsPlayer(iCommandSender);
ItemStack item = entityplayermp.getCurrentEquippedItem();
if (item != null && item.getItem() instanceof IBindable) {
if (!EnergyItems.getOwnerName(item).isEmpty()) {
item.getTagCompound().removeTag("ownerName");
func_152373_a(iCommandSender, this, "commands.unbind.success");
} else {
throw new CommandException("commands.unbind.failed.notBindable");
}
} else if (!(item.getItem() instanceof IBindable)) {
throw new CommandException("commands.unbind.failed.notBindable");
}
}
Aggregations