Update to Minecraft 1.17

By: md_5 <git@md-5.net>
This commit is contained in:
Bukkit/Spigot
2021-06-11 15:00:00 +10:00
parent 2e1a3720cf
commit 153752dfac
44 changed files with 3379 additions and 958 deletions

View File

@@ -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.
*/

View File

@@ -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;
}
}

View File

@@ -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.
*/

View File

@@ -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;
}
}