Skip to content

Commit

Permalink
Added GUICloseEvent
Browse files Browse the repository at this point in the history
  • Loading branch information
alfonsoLeandro committed Sep 8, 2020
1 parent ed9b4a8 commit dfdf56e
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 5 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.github.alfonsoLeandro</groupId>
<artifactId>MPUtils</artifactId>
<version>1.2.1</version>
<version>1.3.0</version>
<packaging>jar</packaging>

<name>MPUtils</name>
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/com/github/alfonsoLeandro/mpUtils/guis/Events.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@ public class Events implements Listener {
@EventHandler
public void onClick(InventoryClickEvent event){
if(event.getWhoClicked() instanceof Player && PlayersOnGUIsManager.isInGUI(event.getWhoClicked().getName())){
GUIAtributes atributes = PlayersOnGUIsManager.getAttributesByPlayer(event.getWhoClicked().getName());
Bukkit.getPluginManager().callEvent(new GUIClickEvent((Player)event.getWhoClicked(), atributes.getGuiType(), atributes.getPage(), event, atributes.getGuiTags(), atributes.getGui()));
GUIAtributes attributes = PlayersOnGUIsManager.getAttributesByPlayer(event.getWhoClicked().getName());
Bukkit.getPluginManager().callEvent(new GUIClickEvent((Player)event.getWhoClicked(), attributes.getGuiType(), attributes.getPage(), event, attributes.getGuiTags(), attributes.getGui()));
}
}

@EventHandler
public void onClose(InventoryCloseEvent event){
PlayersOnGUIsManager.removePlayer(event.getPlayer().getName());
if(PlayersOnGUIsManager.isInGUI(event.getPlayer().getName())) {
GUIAtributes attributes = PlayersOnGUIsManager.getAttributesByPlayer(event.getPlayer().getName());
Bukkit.getPluginManager().callEvent(new GUICloseEvent((Player) event.getPlayer(), attributes.getGuiType(), attributes.getPage(), event, attributes.getGuiTags(), attributes.getGui()));
PlayersOnGUIsManager.removePlayer(event.getPlayer().getName());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class GUIClickEvent extends Event {
* @param clicker The player that clicked the GUI.
* @param guiType The {@link GUIType} clicked, either {@link GUIType#PAGINATED} or {@link GUIType#SIMPLE}
* @param page The page the clicker was on when clicking, or -1 if the {@link GUIType} is {@link GUIType#SIMPLE}
* @param event The actual {@link InventoryClickEvent} fired, for you to modify it at your will.
* @param event The bukkit {@link InventoryClickEvent} fired, for you to modify it at your will.
* @param guiTags Any string tags you may want to add in order to differentiate a GUI from another.
* @param gui The gui object, can be simple or paginated, use {@link GUIClickEvent#getGuiType()} to check whether it is a paginated gui or a simple gui.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package com.github.alfonsoLeandro.mpUtils.guis;


import org.bukkit.entity.Player;
import org.bukkit.event.Event;
import org.bukkit.event.HandlerList;
import org.bukkit.event.inventory.InventoryCloseEvent;

public class GUICloseEvent extends Event {

private static final HandlerList HANDLERS = new HandlerList();
private final Player player;
private final GUIType guiType;
private final int page;
private final InventoryCloseEvent event;
private final String guiTags;
private final Object gui;


/**
* Custom event for registering when a player closes a GUI inventory.
*
* @param player The player that was using the GUI.
* @param guiType The {@link GUIType} clicked, either {@link GUIType#PAGINATED} or {@link GUIType#SIMPLE}
* @param page The page the clicker was on when closing the GUI, or -1 if the {@link GUIType} is {@link GUIType#SIMPLE}
* @param event The bukkit {@link InventoryCloseEvent} fired, for you to modify it at your will.
* @param guiTags Any string tags you may want to add in order to differentiate a GUI from another.
* @param gui The gui object, can be simple or paginated, use {@link GUIClickEvent#getGuiType()} to check whether it is a paginated gui or a simple gui.
*/
public GUICloseEvent(Player player, GUIType guiType, int page, InventoryCloseEvent event, String guiTags, Object gui) {
this.player = player;
this.guiType = guiType;
this.page = page;
this.event = event;
this.guiTags = guiTags;
this.gui = gui;
}

public HandlerList getHandlers() {
return HANDLERS;
}

public static HandlerList getHandlerList() {
return HANDLERS;
}

/**
* Get the player who clicked the inventory.
*
* @return Player who clicked.
*/
public Player getPlayer() {
return player;
}

/**
* Gets the GUI type of the clicked GUI.
*
* @return the type of GUI, either {@link GUIType#SIMPLE} or {@link GUIType#PAGINATED}.
*/
public GUIType getGuiType() {
return guiType;
}

/**
* Gets the page the player was standing on when clicking the GUI.
*
* @return -1 if {@link GUIType} is equal to {@link GUIType#SIMPLE} or the page number in any other case.
*/
public int getPage() {
return page;
}

/**
* Gets the actual {@link InventoryCloseEvent} that was fired when clicking the GUI.
*
* @return Said event.
*/
public InventoryCloseEvent getInventoryCloseEvent() {
return event;
}

/**
* Gets the tags added to the GUI when creating an instance of the object.
*
* @return The tags previously entered.
*/
public String getGuiTags() {
return guiTags;
}

/**
* Gets the instance of the GUI object so you can get the navBar items.
*
* @return Instance of the object {@link SimpleGUI} or {@link PaginatedGUI}.
*/
public Object getGui() {
return gui;
}
}

0 comments on commit dfdf56e

Please sign in to comment.