use of net.minecraft.command.CommandException in project RecurrentComplex by Ivorforce.
the class CommandContaining method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
RCParameters parameters = RCParameters.of(args);
BlockExpression matcher = parameters.rc().expression(new BlockExpression(RecurrentComplex.specialRegistry)).require();
CommandSearchStructure.postResultMessage(commandSender, RCTextStyle::structure, CommandSearchStructure.search(StructureRegistry.INSTANCE.ids(), name -> containedBlocks(StructureRegistry.INSTANCE.get(name), matcher)));
}
use of net.minecraft.command.CommandException in project RecurrentComplex by Ivorforce.
the class CommandSelectFlood method execute.
@Override
public void execute(MockWorld world, ICommandSender commandSender, String[] args) throws CommandException {
RCParameters parameters = RCParameters.of(args);
SelectionOwner selectionOwner = RCCommands.getSelectionOwner(commandSender, null, true);
RCCommands.assertSize(commandSender, selectionOwner);
PreloadedBooleanExpression<EnumFacing> facingExpression = PreloadedBooleanExpression.with(exp -> {
exp.addConstants(EnumFacing.values());
exp.addEvaluators(axis -> facing -> facing.getAxis() == axis, EnumFacing.Axis.values());
exp.addEvaluator("horizontal", f -> f.getHorizontalIndex() >= 0);
exp.addEvaluator("vertical", f -> f.getHorizontalIndex() < 0);
});
facingExpression.setExpression(parameters.get().move(2).text().optional().orElse(""));
List<EnumFacing> available = Arrays.stream(EnumFacing.values()).filter(facingExpression).collect(Collectors.toList());
List<BlockPos> dirty = Lists.newArrayList(selectionOwner.getSelection());
Set<BlockPos> visited = Sets.newHashSet(dirty);
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());
while (!dirty.isEmpty()) {
BlockPos pos = dirty.remove(dirty.size() - 1);
for (EnumFacing facing : available) {
BlockPos offset = pos.offset(facing);
if (RCBlockLogic.isAir(world, offset) && visited.add(offset))
dirty.add(offset);
}
if (visited.size() > MAX_FLOOD)
throw new CommandException("Area too big to flood!");
}
for (BlockPos pos : visited) {
IBlockState state = dst.get(world.rand().nextInt(dst.size()));
world.setBlockState(pos, state, 2);
}
}
use of net.minecraft.command.CommandException in project RecurrentComplex by Ivorforce.
the class CommandWriteAll method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
RCParameters parameters = RCParameters.of(args);
String adapterID = parameters.get().first().require();
if (!RecurrentComplex.saver.has(adapterID))
throw ServerTranslations.commandException("commands.rcsaveall.noregistry");
ResourceDirectory directory = parameters.rc("dir").resourceDirectory().optional().orElse(ResourceDirectory.ACTIVE);
Optional<FileSaverAdapter<?>> adapterOptional = Optional.ofNullable(RecurrentComplex.saver.get(adapterID));
Set<String> ids = adapterOptional.map(a -> a.getRegistry().ids()).orElse(Collections.emptySet());
ResourceExpression resourceExpression = ExpressionCache.of(new ResourceExpression(id -> adapterOptional.map(a -> a.getRegistry().has(id)).orElse(false)), parameters.get().at(1).require());
int saved = 0, failed = 0;
for (String id : ids) {
if (!resourceExpression.test(new RawResourceLocation(adapterOptional.map(a -> a.getRegistry().status(id).getDomain()).orElseThrow(IllegalStateException::new), id)))
continue;
boolean success = RecurrentComplex.saver.trySave(directory.toPath(), adapterID, id);
if (success)
saved++;
else
failed++;
}
commandSender.sendMessage(ServerTranslations.format("commands.rcsaveall.result", saved, directory, failed));
RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.CUSTOM);
RCCommands.tryReload(RecurrentComplex.loader, LeveledRegistry.Level.SERVER);
}
use of net.minecraft.command.CommandException in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.
the class PhysSettingsCommand method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
String key = args[0];
if (key.equals("doSplitting")) {
if (args.length == 1) {
sender.addChatMessage(new TextComponentString("doSplitting=" + ValkyrienWarfareMod.doSplitting + " (Default: false)"));
return;
} else if (args.length == 2) {
boolean value = Boolean.parseBoolean(args[1]);
ValkyrienWarfareMod.doSplitting = value;
sender.addChatMessage(new TextComponentString("Set physics splitting to " + value));
return;
}
} else if (key.equals("maxShipSize")) {
if (args.length == 1) {
sender.addChatMessage(new TextComponentString("maxShipSize=" + ValkyrienWarfareMod.maxShipSize + " (Default: 15000)"));
return;
} else if (args.length == 2) {
int value = Integer.parseInt(args[1]);
ValkyrienWarfareMod.maxShipSize = value;
sender.addChatMessage(new TextComponentString("Set maximum ship size to " + value));
return;
}
} else if (key.equals("gravityVector")) {
if (args.length == 1) {
sender.addChatMessage(new TextComponentString("gravityVector=" + ValkyrienWarfareMod.gravity.toRoundedString() + " (Default: <0,-9.8,0>)"));
return;
} else if (args.length == 4) {
Vector newVector = new Vector(0, -9.8, 0);
try {
if (args[1] != null && args[2] != null && args[3] != null) {
newVector.X = Double.parseDouble(args[1]);
newVector.Y = Double.parseDouble(args[2]);
newVector.Z = Double.parseDouble(args[3]);
} else {
sender.addChatMessage(new TextComponentString("Usage: /physSettings gravityVector <x> <y> <z>"));
return;
}
} catch (Exception e) {
}
ValkyrienWarfareMod.gravity = newVector;
sender.addChatMessage(new TextComponentString("Physics gravity set to " + newVector.toRoundedString() + " (Default: <0,-9.8,0>)"));
return;
} else {
sender.addChatMessage(new TextComponentString("Usage: /physSettings gravityVector <x> <y> <z>"));
}
} else if (key.equals("physicsIterations")) {
if (args.length == 1) {
sender.addChatMessage(new TextComponentString("physicsIterations=" + ValkyrienWarfareMod.physIter + " (Default: 10)"));
return;
} else if (args.length == 2) {
int value = Integer.parseInt(args[1]);
if (value < 0 || value > 1000) {
sender.addChatMessage(new TextComponentString("Please enter a value between 0 and 1000"));
return;
}
ValkyrienWarfareMod.physIter = value;
sender.addChatMessage(new TextComponentString("Set physicsIterations to " + value));
return;
}
} else if (key.equals("physicsSpeed")) {
if (args.length == 1) {
sender.addChatMessage(new TextComponentString("physicsSpeed=" + ValkyrienWarfareMod.physSpeed + " (Default: 0.05)"));
return;
} else if (args.length == 2) {
double value = Double.parseDouble(args[1]);
if (value < 0 || value > 1000) {
sender.addChatMessage(new TextComponentString("Please enter a value between 0 and 1000"));
return;
}
ValkyrienWarfareMod.physSpeed = value;
sender.addChatMessage(new TextComponentString("Set physicsSpeed to " + value));
return;
}
} else if (key.equals("doGravity")) {
if (args.length == 1) {
sender.addChatMessage(new TextComponentString("doGravity=" + PhysicsSettings.doGravity + " (Default: true)"));
return;
} else if (args.length == 2) {
boolean value = Boolean.parseBoolean(args[1]);
PhysicsSettings.doGravity = value;
sender.addChatMessage(new TextComponentString("Set doGravity to " + (PhysicsSettings.doGravity ? "enabled" : "disabled")));
return;
}
} else if (key.equals("doPhysicsBlocks")) {
if (args.length == 1) {
sender.addChatMessage(new TextComponentString("doPhysicsBlocks=" + PhysicsSettings.doPhysicsBlocks + " (Default: true)"));
return;
} else if (args.length == 2) {
boolean value = Boolean.parseBoolean(args[1]);
PhysicsSettings.doPhysicsBlocks = value;
sender.addChatMessage(new TextComponentString("Set doPhysicsBlocks to " + (PhysicsSettings.doPhysicsBlocks ? "enabled" : "disabled")));
return;
}
} else if (key.equals("doBalloons")) {
if (args.length == 1) {
sender.addChatMessage(new TextComponentString("doBalloons=" + PhysicsSettings.doBalloons + " (Default: true)"));
return;
} else if (args.length == 2) {
boolean value = Boolean.parseBoolean(args[1]);
PhysicsSettings.doBalloons = value;
sender.addChatMessage(new TextComponentString("Set doBalloons to " + (PhysicsSettings.doBalloons ? "enabled" : "disabled")));
return;
}
} else if (key.equals("doAirshipRotation")) {
if (args.length == 1) {
sender.addChatMessage(new TextComponentString("doAirshipRotation=" + PhysicsSettings.doAirshipRotation + " (Default: true)"));
return;
} else if (args.length == 2) {
boolean value = Boolean.parseBoolean(args[1]);
PhysicsSettings.doAirshipRotation = value;
sender.addChatMessage(new TextComponentString("Set doAirshipRotation to " + (PhysicsSettings.doAirshipRotation ? "enabled" : "disabled")));
return;
}
} else if (key.equals("doAirshipMovement")) {
if (args.length == 1) {
sender.addChatMessage(new TextComponentString("doAirshipMovement=" + PhysicsSettings.doAirshipMovement + " (Default: true)"));
return;
} else if (args.length == 2) {
boolean value = Boolean.parseBoolean(args[1]);
PhysicsSettings.doAirshipMovement = value;
sender.addChatMessage(new TextComponentString("Set doAirshipMovement to " + (PhysicsSettings.doAirshipMovement ? "enabled" : "disabled")));
return;
}
} else if (key.equals("doEtheriumLifting")) {
if (args.length == 1) {
sender.addChatMessage(new TextComponentString("doEtheriumLifting=" + PhysicsSettings.doEtheriumLifting + " (Default: true)"));
return;
} else if (args.length == 2) {
boolean value = Boolean.parseBoolean(args[1]);
PhysicsSettings.doEtheriumLifting = value;
sender.addChatMessage(new TextComponentString("Set doEtheriumLifting to " + (PhysicsSettings.doEtheriumLifting ? "enabled" : "disabled")));
return;
}
} else if (key.equals("save")) {
ValkyrienWarfareMod.instance.saveConfig();
sender.addChatMessage(new TextComponentString("Saved phyisics settings"));
return;
} else if (key.equals("help")) {
for (String command : completionOptions) {
sender.addChatMessage(new TextComponentString(command));
}
}
sender.addChatMessage(new TextComponentString(this.getCommandUsage(sender)));
}
use of net.minecraft.command.CommandException in project Galacticraft by micdoodle8.
the class CommandGCHouston method processCommand.
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
EntityPlayerMP playerBase = null;
MinecraftServer server = MinecraftServer.getServer();
boolean isOp = false;
Entity entitySender = sender.getCommandSenderEntity();
if (entitySender == null) {
isOp = true;
} else if (entitySender instanceof EntityPlayer) {
GameProfile prof = ((EntityPlayer) entitySender).getGameProfile();
isOp = server.getConfigurationManager().canSendCommands(prof);
}
if (args.length < 2) {
try {
if (args.length == 0) {
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(sender.getName(), true);
if (!playerBase.capabilities.isCreativeMode) {
if (ConfigManagerCore.challengeMode || !(playerBase.worldObj.provider instanceof IGalacticraftWorldProvider)) {
CommandBase.notifyOperators(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.notifyOperators(sender, this, msg);
return;
}
} else {
if (!isOp) {
CommandBase.notifyOperators(sender, this, "commands.gchouston.noop");
return;
}
playerBase = PlayerUtil.getPlayerBaseServerFromPlayerUsername(args[0], true);
}
if (playerBase != null) {
int dimID = ConfigManagerCore.idDimensionOverworld;
WorldServer worldserver = server.worldServerForDimension(dimID);
if (worldserver == null) {
worldserver = server.worldServerForDimension(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(new ItemStack[0]);
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.notifyOperators(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.getCommandUsage(sender)), new Object[0]);
}
}
Aggregations