use of net.minecraft.command.CommandException in project Wizardry by TeamWizardry.
the class CommandWizardry method execute.
@Override
public void execute(@Nonnull MinecraftServer server, @Nonnull ICommandSender sender, @Nonnull String[] args) throws CommandException {
if (args.length < 1)
throw new WrongUsageException(getUsage(sender));
if (args[0].equalsIgnoreCase("reload")) {
ModuleRegistry.INSTANCE.loadUnprocessedModules();
ModuleRegistry.INSTANCE.copyMissingModulesFromResources(CommonProxy.directory);
ModuleRegistry.INSTANCE.processModules();
if (server.isDedicatedServer()) {
PacketHandler.NETWORK.sendToAll(new PacketSyncModules(ModuleRegistry.INSTANCE.modules));
}
notifyCommandListener(sender, this, "wizardry.command.success");
} else if (args[0].equalsIgnoreCase("reset")) {
notifyCommandListener(sender, this, "wizardry.command.reset");
File moduleDirectory = new File(CommonProxy.directory, "modules");
if (moduleDirectory.exists()) {
File[] files = moduleDirectory.listFiles();
if (files != null)
for (File file : files) {
String name = file.getName();
if (!file.delete()) {
throw new CommandException("wizardry.command.fail", name);
} else {
notifyCommandListener(sender, this, "wizardry.command.success_delete", name);
}
}
if (!moduleDirectory.delete()) {
throw new CommandException("wizardry.command.fail_dir_delete");
}
}
if (!moduleDirectory.exists())
if (!moduleDirectory.mkdirs()) {
throw new CommandException("wizardry.command.fail_dir_create");
}
ModuleRegistry.INSTANCE.setDirectory(moduleDirectory);
ModuleRegistry.INSTANCE.loadUnprocessedModules();
ModuleRegistry.INSTANCE.copyMissingModulesFromResources(CommonProxy.directory);
ModuleRegistry.INSTANCE.processModules();
if (server.isDedicatedServer()) {
PacketHandler.NETWORK.sendToAll(new PacketSyncModules(ModuleRegistry.INSTANCE.modules));
}
notifyCommandListener(sender, this, "wizardry.command.success");
} else if (args[0].equalsIgnoreCase("listModules")) {
notifyCommandListener(sender, this, TextFormatting.YELLOW + " ________________________________________________\\\\");
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | " + TextFormatting.GRAY + "Module List");
for (Module module : ModuleRegistry.INSTANCE.modules) {
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + module.getID() + TextFormatting.RESET + ": " + TextFormatting.GRAY + module.getReadableName());
}
notifyCommandListener(sender, this, TextFormatting.YELLOW + " |________________________________________________//");
} else if (args[0].equalsIgnoreCase("debug")) {
if (args.length < 2)
throw new WrongUsageException(getUsage(sender));
Module module = ModuleRegistry.INSTANCE.getModule(args[1]);
if (module == null) {
notifyCommandListener(sender, this, "Module not found.");
return;
}
notifyCommandListener(sender, this, TextFormatting.YELLOW + " ________________________________________________\\\\");
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | " + TextFormatting.GRAY + "Module " + module.getReadableName() + ":");
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Description " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getDescription());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Item Stack " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getItemStack().getDisplayName());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Burnout Fill " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getBurnoutFill());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | | |_ " + TextFormatting.DARK_GREEN + "Burnout Multiplier" + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getBurnoutMultiplier());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Mana Drain " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getManaDrain());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | | |_" + TextFormatting.DARK_GREEN + "Mana Multiplier " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getManaMultiplier());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Power Multiplier " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getPowerMultiplier());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Charge Up Time " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getChargeupTime());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Cooldown Time " + TextFormatting.GRAY + " | " + TextFormatting.GRAY + module.getCooldownTime());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Primary Color " + TextFormatting.GRAY + " | " + TextFormatting.RED + module.getPrimaryColor().getRed() + TextFormatting.GRAY + ", " + TextFormatting.GREEN + module.getPrimaryColor().getGreen() + TextFormatting.GRAY + ", " + TextFormatting.BLUE + module.getPrimaryColor().getBlue());
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Secondary Color " + TextFormatting.GRAY + " | " + TextFormatting.RED + module.getSecondaryColor().getRed() + TextFormatting.GRAY + ", " + TextFormatting.GREEN + module.getSecondaryColor().getGreen() + TextFormatting.GRAY + ", " + TextFormatting.BLUE + module.getSecondaryColor().getBlue());
if (!module.getAttributes().isEmpty())
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Default AttributeRegistry");
for (AttributeModifier attributeModifier : module.getAttributes()) notifyCommandListener(sender, this, TextFormatting.YELLOW + " | | |_ " + TextFormatting.GRAY + attributeModifier.toString());
ModuleModifier[] modifierList = module.applicableModifiers();
if (modifierList != null) {
notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.GREEN + "Applicable Modifiers ");
for (ModuleModifier modifier : modifierList) notifyCommandListener(sender, this, TextFormatting.YELLOW + " | |_ " + TextFormatting.DARK_GREEN + modifier.getID());
}
notifyCommandListener(sender, this, TextFormatting.YELLOW + " |________________________________________________//");
} else {
throw new WrongUsageException(getUsage(sender));
}
}
use of net.minecraft.command.CommandException in project Tropicraft by Tropicraft.
the class CommandTropicsMisc method execute.
@Override
public void execute(MinecraftServer server, ICommandSender commandSender, String[] args) throws CommandException {
EntityPlayerMP player = this.getCommandSenderAsPlayer(commandSender);
if (args.length > 0) {
if (args[0].equals("village_coord")) {
int x = 8452;
int z = 5921;
int relX = x - player.getPosition().getX();
int relZ = z - player.getPosition().getZ();
// x and z swapped on purpose
System.out.println("pos: " + relZ + ", " + 0 + ", " + relX);
} else if (args[0].equals("village_new")) {
int x = MathHelper.floor(player.posX);
int z = MathHelper.floor(player.posZ);
int y = player.world.getHeight(x, z);
if (y < WorldProviderTropicraft.MID_HEIGHT)
y = WorldProviderTropicraft.MID_HEIGHT + 1;
WorldDataInstance storage = player.world.getCapability(Tropicraft.WORLD_DATA_INSTANCE, null);
if (storage != null) {
TownKoaVillage village = new TownKoaVillage();
int newID = storage.getAndIncrementKoaIDVillage();
village.initData(newID, player.world.provider.getDimension(), new BlockPos(x, y, z));
// TEMP!?
village.direction = 0;
village.initFirstTime();
// wd.addTickingLocation(village);
storage.addTickingLocation(village);
}
} else if (args[0].equals("village_try")) {
int x = MathHelper.floor(player.posX);
int z = MathHelper.floor(player.posZ);
int y = player.world.getTopSolidOrLiquidBlock(new BlockPos(x, 0, z)).getY();
if (y < WorldProviderTropicraft.MID_HEIGHT)
y = WorldProviderTropicraft.MID_HEIGHT + 1;
boolean result = TownKoaVillageGenHelper.hookTryGenVillage(new BlockPos(x, y, z), player.world);
if (!result) {
System.out.println("failed to gen village");
}
} else if (args[0].equals("schematic_save")) {
try {
String name = args[1];
// Minecraft.getMinecraft().mouseHelper.ungrabMouseCursor();
Vec3d vec = commandSender.getPositionVector();
// Integer.parseInt(args[2]);
int sx = MathHelper.floor(parseCoordinate(vec.x, args[2], false).getResult());
// Integer.parseInt(args[3]);
int sy = MathHelper.floor(parseCoordinate(vec.y, args[3], false).getResult());
// Integer.parseInt(args[4]);
int sz = MathHelper.floor(parseCoordinate(vec.z, args[4], false).getResult());
// Integer.parseInt(args[5]);
int ex = MathHelper.floor(parseCoordinate(vec.x, args[5], false).getResult());
// Integer.parseInt(args[6]);
int ey = MathHelper.floor(parseCoordinate(vec.y, args[6], false).getResult());
// Integer.parseInt(args[7]);
int ez = MathHelper.floor(parseCoordinate(vec.z, args[7], false).getResult());
Build clipboardData = new Build(0, 0, 0, name, true);
clipboardData.newFormat = true;
clipboardData.recalculateLevelSize(sx, sy, sz, ex, ey, ez, true);
clipboardData.scanLevelToData(player.world);
clipboardData.writeNBT();
commandSender.sendMessage(new TextComponentString("schematic saved to " + name + ".schematic"));
} catch (Exception ex) {
ex.printStackTrace();
commandSender.sendMessage(new TextComponentString("command usage: tc_village schematic_save <filename> <start coords> <end coords>"));
commandSender.sendMessage(new TextComponentString("eg: tc_village schematic_save myfile 0 0 0 5 5 5"));
commandSender.sendMessage(new TextComponentString("start and end coords are inclusive"));
}
} else if (args[0].equals("schematic_print")) {
try {
Vec3d vec = commandSender.getPositionVector();
String name = args[1];
CoordinateArg sx = parseCoordinate(vec.x, args[2], false);
CoordinateArg sy = parseCoordinate(vec.y, args[3], false);
CoordinateArg sz = parseCoordinate(vec.z, args[4], false);
int x = MathHelper.floor(sx.getResult());
int y = MathHelper.floor(sy.getResult());
int z = MathHelper.floor(sz.getResult());
int direction = 0;
if (args.length > 5) {
direction = Integer.parseInt(args[5]);
}
Build buildData = new Build(x, y, z, name, false);
BuildJob bj = new BuildJob(-99, x, y, z, buildData);
bj.build.dim = player.world.provider.getDimension();
// skip air setting pass
bj.useFirstPass = false;
bj.useRotationBuild = true;
bj.build_rate = 10000;
bj.notifyFlag = 2;
bj.setDirection(direction);
// bj.customGenCallback = this;
// bj.blockIDsNoBuildOver.add(HostileWorlds.blockSourceStructure);
BuildServerTicks.buildMan.addBuild(bj);
commandSender.sendMessage(new TextComponentString("printing schematic"));
} catch (Exception ex) {
ex.printStackTrace();
commandSender.sendMessage(new TextComponentString("command usage: tc_village schematic_print <filename> <start coords>"));
commandSender.sendMessage(new TextComponentString("eg: tc_village schematic_print myfile 5 5 5"));
}
} else if (args[0].equals("entities")) {
HashMap<ResourceLocation, Integer> lookupCounts = new HashMap<>();
for (Entity ent : player.world.loadedEntityList) {
if (ent instanceof EntityLivingBase) {
ResourceLocation key = EntityList.getKey(ent.getClass());
lookupCounts.merge(key, 1, (a, b) -> a + b);
}
}
player.sendMessage(new TextComponentString("Entity counts: "));
int count = 0;
for (Map.Entry<ResourceLocation, Integer> entry : lookupCounts.entrySet()) {
ResourceLocation name = entry.getKey();
player.sendMessage(new TextComponentString(name + ": " + entry.getValue()));
count += entry.getValue();
}
player.sendMessage(new TextComponentString("total: " + count));
} else if (args[0].equals("mount")) {
float clDist = 99999;
Entity clEntity = null;
String name = args[1];
boolean reverse = false;
boolean playerMode = false;
Class clazz = EntityList.getClass(new ResourceLocation(name));
if (clazz == null) {
clazz = EntityPlayer.class;
playerMode = true;
}
if (args.length > 2) {
reverse = args[2].equals("reverse");
// no greifing
if (reverse) {
playerMode = false;
}
}
if (clazz != null) {
List<Entity> listEnts = player.world.getEntitiesWithinAABB(clazz, player.getEntityBoundingBox().grow(15, 15, 15));
for (Entity ent : listEnts) {
float dist = player.getDistance(ent);
if (dist < clDist) {
if (!playerMode) {
clDist = dist;
clEntity = ent;
} else {
if (player.getName().equals(name)) {
clEntity = ent;
break;
}
}
}
}
}
if (clEntity != null) {
if (reverse) {
clEntity.startRiding(player);
} else {
player.startRiding(clEntity);
}
}
} else if (args[0].equals("enc_unlock")) {
for (int i = 0; i < Tropicraft.encyclopedia.getPageCount(); i++) {
Tropicraft.encyclopedia.markPageAsNewlyVisible(i);
}
}
}
}
use of net.minecraft.command.CommandException in project Tropicraft by Tropicraft.
the class CommandTropicsTeleport method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
if (!(sender.getCommandSenderEntity() instanceof EntityPlayerMP)) {
throw new CommandException("Cannot teleport non-players!");
}
EntityPlayerMP player = (EntityPlayerMP) sender.getCommandSenderEntity();
TropicraftWorldUtils.teleportPlayer(player);
}
use of net.minecraft.command.CommandException in project DynamicSurroundings by OreCruncher.
the class CommandDS method execute.
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] parms) throws CommandException {
try {
final EntityPlayerMP player = getCommandSenderAsPlayer(sender);
final World world = player.world;
final DimensionEffectData data = DimensionEffectData.get(world);
boolean showHelp = false;
TextComponentString feedback = null;
if (parms.length == 0) {
showHelp = true;
} else if (COMMAND_OPTION_RESET.compareToIgnoreCase(parms[0]) == 0) {
world.provider.resetRainAndThunder();
feedback = new TextComponentString(Localization.format("dsurround.msg.RainReset"));
} else if (COMMAND_OPTION_RELOAD.compareToIgnoreCase(parms[0]) == 0) {
MinecraftForge.EVENT_BUS.post(new ReloadEvent.Configuration());
feedback = new TextComponentString(Localization.format("dsurround.msg.BiomeReload"));
} else if (COMMAND_OPTION_CONFIG.compareToIgnoreCase(parms[0]) == 0) {
feedback = new TextComponentString(config(world, data));
} else if (COMMAND_OPTION_STATUS.compareToIgnoreCase(parms[0]) == 0) {
if (parms.length < 2) {
showHelp = true;
} else if (COMMAND_OPTION_RAIN.compareToIgnoreCase(parms[1]) == 0) {
feedback = new TextComponentString(rainStatusOutput(world, data));
} else if (COMMAND_OPTION_THUNDER.compareToIgnoreCase(parms[1]) == 0) {
feedback = new TextComponentString(thunderStatusOutput(world, data));
}
} else if (COMMAND_OPTION_SETTIME.compareToIgnoreCase(parms[0]) == 0) {
if (parms.length < 3) {
showHelp = true;
} else {
final double d = parseDouble(parms[2], 0.0D, 1000.0D) * 20.0D * 60.0D;
if (COMMAND_OPTION_RAIN.compareToIgnoreCase(parms[1]) == 0) {
world.getWorldInfo().setRainTime((int) d);
feedback = new TextComponentString(Localization.format("dsurround.msg.RainTimeSet", FORMATTER.format(d)));
} else if (COMMAND_OPTION_THUNDER.compareToIgnoreCase(parms[1]) == 0) {
world.getWorldInfo().setThunderTime((int) d);
feedback = new TextComponentString(Localization.format("dsurround.msg.ThunderTimeSet", FORMATTER.format(d)));
} else {
showHelp = true;
}
}
} else if (COMMAND_OPTION_SETSTRENGTH.compareToIgnoreCase(parms[0]) == 0) {
if (parms.length < 3) {
showHelp = true;
} else {
final double d = parseDouble(parms[2], 0.0D, 100.0D) / 100.0D;
if (COMMAND_OPTION_RAIN.compareToIgnoreCase(parms[1]) == 0) {
data.setRainIntensity((float) d);
feedback = new TextComponentString(Localization.format("dsurround.msg.RainIntensitySet", FORMATTER.format(data.getRainIntensity() * 100)));
} else {
showHelp = true;
}
}
} else if (COMMAND_OPTION_SETMIN.compareToIgnoreCase(parms[0]) == 0) {
if (parms.length < 3) {
showHelp = true;
} else {
final double d = parseDouble(parms[2], 0.0D, 100.0D) / 100.0D;
if (COMMAND_OPTION_RAIN.compareToIgnoreCase(parms[1]) == 0) {
data.setMinRainIntensity((float) d);
feedback = new TextComponentString(Localization.format("dsurround.msg.MinRainIntensitySet", FORMATTER.format(data.getMinRainIntensity() * 100)));
} else {
showHelp = true;
}
}
} else if (COMMAND_OPTION_SETMAX.compareToIgnoreCase(parms[0]) == 0) {
if (parms.length < 3) {
showHelp = true;
} else {
final double d = parseDouble(parms[2], 0.0D, 100.0D) / 100.0D;
if (COMMAND_OPTION_RAIN.compareToIgnoreCase(parms[1]) == 0) {
data.setMaxRainIntensity((float) d);
feedback = new TextComponentString(Localization.format("dsurround.msg.MaxRainIntensitySet", FORMATTER.format(data.getMaxRainIntensity() * 100)));
} else {
showHelp = true;
}
}
} else {
showHelp = true;
}
if (showHelp) {
for (final String line : HELP) sender.sendMessage(new TextComponentString(line));
} else if (feedback != null) {
player.sendMessage(feedback);
}
} catch (final Exception ex) {
ex.printStackTrace();
}
}
use of net.minecraft.command.CommandException in project ICBM-Classic by BuiltBrokenModding.
the class CommandBlastSpreadTest method command_badInput.
@ParameterizedTest
@MethodSource("provideBadCommandInputs")
void command_badInput(String[] commandArgs, String errorMessage) {
// Validate we throw the right error
final CommandException exception = Assertions.assertThrows(CommandException.class, () -> command.handleCommand(testManager.getServer(), testManager.getServer(), commandArgs));
// validate the error contains the right message
Assertions.assertEquals(errorMessage, exception.getMessage());
}
Aggregations