Skip to content

Commit

Permalink
+ Back button in GUIInventory
Browse files Browse the repository at this point in the history
#51 Missing translations
  • Loading branch information
MarcinWieczorek committed Jan 10, 2016
1 parent 30512bc commit 324d043
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/main/java/co/marcin/novaguilds/enums/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 12 additions & 2 deletions src/main/java/co/marcin/novaguilds/listener/ChestGUIListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}

Expand All @@ -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);
}
}

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/co/marcin/novaguilds/util/ChestGUIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/de-de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/en-en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/pl-pl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/main/resources/lang/zh-cn.yml
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,7 @@ inventory:
ggui:
name: "公会菜单"
gui:
back: "REDSTONE_TORCH_ON 1 name:&cBack"
playerslist:
title: "队员列表"
iconitem: "SKULL_ITEM:3 1 name:队员列表"
Expand Down

0 comments on commit 324d043

Please sign in to comment.