mirror of
https://github.com/veralol/VeraSpigotAPI.git
synced 2024-11-10 01:01:32 +01:00
add enderpearl, equipment and potion effect events
This commit is contained in:
parent
b1a11b3cc5
commit
a25713722b
30
src/main/java/lol/vera/spigot/event/EquipmentSetEvent.java
Normal file
30
src/main/java/lol/vera/spigot/event/EquipmentSetEvent.java
Normal file
@ -0,0 +1,30 @@
|
||||
package lol.vera.spigot.event;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
@Getter
|
||||
@RequiredArgsConstructor
|
||||
public class EquipmentSetEvent extends Event {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final HumanEntity humanEntity;
|
||||
private final int slot;
|
||||
private final ItemStack previousItem;
|
||||
private final ItemStack newItem;
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
package lol.vera.spigot.event;
|
||||
|
||||
import lombok.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.Event;
|
||||
import org.bukkit.event.HandlerList;
|
||||
|
||||
@Data
|
||||
@RequiredArgsConstructor
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class PlayerPearlRefundEvent extends Event implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final Player player;
|
||||
private boolean cancelled;
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,88 @@
|
||||
package lol.vera.spigot.event.potion;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
/**
|
||||
* Called when a potion effect is applied to an entity, or an existing effect is extended or upgraded
|
||||
*/
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class PotionEffectAddEvent extends PotionEffectEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private boolean cancelled;
|
||||
private final EffectAddReason reason;
|
||||
|
||||
public PotionEffectAddEvent(LivingEntity what, PotionEffect effect, EffectAddReason reason) {
|
||||
super(what, effect);
|
||||
this.reason = reason;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public enum EffectAddReason {
|
||||
/**
|
||||
* Added using the /effect command
|
||||
*/
|
||||
COMMAND,
|
||||
/**
|
||||
* Added by eating a golden apple
|
||||
*/
|
||||
GOLDEN_APPLE,
|
||||
/**
|
||||
* Added by being near a beacon
|
||||
*/
|
||||
BEACON,
|
||||
/**
|
||||
* Added by being hit with a wither skull
|
||||
*/
|
||||
WITHER_SKULL,
|
||||
/**
|
||||
* Added by being hit by a wither skeleton
|
||||
*/
|
||||
WITHER_SKELETON,
|
||||
/**
|
||||
* Added to villagers when they are cured
|
||||
*/
|
||||
VILLAGER_CURE,
|
||||
/**
|
||||
* Added to villagers when they unlock a new set of trades
|
||||
*/
|
||||
VILLAGER_LEVELUP,
|
||||
/**
|
||||
* Added to spiders on higher difficulty
|
||||
*/
|
||||
SPIDER_POWERUP,
|
||||
/**
|
||||
* Added when a potion is splashed
|
||||
*/
|
||||
POTION_SPLASH,
|
||||
/**
|
||||
* Added when a potion is consumed
|
||||
*/
|
||||
POTION_DRINK,
|
||||
/**
|
||||
* Added by a plugin
|
||||
*/
|
||||
CUSTOM,
|
||||
/**
|
||||
* Added by a part of the vanilla code not covered in the above cases
|
||||
*/
|
||||
UNKNOWN
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package lol.vera.spigot.event.potion;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.entity.EntityEvent;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
@Getter
|
||||
public abstract class PotionEffectEvent extends EntityEvent {
|
||||
|
||||
private final PotionEffect effect;
|
||||
|
||||
public PotionEffectEvent(LivingEntity what, PotionEffect effect) {
|
||||
super(what);
|
||||
this.effect = effect;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity getEntity() {
|
||||
return (LivingEntity) super.getEntity();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package lol.vera.spigot.event.potion;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
/**
|
||||
* Called when a potion effect on an entity runs out. Cancelling the event extends
|
||||
* the effect with a practically infinite duration. The new duration can also be set
|
||||
* explicitly by calling {@link #setDuration}.
|
||||
*
|
||||
* Handlers of {@link PotionEffectRemoveEvent} will also receive this event.
|
||||
*/
|
||||
|
||||
@Getter @Setter
|
||||
public class PotionEffectExpireEvent extends PotionEffectRemoveEvent {
|
||||
|
||||
private int duration = 0;
|
||||
|
||||
public PotionEffectExpireEvent(LivingEntity entity, PotionEffect effect) {
|
||||
super(entity, effect);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a new duration for the potion effect. Passing 0 to this method un-cancels
|
||||
* the event, and passing anything above 0 cancels it.
|
||||
*/
|
||||
public void setDuration(int duration) {
|
||||
this.duration = Math.max(0, duration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return duration > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.duration = cancel ? Integer.MAX_VALUE : 0;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package lol.vera.spigot.event.potion;
|
||||
|
||||
import lombok.Getter;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
/**
|
||||
* Called when an entity's active potion effect is extended or upgraded.
|
||||
*
|
||||
* Handlers of {@link PotionEffectAddEvent} will also receive this event.
|
||||
*/
|
||||
|
||||
@Getter
|
||||
public class PotionEffectExtendEvent extends PotionEffectAddEvent {
|
||||
|
||||
private final PotionEffect oldEffect;
|
||||
|
||||
public PotionEffectExtendEvent(LivingEntity what, PotionEffect effect, EffectAddReason reason, PotionEffect oldEffect) {
|
||||
super(what, effect, reason);
|
||||
this.oldEffect = oldEffect;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
package lol.vera.spigot.event.potion;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.potion.PotionEffect;
|
||||
|
||||
/**
|
||||
* Called when a potion effect is removed from an entity for whatever reason
|
||||
*/
|
||||
|
||||
@Getter @Setter
|
||||
public class PotionEffectRemoveEvent extends PotionEffectEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private boolean cancelled;
|
||||
|
||||
public PotionEffectRemoveEvent(LivingEntity entity, PotionEffect effect) {
|
||||
super(entity, effect);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user