Permalink
Browse files

Fix getting the id of certain virtual inventory types.

This is due to a recent change in how Bukkit handles creating certain inventory types like Hoppers. Bukkit now ignores any holder you pass in for these types, returning null if you retrieve the holder from these inventory objects.
  • Loading branch information...
PseudoKnight committed Sep 5, 2018
1 parent 66cd510 commit 76145824711194fbc7e0b71b1dcf9e682f2e4137
@@ -12,6 +12,7 @@
import com.laytonsmith.core.LogLevel;
import com.laytonsmith.core.constructs.Target;
import com.laytonsmith.core.exceptions.CRE.CRERangeException;
import com.laytonsmith.core.functions.InventoryManagement;
import org.bukkit.block.BlockState;
import org.bukkit.block.DoubleChest;
import org.bukkit.entity.Entity;
@@ -148,6 +149,12 @@ public MCInventoryHolder getHolder() {
return new BukkitMCVirtualInventoryHolder(ih);
} else if(ih instanceof DoubleChest) {
return new BukkitMCDoubleChest((DoubleChest) ih);
} else if(ih == null) {
for(Map.Entry<String, MCInventory> entry : InventoryManagement.VIRTUAL_INVENTORIES.entrySet()) {
if(entry.getValue().equals(this)) {
return new BukkitMCVirtualInventoryHolder(entry.getKey());
}
}
}
return new BukkitMCInventoryHolder(ih);
}
@@ -391,9 +391,9 @@ public BindableEvent convert(CArray manualObject, Target t) {
}
map.put("inventory", items);
map.put("inventorytype", new CString(e.getInventory().getType().name(), t));
map.put("holder", InventoryManagement.GetInventoryHolder(e.getInventory(), t));
map.put("virtual", CBoolean.get(e.getInventory().getHolder() instanceof MCVirtualInventoryHolder));
map.put("inventorytype", new CString(inv.getType().name(), t));
map.put("holder", InventoryManagement.GetInventoryHolder(inv, t));
map.put("virtual", CBoolean.get(inv.getHolder() instanceof MCVirtualInventoryHolder));
return map;
} else {
@@ -473,9 +473,9 @@ public BindableEvent convert(CArray manualObject, Target t) {
}
map.put("inventory", items);
map.put("inventorytype", new CString(e.getInventory().getType().name(), t));
map.put("holder", InventoryManagement.GetInventoryHolder(e.getInventory(), t));
map.put("virtual", CBoolean.get(e.getInventory().getHolder() instanceof MCVirtualInventoryHolder));
map.put("inventorytype", new CString(inv.getType().name(), t));
map.put("holder", InventoryManagement.GetInventoryHolder(inv, t));
map.put("virtual", CBoolean.get(inv.getHolder() instanceof MCVirtualInventoryHolder));
return map;
} else {

0 comments on commit 7614582

Please sign in to comment.