mirror of
https://github.com/PaperMC/Paper.git
synced 2025-08-03 05:32:18 -07:00
Begin switching to JSpecify annotations (#11448)
* Begin switching to JSpecify annotations * more * fixes
This commit is contained in:
@@ -31,6 +31,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+
|
||||
+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..00000000000000000000000000000000
|
||||
+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..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @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..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @return the player
|
||||
+ */
|
||||
+ public @NotNull Player getPlayer() {
|
||||
+ public Player getPlayer() {
|
||||
+ return this.player;
|
||||
+ }
|
||||
+
|
||||
@@ -98,7 +98,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ * @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..00000000000000000000000000000000
|
||||
+ * @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..00000000000000000000000000000000
|
||||
+ * @return the result
|
||||
+ * @see #setResult(Result)
|
||||
+ */
|
||||
+ public @NotNull Result getResult() {
|
||||
+ public Result getResult() {
|
||||
+ return this.result;
|
||||
+ }
|
||||
+
|
||||
@@ -148,7 +148,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @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..00000000000000000000000000000000
|
||||
+ * 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..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @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..00000000000000000000000000000000
|
||||
+ *
|
||||
+ * @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;
|
||||
+ }
|
||||
+}
|
||||
|
Reference in New Issue
Block a user