Update Upstream

b1c230d Add conditional checking in help command (1888)
b4fbbc9 Move clearable checks for Bukkit to adapters (1887)
This commit is contained in:
NotMyFault
2021-09-04 10:31:31 +02:00
parent cdc3abbc43
commit d236470df8
4 changed files with 29 additions and 33 deletions

View File

@ -61,7 +61,6 @@ import org.bukkit.block.Block;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.entity.Entity;
import org.bukkit.inventory.DoubleChestInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
@ -242,37 +241,16 @@ public class BukkitWorld extends AbstractWorld {
}
}
/**
* Gets the single block inventory for a potentially double chest.
* Handles people who have an old version of Bukkit.
* This should be replaced with {@link org.bukkit.block.Chest#getBlockInventory()}
* in a few months (now = March 2012) // note from future dev - lol
*
* @param chest The chest to get a single block inventory for
* @return The chest's inventory
*/
private Inventory getBlockInventory(Chest chest) {
try {
return chest.getBlockInventory();
} catch (Throwable t) {
if (chest.getInventory() instanceof DoubleChestInventory) {
DoubleChestInventory inven = (DoubleChestInventory) chest.getInventory();
if (inven.getLeftSide().getHolder().equals(chest)) {
return inven.getLeftSide();
} else if (inven.getRightSide().getHolder().equals(chest)) {
return inven.getRightSide();
} else {
return inven;
}
} else {
return chest.getInventory();
}
}
}
@Override
public boolean clearContainerBlockContents(BlockVector3 pt) {
checkNotNull(pt);
BukkitImplAdapter adapter = WorldEditPlugin.getInstance().getBukkitImplAdapter();
if (adapter != null) {
try {
return adapter.clearContainerBlockContents(getWorld(), pt);
} catch (Exception ignored) {
}
}
if (!getBlock(pt).getBlockType().getMaterial().hasContainer()) {
return false;
}
@ -286,7 +264,7 @@ public class BukkitWorld extends AbstractWorld {
InventoryHolder chest = (InventoryHolder) state;
Inventory inven = chest.getInventory();
if (chest instanceof Chest) {
inven = getBlockInventory((Chest) chest);
inven = ((Chest) chest).getBlockInventory();
}
inven.clear();
return true;

View File

@ -258,6 +258,17 @@ public interface BukkitImplAdapter<T> extends IBukkitAdapter {
throw new UnsupportedOperationException("This adapter does not support regeneration.");
}
/**
* Clears the contents of a Clearable block.
*
* @param world The world
* @param pt The location
* @return If a block was cleared
*/
default boolean clearContainerBlockContents(World world, BlockVector3 pt) {
throw new UnsupportedOperationException("This adapter does not support clearing block contents.");
}
//FAWE start
default BlockMaterial getMaterial(BlockType blockType) {
return getMaterial(blockType.getDefaultState());