此资源仅供开发者使用,如果您是服务器管理员,则不适合您。
此框架需要 Java 8 或更高版本。
IF
IF - Inventory Framework 是一个轻量级但功能强大的 GUI 框架,旨在帮助您更轻松创建、修改和管理 GUI。以下是我认为 IF 在众多同类框架中脱颖而出的原因:
基于面板(Pane):IF 完全依赖于面板的使用,允许您将 GUI 分割成更小的部分,这些部分可以单独更改,而不会影响 GUI 的其他任何部分。
XML 读取:IF 可以读取 XML 文件并从中创建整个 GUI。不再需要冗长的方法来构建您的 GUI,只需从 XML 文件加载即可。(不用担心,XML 是完全可选的,如果您不想使用它,直接忽略即可。)
可扩展:您可以创建具有自身功能的面板,使其按照您希望的方式运行,而无需从头开始重新设计一个新的 GUI 框架。
无需再编写事件处理器:无需创建监听器、监听事件并使用大量的 if 语句来判断点击了哪个物品。IF 将为您处理所有这些工作,使您可以专注于开发插件。
旋转:轻松对面板应用线性二维旋转,以不同方式旋转您的面板。
IF 拥有详尽的 Wiki,详细介绍了该框架的工作原理及其使用方法。您可以在这里找到 Wiki 。
用法
IF 是独立工作的。您需要将其阴影化(shading)到您的插件中,而不是将其添加到服务器上。
如果您没有使用构建系统,可以从这里的下载链接下载资源,并将其作为依赖项添加到您的 IDE 中。
如果您使用 Maven,请将以下内容添加为 pom.xml 中的依赖项:
<dependency>
<groupId>com.github.stefvanschie.inventoryframework</groupId>
<artifactId>IF</artifactId>
<version>0.12.2</version>
</dependency>
IF 位于中央仓库,因此您无需指定仓库。
然后添加以下代码以将 IF 阴影化到您的插件中:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.2</version>
<configuration>
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
<relocations>
<relocation>
<pattern>com.github.stefvanschie.inventoryframework</pattern>
<shadedPattern>[YOUR PACKAGE].inventoryframework</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
将 [YOUR PACKAGE] 替换为您的主包名。
在 Wiki 上有大量的教程和示例,因此我强烈建议您查看它以了解其工作原理。如果您对 XML 不太熟悉,Wiki 上还有一个关于 XML 的 简短教程。
以下是一个如何在其中包含一个物品的基线 GUI 的小片段示例。
//create a gui with 5 rows and the title My GUI
ChestGui gui = new ChestGui(5, "My GUI");
//create a new pane occupying the entire gui
OutlinePane pane = new OutlinePane(9, 5);
ItemStack item = new ItemStack(Material.ICE);
//create an item which will send a message when clicked
GuiItem guiItem = new GuiItem(item, event -> event.getWhoClicked().sendMessage("You clicked on ice!"));
//add the item to the pane
pane.addItem(guiItem);
//add the pane to the item
gui.addPane(pane, Slot.fromXY(0, 0));
非常感谢您的建议和反馈!
链接:
This resource is for developers only, if you're a server owner then this isn't intended for you.
This framework requires Java 8 or higher.
IF
IF - Inventory Framework is a lightweight, but powerful GUI framework, intended to help you create, alter and manage GUIs more easy. Here are a few things why I think IF stands out from other similar frameworks:
Pane based: IF relies fully on the usage of panes which allow you to separate your GUI in smaller parts which can be changed individually, without altering any other parts of your GUI.
XML reading: IF can read XML files and create entire GUIs from those. No more long methods creating your GUIs, just load them from an XML file. (Don't worry, XML is fully optional, just ignore it if you don't want to use it.)
Extensible: You can create your own panes with their own features to behave exactly how you want them to, without having to redesign a new GUI framework yourself from the ground up.
No more event handlers: No need to create listeners, listen to events and use a dozen if-statements to determine which item was clicked. IF will handle this all for you, so you can focus on creating your plugin.
Rotations: Easily apply linear two dimensional rotations on your panes to rotate your panes in different ways.
IF has an in-depth wiki detailing the workings of the framework and how to use it. You can find the wiki here.
Usage
IF works standalone. You have to shade it into your plugin, rather than add it to the server.
If you're not using a build system, you can download the resource from the download link here and add it as a dependency in your IDE.
If you're using Maven, add the following as dependency to your pom.xml:
<dependency>
<groupId>com.github.stefvanschie.inventoryframework</groupId>
<artifactId>IF</artifactId>
<version>0.12.2</version>
</dependency>
IF is in the Central Repository, so you don't have to specify a repository.
Then add this to shade IF into your plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.2</version>
<configuration>
<dependencyReducedPomLocation>${project.build.directory}/dependency-reduced-pom.xml</dependencyReducedPomLocation>
<relocations>
<relocation>
<pattern>com.github.stefvanschie.inventoryframework</pattern>
<shadedPattern>[YOUR PACKAGE].inventoryframework</shadedPattern>
</relocation>
</relocations>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
Replace [YOUR PACKAGE] with your main package.
There are extensive tutorials and examples on the wiki, so I highly recommend checking it out to see how it works. If you're uncertain how XML works, there's also a small tutorial on that on the wiki as well.
Here's a small snippet on how to create a base GUI with one item in it.
//create a gui with 5 rows and the title My GUI
ChestGui gui = new ChestGui(5, "My GUI");
//create a new pane occupying the entire gui
OutlinePane pane = new OutlinePane(9, 5);
ItemStack item = new ItemStack(Material.ICE);
//create an item which will send a message when clicked
GuiItem guiItem = new GuiItem(item, event -> event.getWhoClicked().sendMessage("You clicked on ice!"));
//add the item to the pane
pane.addItem(guiItem);
//add the pane to the item
gui.addPane(pane, Slot.fromXY(0, 0));
Suggestions and feedback are highly appreciated!
Links:
评论 0
登录后参与评分
还没有评论,来抢沙发吧