use of com.sk89q.worldedit.blocks.BaseItemStack in project FastAsyncWorldEdit by IntellectualSites.
the class SelectionCommands method wand.
@Command(name = "/wand", desc = "Get the wand object")
@CommandPermissions("worldedit.wand")
public void wand(Player player, LocalSession session, @Switch(name = 'n', desc = "Get a navigation wand") boolean navWand) throws WorldEditException {
// FAWE start
session.loadDefaults(player, true);
// FAWE end
String wandId = navWand ? session.getNavWandItem() : session.getWandItem();
if (wandId == null) {
wandId = navWand ? we.getConfiguration().navigationWand : we.getConfiguration().wandItem;
}
ItemType itemType = ItemTypes.parse(wandId);
if (itemType == null) {
player.print(Caption.of("worldedit.wand.invalid"));
return;
}
player.giveItem(new BaseItemStack(itemType, 1));
// FAWE start - instance-iate session
if (navWand) {
session.setTool(itemType, NavigationWand.INSTANCE);
player.print(Caption.of("worldedit.wand.navwand.info"));
} else {
session.setTool(itemType, SelectionWand.INSTANCE);
player.print(Caption.of("worldedit.wand.selwand.info"));
// FAWE end
}
}
use of com.sk89q.worldedit.blocks.BaseItemStack in project FastAsyncWorldEdit by IntellectualSites.
the class PaperweightAdapter method adapt.
@Override
public BaseItemStack adapt(org.bukkit.inventory.ItemStack itemStack) {
final ItemStack nmsStack = CraftItemStack.asNMSCopy(itemStack);
final BaseItemStack weStack = new BaseItemStack(BukkitAdapter.asItemType(itemStack.getType()), itemStack.getAmount());
weStack.setNbt(((CompoundBinaryTag) toNativeBinary(nmsStack.getTag())));
return weStack;
}
use of com.sk89q.worldedit.blocks.BaseItemStack in project FastAsyncWorldEdit by IntellectualSites.
the class BukkitPlayerBlockBag method setItem.
@Override
public void setItem(int slot, BaseItem block) {
loadInventory();
BaseItemStack stack = block instanceof BaseItemStack ? (BaseItemStack) block : new BaseItemStack(block.getType(), block.getNbtData(), 1);
items[slot] = BukkitAdapter.adapt(stack);
}
use of com.sk89q.worldedit.blocks.BaseItemStack in project FastAsyncWorldEdit by IntellectualSites.
the class BukkitPlayerBlockBag method storeBlock.
@Override
public void storeBlock(BlockState blockState, int amount) throws BlockBagException {
if (blockState.getBlockType().getMaterial().isAir()) {
throw new IllegalArgumentException("Can't store air block");
}
if (!blockState.getBlockType().hasItemType()) {
throw new IllegalArgumentException("This block cannot be stored");
}
loadInventory();
int freeSlot = -1;
for (int slot = 0; slot < items.length; ++slot) {
ItemStack bukkitItem = items[slot];
if (bukkitItem == null) {
if (freeSlot == -1) {
freeSlot = slot;
}
continue;
}
if (!BukkitAdapter.equals(blockState.getBlockType(), bukkitItem.getType())) {
// Type id doesn't fit
continue;
}
int currentAmount = bukkitItem.getAmount();
if (currentAmount < 0) {
// Unlimited
return;
}
if (currentAmount >= 64) {
// Full stack
continue;
}
int spaceLeft = 64 - currentAmount;
if (spaceLeft >= amount) {
bukkitItem.setAmount(currentAmount + amount);
return;
}
bukkitItem.setAmount(64);
amount -= spaceLeft;
}
if (freeSlot > -1) {
items[freeSlot] = BukkitAdapter.adapt(new BaseItemStack(blockState.getBlockType().getItemType(), amount));
return;
}
throw new OutOfSpaceException(blockState.getBlockType());
}
use of com.sk89q.worldedit.blocks.BaseItemStack in project FastAsyncWorldEdit by IntellectualSites.
the class BukkitPlayer method giveItem.
// FAWE start
@Override
public void giveItem(BaseItemStack itemStack) {
final PlayerInventory inv = player.getInventory();
ItemStack newItem = BukkitAdapter.adapt(itemStack);
if (itemStack.getType().getId().equalsIgnoreCase(WorldEdit.getInstance().getConfiguration().wandItem)) {
inv.remove(newItem);
}
final ItemStack item = player.getInventory().getItemInMainHand();
player.getInventory().setItemInMainHand(newItem);
HashMap<Integer, ItemStack> overflow = inv.addItem(item);
if (!overflow.isEmpty()) {
TaskManager.taskManager().sync(new RunnableVal<>() {
@Override
public void run(Object value) {
for (Map.Entry<Integer, ItemStack> entry : overflow.entrySet()) {
ItemStack stack = entry.getValue();
if (stack.getType() != Material.AIR && stack.getAmount() > 0) {
Item dropped = player.getWorld().dropItem(player.getLocation(), stack);
PlayerDropItemEvent event = new PlayerDropItemEvent(player, dropped);
Bukkit.getPluginManager().callEvent(event);
if (event.isCancelled()) {
dropped.remove();
}
}
}
}
});
}
player.updateInventory();
}
Aggregations