Better way to get inventory. This prevents problems with other plugins.

This commit is contained in:
lishid 2014-09-12 23:17:41 -07:00
parent be5f784d74
commit 9491153e30
3 changed files with 28 additions and 4 deletions

2
README
View file

@ -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 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 it under the terms of the GNU General Public License as published by

View file

@ -16,6 +16,8 @@
package com.lishid.openinv.internal.v1_7_R4; package com.lishid.openinv.internal.v1_7_R4;
import java.lang.reflect.Field;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
@ -29,8 +31,8 @@ import org.bukkit.craftbukkit.v1_7_R4.inventory.*;
public class InventoryAccess implements IInventoryAccess { public class InventoryAccess implements IInventoryAccess {
public boolean check(Inventory inventory, HumanEntity player) { public boolean check(Inventory inventory, HumanEntity player) {
IInventory inv = ((CraftInventory) inventory).getInventory(); IInventory inv = grabInventory(inventory);
if (inv instanceof SpecialPlayerInventory) { if (inv instanceof SpecialPlayerInventory) {
if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) { if (!OpenInv.hasPermission(player, Permissions.PERM_EDITINV)) {
return false; return false;
@ -45,4 +47,26 @@ public class InventoryAccess implements IInventoryAccess {
return true; 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;
}
} }

View file

@ -1,6 +1,6 @@
name: OpenInv name: OpenInv
main: com.lishid.openinv.OpenInv main: com.lishid.openinv.OpenInv
version: 2.2.2 version: 2.2.4
author: lishid author: lishid
description: > description: >
This plugin allows you to open a player's inventory as a chest and interact with it in real time. This plugin allows you to open a player's inventory as a chest and interact with it in real time.