Skip to content

Commit

Permalink
Fix pinventory_holder() in versions prior to 1.21
Browse files Browse the repository at this point in the history
InventoryView was changed from an abstract class to an interface in the latest spigot commit
  • Loading branch information
PseudoKnight committed Jun 16, 2024
1 parent 5b137ff commit 15d2b5b
Showing 1 changed file with 12 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.laytonsmith.abstraction.bukkit;

import com.laytonsmith.PureUtilities.Common.ReflectionUtils;
import com.laytonsmith.abstraction.MCHumanEntity;
import com.laytonsmith.abstraction.MCInventory;
import com.laytonsmith.abstraction.MCInventoryView;
import com.laytonsmith.abstraction.MCItemStack;
import com.laytonsmith.abstraction.bukkit.entities.BukkitMCHumanEntity;
import com.laytonsmith.abstraction.enums.MCInventoryType;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.InventoryView;

public class BukkitMCInventoryView implements MCInventoryView {
Expand Down Expand Up @@ -33,27 +35,27 @@ public int hashCode() {

@Override
public MCInventory getBottomInventory() {
return new BukkitMCInventory(iv.getBottomInventory());
return new BukkitMCInventory(ReflectionUtils.invokeMethod(iv, "getBottomInventory"));
}

@Override
public MCInventory getTopInventory() {
return new BukkitMCInventory(iv.getTopInventory());
return new BukkitMCInventory(ReflectionUtils.invokeMethod(iv, "getTopInventory"));
}

@Override
public void close() {
iv.close();
ReflectionUtils.invokeMethod(iv, "close");
}

@Override
public int countSlots() {
return iv.countSlots();
return ReflectionUtils.invokeMethod(iv, "countSlots");
}

@Override
public int convertSlot(int rawSlot) {
return iv.convertSlot(rawSlot);
return ReflectionUtils.invokeMethod(iv, "convertSlot", rawSlot);
}

@Override
Expand All @@ -63,26 +65,26 @@ public MCItemStack getItem(int slot) {

@Override
public MCHumanEntity getPlayer() {
return new BukkitMCHumanEntity(iv.getPlayer());
return new BukkitMCHumanEntity(ReflectionUtils.invokeMethod(iv, "getPlayer"));
}

@Override
public String getTitle() {
return iv.getTitle();
return ReflectionUtils.invokeMethod(iv, "getTitle");
}

@Override
public MCInventoryType getType() {
return MCInventoryType.valueOf(this.iv.getType().name());
return MCInventoryType.valueOf(((InventoryType) ReflectionUtils.invokeMethod(iv, "getType")).name());
}

@Override
public void setCursor(MCItemStack item) {
iv.setCursor(((BukkitMCItemStack) item).__ItemStack());
ReflectionUtils.invokeMethod(iv, "setCursor", ((BukkitMCItemStack) item).__ItemStack());
}

@Override
public void setItem(int slot, MCItemStack item) {
iv.setItem(slot, (((BukkitMCItemStack) item).__ItemStack()));
ReflectionUtils.invokeMethod(iv, "setItem", slot, (((BukkitMCItemStack) item).__ItemStack()));
}
}

0 comments on commit 15d2b5b

Please sign in to comment.