Skip to content

Commit

Permalink
Better way to get inventory. This prevents problems with other plugins.
Browse files Browse the repository at this point in the history
  • Loading branch information
lishid committed Sep 13, 2014
1 parent be5f784 commit 9491153
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (C) 2011-2012 lishid. All rights reserved.
Copyright (C) 2011-2014 lishid. All rights reserved.

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
Expand Down
28 changes: 26 additions & 2 deletions src/com/lishid/openinv/internal/v1_7_R4/InventoryAccess.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.lishid.openinv.internal.v1_7_R4;

import java.lang.reflect.Field;

import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory;

Expand All @@ -29,8 +31,8 @@

public class InventoryAccess implements IInventoryAccess {
public boolean check(Inventory inventory, HumanEntity player) {
IInventory inv = ((CraftInventory) inventory).getInventory();

IInventory inv = grabInventory(inventory);
if (inv instanceof SpecialPlayerInventory) {
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
return false;
Expand All @@ -45,4 +47,26 @@ else if (inv instanceof SpecialEnderChest) {

return true;
}

private IInventory grabInventory(Inventory inventory) {
if(inventory instanceof CraftInventory) {
return ((CraftInventory) inventory).getInventory();
}

//Use reflection to find the iiventory
Class<? extends Inventory> clazz = inventory.getClass();
IInventory result = null;
for(Field f : clazz.getDeclaredFields()) {
f.setAccessible(true);
if(IInventory.class.isAssignableFrom(f.getDeclaringClass())) {
try {
result = (IInventory) f.get(inventory);
}
catch (Exception e) {
OpenInv.log(e);
}
}
}
return result;
}
}
2 changes: 1 addition & 1 deletion src/plugin.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: OpenInv
main: com.lishid.openinv.OpenInv
version: 2.2.2
version: 2.2.4
author: lishid
description: >
This plugin allows you to open a player's inventory as a chest and interact with it in real time.
Expand Down

0 comments on commit 9491153

Please sign in to comment.