Search in sources :

Example 1 with Container

use of org.spongepowered.api.item.inventory.Container in project RedProtect by FabioZumbi12.

the class RPPlayerListener method onInteractBlock.

// listen all
@Listener(order = Order.FIRST, beforeModifications = true)
public void onInteractBlock(InteractBlockEvent event, @First Player p) {
    RedProtect.get().logger.debug("player", "RPPlayerListener - InteractBlockEvent canceled? " + event.isCancelled());
    BlockSnapshot b = event.getTargetBlock();
    BlockState bstate = b.getState();
    Location<World> l = null;
    if (!b.getState().getType().equals(BlockTypes.AIR)) {
        l = b.getLocation().get();
        RedProtect.get().logger.debug("player", "RPPlayerListener - Is InteractBlockEvent event. The block is " + bstate.getType().getName());
    } else {
        l = p.getLocation();
    }
    Region r = RedProtect.get().rm.getTopRegion(l);
    ItemType itemInHand = ItemTypes.NONE;
    ItemStack stack = ItemStack.of(ItemTypes.NONE, 1);
    if (p.getItemInHand(HandTypes.MAIN_HAND).isPresent()) {
        stack = p.getItemInHand(HandTypes.MAIN_HAND).get();
        itemInHand = stack.getItem();
        if (RPUtil.removeGuiItem(stack)) {
            p.setItemInHand(HandTypes.MAIN_HAND, ItemStack.of(ItemTypes.NONE, 1));
            event.setCancelled(true);
        }
    } else if (p.getItemInHand(HandTypes.OFF_HAND).isPresent()) {
        stack = p.getItemInHand(HandTypes.OFF_HAND).get();
        itemInHand = stack.getItem();
        if (RPUtil.removeGuiItem(stack)) {
            p.setItemInHand(HandTypes.OFF_HAND, ItemStack.of(ItemTypes.NONE, 1));
            event.setCancelled(true);
        }
    }
    if (itemInHand.getId().equalsIgnoreCase(RedProtect.get().cfgs.getString("wands.infoWandID"))) {
        r = RedProtect.get().rm.getTopRegion(l);
        if (RedProtect.get().ph.hasUserPerm(p, "RedProtect.get().infowand")) {
            if (r == null) {
                RPLang.sendMessage(p, "playerlistener.noregion.atblock");
            } else if (r.canBuild(p)) {
                p.sendMessage(RPUtil.toText(RPLang.get("general.color") + "--------------- [&e" + r.getName() + RPLang.get("general.color") + "] ---------------"));
                p.sendMessage(r.info());
                p.sendMessage(RPUtil.toText(RPLang.get("general.color") + "-----------------------------------------"));
            } else {
                p.sendMessage(RPUtil.toText(RPLang.get("playerlistener.region.entered").replace("{region}", r.getName()).replace("{leaders}", RPUtil.UUIDtoPlayer(r.getLeadersDesc()))));
            }
            event.setCancelled(true);
            return;
        }
    }
    // start player checks
    if (r == null) {
        if (b != null && (bstate instanceof Container || RedProtect.get().cfgs.getStringList("private.allowed-blocks").contains(bstate.getType().getName()))) {
            Boolean out = RedProtect.get().cfgs.getBool("private.allow-outside");
            if (out && !cont.canOpen(b, p)) {
                if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
                    RPLang.sendMessage(p, "playerlistener.region.cantopen");
                    event.setCancelled(true);
                } else {
                    int x = b.getLocation().get().getBlockX();
                    int y = b.getLocation().get().getBlockY();
                    int z = b.getLocation().get().getBlockZ();
                    RPLang.sendMessage(p, RPLang.get("playerlistener.region.opened").replace("{region}", "X:" + x + " Y:" + y + " Z:" + z));
                }
            }
        }
    } else {
        // if (r != null) && (b != null) >>
        if (b != null) {
            if (bstate.getType().equals(BlockTypes.DRAGON_EGG) || bstate.getType().equals(BlockTypes.BED) || bstate.getType().equals(BlockTypes.NOTEBLOCK) || bstate.getType().getName().contains("repeater") || bstate.getType().getName().contains("comparator")) {
                if (!r.canBuild(p)) {
                    RPLang.sendMessage(p, "playerlistener.region.cantinteract");
                    event.setCancelled(true);
                }
            } else if ((b.getState() instanceof Carrier) || RedProtect.get().cfgs.getStringList("private.allowed-blocks").contains(bstate.getType().getName())) {
                if ((r.canChest(p) && !cont.canOpen(b, p) || (!r.canChest(p) && cont.canOpen(b, p)) || (!r.canChest(p) && !cont.canOpen(b, p)))) {
                    if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
                        RPLang.sendMessage(p, "playerlistener.region.cantopen");
                        event.setCancelled(true);
                    } else {
                        RPLang.sendMessage(p, RPLang.get("playerlistener.region.opened").replace("{region}", RPUtil.UUIDtoPlayer(r.getLeadersDesc())));
                    }
                }
            } else if (bstate.getType().getName().contains("lever")) {
                if (!r.canLever(p)) {
                    if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
                        RPLang.sendMessage(p, "playerlistener.region.cantlever");
                        event.setCancelled(true);
                    } else {
                        RPLang.sendMessage(p, RPLang.get("playerlistener.region.levertoggled").replace("{region}", RPUtil.UUIDtoPlayer(r.getLeadersDesc())));
                    }
                }
            } else if (bstate.getType().getName().contains("button")) {
                if (!r.canButton(p)) {
                    if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
                        RPLang.sendMessage(p, "playerlistener.region.cantbutton");
                        event.setCancelled(true);
                    } else {
                        RPLang.sendMessage(p, RPLang.get("playerlistener.region.buttonactivated").replace("{region}", RPUtil.UUIDtoPlayer(r.getLeadersDesc())));
                    }
                }
            } else if (RPDoor.isOpenable(b)) {
                if (!r.canDoor(p)) /* || (r.canDoor(p) && !cont.canOpen(b, p))*/
                {
                    if (!RedProtect.get().ph.hasPerm(p, "RedProtect.get().bypass")) {
                        RPLang.sendMessage(p, "playerlistener.region.cantdoor");
                        event.setCancelled(true);
                    } else {
                        RPLang.sendMessage(p, "playerlistener.region.opendoor");
                        RPDoor.ChangeDoor(b, r);
                    }
                } else {
                    RPDoor.ChangeDoor(b, r);
                }
            } else if (bstate.getType().getName().contains("rail")) {
                if (!r.canMinecart(p)) {
                    RPLang.sendMessage(p, "blocklistener.region.cantplace");
                    event.setCancelled(true);
                }
            } else if (bstate.getType().getName().contains("sign") && !r.canSign(p)) {
                if (b.get(Keys.SIGN_LINES).isPresent()) {
                    List<Text> sign = b.get(Keys.SIGN_LINES).get();
                    for (String tag : RedProtect.get().cfgs.getStringList("region-settings.allow-sign-interact-tags")) {
                        // check first rule
                        if (tag.equalsIgnoreCase(sign.get(0).toPlain())) {
                            return;
                        }
                        // check if tag is leaders or members names
                        if (tag.equalsIgnoreCase("{membername}")) {
                            for (String leader : r.getLeaders()) {
                                if (sign.get(0).toPlain().equalsIgnoreCase(RPUtil.UUIDtoPlayer(leader))) {
                                    return;
                                }
                            }
                            for (String member : r.getMembers()) {
                                if (sign.get(0).toPlain().equalsIgnoreCase(RPUtil.UUIDtoPlayer(member))) {
                                    return;
                                }
                            }
                            for (String admin : r.getAdmins()) {
                                if (sign.get(0).toPlain().equalsIgnoreCase(RPUtil.UUIDtoPlayer(admin))) {
                                    return;
                                }
                            }
                        }
                        // check if tag is player name
                        if (tag.equalsIgnoreCase("{playername}")) {
                            if (sign.get(0).toPlain().equalsIgnoreCase(RPUtil.UUIDtoPlayer(p.getName()))) {
                                return;
                            }
                        }
                    }
                }
                RPLang.sendMessage(p, "playerlistener.region.cantinteract.signs");
                event.setCancelled(true);
            } else if ((itemInHand.equals(ItemTypes.FLINT_AND_STEEL) || itemInHand.equals(ItemTypes.WATER_BUCKET) || itemInHand.equals(ItemTypes.BUCKET) || itemInHand.equals(ItemTypes.LAVA_BUCKET) || itemInHand.equals(ItemTypes.ITEM_FRAME) || itemInHand.equals(ItemTypes.PAINTING)) && !r.canBuild(p)) {
                RPLang.sendMessage(p, RPLang.get("playerlistener.region.cantuse"));
                event.setCancelled(true);
            } else if (!r.allowMod(p) && !RPUtil.isBukkitBlock(bstate)) {
                RPLang.sendMessage(p, "playerlistener.region.cantinteract");
                event.setCancelled(true);
            }
        }
    }
}
Also used : ItemType(org.spongepowered.api.item.ItemType) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Text(org.spongepowered.api.text.Text) World(org.spongepowered.api.world.World) RPContainer(br.net.fabiozumbi12.RedProtect.Sponge.RPContainer) Container(org.spongepowered.api.item.inventory.Container) BlockState(org.spongepowered.api.block.BlockState) Region(br.net.fabiozumbi12.RedProtect.Sponge.Region) Carrier(org.spongepowered.api.item.inventory.Carrier) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Listener(org.spongepowered.api.event.Listener)

Example 2 with Container

use of org.spongepowered.api.item.inventory.Container in project Nucleus by NucleusPowered.

the class KitEditCommand method executeCommand.

@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
    final Kit kitInfo = args.<Kit>getOne(KIT_PARAMETER).get();
    if (KIT_HANDLER.isOpen(kitInfo.getName())) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.edit.current", kitInfo.getName()));
    }
    Inventory inventory = Util.getKitInventoryBuilder().property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.edit.title", kitInfo.getName()))).build(plugin);
    kitInfo.getStacks().stream().filter(x -> !x.getType().equals(ItemTypes.NONE)).forEach(x -> inventory.offer(x.createStack()));
    Optional<Container> openedInventory = src.openInventory(inventory);
    if (openedInventory.isPresent()) {
        KIT_HANDLER.addKitInventoryToListener(Tuple.of(kitInfo, inventory), openedInventory.get());
        return CommandResult.success();
    }
    throw ReturnMessageException.fromKey("command.kit.edit.cantopen", kitInfo.getName());
}
Also used : Inventory(org.spongepowered.api.item.inventory.Inventory) RegisterCommand(io.github.nucleuspowered.nucleus.internal.annotations.command.RegisterCommand) ItemTypes(org.spongepowered.api.item.ItemTypes) Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit) NonnullByDefault(org.spongepowered.api.util.annotation.NonnullByDefault) Since(io.github.nucleuspowered.nucleus.internal.annotations.Since) KitFallbackBase(io.github.nucleuspowered.nucleus.modules.kit.commands.KitFallbackBase) GenericArguments(org.spongepowered.api.command.args.GenericArguments) CommandContext(org.spongepowered.api.command.args.CommandContext) Text(org.spongepowered.api.text.Text) SuggestedLevel(io.github.nucleuspowered.nucleus.internal.permissions.SuggestedLevel) Util(io.github.nucleuspowered.nucleus.Util) Permissions(io.github.nucleuspowered.nucleus.internal.annotations.command.Permissions) NoModifiers(io.github.nucleuspowered.nucleus.internal.annotations.command.NoModifiers) CommandResult(org.spongepowered.api.command.CommandResult) KitHandler(io.github.nucleuspowered.nucleus.modules.kit.handlers.KitHandler) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) Tuple(org.spongepowered.api.util.Tuple) InventoryTitle(org.spongepowered.api.item.inventory.property.InventoryTitle) CommandElement(org.spongepowered.api.command.args.CommandElement) AbstractCommand(io.github.nucleuspowered.nucleus.internal.command.AbstractCommand) Container(org.spongepowered.api.item.inventory.Container) Optional(java.util.Optional) Player(org.spongepowered.api.entity.living.player.Player) KitArgument(io.github.nucleuspowered.nucleus.argumentparsers.KitArgument) Container(org.spongepowered.api.item.inventory.Container) Kit(io.github.nucleuspowered.nucleus.api.nucleusdata.Kit) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) Inventory(org.spongepowered.api.item.inventory.Inventory)

Example 3 with Container

use of org.spongepowered.api.item.inventory.Container in project Nucleus by NucleusPowered.

the class InvSeeCommand method executeCommand.

@Override
public CommandResult executeCommand(Player src, CommandContext args) throws Exception {
    User target = args.<User>getOne(player).get();
    if (!target.isOnline() && !permissions.testSuffix(src, "offline")) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.invsee.nooffline"));
    }
    if (!this.self && target.getUniqueId().equals(src.getUniqueId())) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.invsee.self"));
    }
    if (permissions.testSuffix(target, "exempt.target", src, false)) {
        throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.invsee.targetexempt", target.getName()));
    }
    // Just in case, get the subject inventory if they are online.
    try {
        Inventory targetInv = target.isOnline() ? target.getPlayer().get().getInventory() : target.getInventory();
        Optional<Container> oc = src.openInventory(targetInv);
        if (oc.isPresent()) {
            if (!permissions.testSuffix(src, "modify") || permissions.testSuffix(target, "exempt.interact")) {
                InvSeeListener.addEntry(src.getUniqueId(), oc.get());
            }
            return CommandResult.success();
        }
        throw ReturnMessageException.fromKey("command.invsee.failed");
    } catch (UnsupportedOperationException e) {
        throw ReturnMessageException.fromKey("command.invsee.offlinenotsupported");
    }
}
Also used : Container(org.spongepowered.api.item.inventory.Container) User(org.spongepowered.api.entity.living.player.User) ReturnMessageException(io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException) Inventory(org.spongepowered.api.item.inventory.Inventory)

Example 4 with Container

use of org.spongepowered.api.item.inventory.Container in project SpongeCommon by SpongePowered.

the class ContainerUtil method generateLens.

/**
 * Generates a fallback lens for given Container
 *
 * @param container The Container to generate a lens for
 * @param slots The slots of the Container
 * @return The generated fallback lens
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
private static Lens<IInventory, ItemStack> generateLens(net.minecraft.inventory.Container container, SlotProvider<IInventory, ItemStack> slots) {
    // Get all inventories viewed in the Container & count slots & retain order
    Map<Optional<IInventory>, List<Slot>> viewed = container.inventorySlots.stream().collect(Collectors.groupingBy(i -> Optional.<IInventory>ofNullable(i.inventory), LinkedHashMap::new, Collectors.toList()));
    // Count the index
    int index = 0;
    CraftingInventoryData crafting = new CraftingInventoryData();
    List<Lens<IInventory, ItemStack>> lenses = new ArrayList<>();
    for (Map.Entry<Optional<IInventory>, List<Slot>> entry : viewed.entrySet()) {
        List<Slot> slotList = entry.getValue();
        int slotCount = slotList.size();
        IInventory subInventory = entry.getKey().orElse(null);
        // Generate Lens based on existing InventoryAdapter
        Lens<IInventory, ItemStack> lens = generateAdapterLens(slots, index, crafting, slotList, subInventory);
        // Check if sub-inventory is LensProvider
        if (lens == null && subInventory instanceof LensProvider) {
            Fabric<IInventory> keyFabric = MinecraftFabric.of(subInventory);
            lens = ((LensProvider) subInventory).rootLens(keyFabric, new VanillaAdapter(keyFabric, container));
        }
        // Unknown Inventory or Inventory size <> Lens size
        if (lens == null || lens.slotCount() != slotCount) {
            if (subInventory instanceof InventoryCraftResult) {
                // InventoryCraftResult is a Slot
                Slot slot = slotList.get(0);
                lens = new CraftingOutputSlotLensImpl(index, item -> slot.isItemValid(((ItemStack) item)), itemType -> (slot.isItemValid((ItemStack) org.spongepowered.api.item.inventory.ItemStack.of(itemType, 1))));
            } else if (subInventory instanceof InventoryCrafting) {
                // InventoryCrafting has width and height and is Input
                InventoryCrafting craftGrid = (InventoryCrafting) subInventory;
                lens = new GridInventoryLensImpl(index, craftGrid.getWidth(), craftGrid.getHeight(), craftGrid.getWidth(), InputSlot.class, slots);
            } else if (slotCount == 1) {
                // Unknown - A single Slot
                lens = new SlotLensImpl(index);
            } else if (subInventory instanceof InventoryBasic && subInventory.getClass().isAnonymousClass()) {
                // Anonymous InventoryBasic -> Check for Vanilla Containers:
                switch(subInventory.getName()) {
                    // Container InputSlots
                    case "Enchant":
                    case // Container InputSlots
                    "Repair":
                        lens = new OrderedInventoryLensImpl(index, slotCount, 1, InputSlot.class, slots);
                        break;
                    default:
                        // Unknown
                        lens = new OrderedInventoryLensImpl(index, slotCount, 1, slots);
                }
            } else {
                // Unknown - fallback to OrderedInventory
                lens = new OrderedInventoryLensImpl(index, slotCount, 1, slots);
            }
        }
        lenses.add(lens);
        index += slotCount;
    }
    List<Lens<IInventory, ItemStack>> additional = new ArrayList<>();
    try {
        if (crafting.out != null && crafting.base != null && crafting.grid != null) {
            additional.add(new CraftingInventoryLensImpl(crafting.out, crafting.base, crafting.grid.getWidth(), crafting.grid.getHeight(), slots));
        }
    } catch (Exception e) {
        SpongeImpl.getLogger().error("Error while creating CraftingInventoryLensImpl for " + container.getClass().getName(), e);
    }
    // Lens containing/delegating to other lenses
    return new ContainerLens((InventoryAdapter<IInventory, ItemStack>) container, slots, lenses, additional);
}
Also used : MainPlayerInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.MainPlayerInventoryLensImpl) MinecraftFabric(org.spongepowered.common.item.inventory.lens.impl.MinecraftFabric) LargeChestInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.LargeChestInventoryLens) Random(java.util.Random) ContainerChest(net.minecraft.inventory.ContainerChest) ContainerWorkbench(net.minecraft.inventory.ContainerWorkbench) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) DelegatingLens(org.spongepowered.common.item.inventory.lens.impl.DelegatingLens) PhaseData(org.spongepowered.common.event.tracking.PhaseData) CustomContainer(org.spongepowered.common.item.inventory.custom.CustomContainer) BlockCarrier(org.spongepowered.api.item.inventory.BlockCarrier) Map(java.util.Map) InventoryArchetypes(org.spongepowered.api.item.inventory.InventoryArchetypes) AbstractChestHorse(net.minecraft.entity.passive.AbstractChestHorse) EntityItem(net.minecraft.entity.item.EntityItem) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) CraftingOutputSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.CraftingOutputSlotLensImpl) ContainerBeacon(net.minecraft.inventory.ContainerBeacon) Location(org.spongepowered.api.world.Location) InventoryAdapter(org.spongepowered.common.item.inventory.adapter.InventoryAdapter) InventoryHelper(net.minecraft.inventory.InventoryHelper) Collection(java.util.Collection) GridInventoryLens(org.spongepowered.common.item.inventory.lens.comp.GridInventoryLens) Carrier(org.spongepowered.api.item.inventory.Carrier) Collectors(java.util.stream.Collectors) SlotCrafting(net.minecraft.inventory.SlotCrafting) InventoryArchetype(org.spongepowered.api.item.inventory.InventoryArchetype) InventoryBasic(net.minecraft.inventory.InventoryBasic) BrewingStandInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.BrewingStandInventoryLens) List(java.util.List) ContainerLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.container.ContainerLens) PhaseContext(org.spongepowered.common.event.tracking.PhaseContext) CraftingOutputAdapter(org.spongepowered.common.item.inventory.adapter.impl.slots.CraftingOutputAdapter) EntityPlayer(net.minecraft.entity.player.EntityPlayer) ContainerDispenser(net.minecraft.inventory.ContainerDispenser) CarriedInventory(org.spongepowered.api.item.inventory.type.CarriedInventory) Lens(org.spongepowered.common.item.inventory.lens.Lens) Optional(java.util.Optional) MixinInventoryHelper(org.spongepowered.common.mixin.core.inventory.MixinInventoryHelper) LensProvider(org.spongepowered.common.item.inventory.lens.LensProvider) ContainerRepair(net.minecraft.inventory.ContainerRepair) PlayerInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.PlayerInventoryLens) ContainerMerchant(net.minecraft.inventory.ContainerMerchant) SpongeImpl(org.spongepowered.common.SpongeImpl) GridInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.GridInventoryLensImpl) AbstractHorse(net.minecraft.entity.passive.AbstractHorse) VanillaAdapter(org.spongepowered.common.item.inventory.adapter.impl.VanillaAdapter) SpongeImplHooks(org.spongepowered.common.SpongeImplHooks) ContainerHopper(net.minecraft.inventory.ContainerHopper) InventoryCraftResult(net.minecraft.inventory.InventoryCraftResult) Multimap(com.google.common.collect.Multimap) TileEntityChest(net.minecraft.tileentity.TileEntityChest) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) ItemStack(net.minecraft.item.ItemStack) InputSlot(org.spongepowered.api.item.inventory.slot.InputSlot) Inventory2DLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.Inventory2DLensImpl) ContainerEnchantment(net.minecraft.inventory.ContainerEnchantment) DefaultEmptyLens(org.spongepowered.common.item.inventory.lens.impl.DefaultEmptyLens) InventoryLargeChest(net.minecraft.inventory.InventoryLargeChest) ContainerFurnace(net.minecraft.inventory.ContainerFurnace) IMixinContainer(org.spongepowered.common.interfaces.IMixinContainer) ContainerBrewingStand(net.minecraft.inventory.ContainerBrewingStand) WorldServer(net.minecraft.world.WorldServer) Nullable(javax.annotation.Nullable) FurnaceInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.FurnaceInventoryLens) Fabric(org.spongepowered.common.item.inventory.lens.Fabric) Inventory2DLens(org.spongepowered.common.item.inventory.lens.comp.Inventory2DLens) SlotProvider(org.spongepowered.common.item.inventory.lens.SlotProvider) ContainerHorseInventory(net.minecraft.inventory.ContainerHorseInventory) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) IMixinSingleBlockCarrier(org.spongepowered.common.interfaces.IMixinSingleBlockCarrier) PhaseTracker(org.spongepowered.common.event.tracking.PhaseTracker) CraftingInventoryLens(org.spongepowered.common.item.inventory.lens.comp.CraftingInventoryLens) CraftingInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.CraftingInventoryLensImpl) ContainerPlayer(net.minecraft.inventory.ContainerPlayer) Container(org.spongepowered.api.item.inventory.Container) SlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.SlotLensImpl) IInventory(net.minecraft.inventory.IInventory) Slot(net.minecraft.inventory.Slot) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) VecHelper(org.spongepowered.common.util.VecHelper) ItemDropData(org.spongepowered.common.event.tracking.context.ItemDropData) TileEntity(net.minecraft.tileentity.TileEntity) SlotCollection(org.spongepowered.common.item.inventory.lens.impl.collections.SlotCollection) Collections(java.util.Collections) InventoryCrafting(net.minecraft.inventory.InventoryCrafting) ArrayList(java.util.ArrayList) InventoryCrafting(net.minecraft.inventory.InventoryCrafting) GridInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.GridInventoryLensImpl) CraftingOutputSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.CraftingOutputSlotLensImpl) List(java.util.List) ArrayList(java.util.ArrayList) IInventory(net.minecraft.inventory.IInventory) Optional(java.util.Optional) OrderedInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.OrderedInventoryLensImpl) CraftingInventoryLensImpl(org.spongepowered.common.item.inventory.lens.impl.comp.CraftingInventoryLensImpl) ContainerLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.container.ContainerLens) InventoryCraftResult(net.minecraft.inventory.InventoryCraftResult) LensProvider(org.spongepowered.common.item.inventory.lens.LensProvider) VanillaAdapter(org.spongepowered.common.item.inventory.adapter.impl.VanillaAdapter) CraftingOutputSlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.CraftingOutputSlotLensImpl) SlotLensImpl(org.spongepowered.common.item.inventory.lens.impl.slots.SlotLensImpl) InputSlot(org.spongepowered.api.item.inventory.slot.InputSlot) Slot(net.minecraft.inventory.Slot) LargeChestInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.LargeChestInventoryLens) DelegatingLens(org.spongepowered.common.item.inventory.lens.impl.DelegatingLens) GridInventoryLens(org.spongepowered.common.item.inventory.lens.comp.GridInventoryLens) BrewingStandInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.BrewingStandInventoryLens) ContainerLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.container.ContainerLens) Lens(org.spongepowered.common.item.inventory.lens.Lens) PlayerInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.PlayerInventoryLens) DefaultEmptyLens(org.spongepowered.common.item.inventory.lens.impl.DefaultEmptyLens) FurnaceInventoryLens(org.spongepowered.common.item.inventory.lens.impl.minecraft.FurnaceInventoryLens) Inventory2DLens(org.spongepowered.common.item.inventory.lens.comp.Inventory2DLens) CraftingInventoryLens(org.spongepowered.common.item.inventory.lens.comp.CraftingInventoryLens) ItemStack(net.minecraft.item.ItemStack) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) InventoryBasic(net.minecraft.inventory.InventoryBasic)

Example 5 with Container

use of org.spongepowered.api.item.inventory.Container in project modules-extra by CubeEngine.

the class BackpackInventory method closeInventory.

public void closeInventory() {
    viewers.stream().map(id -> Sponge.getServer().getPlayer(id)).forEach(p -> p.ifPresent(Player::closeInventory));
    for (Player player : ((Container) view.getInventory()).getViewers()) {
        player.closeInventory();
    }
    this.saveData(view.getInventory());
}
Also used : Inventory(org.spongepowered.api.item.inventory.Inventory) HashSet(java.util.HashSet) ItemStack(org.spongepowered.api.item.inventory.ItemStack) Container(org.spongepowered.api.item.inventory.Container) Context(org.spongepowered.api.service.context.Context) ContextUtil(org.cubeengine.libcube.util.ContextUtil) Sponge(org.spongepowered.api.Sponge) Set(java.util.Set) Player(org.spongepowered.api.entity.living.player.Player) UUID(java.util.UUID) Player(org.spongepowered.api.entity.living.player.Player) Container(org.spongepowered.api.item.inventory.Container)

Aggregations

Container (org.spongepowered.api.item.inventory.Container)9 Player (org.spongepowered.api.entity.living.player.Player)5 Inventory (org.spongepowered.api.item.inventory.Inventory)4 ReturnMessageException (io.github.nucleuspowered.nucleus.internal.command.ReturnMessageException)3 Listener (org.spongepowered.api.event.Listener)3 Kit (io.github.nucleuspowered.nucleus.api.nucleusdata.Kit)2 KitHandler (io.github.nucleuspowered.nucleus.modules.kit.handlers.KitHandler)2 List (java.util.List)2 Optional (java.util.Optional)2 Collectors (java.util.stream.Collectors)2 CarriedInventory (org.spongepowered.api.item.inventory.type.CarriedInventory)2 Text (org.spongepowered.api.text.Text)2 RPContainer (br.net.fabiozumbi12.RedProtect.Sponge.RPContainer)1 Region (br.net.fabiozumbi12.RedProtect.Sponge.Region)1 Lists (com.google.common.collect.Lists)1 Multimap (com.google.common.collect.Multimap)1 Nucleus (io.github.nucleuspowered.nucleus.Nucleus)1 Util (io.github.nucleuspowered.nucleus.Util)1 NucleusFirstJoinEvent (io.github.nucleuspowered.nucleus.api.events.NucleusFirstJoinEvent)1 KitRedeemException (io.github.nucleuspowered.nucleus.api.exceptions.KitRedeemException)1