#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:
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user