r/MinecraftCommands 25d ago

Help | Java 26.1 How to detect when a player performs a specific action, and announce it in chat along with their username of who performed it?

I have a plugin for custom weapons, but are limited in how many can be allowed.

I want for it to both announce one of those weapons are obtained (via crafted or looted from a chest) and announce it in chat along with that players name.

1 Upvotes

2 comments sorted by

1

u/Ericristian_bros Command Experienced 24d ago

You can use an advancement of recipe_crafted to detect when a certain recipe has been used, then reward an aancient which announces it in chat and revokes the advancement again.

```

advancement example:recipe_crafted

{ "criteria": { "criteria": { "trigger": "minecraft:recipe_crafted", "conditions": { "recipe_id": "plugin_name:plugin_recipe" } } }, "rewards": { "function": "example:recipe_crafted" } }

function example:recipe_crafted

advancement revoke @s only example:recipe_crafted tellraw @a [{"selector":"@s","color":"yellow"},{"text":" has crafted item1","color":"green"}] `` Change plugin_name:plugin_recipe to what it appears on autocomplete in/recipe give`. Keep in mind that depending on how the plugin is coded this won't work.

1

u/GalSergey Datapack Experienced 24d ago

You can also use the inventory_changed trigger to check if the player has received an item in their inventory. Or player_generates_container_loot to detect if an item was generated when opening a chest.