This event is fired when the player's xp count is changed. If the amount is positive the xp is being added. If the xp is negative, the xp is being removed. This event takes place before the xp has changed, allowing you to change the amount, or negate the change entirely.

The event is cancelable.

If the event is canceled, the xp will not change

The event does not have a result.

Importing the class

Link to importing-the-class

It might be required for you to import the package if you encounter any issues (like casting an Array), so better be safe than sorry and add the import at the very top of the file.

ZenScript
Copy
import crafttweaker.api.event.entity.player.xp.MCXpChangeEvent;

Extending MCPlayerXPEvent

Link to extending-mcplayerxpevent

MCXpChangeEvent extends MCPlayerXPEvent. That means all methods available in MCPlayerXPEvent are also available in MCXpChangeEvent

Name: getXp

Gets the amount of xp that the player's xp counter is being changed by.

Returns: The amount of xp that the player's xp counter is being changed by.
Return Type: int

ZenScript
Copy
// MCXpChangeEvent.getXp() as int

event.getXp();

Name: setXp

Sets the amount of xp to change the player's xp counter by.

Return Type: void

ZenScript
Copy
// MCXpChangeEvent.setXp(amount as int) as void

event.setXp(15);
ParameterTypeDescription
Parameter
amount
Type
int
Description
The amount of xp that the player's xp counter should be
changed by.
NameTypeHas GetterHas SetterDescription
Name
xp
Type
int
Has Getter
true
Has Setter
true
Description
Gets the amount of xp that the player's xp counter is being changed by.