/* * This file is part of LanternServer, licensed under the MIT License (MIT). * * Copyright (c) LanternPowered <https://www.lanternpowered.org> * Copyright (c) SpongePowered <https://www.spongepowered.org> * Copyright (c) contributors * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the Software), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED AS IS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ package org.lanternpowered.server.command.test; import static org.lanternpowered.server.text.translation.TranslationHelper.t; import org.lanternpowered.server.command.CommandProvider; import org.lanternpowered.server.data.key.LanternKeys; import org.lanternpowered.server.inventory.InventorySnapshot; import org.lanternpowered.server.inventory.LanternItemStack; import org.lanternpowered.server.inventory.block.ChestInventory; import org.spongepowered.api.block.BlockTypes; import org.spongepowered.api.command.CommandException; import org.spongepowered.api.command.CommandResult; import org.spongepowered.api.command.spec.CommandSpec; import org.spongepowered.api.data.key.Keys; import org.spongepowered.api.data.meta.ItemEnchantment; import org.spongepowered.api.data.type.CoalTypes; import org.spongepowered.api.data.type.TreeTypes; import org.spongepowered.api.entity.living.player.Player; import org.spongepowered.api.event.cause.Cause; import org.spongepowered.api.item.Enchantments; import org.spongepowered.api.item.ItemTypes; import org.spongepowered.api.item.inventory.ItemStack; import org.spongepowered.api.plugin.PluginContainer; import org.spongepowered.api.text.Text; import org.spongepowered.api.util.annotation.NonnullByDefault; import java.util.Collections; @NonnullByDefault public class CommandOpenTestContainer extends CommandProvider { public CommandOpenTestContainer() { super(2, "test-container"); } @Override public void completeSpec(PluginContainer pluginContainer, CommandSpec.Builder specBuilder) { specBuilder .executor((src, args) -> { if (!(src instanceof Player)) { throw new CommandException(t("Only players may use this command.")); } final ChestInventory inventory = new ChestInventory(null, 2); inventory.offer(new LanternItemStack(BlockTypes.BEDROCK, 64)); inventory.offer(new LanternItemStack(BlockTypes.GLASS, 64)); inventory.offer(new LanternItemStack(BlockTypes.STONE, 64)); inventory.offer(new LanternItemStack(BlockTypes.SAND, 64)); inventory.offer(new LanternItemStack(BlockTypes.DIRT, 64)); inventory.offer(new LanternItemStack(BlockTypes.GRASS, 64)); inventory.offer(new LanternItemStack(BlockTypes.PLANKS, 64)); inventory.offer(new LanternItemStack(BlockTypes.LOG, 64)); inventory.offer(new LanternItemStack(BlockTypes.LOG2, 64)); inventory.offer(new LanternItemStack(BlockTypes.SAPLING, 64)); inventory.offer(new LanternItemStack(BlockTypes.STONE_SLAB, 64)); inventory.offer(new LanternItemStack(BlockTypes.STONE_SLAB2, 64)); inventory.offer(new LanternItemStack(BlockTypes.ENDER_CHEST, 5)); inventory.offer(new LanternItemStack(BlockTypes.CHEST, 5)); inventory.offer(createShulkerBox()); LanternItemStack itemStack = new LanternItemStack(ItemTypes.COAL, 51); itemStack.offer(Keys.COAL_TYPE, CoalTypes.CHARCOAL); inventory.offer(itemStack.copy()); itemStack.offer(Keys.DISPLAY_NAME, Text.of("Awesome Charcoal")); itemStack.offer(Keys.ITEM_ENCHANTMENTS, Collections.singletonList(new ItemEnchantment(Enchantments.POWER, 2))); inventory.offer(itemStack); itemStack = new LanternItemStack(ItemTypes.LOG, 64); itemStack.offer(Keys.TREE_TYPE, TreeTypes.JUNGLE); inventory.offer(itemStack); ((Player) src).openInventory(inventory, Cause.source(src).build()); return CommandResult.success(); }); } private static ItemStack createShulkerBox() { final ChestInventory inventory = new ChestInventory(null, 1); inventory.offer(new LanternItemStack(BlockTypes.REDSTONE_BLOCK, 64)); inventory.offer(new LanternItemStack(BlockTypes.HOPPER, 64)); // Create the pumpkin stacks LanternItemStack itemStack = new LanternItemStack(BlockTypes.LIT_PUMPKIN, 20); inventory.offer(itemStack); // Create the shulker box itemStack = new LanternItemStack(BlockTypes.BLACK_SHULKER_BOX); itemStack.tryOffer(LanternKeys.INVENTORY_SNAPSHOT, InventorySnapshot.ofInventory(inventory)); return itemStack; } }