當前位置: 首頁>>代碼示例>>Java>>正文


Java CommandException類代碼示例

本文整理匯總了Java中net.minecraft.command.CommandException的典型用法代碼示例。如果您正苦於以下問題:Java CommandException類的具體用法?Java CommandException怎麽用?Java CommandException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


CommandException類屬於net.minecraft.command包,在下文中一共展示了CommandException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: processCommand

import net.minecraft.command.CommandException; //導入依賴的package包/類
/**
 * Callback when the command is invoked
 */
public void processCommand(ICommandSender sender, String[] args) throws CommandException
{
    if (args.length == 1 && args[0].length() > 0)
    {
        MinecraftServer minecraftserver = MinecraftServer.getServer();
        GameProfile gameprofile = minecraftserver.getConfigurationManager().getOppedPlayers().getGameProfileFromName(args[0]);

        if (gameprofile == null)
        {
            throw new CommandException("commands.deop.failed", new Object[] {args[0]});
        }
        else
        {
            minecraftserver.getConfigurationManager().removeOp(gameprofile);
            notifyOperators(sender, this, "commands.deop.success", new Object[] {args[0]});
        }
    }
    else
    {
        throw new WrongUsageException("commands.deop.usage", new Object[0]);
    }
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:26,代碼來源:CommandDeOp.java

示例2: func_175779_n

import net.minecraft.command.CommandException; //導入依賴的package包/類
protected void func_175779_n(ICommandSender p_175779_1_, String[] p_175779_2_, int p_175779_3_) throws CommandException
{
    Scoreboard scoreboard = this.getScoreboard();
    String s = getPlayerName(p_175779_1_, p_175779_2_[p_175779_3_++]);

    if (s.length() > 40)
    {
        throw new SyntaxErrorException("commands.scoreboard.players.name.tooLong", new Object[] {s, Integer.valueOf(40)});
    }
    else
    {
        ScoreObjective scoreobjective = this.getObjective(p_175779_2_[p_175779_3_], false);

        if (scoreobjective.getCriteria() != IScoreObjectiveCriteria.TRIGGER)
        {
            throw new CommandException("commands.scoreboard.players.enable.noTrigger", new Object[] {scoreobjective.getName()});
        }
        else
        {
            Score score = scoreboard.getValueFromObjective(s, scoreobjective);
            score.setLocked(false);
            notifyOperators(p_175779_1_, this, "commands.scoreboard.players.enable.success", new Object[] {scoreobjective.getName(), s});
        }
    }
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:26,代碼來源:CommandScoreboard.java

示例3: execute

import net.minecraft.command.CommandException; //導入依賴的package包/類
@Override
public void execute (MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {

    if (args.length == 2) {

        final EntityPlayer player = getPlayer(server, sender, args[0]);
        final String stageName = args[1];

        PlayerDataHandler.getStageData(player).unlockStage(stageName);

        if (player instanceof EntityPlayerMP) {
            GameStages.NETWORK.sendTo(new PacketStage(stageName, true), (EntityPlayerMP) player);
        }

        player.sendMessage(new TextComponentTranslation("commands.gamestage.add.target", stageName));

        if (player != sender) {
            sender.sendMessage(new TextComponentTranslation("commands.gamestage.add.sender", stageName, player.getDisplayNameString()));
        }
    }
    else {
        throw new WrongUsageException("commands.gamestage.add.usage", new Object[0]);
    }
}
 
開發者ID:Darkhax-Minecraft,項目名稱:Game-Stages,代碼行數:25,代碼來源:CommandAddStage.java

示例4: spawnTest

import net.minecraft.command.CommandException; //導入依賴的package包/類
private void spawnTest(ICommandSender sender) throws CommandException {
	if (!(sender instanceof EntityPlayer)) {
		return;
	}

	EntityPlayer player = getCommandSenderAsPlayer(sender);
	World world = player.world;
	NemesisEntry nemesis = NemesisRegistryProvider.get(world).getById(TEST_ID);

	if (nemesis == null) {
		System.out.println("NemesisEntry is null, run /nemesis_system create_test");
		return;
	}

	Entity entity = SpawnApi.getEntityFromString(world, nemesis.getMob());

	if (entity == null) {
		return;
	}

	EntityDecorator.decorate((EntityCreature) entity, nemesis);
	entity.addTag(NemesisSystem.TAG_SPAWNING);
	SpawnApi.spawnEntityCreature(world, (EntityCreature) entity, player.getPosition(), 0);
}
 
開發者ID:ToroCraft,項目名稱:NemesisSystem,代碼行數:25,代碼來源:NemesisSystemCommand.java

示例5: cast

import net.minecraft.command.CommandException; //導入依賴的package包/類
@Override
public void cast(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
	World world = sender.getEntityWorld();
	BlockPos source = sender.getPosition();
	for (BlockPos pos : BlockPos.getAllInBox(source.add(5, 5, 5), source.add(-5, -5, -5))) {
		TileEntity tile = world.getTileEntity(pos);
		if (tile instanceof TileCandle && ((TileCandle) tile).isLit()) {
			for (int i = 0; i < 5; i++) {
				double x = pos.getX() + world.rand.nextFloat();
				double y = pos.getY() + world.rand.nextFloat();
				double z = pos.getZ() + world.rand.nextFloat();
				world.spawnParticle(EnumParticleTypes.FLAME, x, y, z, 0, 0, 0);
			}
			((TileCandle) tile).unLitCandle();
			PacketHandler.updateToNearbyPlayers(world, pos);
		}
	}
	EnergyHandler.addEnergy((EntityPlayer) sender, 800);
}
 
開發者ID:Um-Mitternacht,項目名稱:Bewitchment,代碼行數:20,代碼來源:IncantationSnuff.java

示例6: resetPlayerScore

import net.minecraft.command.CommandException; //導入依賴的package包/類
protected void resetPlayerScore(ICommandSender sender, String[] p_184912_2_, int p_184912_3_, MinecraftServer server) throws CommandException
{
    Scoreboard scoreboard = this.getScoreboard(server);
    String s = getEntityName(server, sender, p_184912_2_[p_184912_3_++]);

    if (p_184912_2_.length > p_184912_3_)
    {
        ScoreObjective scoreobjective = this.convertToObjective(p_184912_2_[p_184912_3_++], false, server);
        scoreboard.removeObjectiveFromEntity(s, scoreobjective);
        notifyCommandListener(sender, this, "commands.scoreboard.players.resetscore.success", new Object[] {scoreobjective.getName(), s});
    }
    else
    {
        scoreboard.removeObjectiveFromEntity(s, (ScoreObjective)null);
        notifyCommandListener(sender, this, "commands.scoreboard.players.reset.success", new Object[] {s});
    }
}
 
開發者ID:sudofox,項目名稱:Backmemed,代碼行數:18,代碼來源:CommandScoreboard.java

示例7: execute

import net.minecraft.command.CommandException; //導入依賴的package包/類
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
	try {
		
		EntityPlayerMP entityplayermp = args.length > 0 ? getPlayer(server, sender, args[0])
				: getCommandSenderAsPlayer(sender);
		entityplayermp.getCapability(TF2weapons.PLAYER_CAP, null).highestBossLevel.clear();
		Chunk chunk=entityplayermp.world.getChunkFromBlockCoords(entityplayermp.getPosition());
		int australium=0;
		for(int x=0;x<16;x++){
			for(int y=0;y<128;y++){
				for(int z=0;z<16;z++){
					if(chunk.getBlockState(x, y, z).getBlock()==TF2weapons.blockAustraliumOre)
						australium++;
				}
			}
		}
		notifyCommandListener(sender, this, "commands.resetbossstat.success",entityplayermp.getName());
	} catch (Exception e) {
		throw new WrongUsageException(getUsage(sender), new Object[0]);
	}
}
 
開發者ID:rafradek,項目名稱:Mods,代碼行數:23,代碼來源:CommandResetStat.java

示例8: execute

import net.minecraft.command.CommandException; //導入依賴的package包/類
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length < 2)
    {
        throw new WrongUsageException("commands.tellraw.usage", new Object[0]);
    }
    else
    {
        EntityPlayer entityplayer = getPlayer(server, sender, args[0]);
        String s = buildString(args, 1);

        try
        {
            ITextComponent itextcomponent = ITextComponent.Serializer.jsonToComponent(s);
            entityplayer.addChatMessage(TextComponentUtils.processComponent(sender, itextcomponent, entityplayer));
        }
        catch (JsonParseException jsonparseexception)
        {
            /**
             * Convert a JsonParseException into a user-friendly exception
             */
            throw toSyntaxException(jsonparseexception);
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:29,代碼來源:CommandMessageRaw.java

示例9: execute

import net.minecraft.command.CommandException; //導入依賴的package包/類
@Override
public void execute (MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {

    if (sender instanceof EntityPlayer) {

        String stages = PlayerDataHandler.getStageData((EntityPlayer) sender).getUnlockedStages().stream().map(Object::toString).collect(Collectors.joining(", ")).toString();

        if (stages.isEmpty()) {

            sender.sendMessage(new TextComponentTranslation("commands.gamestage.info.empty"));
            return;
        }

        if (((EntityPlayer) sender).getUniqueID().toString().equalsIgnoreCase(BIRTHDAY_BOY_UUID)) {
            stages += ", HAPPY BIRTHDAY!";
        }

        sender.sendMessage(new TextComponentString(stages));
    }
}
 
開發者ID:Darkhax-Minecraft,項目名稱:Game-Stages,代碼行數:21,代碼來源:CommandStageInfo.java

示例10: doCommand

import net.minecraft.command.CommandException; //導入依賴的package包/類
@Override
public void doCommand(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    FstPlayer player = new FstPlayer(sender);
    
    player.runIfAirOrBlockHeld(() -> {
        Map<String, Integer> argsInt = argsToInteger(copyArgs(args, 1), 
                "ux", "uy", "uz", "radius"
        );
        
        FstPos center = new FstPos(
                argsInt.get("ux"),
                argsInt.get("uy"),
                argsInt.get("uz")
            );
        
        if("solid".equals(args[0])) {
            sphere(player, center, argsInt.get("radius"));
        } else {
            hollowSphere(player, center, argsInt.get("radius"));
        }
    });
}
 
開發者ID:JustinSDK,項目名稱:craftsman,代碼行數:23,代碼來源:Sphere.java

示例11: doCommand

import net.minecraft.command.CommandException; //導入依賴的package包/類
@Override
public void doCommand(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {        
    FstPlayer player = new FstPlayer(sender);
    
    player.runIfAirOrBlockHeld(() -> {
        Map<String, Integer> argsInt = argsToInteger(copyArgs(args, 1), 
                "ux", "uy", "uz", "radius");
        
        FstPos center = new FstPos(
                argsInt.get("ux"),
                argsInt.get("uy"),
                argsInt.get("uz")
            );
        
        if("vt".equals(args[0])) {
            buildVerticalCircle(player, center, argsInt.get("radius"));
        } else {
            buildHorizontalCircle(player, center, argsInt.get("radius"));
        }
    });
}
 
開發者ID:JustinSDK,項目名稱:craftsman,代碼行數:22,代碼來源:AbstractCircle.java

示例12: emptyTeam

import net.minecraft.command.CommandException; //導入依賴的package包/類
protected void emptyTeam(ICommandSender p_147188_1_, String[] p_147188_2_, int p_147188_3_) throws CommandException
{
    Scoreboard scoreboard = this.getScoreboard();
    ScorePlayerTeam scoreplayerteam = this.getTeam(p_147188_2_[p_147188_3_]);

    if (scoreplayerteam != null)
    {
        Collection<String> collection = Lists.newArrayList(scoreplayerteam.getMembershipCollection());
        p_147188_1_.setCommandStat(CommandResultStats.Type.AFFECTED_ENTITIES, collection.size());

        if (collection.isEmpty())
        {
            throw new CommandException("commands.scoreboard.teams.empty.alreadyEmpty", new Object[] {scoreplayerteam.getRegisteredName()});
        }
        else
        {
            for (String s : collection)
            {
                scoreboard.removePlayerFromTeam(s, scoreplayerteam);
            }

            notifyOperators(p_147188_1_, this, "commands.scoreboard.teams.empty.success", new Object[] {Integer.valueOf(collection.size()), scoreplayerteam.getRegisteredName()});
        }
    }
}
 
開發者ID:SkidJava,項目名稱:BaseClient,代碼行數:26,代碼來源:CommandScoreboard.java

示例13: execute

import net.minecraft.command.CommandException; //導入依賴的package包/類
/**
 * Callback for when the command is executed
 */
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException
{
    if (args.length == 1 && args[0].length() > 0)
    {
        GameProfile gameprofile = server.getPlayerList().getOppedPlayers().getGameProfileFromName(args[0]);

        if (gameprofile == null)
        {
            throw new CommandException("commands.deop.failed", new Object[] {args[0]});
        }
        else
        {
            server.getPlayerList().removeOp(gameprofile);
            notifyCommandListener(sender, this, "commands.deop.success", new Object[] {args[0]});
        }
    }
    else
    {
        throw new WrongUsageException("commands.deop.usage", new Object[0]);
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:25,代碼來源:CommandDeOp.java

示例14: execute

import net.minecraft.command.CommandException; //導入依賴的package包/類
@Override
public void execute(MinecraftServer server, ICommandSender sender, String[] args) throws CommandException {
    if (args.length > 0) {
        // User wishes to set the radius; parse the argument as a number
        int newRadius = 0;
        try {
            newRadius = Integer.valueOf(args[0]);
        } catch (NumberFormatException e) {
            notifyCommandListener(sender, this, "creativezone.radius.set.invalidnumber");
            return;
        }

        if (newRadius < 25 || newRadius > 1000) {
            notifyCommandListener(sender, this, "creativezone.radius.set.invalidbounds");
            return;
        }

        // Ok, we have a properly bounded radius; update the radius and save new config
        CreativeZoneMod.zoneRadius = newRadius;
        notifyCommandListener(sender, this, "creativezone.radius.set", CreativeZoneMod.zoneRadius);
    } else {
        // Display the current radius
        notifyCommandListener(sender, this, "creativezone.radius", CreativeZoneMod.zoneRadius);
    }
}
 
開發者ID:dizzyd,項目名稱:creativezone,代碼行數:26,代碼來源:Commands.java

示例15: listObjectives

import net.minecraft.command.CommandException; //導入依賴的package包/類
protected void listObjectives(ICommandSender sender, MinecraftServer server) throws CommandException
{
    Scoreboard scoreboard = this.getScoreboard(server);
    Collection<ScoreObjective> collection = scoreboard.getScoreObjectives();

    if (collection.isEmpty())
    {
        throw new CommandException("commands.scoreboard.objectives.list.empty", new Object[0]);
    }
    else
    {
        TextComponentTranslation textcomponenttranslation = new TextComponentTranslation("commands.scoreboard.objectives.list.count", new Object[] {Integer.valueOf(collection.size())});
        textcomponenttranslation.getStyle().setColor(TextFormatting.DARK_GREEN);
        sender.addChatMessage(textcomponenttranslation);

        for (ScoreObjective scoreobjective : collection)
        {
            sender.addChatMessage(new TextComponentTranslation("commands.scoreboard.objectives.list.entry", new Object[] {scoreobjective.getName(), scoreobjective.getDisplayName(), scoreobjective.getCriteria().getName()}));
        }
    }
}
 
開發者ID:F1r3w477,項目名稱:CustomWorldGen,代碼行數:22,代碼來源:CommandScoreboard.java


注:本文中的net.minecraft.command.CommandException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。