Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/version/7.2.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
me4502 committed Sep 5, 2021
2 parents bb9cd57 + b4fbbc9 commit f135011
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@
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;

Expand Down Expand Up @@ -223,37 +222,18 @@ public boolean regenerate(Region region, Extent extent, RegenOptions options) {
}
}

/**
* 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;
}
Expand All @@ -267,7 +247,7 @@ public boolean clearContainerBlockContents(BlockVector3 pt) {
InventoryHolder chest = (InventoryHolder) state;
Inventory inven = chest.getInventory();
if (chest instanceof Chest) {
inven = getBlockInventory((Chest) chest);
inven = ((Chest) chest).getBlockInventory();
}
inven.clear();
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,15 @@ default OptionalInt getInternalBlockStateId(BlockState state) {
default boolean regenerate(World world, Region region, Extent extent, RegenOptions options) {
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.");
}
}
Binary file modified worldedit-bukkit/src/main/resources/worldedit-adapters.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
import com.sk89q.worldedit.util.formatting.text.TranslatableComponent;
import org.enginehub.piston.Command;
import org.enginehub.piston.CommandManager;
import org.enginehub.piston.inject.InjectedValueStore;
import org.enginehub.piston.inject.Key;
import org.enginehub.piston.inject.MapBackedValueStore;

import java.util.ArrayList;
import java.util.List;
Expand Down Expand Up @@ -128,8 +131,13 @@ private static String toCommandString(List<Command> visited) {

private static void printCommands(int page, Stream<Command> commandStream, Actor actor,
List<Command> commandList, String helpRootCommand) throws InvalidComponentException {
InjectedValueStore store = MapBackedValueStore.create();
store.injectValue(Key.of(Actor.class), context ->
Optional.of(actor));

// Get a list of aliases
List<Command> commands = commandStream
.filter(command -> command.getCondition().satisfied(store))
.sorted(byCleanName())
.collect(toList());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,6 @@ public int getBlockLightLevel(BlockVector3 position) {
@Override
public boolean clearContainerBlockContents(BlockVector3 position) {
checkNotNull(position);
if (!getBlock(position).getBlockType().getMaterial().hasContainer()) {
return false;
}

BlockEntity tile = getWorld().getBlockEntity(FabricAdapter.toBlockPos(position));
if ((tile instanceof Clearable)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,6 @@ public int getBlockLightLevel(BlockVector3 position) {
@Override
public boolean clearContainerBlockContents(BlockVector3 position) {
checkNotNull(position);
if (!getBlock(position).getBlockType().getMaterial().hasContainer()) {
return false;
}

BlockEntity tile = getWorld().getBlockEntity(ForgeAdapter.toBlockPos(position));
if (tile instanceof Clearable) {
Expand Down

0 comments on commit f135011

Please sign in to comment.