Begin switching to JSpecify annotations (#11448)
* Begin switching to JSpecify annotations * more * fixes
This commit is contained in:
parent
6d7a438fad
commit
f9c7f2a5c1
66 changed files with 750 additions and 920 deletions
|
@ -23,7 +23,7 @@ index 0000000000000000000000000000000000000000..f309961e0e96b6baacc4fe6d80dabd6c
|
|||
+}
|
||||
diff --git a/src/main/java/io/papermc/paper/event/block/BlockLockCheckEvent.java b/src/main/java/io/papermc/paper/event/block/BlockLockCheckEvent.java
|
||||
new file mode 100644
|
||||
index 0000000000000000000000000000000000000000..5e2c8ad26dea2c8a84ae10f7da8cb836e78d7b68
|
||||
index 0000000000000000000000000000000000000000..f08d390f0ee9357dcc229d7a2520da602677d9ef
|
||||
--- /dev/null
|
||||
+++ b/src/main/java/io/papermc/paper/event/block/BlockLockCheckEvent.java
|
||||
@@ -0,0 +1,187 @@
|
||||
|
@ -31,6 +31,7 @@ index 0000000000000000000000000000000000000000..5e2c8ad26dea2c8a84ae10f7da8cb836
|
|||
+
|
||||
+import com.google.common.base.Preconditions;
|
||||
+import io.papermc.paper.block.LockableTileState;
|
||||
+import java.util.Objects;
|
||||
+import net.kyori.adventure.sound.Sound;
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import org.bukkit.block.Block;
|
||||
|
@ -40,28 +41,27 @@ index 0000000000000000000000000000000000000000..5e2c8ad26dea2c8a84ae10f7da8cb836
|
|||
+import org.bukkit.event.block.BlockEvent;
|
||||
+import org.bukkit.inventory.ItemStack;
|
||||
+import org.jetbrains.annotations.ApiStatus;
|
||||
+import org.jetbrains.annotations.NotNull;
|
||||
+import org.jetbrains.annotations.Nullable;
|
||||
+
|
||||
+import java.util.Objects;
|
||||
+import org.jspecify.annotations.NullMarked;
|
||||
+import org.jspecify.annotations.Nullable;
|
||||
+
|
||||
+/**
|
||||
+ * Called when the server tries to check the lock on a lockable block entity.
|
||||
+ * <br>
|
||||
+ * See {@link #setResult(Result)} to change behavior
|
||||
+ */
|
||||
+@NullMarked
|
||||
+public class BlockLockCheckEvent extends BlockEvent {
|
||||
+
|
||||
+ private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
+
|
||||
+ private final Player player;
|
||||
+ private Component lockedMessage;
|
||||
+ private Sound lockedSound;
|
||||
+ private ItemStack itemStack;
|
||||
+ private @Nullable Component lockedMessage;
|
||||
+ private @Nullable Sound lockedSound;
|
||||
+ private @Nullable ItemStack itemStack;
|
||||
+ private Result result = Result.DEFAULT;
|
||||
+
|
||||
+ @ApiStatus.Internal
|
||||
+ public BlockLockCheckEvent(final @NotNull Block block, final @NotNull Player player, final @NotNull Component lockedMessage, final @NotNull Sound lockedSound) {
|
||||
+ public BlockLockCheckEvent(final Block block, final Player player, final Component lockedMessage, final Sound lockedSound) {
|
||||
+ super(block);
|
||||
+ this.player = player;
|
||||
+ this.lockedMessage = lockedMessage;
|
||||
|
@ -74,7 +74,7 @@ index 0000000000000000000000000000000000000000..5e2c8ad26dea2c8a84ae10f7da8cb836
|
|||
+ *
|
||||
+ * @return the snapshot block state.
|
||||
+ */
|
||||
+ public @NotNull LockableTileState getBlockState() {
|
||||
+ public LockableTileState getBlockState() {
|
||||
+ final BlockState blockState = this.getBlock().getState();
|
||||
+ Preconditions.checkState(blockState instanceof LockableTileState, "Block state of lock-checked block is no longer a lockable tile state!");
|
||||
+ return (LockableTileState) blockState;
|
||||
|
@ -85,7 +85,7 @@ index 0000000000000000000000000000000000000000..5e2c8ad26dea2c8a84ae10f7da8cb836
|
|||
+ *
|
||||
+ * @return the player
|
||||
+ */
|
||||
+ public @NotNull Player getPlayer() {
|
||||
+ public Player getPlayer() {
|
||||
+ return this.player;
|
||||
+ }
|
||||
+
|
||||
|
@ -98,7 +98,7 @@ index 0000000000000000000000000000000000000000..5e2c8ad26dea2c8a84ae10f7da8cb836
|
|||
+ * @return the item being used as the key item
|
||||
+ * @see #isUsingCustomKeyItemStack()
|
||||
+ */
|
||||
+ public @NotNull ItemStack getKeyItem() {
|
||||
+ public ItemStack getKeyItem() {
|
||||
+ return Objects.requireNonNullElseGet(this.itemStack, this.player.getInventory()::getItemInMainHand);
|
||||
+ }
|
||||
+
|
||||
|
@ -108,7 +108,7 @@ index 0000000000000000000000000000000000000000..5e2c8ad26dea2c8a84ae10f7da8cb836
|
|||
+ * @param stack the stack to use as a key
|
||||
+ * @see #resetKeyItem() to clear a custom key item
|
||||
+ */
|
||||
+ public void setKeyItem(@NotNull ItemStack stack) {
|
||||
+ public void setKeyItem(final ItemStack stack) {
|
||||
+ Preconditions.checkArgument(stack != null, "stack cannot be null");
|
||||
+ this.itemStack = stack;
|
||||
+ }
|
||||
|
@ -135,7 +135,7 @@ index 0000000000000000000000000000000000000000..5e2c8ad26dea2c8a84ae10f7da8cb836
|
|||
+ * @return the result
|
||||
+ * @see #setResult(Result)
|
||||
+ */
|
||||
+ public @NotNull Result getResult() {
|
||||
+ public Result getResult() {
|
||||
+ return this.result;
|
||||
+ }
|
||||
+
|
||||
|
@ -148,7 +148,7 @@ index 0000000000000000000000000000000000000000..5e2c8ad26dea2c8a84ae10f7da8cb836
|
|||
+ *
|
||||
+ * @param result the result of this event
|
||||
+ */
|
||||
+ public void setResult(@NotNull Result result) {
|
||||
+ public void setResult(final Result result) {
|
||||
+ this.result = result;
|
||||
+ }
|
||||
+
|
||||
|
@ -157,9 +157,9 @@ index 0000000000000000000000000000000000000000..5e2c8ad26dea2c8a84ae10f7da8cb836
|
|||
+ * the locked message and locked sound.
|
||||
+ *
|
||||
+ * @param lockedMessage the message to show if locked (or {@code null} for none)
|
||||
+ * @param lockedSound the sound to play if locked (or {@code null} for none)
|
||||
+ * @param lockedSound the sound to play if locked (or {@code null} for none)
|
||||
+ */
|
||||
+ public void denyWithMessageAndSound(@Nullable Component lockedMessage, @Nullable Sound lockedSound) {
|
||||
+ public void denyWithMessageAndSound(final @Nullable Component lockedMessage, final @Nullable Sound lockedSound) {
|
||||
+ this.result = Result.DENY;
|
||||
+ this.lockedMessage = lockedMessage;
|
||||
+ this.lockedSound = lockedSound;
|
||||
|
@ -181,7 +181,7 @@ index 0000000000000000000000000000000000000000..5e2c8ad26dea2c8a84ae10f7da8cb836
|
|||
+ *
|
||||
+ * @param lockedMessage the locked message (or {@code null} for none)
|
||||
+ */
|
||||
+ public void setLockedMessage(@Nullable Component lockedMessage) {
|
||||
+ public void setLockedMessage(final @Nullable Component lockedMessage) {
|
||||
+ this.lockedMessage = lockedMessage;
|
||||
+ }
|
||||
+
|
||||
|
@ -201,16 +201,16 @@ index 0000000000000000000000000000000000000000..5e2c8ad26dea2c8a84ae10f7da8cb836
|
|||
+ *
|
||||
+ * @param lockedSound the locked sound (or {@code null} for none)
|
||||
+ */
|
||||
+ public void setLockedSound(@Nullable Sound lockedSound) {
|
||||
+ public void setLockedSound(final @Nullable Sound lockedSound) {
|
||||
+ this.lockedSound = lockedSound;
|
||||
+ }
|
||||
+
|
||||
+ @Override
|
||||
+ public @NotNull HandlerList getHandlers() {
|
||||
+ public HandlerList getHandlers() {
|
||||
+ return HANDLER_LIST;
|
||||
+ }
|
||||
+
|
||||
+ public static @NotNull HandlerList getHandlerList() {
|
||||
+ public static HandlerList getHandlerList() {
|
||||
+ return HANDLER_LIST;
|
||||
+ }
|
||||
+}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue