Skip to content
This repository has been archived by the owner on Jan 16, 2019. It is now read-only.

Commit

Permalink
allow crafting inventories that sometimes work, for DenizenScript#1872
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 16, 2019
1 parent 13ede02 commit 8c40fce
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 9 deletions.
Expand Up @@ -32,12 +32,7 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.HorseInventory;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder;
import org.bukkit.inventory.ItemStack;
import org.bukkit.inventory.PlayerInventory;
import org.bukkit.inventory.*;
import org.bukkit.inventory.meta.BookMeta;

import java.util.*;
Expand Down Expand Up @@ -88,7 +83,7 @@ public static dInventory mirrorBukkitInventory(Inventory inventory) {
public final static int maxSlots = 54;

// All of the inventory id types we use
public final static String[] idTypes = {"npc", "player", "enderchest", "workbench", "entity", "location", "generic"};
public final static String[] idTypes = {"npc", "player", "crafting", "enderchest", "workbench", "entity", "location", "generic"};


/////////////////////
Expand Down Expand Up @@ -246,6 +241,16 @@ else if (type.equals("npc")) {
return dNPC.valueOf(holder).getDenizenInventory();
}
}
else if (type.equals("crafting")) {
if (dPlayer.matches(holder)) {
dPlayer holderPlayer = dPlayer.valueOf(holder);
Inventory opened = holderPlayer.getPlayerEntity().getOpenInventory().getTopInventory();
if (opened instanceof CraftingInventory) {
return new dInventory(opened);
}
return dPlayer.valueOf(holder).getInventory();
}
}
else if (type.equals("player")) {
if (dPlayer.matches(holder)) {
return dPlayer.valueOf(holder).getInventory();
Expand Down Expand Up @@ -580,8 +585,7 @@ else if (holder instanceof Player) {
return;
}
if (inventory.getType() == InventoryType.CRAFTING) {
idType = "player";
inventory = ((Player) holder).getInventory();
idType = "crafting";
}
if (inventory.getType() == InventoryType.ENDER_CHEST) {
idType = "enderchest";
Expand Down Expand Up @@ -645,6 +649,13 @@ public dInventory setIdentifiers(String type, String holder) {
return this;
}

/**
* Generally shouldn't be used.
*/
public void setIdType(String type) {
idType = type;
}

public String getIdType() {
return idType == null ? "" : idType;
}
Expand Down
Expand Up @@ -15,6 +15,8 @@
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.CraftingInventory;
import org.bukkit.inventory.Inventory;

public class InventoryHolder implements Property {

Expand Down Expand Up @@ -91,6 +93,14 @@ public void setHolder(dPlayer player) {
else if (inventory.getIdType().equals("workbench")) {
inventory.setInventory(player.getBukkitWorkbench(), player);
}
else if (inventory.getIdType().equals("crafting")) {
Inventory opened = player.getPlayerEntity().getOpenInventory().getTopInventory();
if (opened instanceof CraftingInventory) {
inventory.setInventory(opened, player);
}
inventory.setIdType("player");
inventory.setInventory(player.getBukkitInventory(), player);
}
else {
inventory.setInventory(player.getBukkitInventory(), player);
}
Expand Down

0 comments on commit 8c40fce

Please sign in to comment.