use of net.minecraft.command.CommandException in project RecurrentComplex by Ivorforce.
the class CommandSelectFill method execute.
@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
RCParameters parameters = RCParameters.of(args);
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());
SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
RCCommands.assertSize(commandSender, selectionOwner);
String shape = parameters.get("shape").first().optional().orElse("cube");
BlockArea area = selectionOwner.getSelection();
BlockPos p1 = area.getPoint1();
BlockPos p2 = area.getPoint2();
switch(shape) {
case "cube":
for (BlockPos pos : area) {
IBlockState state = dst.get(world.rand().nextInt(dst.size()));
world.setBlockState(pos, state, 2);
}
break;
case "sphere":
{
double[] spheroidOrigin = new double[] { (p1.getX() + p2.getX()) * 0.5, (p1.getY() + p2.getY()) * 0.5, (p1.getZ() + p2.getZ()) * 0.5 };
int[] areaSize = area.areaSize();
double[] spheroidSize = new double[] { areaSize[0] * 0.5, areaSize[1] * 0.5, areaSize[2] * 0.5 };
for (BlockPos coord : area) {
double[] coordPoint = new double[] { coord.getX(), coord.getY(), coord.getZ() };
if (IvShapeHelper.isPointInSpheroid(coordPoint, spheroidOrigin, spheroidSize)) {
IBlockState state = dst.get(world.rand().nextInt(dst.size()));
world.setBlockState(coord, state, 2);
}
}
break;
}
default:
throw new WrongUsageException(getUsage(commandSender));
}
}
use of net.minecraft.command.CommandException in project RecurrentComplex by Ivorforce.
the class CommandSelectReplace method execute.
@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
RCParameters parameters = RCParameters.of(args);
Block dstBlock = parameters.mc().block(commandSender).require();
int[] dstMeta = parameters.rc("metadata").metadatas().optional().orElse(new int[1]);
List<IBlockState> dst = IntStream.of(dstMeta).mapToObj(m -> BlockStates.fromMetadata(dstBlock, m)).collect(Collectors.toList());
PositionedBlockExpression matcher = parameters.rc().move(1).expression(new PositionedBlockExpression(RecurrentComplex.specialRegistry)).require();
SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
RCCommands.assertSize(commandSender, selectionOwner);
for (BlockPos coord : selectionOwner.getSelection()) {
if (matcher.evaluate(() -> PositionedBlockExpression.Argument.at(world, coord))) {
IBlockState state = dst.get(world.rand().nextInt(dst.size()));
world.setBlockState(coord, state, 3);
}
}
}
use of net.minecraft.command.CommandException in project SpongeCommon by SpongePowered.
the class MixinCommandTP method execute.
/**
* @author blood - May 31st, 2016
* @author gabizou - May 31st, 2016 - Update to 1.9.4
* @author Aaron1011 - August 15, 2016 - Update to 1.10.2
* @reason to fix LVT errors with SpongeForge
*
* @param sender The command source
* @param args The command arguments
*/
@Override
@Overwrite
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length < 1) {
throw new WrongUsageException("commands.tp.usage", new Object[0]);
} else {
int i = 0;
Entity entity;
if (args.length != 2 && args.length != 4 && args.length != 6) {
entity = getCommandSenderAsPlayer(sender);
} else {
entity = getEntity(server, sender, args[0]);
i = 1;
}
if (args.length != 1 && args.length != 2) {
if (args.length < i + 3) {
throw new WrongUsageException("commands.tp.usage", new Object[0]);
} else if (entity.world != null) {
// int j = 4096;
int lvt_6_2_ = i + 1;
CommandBase.CoordinateArg commandbase$coordinatearg = parseCoordinate(entity.posX, args[i], true);
CommandBase.CoordinateArg commandbase$coordinatearg1 = parseCoordinate(entity.posY, args[lvt_6_2_++], -4096, 4096, false);
CommandBase.CoordinateArg commandbase$coordinatearg2 = parseCoordinate(entity.posZ, args[lvt_6_2_++], true);
CommandBase.CoordinateArg commandbase$coordinatearg3 = parseCoordinate((double) entity.rotationYaw, args.length > lvt_6_2_ ? args[lvt_6_2_++] : "~", false);
CommandBase.CoordinateArg commandbase$coordinatearg4 = parseCoordinate((double) entity.rotationPitch, args.length > lvt_6_2_ ? args[lvt_6_2_] : "~", false);
// Sponge start - check shouldNotifyCommandListener before calling 'notifyCommandListener'
// Guard against any possible re-entrance
boolean shouldNotify = shouldNotifyCommandListener;
teleportEntityToCoordinates(entity, commandbase$coordinatearg, commandbase$coordinatearg1, commandbase$coordinatearg2, commandbase$coordinatearg3, commandbase$coordinatearg4);
if (shouldNotifyCommandListener) {
notifyCommandListener(sender, this, "commands.tp.success.coordinates", new Object[] { entity.getName(), Double.valueOf(commandbase$coordinatearg.getResult()), Double.valueOf(commandbase$coordinatearg1.getResult()), Double.valueOf(commandbase$coordinatearg2.getResult()) });
}
shouldNotifyCommandListener = shouldNotify;
// Sponge end
}
} else {
Entity entity1 = getEntity(server, sender, args[args.length - 1]);
if (entity1.world != entity.world) {
throw new CommandException("commands.tp.notSameDimension", new Object[0]);
} else {
entity.dismountRidingEntity();
if (entity instanceof EntityPlayerMP) {
// Sponge start
EntityPlayerMP player = (EntityPlayerMP) entity;
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
frame.addContext(EventContextKeys.TELEPORT_TYPE, TeleportTypes.COMMAND);
MoveEntityEvent.Teleport event = EntityUtil.handleDisplaceEntityTeleportEvent(entity, entity1.posX, entity1.posY, entity1.posZ, entity1.rotationYaw, entity1.rotationPitch);
if (event.isCancelled()) {
return;
}
Vector3d position = event.getToTransform().getPosition();
player.connection.setPlayerLocation(position.getX(), position.getY(), position.getZ(), (float) event.getToTransform().getYaw(), (float) event.getToTransform().getPitch());
}
// Sponge end
} else {
// Sponge Start - Events
try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
frame.addContext(EventContextKeys.TELEPORT_TYPE, TeleportTypes.COMMAND);
MoveEntityEvent.Teleport event = EntityUtil.handleDisplaceEntityTeleportEvent(entity, entity1.posX, entity1.posY, entity1.posZ, entity1.rotationYaw, entity1.rotationPitch);
if (event.isCancelled()) {
return;
}
Vector3d position = event.getToTransform().getPosition();
entity.setLocationAndAngles(position.getX(), position.getY(), position.getZ(), (float) event.getToTransform().getYaw(), (float) event.getToTransform().getPitch());
}
// Sponge End
}
notifyCommandListener(sender, this, "commands.tp.success", new Object[] { entity.getName(), entity1.getName() });
}
}
}
}
use of net.minecraft.command.CommandException in project HorsePower by GoryMoon.
the class HorsePowerCommand method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (args.length == 1) {
if ("entity".equals(args[0])) {
if (sender instanceof EntityPlayerSP) {
RayTraceResult result = Minecraft.getMinecraft().objectMouseOver;
if (result != null && result.typeOfHit == RayTraceResult.Type.ENTITY) {
Entity entity = result.entityHit;
sender.sendMessage(new TextComponentTranslation("commands.horsepower.entity.has", entity.getClass().getName()));
try {
StringSelection selection = new StringSelection(entity.getClass().getName());
Toolkit.getDefaultToolkit().getSystemClipboard().setContents(selection, selection);
} catch (Exception ignored) {
}
} else
sender.sendMessage(new TextComponentTranslation("commands.horsepower.entity.no"));
} else
throw new CommandException("commands.horsepower.entity.invalid");
return;
}
if ("reload".equals(args[0])) {
sender.sendMessage(new TextComponentTranslation("commands.horsepower.reload").setStyle(new Style().setColor(TextFormatting.YELLOW).setBold(true)));
HPEventHandler.reloadConfig();
boolean hasErrors = HPRecipes.ERRORS.size() > 0;
Utils.sendSavedErrors();
if (hasErrors)
sender.sendMessage(new TextComponentTranslation("commands.horsepower.reload.error").setStyle(new Style().setColor(TextFormatting.DARK_RED).setBold(true)));
else
sender.sendMessage(new TextComponentTranslation("commands.horsepower.reload.noerror").setStyle(new Style().setColor(TextFormatting.GREEN).setBold(true)));
return;
}
}
throw new WrongUsageException(getUsage(sender));
}
use of net.minecraft.command.CommandException in project Minestuck by mraof.
the class ServerEditHandler method onCommandEvent.
@SubscribeEvent(priority = EventPriority.LOWEST, receiveCanceled = false)
public void onCommandEvent(CommandEvent event) {
if (list.isEmpty())
return;
try {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
if (commands.contains(event.getCommand().getName())) {
String c = event.getCommand().getName();
EntityPlayer target;
if (c.equals("kill") || (c.equals("clear") || c.equals("spawnpoint")) && event.getParameters().length == 0 || c.equals("tp") && event.getParameters().length != 2 && event.getParameters().length != 4 || c.equals("setworldspawn") && (event.getParameters().length == 0 || event.getParameters().length == 3))
target = CommandBase.getCommandSenderAsPlayer(event.getSender());
else if (c.equals("defaultgamemode") && server.getForceGamemode()) {
for (EditData data : (EditData[]) list.toArray()) reset(data);
return;
} else if (c.equals("spreadplayers")) {
ArrayList<EntityPlayer> targets = new ArrayList<EntityPlayer>();
for (int i = 5; i < event.getParameters().length; i++) {
String s = event.getParameters()[i];
if (EntitySelector.isSelector(s)) {
Entity[] list = (Entity[]) EntitySelector.matchEntities(event.getSender(), s, Entity.class).toArray();
if (list.length == 0)
return;
for (Entity e : list) if (e instanceof EntityPlayer)
targets.add((EntityPlayer) e);
} else {
EntityPlayer player = server.getPlayerList().getPlayerByUsername(s);
if (player == null)
return;
targets.add(player);
}
}
for (EntityPlayer player : targets) if (getData(player) != null) {
reset(getData(player));
}
return;
} else if (c.equals("gamemode") || c.equals("xp"))
target = event.getParameters().length >= 2 ? CommandBase.getPlayer(server, event.getSender(), event.getParameters()[1]) : CommandBase.getCommandSenderAsPlayer(event.getSender());
else
target = CommandBase.getPlayer(server, event.getSender(), event.getParameters()[0]);
if (target != null && getData(target) != null)
reset(getData(target));
}
} catch (CommandException e) {
}
}
Aggregations