Skip to content

Event triggers ​

Craftorithm supports multiple Bukkit event types as trigger types, covering player, entity, inventory, and block events.

Usage ​

Set the event name as the type field in your trigger YAML:

yaml
my_trigger:
  type: 'player_join'
  actions:
    - 'tell("&aWelcome!")'

Event List ​

Player Events ​

EventDescriptionContext Variables
player_joinPlayer joins—
player_quitPlayer quits—
player_deathPlayer dieskiller_name
player_respawnPlayer respawns—
player_interactPlayer interactsaction
player_interact_entityInteract with entityentity_type
player_advancementAdvancement completedadvancement
player_level_changeLevel changesold_level, new_level
player_exp_changeExperience changesamount
player_toggle_sneakSneak togglesneaking
player_toggle_sprintSprint togglesprinting
player_item_consumeItem consumeditem
player_item_heldHeld item slot changesprevious_slot, new_slot
player_animationPlayer animation—
player_bed_enterEnter bed—
player_bed_leaveLeave bed—
player_bucket_fillFill bucket—
player_bucket_emptyEmpty bucket—
player_changed_worldWorld changefrom
player_portalEnter portal—
player_teleportTeleportcause
player_fishFishingstate
player_shear_entityShear entityentity_type
player_unleash_entityUnleash entity—
player_edit_bookEdit book—
player_statisticStatistic changesstatistic, value
player_swap_hand_itemsSwap hand items—
player_drop_itemDrop itemitem
player_pickup_itemPick up itemitem
player_velocityVelocity change—
player_game_mode_changeGame mode changenew_game_mode
player_resource_pack_statusResource pack status changestatus
player_item_damageItem durability lossitem, damage
player_item_mendMendingitem, amount, repair_amount
player_recipe_discoverRecipe discoveredrecipe
player_take_campfireTake item from campfireitem
player_movePlayer moves-
player_command_preprocessCommand preprocessingmessage
async_player_chatAsync chatmessage

Entity Events ​

EventDescriptionContext Variables
damage_entityEntity damageddamage, entity_type, entity_name
kill_entityEntity killedentity_type, entity_name
entity_shoot_bowShoot bowforce
entity_breedBreedingentity_type
entity_tameTamingentity_type
entity_potion_effectPotion effect changeeffect_type

Inventory Events ​

EventDescriptionContext Variables
inventory_clickClick slotslot, click_type
inventory_closeClose inventory—
inventory_openOpen inventory—
prepare_grindstoneGrindstone shows result—
trade_selectSelect villager tradeindex

Block Events ​

EventDescriptionContext Variables
block_breakBreak blockblock_type
block_placePlace blockblock_type

Recipe Events ​

EventDescriptionContext Variables
recipe_loadFires when Craftorithm loads a reciperecipe_key

In a recipe_load trigger, recipe_key holds the key of the recipe being loaded (for example craftorithm:my_recipe). This event fires while loading recipes, and there is no player in the context.

yaml
on_recipe_load:
  type: 'recipe_load'
  actions:
    - 'log("Loading recipe: " + recipe_key)'

Context Variables ​

Each event type automatically injects relevant variables into the script context.

Event Object ​

All triggers have an event object in their context that allows direct access to the Bukkit event object.

The event object is a reflective property resolver that can access event properties through method calls.

Usage Example ​

yaml
on_craft_diamond_sword:
  type: 'crafting'
  recipes:
    - 'minecraft:diamond_sword'
  conditions:
    mode: script
    body:
      - 'if event.get("view").get("player").invoke("getName") == "Yufiria_"'
      - '  tell("The plugin developer is crafting!")'
      - 'endif'
  actions:
    - 'tell("&aCrafting successful!")'
    - 'give_level(100)'

Access Methods ​

  • event.get("propertyName") - Get event property
  • .invoke("methodName") - Call method on object
  • Chained calls supported: event.get("view").get("player").invoke("getName")

Example: Check Killed Entity Type ​

yaml
on_kill_zombie:
  type: 'kill_entity'
  conditions:
    - 'entity_type == "ZOMBIE"'
  actions:
    - 'tell("&aYou killed a zombie!")'

Example: Check Advancement ​

yaml
on_diamond_advancement:
  type: 'player_advancement'
  conditions:
    - 'advancement == "minecraft:story/mine_diamond"'
  actions:
    - 'tell("&bYou found diamonds!")'
    - 'give_money(1000)'

Example: Check Chat Message ​

yaml
on_keyword:
  type: 'async_player_chat'
  conditions:
    - 'perm("craftorithm.vip")'
  actions:
    - 'tell("&aVIP spoke!")'

基于 GPL-3.0 许可证发布