-
Notifications
You must be signed in to change notification settings - Fork 26
Migrating to version 3
The new version 3.0 is especially needed to restructure the project's packages, previously everything was unified in a single package "me.saiintbrisson.minecraft", also, everything that was created had to be compatible with previous versions so nothing could be changed if it would not break code compatibility.
To give you an idea, it had working code from 2016 using the first version of Inventory Framework that works perfectly in the latest version 2.5.4-rc.1. But things get complicated when it comes to adding features, fixing bugs and so on, so now we have version 3.
Everything that was in the "me.saiintbrisson.minecraft" package has been moved to "me.devnatan.inventoryframework" and subpackages.
An attempt has been made to preserve as many names as possible such as the View
name and context names to make relocation easier.
As of this new version 3, all of its views are designed with a single platform in mind, and when I say platform I mean: Bukkit, Sponge, Bungeecord, among others. Now you will have access to the APIs you are most familiar with like ItemStack
in Bukkit, ProxiedPlayer
in BungeeCord and more.
Previously it was not possible to use Lombok in views because it was mandatory to define a constructor and use super
to choose the properties and initial options of the view.
This has changed, now we have a method specifically for configuring the view and another specifically for defining the items that will be rendered.
So you can use all Lombok annotations naturally like this
@RequiredArgsConstructor
private final class PetShopView extends View {
private final PetsManager petsManager;
}
Perhaps the biggest change of all was on the pagination issue, the PaginatedView
class no longer exists. Now everything is handled through states so if you have a PaginatedView
, simply change it to a View
. Any and all views are now paginated if they have pagination state, and the IF internally takes care of everything else for you.
- public final class PetShopView extends PaginatedView<Pet>
+ public final class PetShopView extends View
The way paging was defined has also changed, before we had specific methods for each type of paging: static, dynamic computed and dynamic asynchronous, we don't have that anymore. Now the type of paging will depend on what kind of data source you provide for the paging state.
The new state handling came to make the data handling experience inside the view more reactive, easy and explicit.
Previously it was necessary to use a combination of context.set
, context.get
and context.update
together to get and update data and this was a bit strange because the Inventory Framework was not specifically written for this so some things they just didn't work which led to several issues.
Learn more about the new State Management System
Previously, options like title, size and type of the inventory were defined in the constructor or in onRender
sometimes, now, it's all before initialization.
-
onInit
used to set root options, create states, apply features, etc, called before initialization; -
onOpen
used to configure context-specific options like container size, title, cancellation things and so on; -
onFirstRender
used ONLY TO renderize items (previouslyonRender
); -
onUpdate
used to listen to updates, no longer possible to define items in this phase.
Before (root functions are accessible)
public final class PetShopView extends View {
public PetShopView() {
super(4, "Pet shop");
setCancelOnClick(true);
setLayout(...);
}
@Override
public void onOpen(OpenViewContext context) {
// context-specific
context.setContainerTitle("Hello world!");
}
}
After (root functions do not exist, defined only once in configuration)
For root options use onInit
, for context-specific options use modifyConfig()
on onOpen
public final class PetShopView extends View {
@Override
public void onInit(ViewConfigBuilder config) {
config.title("Pet Shop").size(4).cancelOnClick().layout(...);
}
@Override
public void onOpen(OpenContext open) {
// context-specific
open.modifyConfig().title("Hello World!");
}
}
Before (defined on onRender)
public final class PetShopView extends PaginatedView<...> {
@Override
public void onRender(ViewContext context) {
context.setLayout("...");
context.paginated().setSource(...);
}
}
After (defined onOpen with modifyConfig()
)
public final class PetShopView extends View {
@Override
public void onOpen(OpenContext open) {
open.modifyConfig().layout("...");
}
}
Pagination now uses State Management, please see Pagination page on Wiki to learn more about the new way to paginate your views.
Before (defined on constructor and onRender)
public final class PetShopView extends View {
public PetShopView() {
slot(4, 3, new ItemStack(Material.GOLD_INGOT)).closeOnClick();
firstSlot().onRender(render -> render.setItem(new ItemStack(Material.DIAMOND)));
}
@Override
public void onRender(ViewContext context) {
context.availableSlot(new ItemStack(Material.GOLDEN_AXE));
}
}
After (no more construtor, only onFirstRender)
Now it is only possible to define items in onFirstRender
. There is no longer any other possible way to define items.
public final class PetShopView extends View {
@Override
public void onFirstRender(RenderContext render) {
render.slot(4, 3, new ItemStack(Material.GOLD_INGOT)).closeOnClick();
render.firstSlot().rendered(() -> new ItemStack(Material.DIAMOND)));
render.availableSlot(new ItemStack(Material.GOLDEN_AXE));
}
}
- Installation
- Introduction
- Advanced Usage
- Built-In Features
- Extra Features
- Anvil Input
- Proxy Inventory