Java Code Examples for net.minecraft.command.CommandException

The following examples show how to use net.minecraft.command.CommandException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may want to check out the right sidebar which shows the related API usage.
Example 1
Source Project: fabric-carpet   Source File: CounterCommand.java    License: MIT License 6 votes vote down vote up
private static int resetCounter(ServerCommandSource source, String color)
{
    if (color == null)
    {
        HopperCounter.resetAll(source.getMinecraftServer());
        Messenger.m(source, "w Restarted all counters");
    }
    else
    {
        HopperCounter counter = HopperCounter.getCounter(color);
        if (counter == null) throw new CommandException(Messenger.s("Unknown wool color"));
        counter.reset(source.getMinecraftServer());
        Messenger.m(source, "w Restarted "+color+" counter");
    }
    return 1;
}
 
Example 2
@Override
public void execute(@Nonnull MinecraftServer server, @Nonnull ICommandSender sender, @Nonnull String[] args)
		throws CommandException {
	if (!IC2.platform.isOp(sender.getCommandSenderEntity().getUniqueID())) {
		sender.sendMessage(new TextComponentString(TextFormatting.RED
				+ "You do not have permission to use this command"));
		return;
	}
	if (args.length < 1) {
		return;
	}
	String s = args[0];
	int dim;
	try {
		dim = Integer.parseInt(s);
	} catch (NumberFormatException e) {
		sender.sendMessage(new TextComponentString(TextFormatting.RED + "Error parsing dimension!"));
		return;
	}
	if (sender instanceof EntityPlayer) {
		GTCommandTeleporter.teleportToDimension((EntityPlayer) sender, dim, 0, 100, 0);
	}
}
 
Example 3
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args)
    throws CommandException {
  StringBuilder builder = new StringBuilder();
  if (args.length < 2) {
    showMessage(getUsage(sender), sender);
    return;
  }

  String author = args[0];
  for (int i = 1; i < args.length; i++) {
    if (i > 1) {
      builder.append(" ");
    }
    builder.append(args[i]);
  }
  String message = builder.toString();
  System.out.println(String.format("YouTubeChatMock received %1$s from %2$s", message, author));
  LiveChatMessageAuthorDetails authorDetails = new LiveChatMessageAuthorDetails();
  authorDetails.setDisplayName(author);
  authorDetails.setChannelId(author);
  ((ChatService) YouTubeChat.getService()).broadcastMessage(
      authorDetails, new LiveChatSuperChatDetails(), message);
}
 
Example 4
Source Project: Signals   Source File: CommandSignals.java    License: GNU General Public License v3.0 6 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException{
    if(args.length == 0) throw new WrongUsageException("command.signals.noArgs");
    String subCommand = args[0];
    if(subCommand.equals("rebuildNetwork")) {
        RailNetworkManager.getServerInstance().rebuildNetwork();
        sender.sendMessage(new TextComponentTranslation("command.signals.networkCleared"));
    } else if(subCommand.equals("debug") && sender.getName().startsWith("Player" /* Playerx */)) {
        if(debug(server, sender, args)) {
            sender.sendMessage(new TextComponentString("DEBUG EXECUTED"));
        } else {
            sender.sendMessage(new TextComponentString("Could not execute debug!"));
        }
    } else {
        throw new WrongUsageException("command.signals.invalidSubCommand", subCommand);
    }
}
 
Example 5
Source Project: TinkersToolLeveling   Source File: CommandLevelTool.java    License: MIT License 6 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
  EntityPlayer player = getCommandSenderAsPlayer(sender);
  ItemStack itemStack = player.getHeldItemMainhand();

  if(itemStack != null && itemStack.getItem() instanceof ToolCore) {
    int xp;
    if(args.length > 0) {
      xp = parseInt(args[0]);
    }
    else {
      ToolLevelNBT data = new ToolLevelNBT(TinkerUtil.getModifierTag(itemStack, TinkerToolLeveling.modToolLeveling.getModifierIdentifier()));
      xp = TinkerToolLeveling.modToolLeveling.getXpForLevelup(data.level, itemStack);
    }
    TinkerToolLeveling.modToolLeveling.addXp(itemStack, xp, player);
  }
  else {
    throw new CommandException("No tinker tool in hand");
  }
}
 
Example 6
Source Project: AgriCraft   Source File: CommandStat.java    License: MIT License 6 votes vote down vote up
private void setStat(@Nonnull EntityPlayer player, @Nonnull ItemStack stack, @Nonnull IAgriStat stat, @Nonnull String target, @Nonnull int value) throws CommandException {
    switch (target) {
        case "growth":
            MessageUtil.messagePlayer(player, "Growth: {0} -> {1}", stat.getGrowth(), value);
            stat.withGrowth(value);
            break;
        case "gain":
            MessageUtil.messagePlayer(player, "Gain: {0} -> {1}", stat.getGain(), value);
            stat.withGain(value);
            break;
        case "strength":
            MessageUtil.messagePlayer(player, "Strength: {0} -> {1}", stat.getStrength(), value);
            stat.withStrength(value);
            break;
        case "all":
            MessageUtil.messagePlayer(player, "Growth: {0} -> {1}", stat.getGrowth(), value);
            stat.withGrowth(value);
            MessageUtil.messagePlayer(player, "Gain: {0} -> {1}", stat.getGain(), value);
            stat.withGain(value);
            MessageUtil.messagePlayer(player, "Strength: {0} -> {1}", stat.getStrength(), value);
            stat.withStrength(value);
            break;
        default:
            throw new CommandException("Invalid target: \"{0}\"!", target);
    }
}
 
Example 7
Source Project: AgriCraft   Source File: CommandStat.java    License: MIT License 6 votes vote down vote up
private void getStat(@Nonnull EntityPlayer player, @Nonnull ItemStack stack, @Nonnull IAgriStat stat, @Nonnull String target) throws CommandException {
    switch (target) {
        case "id":
            MessageUtil.messagePlayer(player, "ID: {0}", stat.getId());
            break;
        case "growth":
            MessageUtil.messagePlayer(player, "Growth: {0}", stat.getGrowth());
            break;
        case "gain":
            MessageUtil.messagePlayer(player, "Gain: {0}", stat.getGrowth());
            break;
        case "strength":
            MessageUtil.messagePlayer(player, "Strength: {0}", stat.getGrowth());
            break;
        case "all":
            MessageUtil.messagePlayer(player, "ID: {0}", stat.getId());
            MessageUtil.messagePlayer(player, "Growth: {0}", stat.getGrowth());
            MessageUtil.messagePlayer(player, "Gain: {0}", stat.getGain());
            MessageUtil.messagePlayer(player, "Strength: {0}", stat.getStrength());
            break;
        default:
            throw new CommandException("Invalid target: \"%s\"!", target);
    }
}
 
Example 8
Source Project: OpenModsLib   Source File: CommandGlDebug.java    License: MIT License 6 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
	if (args.length != 1) throw new CommandException("commands.generic.syntax");
	final String arg = args[0].toLowerCase(Locale.ROOT);
	if (arg.equals("disable")) {
		GL11.glDisable(KHRDebug.GL_DEBUG_OUTPUT);
	} else {
		final Set<Integer> allowedLevels = ALLOWED_LEVELS.get(arg);
		if (allowedLevels == null) throw new CommandException("commands.generic.syntax");

		GL11.glEnable(KHRDebug.GL_DEBUG_OUTPUT);
		for (int level : ALL_LEVELS) {
			final boolean isEnabled = allowedLevels.contains(level);
			KHRDebug.glDebugMessageControl(GL11.GL_DONT_CARE, GL11.GL_DONT_CARE, level, null, isEnabled);
		}
		KHRDebug.glDebugMessageCallback(new KHRDebugCallback());
	}

}
 
Example 9
Source Project: OpenModsLib   Source File: CommandSource.java    License: MIT License 6 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
	if (args.length < 1) throw new SyntaxErrorException();

	final String subCommand = args[0];

	if (subCommand.equals(COMMAND_CLASS)) {
		if (args.length < 2) throw new SyntaxErrorException();
		final String clsName = args[1];
		final ClassMeta meta = getMeta(clsName);

		sender.sendMessage(new TextComponentTranslation("openmodslib.command.class_source", meta.cls.getName(), meta.source()));

		final ApiInfo api = meta.api;
		if (api != null) {
			sender.sendMessage(new TextComponentTranslation("openmodslib.command.api_class",
					api.api, api.owner, api.version));
		}

		for (Map.Entry<File, Set<String>> e : meta.providerMods.entrySet())
			sender.sendMessage(new TextComponentTranslation("openmodslib.command.class_provider",
					e.getKey().getAbsolutePath(),
					Joiner.on(',').join(e.getValue())));
	}
}
 
Example 10
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
	Biome biome = null;
	if (args.length == 0) {
		sender.sendMessage(new TextComponentString("No biome specified"));
		return;
	}
	for (Biome b : ForgeRegistries.BIOMES.getValues()) {
		String name = b.getRegistryName().toString().replaceAll(" ", "_").toLowerCase();
		if (args[0].equalsIgnoreCase(name)) {
			biome = b;
		}
	}
	if (biome == null) {
		sender.sendMessage(new TextComponentString(TextFormatting.RED + "Error! Biome '" + args[0] + "' cannot be found!"));
		return;
	}
	long start = System.currentTimeMillis();
	final Biome finalBiome = biome;
	new Thread(() -> {
		BlockPos pos = spiralOutwardsLookingForBiome(sender, sender.getEntityWorld(), finalBiome, sender.getPosition().getX(), sender.getPosition().getZ(), TraverseConfig.findBiomeCommandTimeout);
		if (pos == null) {
			server.addScheduledTask(() -> sender.sendMessage(new TextComponentString(TextFormatting.RED + "Error! Biome '" + args[0] + "' could not be found after " + TextFormatting.GRAY + TraverseConfig.findBiomeCommandTimeout + "ms" + TextFormatting.RED + ".")));
			return;
		}
		if (sender instanceof EntityPlayerMP) {
			server.addScheduledTask(() -> {
				EntityPlayerMP playerMP = (EntityPlayerMP) sender;
				playerMP.connection.setPlayerLocation(pos.getX(), 150, pos.getZ(), 0, 0);
				sender.sendMessage(new TextComponentString(TextFormatting.WHITE + "Found '" + finalBiome.getRegistryName().toString() + "' Biome! " + TextFormatting.GRAY + "(" + (System.currentTimeMillis() - start) + "ms)"));
			});
			return;
		}
		server.addScheduledTask(() -> sender.sendMessage(new TextComponentString(TextFormatting.RED + "Error! An unknown error occurred.")));
	}, "Biome Finder - Traverse").start();
}
 
Example 11
Source Project: fabric-carpet   Source File: CounterCommand.java    License: MIT License 5 votes vote down vote up
private static int displayCounter(ServerCommandSource source, String color, boolean realtime)
{
    HopperCounter counter = HopperCounter.getCounter(color);
    if (counter == null) throw new CommandException(Messenger.s("Unknown wool color: "+color));

    for (BaseText message: counter.format(source.getMinecraftServer(), realtime, false))
    {
        source.sendFeedback(message, false);
    }
    return 1;
}
 
Example 12
Source Project: Kettle   Source File: VanillaCommandWrapper.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
    if (!testPermission(sender)) return true;

    ICommandSender icommandlistener = getListener(sender);
    try {
        dispatchVanillaCommand(sender, icommandlistener, args);
    } catch (CommandException commandexception) {
        // Taken from CommandHandler
        TextComponentTranslation chatmessage = new TextComponentTranslation(commandexception.getMessage(), commandexception.getErrorObjects());
        chatmessage.getStyle().setColor(TextFormatting.RED);
        icommandlistener.sendMessage(chatmessage);
    }
    return true;
}
 
Example 13
Source Project: Kettle   Source File: VanillaCommandWrapper.java    License: GNU General Public License v3.0 5 votes vote down vote up
private int getPlayerListSize(String as[]) throws CommandException {
    for (int i = 0; i < as.length; i++) {
        if (vanillaCommand.isUsernameIndex(as, i) && EntitySelector.matchesMultiplePlayersDefault(as[i])) {
            return i;
        }
    }
    return -1;
}
 
Example 14
Source Project: Kettle   Source File: CommandWrapper.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender iCommandSender, String[] args) throws CommandException {
    try {
        this.command.execute(sender, name, args);
    } catch (Exception e) {
        throw new CommandException(e.getMessage());
    }
}
 
Example 15
Source Project: Traverse-Legacy-1-12-2   Source File: CommandFindBiome.java    License: MIT License 5 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
	Biome biome = null;
	if (args.length == 0) {
		sender.sendMessage(new TextComponentString("No biome specified"));
		return;
	}
	for (Biome b : ForgeRegistries.BIOMES.getValues()) {
		String name = b.getRegistryName().toString().replaceAll(" ", "_").toLowerCase();
		if (args[0].equalsIgnoreCase(name)) {
			biome = b;
		}
	}
	if (biome == null) {
		sender.sendMessage(new TextComponentString(TextFormatting.RED + "Error! Biome '" + args[0] + "' cannot be found!"));
		return;
	}
	long start = System.currentTimeMillis();
	final Biome finalBiome = biome;
	new Thread(() -> {
		BlockPos pos = spiralOutwardsLookingForBiome(sender, sender.getEntityWorld(), finalBiome, sender.getPosition().getX(), sender.getPosition().getZ(), TraverseConfig.findBiomeCommandTimeout);
		if (pos == null) {
			server.addScheduledTask(() -> sender.sendMessage(new TextComponentString(TextFormatting.RED + "Error! Biome '" + args[0] + "' could not be found after " + TextFormatting.GRAY + TraverseConfig.findBiomeCommandTimeout + "ms" + TextFormatting.RED + ".")));
			return;
		}
		if (sender instanceof EntityPlayerMP) {
			server.addScheduledTask(() -> {
				EntityPlayerMP playerMP = (EntityPlayerMP) sender;
				playerMP.connection.setPlayerLocation(pos.getX(), 150, pos.getZ(), 0, 0);
				sender.sendMessage(new TextComponentString(TextFormatting.WHITE + "Found '" + finalBiome.getRegistryName().toString() + "' Biome! " + TextFormatting.GRAY + "(" + (System.currentTimeMillis() - start) + "ms)"));
			});
			return;
		}
		server.addScheduledTask(() -> sender.sendMessage(new TextComponentString(TextFormatting.RED + "Error! An unknown error occurred.")));
	}, "Biome Finder - Traverse").start();
}
 
Example 16
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
	if(sender instanceof EntityPlayer) {
		ItemStack cape = new ItemStack(ModItems.CAPE);
		NBTHelper.setInt(cape, "maxTick", 1000000);
		((EntityPlayer)sender).inventory.addItemStackToInventory(cape);
	} else {
		notifyCommandListener(sender, this, "wizardry.command.notplayer");
	}
}
 
Example 17
Source Project: ToroQuest   Source File: ToroQuestCommand.java    License: GNU General Public License v3.0 5 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {

	if (!(sender instanceof EntityPlayer)) {
		return;
	}

	EntityPlayer player = (EntityPlayer) sender;

	if (args.length < 1) {
		throw new WrongUsageException("commands.tq.usage", new Object[0]);
	}

	String command = args[0];

	System.out.println("command " + command);

	if ("rep".equals(command)) {
		adjustRep(server, player, args);
	} else if ("list".equals(command)) {
		listCommand(player, args);
	} else if ("gen".equals(command)) {
		genCommand(player, args);
	} else if ("gui".equals(command)) {
		guiCommand(player, args);
	} else if ("quest".equals(command)) {
		questCommand(player, args);
	} else if ("book".equals(command)) {
		bookCommand(player, args);
	} else {
		throw new WrongUsageException("commands.tq.usage", new Object[0]);
	}
}
 
Example 18
Source Project: ToroQuest   Source File: ToroQuestCommand.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void listCommand(EntityPlayer player, String[] args) throws CommandException {
	List<Province> provinces = CivilizationsWorldSaveData.get(player.world).getProvinces();
	StringBuilder sb = new StringBuilder();
	for (Province province : provinces) {
		sb.append(province.toString()).append("\n");
	}
	player.sendMessage(new TextComponentString(sb.toString()));
}
 
Example 19
Source Project: ToroQuest   Source File: ToroQuestCommand.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void genCommand(EntityPlayer player, String[] args) throws CommandException {
	if (args.length < 2) {
		throw new WrongUsageException("commands.tq.usage", new Object[0]);
	}
	String structure = args[1];

	if ("throne_room".equals(structure)) {
		new ThroneRoomGenerator().generate(player.getEntityWorld(), player.getEntityWorld().rand, player.getPosition());
		return;
	}

	if ("mage_tower".equals(structure)) {
		new MageTowerGenerator().generate(player.getEntityWorld(), player.getEntityWorld().rand, player.getPosition());
		return;
	}

	if ("bastions_lair".equals(structure)) {
		new BastionsLairGenerator().generate(player.getEntityWorld(), player.getEntityWorld().rand, player.getPosition());
		return;
	}

	if ("monolith".equals(structure)) {
		new MonolithGenerator().generate(player.getEntityWorld(), player.getEntityWorld().rand, player.getPosition());
		return;
	}

	if ("graveyard".equals(structure)) {
		new GraveyardGenerator().generate(player.getEntityWorld(), player.getEntityWorld().rand, player.getPosition());
		return;
	}

	throw new WrongUsageException("commands.tq.usage", new Object[0]);
}
 
Example 20
Source Project: ToroQuest   Source File: ToroQuestCommand.java    License: GNU General Public License v3.0 5 votes vote down vote up
private void guiCommand(EntityPlayer player, String[] args) throws CommandException {
	if (args.length < 2) {
		throw new WrongUsageException("commans.tq.usage", new Object[0]);
	}

	String type = args[1];

	if ("lord".equals(type)) {
		player.openGui(ToroQuest.INSTANCE, VillageLordGuiHandler.getGuiID(), player.world, player.getPosition().getX(),
				player.getPosition().getY(), player.getPosition().getZ());
		return;
	}

	throw new WrongUsageException("commands.tq.usage", new Object[0]);
}
 
Example 21
Source Project: Cyberware   Source File: CommandClearCyberware.java    License: MIT License 5 votes vote down vote up
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
	EntityPlayerMP entityplayermp = args.length == 0 ? getCommandSenderAsPlayer(sender) : getPlayer(server, sender, args[0]);
	NBTTagCompound nbttagcompound = null;

	CyberwareAPI.getCapability(entityplayermp).resetWare(entityplayermp);
	CyberwareAPI.updateData(entityplayermp);
	
	notifyCommandListener(sender, this, "cyberware.commands.clearCyberware.success", new Object[] {entityplayermp.getName()});
}
 
Example 22
Source Project: ExNihiloAdscensio   Source File: CommandReloadConfig.java    License: MIT License 5 votes vote down vote up
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    ExNihiloAdscensio.loadConfigs();
    Config.doNormalConfig(new File(ExNihiloAdscensio.configDirectory, "ExNihiloAdscensio.cfg"));
    sender.sendMessage(new TextComponentTranslation("commands.enreloadconfig.confirm"));
}
 
Example 23
Source Project: LookingGlass   Source File: CommandBaseAdv.java    License: GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns the given ICommandSender as a EntityPlayer or throw an exception.
 */
public static TileEntity getCommandSenderAsTileEntity(ICommandSender sender) {
	try {
		World world = sender.getEntityWorld();
		ChunkCoordinates coords = sender.getPlayerCoordinates();
		return world.getTileEntity(coords.posX, coords.posY, coords.posZ);
	} catch (Exception e) {
		throw new CommandException("Could not get tile entity");
	}
}
 
Example 24
@Override
public void execute(MinecraftServer minecraftServer, ICommandSender sender, String[] args) throws CommandException {
    if ((sender instanceof EntityPlayerMP)) {
        EntityPlayerMP player = (EntityPlayerMP) sender;
        if (player.worldObj.isRemote) {
            return;
        }
        FawePlayer<Object> fp = FawePlayer.wrap(player);
        cmd.executeSafe(fp, args);
    }
}
 
Example 25
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
    if ((sender instanceof EntityPlayerMP)) {
        EntityPlayerMP player = (EntityPlayerMP) sender;
        if (player.worldObj.isRemote) {
            return;
        }
        FawePlayer<Object> fp = FawePlayer.wrap(player);
        cmd.executeSafe(fp, args);
    }
}
 
Example 26
@Override
public void execute(MinecraftServer minecraftServer, ICommandSender sender, String[] args) throws CommandException {
    if ((sender instanceof EntityPlayerMP)) {
        EntityPlayerMP player = (EntityPlayerMP) sender;
        if (player.world.isRemote) {
            return;
        }
        FawePlayer<Object> fp = FawePlayer.wrap(player);
        cmd.executeSafe(fp, args);
    }
}
 
Example 27
@Override
public void processCommand(ICommandSender sender, String[] args) throws CommandException {
    if ((sender instanceof EntityPlayerMP)) {
        EntityPlayerMP player = (EntityPlayerMP) sender;
        if (player.worldObj.isRemote) {
            return;
        }
        FawePlayer<Object> fp = FawePlayer.wrap(player);
        cmd.executeSafe(fp, args);
    }
}
 
Example 28
@Override
public void execute(MinecraftServer minecraftServer, ICommandSender sender, String[] args) throws CommandException {
    if ((sender instanceof EntityPlayerMP)) {
        EntityPlayerMP player = (EntityPlayerMP) sender;
        if (player.worldObj.isRemote) {
            return;
        }
        FawePlayer<Object> fp = FawePlayer.wrap(player);
        cmd.executeSafe(fp, args);
    }
}
 
Example 29
@Override
public void execute(MinecraftServer minecraftServer, ICommandSender sender, String[] args) throws CommandException {
    if ((sender instanceof EntityPlayerMP)) {
        EntityPlayerMP player = (EntityPlayerMP) sender;
        if (player.world.isRemote) {
            return;
        }
        FawePlayer<Object> fp = FawePlayer.wrap(player);
        cmd.executeSafe(fp, args);
    }
}
 
Example 30
Source Project: AgriCraft   Source File: CommandNbt.java    License: MIT License 5 votes vote down vote up
private void listNbt(@Nonnull EntityPlayer player, @Nonnull ItemStack stack, @Nonnull NBTTagCompound tag) throws CommandException {
    for (String key : tag.getKeySet()) {
        final NBTBase entry = tag.getTag(key);
        final String type = NBTBase.NBT_TYPES[entry.getId()];
        MessageUtil.messagePlayer(player, "`l`3{0}`r `b{1}`r: `2{2}`r", type, key, entry);
    }
}