diff --git a/src/main/java/co/marcin/novaguilds/enums/Message.java b/src/main/java/co/marcin/novaguilds/enums/Message.java index 4fb68ca5..f556cd63 100644 --- a/src/main/java/co/marcin/novaguilds/enums/Message.java +++ b/src/main/java/co/marcin/novaguilds/enums/Message.java @@ -342,6 +342,7 @@ public enum Message { INVENTORY_REQUIREDITEMS_NAME, INVENTORY_GGUI_NAME, + INVENTORY_GUI_BACK, INVENTORY_GUI_PLAYERSLIST_ICONITEM, INVENTORY_GUI_PLAYERSLIST_ROWITEM, INVENTORY_GUI_PLAYERSLIST_TITLE, diff --git a/src/main/java/co/marcin/novaguilds/listener/ChestGUIListener.java b/src/main/java/co/marcin/novaguilds/listener/ChestGUIListener.java index 20adc3ba..dd2ebc16 100644 --- a/src/main/java/co/marcin/novaguilds/listener/ChestGUIListener.java +++ b/src/main/java/co/marcin/novaguilds/listener/ChestGUIListener.java @@ -20,13 +20,16 @@ import co.marcin.novaguilds.NovaGuilds; import co.marcin.novaguilds.basic.NovaPlayer; +import co.marcin.novaguilds.enums.Message; import co.marcin.novaguilds.interfaces.GUIInventory; import co.marcin.novaguilds.util.ChestGUIUtils; +import co.marcin.novaguilds.util.InventoryUtils; import org.bukkit.entity.Player; import org.bukkit.event.EventHandler; import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.event.inventory.InventoryCloseEvent; +import org.bukkit.inventory.Inventory; import java.util.concurrent.TimeUnit; @@ -39,7 +42,8 @@ public ChestGUIListener() { @EventHandler public void onInventoryClick(InventoryClickEvent event) { - if(event.getClickedInventory() == null || event.getCurrentItem()==null) { + Inventory inventory = InventoryUtils.getClickedInventory(event); + if(inventory == null || event.getCurrentItem()==null || !inventory.equals(event.getView().getTopInventory())) { return; } @@ -48,8 +52,14 @@ public void onInventoryClick(InventoryClickEvent event) { GUIInventory guiInventory = nPlayer.getGuiInventory(); if(guiInventory != null) { - guiInventory.onClick(event); event.setCancelled(true); + + if(event.getSlot() == inventory.getSize()-1 && event.getCurrentItem().equals(Message.INVENTORY_GUI_BACK.getItemStack())) { + player.closeInventory(); + return; + } + + guiInventory.onClick(event); } } diff --git a/src/main/java/co/marcin/novaguilds/util/ChestGUIUtils.java b/src/main/java/co/marcin/novaguilds/util/ChestGUIUtils.java index f7157f09..6dc53254 100644 --- a/src/main/java/co/marcin/novaguilds/util/ChestGUIUtils.java +++ b/src/main/java/co/marcin/novaguilds/util/ChestGUIUtils.java @@ -22,7 +22,9 @@ import co.marcin.novaguilds.enums.Message; import co.marcin.novaguilds.interfaces.GUIInventory; import org.bukkit.Bukkit; +import org.bukkit.Material; import org.bukkit.inventory.Inventory; +import org.bukkit.inventory.ItemStack; import java.util.ArrayList; import java.util.List; @@ -44,7 +46,15 @@ public static void openGUIInventory(NovaPlayer nPlayer, GUIInventory guiInventor guiInventory.setViewer(nPlayer); guiInventory.generateContent(); - nPlayer.getPlayer().openInventory(guiInventory.getInventory()); + + Inventory inventory = guiInventory.getInventory(); + + ItemStack lastItem = inventory.getItem(inventory.getSize() - 1); + if((lastItem == null || lastItem.getType() == Material.AIR) && nPlayer.getGuiInventoryHistory().size()>1) { + inventory.setItem(inventory.getSize()-1, Message.INVENTORY_GUI_BACK.getItemStack()); + } + + nPlayer.getPlayer().openInventory(inventory); guiContinueList.remove(nPlayer); } diff --git a/src/main/resources/lang/de-de.yml b/src/main/resources/lang/de-de.yml index 9edae67f..e44540c9 100644 --- a/src/main/resources/lang/de-de.yml +++ b/src/main/resources/lang/de-de.yml @@ -487,6 +487,7 @@ inventory: ggui: name: Gilden Menü gui: + back: "REDSTONE_TORCH_ON 1 name:&cBack" playerslist: title: "Spieker Liste" iconitem: "SKULL_ITEM:3 1 name:Spieler_Liste" diff --git a/src/main/resources/lang/en-en.yml b/src/main/resources/lang/en-en.yml index 4250680b..e0b4bd81 100644 --- a/src/main/resources/lang/en-en.yml +++ b/src/main/resources/lang/en-en.yml @@ -487,6 +487,7 @@ inventory: ggui: name: Guild's Menu gui: + back: "REDSTONE_TORCH_ON 1 name:&cBack" playerslist: title: "Players list" iconitem: "SKULL_ITEM:3 1 name:Players_list" diff --git a/src/main/resources/lang/pl-pl.yml b/src/main/resources/lang/pl-pl.yml index c4cd6b7f..8f1c5c15 100644 --- a/src/main/resources/lang/pl-pl.yml +++ b/src/main/resources/lang/pl-pl.yml @@ -487,6 +487,7 @@ inventory: ggui: name: Menu Gildii gui: + back: "REDSTONE_TORCH_ON 1 name:&cPowrót" playerslist: title: "Lista członków" iconitem: "SKULL_ITEM:3 1 name:Lista_członków" diff --git a/src/main/resources/lang/zh-cn.yml b/src/main/resources/lang/zh-cn.yml index f05dd73c..29d92fb6 100644 --- a/src/main/resources/lang/zh-cn.yml +++ b/src/main/resources/lang/zh-cn.yml @@ -487,6 +487,7 @@ inventory: ggui: name: "公会菜单" gui: + back: "REDSTONE_TORCH_ON 1 name:&cBack" playerslist: title: "队员列表" iconitem: "SKULL_ITEM:3 1 name:队员列表"