How do I cause a command to only work for me?

I have a command in a command block that's repeating and always active with this command in it:

/execute @e[type=snowball] ~ ~ ~ summon Fireball ~ ~ ~ {direction:[0.0,0.0,0.0],ExplosionPower:0}

And I was wondering if I was able to make it so only I can use it.


Solution 1:

The command you posted does work but it is an odd command. In the comments, @Fabian warns of producing several fireballs in the path of the snowball. This is because you never kill the original snowball. That looks like this: Trail

In order to make this happen, I removed the direction data from your original command.

I believe the reason your command only summons one fireball is because with the direction data, the fireball follows the path of the snowball for a short time. The fireball destroys the snowball.


I had the same idea as @Galen Nare to use named snowballs but I believe they lose their name once then are thrown. Items vs entities vs projectiles kind of thing.


You could use this:

execute <your name> ~ ~ ~ execute @e[type=Snowball,r=2] ~ ~ ~ summon Fireball ~ ~ ~ {direction:[0.0d,0.0d,0.0d],ExplosionPower:0}

It will only succeed on snowballs found within a radius of 2 from you. It works as intended when you throw a snowball but it isn't perfect.

If someone were to stand next to you and throw a snowball or any time someone were to throw a snowball directly at you, it would summon a fireball.

Also, if you load snowballs into a dispenser and either stand near the dispenser or in it's path, a fireball with no direction is summoned.


Edit: This is an addition based on the suggestion of @D-Inventer. It adds some complication but also adds an extra check that will prevent some of the problems I listed with the original command.

Create a scoreboard using the statistic of snowballs used:

scoreboard objectives add Thrown stat.useItem.minecraft.snowball 

Next use 3 command blocks in a chain to test yourself for a score, run the summon command, and reset player scores.

First in a repeating/unconditional/always active command block:

scoreboard players test <Your Name> Thrown 1 

Second in a chain/conditional/always active command block:

execute @a[name=<Player Name>,score_Thrown_min=1] ~ ~ ~ execute @e[type=Snowball,r=2] ~ ~ ~ summon Fireball ~ ~ ~ {direction:[0.0d,0.0d,0.0d],ExplosionPower:0}

Third in another chain/conditional/always active command block:

scoreboard players set * Thrown 0

As you see, the second command is similar to the original command but includes a check for your score for snowballs thrown.

It only resets the player scores when you throw a snowball. You could make the last command block unconditional and it would reset the scores continuously. If you decide to do this, it will spam chat with command block output unless you use /gamerule commandBlockOutput false.

Also to note, these command blocks have to be located in loaded chunks. I would recommend the spawn chunks.