Update Upstream

b1c230d Add conditional checking in help command (1888)
b4fbbc9 Move clearable checks for Bukkit to adapters (1887)
Dieser Commit ist enthalten in:
NotMyFault 2021-09-04 10:31:31 +02:00
Ursprung cdc3abbc43
Commit d236470df8
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: 158F5701A6AAD00C
4 geänderte Dateien mit 29 neuen und 33 gelöschten Zeilen

Datei anzeigen

@ -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;

Datei anzeigen

@ -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());

Datei anzeigen

@ -30,6 +30,9 @@ import com.sk89q.worldedit.util.formatting.component.InvalidComponentException;
import com.sk89q.worldedit.util.formatting.text.TextComponent;
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;
@ -48,6 +51,9 @@ import static java.util.stream.Collectors.toList;
// Stored in a separate class to prevent import conflicts, and because it's aliased via /we help.
public class PrintCommandHelp {
private PrintCommandHelp() {
}
private static Command detectCommand(CommandManager manager, String command) {
Optional<Command> mapping;
@ -140,8 +146,12 @@ public class PrintCommandHelp {
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());
@ -166,7 +176,4 @@ public class PrintCommandHelp {
actor.print(box.create(page));
}
private PrintCommandHelp() {
}
}