mirror of
https://github.com/BentoBoxWorld/BentoBox.git
synced 2025-01-22 08:01:24 +01:00
Add support for older 1.20.x versions
This commit is contained in:
parent
2d0d9ac1c2
commit
b63aef5589
18
pom.xml
18
pom.xml
@ -224,6 +224,24 @@
|
||||
<version>${spigot.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc.</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.20.3-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc..</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.20.2-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc...</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>1.20.1-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<!-- Paper API -->
|
||||
<dependency>
|
||||
<groupId>io.papermc.paper</groupId>
|
||||
|
@ -641,7 +641,7 @@ public class YamlDatabaseHandler<T> extends AbstractDatabaseHandler<T> {
|
||||
.or(Enums.getIfPresent(EntityType.class, "PIG_ZOMBIE").or(EntityType.PIG));
|
||||
}
|
||||
// Backwards compatibility for upgrade to 1.20.4
|
||||
if (name.equals("GRASS")) {
|
||||
if (name.equals("GRASS") && Enums.getIfPresent(EntityType.class, "SHORT_GRASS").isPresent()) {
|
||||
return Enums.getIfPresent(EntityType.class, "SHORT_GRASS");
|
||||
}
|
||||
value = Enum.valueOf(enumClass, name);
|
||||
|
@ -0,0 +1,74 @@
|
||||
package world.bentobox.bentobox.nms.v1_20_R1;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData;
|
||||
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import net.minecraft.world.level.chunk.Chunk;
|
||||
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBlock;
|
||||
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.nms.PasteHandler;
|
||||
import world.bentobox.bentobox.util.DefaultPasteUtil;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class PasteHandlerImpl implements PasteHandler {
|
||||
|
||||
protected static final IBlockData AIR = ((CraftBlockData) Bukkit.createBlockData(Material.AIR)).getState();
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> pasteBlocks(Island island, World world, Map<Location, BlueprintBlock> blockMap) {
|
||||
return blockMap.entrySet().stream().map(entry -> setBlock(island, entry.getKey(), entry.getValue()))
|
||||
.collect(Collectors.collectingAndThen(Collectors.toList(),
|
||||
list -> CompletableFuture.allOf(list.toArray(new CompletableFuture[0]))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> pasteEntities(Island island, World world,
|
||||
Map<Location, List<BlueprintEntity>> entityMap) {
|
||||
return entityMap.entrySet().stream()
|
||||
.map(entry -> DefaultPasteUtil.setEntity(island, entry.getKey(), entry.getValue()))
|
||||
.collect(Collectors.collectingAndThen(Collectors.toList(),
|
||||
list -> CompletableFuture.allOf(list.toArray(new CompletableFuture[0]))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the block to the location
|
||||
*
|
||||
* @param island - island
|
||||
* @param location - location
|
||||
* @param bpBlock - blueprint block
|
||||
*/
|
||||
public static CompletableFuture<Void> setBlock(Island island, Location location, BlueprintBlock bpBlock) {
|
||||
return Util.getChunkAtAsync(location).thenRun(() -> {
|
||||
Block block = location.getBlock();
|
||||
// Set the block data - default is AIR
|
||||
BlockData bd = DefaultPasteUtil.createBlockData(bpBlock);
|
||||
CraftBlockData craft = (CraftBlockData) bd;
|
||||
net.minecraft.world.level.World nmsWorld = ((CraftWorld) location.getWorld()).getHandle();
|
||||
Chunk nmsChunk = nmsWorld.d(location.getBlockX() >> 4, location.getBlockZ() >> 4);
|
||||
BlockPosition bp = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
// Setting the block to air before setting to another state prevents some console errors
|
||||
nmsChunk.a(bp, AIR, false);
|
||||
nmsChunk.a(bp, craft.getState(), false);
|
||||
block.setBlockData(bd, false);
|
||||
DefaultPasteUtil.setBlockState(island, block, bpBlock);
|
||||
// Set biome
|
||||
if (bpBlock.getBiome() != null) {
|
||||
block.setBiome(bpBlock.getBiome());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package world.bentobox.bentobox.nms.v1_20_R1;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_20_R1.block.data.CraftBlockData;
|
||||
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.world.level.World;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import net.minecraft.world.level.chunk.Chunk;
|
||||
import world.bentobox.bentobox.nms.CopyWorldRegenerator;
|
||||
|
||||
public class WorldRegeneratorImpl extends CopyWorldRegenerator {
|
||||
|
||||
private static final IBlockData AIR = ((CraftBlockData) Bukkit.createBlockData(Material.AIR)).getState();
|
||||
|
||||
@Override
|
||||
public void setBlockInNativeChunk(org.bukkit.Chunk chunk, int x, int y, int z, BlockData blockData,
|
||||
boolean applyPhysics) {
|
||||
CraftBlockData craft = (CraftBlockData) blockData;
|
||||
World nmsWorld = ((CraftWorld) chunk.getWorld()).getHandle();
|
||||
Chunk nmsChunk = nmsWorld.d(chunk.getX(), chunk.getZ());
|
||||
BlockPosition bp = new BlockPosition((chunk.getX() << 4) + x, y, (chunk.getZ() << 4) + z);
|
||||
// Setting the block to air before setting to another state prevents some console errors
|
||||
nmsChunk.a(bp, AIR, applyPhysics);
|
||||
nmsChunk.a(bp, craft.getState(), applyPhysics);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,74 @@
|
||||
package world.bentobox.bentobox.nms.v1_20_R2;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData;
|
||||
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import net.minecraft.world.level.chunk.Chunk;
|
||||
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintBlock;
|
||||
import world.bentobox.bentobox.blueprints.dataobjects.BlueprintEntity;
|
||||
import world.bentobox.bentobox.database.objects.Island;
|
||||
import world.bentobox.bentobox.nms.PasteHandler;
|
||||
import world.bentobox.bentobox.util.DefaultPasteUtil;
|
||||
import world.bentobox.bentobox.util.Util;
|
||||
|
||||
public class PasteHandlerImpl implements PasteHandler {
|
||||
|
||||
protected static final IBlockData AIR = ((CraftBlockData) Bukkit.createBlockData(Material.AIR)).getState();
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> pasteBlocks(Island island, World world, Map<Location, BlueprintBlock> blockMap) {
|
||||
return blockMap.entrySet().stream().map(entry -> setBlock(island, entry.getKey(), entry.getValue()))
|
||||
.collect(Collectors.collectingAndThen(Collectors.toList(),
|
||||
list -> CompletableFuture.allOf(list.toArray(new CompletableFuture[0]))));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<Void> pasteEntities(Island island, World world,
|
||||
Map<Location, List<BlueprintEntity>> entityMap) {
|
||||
return entityMap.entrySet().stream()
|
||||
.map(entry -> DefaultPasteUtil.setEntity(island, entry.getKey(), entry.getValue()))
|
||||
.collect(Collectors.collectingAndThen(Collectors.toList(),
|
||||
list -> CompletableFuture.allOf(list.toArray(new CompletableFuture[0]))));
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the block to the location
|
||||
*
|
||||
* @param island - island
|
||||
* @param location - location
|
||||
* @param bpBlock - blueprint block
|
||||
*/
|
||||
public static CompletableFuture<Void> setBlock(Island island, Location location, BlueprintBlock bpBlock) {
|
||||
return Util.getChunkAtAsync(location).thenRun(() -> {
|
||||
Block block = location.getBlock();
|
||||
// Set the block data - default is AIR
|
||||
BlockData bd = DefaultPasteUtil.createBlockData(bpBlock);
|
||||
CraftBlockData craft = (CraftBlockData) bd;
|
||||
net.minecraft.world.level.World nmsWorld = ((CraftWorld) location.getWorld()).getHandle();
|
||||
Chunk nmsChunk = nmsWorld.d(location.getBlockX() >> 4, location.getBlockZ() >> 4);
|
||||
BlockPosition bp = new BlockPosition(location.getBlockX(), location.getBlockY(), location.getBlockZ());
|
||||
// Setting the block to air before setting to another state prevents some console errors
|
||||
nmsChunk.a(bp, AIR, false);
|
||||
nmsChunk.a(bp, craft.getState(), false);
|
||||
block.setBlockData(bd, false);
|
||||
DefaultPasteUtil.setBlockState(island, block, bpBlock);
|
||||
// Set biome
|
||||
if (bpBlock.getBiome() != null) {
|
||||
block.setBiome(bpBlock.getBiome());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -0,0 +1,31 @@
|
||||
package world.bentobox.bentobox.nms.v1_20_R2;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Material;
|
||||
import org.bukkit.block.data.BlockData;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_20_R2.block.data.CraftBlockData;
|
||||
|
||||
import net.minecraft.core.BlockPosition;
|
||||
import net.minecraft.world.level.World;
|
||||
import net.minecraft.world.level.block.state.IBlockData;
|
||||
import net.minecraft.world.level.chunk.Chunk;
|
||||
import world.bentobox.bentobox.nms.CopyWorldRegenerator;
|
||||
|
||||
public class WorldRegeneratorImpl extends CopyWorldRegenerator {
|
||||
|
||||
private static final IBlockData AIR = ((CraftBlockData) Bukkit.createBlockData(Material.AIR)).getState();
|
||||
|
||||
@Override
|
||||
public void setBlockInNativeChunk(org.bukkit.Chunk chunk, int x, int y, int z, BlockData blockData,
|
||||
boolean applyPhysics) {
|
||||
CraftBlockData craft = (CraftBlockData) blockData;
|
||||
World nmsWorld = ((CraftWorld) chunk.getWorld()).getHandle();
|
||||
Chunk nmsChunk = nmsWorld.d(chunk.getX(), chunk.getZ());
|
||||
BlockPosition bp = new BlockPosition((chunk.getX() << 4) + x, y, (chunk.getZ() << 4) + z);
|
||||
// Setting the block to air before setting to another state prevents some console errors
|
||||
nmsChunk.a(bp, AIR, applyPhysics);
|
||||
nmsChunk.a(bp, craft.getState(), applyPhysics);
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user