From 40c9547a298a72b5ef83e9f5eee643dcc1f5adce Mon Sep 17 00:00:00 2001 From: Daniel Saukel Date: Thu, 5 Oct 2017 17:00:48 +0200 Subject: [PATCH] Fix announcer GUI exceptions --- .../io/github/dre2n/dungeonsxl/announcer/Announcer.java | 6 +++++- .../dre2n/dungeonsxl/announcer/AnnouncerListener.java | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java b/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java index 5fd5e2c8..2819556e 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/announcer/Announcer.java @@ -458,7 +458,11 @@ public class Announcer { */ public DGroup getDGroupByButton(ItemStack button) { int index = buttons.indexOf(button); - return dGroups.get(index); + if (dGroups.size() <= index || index < 0) { + return null; + } else { + return dGroups.get(index); + } } } diff --git a/src/main/java/io/github/dre2n/dungeonsxl/announcer/AnnouncerListener.java b/src/main/java/io/github/dre2n/dungeonsxl/announcer/AnnouncerListener.java index a0b795b6..a2d376e5 100644 --- a/src/main/java/io/github/dre2n/dungeonsxl/announcer/AnnouncerListener.java +++ b/src/main/java/io/github/dre2n/dungeonsxl/announcer/AnnouncerListener.java @@ -23,6 +23,7 @@ import org.bukkit.event.Listener; import org.bukkit.event.inventory.InventoryClickEvent; import org.bukkit.inventory.Inventory; import org.bukkit.inventory.ItemStack; +import org.bukkit.material.Wool; /** * @author Daniel Saukel @@ -37,9 +38,9 @@ public class AnnouncerListener implements Listener { Player player = (Player) event.getWhoClicked(); Inventory gui = event.getInventory(); - ItemStack button = gui.getItem(event.getSlot()); + ItemStack button = event.getCurrentItem(); Announcer announcer = DungeonsXL.getInstance().getAnnouncers().getByGUI(gui); - if (announcer != null) { + if (announcer != null && button != null && button.getData() instanceof Wool) { announcer.clickGroupButton(player, button); } }