Skip to content

Commit

Permalink
Added null checks to inventories and inventory titles to avoid errors
Browse files Browse the repository at this point in the history
with customize inventories that do not have titles or holders.
  • Loading branch information
tastybento committed May 11, 2016
1 parent 4ae7861 commit 276b57a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ protected static boolean inWorld(Location loc) {
*/
@EventHandler(priority = EventPriority.LOW, ignoreCancelled=true)
public void onHorseInventoryClick(InventoryClickEvent event) {
if (!(event.getInventory().getHolder() instanceof Horse)) {
if (event.getInventory().getHolder() == null || !(event.getInventory().getHolder() instanceof Horse)) {
//plugin.getLogger().info("DEBUG: not a horse!");
return;
}
Expand Down
2 changes: 1 addition & 1 deletion src/com/wasteofplastic/askyblock/panels/BiomesPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ public void onInventoryClick(InventoryClickEvent event) {
// clicked in
int slot = event.getRawSlot();
// Check this is the right panel
if (!inventory.getName().equals(plugin.myLocale().biomePanelTitle)) {
if (inventory.getName() == null || !inventory.getName().equals(plugin.myLocale().biomePanelTitle)) {
return;
}
if (slot == -999) {
Expand Down
6 changes: 4 additions & 2 deletions src/com/wasteofplastic/askyblock/panels/ControlPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,10 @@ public void onInventoryClick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked(); // The player that
// clicked the item
ItemStack clicked = event.getCurrentItem(); // The item that was clicked
Inventory inventory = event.getInventory(); // The inventory that was
// clicked in
Inventory inventory = event.getInventory(); // The inventory that was clicked in
if (inventory.getName() == null) {
return;
}
// ASkyBlock plugin = ASkyBlock.getPlugin();
int slot = event.getRawSlot();
// Challenges
Expand Down
6 changes: 4 additions & 2 deletions src/com/wasteofplastic/askyblock/panels/SchematicsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,10 @@ public Inventory getPanel(Player player) {
public void onInventoryClick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked(); // The player that
// clicked the item
Inventory inventory = event.getInventory(); // The inventory that was
// clicked in
Inventory inventory = event.getInventory(); // The inventory that was clicked in
if (inventory.getName() == null) {
return;
}
int slot = event.getRawSlot();
// Check this is the right panel
if (!inventory.getName().equals(plugin.myLocale(player.getUniqueId()).schematicsTitle)) {
Expand Down
3 changes: 3 additions & 0 deletions src/com/wasteofplastic/askyblock/panels/SettingsPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ public Inventory islandGuardPanel(Player player) {
public void onInventoryClick(InventoryClickEvent event) {
Player player = (Player) event.getWhoClicked(); // The player that clicked the item
Inventory inventory = event.getInventory(); // The inventory that was clicked in
if (inventory.getName() == null) {
return;
}
int slot = event.getRawSlot();
// Check this is the right panel
if (!inventory.getName().equals(plugin.myLocale(player.getUniqueId()).igsTitle)) {
Expand Down
3 changes: 3 additions & 0 deletions src/com/wasteofplastic/askyblock/panels/WarpPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ public Inventory getWarpPanel(int panelNumber) {
@EventHandler(priority = EventPriority.LOWEST, ignoreCancelled=true)
public void onInventoryClick(InventoryClickEvent event) {
Inventory inventory = event.getInventory(); // The inventory that was clicked in
if (inventory.getName() == null) {
return;
}
String title = inventory.getTitle();
if (!inventory.getTitle().startsWith(plugin.myLocale().warpsTitle + " #")) {
return;
Expand Down

0 comments on commit 276b57a

Please sign in to comment.