use of org.spongepowered.api.item.inventory.Container in project modules-extra by CubeEngine.
the class BackpackManager method onInventoryClose.
@Listener
public void onInventoryClose(InteractInventoryEvent.Close event, @First Player player) {
Container inventory = event.getTargetInventory();
if (inventory instanceof CarriedInventory) {
if (((CarriedInventory) inventory).getCarrier().orElse(null) instanceof BackpackHolder) {
BackpackHolder holder = (BackpackHolder) ((CarriedInventory) inventory).getCarrier().get();
holder.getBackpack().closeInventory(inventory, player);
}
}
}
use of org.spongepowered.api.item.inventory.Container in project LanternServer by LanternPowered.
the class CraftingTableInteractionBehavior method tryInteract.
@Override
public BehaviorResult tryInteract(BehaviorPipeline<Behavior> pipeline, BehaviorContext context) {
final Optional<Player> optPlayer = context.getContext(ContextKeys.PLAYER);
if (optPlayer.isPresent()) {
final CraftingTableInventory craftingTableInventory = VanillaInventoryArchetypes.CRAFTING_TABLE.builder().withCarrier(new LanternBlockCarrier(context.requireContext(ContextKeys.BLOCK_LOCATION))).build(Lantern.getMinecraftPlugin());
final Optional<Container> optContainer = optPlayer.get().openInventory(craftingTableInventory);
if (optContainer.isPresent()) {
return BehaviorResult.SUCCESS;
}
}
return BehaviorResult.PASS;
}
use of org.spongepowered.api.item.inventory.Container in project Nucleus by NucleusPowered.
the class KitListener method onPlayerInteractInventoryClose.
@Listener
public void onPlayerInteractInventoryClose(final InteractInventoryEvent.Close event, @Root final Player player, @Getter("getTargetInventory") final Container inventory) {
handler.getCurrentlyOpenInventoryCommandKit(inventory).ifPresent(x -> {
// Set the commands.
Kit kitInfo = x.getFirst();
List<String> c = Lists.newArrayList();
// For each slot, is it a written book?
x.getSecond().slots().forEach(slot -> slot.poll().ifPresent(item -> {
if (item.getType().equals(ItemTypes.WRITTEN_BOOK)) {
item.get(Keys.BOOK_PAGES).ifPresent(y -> c.add(fixup(y)));
} else if (item.getType().equals(ItemTypes.WRITABLE_BOOK)) {
item.get(Keys.BOOK_PAGES).ifPresent(page -> c.add(getCommandFromText(page)));
} else {
// Drop the item.
item.get(Keys.ITEM_BLOCKSTATE).ifPresent(z -> {
World world = player.getLocation().getExtent();
Entity e = world.createEntity(EntityTypes.ITEM, player.getLocation().getPosition());
e.offer(Keys.ITEM_BLOCKSTATE, z);
world.spawnEntity(e);
});
}
kitInfo.setCommands(c);
handler.saveKit(kitInfo);
}));
player.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.command.edit.success", kitInfo.getName()));
handler.removeKitCommandInventoryFromListener(inventory);
});
handler.removeViewer(inventory);
}
use of org.spongepowered.api.item.inventory.Container in project Nucleus by NucleusPowered.
the class KitCreateCommand method executeCommand.
@Override
public CommandResult executeCommand(final CommandSource source, CommandContext args) throws ReturnMessageException {
String kitName = args.<String>getOne(name).get();
if (KIT_HANDLER.getKitNames().stream().anyMatch(kitName::equalsIgnoreCase)) {
throw new ReturnMessageException(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.add.alreadyexists", kitName));
}
if (source instanceof Player) {
final Player player = (Player) source;
Inventory inventory = Util.getKitInventoryBuilder().property(InventoryTitle.PROPERTY_NAME, InventoryTitle.of(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.create.title", kitName))).build(plugin);
Container container = player.openInventory(inventory).orElseThrow(() -> ReturnMessageException.fromKey("command.kit.create.notcreated"));
Sponge.getEventManager().registerListeners(plugin, new TemporaryEventListener(inventory, container, kitName));
} else {
try {
KIT_HANDLER.saveKit(KIT_HANDLER.createKit(kitName));
source.sendMessage(plugin.getMessageProvider().getTextMessageWithFormat("command.kit.addempty.success", kitName));
} catch (IllegalArgumentException ex) {
throw ReturnMessageException.fromKey("command.kit.create.failed", kitName);
}
}
return CommandResult.success();
}
Aggregations