mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-20 23:39:16 +00:00
cleanup
This commit is contained in:
@@ -1,87 +0,0 @@
|
||||
package org.bxteam.divinemc.event.entity;
|
||||
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.entity.EntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
import org.jspecify.annotations.Nullable;
|
||||
import java.util.function.Predicate;
|
||||
|
||||
/**
|
||||
* Called when some item needs a projectile for further actions
|
||||
*/
|
||||
@NullMarked
|
||||
public class EntityLoadsProjectileEvent extends EntityEvent {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final ItemStack weapon;
|
||||
private final Predicate<ItemStack> projectileValidator;
|
||||
private ItemStack projectile;
|
||||
|
||||
public EntityLoadsProjectileEvent(LivingEntity entity, ItemStack weapon, @Nullable ItemStack projectile, Predicate<ItemStack> projectileValidator) {
|
||||
super(entity);
|
||||
this.weapon = weapon;
|
||||
this.projectile = projectile == null ? ItemStack.empty() : projectile;
|
||||
this.projectileValidator = projectileValidator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the entity firing the weapon
|
||||
*
|
||||
* @return the entity firing the weapon
|
||||
*/
|
||||
@Override
|
||||
public LivingEntity getEntity() {
|
||||
return (LivingEntity) this.entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the weapon requesting the projectile
|
||||
*
|
||||
* @return weapon
|
||||
*/
|
||||
public ItemStack getWeapon() {
|
||||
return weapon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the projectile that will be submitted to the weapon.
|
||||
* {@link ItemStack#isEmpty()} items mean no projectile.
|
||||
*
|
||||
* @return projectile
|
||||
*/
|
||||
public ItemStack getProjectile() {
|
||||
return projectile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the projectile that will be used by the weapon
|
||||
*
|
||||
* @param projectile projectile
|
||||
*/
|
||||
public void setProjectile(@Nullable ItemStack projectile) {
|
||||
this.projectile = projectile == null ? ItemStack.empty() : projectile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the provided item can be fired from the weapon.
|
||||
* <br>
|
||||
* You may still provide a non-fireable projectile to it.
|
||||
*
|
||||
* @param item projectile item
|
||||
* @return whether the provided item can be fired from the weapon
|
||||
*/
|
||||
public boolean canBeFired(@Nullable ItemStack item) {
|
||||
return item != null && this.projectileValidator.test(item);
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
@@ -1,84 +0,0 @@
|
||||
package org.bxteam.divinemc.event.entity;
|
||||
|
||||
import org.bukkit.entity.LivingEntity;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.event.entity.EntityEvent;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.jspecify.annotations.NullMarked;
|
||||
|
||||
@NullMarked
|
||||
public class EntityStartUsingItemEvent extends EntityEvent implements Cancellable {
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
|
||||
private final ItemStack item;
|
||||
private int useDuration;
|
||||
private boolean cancelled;
|
||||
|
||||
public EntityStartUsingItemEvent(LivingEntity entity, ItemStack item, int useDuration) {
|
||||
super(entity);
|
||||
this.item = item;
|
||||
this.useDuration = useDuration;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LivingEntity getEntity() {
|
||||
return (LivingEntity) this.entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the item that's being used
|
||||
*
|
||||
* @return the item that's being used
|
||||
*/
|
||||
public ItemStack getItem() {
|
||||
return this.item;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets for how long in ticks the item should be used until it's ready
|
||||
*
|
||||
* @return item use duration
|
||||
*/
|
||||
public int getUseDuration() {
|
||||
return this.useDuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets for how long in ticks the item should be used until it's ready
|
||||
*
|
||||
* @param useDuration item use duration in ticks
|
||||
*/
|
||||
public void setUseDuration(int useDuration) {
|
||||
this.useDuration = useDuration;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @return if cancelled, the item will stop being in use
|
||||
*/
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return this.cancelled;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to cancel item use. If canceled,
|
||||
* the item will stop being in use.
|
||||
*
|
||||
* @param cancel whether you wish to cancel this event
|
||||
*/
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user