mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-24 17:03:51 -07:00
@@ -1,7 +1,11 @@
|
||||
package org.bukkit.event.block;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.block.data.Levelled;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
@@ -15,15 +19,13 @@ public class CauldronLevelChangeEvent extends BlockEvent implements Cancellable
|
||||
//
|
||||
private final Entity entity;
|
||||
private final ChangeReason reason;
|
||||
private final int oldLevel;
|
||||
private int newLevel;
|
||||
private final BlockState newState;
|
||||
|
||||
public CauldronLevelChangeEvent(@NotNull Block block, @Nullable Entity entity, @NotNull ChangeReason reason, int oldLevel, int newLevel) {
|
||||
public CauldronLevelChangeEvent(@NotNull Block block, @Nullable Entity entity, @NotNull ChangeReason reason, @NotNull BlockState newBlock) {
|
||||
super(block);
|
||||
this.entity = entity;
|
||||
this.reason = reason;
|
||||
this.oldLevel = oldLevel;
|
||||
this.newLevel = newLevel;
|
||||
this.newState = newBlock;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -41,17 +43,59 @@ public class CauldronLevelChangeEvent extends BlockEvent implements Cancellable
|
||||
return reason;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the new state of the cauldron.
|
||||
*
|
||||
* @return The block state of the block that will be changed
|
||||
*/
|
||||
@NotNull
|
||||
public BlockState getNewState() {
|
||||
return newState;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the old level of the cauldron.
|
||||
*
|
||||
* @return old level
|
||||
* @deprecated not all cauldron contents are Levelled
|
||||
* @see #getBlock()
|
||||
*/
|
||||
@Deprecated
|
||||
public int getOldLevel() {
|
||||
return oldLevel;
|
||||
BlockData oldBlock = getBlock().getBlockData();
|
||||
return (oldBlock instanceof Levelled) ? ((Levelled) oldBlock).getLevel() : ((oldBlock.getMaterial() == Material.CAULDRON) ? 0 : 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the new level of the cauldron.
|
||||
*
|
||||
* @return new level
|
||||
* @deprecated not all cauldron contents are Levelled
|
||||
* @see #getNewState()
|
||||
*/
|
||||
@Deprecated
|
||||
public int getNewLevel() {
|
||||
return newLevel;
|
||||
BlockData newBlock = newState.getBlockData();
|
||||
return (newBlock instanceof Levelled) ? ((Levelled) newBlock).getLevel() : ((newBlock.getMaterial() == Material.CAULDRON) ? 0 : 3);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the new level of the cauldron.
|
||||
*
|
||||
* @param newLevel new level
|
||||
* @deprecated not all cauldron contents are Levelled
|
||||
* @see #getNewState()
|
||||
*/
|
||||
@Deprecated
|
||||
public void setNewLevel(int newLevel) {
|
||||
Preconditions.checkArgument(0 <= newLevel && newLevel <= 3, "Cauldron level out of bounds 0 <= %s <= 3", newLevel);
|
||||
this.newLevel = newLevel;
|
||||
if (newLevel == 0) {
|
||||
newState.setType(Material.CAULDRON);
|
||||
} else if (newState.getBlockData() instanceof Levelled) {
|
||||
((Levelled) newState.getBlockData()).setLevel(newLevel);
|
||||
} else {
|
||||
// Error, non-levellable block
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -100,6 +144,10 @@ public class CauldronLevelChangeEvent extends BlockEvent implements Cancellable
|
||||
* Player cleaning their armor.
|
||||
*/
|
||||
ARMOR_WASH,
|
||||
/**
|
||||
* Player cleaning a shulker box.
|
||||
*/
|
||||
SHULKER_WASH,
|
||||
/**
|
||||
* Entity being extinguished.
|
||||
*/
|
||||
@@ -108,6 +156,10 @@ public class CauldronLevelChangeEvent extends BlockEvent implements Cancellable
|
||||
* Evaporating due to biome dryness.
|
||||
*/
|
||||
EVAPORATE,
|
||||
/**
|
||||
* Filling due to natural fluid sources, eg rain.
|
||||
*/
|
||||
NATURAL_FILL,
|
||||
/**
|
||||
* Unknown.
|
||||
*/
|
||||
|
@@ -429,6 +429,12 @@ public class EntityDamageEvent extends EntityEvent implements Cancellable {
|
||||
* <p>
|
||||
* Damage: 1
|
||||
*/
|
||||
DRYOUT
|
||||
DRYOUT,
|
||||
/**
|
||||
* Damage caused from freezing.
|
||||
* <p>
|
||||
* Damage: 1 or 5
|
||||
*/
|
||||
FREEZE;
|
||||
}
|
||||
}
|
||||
|
@@ -170,6 +170,10 @@ public class EntityPotionEffectEvent extends EntityEvent implements Cancellable
|
||||
* attack (e.g. a cave spider or a shulker bullet).
|
||||
*/
|
||||
ATTACK,
|
||||
/**
|
||||
* When an entity gets the effect from an axolotl.
|
||||
*/
|
||||
AXOLOTL,
|
||||
/**
|
||||
* When beacon effects get applied due to the entity being nearby.
|
||||
*/
|
||||
|
@@ -0,0 +1,103 @@
|
||||
package org.bukkit.event.world;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import org.bukkit.GameEvent;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a generic Mojang game event.
|
||||
*
|
||||
* Specific Bukkit events should be used where possible, this event is mainly
|
||||
* used internally by Sculk sensors.
|
||||
*/
|
||||
public class GenericGameEvent extends WorldEvent implements Cancellable {
|
||||
|
||||
private static final HandlerList handlers = new HandlerList();
|
||||
private final GameEvent event;
|
||||
private final Location location;
|
||||
private final Entity entity;
|
||||
private int radius;
|
||||
private boolean cancelled;
|
||||
|
||||
public GenericGameEvent(@NotNull GameEvent event, @NotNull Location location, @Nullable Entity entity, int radius) {
|
||||
super(location.getWorld());
|
||||
this.event = event;
|
||||
this.location = location;
|
||||
this.entity = entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the underlying event.
|
||||
*
|
||||
* @return the event
|
||||
*/
|
||||
@NotNull
|
||||
public GameEvent getEvent() {
|
||||
return event;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the location where the event occurred.
|
||||
*
|
||||
* @return event location
|
||||
*/
|
||||
@NotNull
|
||||
public Location getLocation() {
|
||||
return location;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the entity which triggered this event, if present.
|
||||
*
|
||||
* @return triggering entity or null
|
||||
*/
|
||||
@Nullable
|
||||
public Entity getEntity() {
|
||||
return entity;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the block radius to which this event will be broadcast.
|
||||
*
|
||||
* @return broadcast radius
|
||||
*/
|
||||
public int getRadius() {
|
||||
return radius;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the radius to which the event should be broadcast.
|
||||
*
|
||||
* @param radius radius, must be greater than or equal to 0
|
||||
*/
|
||||
public void setRadius(int radius) {
|
||||
Preconditions.checkArgument(radius >= 0, "Radius must be >= 0");
|
||||
this.radius = radius;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCancelled(boolean cancel) {
|
||||
this.cancelled = cancel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isCancelled() {
|
||||
return cancelled;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public HandlerList getHandlers() {
|
||||
return handlers;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static HandlerList getHandlerList() {
|
||||
return handlers;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user