HomeJavaModsGUI-API
GUI-API
[​IMG]
This API is made to simplify the making of a good-looking and working GUI - You will also have to write code with this API, but
you get some cool and useful features and a good handling structure. It has been tested for the version 1.12 and works fine for me.
If you get errors, then please message me and I will try to fix this issue as soon as possible.



[​IMG]


[​IMG]
For the best working experience, I recommend reading my documentation to get a fundamental knowledge about this API and its concept, so you actually know what you're doing:
Spoiler: Read more
Listing: This object is the core of this whole API - It is used to represent an inventory and its view, manage the pages, hold data for internal handling, handle events corresponding to the stored inventory and manage every single ItemStack with its bound action.
Initializing:
Code (Text):
            /**
             * Listing
             */
            Listing listing = new Listing ( SIZE , "TITLE" ) {
       
                @Override
                public void load () {
           
                }
       
            };


Action: This objects 'execute-method' will be called when its bound ItemStack gets clicked. There are some pre-made ones in this library, which are working as simple worarounds to simplify the code you would have to write.
Initializing:
Code (Text):
            /**
             * Action
             */
            Action action = new Action () {
       
                @Override
                public void execute () {
           
                                     //CODE

                }
       
            };



Link: This object is used to bind an ItemStack with an action. When the stored ItemStack gets clicked, the corresponding action gets executed.
Initializing:
Code (Text):
            /**
             * Link
             */
            Link link = new Link ( STACK , ACTION );


Content: This object is representing a whole inventory content. The inventory content is stored as single 'Links (above)'. This object does also have some useful methods, that will make it easy to create a GUI with multiple pages.
Initializing:
Code (Text):
-


PermissionedPlayer: This object is binding a player with some internal permissions. The permissions can be changed at a later moment.
Initializing:
Code (Text):
            /**
             * PermissionedPlayer
             */
            PermissionedPlayer permissioned = new PermissionedPlayer ( PLAYER , Permission.??? , Permission.??? , ... );


SharedView: This object is containing every player that is bound to a specific listing and its inventory. This listing is also saved by this object.
Initializing:
Code (Text):
-


Here is the full walkthrough for how to write the right code:
Spoiler: Read more
First off all, you have to create an instance of listing:
Code (Text):
            /**

             * Listing
             */
            Listing listing = new Listing ( SIZE , TITLE ) {
       
                @Override
                public void load () {
           
                }
       
            };
Then you want to inject some content into its inventory. This can be done by using the
set()- and add()-method:
Code (Text):
            Listing listing = new Listing ( SIZE , TITLE ) {
       
                @Override
                public void load () {
           
                    this.add( new Link ( STACK , ACTION ) );
                    this.set( 19 , new Link ( STACK , ACTION ) );
           
                }
       
            };
Note: Adding an element to this inventory will just increase the size of its list by one. Setting an element into this inventory will expand the list to the given size if needed - Therefore the set()-method can either be used to replace an already existing element or add a new one. This is one of the features of the Content-Class.

You also want to bind a player to this listing, so this inventory can be viewed - For that you have to create an instance of 'PermissionedPlayer' with corresponding permissions:
Code (Text):
            /**
             * Permissioned
             */
            PermissionedPlayer permissioned = new PermissionedPlayer( PLAYER , Permission.CLICK , Permission.CLOSE , Permission.OPEN );
Note: There are three internal permissions provided by this API: CLICK ( allow to interact with item ), CLOSE ( allow closing inventory ) and OPEN ( allow opening inventory ). When you want to fully authorize the player, then just use every of this three permissions as a parameter when construction an instance of 'PermissionedPlayer'.

After that, you must bind this instance with the listing:
Code (Text):
            /**
             * Bind
             */
            ListingManager.bind( listing , permissioned );
You can also do change some listing-specific options. For example this one, which lets your listing get closed when the plugin gets unloaded due to a server reload or similar:
Code (Text):
            /**
             * Options
             */
            listing.getOptions().setClosing( true );

The last step is to open the view:
Code (Text):
            /**
             * Open
             */
            list.open();


Here is also a finished code example for everybody needing help:
Spoiler: Read more
Code (Text):
            /**
             * Action
             */
            final Action action = new Action () {
         
                @Override
                public void execute () {
             
                    this.setEventStatus( EventStatus.GO );
                    this.setHandleStatus( HandleStatus.UNHANDLE );
             
                }
         
            };
     
            /**
             * Listing
             */
            Listing listing = new Listing ( 9 , "§cExample" ) {
         
                @Override
                public void load () {
             
                    this.set( 0 , new Link ( new ItemStack ( Material.GOLD_NUGGET , 1 ) , action ) );
             
                    this.set( 4 , new Link ( new ItemStack ( Material.BARRIER , 1 ) , new CloseAction() ) );
                    this.set( 8 , new Link ( new ItemStack ( Material.ARROW , 1 ) , new NextAction() ) );
                    this.set( 9 , new Link ( new ItemStack ( Material.ARROW , 1 ) , new PreviousAction() ) );
             
                }
         
            };
     
            /**
             * Permissioned
             */
            PermissionedPlayer permissioned = new PermissionedPlayer( player , Permission.CLICK , Permission.CLOSE , Permission.OPEN );
     
            /**
             * Bind
             */
            ListingManager.bind( listing , permissioned );

            /**
             * Options
             */
            listing.getOptions().setClosing( true );

            /**
             * Open
             */
            listing.open();
Note: The EventStatus can be set to 'GO' and 'CANCEL' - When you set it to CANCEL, the ClickEvent will be cancelled, therefore the ItemStack cannot be taken out of the inventory.
Note: The HandleStatus can be set to 'HANDLE' and 'UNHANDLE' - When you set it to UNHANDLE, the ItemStack will be taken out of the Content-List of the corresponding listing - Therefore it won't be handelled anymore.
Note: There are some pre-made actions:
CloseAction: Allowing to close the inventory when executing
NextAction: Allowing to switch to next page when executing
PreviousAction: Allowing to switch to previous page when executing
BlockAction: Allowing to block an interaction when executing, so slots are blocked without specific functionality
MoveAction: Allowing to move the clicked ItemStack to a specific slot when executing
SwitchAction: Allowing to switch the clicked ItemStack with a specific ItemStack when executing



[​IMG]
This API has no dependencies.

But: Since spigot is loading plugins in an order, it can happen, that this API gets loaded after the plugin dependant of it. This will lead to an exception because the resources are not available when your plugin is loading.

To prevent this, just write this line of code into your 'plugin.yml':
Code (Text):
depend: [GUI-API]
If you got more than one dependency, then write:
Code (Text):
depend: [GUI-API,another,another, ... ]


[​IMG]
I hope that there is a community, which I can help and that you like my work.

In addition, I am looking forward to any form of constructive criticism, suggestions for improvement or implementation ideas


~Lyras
Note: Dude, that were many side notes.
Quick facts

Install steps are the general flow for this file type — How to install Minecraft Java mods & modpacks walks through it step by step.

GUI-API is a free Minecraft Java mod. Compatible with Minecraft 1.8, 1.9, 1.10, 1.11 and newer. Downloaded 755 times (via Spigot). Download it and open it directly in the game.

Explore more