Skip to content

Commit

Permalink
Deprecate bundled item data (#2514)
Browse files Browse the repository at this point in the history
* Deprecate bundled item data

* Use forRemoval further, and add the extra suppressions necessary due to this
  • Loading branch information
me4502 authored Dec 7, 2024
1 parent a1132ab commit e68086b
Show file tree
Hide file tree
Showing 13 changed files with 38 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BundledItemRegistry;

@SuppressWarnings("removal")
class BukkitItemRegistry extends BundledItemRegistry {
@Override
public Component getRichName(ItemType itemType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BundledBlockData;
import com.sk89q.worldedit.world.registry.BundledItemData;
import com.sk89q.worldedit.world.registry.LegacyMapper;
import org.apache.logging.log4j.Logger;

Expand Down Expand Up @@ -405,8 +404,7 @@ private boolean checkFilename(String filename) {
*/
public void loadMappings() {
BundledBlockData.getInstance(); // Load block registry
BundledItemData.getInstance(); // Load item registry
LegacyMapper.getInstance(); // Load item registry
LegacyMapper.getInstance(); // Load legacy mappings
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public class ItemType implements Keyed {
WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS)
.getRegistries().getItemRegistry().getRichName(this)
);
@SuppressWarnings("this-escape")
@SuppressWarnings("removal")
private final LazyReference<ItemMaterial> itemMaterial = LazyReference.from(() ->
WorldEdit.getInstance().getPlatformManager().queryCapability(Capability.GAME_HOOKS)
.getRegistries().getItemRegistry().getMaterial(this)
Expand Down Expand Up @@ -109,7 +109,10 @@ public BlockType getBlockType() {
* Get the material for this ItemType.
*
* @return The material
* @deprecated Deprecated without alternative
*/
@Deprecated(forRemoval = true)
@SuppressWarnings("removal")
public ItemMaterial getMaterial() {
return itemMaterial.getValue();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
* <p>The data is read from a JSON file that is bundled with WorldEdit. If
* reading fails (which occurs when this class is first instantiated), then
* the methods will return {@code null}s for all items.</p>
*
* @deprecated Deprecated without replacement.
*/
@Deprecated(forRemoval = true)
public final class BundledItemData {

private static final Logger LOGGER = LogManagerCompat.getLogger();
Expand Down Expand Up @@ -91,6 +94,7 @@ private void loadFromResource() throws IOException {
* @return the entry, or null
*/
@Nullable
@Deprecated
public ItemEntry findById(String id) {
// If it has no namespace, assume minecraft.
if (!id.contains(":")) {
Expand All @@ -104,8 +108,11 @@ public ItemEntry findById(String id) {
*
* @param id the string ID
* @return the material's properties, or null
* @deprecated Deprecated without alternative
*/
@Nullable
@Deprecated(forRemoval = true)
@SuppressWarnings("removal")
public ItemMaterial getMaterialById(String id) {
ItemEntry entry = findById(id);
if (entry != null) {
Expand All @@ -121,6 +128,7 @@ public ItemMaterial getMaterialById(String id) {
*
* @return the instance
*/
@Deprecated
public static BundledItemData getInstance() {
if (INSTANCE == null) {
INSTANCE = new BundledItemData();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,19 @@
/**
* A item registry that uses {@link BundledItemRegistry} to serve information
* about items.
*
* @deprecated Use the platform Item Registries
*/
@Deprecated(forRemoval = true)
public class BundledItemRegistry implements ItemRegistry {

@SuppressWarnings("removal")
private BundledItemData.ItemEntry getEntryById(ItemType itemType) {
return BundledItemData.getInstance().findById(itemType.id());
}

@Override
@SuppressWarnings("removal")
public Component getRichName(ItemType itemType) {
BundledItemData.ItemEntry itemEntry = getEntryById(itemType);
if (itemEntry != null && !itemEntry.localizedName.equals("Air")) {
Expand All @@ -56,7 +61,7 @@ public Component getRichName(ItemType itemType) {
@Override
@Deprecated
// dumb_intellij.jpg
@SuppressWarnings("deprecation")
@SuppressWarnings({"deprecation", "removal"})
public String getName(ItemType itemType) {
BundledItemData.ItemEntry itemEntry = getEntryById(itemType);
if (itemEntry != null) {
Expand All @@ -73,6 +78,8 @@ public String getName(ItemType itemType) {

@Nullable
@Override
@Deprecated(forRemoval = true)
@SuppressWarnings("removal")
public ItemMaterial getMaterial(ItemType itemType) {
return new PassthroughItemMaterial(BundledItemData.getInstance().getMaterialById(itemType.id()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ static URL loadRegistry(String name) throws IOException {
}

private final BundledBlockRegistry blockRegistry = new BundledBlockRegistry();
@SuppressWarnings("removal")
private final BundledItemRegistry itemRegistry = new BundledItemRegistry();
private final NullEntityRegistry entityRegistry = new NullEntityRegistry();
private final NullBiomeRegistry biomeRegistry = new NullBiomeRegistry();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import com.sk89q.worldedit.internal.util.DeprecationUtil;
import com.sk89q.worldedit.internal.util.NonAbstractForCompatibility;

@Deprecated(forRemoval = true)
public interface ItemMaterial {
/**
* Gets the the maximum quantity of this item that can be in a single stack.
Expand All @@ -38,7 +39,9 @@ default int getMaxStackSize() {
* Gets the the maximum quantity of this item that can be in a single stack.
*
* @return the maximum quantity
* @deprecated Deprecated with no alternative
*/
@Deprecated(forRemoval = true)
@NonAbstractForCompatibility(delegateName = "getMaxStackSize", delegateParams = {})
default int maxStackSize() {
DeprecationUtil.checkDelegatingOverride(getClass());
Expand All @@ -60,7 +63,9 @@ default int getMaxDamage() {
* Gets the the maximum damage this item can take before being broken.
*
* @return the maximum damage, or 0 if not applicable
* @deprecated Deprecated with no alternative
*/
@Deprecated(forRemoval = true)
@NonAbstractForCompatibility(delegateName = "getMaxDamage", delegateParams = {})
default int maxDamage() {
DeprecationUtil.checkDelegatingOverride(getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ default String getName(ItemType itemType) {
*
* @param itemType the item
* @return the material, or null if the material information is not known
* @deprecated ItemMaterial is deprecated with no alternative.
*/
@Deprecated(forRemoval = true)
@Nullable
@SuppressWarnings("removal")
ItemMaterial getMaterial(ItemType itemType);
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@

import static com.sk89q.worldedit.util.GuavaUtil.firstNonNull;

@Deprecated(forRemoval = true)
@SuppressWarnings("removal")
public class PassthroughItemMaterial implements ItemMaterial {

private static final ItemMaterial DEFAULT_MATERIAL = new SimpleItemMaterial(0, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,7 @@

package com.sk89q.worldedit.world.registry;

@Deprecated(forRemoval = true)
@SuppressWarnings("removal")
public record SimpleItemMaterial(int maxStackSize, int maxDamage) implements ItemMaterial {
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BundledItemRegistry;

@SuppressWarnings("removal")
public class FabricItemRegistry extends BundledItemRegistry {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import com.sk89q.worldedit.world.item.ItemType;
import com.sk89q.worldedit.world.registry.BundledItemRegistry;

@SuppressWarnings("removal")
public class NeoForgeItemRegistry extends BundledItemRegistry {

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.spongepowered.api.Sponge;
import org.spongepowered.api.registry.RegistryTypes;

@SuppressWarnings("removal")
public class SpongeItemRegistry extends BundledItemRegistry {

@Override
Expand Down

0 comments on commit e68086b

Please sign in to comment.