moaaaaaaaar patches

This commit is contained in:
Jake 2021-11-24 12:15:19 -08:00 committed by MiniDigger | Martin
parent 6f5b43e290
commit 1cb76e15be
31 changed files with 96 additions and 106 deletions

View file

@ -105,6 +105,20 @@ index 2ff1b1308571d8f8056d3359e8a8ba4a589c3726..e669ad8ecd182c6899c7820414e6ee1f
@NotNull
public int[] getExpLevelCostsOffered() {
int[] levelOffers = new int[offers.length];
diff --git a/src/main/java/org/bukkit/inventory/Inventory.java b/src/main/java/org/bukkit/inventory/Inventory.java
index 9c6a5bdac8c3ab682bbfae04ff24b76a62bc2883..c0ff615fe7ce8b398d49f52937c378eda8e79914 100644
--- a/src/main/java/org/bukkit/inventory/Inventory.java
+++ b/src/main/java/org/bukkit/inventory/Inventory.java
@@ -158,8 +158,7 @@ public interface Inventory extends Iterable<ItemStack> {
*
* @return An array of ItemStacks from the inventory. Individual items may be null.
*/
- @NotNull
- public ItemStack[] getContents();
+ public @Nullable ItemStack @NotNull [] getContents(); // Paper - make array elements nullable instead array
/**
* Completely replaces the inventory's contents. Removes all existing
diff --git a/src/main/java/org/bukkit/inventory/ItemFactory.java b/src/main/java/org/bukkit/inventory/ItemFactory.java
index 71e5ee496a947fbd8e3ec579833b157c76b51833..d773e8594f91017bddd7ea8aada3a1ff2781d05b 100644
--- a/src/main/java/org/bukkit/inventory/ItemFactory.java

View file

@ -28,10 +28,10 @@ index 83a4642119c3f33749e04c774cf2b39839f797e2..a39d2f1acbbd84ae0e2cf29f85594e09
public Location getLocation() {
return getInventory().getLocation();
diff --git a/src/main/java/org/bukkit/inventory/Inventory.java b/src/main/java/org/bukkit/inventory/Inventory.java
index 9c6a5bdac8c3ab682bbfae04ff24b76a62bc2883..6386206188e820206bb1a9f516b5e194fdc9d952 100644
index c0ff615fe7ce8b398d49f52937c378eda8e79914..3fa4fa4170633abf472a60d5bd07fb3ac7c58947 100644
--- a/src/main/java/org/bukkit/inventory/Inventory.java
+++ b/src/main/java/org/bukkit/inventory/Inventory.java
@@ -384,6 +384,17 @@ public interface Inventory extends Iterable<ItemStack> {
@@ -383,6 +383,17 @@ public interface Inventory extends Iterable<ItemStack> {
@Nullable
public InventoryHolder getHolder();

View file

@ -0,0 +1,38 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jason Penilla <11360596+jpenilla@users.noreply.github.com>
Date: Tue, 2 Mar 2021 15:24:58 -0800
Subject: [PATCH] Cache the result of Material#isBlock
diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java
index b637686404f0aa87c6996220987ed4a303496b43..5922f4a3d5ac69abb232e8e497d838e10e35316e 100644
--- a/src/main/java/org/bukkit/Material.java
+++ b/src/main/java/org/bukkit/Material.java
@@ -3928,6 +3928,7 @@ public enum Material implements Keyed, net.kyori.adventure.translation.Translata
public final Class<?> data;
private final boolean legacy;
private final NamespacedKey key;
+ private boolean isBlock; // Paper
private Material(final int id) {
this(id, 64);
@@ -4132,6 +4133,11 @@ public enum Material implements Keyed, net.kyori.adventure.translation.Translata
* @return true if this material is a block
*/
public boolean isBlock() {
+ // Paper start - cache isBlock
+ return this.isBlock;
+ }
+ private boolean isBlock0() {
+ // Paper end
switch (this) {
//<editor-fold defaultstate="collapsed" desc="isBlock">
case ACACIA_BUTTON:
@@ -5213,6 +5219,7 @@ public enum Material implements Keyed, net.kyori.adventure.translation.Translata
static {
for (Material material : values()) {
BY_NAME.put(material.name(), material);
+ material.isBlock = material.isBlock0(); // Paper
}
}

View file

@ -0,0 +1,308 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Mon, 4 Jan 2021 22:40:26 -0800
Subject: [PATCH] Add worldborder events
diff --git a/src/main/java/io/papermc/paper/event/world/border/WorldBorderBoundsChangeEvent.java b/src/main/java/io/papermc/paper/event/world/border/WorldBorderBoundsChangeEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..126fe50b519a8d7cd158f799058cb235f9c4cbdb
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/world/border/WorldBorderBoundsChangeEvent.java
@@ -0,0 +1,114 @@
+package io.papermc.paper.event.world.border;
+
+import org.bukkit.World;
+import org.bukkit.WorldBorder;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Called when a world border changes its bounds, either over time, or instantly.
+ */
+public class WorldBorderBoundsChangeEvent extends WorldBorderEvent implements Cancellable {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private Type type;
+ private final double oldSize;
+ private double newSize;
+ private long duration;
+ private boolean cancelled;
+
+ public WorldBorderBoundsChangeEvent(@NotNull World world, @NotNull WorldBorder worldBorder, @NotNull Type type, double oldSize, double newSize, long duration) {
+ super(world, worldBorder);
+ this.type = type;
+ this.oldSize = oldSize;
+ this.newSize = newSize;
+ this.duration = duration;
+ }
+
+ /**
+ * Gets if this change is an instant change or over-time change.
+ *
+ * @return the change type
+ */
+ @NotNull
+ public Type getType() {
+ return type;
+ }
+
+ /**
+ * Gets the old size or the world border.
+ *
+ * @return the old size
+ */
+ public double getOldSize() {
+ return oldSize;
+ }
+
+ /**
+ * Gets the new size of the world border.
+ *
+ * @return the new size
+ */
+ public double getNewSize() {
+ return newSize;
+ }
+
+ /**
+ * Sets the new size of the world border.
+ *
+ * @param newSize the new size
+ */
+ public void setNewSize(double newSize) {
+ // PAIL: TODO: Magic Values
+ this.newSize = Math.min(6.0E7D, Math.max(1.0D, newSize));
+ }
+
+ /**
+ * Gets the time in milliseconds for the change. Will be 0 if instant.
+ *
+ * @return the time in milliseconds for the change
+ */
+ public long getDuration() {
+ return duration;
+ }
+
+ /**
+ * Sets the time in milliseconds for the change. Will change {@link #getType()} to return
+ * {@link Type#STARTED_MOVE}.
+ *
+ * @param duration the time in milliseconds for the change
+ */
+ public void setDuration(long duration) {
+ // PAIL: TODO: Magic Values
+ this.duration = Math.min(9223372036854775L, Math.max(0L, duration));
+ if (duration >= 0 && type == Type.INSTANT_MOVE) type = Type.STARTED_MOVE;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancelled = cancel;
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+
+ public enum Type {
+ STARTED_MOVE,
+ INSTANT_MOVE
+ }
+}
diff --git a/src/main/java/io/papermc/paper/event/world/border/WorldBorderBoundsChangeFinishEvent.java b/src/main/java/io/papermc/paper/event/world/border/WorldBorderBoundsChangeFinishEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..c3d578ae2c5615b0ebace99d9bacf100b086c971
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/world/border/WorldBorderBoundsChangeFinishEvent.java
@@ -0,0 +1,65 @@
+package io.papermc.paper.event.world.border;
+
+import org.bukkit.World;
+import org.bukkit.WorldBorder;
+import org.bukkit.event.HandlerList;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Called when a moving world border has finished it's move.
+ */
+public class WorldBorderBoundsChangeFinishEvent extends WorldBorderEvent {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final double oldSize;
+ private final double newSize;
+ private final double duration;
+
+ public WorldBorderBoundsChangeFinishEvent(@NotNull World world, @NotNull WorldBorder worldBorder, double oldSize, double newSize, double duration) {
+ super(world, worldBorder);
+ this.oldSize = oldSize;
+ this.newSize = newSize;
+ this.duration = duration;
+ }
+
+ /**
+ * Gets the old size of the worldborder.
+ *
+ * @return the old size
+ */
+ public double getOldSize() {
+ return oldSize;
+ }
+
+ /**
+ * Gets the new size of the worldborder.
+ *
+ * @return the new size
+ */
+ public double getNewSize() {
+ return newSize;
+ }
+
+ /**
+ * Gets the duration this worldborder took to make the change.
+ * <p>
+ * Can be 0 if handlers for {@link io.papermc.paper.event.world.border.WorldBorderCenterChangeEvent} set the duration to 0.
+ *
+ * @return the duration of the transition
+ */
+ public double getDuration() {
+ return duration;
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+}
diff --git a/src/main/java/io/papermc/paper/event/world/border/WorldBorderCenterChangeEvent.java b/src/main/java/io/papermc/paper/event/world/border/WorldBorderCenterChangeEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..4a10c773a8d05a596066e63306dead74c1363fd7
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/world/border/WorldBorderCenterChangeEvent.java
@@ -0,0 +1,77 @@
+package io.papermc.paper.event.world.border;
+
+import org.bukkit.Location;
+import org.bukkit.World;
+import org.bukkit.WorldBorder;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.world.WorldEvent;
+import org.jetbrains.annotations.NotNull;
+
+/**
+ * Called when a world border's center is changed.
+ */
+public class WorldBorderCenterChangeEvent extends WorldBorderEvent implements Cancellable {
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ private final Location oldCenter;
+ private Location newCenter;
+ private boolean cancelled;
+
+ public WorldBorderCenterChangeEvent(@NotNull World world, @NotNull WorldBorder worldBorder, @NotNull Location oldCenter, @NotNull Location newCenter) {
+ super(world, worldBorder);
+ this.oldCenter = oldCenter;
+ this.newCenter = newCenter;
+ }
+
+ /**
+ * Gets the original center location of the world border.
+ *
+ * @return the old center
+ */
+ @NotNull
+ public Location getOldCenter() {
+ return oldCenter;
+ }
+
+ /**
+ * Gets the new center location for the world border.
+ *
+ * @return the new center
+ */
+ @NotNull
+ public Location getNewCenter() {
+ return newCenter;
+ }
+
+ /**
+ * Sets the new center location for the world border. Y coordinate is ignored.
+ *
+ * @param newCenter the new center
+ */
+ public void setNewCenter(@NotNull Location newCenter) {
+ this.newCenter = newCenter;
+ }
+
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancelled = cancel;
+ }
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+}
diff --git a/src/main/java/io/papermc/paper/event/world/border/WorldBorderEvent.java b/src/main/java/io/papermc/paper/event/world/border/WorldBorderEvent.java
new file mode 100644
index 0000000000000000000000000000000000000000..67bd469d3680c9554ce6c1d5493826a252682835
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/world/border/WorldBorderEvent.java
@@ -0,0 +1,22 @@
+package io.papermc.paper.event.world.border;
+
+import org.bukkit.World;
+import org.bukkit.WorldBorder;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.world.WorldEvent;
+import org.jetbrains.annotations.NotNull;
+
+public abstract class WorldBorderEvent extends WorldEvent {
+
+ private final WorldBorder worldBorder;
+
+ public WorldBorderEvent(@NotNull World world, @NotNull WorldBorder worldBorder) {
+ super(world);
+ this.worldBorder = worldBorder;
+ }
+
+ @NotNull
+ public WorldBorder getWorldBorder() {
+ return worldBorder;
+ }
+}

View file

@ -0,0 +1,130 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Sun, 5 Jul 2020 00:34:24 -0700
Subject: [PATCH] added PlayerNameEntityEvent
diff --git a/src/main/java/io/papermc/paper/event/player/PlayerNameEntityEvent.java b/src/main/java/io/papermc/paper/event/player/PlayerNameEntityEvent.java
new file mode 100755
index 0000000000000000000000000000000000000000..ef9e53a73eff469bbaa8fb20c634297acb9d1986
--- /dev/null
+++ b/src/main/java/io/papermc/paper/event/player/PlayerNameEntityEvent.java
@@ -0,0 +1,118 @@
+package io.papermc.paper.event.player;
+
+import net.kyori.adventure.text.Component;
+import org.bukkit.entity.LivingEntity;
+import org.bukkit.entity.Player;
+import org.bukkit.event.Cancellable;
+import org.bukkit.event.HandlerList;
+import org.bukkit.event.player.PlayerEvent;
+import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
+
+/**
+ * Called when the player is attempting to rename a mob
+ */
+public class PlayerNameEntityEvent extends PlayerEvent implements Cancellable {
+
+ private LivingEntity entity;
+ private Component name;
+ private boolean persistent;
+ private boolean cancelled;
+
+ public PlayerNameEntityEvent(@NotNull Player player, @NotNull LivingEntity entity, @NotNull Component name, boolean persistent) {
+ super(player);
+ this.entity = entity;
+ this.name = name;
+ this.persistent = persistent;
+ }
+
+ /**
+ * Gets the name to be given to the entity.
+ * @return the name
+ */
+ @Nullable
+ public Component getName() {
+ return name;
+ }
+
+ /**
+ * Sets the name to be given to the entity.
+ *
+ * @param name the name
+ */
+ public void setName(@Nullable Component name) {
+ this.name = name;
+ }
+
+ /**
+ * Gets the entity involved in this event.
+ *
+ * @return the entity
+ */
+ @NotNull
+ public LivingEntity getEntity() {
+ return entity;
+ }
+
+ /**
+ * Sets the entity involved in this event.
+ *
+ * @param entity the entity
+ */
+ public void setEntity(@NotNull LivingEntity entity) {
+ this.entity = entity;
+ }
+
+ /**
+ * Gets whether this will set the mob to be persistent.
+ *
+ * @return persistent
+ */
+ public boolean isPersistent() {
+ return persistent;
+ }
+
+ /**
+ * Sets whether this will set the mob to be persistent.
+ *
+ * @param persistent persistent
+ */
+ public void setPersistent(boolean persistent) {
+ this.persistent = persistent;
+ }
+
+ /**
+ * Gets the cancellation state of this event. A cancelled event will not
+ * be executed in the server, but will still pass to other plugins
+ *
+ * @return true if this event is cancelled
+ */
+ @Override
+ public boolean isCancelled() {
+ return cancelled;
+ }
+
+ /**
+ * Sets the cancellation state of this event. A cancelled event will not
+ * be executed in the server, but will still pass to other plugins.
+ *
+ * @param cancel true if you wish to cancel this event
+ */
+ @Override
+ public void setCancelled(boolean cancel) {
+ this.cancelled = cancel;
+ }
+
+ private static final HandlerList HANDLER_LIST = new HandlerList();
+
+ @NotNull
+ @Override
+ public HandlerList getHandlers() {
+ return HANDLER_LIST;
+ }
+
+ @NotNull
+ public static HandlerList getHandlerList() {
+ return HANDLER_LIST;
+ }
+}

View file

@ -0,0 +1,69 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Thonk <30448663+ExcessiveAmountsOfZombies@users.noreply.github.com>
Date: Wed, 6 Jan 2021 12:05:29 -0800
Subject: [PATCH] Add recipe to cook events
diff --git a/src/main/java/org/bukkit/event/block/BlockCookEvent.java b/src/main/java/org/bukkit/event/block/BlockCookEvent.java
index be7af5440bf9923f0c9c84efa4d70a89337a2f96..a3f1c9cb36c9069ed622985a525bfc2a7a27ab91 100644
--- a/src/main/java/org/bukkit/event/block/BlockCookEvent.java
+++ b/src/main/java/org/bukkit/event/block/BlockCookEvent.java
@@ -14,12 +14,21 @@ public class BlockCookEvent extends BlockEvent implements Cancellable {
private final ItemStack source;
private ItemStack result;
private boolean cancelled;
+ private final org.bukkit.inventory.CookingRecipe<?> recipe; // Paper
+ @Deprecated // Paper
public BlockCookEvent(@NotNull final Block block, @NotNull final ItemStack source, @NotNull final ItemStack result) {
+ // Paper start
+ this(block, source, result, null);
+ }
+
+ public BlockCookEvent(@NotNull final Block block, @NotNull final ItemStack source, @NotNull final ItemStack result, @org.jetbrains.annotations.Nullable org.bukkit.inventory.CookingRecipe<?> recipe) {
+ // Paper end
super(block);
this.source = source;
this.result = result;
this.cancelled = false;
+ this.recipe = recipe; // Paper
}
/**
@@ -61,6 +70,18 @@ public class BlockCookEvent extends BlockEvent implements Cancellable {
this.cancelled = cancel;
}
+ // Paper start
+ /**
+ * Gets the cooking recipe associated with this event.
+ *
+ * @return the recipe
+ */
+ @org.jetbrains.annotations.Nullable
+ public org.bukkit.inventory.CookingRecipe<?> getRecipe() {
+ return recipe;
+ }
+ // Paper end
+
@NotNull
@Override
public HandlerList getHandlers() {
diff --git a/src/main/java/org/bukkit/event/inventory/FurnaceSmeltEvent.java b/src/main/java/org/bukkit/event/inventory/FurnaceSmeltEvent.java
index 066e7dd9a34d35c8b643a5efcf95d6a5ef47c7ee..16b3ab8f525c4e863f804cc8460a330407d85478 100644
--- a/src/main/java/org/bukkit/event/inventory/FurnaceSmeltEvent.java
+++ b/src/main/java/org/bukkit/event/inventory/FurnaceSmeltEvent.java
@@ -10,7 +10,13 @@ import org.jetbrains.annotations.NotNull;
*/
public class FurnaceSmeltEvent extends BlockCookEvent {
+ @Deprecated // Paper
public FurnaceSmeltEvent(@NotNull final Block furnace, @NotNull final ItemStack source, @NotNull final ItemStack result) {
super(furnace, source, result);
}
+ // Paper start
+ public FurnaceSmeltEvent(@NotNull final Block furnace, @NotNull final ItemStack source, @NotNull final ItemStack result, @org.jetbrains.annotations.Nullable org.bukkit.inventory.CookingRecipe<?> recipe) {
+ super(furnace, source, result, recipe);
+ }
+ // Paper end
}

View file

@ -0,0 +1,26 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Mon, 6 Jul 2020 12:44:23 -0700
Subject: [PATCH] Add Block#isValidTool
diff --git a/src/main/java/org/bukkit/block/Block.java b/src/main/java/org/bukkit/block/Block.java
index 40fc747fa229d8ae682e8b126de98de6471eef6b..e959f844581eaa88f581a4fabcb39148624bbe9b 100644
--- a/src/main/java/org/bukkit/block/Block.java
+++ b/src/main/java/org/bukkit/block/Block.java
@@ -219,6 +219,15 @@ public interface Block extends Metadatable, net.kyori.adventure.translation.Tran
public static int getBlockKeyZ(long packed) {
return (int) ((packed << 10) >> 37);
}
+
+ /**
+ * Checks if the itemstack is a valid tool to
+ * break the block with
+ *
+ * @param itemStack The (tool) itemstack
+ * @return whether the block will drop items
+ */
+ boolean isValidTool(@NotNull ItemStack itemStack);
// Paper End
/**

View file

@ -0,0 +1,164 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Wed, 6 Jan 2021 00:34:10 -0800
Subject: [PATCH] Implement Keyed on World
diff --git a/src/main/java/org/bukkit/Bukkit.java b/src/main/java/org/bukkit/Bukkit.java
index 60528523299f92f842700cafd513a8ef6fd3c290..71423daecacf5cc8ec797ddfc8d74ca0af85b7b4 100644
--- a/src/main/java/org/bukkit/Bukkit.java
+++ b/src/main/java/org/bukkit/Bukkit.java
@@ -708,6 +708,18 @@ public final class Bukkit {
public static World getWorld(@NotNull UUID uid) {
return server.getWorld(uid);
}
+ // Paper start
+ /**
+ * Gets the world from the given NamespacedKey
+ *
+ * @param worldKey the NamespacedKey of the world to retrieve
+ * @return a world with the given NamespacedKey, or null if none exists
+ */
+ @Nullable
+ public static World getWorld(@NotNull NamespacedKey worldKey) {
+ return server.getWorld(worldKey);
+ }
+ // Paper end
/**
* Gets the map from the given item ID.
diff --git a/src/main/java/org/bukkit/Server.java b/src/main/java/org/bukkit/Server.java
index 5e0124fbfa7caa4ed321bf1e01ad0fde9941d7ef..6aee6423d9c68e567f581899a2d83dc35e56bd55 100644
--- a/src/main/java/org/bukkit/Server.java
+++ b/src/main/java/org/bukkit/Server.java
@@ -601,6 +601,17 @@ public interface Server extends PluginMessageRecipient, net.kyori.adventure.audi
@Nullable
public World getWorld(@NotNull UUID uid);
+ // Paper start
+ /**
+ * Gets the world from the given NamespacedKey
+ *
+ * @param worldKey the NamespacedKey of the world to retrieve
+ * @return a world with the given NamespacedKey, or null if none exists
+ */
+ @Nullable
+ public World getWorld(@NotNull NamespacedKey worldKey);
+ // Paper end
+
/**
* Gets the map from the given item ID.
*
diff --git a/src/main/java/org/bukkit/World.java b/src/main/java/org/bukkit/World.java
index 9506523227af07667fe2aaa7479f87e4a79b369f..49cbc8c1f05f2d48177f1b8fec25e2e1439be0d8 100644
--- a/src/main/java/org/bukkit/World.java
+++ b/src/main/java/org/bukkit/World.java
@@ -41,7 +41,7 @@ import org.jetbrains.annotations.Nullable;
/**
* Represents a world, which may contain entities, chunks and blocks
*/
-public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient, Metadatable, net.kyori.adventure.audience.ForwardingAudience { // Paper
+public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient, Metadatable, net.kyori.adventure.audience.ForwardingAudience, Keyed { // Paper
// Paper start
/**
@@ -1525,6 +1525,15 @@ public interface World extends RegionAccessor, WorldInfo, PluginMessageRecipient
@NotNull
java.util.concurrent.CompletableFuture<Chunk> getChunkAtAsync(int x, int z, boolean gen, boolean urgent);
+
+ /**
+ * Get the world's key
+ *
+ * @return the world's key
+ */
+ @NotNull
+ @Override
+ NamespacedKey getKey();
// Paper end
/**
diff --git a/src/main/java/org/bukkit/WorldCreator.java b/src/main/java/org/bukkit/WorldCreator.java
index 60bed20c2845f9dc15ecbed81157a63d75a4c4f4..14986911b4d0099ea2c91ab2196a771b7dee4c50 100644
--- a/src/main/java/org/bukkit/WorldCreator.java
+++ b/src/main/java/org/bukkit/WorldCreator.java
@@ -12,6 +12,7 @@ import org.jetbrains.annotations.Nullable;
* Represents various types of options that may be used to create a world.
*/
public class WorldCreator {
+ private final NamespacedKey key; // Paper
private final String name;
private long seed;
private World.Environment environment = World.Environment.NORMAL;
@@ -28,13 +29,67 @@ public class WorldCreator {
* @param name Name of the world that will be created
*/
public WorldCreator(@NotNull String name) {
- if (name == null) {
- throw new IllegalArgumentException("World name cannot be null");
- }
+ // Paper start
+ this(name, NamespacedKey.minecraft(name.toLowerCase(java.util.Locale.ENGLISH).replace(" ", "_")));
+ }
- this.name = name;
+ /**
+ * Creates an empty WorldCreator for the given world name and key
+ *
+ * @param levelName LevelName of the world that will be created
+ * @param worldKey NamespacedKey of the world that will be created
+ */
+ public WorldCreator(@NotNull String levelName, @NotNull NamespacedKey worldKey) {
+ if (levelName == null || worldKey == null) {
+ throw new IllegalArgumentException("World name and key cannot be null");
+ }
+ this.name = levelName;
this.seed = (new Random()).nextLong();
+ this.key = worldKey;
+ }
+
+ /**
+ * Creates an empty WorldCreator for the given key.
+ * LevelName will be the Key part of the NamespacedKey.
+ *
+ * @param worldKey NamespacedKey of the world that will be created
+ */
+ public WorldCreator(@NotNull NamespacedKey worldKey) {
+ this(worldKey.getKey(), worldKey);
+ }
+
+ /**
+ * Gets the key for this WorldCreator
+ *
+ * @return the key
+ */
+ @NotNull
+ public NamespacedKey key() {
+ return key;
+ }
+
+ /**
+ * Creates an empty WorldCreator for the given world name and key
+ *
+ * @param levelName LevelName of the world that will be created
+ * @param worldKey NamespacedKey of the world that will be created
+ */
+ @NotNull
+ public static WorldCreator ofNameAndKey(@NotNull String levelName, @NotNull NamespacedKey worldKey) {
+ return new WorldCreator(levelName, worldKey);
+ }
+
+ /**
+ * Creates an empty WorldCreator for the given key.
+ * LevelName will be the Key part of the NamespacedKey.
+ *
+ * @param worldKey NamespacedKey of the world that will be created
+ */
+ @NotNull
+ public static WorldCreator ofKey(@NotNull NamespacedKey worldKey) {
+ return new WorldCreator(worldKey);
}
+ // Paper end
/**
* Copies the options from the specified world

View file

@ -0,0 +1,109 @@
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Jake Potrebic <jake.m.potrebic@gmail.com>
Date: Fri, 12 Mar 2021 17:09:40 -0800
Subject: [PATCH] Item Rarity API
diff --git a/src/main/java/io/papermc/paper/inventory/ItemRarity.java b/src/main/java/io/papermc/paper/inventory/ItemRarity.java
new file mode 100644
index 0000000000000000000000000000000000000000..74ef8395cc040ce488c2acaa416db20272cc2734
--- /dev/null
+++ b/src/main/java/io/papermc/paper/inventory/ItemRarity.java
@@ -0,0 +1,28 @@
+package io.papermc.paper.inventory;
+
+import net.kyori.adventure.text.format.NamedTextColor;
+import net.kyori.adventure.text.format.TextColor;
+import org.jetbrains.annotations.NotNull;
+
+public enum ItemRarity {
+
+ COMMON(NamedTextColor.WHITE),
+ UNCOMMON(NamedTextColor.YELLOW),
+ RARE(NamedTextColor.AQUA),
+ EPIC(NamedTextColor.LIGHT_PURPLE);
+
+ TextColor color;
+
+ ItemRarity(TextColor color) {
+ this.color = color;
+ }
+
+ /**
+ * Gets the color formatting associated with the rarity.
+ * @return
+ */
+ @NotNull
+ public TextColor getColor() {
+ return color;
+ }
+}
diff --git a/src/main/java/org/bukkit/Material.java b/src/main/java/org/bukkit/Material.java
index 5922f4a3d5ac69abb232e8e497d838e10e35316e..fd1f64089359bf432a4934932ca6cad46145c04b 100644
--- a/src/main/java/org/bukkit/Material.java
+++ b/src/main/java/org/bukkit/Material.java
@@ -4002,6 +4002,17 @@ public enum Material implements Keyed, net.kyori.adventure.translation.Translata
public @NotNull String translationKey() {
return Bukkit.getUnsafe().getTranslationKey(this);
}
+
+ /**
+ * Returns the item rarity for the item. The Material <b>MUST</b> be an Item not a block.
+ * Use {@link #isItem()} before this.
+ *
+ * @return the item rarity
+ */
+ @NotNull
+ public io.papermc.paper.inventory.ItemRarity getItemRarity() {
+ return Bukkit.getUnsafe().getItemRarity(this);
+ }
// Paper end
/**
diff --git a/src/main/java/org/bukkit/UnsafeValues.java b/src/main/java/org/bukkit/UnsafeValues.java
index 84eda68281c6c6968d95b1313a33696c3a9980d4..bcd10b2c9255d778b678310febf1937301d01a50 100644
--- a/src/main/java/org/bukkit/UnsafeValues.java
+++ b/src/main/java/org/bukkit/UnsafeValues.java
@@ -137,5 +137,22 @@ public interface UnsafeValues {
* Use this when sending custom packets, so that there are no collisions on the client or server.
*/
public int nextEntityId();
+
+ /**
+ * Gets the item rarity of a material. The material <b>MUST</b> be an item.
+ * Use {@link Material#isItem()} before this.
+ *
+ * @param material the material to get the rarity of
+ * @return the item rarity
+ */
+ public io.papermc.paper.inventory.ItemRarity getItemRarity(Material material);
+
+ /**
+ * Gets the item rarity of the itemstack. The rarity can change based on enchantements.
+ *
+ * @param itemStack the itemstack to get the rarity of
+ * @return the itemstack rarity
+ */
+ public io.papermc.paper.inventory.ItemRarity getItemStackRarity(ItemStack itemStack);
// Paper end
}
diff --git a/src/main/java/org/bukkit/inventory/ItemStack.java b/src/main/java/org/bukkit/inventory/ItemStack.java
index e6eab5d8ca3fea8d2e0ccc1cd1c1a7a110b589db..f46aeb59a5a1bde4011cd1d933afcc19c7d1b3bd 100644
--- a/src/main/java/org/bukkit/inventory/ItemStack.java
+++ b/src/main/java/org/bukkit/inventory/ItemStack.java
@@ -877,5 +877,15 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, net.kyor
public @NotNull String translationKey() {
return Bukkit.getUnsafe().getTranslationKey(this);
}
+
+ /**
+ * Gets the item rarity of the itemstack. The rarity can change based on enchantements.
+ *
+ * @return the itemstack rarity
+ */
+ @NotNull
+ public io.papermc.paper.inventory.ItemRarity getRarity() {
+ return Bukkit.getUnsafe().getItemStackRarity(this);
+ }
// Paper end
}