mirror of
https://github.com/plexusorg/Plex-FAWE.git
synced 2024-12-22 17:27:38 +00:00
Update Upstream
b1c230d Add conditional checking in help command (1888) b4fbbc9 Move clearable checks for Bukkit to adapters (1887)
This commit is contained in:
parent
cdc3abbc43
commit
d236470df8
@ -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;
|
||||
|
@ -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());
|
||||
|
Binary file not shown.
@ -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() {
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user