mirror of
https://github.com/JamesPeters98/ChestsPlusPlus.git
synced 2024-11-25 12:06:09 +01:00
Merge branch 'master' into Database_Migration
This commit is contained in:
commit
816a1eb9cc
@ -9,7 +9,7 @@ before_install:
|
||||
- export JAVA_HOME=$HOME/openjdk16
|
||||
- $TRAVIS_BUILD_DIR/BuildTools/install-jdk.sh -F 16 --target $JAVA_HOME
|
||||
- export PATH=$JAVA_HOME/bin:$PATH
|
||||
- bash build-1.17+.sh
|
||||
#- bash build-1.17+.sh
|
||||
- cd ../
|
||||
|
||||
install:
|
||||
|
@ -3,6 +3,8 @@ package com.jamesdpeters.minecraft.chests;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.plugin.Plugin;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class Api {
|
||||
|
||||
private static Plugin plugin;
|
||||
@ -21,13 +23,11 @@ public class Api {
|
||||
String nmsProvider = packageName + "." + nmsVersion + ".NMSProviderImpl";
|
||||
plugin.getLogger().info("Found API version: " + nmsVersion);
|
||||
try {
|
||||
return (NMSProvider) Class.forName(nmsProvider).newInstance();
|
||||
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException e) {
|
||||
plugin.getLogger().warning("A valid server implementation wasn't found for: " + nmsVersion);
|
||||
plugin.getLogger().warning("You may be running an outdated version of the plugin or it needs to be updated to the latest version!");
|
||||
|
||||
// Currently depends on NMS for any Crafting abilities
|
||||
throw new RuntimeException("Currently no NMS version support for "+nmsVersion);
|
||||
return (NMSProvider) Class.forName(nmsProvider).getDeclaredConstructor().newInstance();
|
||||
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException | NoSuchMethodException | InvocationTargetException e) {
|
||||
// Plugin now doesn't depend on NMS after 1.17.
|
||||
// So NMSProviderDefault is used for all versions 1.17+
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,11 +5,9 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface CraftingProvider {
|
||||
|
||||
CraftingResult craft(Player player, World world, List<ItemStack> items);
|
||||
CraftingResult craft(Player player, World world, ItemStack[] items);
|
||||
|
||||
Recipe getRecipe(Player player, World world, List<ItemStack> items);
|
||||
Recipe getRecipe(Player player, World world, ItemStack[] items);
|
||||
}
|
||||
|
@ -2,17 +2,22 @@ package com.jamesdpeters.minecraft.chests;
|
||||
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class CraftingResult {
|
||||
ItemStack result;
|
||||
List<ItemStack> matrixResult;
|
||||
ItemStack[] matrixResult;
|
||||
|
||||
public List<ItemStack> getMatrixResult() {
|
||||
public CraftingResult(ItemStack result, ItemStack[] matrixResult) {
|
||||
this.result = result;
|
||||
this.matrixResult = matrixResult;
|
||||
}
|
||||
|
||||
public CraftingResult() {}
|
||||
|
||||
public ItemStack[] getMatrixResult() {
|
||||
return matrixResult;
|
||||
}
|
||||
|
||||
public void setMatrixResult(List<ItemStack> matrixResult) {
|
||||
public void setMatrixResult(ItemStack[] matrixResult) {
|
||||
this.matrixResult = matrixResult;
|
||||
}
|
||||
|
||||
|
@ -6,7 +6,6 @@ public interface NMSProvider {
|
||||
ChestOpener getChestOpener();
|
||||
MaterialChecker getMaterialChecker();
|
||||
CraftingProvider getCraftingProvider();
|
||||
NPCProvider getNPCProvider();
|
||||
|
||||
void setItemFrameVisible(ItemFrame itemFrame, boolean visible);
|
||||
}
|
||||
|
@ -3,75 +3,67 @@ package com.jamesdpeters.minecraft.chests.v1_14_R1;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingProvider;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingResult;
|
||||
import net.minecraft.server.v1_14_R1.Container;
|
||||
import net.minecraft.server.v1_14_R1.ContainerWorkbench;
|
||||
import net.minecraft.server.v1_14_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_14_R1.IRecipe;
|
||||
import net.minecraft.server.v1_14_R1.InventoryCraftResult;
|
||||
import net.minecraft.server.v1_14_R1.InventoryCrafting;
|
||||
import net.minecraft.server.v1_14_R1.Item;
|
||||
import net.minecraft.server.v1_14_R1.RecipeCrafting;
|
||||
import net.minecraft.server.v1_14_R1.RecipeRepair;
|
||||
import net.minecraft.server.v1_14_R1.Recipes;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.event.CraftEventFactory;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryCrafting;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftInventoryView;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Crafting implements CraftingProvider {
|
||||
|
||||
@Override
|
||||
public CraftingResult craft(Player player, World world, List<ItemStack> items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityHuman) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
InventoryCrafting crafting = new InventoryCrafting(container, 3, 3);
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items.get(i)));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
public CraftingResult craft(Player player, World world, ItemStack[] items) {
|
||||
CraftWorld craftWorld = (CraftWorld) world;
|
||||
Optional<RecipeCrafting> optional = server.getServer().getCraftingManager().craft(Recipes.CRAFTING, crafting, craftWorld.getHandle());
|
||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||
ContainerWorkbench workbench = new ContainerWorkbench(-1, craftPlayer.getHandle().inventory);
|
||||
|
||||
CraftInventoryView view = workbench.getBukkitView();
|
||||
CraftInventoryCrafting craftInventoryCrafting = (CraftInventoryCrafting) view.getTopInventory();
|
||||
InventoryCrafting inventoryCrafting = (InventoryCrafting) craftInventoryCrafting.getMatrixInventory();
|
||||
InventoryCraftResult resultInventory = (InventoryCraftResult) craftInventoryCrafting.getResultInventory();
|
||||
|
||||
Optional<RecipeCrafting> recipe = getNMSRecipe(items, inventoryCrafting, craftWorld);
|
||||
|
||||
net.minecraft.server.v1_14_R1.ItemStack itemstack = net.minecraft.server.v1_14_R1.ItemStack.a;
|
||||
|
||||
if (optional.isPresent()) {
|
||||
RecipeCrafting recipeCrafting = optional.get();
|
||||
itemstack = recipeCrafting.a(crafting);
|
||||
if (recipe.isPresent()) {
|
||||
RecipeCrafting recipeCrafting = recipe.get();
|
||||
if (resultInventory.a(craftWorld.getHandle(), craftPlayer.getHandle(), recipeCrafting)) {
|
||||
itemstack = recipeCrafting.a(inventoryCrafting);
|
||||
}
|
||||
}
|
||||
|
||||
CraftingResult result = new CraftingResult();
|
||||
result.setResult(CraftItemStack.asBukkitCopy(itemstack));
|
||||
net.minecraft.server.v1_14_R1.ItemStack result = CraftEventFactory.callPreCraftEvent(inventoryCrafting, resultInventory, itemstack, view, recipe.orElse(null) instanceof RecipeRepair);
|
||||
|
||||
List<ItemStack> matrixResult = crafting.getContents().stream()
|
||||
.map(itemStack -> {
|
||||
Item remainingItem = itemStack.getItem().n();
|
||||
return remainingItem != null ? CraftItemStack.asBukkitCopy(new net.minecraft.server.v1_14_R1.ItemStack(remainingItem)) : null;
|
||||
}).collect(Collectors.toList());
|
||||
for(int i = 0; i < items.length; ++i) {
|
||||
Item remaining = inventoryCrafting.getContents().get(i).getItem().n();
|
||||
items[i] = remaining != null ? CraftItemStack.asBukkitCopy(new net.minecraft.server.v1_14_R1.ItemStack(remaining)) : null;
|
||||
}
|
||||
|
||||
result.setMatrixResult(matrixResult);
|
||||
|
||||
return result;
|
||||
return new CraftingResult(CraftItemStack.asBukkitCopy(result), items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(Player player, World world, List<ItemStack> items) {
|
||||
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
@ -86,9 +78,9 @@ public class Crafting implements CraftingProvider {
|
||||
|
||||
InventoryCrafting crafting = new InventoryCrafting(container, 3, 3);
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if(i >= 9) break; // ItemList cant contain more than 9 items.
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items.get(i)));
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
@ -96,6 +88,14 @@ public class Crafting implements CraftingProvider {
|
||||
Optional<RecipeCrafting> optional = server.getServer().getCraftingManager().craft(Recipes.CRAFTING, crafting, craftWorld.getHandle());
|
||||
|
||||
return optional.map(IRecipe::toBukkitRecipe).orElse(null);
|
||||
}
|
||||
|
||||
private Optional<RecipeCrafting> getNMSRecipe(ItemStack[] craftingMatrix, InventoryCrafting inventoryCrafting, CraftWorld world) {
|
||||
for(int i = 0; i < craftingMatrix.length; ++i) {
|
||||
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(craftingMatrix[i]));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
return server.getServer().getCraftingManager().craft(Recipes.CRAFTING, inventoryCrafting, world.getHandle());
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,6 @@ public class NMSProviderImpl implements NMSProvider {
|
||||
return new Crafting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPCProvider getNPCProvider() {
|
||||
return new NPC();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
|
||||
//Not support in 1.14
|
||||
|
@ -1,24 +0,0 @@
|
||||
package com.jamesdpeters.minecraft.chests.v1_14_R1;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.NPCProvider;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.server.v1_14_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_14_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_14_R1.PlayerInteractManager;
|
||||
import net.minecraft.server.v1_14_R1.WorldServer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_14_R1.CraftWorld;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class NPC implements NPCProvider {
|
||||
public HumanEntity createHumanEntity() {
|
||||
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
WorldServer nmsWorld = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
|
||||
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "Chests++NPC");
|
||||
EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, new PlayerInteractManager(nmsWorld));
|
||||
return npc.getBukkitEntity();
|
||||
}
|
||||
}
|
@ -3,75 +3,67 @@ package com.jamesdpeters.minecraft.chests.v1_15_R1;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingProvider;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingResult;
|
||||
import net.minecraft.server.v1_15_R1.Container;
|
||||
import net.minecraft.server.v1_15_R1.ContainerWorkbench;
|
||||
import net.minecraft.server.v1_15_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_15_R1.IRecipe;
|
||||
import net.minecraft.server.v1_15_R1.InventoryCraftResult;
|
||||
import net.minecraft.server.v1_15_R1.InventoryCrafting;
|
||||
import net.minecraft.server.v1_15_R1.Item;
|
||||
import net.minecraft.server.v1_15_R1.RecipeCrafting;
|
||||
import net.minecraft.server.v1_15_R1.RecipeRepair;
|
||||
import net.minecraft.server.v1_15_R1.Recipes;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.event.CraftEventFactory;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryCrafting;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftInventoryView;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Crafting implements CraftingProvider {
|
||||
|
||||
@Override
|
||||
public CraftingResult craft(Player player, World world, List<ItemStack> items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityHuman) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
InventoryCrafting crafting = new InventoryCrafting(container, 3, 3);
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items.get(i)));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
public CraftingResult craft(Player player, World world, ItemStack[] items) {
|
||||
CraftWorld craftWorld = (CraftWorld) world;
|
||||
Optional<RecipeCrafting> optional = server.getServer().getCraftingManager().craft(Recipes.CRAFTING, crafting, craftWorld.getHandle());
|
||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||
ContainerWorkbench workbench = new ContainerWorkbench(-1, craftPlayer.getHandle().inventory);
|
||||
|
||||
CraftInventoryView view = workbench.getBukkitView();
|
||||
CraftInventoryCrafting craftInventoryCrafting = (CraftInventoryCrafting) view.getTopInventory();
|
||||
InventoryCrafting inventoryCrafting = (InventoryCrafting) craftInventoryCrafting.getMatrixInventory();
|
||||
InventoryCraftResult resultInventory = (InventoryCraftResult) craftInventoryCrafting.getResultInventory();
|
||||
|
||||
Optional<RecipeCrafting> recipe = getNMSRecipe(items, inventoryCrafting, craftWorld);
|
||||
|
||||
net.minecraft.server.v1_15_R1.ItemStack itemstack = net.minecraft.server.v1_15_R1.ItemStack.a;
|
||||
|
||||
if (optional.isPresent()) {
|
||||
RecipeCrafting recipeCrafting = optional.get();
|
||||
itemstack = recipeCrafting.a(crafting);
|
||||
if (recipe.isPresent()) {
|
||||
RecipeCrafting recipeCrafting = recipe.get();
|
||||
if (resultInventory.a(craftWorld.getHandle(), craftPlayer.getHandle(), recipeCrafting)) {
|
||||
itemstack = recipeCrafting.a(inventoryCrafting);
|
||||
}
|
||||
}
|
||||
|
||||
CraftingResult result = new CraftingResult();
|
||||
result.setResult(CraftItemStack.asBukkitCopy(itemstack));
|
||||
net.minecraft.server.v1_15_R1.ItemStack result = CraftEventFactory.callPreCraftEvent(inventoryCrafting, resultInventory, itemstack, view, recipe.orElse(null) instanceof RecipeRepair);
|
||||
|
||||
List<ItemStack> matrixResult = crafting.getContents().stream()
|
||||
.map(itemStack -> {
|
||||
Item remainingItem = itemStack.getItem().p();
|
||||
return remainingItem != null ? CraftItemStack.asBukkitCopy(new net.minecraft.server.v1_15_R1.ItemStack(remainingItem)) : null;
|
||||
}).collect(Collectors.toList());
|
||||
for(int i = 0; i < items.length; ++i) {
|
||||
Item remaining = inventoryCrafting.getContents().get(i).getItem().p();
|
||||
items[i] = remaining != null ? CraftItemStack.asBukkitCopy(new net.minecraft.server.v1_15_R1.ItemStack(remaining)) : null;
|
||||
}
|
||||
|
||||
result.setMatrixResult(matrixResult);
|
||||
|
||||
return result;
|
||||
return new CraftingResult(CraftItemStack.asBukkitCopy(result), items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(Player player, World world, List<ItemStack> items) {
|
||||
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
@ -86,9 +78,9 @@ public class Crafting implements CraftingProvider {
|
||||
|
||||
InventoryCrafting crafting = new InventoryCrafting(container, 3, 3);
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if(i >= 9) break; // ItemList cant contain more than 9 items.
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items.get(i)));
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
@ -96,6 +88,14 @@ public class Crafting implements CraftingProvider {
|
||||
Optional<RecipeCrafting> optional = server.getServer().getCraftingManager().craft(Recipes.CRAFTING, crafting, craftWorld.getHandle());
|
||||
|
||||
return optional.map(IRecipe::toBukkitRecipe).orElse(null);
|
||||
}
|
||||
|
||||
private Optional<RecipeCrafting> getNMSRecipe(ItemStack[] craftingMatrix, InventoryCrafting inventoryCrafting, CraftWorld world) {
|
||||
for(int i = 0; i < craftingMatrix.length; ++i) {
|
||||
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(craftingMatrix[i]));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
return server.getServer().getCraftingManager().craft(Recipes.CRAFTING, inventoryCrafting, world.getHandle());
|
||||
}
|
||||
}
|
||||
|
@ -19,11 +19,6 @@ public class NMSProviderImpl implements NMSProvider {
|
||||
return new Crafting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPCProvider getNPCProvider() {
|
||||
return new NPC();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
|
||||
//Not supported in 1.15
|
||||
|
@ -1,24 +0,0 @@
|
||||
package com.jamesdpeters.minecraft.chests.v1_15_R1;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.NPCProvider;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.server.v1_15_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_15_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_15_R1.PlayerInteractManager;
|
||||
import net.minecraft.server.v1_15_R1.WorldServer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_15_R1.CraftWorld;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class NPC implements NPCProvider {
|
||||
public HumanEntity createHumanEntity() {
|
||||
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
WorldServer nmsWorld = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
|
||||
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "Chests++NPC");
|
||||
EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, new PlayerInteractManager(nmsWorld));
|
||||
return npc.getBukkitEntity();
|
||||
}
|
||||
}
|
@ -3,75 +3,67 @@ package com.jamesdpeters.minecraft.chests.v1_16_R1;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingProvider;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingResult;
|
||||
import net.minecraft.server.v1_16_R1.Container;
|
||||
import net.minecraft.server.v1_16_R1.ContainerWorkbench;
|
||||
import net.minecraft.server.v1_16_R1.EntityHuman;
|
||||
import net.minecraft.server.v1_16_R1.IRecipe;
|
||||
import net.minecraft.server.v1_16_R1.InventoryCraftResult;
|
||||
import net.minecraft.server.v1_16_R1.InventoryCrafting;
|
||||
import net.minecraft.server.v1_16_R1.Item;
|
||||
import net.minecraft.server.v1_16_R1.RecipeCrafting;
|
||||
import net.minecraft.server.v1_16_R1.RecipeRepair;
|
||||
import net.minecraft.server.v1_16_R1.Recipes;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.event.CraftEventFactory;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventoryCrafting;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftInventoryView;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Crafting implements CraftingProvider {
|
||||
|
||||
@Override
|
||||
public CraftingResult craft(Player player, World world, List<ItemStack> items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityHuman) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
InventoryCrafting crafting = new InventoryCrafting(container, 3, 3);
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items.get(i)));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
public CraftingResult craft(Player player, World world, ItemStack[] items) {
|
||||
CraftWorld craftWorld = (CraftWorld) world;
|
||||
Optional<RecipeCrafting> optional = server.getServer().getCraftingManager().craft(Recipes.CRAFTING, crafting, craftWorld.getHandle());
|
||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||
ContainerWorkbench workbench = new ContainerWorkbench(-1, craftPlayer.getHandle().inventory);
|
||||
|
||||
CraftInventoryView view = workbench.getBukkitView();
|
||||
CraftInventoryCrafting craftInventoryCrafting = (CraftInventoryCrafting) view.getTopInventory();
|
||||
InventoryCrafting inventoryCrafting = (InventoryCrafting) craftInventoryCrafting.getMatrixInventory();
|
||||
InventoryCraftResult resultInventory = (InventoryCraftResult) craftInventoryCrafting.getResultInventory();
|
||||
|
||||
Optional<RecipeCrafting> recipe = getNMSRecipe(items, inventoryCrafting, craftWorld);
|
||||
|
||||
net.minecraft.server.v1_16_R1.ItemStack itemstack = net.minecraft.server.v1_16_R1.ItemStack.b;
|
||||
|
||||
if (optional.isPresent()) {
|
||||
RecipeCrafting recipeCrafting = optional.get();
|
||||
itemstack = recipeCrafting.a(crafting);
|
||||
if (recipe.isPresent()) {
|
||||
RecipeCrafting recipeCrafting = recipe.get();
|
||||
if (resultInventory.a(craftWorld.getHandle(), craftPlayer.getHandle(), recipeCrafting)) {
|
||||
itemstack = recipeCrafting.a(inventoryCrafting);
|
||||
}
|
||||
}
|
||||
|
||||
CraftingResult result = new CraftingResult();
|
||||
result.setResult(CraftItemStack.asBukkitCopy(itemstack));
|
||||
net.minecraft.server.v1_16_R1.ItemStack result = CraftEventFactory.callPreCraftEvent(inventoryCrafting, resultInventory, itemstack, view, recipe.orElse(null) instanceof RecipeRepair);
|
||||
|
||||
List<ItemStack> matrixResult = crafting.getContents().stream()
|
||||
.map(itemStack -> {
|
||||
Item remainingItem = itemStack.getItem().getCraftingRemainingItem();
|
||||
return remainingItem != null ? CraftItemStack.asBukkitCopy(remainingItem.r()) : null;
|
||||
}).collect(Collectors.toList());
|
||||
for(int i = 0; i < items.length; ++i) {
|
||||
Item remaining = inventoryCrafting.getContents().get(i).getItem().getCraftingRemainingItem();
|
||||
items[i] = remaining != null ? CraftItemStack.asBukkitCopy(remaining.r()) : null;
|
||||
}
|
||||
|
||||
result.setMatrixResult(matrixResult);
|
||||
|
||||
return result;
|
||||
return new CraftingResult(CraftItemStack.asBukkitCopy(result), items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(Player player, World world, List<ItemStack> items) {
|
||||
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
@ -86,9 +78,9 @@ public class Crafting implements CraftingProvider {
|
||||
|
||||
InventoryCrafting crafting = new InventoryCrafting(container, 3, 3);
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if(i >= 9) break; // ItemList cant contain more than 9 items.
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items.get(i)));
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
@ -96,6 +88,14 @@ public class Crafting implements CraftingProvider {
|
||||
Optional<RecipeCrafting> optional = server.getServer().getCraftingManager().craft(Recipes.CRAFTING, crafting, craftWorld.getHandle());
|
||||
|
||||
return optional.map(IRecipe::toBukkitRecipe).orElse(null);
|
||||
}
|
||||
|
||||
private Optional<RecipeCrafting> getNMSRecipe(ItemStack[] craftingMatrix, InventoryCrafting inventoryCrafting, CraftWorld world) {
|
||||
for(int i = 0; i < craftingMatrix.length; ++i) {
|
||||
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(craftingMatrix[i]));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
return server.getServer().getCraftingManager().craft(Recipes.CRAFTING, inventoryCrafting, world.getHandle());
|
||||
}
|
||||
}
|
||||
|
@ -32,11 +32,6 @@ public class NMSProviderImpl implements NMSProvider {
|
||||
return new Crafting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPCProvider getNPCProvider() {
|
||||
return new NPC();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
|
||||
itemFrame.setVisible(visible);
|
||||
|
@ -1,24 +0,0 @@
|
||||
package com.jamesdpeters.minecraft.chests.v1_16_R1;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.NPCProvider;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.server.v1_16_R1.EntityPlayer;
|
||||
import net.minecraft.server.v1_16_R1.MinecraftServer;
|
||||
import net.minecraft.server.v1_16_R1.PlayerInteractManager;
|
||||
import net.minecraft.server.v1_16_R1.WorldServer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_16_R1.CraftWorld;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class NPC implements NPCProvider {
|
||||
public HumanEntity createHumanEntity() {
|
||||
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
WorldServer nmsWorld = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
|
||||
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "Chests++NPC");
|
||||
EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, new PlayerInteractManager(nmsWorld));
|
||||
return npc.getBukkitEntity();
|
||||
}
|
||||
}
|
@ -3,75 +3,67 @@ package com.jamesdpeters.minecraft.chests.v1_16_R2;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingProvider;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingResult;
|
||||
import net.minecraft.server.v1_16_R2.Container;
|
||||
import net.minecraft.server.v1_16_R2.ContainerWorkbench;
|
||||
import net.minecraft.server.v1_16_R2.EntityHuman;
|
||||
import net.minecraft.server.v1_16_R2.IRecipe;
|
||||
import net.minecraft.server.v1_16_R2.InventoryCraftResult;
|
||||
import net.minecraft.server.v1_16_R2.InventoryCrafting;
|
||||
import net.minecraft.server.v1_16_R2.Item;
|
||||
import net.minecraft.server.v1_16_R2.RecipeCrafting;
|
||||
import net.minecraft.server.v1_16_R2.RecipeRepair;
|
||||
import net.minecraft.server.v1_16_R2.Recipes;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.event.CraftEventFactory;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftInventoryCrafting;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftInventoryView;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Crafting implements CraftingProvider {
|
||||
|
||||
@Override
|
||||
public CraftingResult craft(Player player, World world, List<ItemStack> items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityHuman) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
InventoryCrafting crafting = new InventoryCrafting(container, 3, 3);
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items.get(i)));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
public CraftingResult craft(Player player, World world, ItemStack[] items) {
|
||||
CraftWorld craftWorld = (CraftWorld) world;
|
||||
Optional<RecipeCrafting> optional = server.getServer().getCraftingManager().craft(Recipes.CRAFTING, crafting, craftWorld.getHandle());
|
||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||
ContainerWorkbench workbench = new ContainerWorkbench(-1, craftPlayer.getHandle().inventory);
|
||||
|
||||
CraftInventoryView view = workbench.getBukkitView();
|
||||
CraftInventoryCrafting craftInventoryCrafting = (CraftInventoryCrafting) view.getTopInventory();
|
||||
InventoryCrafting inventoryCrafting = (InventoryCrafting) craftInventoryCrafting.getMatrixInventory();
|
||||
InventoryCraftResult resultInventory = (InventoryCraftResult) craftInventoryCrafting.getResultInventory();
|
||||
|
||||
Optional<RecipeCrafting> recipe = getNMSRecipe(items, inventoryCrafting, craftWorld);
|
||||
|
||||
net.minecraft.server.v1_16_R2.ItemStack itemstack = net.minecraft.server.v1_16_R2.ItemStack.b;
|
||||
|
||||
if (optional.isPresent()) {
|
||||
RecipeCrafting recipeCrafting = optional.get();
|
||||
itemstack = recipeCrafting.a(crafting);
|
||||
if (recipe.isPresent()) {
|
||||
RecipeCrafting recipeCrafting = recipe.get();
|
||||
if (resultInventory.a(craftWorld.getHandle(), craftPlayer.getHandle(), recipeCrafting)) {
|
||||
itemstack = recipeCrafting.a(inventoryCrafting);
|
||||
}
|
||||
}
|
||||
|
||||
CraftingResult result = new CraftingResult();
|
||||
result.setResult(CraftItemStack.asBukkitCopy(itemstack));
|
||||
net.minecraft.server.v1_16_R2.ItemStack result = CraftEventFactory.callPreCraftEvent(inventoryCrafting, resultInventory, itemstack, view, recipe.orElse(null) instanceof RecipeRepair);
|
||||
|
||||
List<ItemStack> matrixResult = crafting.getContents().stream()
|
||||
.map(itemStack -> {
|
||||
Item remainingItem = itemStack.getItem().getCraftingRemainingItem();
|
||||
return remainingItem != null ? CraftItemStack.asBukkitCopy(remainingItem.createItemStack()) : null;
|
||||
}).collect(Collectors.toList());
|
||||
for(int i = 0; i < items.length; ++i) {
|
||||
Item remaining = inventoryCrafting.getContents().get(i).getItem().getCraftingRemainingItem();
|
||||
items[i] = remaining != null ? CraftItemStack.asBukkitCopy(remaining.createItemStack()) : null;
|
||||
}
|
||||
|
||||
result.setMatrixResult(matrixResult);
|
||||
|
||||
return result;
|
||||
return new CraftingResult(CraftItemStack.asBukkitCopy(result), items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(Player player, World world, List<ItemStack> items) {
|
||||
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
@ -86,9 +78,9 @@ public class Crafting implements CraftingProvider {
|
||||
|
||||
InventoryCrafting crafting = new InventoryCrafting(container, 3, 3);
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if(i >= 9) break; // ItemList cant contain more than 9 items.
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items.get(i)));
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
@ -96,6 +88,14 @@ public class Crafting implements CraftingProvider {
|
||||
Optional<RecipeCrafting> optional = server.getServer().getCraftingManager().craft(Recipes.CRAFTING, crafting, craftWorld.getHandle());
|
||||
|
||||
return optional.map(IRecipe::toBukkitRecipe).orElse(null);
|
||||
}
|
||||
|
||||
private Optional<RecipeCrafting> getNMSRecipe(ItemStack[] craftingMatrix, InventoryCrafting inventoryCrafting, CraftWorld world) {
|
||||
for(int i = 0; i < craftingMatrix.length; ++i) {
|
||||
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(craftingMatrix[i]));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
return server.getServer().getCraftingManager().craft(Recipes.CRAFTING, inventoryCrafting, world.getHandle());
|
||||
}
|
||||
}
|
||||
|
@ -32,11 +32,6 @@ public class NMSProviderImpl implements NMSProvider {
|
||||
return new Crafting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPCProvider getNPCProvider() {
|
||||
return new NPC();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
|
||||
itemFrame.setVisible(visible);
|
||||
|
@ -1,24 +0,0 @@
|
||||
package com.jamesdpeters.minecraft.chests.v1_16_R2;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.NPCProvider;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.server.v1_16_R2.EntityPlayer;
|
||||
import net.minecraft.server.v1_16_R2.MinecraftServer;
|
||||
import net.minecraft.server.v1_16_R2.PlayerInteractManager;
|
||||
import net.minecraft.server.v1_16_R2.WorldServer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_16_R2.CraftWorld;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class NPC implements NPCProvider {
|
||||
public HumanEntity createHumanEntity() {
|
||||
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
WorldServer nmsWorld = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
|
||||
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "Chests++NPC");
|
||||
EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, new PlayerInteractManager(nmsWorld));
|
||||
return npc.getBukkitEntity();
|
||||
}
|
||||
}
|
@ -3,75 +3,67 @@ package com.jamesdpeters.minecraft.chests.v1_16_R3;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingProvider;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingResult;
|
||||
import net.minecraft.server.v1_16_R3.Container;
|
||||
import net.minecraft.server.v1_16_R3.ContainerWorkbench;
|
||||
import net.minecraft.server.v1_16_R3.EntityHuman;
|
||||
import net.minecraft.server.v1_16_R3.IRecipe;
|
||||
import net.minecraft.server.v1_16_R3.InventoryCraftResult;
|
||||
import net.minecraft.server.v1_16_R3.InventoryCrafting;
|
||||
import net.minecraft.server.v1_16_R3.Item;
|
||||
import net.minecraft.server.v1_16_R3.RecipeCrafting;
|
||||
import net.minecraft.server.v1_16_R3.RecipeRepair;
|
||||
import net.minecraft.server.v1_16_R3.Recipes;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.event.CraftEventFactory;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryCrafting;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftInventoryView;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.InventoryView;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Crafting implements CraftingProvider {
|
||||
|
||||
@Override
|
||||
public CraftingResult craft(Player player, World world, List<ItemStack> items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canUse(EntityHuman entityHuman) {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
InventoryCrafting crafting = new InventoryCrafting(container, 3, 3);
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items.get(i)));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
public CraftingResult craft(Player player, World world, ItemStack[] items) {
|
||||
CraftWorld craftWorld = (CraftWorld) world;
|
||||
Optional<RecipeCrafting> optional = server.getServer().getCraftingManager().craft(Recipes.CRAFTING, crafting, craftWorld.getHandle());
|
||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||
ContainerWorkbench workbench = new ContainerWorkbench(-1, craftPlayer.getHandle().inventory);
|
||||
|
||||
CraftInventoryView view = workbench.getBukkitView();
|
||||
CraftInventoryCrafting craftInventoryCrafting = (CraftInventoryCrafting) view.getTopInventory();
|
||||
InventoryCrafting inventoryCrafting = (InventoryCrafting) craftInventoryCrafting.getMatrixInventory();
|
||||
InventoryCraftResult resultInventory = (InventoryCraftResult) craftInventoryCrafting.getResultInventory();
|
||||
|
||||
Optional<RecipeCrafting> recipe = getNMSRecipe(items, inventoryCrafting, craftWorld);
|
||||
|
||||
net.minecraft.server.v1_16_R3.ItemStack itemstack = net.minecraft.server.v1_16_R3.ItemStack.b;
|
||||
|
||||
if (optional.isPresent()) {
|
||||
RecipeCrafting recipeCrafting = optional.get();
|
||||
itemstack = recipeCrafting.a(crafting);
|
||||
if (recipe.isPresent()) {
|
||||
RecipeCrafting recipeCrafting = recipe.get();
|
||||
if (resultInventory.a(craftWorld.getHandle(), craftPlayer.getHandle(), recipeCrafting)) {
|
||||
itemstack = recipeCrafting.a(inventoryCrafting);
|
||||
}
|
||||
}
|
||||
|
||||
CraftingResult result = new CraftingResult();
|
||||
result.setResult(CraftItemStack.asBukkitCopy(itemstack));
|
||||
net.minecraft.server.v1_16_R3.ItemStack result = CraftEventFactory.callPreCraftEvent(inventoryCrafting, resultInventory, itemstack, view, recipe.orElse(null) instanceof RecipeRepair);
|
||||
|
||||
List<ItemStack> matrixResult = crafting.getContents().stream()
|
||||
.map(itemStack -> {
|
||||
Item remainingItem = itemStack.getItem().getCraftingRemainingItem();
|
||||
return remainingItem != null ? CraftItemStack.asBukkitCopy(remainingItem.createItemStack()) : null;
|
||||
}).collect(Collectors.toList());
|
||||
for(int i = 0; i < items.length; ++i) {
|
||||
Item remaining = inventoryCrafting.getContents().get(i).getItem().getCraftingRemainingItem();
|
||||
items[i] = remaining != null ? CraftItemStack.asBukkitCopy(remaining.createItemStack()) : null;
|
||||
}
|
||||
|
||||
result.setMatrixResult(matrixResult);
|
||||
|
||||
return result;
|
||||
return new CraftingResult(CraftItemStack.asBukkitCopy(result), items);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(Player player, World world, List<ItemStack> items) {
|
||||
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
|
||||
Container container = new Container(null, -1) {
|
||||
@Override
|
||||
public InventoryView getBukkitView() {
|
||||
@ -86,9 +78,9 @@ public class Crafting implements CraftingProvider {
|
||||
|
||||
InventoryCrafting crafting = new InventoryCrafting(container, 3, 3);
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if(i >= 9) break; // ItemList cant contain more than 9 items.
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items.get(i)));
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
@ -96,6 +88,14 @@ public class Crafting implements CraftingProvider {
|
||||
Optional<RecipeCrafting> optional = server.getServer().getCraftingManager().craft(Recipes.CRAFTING, crafting, craftWorld.getHandle());
|
||||
|
||||
return optional.map(IRecipe::toBukkitRecipe).orElse(null);
|
||||
}
|
||||
|
||||
private Optional<RecipeCrafting> getNMSRecipe(ItemStack[] craftingMatrix, InventoryCrafting inventoryCrafting, CraftWorld world) {
|
||||
for(int i = 0; i < craftingMatrix.length; ++i) {
|
||||
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(craftingMatrix[i]));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
return server.getServer().getCraftingManager().craft(Recipes.CRAFTING, inventoryCrafting, world.getHandle());
|
||||
}
|
||||
}
|
||||
|
@ -32,11 +32,6 @@ public class NMSProviderImpl implements NMSProvider {
|
||||
return new Crafting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPCProvider getNPCProvider() {
|
||||
return new NPC();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
|
||||
itemFrame.setVisible(visible);
|
||||
|
@ -1,24 +0,0 @@
|
||||
package com.jamesdpeters.minecraft.chests.v1_16_R3;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.NPCProvider;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.server.v1_16_R3.EntityPlayer;
|
||||
import net.minecraft.server.v1_16_R3.MinecraftServer;
|
||||
import net.minecraft.server.v1_16_R3.PlayerInteractManager;
|
||||
import net.minecraft.server.v1_16_R3.WorldServer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_16_R3.CraftWorld;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class NPC implements NPCProvider {
|
||||
public HumanEntity createHumanEntity() {
|
||||
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
WorldServer nmsWorld = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
|
||||
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "Chests++NPC");
|
||||
EntityPlayer npc = new EntityPlayer(nmsServer, nmsWorld, gameProfile, new PlayerInteractManager(nmsWorld));
|
||||
return npc.getBukkitEntity();
|
||||
}
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<artifactId>ChestsPlusPlus-Parent</artifactId>
|
||||
<groupId>com.jamesdpeters.minecraft.chests</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<minecraft.version>1.17.1</minecraft.version>
|
||||
</properties>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>ChestsPlusPlus_1_17_R1</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.jamesdpeters.minecraft.chests</groupId>
|
||||
<artifactId>ChestsPlusPlus-API</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>${minecraft.version}-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jamesdpeters.minecraft.chests</groupId>
|
||||
<artifactId>ChestsPlusPlus_1_16</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot</artifactId>
|
||||
<version>${minecraft.version}-R0.1-SNAPSHOT</version>
|
||||
<classifier>remapped-mojang</classifier>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>net.md-5</groupId>
|
||||
<artifactId>specialsource-maven-plugin</artifactId>
|
||||
<version>1.2.2</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>remap</goal>
|
||||
</goals>
|
||||
<id>remap-obf</id>
|
||||
<configuration>
|
||||
<srgIn>org.spigotmc:minecraft-server:${minecraft.version}-R0.1-SNAPSHOT:txt:maps-mojang</srgIn>
|
||||
<reverse>true</reverse>
|
||||
<remappedDependencies>org.spigotmc:spigot:${minecraft.version}-R0.1-SNAPSHOT:jar:remapped-mojang</remappedDependencies>
|
||||
<remappedArtifactAttached>true</remappedArtifactAttached>
|
||||
<remappedClassifierName>remapped-obf</remappedClassifierName>
|
||||
</configuration>
|
||||
</execution>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>remap</goal>
|
||||
</goals>
|
||||
<id>remap-spigot</id>
|
||||
<configuration>
|
||||
<inputFile>${project.build.directory}/${project.artifactId}-${project.version}-remapped-obf.jar</inputFile>
|
||||
<srgIn>org.spigotmc:minecraft-server:${minecraft.version}-R0.1-SNAPSHOT:csrg:maps-spigot</srgIn>
|
||||
<remappedDependencies>org.spigotmc:spigot:${minecraft.version}-R0.1-SNAPSHOT:jar:remapped-obf</remappedDependencies>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>16</source>
|
||||
<target>16</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
@ -1,79 +0,0 @@
|
||||
package com.jamesdpeters.minecraft.chests.v1_17_R1;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.CraftingProvider;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingResult;
|
||||
import net.minecraft.world.inventory.CraftingContainer;
|
||||
import net.minecraft.world.inventory.CraftingMenu;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.crafting.CraftingRecipe;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.entity.CraftPlayer;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class Crafting implements CraftingProvider {
|
||||
|
||||
@Override
|
||||
public CraftingResult craft(Player player, World world, List<ItemStack> items) {
|
||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||
CraftingMenu menu = new CraftingMenu(-1, craftPlayer.getHandle().getInventory());
|
||||
CraftingContainer crafting = new CraftingContainer(menu.getBukkitView().getHandle(), 3, 3);
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items.get(i)));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
CraftWorld craftWorld = (CraftWorld) world;
|
||||
Optional<CraftingRecipe> optional = server.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, crafting, craftWorld.getHandle());
|
||||
|
||||
net.minecraft.world.item.ItemStack itemStack = net.minecraft.world.item.ItemStack.EMPTY;
|
||||
|
||||
if (optional.isPresent()) {
|
||||
CraftingRecipe recipeCrafting = optional.get();
|
||||
itemStack = recipeCrafting.assemble(crafting);
|
||||
}
|
||||
|
||||
CraftingResult result = new CraftingResult();
|
||||
result.setResult(CraftItemStack.asBukkitCopy(itemStack));
|
||||
|
||||
List<ItemStack> matrixResult = crafting.getContents().stream()
|
||||
.map(item -> {
|
||||
Item remainingItem = item.getItem().getCraftingRemainingItem();
|
||||
return remainingItem != null ? CraftItemStack.asBukkitCopy(remainingItem.getDefaultInstance()) : null;
|
||||
}).collect(Collectors.toList());
|
||||
|
||||
result.setMatrixResult(matrixResult);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(Player player, World world, List<ItemStack> items) {
|
||||
CraftPlayer craftPlayer = (CraftPlayer) player;
|
||||
CraftingMenu menu = new CraftingMenu(-1, craftPlayer.getHandle().getInventory());
|
||||
CraftingContainer crafting = new CraftingContainer(menu.getBukkitView().getHandle(), 3, 3);
|
||||
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
if(i >= 9) break; // ItemList cant contain more than 9 items.
|
||||
crafting.setItem(i, CraftItemStack.asNMSCopy(items.get(i)));
|
||||
}
|
||||
|
||||
CraftServer server = (CraftServer) Bukkit.getServer();
|
||||
CraftWorld craftWorld = (CraftWorld) world;
|
||||
Optional<CraftingRecipe> optional = server.getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, crafting, craftWorld.getHandle());
|
||||
|
||||
return optional.map(net.minecraft.world.item.crafting.Recipe::toBukkitRecipe).orElse(null);
|
||||
|
||||
}
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
package com.jamesdpeters.minecraft.chests.v1_17_R1;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.NPCProvider;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftServer;
|
||||
import org.bukkit.craftbukkit.v1_17_R1.CraftWorld;
|
||||
import org.bukkit.entity.HumanEntity;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class NPC implements NPCProvider {
|
||||
public HumanEntity createHumanEntity() {
|
||||
MinecraftServer nmsServer = ((CraftServer) Bukkit.getServer()).getServer();
|
||||
ServerLevel nmsWorld = ((CraftWorld) Bukkit.getWorlds().get(0)).getHandle();
|
||||
GameProfile gameProfile = new GameProfile(UUID.randomUUID(), "Chests++NPC");
|
||||
ServerPlayer npc = new ServerPlayer(nmsServer, nmsWorld, gameProfile);
|
||||
return npc.getBukkitEntity();
|
||||
}
|
||||
}
|
64
ChestsPlusPlus_LatestMC/pom.xml
Normal file
64
ChestsPlusPlus_LatestMC/pom.xml
Normal file
@ -0,0 +1,64 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
|
||||
<parent>
|
||||
<artifactId>ChestsPlusPlus-Parent</artifactId>
|
||||
<groupId>com.jamesdpeters.minecraft.chests</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<minecraft.version>1.17.1</minecraft.version>
|
||||
</properties>
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<packaging>jar</packaging>
|
||||
<artifactId>ChestsPlusPlus_LatestMC</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>com.jamesdpeters.minecraft.chests</groupId>
|
||||
<artifactId>ChestsPlusPlus-API</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>${minecraft.version}-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.jamesdpeters.minecraft.chests</groupId>
|
||||
<artifactId>ChestsPlusPlus_1_16</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<configuration>
|
||||
<source>16</source>
|
||||
<target>16</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
</project>
|
@ -0,0 +1,26 @@
|
||||
package com.jamesdpeters.minecraft.chests.latest;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.CraftingProvider;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingResult;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
import org.bukkit.inventory.Recipe;
|
||||
|
||||
public class Crafting implements CraftingProvider {
|
||||
|
||||
@Override
|
||||
public CraftingResult craft(Player player, World world, ItemStack[] items) {
|
||||
var item = Bukkit.craftItem(items, world, player);
|
||||
CraftingResult result = new CraftingResult();
|
||||
result.setResult(item);
|
||||
result.setMatrixResult(items);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
|
||||
return Bukkit.getCraftingRecipe(items, world);
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package com.jamesdpeters.minecraft.chests.v1_17_R1;
|
||||
package com.jamesdpeters.minecraft.chests.latest;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.MaterialChecker;
|
||||
import com.jamesdpeters.minecraft.chests.v1_16_R1.MaterialChecker_1_16;
|
@ -1,6 +1,9 @@
|
||||
package com.jamesdpeters.minecraft.chests.v1_17_R1;
|
||||
package com.jamesdpeters.minecraft.chests.latest;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.*;
|
||||
import com.jamesdpeters.minecraft.chests.ChestOpener;
|
||||
import com.jamesdpeters.minecraft.chests.CraftingProvider;
|
||||
import com.jamesdpeters.minecraft.chests.MaterialChecker;
|
||||
import com.jamesdpeters.minecraft.chests.NMSProvider;
|
||||
import org.bukkit.block.Lidded;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
|
||||
@ -9,13 +12,11 @@ public class NMSProviderImpl implements NMSProvider {
|
||||
@Override
|
||||
public ChestOpener getChestOpener() {
|
||||
return (inventory, container, tileEntityOpener) -> {
|
||||
if(hasLiddedAPI()){
|
||||
if(container instanceof Lidded){
|
||||
if(inventory.getViewers().size() > 0){
|
||||
((Lidded) container).open();
|
||||
} else {
|
||||
((Lidded) container).close();
|
||||
}
|
||||
if(container instanceof Lidded){
|
||||
if(inventory.getViewers().size() > 0){
|
||||
((Lidded) container).open();
|
||||
} else {
|
||||
((Lidded) container).close();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
@ -32,17 +33,9 @@ public class NMSProviderImpl implements NMSProvider {
|
||||
return new Crafting();
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPCProvider getNPCProvider() {
|
||||
return new NPC();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
|
||||
itemFrame.setVisible(visible);
|
||||
}
|
||||
|
||||
private boolean hasLiddedAPI(){
|
||||
return true;
|
||||
}
|
||||
}
|
161
ChestsPlusPlus_Main/dependency-reduced-pom.xml
Normal file
161
ChestsPlusPlus_Main/dependency-reduced-pom.xml
Normal file
@ -0,0 +1,161 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>com.jamesdpeters.minecraft.chests</groupId>
|
||||
<artifactId>ChestsPlusPlus-Master</artifactId>
|
||||
<version>2.5-Beta</version>
|
||||
<scm>
|
||||
<connection>scm:git:git@github.com:JamesPeters98/ChestsPlusPlus.git</connection>
|
||||
<developerConnection>scm:git:git@github.com:JamesPeters98/ChestsPlusPlus.git</developerConnection>
|
||||
<tag>@{project.version}</tag>
|
||||
<url>https://github.com/JamesPeters98/ChestsPlusPlus</url>
|
||||
</scm>
|
||||
<build>
|
||||
<resources>
|
||||
<resource>
|
||||
<filtering>true</filtering>
|
||||
<directory>src/main/resources</directory>
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-shade-plugin</artifactId>
|
||||
<version>3.3.0-SNAPSHOT</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>shade</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputFile>../Server/plugins/ChestsPlusPlus-${project.version}.jar</outputFile>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<artifactSet>
|
||||
<includes>
|
||||
<include>fr.minuskube.inv*:*</include>
|
||||
<include>com.github.MinusKube*:*</include>
|
||||
<include>net.wesjd:anvilgui*</include>
|
||||
<include>org.bstats*:*</include>
|
||||
<include>com.jamesdpeters.minecraft.chests</include>
|
||||
</includes>
|
||||
</artifactSet>
|
||||
<relocations>
|
||||
<relocation>
|
||||
<pattern>org.bstats</pattern>
|
||||
<shadedPattern>com.jamesdpeters.minecraft.chests</shadedPattern>
|
||||
</relocation>
|
||||
<relocation>
|
||||
<pattern>fr.minuskube.inv</pattern>
|
||||
<shadedPattern>com.jamesdpeters.minecraft.chests</shadedPattern>
|
||||
</relocation>
|
||||
</relocations>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>templating-maven-plugin</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>filter-src</id>
|
||||
<goals>
|
||||
<goal>filter-sources</goal>
|
||||
<goal>filter-test-sources</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<artifactId>maven-release-plugin</artifactId>
|
||||
<version>3.0.0-M1</version>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.codehaus.mojo</groupId>
|
||||
<artifactId>exec-maven-plugin</artifactId>
|
||||
<version>3.0.0</version>
|
||||
<executions>
|
||||
<execution>
|
||||
<phase>compile</phase>
|
||||
<goals>
|
||||
<goal>java</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
<configuration>
|
||||
<mainClass>com.jamesdpeters.minecraft.chests.lang.LangFileProperties</mainClass>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>spigotmc-repo</id>
|
||||
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>dmulloy2-repo</id>
|
||||
<url>http://repo.dmulloy2.net/nexus/repository/public/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>CodeMC</id>
|
||||
<url>https://repo.codemc.org/repository/maven-public</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>sytm-nexus</id>
|
||||
<url>https://repo.sytm.de/repository/maven-hosted/</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>jitpack.io</id>
|
||||
<url>https://jitpack.io</url>
|
||||
</repository>
|
||||
<repository>
|
||||
<id>codemc-snapshots</id>
|
||||
<url>https://repo.codemc.io/repository/maven-snapshots/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
<pluginRepositories>
|
||||
<pluginRepository>
|
||||
<id>maven-snapshots</id>
|
||||
<url>https://repository.apache.org/content/repositories/snapshots/</url>
|
||||
</pluginRepository>
|
||||
</pluginRepositories>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>spigot-api</artifactId>
|
||||
<version>1.14.4-R0.1-SNAPSHOT</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.4</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.spigotmc</groupId>
|
||||
<artifactId>plugin-annotations</artifactId>
|
||||
<version>1.2.3-SNAPSHOT</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.jetbrains</groupId>
|
||||
<artifactId>annotations</artifactId>
|
||||
<version>18.0.0</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.20</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<properties>
|
||||
<maven.compiler.target>16</maven.compiler.target>
|
||||
<maven.compiler.source>16</maven.compiler.source>
|
||||
</properties>
|
||||
</project>
|
@ -101,7 +101,7 @@
|
||||
|
||||
<dependency>
|
||||
<groupId>com.jamesdpeters.minecraft.chests</groupId>
|
||||
<artifactId>ChestsPlusPlus_1_17_R1</artifactId>
|
||||
<artifactId>ChestsPlusPlus_LatestMC</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
<type>jar</type>
|
||||
<scope>compile</scope>
|
||||
|
@ -1,44 +1,39 @@
|
||||
package com.jamesdpeters.minecraft.chests.api;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.*;
|
||||
import com.jamesdpeters.minecraft.chests.v1_16_R1.NMSProviderImpl;
|
||||
import com.jamesdpeters.minecraft.chests.latest.NMSProviderImpl;
|
||||
import org.bukkit.entity.ItemFrame;
|
||||
|
||||
public class NMSProviderDefault implements NMSProvider {
|
||||
|
||||
//Latest version at time of build is 1.16
|
||||
NMSProviderImpl provider1_16;
|
||||
//Latest version at time of build is 1.17
|
||||
//All new versions should be able to run with the default provided after 1.17
|
||||
NMSProviderImpl defaultProvider;
|
||||
|
||||
public NMSProviderDefault() {
|
||||
provider1_16 = new NMSProviderImpl();
|
||||
defaultProvider = new NMSProviderImpl();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChestOpener getChestOpener() {
|
||||
//1.16 ChestOpener contains lidded API!
|
||||
return provider1_16.getChestOpener();
|
||||
return defaultProvider.getChestOpener();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MaterialChecker getMaterialChecker() {
|
||||
//Return the current latest MaterialChecker when an newer server implementation is found.
|
||||
return provider1_16.getMaterialChecker();
|
||||
return defaultProvider.getMaterialChecker();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CraftingProvider getCraftingProvider() {
|
||||
// TODO
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NPCProvider getNPCProvider() {
|
||||
return null;
|
||||
return defaultProvider.getCraftingProvider();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
|
||||
//Not supported in Bukkit api 1.14.
|
||||
provider1_16.setItemFrameVisible(itemFrame, visible);
|
||||
defaultProvider.setItemFrameVisible(itemFrame, visible);
|
||||
}
|
||||
}
|
||||
|
@ -32,11 +32,11 @@ public class Crafting {
|
||||
});
|
||||
}
|
||||
|
||||
public static Recipe getRecipe(Player player, List<ItemStack> craftingTable) {
|
||||
public static Recipe getRecipe(Player player, ItemStack[] craftingTable) {
|
||||
return ApiSpecific.getNmsProvider().getCraftingProvider().getRecipe(player, Bukkit.getWorlds().get(0), craftingTable);
|
||||
}
|
||||
|
||||
public static CraftingResult craft(Player player, List<ItemStack> recipe) {
|
||||
public static CraftingResult craft(Player player, ItemStack[] recipe) {
|
||||
return ApiSpecific.getNmsProvider().getCraftingProvider().craft(player, Bukkit.getWorlds().get(0), recipe);
|
||||
}
|
||||
|
||||
|
@ -19,7 +19,6 @@ import org.bukkit.block.Container;
|
||||
import org.bukkit.block.Hopper;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.event.inventory.PrepareItemCraftEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
@ -34,7 +33,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class VirtualCraftingHolder implements InventoryHolder {
|
||||
@ -105,14 +103,14 @@ public class VirtualCraftingHolder implements InventoryHolder {
|
||||
setHasCompleteRecipe();
|
||||
}
|
||||
|
||||
public void setCrafting(Recipe recipe, List<ItemStack> matrix) {
|
||||
public void setCrafting(Recipe recipe, ItemStack[] matrix) {
|
||||
if (recipe instanceof ShapedRecipe) setCrafting((ShapedRecipe) recipe);
|
||||
else if (recipe instanceof ShapelessRecipe) setCrafting((ShapelessRecipe) recipe);
|
||||
else {
|
||||
// For ComplexRecipes or other implementations just use the result and original matrix for choices.
|
||||
result = ApiSpecific.getNmsProvider().getCraftingProvider().craft(storage.getOwner().getPlayer(), Bukkit.getWorlds().get(0), matrix).getResult();
|
||||
for (int i = 0; i < matrix.size(); i++) {
|
||||
ItemStack item = matrix.get(i);
|
||||
for (int i = 0; i < matrix.length; i++) {
|
||||
ItemStack item = matrix[i];
|
||||
if (item != null) {
|
||||
recipeChoices[i] = new ItemStack[]{item};
|
||||
} else {
|
||||
@ -136,8 +134,7 @@ public class VirtualCraftingHolder implements InventoryHolder {
|
||||
}
|
||||
|
||||
public void updateCrafting() {
|
||||
List<ItemStack> crafting = new ArrayList<>(Arrays.asList(inventory.getContents()));
|
||||
crafting.remove(0);
|
||||
var crafting = Arrays.copyOfRange(inventory.getContents(),1, inventory.getContents().length);
|
||||
|
||||
Recipe recipe = Crafting.getRecipe(storage.getOwner().getPlayer(), crafting);
|
||||
getStorage().setRecipe(recipe, crafting); // Only store the crafting matrix if the recipe is valid
|
||||
@ -314,17 +311,16 @@ public class VirtualCraftingHolder implements InventoryHolder {
|
||||
* @param inventories
|
||||
* @return a valid recipe matrix selected from the inventories provided.
|
||||
*/
|
||||
private List<ItemStack> getRecipeMatrix(List<Inventory> inventories) {
|
||||
private ItemStack[] getRecipeMatrix(List<Inventory> inventories) {
|
||||
|
||||
// Loop through recipe choice array to find recipeChoice index.
|
||||
int recipeChoicesAmount = getRecipeChoiceAmount();
|
||||
// Bukkit.broadcastMessage("Recipe choices: "+recipeChoicesAmount);
|
||||
|
||||
for (int recipeChoiceIndex = 0; recipeChoiceIndex < recipeChoicesAmount; recipeChoiceIndex++) {
|
||||
|
||||
// Store each item selected for the recipe.
|
||||
// This is used to retrieve the actual result taking into account meta data, such as repairing items.
|
||||
List<ItemStack> tempRecipe = Utils.createAirList(9);
|
||||
ItemStack[] tempRecipe = Utils.createAirList(9);
|
||||
int recipeIndex = 0;
|
||||
|
||||
// Need a new copy of the inventories to test for each recipe choice.
|
||||
@ -337,7 +333,7 @@ public class VirtualCraftingHolder implements InventoryHolder {
|
||||
|
||||
// If there's no recipe choice at this index skip and set the matrix pos to null
|
||||
if (choices == null){
|
||||
tempRecipe.set(recipeIndex, null);
|
||||
tempRecipe[recipeIndex] = null;
|
||||
recipeIndex++;
|
||||
|
||||
} else { // Otherwise check for a valid item for this recipe choice.
|
||||
@ -361,7 +357,7 @@ public class VirtualCraftingHolder implements InventoryHolder {
|
||||
tempInv.setItem(index, item);
|
||||
|
||||
selectedItem.setAmount(1);
|
||||
tempRecipe.set(recipeIndex, selectedItem);
|
||||
tempRecipe[recipeIndex] = selectedItem;
|
||||
|
||||
recipeIndex++;
|
||||
foundMatch = true;
|
||||
@ -412,31 +408,34 @@ public class VirtualCraftingHolder implements InventoryHolder {
|
||||
}
|
||||
}
|
||||
|
||||
List<ItemStack> recipe = getRecipeMatrix(tempInvs);
|
||||
ItemStack[] recipe = getRecipeMatrix(tempInvs);
|
||||
// null recipe means no recipe was found from the inventories.
|
||||
if (recipe == null) return false;
|
||||
|
||||
// Use NMS to get the real result considering meta data etc.
|
||||
CraftingResult craftingResult = Crafting.craft(storage.getOwner().getPlayer(), recipe);
|
||||
|
||||
Recipe recipeActual = Crafting.getRecipe(storage.getOwner().getPlayer(), recipe);
|
||||
CraftingInventoryImpl craftingInventoryImpl = new CraftingInventoryImpl(craftingInventory, craftingResult.getResult(), recipe, recipeActual);
|
||||
InventoryViewImpl inventoryView = new InventoryViewImpl(craftingInventory, output, ApiSpecific.getNmsProvider().getNPCProvider().createHumanEntity());
|
||||
PrepareItemCraftEvent itemCraftEvent = new PrepareItemCraftEvent(craftingInventoryImpl, inventoryView, false);
|
||||
Bukkit.getPluginManager().callEvent(itemCraftEvent);
|
||||
//TODO
|
||||
// Recipe recipeActual = Crafting.getRecipe(storage.getOwner().getPlayer(), recipe);
|
||||
// CraftingInventoryImpl craftingInventoryImpl = new CraftingInventoryImpl(craftingInventory, craftingResult.getResult(), recipe, recipeActual);
|
||||
// InventoryViewImpl inventoryView = new InventoryViewImpl(craftingInventory, output, ApiSpecific.getNmsProvider().getNPCProvider().createHumanEntity());
|
||||
// PrepareItemCraftEvent itemCraftEvent = new PrepareItemCraftEvent(craftingInventoryImpl, inventoryView, false);
|
||||
// Bukkit.getPluginManager().callEvent(itemCraftEvent);
|
||||
|
||||
if (craftingInventoryImpl.result == null) return false;
|
||||
if (craftingResult.getResult() == null) return false;
|
||||
|
||||
//If we reach here there are enough materials so check for space in the Hopper and update inventory.
|
||||
//Check if output and input are the same inventory to avoid duplication.
|
||||
Inventory tempOutput = sameInv ? sameInventory : Utils.copyInventory(output);
|
||||
HashMap<Integer, ItemStack> map = tempOutput.addItem(craftingInventoryImpl.result);
|
||||
HashMap<Integer, ItemStack> map = tempOutput.addItem(craftingResult.getResult());
|
||||
|
||||
boolean isEmpty = Arrays.stream(craftingResult.getMatrixResult())
|
||||
.anyMatch(itemStack -> (itemStack == null || itemStack.getType() == Material.AIR));
|
||||
|
||||
// Add any leftover items from the recipe e.g buckets.
|
||||
HashMap<Integer, ItemStack> craftingMatrixLeftOvers =
|
||||
craftingResult.getMatrixResult().isEmpty()
|
||||
? Maps.newHashMap()
|
||||
: tempOutput.addItem(craftingResult.getMatrixResult().stream().filter(Objects::nonNull).toArray(ItemStack[]::new));
|
||||
isEmpty ? Maps.newHashMap()
|
||||
: tempOutput.addItem(craftingResult.getMatrixResult());
|
||||
|
||||
//If result fits into output copy over the temporary inventories.
|
||||
if (map.isEmpty() && craftingMatrixLeftOvers.isEmpty()) {
|
||||
|
@ -224,11 +224,11 @@ public class Utils {
|
||||
return tempInvs;
|
||||
}
|
||||
|
||||
public static List<ItemStack> createAirList(int size) {
|
||||
List<ItemStack> itemStacks = new ArrayList<>();
|
||||
public static ItemStack[] createAirList(int size) {
|
||||
ItemStack[] itemStacks = new ItemStack[size];
|
||||
ItemStack AIR = new ItemStack(Material.AIR);
|
||||
for (int i = 0; i < size; i++) {
|
||||
itemStacks.add(AIR);
|
||||
itemStacks[i] = AIR;
|
||||
}
|
||||
return itemStacks;
|
||||
}
|
||||
|
@ -24,9 +24,9 @@ public class RecipeSerializable implements ConfigurationSerializable {
|
||||
private NamespacedKey namespacedKey;
|
||||
|
||||
// Store items used for ComplexRecipes
|
||||
private List<ItemStack> items;
|
||||
private ItemStack[] items;
|
||||
|
||||
public RecipeSerializable(Recipe recipe, List<ItemStack> items) {
|
||||
public RecipeSerializable(Recipe recipe, ItemStack[] items) {
|
||||
this.recipe = recipe;
|
||||
this.items = items;
|
||||
if (recipe instanceof Keyed){
|
||||
@ -38,7 +38,7 @@ public class RecipeSerializable implements ConfigurationSerializable {
|
||||
Object obj = map.get("items");
|
||||
if (obj != null) {
|
||||
//noinspection unchecked
|
||||
items = (List<ItemStack>) obj;
|
||||
items = (ItemStack[]) obj;
|
||||
}
|
||||
|
||||
//noinspection deprecation
|
||||
@ -71,7 +71,7 @@ public class RecipeSerializable implements ConfigurationSerializable {
|
||||
return namespacedKey;
|
||||
}
|
||||
|
||||
public List<ItemStack> getItems() {
|
||||
public ItemStack[] getItems() {
|
||||
return items;
|
||||
}
|
||||
}
|
||||
|
@ -11,6 +11,7 @@ import com.jamesdpeters.minecraft.chests.serialize.ConfigStorage;
|
||||
import com.jamesdpeters.minecraft.chests.serialize.LocationInfo;
|
||||
import com.jamesdpeters.minecraft.chests.serialize.PluginConfig;
|
||||
import com.jamesdpeters.minecraft.chests.storage.StorageUtils;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.Chunk;
|
||||
import org.bukkit.GameMode;
|
||||
import org.bukkit.Location;
|
||||
@ -27,6 +28,7 @@ import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.block.Action;
|
||||
import org.bukkit.event.block.BlockBreakEvent;
|
||||
import org.bukkit.event.block.BlockPlaceEvent;
|
||||
import org.bukkit.event.block.SignChangeEvent;
|
||||
import org.bukkit.event.player.PlayerInteractEvent;
|
||||
@ -269,10 +271,14 @@ public abstract class StorageType<T extends AbstractStorage> implements Listener
|
||||
public void removeStorage(Player player, String group) {
|
||||
T storage = getStorage(player.getUniqueId(), group);
|
||||
if (storage != null) {
|
||||
storage.getLocations().forEach(location -> {
|
||||
var locations = new ArrayList<>(storage.getLocations());
|
||||
locations.forEach(location -> {
|
||||
if (location != null) {
|
||||
Block block = location.getLocation().getBlock();
|
||||
block.breakNaturally();
|
||||
BlockBreakEvent bbe = new BlockBreakEvent(block, player);
|
||||
Bukkit.getPluginManager().callEvent(bbe);
|
||||
if (!bbe.isCancelled())
|
||||
block.breakNaturally();
|
||||
}
|
||||
});
|
||||
storage.dropInventory(player.getLocation());
|
||||
|
@ -17,7 +17,6 @@ import org.bukkit.inventory.Recipe;
|
||||
import org.bukkit.inventory.ShapedRecipe;
|
||||
import org.bukkit.inventory.ShapelessRecipe;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@SerializableAs("AutoCraftingStorage")
|
||||
@ -61,7 +60,7 @@ public class AutoCraftingStorage extends AbstractStorage implements Configuratio
|
||||
return false;
|
||||
}
|
||||
|
||||
public void setRecipe(Recipe recipe, List<ItemStack> items) {
|
||||
public void setRecipe(Recipe recipe, ItemStack[] items) {
|
||||
if (recipe == null) {
|
||||
recipeSerializable = null;
|
||||
return;
|
||||
|
2
pom.xml
2
pom.xml
@ -17,7 +17,7 @@
|
||||
<modules>
|
||||
<module>ChestsPlusPlus-Database</module>
|
||||
<module>ChestsPlusPlusAPI</module>
|
||||
<module>ChestsPlusPlus_1_17_R1</module>
|
||||
<module>ChestsPlusPlus_LatestMC</module>
|
||||
<module>ChestsPlusPlus_1_16_R3</module>
|
||||
<module>ChestsPlusPlus_1_16_R2</module>
|
||||
<module>ChestsPlusPlus_1_16</module>
|
||||
|
Loading…
Reference in New Issue
Block a user