#How do I execute a console command with the player's name in it, but not send the player a message?

1 messages · Page 1 of 1 (latest)

frozen flint
#

How do I execute a console command with the player's name in it, but not send the player a message?

crystal lagoon
#

Bukkit.getConsoleSender().sendMessage("/command")?

#

that doesnt make sense

frozen flint
#

i want the console to execute command
/give player minecraft:enderman_spawn_egg{display:{Name:'{"text":"Ender Dragon Spawn Egg","italic":false}'},EntityTag:{id:"minecraft:ender_dragon",CustomName:""}}

crystal lagoon
#

then use the thing i sent

frozen flint
#

but it has a quotation mark

#

wouldn't it end the command?

#

or should I double it?

crystal lagoon
#

whats a quotation mark

#

:?

frozen flint
#

"

crystal lagoon
#

ah nope that wont

frozen flint
#

it also has '

storm nexus
#

Why not just parse the players name using Bukkit#getOfflinePlayer(String name)?

frozen flint
#

the player is online

#

why would it get the offline player name

#

(im new to spigot so if thats dumb please tell me)

storm nexus
#

Yea, but offline players work just fine even if they are actually online.

frozen flint
#

how would I insert it?

crystal lagoon
#

lol

frozen flint
#

"hihihi" Bukkit#getOfflinePlayer(String name) "hihi"?

storm nexus
#

Oh, well if they are online you cod use Bukkit#getPlayer(string)

#

Well Bukkit#getOfflinePlayer() returns an OfflinePlayer. Bukkit#getPlayer() returns a player. So you just need to use the method #getName() on one of those objects if you want to put it in a string.

frozen flint
#

could you give me an example?

#

of how it would look

crystal lagoon
#

Player player = Bukkit.getPlayer("FourteenDoggo")

storm nexus
#

^

crystal lagoon
#

same for offline player

#

but that method wont return null iir

frozen flint
#

as in how do i add it to the command

#

"part1" player "part2"?

storm nexus
#

By using the methods in the Player object.
Player#getName().

crystal lagoon
#

why do you need a player object if youre sending the command with the player name in?

storm nexus
#

You do know how to concatenate strings right?

#

Also, if you are making commands and running them from console, you have far fewer things to worry about.

You could just get the input after the player name and use that for your whatever the command does.

#

Oh wait a minute.

#

You could also use Bukkit#dispatchCommand() if you wanted to run a premade command.

#

You’d just want to replace the parts of the string with the proper variables.

crystal lagoon
#

ah he thats something too

storm nexus
#

You may also want to use the namespaced versions of the commands if you are putting it in string format.

Any plugin could overwrite the functionality of an existing command.

So if you want to make sure your code works regardless of whatever plugins you have installed, make sure you prefix it with whatever plugin namespace you need.

Example: /give vs /minecraft:give vs /essentials:give

frozen flint
#

exactly

#

im gonna do /minecraft:give

#

because everyone has essentials installed

crystal lagoon
#

not everyone >_<

frozen flint
#

nearly everyone

willow hare
#

bro essentials give sucks

#

ngl

#

oops reactivated an old thread lol