ζetaCore icon

ζetaCore -----

A core API for a bunch of plugins I develop



Adding chat input to a menu
This is an example of how to implement chat input for a GUI using ZetaCore. This builds off of the `Creating a simple GUI using ZetaCore` example. However, to get a barrier, the player must type "barrier" in chat. This will also close the GUI and send a title to the player.
Code (Java):
public class SimpleGUI extends AbstractGUIMenu implements IChatInputable {

    •••
    @Override
    public void handleClick (InventoryClickEvent e ) {
        // Handle clicks here
        // If the player clicks on an item, this method will be called
        switch (e. getSlot ( ) ) {
            •••
            case 5 :
                // Initialize chat input
                this. menuUtil. setMenuToInputTo ( this ) ;
                this. menuUtil. setTakingChatInput ( true ) ;
                // Input Type is used to determine what to do with the input
                this. setInputType (InputType. STRING ) ;
                this. menuUtil. setGUIMenu ( true ) ;
                // Synchronously close menu, since InventoryClick is called asynchronously
                this. syncClose ( ) ;
                // Send title packets
                this. sendTitlePackets ( "&6You must enter a password!" ) ;
                break ;
        }
    }

    @Override
    public void processChatInput (InputType type, AsyncPlayerChatEvent event ) {
        // Process chat input here
        if (type == InputType. STRING ) {
            if (event. getMessage ( ). trim ( ). equals ( "barrier" ) ) {
                // Synchronously give player item
                Bukkit. getScheduler ( ). runTask (MyPlugin. getInstance ( ), ( ) -> owner. getInventory ( ). addItem ( new ItemStack (Material. BARRIER ) ) ) ;
            }
        }
    }
}
Adding player inventory input to a menu
This is an example of how to implement player inventory input for a GUI using ZetaCore. This builds off of the `Creating a simple GUI using ZetaCore` example. However, if the player clicks on the barrier, an input menu will open. The player must input a diamond sword into the input menu. If they do, they get a barrier. If they don't they get a stone sword.
Code (Java):
public class SimpleMenu extends AbstractGUIMenu implements IPlayerInputMenuInputable {


    •••
    @Override
    public void handleClick (InventoryClickEvent e ) {
        // Handle clicks here
        // If the player clicks on an item, this method will be called
        switch (e. getSlot ( ) ) {
            •••
            case 5 :
                // Open input menu
                new PlayerInputMenu ( this ). open ( ) ;
                break ;
        }
    }

    @Override
    public void setInputValuesFromInputMenu (InventoryClickEvent event ) {
        // Handle player's input here
        if (event. getCurrentItem ( ) != null && event. getCurrentItem ( ). getType ( ) != Material. AIR ) {
            ItemStack item = event. getCurrentItem ( ) ;
            if (item. getType ( ) == Material. DIAMOND_SWORD ) {
                Bukkit. getScheduler ( ). runTask (MyPlugin. getInstance ( ), ( ) -> this. owner. getInventory ( ). addItem ( new ItemStack (Material. BARRIER ) ) ) ;
            } else {
                Bukkit. getScheduler ( ). runTask (MyPlugin. getInstance ( ), ( ) -> this. owner. getInventory ( ). addItem ( new ItemStack (Material. STONE_SWORD ) ) ) ;
            }
        }
    }
}
For more advanced topics check out the github page
Resource Information
Author:
----------
Total Downloads: 307
First Release: Jan 17, 2023
Last Update: Feb 16, 2023
Category: ---------------
All-Time Rating:
0 ratings
Find more info at yeetmanlord.github.io...
Version -----
Released: --------------------
Downloads: ------
Version Rating:
----------------------
-- ratings