mirror of
https://github.com/PaperMC/Paper.git
synced 2025-02-17 10:41:41 +01:00
#1013, SPIGOT-4288, SPIGOT-6202: Add material rerouting in preparation for the switch to ItemType and BlockType
This also moves the conversion from and to legacy material to the method calls of legacy plugins, and no longer allows them directly in the server. This has the side effect of fixing some legacy plugin issues, such as SPIGOT-4288, SPIGOT-6161. Also fixes legacy items sometimes not stacking in inventory when using addItem, a client disconnect when using legacy items in recipes and probably some more. By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
parent
6a3d5c24c2
commit
ce747e1973
5 changed files with 44 additions and 5 deletions
paper-api/src/main/java/org/bukkit
event
inventory
|
@ -1,9 +1,11 @@
|
|||
package org.bukkit.event.inventory;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.block.BlockExpEvent;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
@ -17,6 +19,9 @@ public class FurnaceExtractEvent extends BlockExpEvent {
|
|||
public FurnaceExtractEvent(@NotNull Player player, @NotNull Block block, @NotNull Material itemType, int itemAmount, int exp) {
|
||||
super(block, exp);
|
||||
this.player = player;
|
||||
if (itemType != null && itemType.isLegacy()) {
|
||||
itemType = Bukkit.getUnsafe().fromLegacy(new MaterialData(itemType), true);
|
||||
}
|
||||
this.itemType = itemType;
|
||||
this.itemAmount = itemAmount;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package org.bukkit.event.player;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockFace;
|
||||
|
@ -7,6 +8,7 @@ import org.bukkit.entity.Player;
|
|||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.inventory.EquipmentSlot;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -38,7 +40,11 @@ public abstract class PlayerBucketEvent extends PlayerEvent implements Cancellab
|
|||
this.blockClicked = blockClicked;
|
||||
this.blockFace = blockFace;
|
||||
this.itemStack = itemInHand;
|
||||
this.bucket = bucket;
|
||||
if (bucket != null && bucket.isLegacy()) {
|
||||
this.bucket = Bukkit.getUnsafe().fromLegacy(new MaterialData(bucket), true);
|
||||
} else {
|
||||
this.bucket = bucket;
|
||||
}
|
||||
this.hand = hand;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
package org.bukkit.event.player;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Statistic;
|
||||
import org.bukkit.entity.EntityType;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.Cancellable;
|
||||
import org.bukkit.event.HandlerList;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
@ -49,6 +51,16 @@ public class PlayerStatisticIncrementEvent extends PlayerEvent implements Cancel
|
|||
this.initialValue = initialValue;
|
||||
this.newValue = newValue;
|
||||
this.entityType = null;
|
||||
if (material != null && material.isLegacy()) {
|
||||
if (statistic.getType() == Statistic.Type.BLOCK) {
|
||||
material = Bukkit.getUnsafe().fromLegacy(new MaterialData(material), false);
|
||||
} else if (statistic.getType() == Statistic.Type.ITEM) {
|
||||
material = Bukkit.getUnsafe().fromLegacy(new MaterialData(material), true);
|
||||
} else {
|
||||
// Theoretically, this should not happen, can probably print a warning, but for now it should be fine.
|
||||
material = Bukkit.getUnsafe().fromLegacy(new MaterialData(material), false);
|
||||
}
|
||||
}
|
||||
this.material = material;
|
||||
}
|
||||
|
||||
|
|
|
@ -83,8 +83,15 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
|
|||
* @deprecated this method uses an ambiguous data byte object
|
||||
*/
|
||||
@Deprecated
|
||||
public ItemStack(@NotNull final Material type, final int amount, final short damage, @Nullable final Byte data) {
|
||||
public ItemStack(@NotNull Material type, final int amount, final short damage, @Nullable final Byte data) {
|
||||
Preconditions.checkArgument(type != null, "Material cannot be null");
|
||||
if (type.isLegacy()) {
|
||||
if (type.getMaxDurability() > 0) {
|
||||
type = Bukkit.getUnsafe().fromLegacy(new MaterialData(type, data == null ? 0 : data), true);
|
||||
} else {
|
||||
type = Bukkit.getUnsafe().fromLegacy(new MaterialData(type, data == null ? (byte) damage : data), true);
|
||||
}
|
||||
}
|
||||
this.type = type;
|
||||
this.amount = amount;
|
||||
if (damage != 0) {
|
||||
|
|
|
@ -7,8 +7,10 @@ import java.util.Collections;
|
|||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.function.Predicate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.Tag;
|
||||
import org.bukkit.material.MaterialData;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
|
@ -65,12 +67,19 @@ public interface RecipeChoice extends Predicate<ItemStack>, Cloneable {
|
|||
public MaterialChoice(@NotNull List<Material> choices) {
|
||||
Preconditions.checkArgument(choices != null, "choices");
|
||||
Preconditions.checkArgument(!choices.isEmpty(), "Must have at least one choice");
|
||||
|
||||
this.choices = new ArrayList<>(choices.size());
|
||||
|
||||
for (Material choice : choices) {
|
||||
Preconditions.checkArgument(choice != null, "Cannot have null choice");
|
||||
Preconditions.checkArgument(!choice.isAir(), "Cannot have empty/air choice");
|
||||
}
|
||||
|
||||
this.choices = new ArrayList<>(choices);
|
||||
if (choice.isLegacy()) {
|
||||
choice = Bukkit.getUnsafe().fromLegacy(new MaterialData(choice, (byte) 0), true);
|
||||
}
|
||||
|
||||
Preconditions.checkArgument(!choice.isAir(), "Cannot have empty/air choice");
|
||||
this.choices.add(choice);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Reference in a new issue