{"id":21971415,"url":"https://github.com/oldstuffs/SmartInventory","last_synced_at":"2025-07-22T17:32:59.844Z","repository":{"id":49247972,"uuid":"254859246","full_name":"oldstuffs/SmartInventory","owner":"oldstuffs","description":"Moved to https://github.com/Infumia/InfumiaLib","archived":true,"fork":false,"pushed_at":"2021-06-22T01:09:39.000Z","size":506,"stargazers_count":15,"open_issues_count":10,"forks_count":1,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-30T02:38:24.398Z","etag":null,"topics":["bukkit","inventory","spigot"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oldstuffs.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-11T12:06:43.000Z","updated_at":"2024-06-07T21:09:59.000Z","dependencies_parsed_at":"2022-08-20T11:00:34.822Z","dependency_job_id":null,"html_url":"https://github.com/oldstuffs/SmartInventory","commit_stats":null,"previous_names":["portlek/smartinventory"],"tags_count":70,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oldstuffs%2FSmartInventory","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oldstuffs%2FSmartInventory/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oldstuffs%2FSmartInventory/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oldstuffs%2FSmartInventory/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oldstuffs","download_url":"https://codeload.github.com/oldstuffs/SmartInventory/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":227149554,"owners_count":17738260,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bukkit","inventory","spigot"],"created_at":"2024-11-29T14:50:24.694Z","updated_at":"2024-11-29T14:50:38.558Z","avatar_url":"https://github.com/oldstuffs.png","language":"Java","funding_links":[],"categories":["Java"],"sub_categories":[],"readme":"\u003cimg src=\"logo/logo.svg\" width=\"92px\"/\u003e\n\n[![idea](https://www.elegantobjects.org/intellij-idea.svg)](https://www.jetbrains.com/idea/)\n\n![master](https://github.com/portlek/SmartInventory/workflows/build/badge.svg)\n[![Release](https://jitpack.io/v/portlek/SmartInventory.svg)](https://jitpack.io/#portlek/SmartInventory)\n\n## How to Use\n\n### Maven\n\n```xml\n\u003cbuilds\u003e\n  \u003cplugins\u003e\n    \u003cplugin\u003e\n      \u003cgroupId\u003eorg.apache.maven.plugins\u003c/groupId\u003e\n      \u003cartifactId\u003emaven-shade-plugin\u003c/artifactId\u003e\n      \u003cversion\u003e3.2.4\u003c/version\u003e\n      \u003cexecutions\u003e\n        \u003cexecution\u003e\n          \u003cphase\u003epackage\u003c/phase\u003e\n          \u003cgoals\u003e\n            \u003cgoal\u003eshade\u003c/goal\u003e\n          \u003c/goals\u003e\n          \u003cconfiguration\u003e\n            \u003cminimizeJar\u003etrue\u003c/minimizeJar\u003e\n            \u003ccreateDependencyReducedPom\u003efalse\u003c/createDependencyReducedPom\u003e\n            \u003c!-- Relocations(Optional)\n            \u003crelocations\u003e\n              \u003crelocation\u003e\n                \u003cpattern\u003eio.github.portlek.smartinventory\u003c/pattern\u003e\n                \u003cshadedPattern\u003e[YOUR_PLUGIN_PACKAGE].shade\u003c/shadedPattern\u003e\n              \u003c/relocation\u003e\n            \u003c/relocations\u003e\n            --\u003e\n          \u003c/configuration\u003e\n        \u003c/execution\u003e\n      \u003c/executions\u003e\n    \u003c/plugin\u003e\n  \u003c/plugins\u003e\n\u003c/builds\u003e\n```\n\n```xml\n\u003crepositories\u003e\n  \u003crepository\u003e\n    \u003cid\u003ejitpack\u003c/id\u003e\n    \u003curl\u003ehttps://jitpack.io/\u003c/url\u003e\n  \u003c/repository\u003e\n\u003c/repositories\u003e\n```\n\n```xml\n\u003cdependencies\u003e\n  \u003cdependency\u003e\n    \u003cgroupId\u003ecom.github.portlek\u003c/groupId\u003e\n    \u003cartifactId\u003eSmartInventory\u003c/artifactId\u003e\n    \u003cversion\u003e${version}\u003c/version\u003e\n  \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\n\n### Gradle\n\n```groovy\nplugins {\n  id \"com.github.johnrengelman.shadow\" version \"7.0.0\"\n}\n```\n\n```groovy\nrepositories {\n  maven {\n    url \"https://jitpack.io\"\n  }\n}\n```\n\n```groovy\ndependencies {\n  implementation(\"com.github.portlek:SmartInventory:${version}\")\n}\n```\n\n## Getting Started\n\n### Registering the library\n\n```java\nfinal class Main extends JavaPlugin {\n\n  private final SmartInventory inventory = new BasicSmartInventory(this);\n\n  @Override\n  public void onEnable() {\n    this.inventory.init();\n    new SomeClassesThatNeedSmartInventory(this.inventory).foo();\n    new SomeOtherClasses(this.inventory).foo();\n  }\n}\n```\n\n### Creating a Inventory Provider Class\n\n```java\nfinal class ExampleInventoryProvider implements InventoryProvider {\n\n  @Override\n  public void init(@NotNull final InventoryContents contents) {\n    // Runs when the page opens first.\n    // An icon that which is empty(air).\n    final Icon empty = Icon.EMPTY;\n    // An icon that has not any effect.\n    final Icon noEffect = Icon.from(new ItemStack(Material.DIAMOND));\n    // A simple static icon that player can't click it.\n    final Icon cancel = Icon.cancel(new ItemStack(Material.DIAMOND));\n    final Icon click = Icon.click(new ItemStack(Material.DIAMOND), clickEvent -\u003e {\n      // Runs when the player click the icon.\n    }, clickEvent -\u003e {\n      // It's array so, optional.\n      // If the predicate is returning true, the consumer that above will run.\n      return true;\n    });\n    final Icon drag = Icon.drag(new ItemStack(Material.DIAMOND), dragEvent -\u003e {\n      // Runs when the player drag the icon.\n    });\n    final Icon anIcon = Icon.from(new ItemStack(Material.DIAMOND))\n      .whenClick(clickEvent -\u003e {\n        // Runs when player clicks the icon.\n      }, clickEvent -\u003e {\n        // If this predicate returns false, the consumer won't run.\n        return false;\n      })\n      .whenDrag(dragEvent -\u003e {\n        // Runs when player drags the icon.\n      })\n      .whenInteract(dragEvent -\u003e {\n        // Runs when player interact to the icon.\n      })\n      .canSee(cont -\u003e {\n        // If it's returning false, player will see the fallback icon on the page.\n        return false;\n      })\n      .fallback(new ItemStack(Material.AIR))\n      .canUse(cont -\u003e {\n        // If it's returning false, player can't use the icon on the page.\n        return false;\n      });\n    // Adding an icon into the inventory.\n    contents.add(anIcon);\n    // Adds to the certain slot.\n    contents.set(SlotPos.of(0, 4), anIcon);\n    // A pagination example.\n    final Pagination pagination = contents.pagination();\n    final Icon[] icons = new Icon[22];\n    for (int index = 0; index \u003c icons.length; index++) {\n      icons[index] = Icon.cancel(new ItemStack(Material.CHORUS_FRUIT, index));\n    }\n    pagination.setIcons(icons);\n    pagination.setIconsPerPage(7);\n    pagination.addToIterator(contents.newIterator(SlotIterator.Type.HORIZONTAL, 1, 1));\n    final Page page = contents.page();\n    final Player player = contents.player();\n    final Icon previousArrow = Icon.click(new ItemStack(Material.ARROW), clickEvent -\u003e\n      page.open(player, pagination.previous().getPage()));\n    final Icon nextArrow = Icon.click(new ItemStack(Material.ARROW), clickEvent -\u003e\n      page.open(player, pagination.next().getPage()));\n    contents.set(2, 3, previousArrow);\n    contents.set(2, 5, nextArrow);\n    // And other tons of methods will help you to make a awesome pages :)\n  }\n\n  @Override\n  public void tick(@NotNull final InventoryContents contents) {\n    // Runs every tick.\n    // You have options that;\n    // -\u003e make it async or not (default is false)\n    // -\u003e set the tick's start delay (default is 1L)\n    // -\u003e set the tick period (default is 1L)\n  }\n\n  @Override\n  public void update(@NotNull final InventoryContents contents) {\n    // Runs when the notify update method called by you.\n    // SmartInventory#notifyUpdate(Player)\n    // -\u003e Finds the player's page, if it's open, runs the update method.\n    // InventoryContents#notifyUpdate()\n    // -\u003e Runs the update method of this class.\n  }\n}\n```\n\n### Creating a Page\n\n```java\nfinal class CreateAPage {\n\n  @NotNull\n  final SmartInventory inventory;\n\n  @NotNull\n  final InventoryProvider provider;\n\n  CreateAPage(@NotNull final SmartInventory inventory, @NotNull final InventoryProvider provider) {\n    this.inventory = inventory;\n    this.provider = provider;\n  }\n\n  void open(@NotNull final Page parentPage, @NotNull final Player player) {\n    final Map\u003cString, Object\u003e properties = new HashMap\u003c\u003e();\n    properties.put(\"test-key\", player.getName());\n    Page.build(this.inventory, this.provider)\n      // Runs the update method as async. (default is false)\n      .async(true)\n      // If it's returning false, player's page will close and open immediately. (default is true)\n      // Closing a page cannot be canceled. It just closes and opens again method.\n      .canClose(true)\n      .canClose(closeEvent -\u003e true)\n      // Set the page's column. (default is 9)\n      // There is no any different page type, so it must be 9 for now.\n      .column(9)\n      // Set the page's parent page.(default is empty)\n      // contents.page().parent().ifPresent(page -\u003e ...)\n      .parent(parentPage)\n      // Set the page's row size. (default is 1)\n      // The row's range is 1 to 6\n      .row(3)\n      // Set the page's start delay of the tick method. (default is 1L)\n      .startDelay(10L)\n      // Set the page's period time of the tick method. (default is 1L)\n      .tick(1L)\n      // Set the page's title. (default is Smart Inventory)\n      .title(\"Title\")\n      // Runs after the page opened. If predicates cannot passed, the consumer won't run.\n      .whenOpen(openEvent -\u003e {\n        openEvent.contents().player().sendMessage(\"The page opened.\");\n        openEvent.contents().player().sendMessage(\"This message will send to Player.\");\n      }, Arrays.asList(\n        openEvent -\u003e\n          openEvent.contents().player().getName().equals(\"Player\"),\n        openEvent -\u003e\n          openEvent.contents().player().hasPermission(\"test.perm\")\n      ))\n      // Runs after the page closed. If predicates cannot passed, the consumer won't run.\n      .whenClose(closeEvent -\u003e {\n        closeEvent.contents().player().sendMessage(\"The page closed.\");\n        closeEvent.contents().player().sendMessage(\"This message will send to Player.\");\n      }, Arrays.asList(\n        closeEvent -\u003e\n          closeEvent.contents().player().getName().equals(\"Player\"),\n        closeEvent -\u003e\n          closeEvent.contents().player().hasPermission(\"test.perm\")\n      ))\n      // Opens the page for the player.\n      // With properties.\n      // You can get the properties with\n      // Get a property that can be nullable \u003e contents.getProperty(\"test-key\");\n      // Get a property that cannot be nullable \u003e contents.getPropertyOrDefault(\"test-key-2\", \"fallback\");\n      // You can also set a property \u003e contents.setProperty(\"test-key-2\", \"test-object\");\n      // .open(player, properties);\n      // With properties and pagination number.\n      // .open(player, 2, properties);\n      // With pagination number.\n      // .open(player, 2)\n      // Default open method.\n      .open(player);\n  }\n\n  void openAnEmptyPage(@NotNull final Player player) {\n    Page.build(this.inventory, this.provider)\n      .title(\"Title\")\n      .row(3)\n      .open(player);\n  }\n}\n```\n\n## Useful libraries with SmartInventory\n\n### Simple Bukkit item builder library with builder pattern.\n\n[BukkitItemBuilder](https://github.com/portlek/BukkitItemBuilder)\n\n### You can get inputs from players via chat.\n\n[Input](https://github.com/portlek/input)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foldstuffs%2FSmartInventory","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foldstuffs%2FSmartInventory","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foldstuffs%2FSmartInventory/lists"}