net.minestom.server.event.entity.EntityItemMergeEvent Maven / Gradle / Ivy
Show all versions of minestom-snapshots Show documentation
package net.minestom.server.event.entity;
import net.minestom.server.entity.Entity;
import net.minestom.server.entity.ItemEntity;
import net.minestom.server.event.trait.CancellableEvent;
import net.minestom.server.event.trait.EntityInstanceEvent;
import net.minestom.server.item.ItemStack;
import org.jetbrains.annotations.NotNull;
/**
* Called when two {@link ItemEntity} are merging their {@link ItemStack} together to form a sole entity.
*/
public class EntityItemMergeEvent implements EntityInstanceEvent, CancellableEvent {
private final Entity entity;
private final ItemEntity merged;
private ItemStack result;
private boolean cancelled;
public EntityItemMergeEvent(@NotNull ItemEntity source, @NotNull ItemEntity merged, @NotNull ItemStack result) {
this.entity = source;
this.merged = merged;
this.result = result;
}
/**
* Gets the {@link ItemEntity} who is receiving {@link #getMerged()}.
*
* This can be used to get the final ItemEntity position.
*
* @return the source ItemEntity
*/
@Override
public @NotNull ItemEntity getEntity() {
return (ItemEntity) entity;
}
/**
* Gets the entity who will be merged.
*
* This entity will be removed after the event.
*
* @return the merged ItemEntity
*/
public @NotNull ItemEntity getMerged() {
return merged;
}
/**
* Gets the final item stack on the ground.
*
* @return the item stack
*/
public @NotNull ItemStack getResult() {
return result;
}
/**
* Changes the item stack which will appear on the ground.
*
* @param result the new item stack
*/
public void setResult(@NotNull ItemStack result) {
this.result = result;
}
@Override
public boolean isCancelled() {
return cancelled;
}
@Override
public void setCancelled(boolean cancel) {
this.cancelled = cancel;
}
}