Remove all raw usages of BSH, improve API generics

This commit is contained in:
Kenzie Togami
2018-12-26 16:39:10 -08:00
committed by IronApollo
parent 1d87642b52
commit 590b7e23a9
105 changed files with 372 additions and 347 deletions

View File

@ -146,8 +146,8 @@ public enum BukkitAdapter {
return getAdapter().adapt(material);
}
public static BlockData adapt(BlockStateHolder block) {
return getAdapter().adapt(block);
public static <B extends BlockStateHolder<B>> BlockData adapt(B block) {
return getAdapter().adapt(block);
}
public static BlockData getBlockData(int combinedId) {

View File

@ -290,4 +290,22 @@ public class BukkitPlayer extends AbstractPlayerActor {
}
@Override
public <B extends BlockStateHolder<B>> void sendFakeBlock(BlockVector3 pos, B block) {
Location loc = new Location(player.getWorld(), pos.getX(), pos.getY(), pos.getZ());
if (block == null) {
player.sendBlockChange(loc, player.getWorld().getBlockAt(loc).getBlockData());
} else {
player.sendBlockChange(loc, BukkitAdapter.adapt(block));
if (block instanceof BaseBlock && ((BaseBlock) block).hasNbtData()) {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
adapter.sendFakeNBT(player, pos, ((BaseBlock) block).getNbtData());
if (block.getBlockType() == BlockTypes.STRUCTURE_BLOCK) {
adapter.sendFakeOP(player);
}
}
}
}
}
}

View File

@ -452,7 +452,7 @@ public class BukkitWorld extends AbstractWorld {
}
@Override
public boolean setBlock(BlockVector3 position, BlockStateHolder block, boolean notifyAndLight) throws WorldEditException {
public <B extends BlockStateHolder<B>> boolean setBlock(BlockVector3 position, B block, boolean notifyAndLight) throws WorldEditException {
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
try {

View File

@ -22,15 +22,10 @@ package com.sk89q.worldedit.bukkit.adapter;
import com.sk89q.jnbt.Tag;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.worldedit.world.block.BaseBlock;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.entity.Player;
import com.sk89q.worldedit.math.BlockVector3;
import com.sk89q.worldedit.registry.state.Property;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.world.block.BlockStateHolder;
import com.sk89q.worldedit.world.block.BlockState;
import com.sk89q.worldedit.entity.BaseEntity;
import com.sk89q.worldedit.world.block.BlockType;
import com.sk89q.worldedit.world.registry.BlockMaterial;
@ -38,6 +33,7 @@ import org.bukkit.Chunk;
import org.bukkit.Location;
import org.bukkit.block.Biome;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import java.util.Map;
@ -76,9 +72,18 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
*/
BlockState getBlock(Location location);
boolean setBlock(Chunk chunk, int x, int y, int z, BlockStateHolder state, boolean update);
boolean setBlock(Chunk chunk, int x, int y, int z, BlockStateHolder<?> state, boolean update);
boolean isChunkInUse(Chunk chunk);
/**
* Set the block at the given location.
*
* @param location the location
* @param state the block
* @param notifyAndLight notify and light if set
* @return true if a block was likely changed
*/
boolean setBlock(Location location, BlockStateHolder<?> state, boolean notifyAndLight);
/**
* Notifies the simulation that the block at the given location has
@ -114,20 +119,12 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
* @param blockType The block type
* @return The properties map
*/
Map<String, ? extends Property> getProperties(BlockType blockType);
Map<String, ? extends Property<?>> getProperties(BlockType blockType);
default BlockMaterial getMaterial(BlockType blockType) {
return null;
}
/**
* Send the given NBT data to the player.
*
* @param player The player
* @param pos The position
* @param nbtData The NBT Data
*/
void sendFakeNBT(Player player, BlockVector3 pos, CompoundTag nbtData);
default BlockMaterial getMaterial(BlockState blockState) {
return null;
}
@ -139,4 +136,21 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
default T fromNative(Tag foreign) {
return null;
}
/**
* Send the given NBT data to the player.
*
* @param player The player
* @param pos The position
* @param nbtData The NBT Data
*/
void sendFakeNBT(Player player, BlockVector3 pos, CompoundTag nbtData);
/**
* Make the client think it has operator status.
* This does not give them any operator capabilities.
*
* @param player The player
*/
void sendFakeOP(Player player);
}