Custom Events

Explanation

ConditionalEvents allows you to check for any event you want, even from other plugins. Below you will find an explained example to show you how these events work.

This section is mainly dedicated for people which have Java knowledge and know the basics of how to create a Minecraft plugin. If you don't understand this, feel free to contact me through private message (on Spigot) or in the discussion of the plugin.

Here is an example of a custom event which will activate when a player places a Turret of my plugin DefensiveTurrets. Remember you can add as many custom events you want, just add a new section with a new name. The plugin must have an API for this to work.

example1:
    type: custom
    custom_event_data:
      event: dt.ajneb97.api.TurretPlaceEvent
      player_variable: getPlayer()
      variables_to_capture:
      - '%turret_world%;getLocation().getWorld().getName()'
    conditions:
    - '%turret_world% equals spawn'
    actions:
      default:
      - 'cancel_event: true'
      - "message: &cYou can''t place turrets on this world."

As you can see, there is a new option called custom_event_data which is used just for custom events.

Event

This option defines the class of the event. If you want to check for a spigot/bukkit event, you can obtain this value in the Spigot javadocs: https://hub.spigotmc.org/javadocs/spigot/allclasses-index.html Just go to the link, search the event and click on it. In the first lines you will see the "package name" of this class, for example: org.bukkit.event.player.PlayerLevelChangeEvent

On the other hand, if you want to check a plugin event you need the API and the package for that event.

event: "dt.ajneb97.api.TurretPlaceEvent"

Player Variable

This is the method which will return the Player variable. The player variable contains all information about the user who is performing this event. For spigot/bukkit events it will most of the time be getPlayer().

You can create non-player events that don't have the getPlayer() method, if that is the case, remove the player_variable option.

player_variable: "getPlayer()"

Variables to Capture

Here you need to define the variables to capture and save. Each of the variables will be obtained executing a method. This method is provided by the API of the plugin, or the same bukkit/spigot class. For example, in the PlayerLevelChangeEvent link I used before, you can find the getNewLevel() and getOldLevel() methods, which returns the new and old level of the player when the event is executed.

Use the following format: <variable_to_capture>;<method>

variables_to_capture:
 - '%turret_world%;getLocation().getWorld().getName()'

Last updated