mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-30 19:40:37 +01:00
Add getWorld method that uses adventure Key (#11199)
This commit is contained in:
parent
5703e6c6d8
commit
9921a197e7
4 changed files with 31 additions and 8 deletions
|
@ -34,6 +34,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+import net.kyori.adventure.sound.Sound;
|
||||
+import net.kyori.adventure.text.Component;
|
||||
+import org.bukkit.block.Block;
|
||||
+import org.bukkit.block.BlockState;
|
||||
+import org.bukkit.entity.Player;
|
||||
+import org.bukkit.event.HandlerList;
|
||||
+import org.bukkit.event.block.BlockEvent;
|
||||
|
@ -53,7 +54,6 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+
|
||||
+ private static final HandlerList HANDLER_LIST = new HandlerList();
|
||||
+
|
||||
+ private final LockableTileState state;
|
||||
+ private final Player player;
|
||||
+ private Component lockedMessage;
|
||||
+ private Sound lockedSound;
|
||||
|
@ -61,9 +61,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ private Result result = Result.DEFAULT;
|
||||
+
|
||||
+ @ApiStatus.Internal
|
||||
+ public BlockLockCheckEvent(final @NotNull Block block, final @NotNull LockableTileState state, final @NotNull Player player, final @NotNull Component lockedMessage, final @NotNull Sound lockedSound) {
|
||||
+ public BlockLockCheckEvent(final @NotNull Block block, final @NotNull Player player, final @NotNull Component lockedMessage, final @NotNull Sound lockedSound) {
|
||||
+ super(block);
|
||||
+ this.state = state;
|
||||
+ this.player = player;
|
||||
+ this.lockedMessage = lockedMessage;
|
||||
+ this.lockedSound = lockedSound;
|
||||
|
@ -76,7 +75,9 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ * @return the snapshot block state.
|
||||
+ */
|
||||
+ public @NotNull LockableTileState getBlockState() {
|
||||
+ return this.state;
|
||||
+ 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;
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
|
|
|
@ -23,6 +23,17 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ public static World getWorld(@NotNull NamespacedKey worldKey) {
|
||||
+ return server.getWorld(worldKey);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the world from the given Key
|
||||
+ *
|
||||
+ * @param worldKey the Key of the world to retrieve
|
||||
+ * @return a world with the given Key, or null if none exists
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ public static World getWorld(@NotNull net.kyori.adventure.key.Key worldKey) {
|
||||
+ return server.getWorld(worldKey);
|
||||
+ }
|
||||
+ // Paper end
|
||||
|
||||
/**
|
||||
|
@ -71,7 +82,18 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ * @return a world with the given NamespacedKey, or null if none exists
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ public World getWorld(@NotNull NamespacedKey worldKey);
|
||||
+ default World getWorld(@NotNull NamespacedKey worldKey) {
|
||||
+ return getWorld((net.kyori.adventure.key.Key) worldKey);
|
||||
+ }
|
||||
+
|
||||
+ /**
|
||||
+ * Gets the world from the given Key
|
||||
+ *
|
||||
+ * @param worldKey the Key of the world to retrieve
|
||||
+ * @return a world with the given Key, or null if none exists
|
||||
+ */
|
||||
+ @Nullable
|
||||
+ World getWorld(@NotNull net.kyori.adventure.key.Key worldKey);
|
||||
+ // Paper end
|
||||
+
|
||||
/**
|
||||
|
|
|
@ -26,7 +26,7 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
+ final org.bukkit.block.Block block = org.bukkit.craftbukkit.block.CraftBlock.at(blockEntity.getLevel(), blockEntity.getBlockPos());
|
||||
+ net.kyori.adventure.text.Component lockedMessage = net.kyori.adventure.text.Component.translatable("container.isLocked", io.papermc.paper.adventure.PaperAdventure.asAdventure(containerName));
|
||||
+ net.kyori.adventure.sound.Sound lockedSound = net.kyori.adventure.sound.Sound.sound(org.bukkit.Sound.BLOCK_CHEST_LOCKED, net.kyori.adventure.sound.Sound.Source.BLOCK, 1.0F, 1.0F);
|
||||
+ final io.papermc.paper.event.block.BlockLockCheckEvent event = new io.papermc.paper.event.block.BlockLockCheckEvent(block, (io.papermc.paper.block.LockableTileState) block.getState(), serverPlayer.getBukkitEntity(), lockedMessage, lockedSound);
|
||||
+ final io.papermc.paper.event.block.BlockLockCheckEvent event = new io.papermc.paper.event.block.BlockLockCheckEvent(block, serverPlayer.getBukkitEntity(), lockedMessage, lockedSound);
|
||||
+ event.callEvent();
|
||||
+ if (event.getResult() == org.bukkit.event.Event.Result.ALLOW) {
|
||||
+ return true;
|
||||
|
|
|
@ -56,8 +56,8 @@ index 0000000000000000000000000000000000000000..00000000000000000000000000000000
|
|||
|
||||
+ // Paper start
|
||||
+ @Override
|
||||
+ public World getWorld(NamespacedKey worldKey) {
|
||||
+ ServerLevel worldServer = console.getLevel(ResourceKey.create(net.minecraft.core.registries.Registries.DIMENSION, CraftNamespacedKey.toMinecraft(worldKey)));
|
||||
+ public World getWorld(net.kyori.adventure.key.Key worldKey) {
|
||||
+ ServerLevel worldServer = console.getLevel(ResourceKey.create(net.minecraft.core.registries.Registries.DIMENSION, io.papermc.paper.adventure.PaperAdventure.asVanilla(worldKey)));
|
||||
+ if (worldServer == null) return null;
|
||||
+ return worldServer.getWorld();
|
||||
+ }
|
||||
|
|
Loading…
Add table
Reference in a new issue