#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:
Bukkit/Spigot
2024-05-29 06:48:52 +10:00
parent 6a3d5c24c2
commit ce747e1973
5 changed files with 44 additions and 5 deletions

View File

@@ -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;
}

View File

@@ -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;
}

View File

@@ -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;
}