diff --git a/legacy-1_17-compat/pom.xml b/legacy-1_17-compat/pom.xml index f199d0c..57ec9a9 100644 --- a/legacy-1_17-compat/pom.xml +++ b/legacy-1_17-compat/pom.xml @@ -4,10 +4,10 @@ 4.0.0 net.sourcewriters.spigot.rwg legacy-1_17-compat - 2.0.2 + 3.0.0 - 2.1.0 + 3.0.0 diff --git a/legacy-1_17-compat/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/impl/VersionCompatibilityProviderImpl.java b/legacy-1_17-compat/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/impl/VersionCompatibilityProviderImpl.java index 13e3795..111c525 100644 --- a/legacy-1_17-compat/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/impl/VersionCompatibilityProviderImpl.java +++ b/legacy-1_17-compat/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/impl/VersionCompatibilityProviderImpl.java @@ -10,7 +10,6 @@ import net.sourcewriters.spigot.rwg.legacy.api.block.IBlockDataLoaderManager; import net.sourcewriters.spigot.rwg.legacy.api.block.IBlockDataParserManager; import net.sourcewriters.spigot.rwg.legacy.api.block.IBlockDataPlacerManager; -import net.sourcewriters.spigot.rwg.legacy.api.block.impl.BlockAccessImpl; import net.sourcewriters.spigot.rwg.legacy.api.block.impl.DefaultMinecraftLoader; import net.sourcewriters.spigot.rwg.legacy.api.block.impl.DefaultMinecraftParser; import net.sourcewriters.spigot.rwg.legacy.api.block.impl.DefaultMinecraftPlacer; @@ -26,7 +25,6 @@ public class VersionCompatibilityProviderImpl extends VersionCompatibilityProvid public void provide(final ILogger logger, final IArgumentMap map) { final IDataFixHandler dataFixHandler = new DataFixHandlerImpl(); final IVersionAccess versionAccess = new VersionAccessImpl(logger); - set(map, IBlockAccess.class, new BlockAccessImpl(logger, versionAccess.getConversionAccess(), dataFixHandler)); set(map, IVersionAccess.class, versionAccess); set(map, IDataFixHandler.class, dataFixHandler); } diff --git a/legacy-1_17-compat/src/main/resources/api.json b/legacy-1_17-compat/src/main/resources/api.json index 3f3c2c5..2569489 100644 --- a/legacy-1_17-compat/src/main/resources/api.json +++ b/legacy-1_17-compat/src/main/resources/api.json @@ -1,7 +1,7 @@ { - "api": 2, - "version": "${project.version}", + "api": 3, + "version": "${project.version}", "minecraft": [ - "1.17" + "1.17" ] } diff --git a/legacy-1_17_1-compat/pom.xml b/legacy-1_17_1-compat/pom.xml index 053e9d6..65305f4 100644 --- a/legacy-1_17_1-compat/pom.xml +++ b/legacy-1_17_1-compat/pom.xml @@ -4,10 +4,10 @@ 4.0.0 net.sourcewriters.spigot.rwg legacy-1_17_1-compat - 2.0.2 + 3.0.0 - 2.1.0 + 3.0.0 diff --git a/legacy-1_17_1-compat/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/impl/VersionCompatibilityProviderImpl.java b/legacy-1_17_1-compat/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/impl/VersionCompatibilityProviderImpl.java index 13e3795..111c525 100644 --- a/legacy-1_17_1-compat/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/impl/VersionCompatibilityProviderImpl.java +++ b/legacy-1_17_1-compat/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/impl/VersionCompatibilityProviderImpl.java @@ -10,7 +10,6 @@ import net.sourcewriters.spigot.rwg.legacy.api.block.IBlockDataLoaderManager; import net.sourcewriters.spigot.rwg.legacy.api.block.IBlockDataParserManager; import net.sourcewriters.spigot.rwg.legacy.api.block.IBlockDataPlacerManager; -import net.sourcewriters.spigot.rwg.legacy.api.block.impl.BlockAccessImpl; import net.sourcewriters.spigot.rwg.legacy.api.block.impl.DefaultMinecraftLoader; import net.sourcewriters.spigot.rwg.legacy.api.block.impl.DefaultMinecraftParser; import net.sourcewriters.spigot.rwg.legacy.api.block.impl.DefaultMinecraftPlacer; @@ -26,7 +25,6 @@ public class VersionCompatibilityProviderImpl extends VersionCompatibilityProvid public void provide(final ILogger logger, final IArgumentMap map) { final IDataFixHandler dataFixHandler = new DataFixHandlerImpl(); final IVersionAccess versionAccess = new VersionAccessImpl(logger); - set(map, IBlockAccess.class, new BlockAccessImpl(logger, versionAccess.getConversionAccess(), dataFixHandler)); set(map, IVersionAccess.class, versionAccess); set(map, IDataFixHandler.class, dataFixHandler); } diff --git a/legacy-1_17_1-compat/src/main/resources/api.json b/legacy-1_17_1-compat/src/main/resources/api.json index 18753ee..5e82a58 100644 --- a/legacy-1_17_1-compat/src/main/resources/api.json +++ b/legacy-1_17_1-compat/src/main/resources/api.json @@ -1,7 +1,7 @@ { - "api": 2, - "version": "${project.version}", + "api": 3, + "version": "${project.version}", "minecraft": [ - "1.17.1" + "1.17.1" ] } diff --git a/legacy-api/pom.xml b/legacy-api/pom.xml index 2bcdde5..f5a56b8 100644 --- a/legacy-api/pom.xml +++ b/legacy-api/pom.xml @@ -4,7 +4,7 @@ 4.0.0 net.sourcewriters.spigot.rwg legacy-api - 2.5.1 + 3.0.0 diff --git a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/BlockDataLoader.java b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/BlockDataLoader.java index 42dceb2..86645d1 100644 --- a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/BlockDataLoader.java +++ b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/BlockDataLoader.java @@ -2,7 +2,7 @@ import java.util.Objects; -import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; import org.bukkit.plugin.Plugin; @@ -36,6 +36,6 @@ public final String getName() { return name; } - public abstract IBlockData load(@NonNull IBlockAccess access, @NonNull Block block, @NonNull BlockData blockData); + public abstract IBlockData load(@NonNull IBlockAccess access, @NonNull BlockState blockState, @NonNull BlockData blockData); } diff --git a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/IBlockAccess.java b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/IBlockAccess.java index 1ca20a6..4e84608 100644 --- a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/IBlockAccess.java +++ b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/IBlockAccess.java @@ -2,6 +2,7 @@ import org.bukkit.Material; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; import com.syntaxphoenix.syntaxapi.nbt.NbtCompound; @@ -23,6 +24,9 @@ public interface IBlockAccess { @CallerSensitive IBlockData dataOf(@NonNull Block block); + + @CallerSensitive + IBlockData dataOf(@NonNull BlockState blockState); @CallerSensitive IBlockData dataOf(@NonNull String rawData); diff --git a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/IBlockDataLoaderManager.java b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/IBlockDataLoaderManager.java index a1f5c41..8ba430f 100644 --- a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/IBlockDataLoaderManager.java +++ b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/IBlockDataLoaderManager.java @@ -4,6 +4,7 @@ import org.bukkit.Location; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import net.sourcewriters.spigot.rwg.legacy.api.util.annotation.source.NonNull; @@ -29,5 +30,7 @@ default boolean register(final boolean expression, @NonNull final Supplier> clazz = Tracker.getCallerClass(); + if (clazz.isPresent() && BlockDataLoader.class.isAssignableFrom(clazz.get())) { + logger.log(LogTypeId.WARNING, + "BlockDataLoader (" + clazz.get().getName() + ") is calling dataOf(Block), this could cause an infinite loop!"); + } + return loaderManager.load(blockState); + } + @CallerSensitive @Override public IBlockData dataOf(@NonNull final String rawData) { diff --git a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/impl/BlockDataLoaderManagerImpl.java b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/impl/BlockDataLoaderManagerImpl.java index bbf6910..918d094 100644 --- a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/impl/BlockDataLoaderManagerImpl.java +++ b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/impl/BlockDataLoaderManagerImpl.java @@ -7,6 +7,7 @@ import org.bukkit.Bukkit; import org.bukkit.Location; import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; import com.syntaxphoenix.syntaxapi.logging.ILogger; @@ -68,7 +69,7 @@ public IBlockData load(@NonNull final Location location) { Objects.requireNonNull(location, "Location can't be null!"); if (Bukkit.isPrimaryThread()) { try { - return load(location.getBlock()); + return load(location.getBlock().getState()); } catch (final Exception exp) { logger.log(LogTypeId.WARNING, "Failed to load block"); logger.log(LogTypeId.WARNING, exp); @@ -76,7 +77,7 @@ public IBlockData load(@NonNull final Location location) { } } try { - return load(location.getBlock()); + return load(location.getBlock().getState()); } catch (final Exception exp) { logger.log(LogTypeId.WARNING, "Failed to load block asynchronously to main thread"); logger.log(LogTypeId.WARNING, exp); @@ -87,14 +88,35 @@ public IBlockData load(@NonNull final Location location) { @Override public IBlockData load(@NonNull final Block block) { Objects.requireNonNull(block, "Block can't be null!"); + if (Bukkit.isPrimaryThread()) { + try { + return load(block.getState()); + } catch (final Exception exp) { + logger.log(LogTypeId.WARNING, "Failed to load block"); + logger.log(LogTypeId.WARNING, exp); + return null; + } + } + try { + return load(block.getState()); + } catch (final Exception exp) { + logger.log(LogTypeId.WARNING, "Failed to load block asynchronously to main thread"); + logger.log(LogTypeId.WARNING, exp); + return null; + } + } + + @Override + public IBlockData load(@NonNull final BlockState blockState) { + Objects.requireNonNull(blockState, "BlockState can't be null!"); if (loaders.isEmpty()) { logger.log(LogTypeId.ERROR, "Can't load blocks without BlockDataLoader's!"); return null; } - final BlockData data = block.getBlockData(); + final BlockData data = blockState.getBlockData(); final int size = order.size(); for (int index = size - 1; index >= 0; index--) { - final IBlockData output = loaders.get(order.get(index)).load(access, block, data); + final IBlockData output = loaders.get(order.get(index)).load(access, blockState, data); if (output != null) { return output; } diff --git a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/impl/DefaultMinecraftLoader.java b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/impl/DefaultMinecraftLoader.java index 27559e9..4f8448f 100644 --- a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/impl/DefaultMinecraftLoader.java +++ b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/block/impl/DefaultMinecraftLoader.java @@ -1,6 +1,6 @@ package net.sourcewriters.spigot.rwg.legacy.api.block.impl; -import org.bukkit.block.Block; +import org.bukkit.block.BlockState; import org.bukkit.block.data.BlockData; import org.bukkit.plugin.Plugin; @@ -15,7 +15,7 @@ public DefaultMinecraftLoader(final Plugin plugin) { } @Override - public IBlockData load(final IBlockAccess access, final Block block, final BlockData blockData) { + public IBlockData load(final IBlockAccess access, final BlockState block, final BlockData blockData) { return access.dataOf(blockData).setConversionPossible(true); } diff --git a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/chest/IChestStorage.java b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/chest/IChestStorage.java index cb8a0d8..f14170a 100644 --- a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/chest/IChestStorage.java +++ b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/chest/IChestStorage.java @@ -12,6 +12,10 @@ @Unsafe(status = UnsafeStatus.WORK_IN_PROGRESS, useable = true) public interface IChestStorage { + + String[] getNames(); + + boolean has(String chest); void fillInventory(String chest, Inventory inventory); diff --git a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/data/property/Properties.java b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/data/property/Properties.java index 62e79b6..cb4a6c3 100644 --- a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/data/property/Properties.java +++ b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/data/property/Properties.java @@ -3,8 +3,14 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Optional; +import java.util.concurrent.ConcurrentHashMap; +import java.util.function.Function; class Properties implements IProperties { + + private static final ConcurrentHashMap VOIDS = new ConcurrentHashMap<>(); + private static final Function VOID_PROPERTY_BUILD = VoidProperty::new; private final List> properties = Collections.synchronizedList(new ArrayList<>()); @@ -99,7 +105,8 @@ public List> find(final String... keys) { @Override public IProperty find(final String key) { - return properties.stream().filter(property -> property.getKey().equals(key)).findFirst().orElse(new VoidProperty(key)); + Optional> option = properties.stream().filter(property -> property.getKey().equals(key)).findFirst(); + return option.isPresent() ? option.get() : VOIDS.computeIfAbsent(key, VOID_PROPERTY_BUILD); } @Override diff --git a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/schematic/ISchematicLoader.java b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/schematic/ISchematicLoader.java index 63a3d99..d01f638 100644 --- a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/schematic/ISchematicLoader.java +++ b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/schematic/ISchematicLoader.java @@ -3,6 +3,7 @@ import java.io.File; import java.util.function.Supplier; +import net.sourcewriters.spigot.rwg.legacy.api.data.asset.IAsset; import net.sourcewriters.spigot.rwg.legacy.api.util.annotation.source.NonNull; public interface ISchematicLoader { @@ -22,7 +23,7 @@ public interface ISchematicLoader { * format */ @NonNull - ISchematic load(@NonNull File file) throws Exception; + IAsset load(@NonNull File file) throws Exception; boolean register(@NonNull SchematicConverter converter); diff --git a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/schematic/ISchematicStorage.java b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/schematic/ISchematicStorage.java index 5f7fb73..33db54e 100644 --- a/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/schematic/ISchematicStorage.java +++ b/legacy-api/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/schematic/ISchematicStorage.java @@ -6,6 +6,7 @@ import com.syntaxphoenix.syntaxapi.random.RandomNumberGenerator; +import net.sourcewriters.spigot.rwg.legacy.api.data.asset.IAsset; import net.sourcewriters.spigot.rwg.legacy.api.schematic.update.ISchematicUpdater; import net.sourcewriters.spigot.rwg.legacy.api.util.annotation.source.NonNull; import net.sourcewriters.spigot.rwg.legacy.api.util.annotation.unsafe.Unsafe; @@ -14,7 +15,7 @@ @Unsafe(status = UnsafeStatus.SUBJECT_TO_CHANGE, useable = true) public interface ISchematicStorage { - ISchematic get(String name); + IAsset get(String name); boolean has(String name); @@ -24,7 +25,7 @@ public interface ISchematicStorage { String[] getNames(); @NonNull - ISchematic[] getSchematics(); + IAsset[] getSchematics(); @NonNull Future paste(ISchematic schmeatic, Location location); diff --git a/legacy-pre1_17-compat/pom.xml b/legacy-pre1_17-compat/pom.xml index 87c61f0..b975acc 100644 --- a/legacy-pre1_17-compat/pom.xml +++ b/legacy-pre1_17-compat/pom.xml @@ -4,10 +4,10 @@ 4.0.0 net.sourcewriters.spigot.rwg legacy-pre1_17-compat - 2.0.1 + 3.0.0 - 2.1.0 + 3.0.0 diff --git a/legacy-pre1_17-compat/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/impl/VersionCompatibilityProviderImpl.java b/legacy-pre1_17-compat/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/impl/VersionCompatibilityProviderImpl.java index 13e3795..111c525 100644 --- a/legacy-pre1_17-compat/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/impl/VersionCompatibilityProviderImpl.java +++ b/legacy-pre1_17-compat/src/main/java/net/sourcewriters/spigot/rwg/legacy/api/impl/VersionCompatibilityProviderImpl.java @@ -10,7 +10,6 @@ import net.sourcewriters.spigot.rwg.legacy.api.block.IBlockDataLoaderManager; import net.sourcewriters.spigot.rwg.legacy.api.block.IBlockDataParserManager; import net.sourcewriters.spigot.rwg.legacy.api.block.IBlockDataPlacerManager; -import net.sourcewriters.spigot.rwg.legacy.api.block.impl.BlockAccessImpl; import net.sourcewriters.spigot.rwg.legacy.api.block.impl.DefaultMinecraftLoader; import net.sourcewriters.spigot.rwg.legacy.api.block.impl.DefaultMinecraftParser; import net.sourcewriters.spigot.rwg.legacy.api.block.impl.DefaultMinecraftPlacer; @@ -26,7 +25,6 @@ public class VersionCompatibilityProviderImpl extends VersionCompatibilityProvid public void provide(final ILogger logger, final IArgumentMap map) { final IDataFixHandler dataFixHandler = new DataFixHandlerImpl(); final IVersionAccess versionAccess = new VersionAccessImpl(logger); - set(map, IBlockAccess.class, new BlockAccessImpl(logger, versionAccess.getConversionAccess(), dataFixHandler)); set(map, IVersionAccess.class, versionAccess); set(map, IDataFixHandler.class, dataFixHandler); } diff --git a/legacy-pre1_17-compat/src/main/resources/api.json b/legacy-pre1_17-compat/src/main/resources/api.json index 14537f2..3c08842 100644 --- a/legacy-pre1_17-compat/src/main/resources/api.json +++ b/legacy-pre1_17-compat/src/main/resources/api.json @@ -1,6 +1,6 @@ { - "api": 2, - "version": "${project.version}", + "api": 3, + "version": "${project.version}", "minecraft": [ "1.13", "1.13.1",