SPIGOT-7209: Accessors and events for player's exp cooldown

By: FreeSoccerHDX <freesoccerhdx@gmail.com>
This commit is contained in:
Bukkit/Spigot 2023-04-21 18:46:56 +10:00
parent c156e89f42
commit 6c20b023e6
2 changed files with 100 additions and 0 deletions

View File

@ -26,6 +26,7 @@ import org.bukkit.block.data.BlockData;
import org.bukkit.conversations.Conversable;
import org.bukkit.event.block.BlockBreakEvent;
import org.bukkit.event.block.BlockDropItemEvent;
import org.bukkit.event.player.PlayerExpCooldownChangeEvent;
import org.bukkit.event.player.PlayerResourcePackStatusEvent;
import org.bukkit.inventory.EquipmentSlot;
import org.bukkit.inventory.ItemStack;
@ -802,6 +803,27 @@ public interface Player extends HumanEntity, Conversable, OfflinePlayer, PluginM
*/
public void resetPlayerWeather();
/**
* Gets the player's cooldown between picking up experience orbs.
*
* @return The cooldown in ticks
*/
public int getExpCooldown();
/**
* Sets the player's cooldown between picking up experience orbs..
*
* <strong>Note:</strong> Setting this to 0 allows the player to pick up
* instantly, but setting this to a negative value will cause the player to
* be unable to pick up xp-orbs.
*
* Calling this Method will result in {@link PlayerExpCooldownChangeEvent}
* being called.
*
* @param ticks The cooldown in ticks
*/
public void setExpCooldown(int ticks);
/**
* Gives the player the amount of experience specified.
*

View File

@ -0,0 +1,78 @@
package org.bukkit.event.player;
import org.bukkit.entity.Player;
import org.bukkit.event.HandlerList;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
/**
* Called when a player's experience cooldown changes.
*/
@ApiStatus.Experimental
public class PlayerExpCooldownChangeEvent extends PlayerEvent {
private static final HandlerList handlers = new HandlerList();
private int newCooldown;
private final ChangeReason reason;
public PlayerExpCooldownChangeEvent(@NotNull final Player player, int newcooldown, @NotNull ChangeReason reason) {
super(player);
this.newCooldown = newcooldown;
this.reason = reason;
}
/**
* Gets the reason for the change.
*
* @return The reason for the change
*/
@NotNull
public ChangeReason getReason() {
return reason;
}
/**
* Gets the new cooldown for the player.
*
* @return The new cooldown
* @see Player#getExpCooldown()
*/
public int getNewCooldown() {
return newCooldown;
}
/**
* Sets the new cooldown for the player.
*
* @param newCooldown The new cooldown to set
* @see Player#setExpCooldown(int)
*/
public void setNewCooldown(int newCooldown) {
this.newCooldown = newCooldown;
}
@NotNull
@Override
public HandlerList getHandlers() {
return handlers;
}
@NotNull
public static HandlerList getHandlerList() {
return handlers;
}
public enum ChangeReason {
/**
* The cooldown was set by picking up an experience orb.
*/
PICKUP_ORB,
/**
* The cooldown was set by a plugin.
*
* @see Player#setExpCooldown(int)
*/
PLUGIN;
}
}