Make 1.21 new baseline version

Upgrade to 1.21 Bukkit API
Remove all old NMS versions
This commit is contained in:
James Peters 2024-08-03 12:14:12 +01:00
parent 386962c3d7
commit 5a1188928a
44 changed files with 47 additions and 2524 deletions

View File

@ -1,8 +0,0 @@
package com.jamesdpeters.minecraft.chests;
import org.bukkit.block.Container;
import org.bukkit.inventory.Inventory;
public interface ChestOpener {
TileEntityOpener updateState(Inventory inventory, Container chest, TileEntityOpener tileEntityOpener);
}

View File

@ -1,12 +1,6 @@
package com.jamesdpeters.minecraft.chests;
import org.bukkit.entity.ItemFrame;
public interface NMSProvider {
ChestOpener getChestOpener();
MaterialChecker getMaterialChecker();
CraftingProvider getCraftingProvider();
EntityEventListener getEntityEventListener();
void setItemFrameVisible(ItemFrame itemFrame, boolean visible);
}

View File

@ -1,9 +0,0 @@
package com.jamesdpeters.minecraft.chests;
import org.bukkit.entity.HumanEntity;
import java.util.List;
public interface TileEntityOpener {
void setViewers(List<HumanEntity> viewers);
}

View File

@ -1,98 +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>spigot-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>org.spigotmc</groupId>
<artifactId>spigot</artifactId>
<version>${minecraft.version}-R0.1-SNAPSHOT</version>
<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>

View File

@ -1,97 +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.core.NonNullList;
import net.minecraft.server.level.WorldServer;
import net.minecraft.world.entity.player.EntityHuman;
import net.minecraft.world.inventory.Container;
import net.minecraft.world.inventory.InventoryCrafting;
import net.minecraft.world.item.crafting.Recipes;
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.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.ArrayList;
public class Crafting implements CraftingProvider {
@Override
public CraftingResult craft(World world, ItemStack[] items) {
CraftWorld craftWorld = (CraftWorld) world;
// Setup crafting inventories.
InventoryCrafting inventoryCrafting = new InventoryCrafting(new Container(null, -1) {
@Override
public InventoryView getBukkitView() {
return null;
}
@Override
public boolean canUse(EntityHuman entityHuman) {
return false;
}
}, 3, 3);
for (int i = 0; i < items.length; i++) {
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
}
var recipe = ((CraftServer) Bukkit.getServer()).getServer().getCraftingManager().craft(Recipes.a, inventoryCrafting, craftWorld.getHandle());
// Generate the resulting ItemStack from the Crafting Matrix
net.minecraft.world.item.ItemStack itemStack = net.minecraft.world.item.ItemStack.b;
if (recipe.isPresent()) {
itemStack = recipe.get().a(inventoryCrafting);
}
return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
}
@Override
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
return Bukkit.getCraftingRecipe(items, world);
}
private CraftingResult createItemCraftResult(ItemStack itemStack, InventoryCrafting inventoryCrafting, WorldServer worldServer) {
CraftServer server = (CraftServer) Bukkit.getServer();
NonNullList<net.minecraft.world.item.ItemStack> remainingItems = server.getServer().getCraftingManager().c(Recipes.a, inventoryCrafting, worldServer);
CraftingResult craftItemResult = new CraftingResult(itemStack, new ItemStack[9], new ArrayList<>());
// Create resulting matrix and overflow items
for (int i = 0; i < remainingItems.size(); ++i) {
net.minecraft.world.item.ItemStack itemstack1 = inventoryCrafting.getItem(i);
net.minecraft.world.item.ItemStack itemstack2 = (net.minecraft.world.item.ItemStack) remainingItems.get(i);
if (!itemstack1.isEmpty()) {
inventoryCrafting.splitStack(i, 1);
itemstack1 = inventoryCrafting.getItem(i);
}
if (!itemstack2.isEmpty()) {
if (itemstack1.isEmpty()) {
inventoryCrafting.setItem(i, itemstack2);
} else if (net.minecraft.world.item.ItemStack.equals(itemstack1, itemstack2) && net.minecraft.world.item.ItemStack.matches(itemstack1, itemstack2)) {
itemstack2.add(itemstack1.getCount());
inventoryCrafting.setItem(i, itemstack2);
} else {
craftItemResult.overflowItems().add(CraftItemStack.asBukkitCopy(itemstack2));
}
}
}
for (int i = 0; i < inventoryCrafting.getContents().size(); i++) {
craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i)));
}
return craftItemResult;
}
}

View File

@ -1,13 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_17_R1;
import com.jamesdpeters.minecraft.chests.EntityEventListener;
import org.bukkit.event.EventHandler;
import org.bukkit.event.world.EntitiesLoadEvent;
public class EntityEventListener_1_17 extends EntityEventListener {
@EventHandler
public void onEntityLoad(EntitiesLoadEvent event) {
event.getEntities().forEach(this::removeEntity);
}
}

View File

@ -1,47 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_17_R1;
import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.EntityEventListener;
import com.jamesdpeters.minecraft.chests.MaterialChecker;
import com.jamesdpeters.minecraft.chests.NMSProvider;
import org.bukkit.block.Lidded;
import org.bukkit.entity.ItemFrame;
public class NMSProviderImpl implements NMSProvider {
@Override
public ChestOpener getChestOpener() {
return (inventory, container, tileEntityOpener) -> {
if(container instanceof Lidded){
if(inventory.getViewers().size() > 0){
((Lidded) container).open();
} else {
((Lidded) container).close();
}
}
return null;
};
}
@Override
public MaterialChecker getMaterialChecker() {
return new MaterialChecker_1_17_R1();
}
@Override
public CraftingProvider getCraftingProvider() {
return new Crafting();
}
@Override
public EntityEventListener getEntityEventListener() {
return new EntityEventListener_1_17();
}
@Override
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
itemFrame.setVisible(visible);
}
}

View File

@ -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.18.1</minecraft.version>
</properties>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>ChestsPlusPlus_1_18_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_17_R1</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.3</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>

View File

@ -1,97 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_18_R1;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.CraftingResult;
import net.minecraft.core.NonNullList;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_18_R1.CraftServer;
import org.bukkit.craftbukkit.v1_18_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_18_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.ArrayList;
public class Crafting implements CraftingProvider {
@Override
public CraftingResult craft(World world, ItemStack[] items) {
CraftWorld craftWorld = (CraftWorld) world;
// Setup crafting inventories.
CraftingContainer inventoryCrafting = new CraftingContainer(new AbstractContainerMenu(null, -1) {
@Override
public InventoryView getBukkitView() {
return null;
}
@Override
public boolean stillValid(net.minecraft.world.entity.player.Player player) {
return false;
}
}, 3, 3);
for (int i = 0; i < items.length; i++) {
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
}
var recipe = ((CraftServer) Bukkit.getServer()).getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, inventoryCrafting, craftWorld.getHandle());
// Generate the resulting ItemStack from the Crafting Matrix
net.minecraft.world.item.ItemStack itemStack = net.minecraft.world.item.ItemStack.EMPTY;
if (recipe.isPresent()) {
itemStack = recipe.get().assemble(inventoryCrafting);
}
return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
}
@Override
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
return Bukkit.getCraftingRecipe(items, world);
}
private CraftingResult createItemCraftResult(ItemStack itemStack, CraftingContainer inventoryCrafting, Level worldServer) {
CraftServer server = (CraftServer) Bukkit.getServer();
NonNullList<net.minecraft.world.item.ItemStack> remainingItems = server.getServer().getRecipeManager().getRemainingItemsFor(RecipeType.CRAFTING, inventoryCrafting, worldServer);
CraftingResult craftItemResult = new CraftingResult(itemStack, new ItemStack[9], new ArrayList<>());
// Create resulting matrix and overflow items
for (int i = 0; i < remainingItems.size(); ++i) {
net.minecraft.world.item.ItemStack itemstack1 = inventoryCrafting.getItem(i);
net.minecraft.world.item.ItemStack itemstack2 = (net.minecraft.world.item.ItemStack) remainingItems.get(i);
if (!itemstack1.isEmpty()) {
inventoryCrafting.removeItem(i, 1);
itemstack1 = inventoryCrafting.getItem(i);
}
if (!itemstack2.isEmpty()) {
if (itemstack1.isEmpty()) {
inventoryCrafting.setItem(i, itemstack2);
} else if (net.minecraft.world.item.ItemStack.tagMatches(itemstack1, itemstack2) && net.minecraft.world.item.ItemStack.matches(itemstack1, itemstack2)) {
itemstack2.grow(itemstack1.getCount());
inventoryCrafting.setItem(i, itemstack2);
} else {
craftItemResult.overflowItems().add(CraftItemStack.asBukkitCopy(itemstack2));
}
}
}
for (int i = 0; i < inventoryCrafting.getContents().size(); i++) {
craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i)));
}
return craftItemResult;
}
}

View File

@ -1,49 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_18_R1;
import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.EntityEventListener;
import com.jamesdpeters.minecraft.chests.MaterialChecker;
import com.jamesdpeters.minecraft.chests.NMSProvider;
import com.jamesdpeters.minecraft.chests.v1_17_R1.EntityEventListener_1_17;
import com.jamesdpeters.minecraft.chests.v1_17_R1.MaterialChecker_1_17_R1;
import org.bukkit.block.Lidded;
import org.bukkit.entity.ItemFrame;
public class NMSProviderImpl implements NMSProvider {
@Override
public ChestOpener getChestOpener() {
return (inventory, container, tileEntityOpener) -> {
if(container instanceof Lidded){
if(inventory.getViewers().size() > 0){
((Lidded) container).open();
} else {
((Lidded) container).close();
}
}
return null;
};
}
@Override
public MaterialChecker getMaterialChecker() {
return new MaterialChecker_1_17_R1();
}
@Override
public CraftingProvider getCraftingProvider() {
return new Crafting();
}
@Override
public EntityEventListener getEntityEventListener() {
return new EntityEventListener_1_17();
}
@Override
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
itemFrame.setVisible(visible);
}
}

View File

@ -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.18.2</minecraft.version>
</properties>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>ChestsPlusPlus_1_18_R2</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_17_R1</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.3</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>

View File

@ -1,97 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_18_R2;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.CraftingResult;
import net.minecraft.core.NonNullList;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_18_R2.CraftServer;
import org.bukkit.craftbukkit.v1_18_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_18_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.ArrayList;
public class Crafting implements CraftingProvider {
@Override
public CraftingResult craft(World world, ItemStack[] items) {
CraftWorld craftWorld = (CraftWorld) world;
// Setup crafting inventories.
CraftingContainer inventoryCrafting = new CraftingContainer(new AbstractContainerMenu(null, -1) {
@Override
public InventoryView getBukkitView() {
return null;
}
@Override
public boolean stillValid(net.minecraft.world.entity.player.Player player) {
return false;
}
}, 3, 3);
for (int i = 0; i < items.length; i++) {
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
}
var recipe = ((CraftServer) Bukkit.getServer()).getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, inventoryCrafting, craftWorld.getHandle());
// Generate the resulting ItemStack from the Crafting Matrix
net.minecraft.world.item.ItemStack itemStack = net.minecraft.world.item.ItemStack.EMPTY;
if (recipe.isPresent()) {
itemStack = recipe.get().assemble(inventoryCrafting);
}
return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
}
@Override
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
return Bukkit.getCraftingRecipe(items, world);
}
private CraftingResult createItemCraftResult(ItemStack itemStack, CraftingContainer inventoryCrafting, Level worldServer) {
CraftServer server = (CraftServer) Bukkit.getServer();
NonNullList<net.minecraft.world.item.ItemStack> remainingItems = server.getServer().getRecipeManager().getRemainingItemsFor(RecipeType.CRAFTING, inventoryCrafting, worldServer);
CraftingResult craftItemResult = new CraftingResult(itemStack, new ItemStack[9], new ArrayList<>());
// Create resulting matrix and overflow items
for (int i = 0; i < remainingItems.size(); ++i) {
net.minecraft.world.item.ItemStack itemstack1 = inventoryCrafting.getItem(i);
net.minecraft.world.item.ItemStack itemstack2 = (net.minecraft.world.item.ItemStack) remainingItems.get(i);
if (!itemstack1.isEmpty()) {
inventoryCrafting.removeItem(i, 1);
itemstack1 = inventoryCrafting.getItem(i);
}
if (!itemstack2.isEmpty()) {
if (itemstack1.isEmpty()) {
inventoryCrafting.setItem(i, itemstack2);
} else if (net.minecraft.world.item.ItemStack.tagMatches(itemstack1, itemstack2) && net.minecraft.world.item.ItemStack.matches(itemstack1, itemstack2)) {
itemstack2.grow(itemstack1.getCount());
inventoryCrafting.setItem(i, itemstack2);
} else {
craftItemResult.overflowItems().add(CraftItemStack.asBukkitCopy(itemstack2));
}
}
}
for (int i = 0; i < inventoryCrafting.getContents().size(); i++) {
craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i)));
}
return craftItemResult;
}
}

View File

@ -1,49 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_18_R2;
import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.EntityEventListener;
import com.jamesdpeters.minecraft.chests.MaterialChecker;
import com.jamesdpeters.minecraft.chests.NMSProvider;
import com.jamesdpeters.minecraft.chests.v1_17_R1.EntityEventListener_1_17;
import com.jamesdpeters.minecraft.chests.v1_17_R1.MaterialChecker_1_17_R1;
import org.bukkit.block.Lidded;
import org.bukkit.entity.ItemFrame;
public class NMSProviderImpl implements NMSProvider {
@Override
public ChestOpener getChestOpener() {
return (inventory, container, tileEntityOpener) -> {
if(container instanceof Lidded){
if(inventory.getViewers().size() > 0){
((Lidded) container).open();
} else {
((Lidded) container).close();
}
}
return null;
};
}
@Override
public MaterialChecker getMaterialChecker() {
return new MaterialChecker_1_17_R1();
}
@Override
public CraftingProvider getCraftingProvider() {
return new Crafting();
}
@Override
public EntityEventListener getEntityEventListener() {
return new EntityEventListener_1_17();
}
@Override
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
itemFrame.setVisible(visible);
}
}

View File

@ -1,104 +0,0 @@
<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.19</minecraft.version>
</properties>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>ChestsPlusPlus_1_19_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_17_R1</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.3</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>

View File

@ -1,102 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_19_R1;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.CraftingResult;
import net.minecraft.core.NonNullList;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_19_R1.CraftServer;
import org.bukkit.craftbukkit.v1_19_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_19_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.ArrayList;
public class Crafting implements CraftingProvider {
@Override
public CraftingResult craft(World world, ItemStack[] items) {
CraftWorld craftWorld = (CraftWorld) world;
// Setup crafting inventories.
CraftingContainer inventoryCrafting = new CraftingContainer(new AbstractContainerMenu(null, -1) {
@Override
public InventoryView getBukkitView() {
return null;
}
@Override
public net.minecraft.world.item.ItemStack quickMoveStack(net.minecraft.world.entity.player.Player player, int i) {
return null;
}
@Override
public boolean stillValid(net.minecraft.world.entity.player.Player player) {
return false;
}
}, 3, 3);
for (int i = 0; i < items.length; i++) {
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
}
var recipe = ((CraftServer) Bukkit.getServer()).getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, inventoryCrafting, craftWorld.getHandle());
// Generate the resulting ItemStack from the Crafting Matrix
net.minecraft.world.item.ItemStack itemStack = net.minecraft.world.item.ItemStack.EMPTY;
if (recipe.isPresent()) {
itemStack = recipe.get().assemble(inventoryCrafting);
}
return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
}
@Override
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
return Bukkit.getCraftingRecipe(items, world);
}
private CraftingResult createItemCraftResult(ItemStack itemStack, CraftingContainer inventoryCrafting, Level worldServer) {
CraftServer server = (CraftServer) Bukkit.getServer();
NonNullList<net.minecraft.world.item.ItemStack> remainingItems = server.getServer().getRecipeManager().getRemainingItemsFor(RecipeType.CRAFTING, inventoryCrafting, worldServer);
CraftingResult craftItemResult = new CraftingResult(itemStack, new ItemStack[9], new ArrayList<>());
// Create resulting matrix and overflow items
for (int i = 0; i < remainingItems.size(); ++i) {
net.minecraft.world.item.ItemStack itemstack1 = inventoryCrafting.getItem(i);
net.minecraft.world.item.ItemStack itemstack2 = (net.minecraft.world.item.ItemStack) remainingItems.get(i);
if (!itemstack1.isEmpty()) {
inventoryCrafting.removeItem(i, 1);
itemstack1 = inventoryCrafting.getItem(i);
}
if (!itemstack2.isEmpty()) {
if (itemstack1.isEmpty()) {
inventoryCrafting.setItem(i, itemstack2);
} else if (net.minecraft.world.item.ItemStack.tagMatches(itemstack1, itemstack2) && net.minecraft.world.item.ItemStack.matches(itemstack1, itemstack2)) {
itemstack2.grow(itemstack1.getCount());
inventoryCrafting.setItem(i, itemstack2);
} else {
craftItemResult.overflowItems().add(CraftItemStack.asBukkitCopy(itemstack2));
}
}
}
for (int i = 0; i < inventoryCrafting.getContents().size(); i++) {
craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i)));
}
return craftItemResult;
}
}

View File

@ -1,49 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_19_R1;
import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.EntityEventListener;
import com.jamesdpeters.minecraft.chests.MaterialChecker;
import com.jamesdpeters.minecraft.chests.NMSProvider;
import com.jamesdpeters.minecraft.chests.v1_17_R1.EntityEventListener_1_17;
import com.jamesdpeters.minecraft.chests.v1_17_R1.MaterialChecker_1_17_R1;
import org.bukkit.block.Lidded;
import org.bukkit.entity.ItemFrame;
public class NMSProviderImpl implements NMSProvider {
@Override
public ChestOpener getChestOpener() {
return (inventory, container, tileEntityOpener) -> {
if(container instanceof Lidded){
if(inventory.getViewers().size() > 0){
((Lidded) container).open();
} else {
((Lidded) container).close();
}
}
return null;
};
}
@Override
public MaterialChecker getMaterialChecker() {
return new MaterialChecker_1_17_R1();
}
@Override
public CraftingProvider getCraftingProvider() {
return new Crafting();
}
@Override
public EntityEventListener getEntityEventListener() {
return new EntityEventListener_1_17();
}
@Override
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
itemFrame.setVisible(visible);
}
}

View File

@ -1,104 +0,0 @@
<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.19.3</minecraft.version>
</properties>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>ChestsPlusPlus_1_19_R2</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_17_R1</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.3</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>

View File

@ -1,102 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_19_R2;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.CraftingResult;
import net.minecraft.core.NonNullList;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_19_R2.CraftServer;
import org.bukkit.craftbukkit.v1_19_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_19_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.ArrayList;
public class Crafting implements CraftingProvider {
@Override
public CraftingResult craft(World world, ItemStack[] items) {
CraftWorld craftWorld = (CraftWorld) world;
// Setup crafting inventories.
CraftingContainer inventoryCrafting = new CraftingContainer(new AbstractContainerMenu(null, -1) {
@Override
public InventoryView getBukkitView() {
return null;
}
@Override
public net.minecraft.world.item.ItemStack quickMoveStack(net.minecraft.world.entity.player.Player player, int i) {
return null;
}
@Override
public boolean stillValid(net.minecraft.world.entity.player.Player player) {
return false;
}
}, 3, 3);
for (int i = 0; i < items.length; i++) {
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
}
var recipe = ((CraftServer) Bukkit.getServer()).getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, inventoryCrafting, craftWorld.getHandle());
// Generate the resulting ItemStack from the Crafting Matrix
net.minecraft.world.item.ItemStack itemStack = net.minecraft.world.item.ItemStack.EMPTY;
if (recipe.isPresent()) {
itemStack = recipe.get().assemble(inventoryCrafting);
}
return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
}
@Override
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
return Bukkit.getCraftingRecipe(items, world);
}
private CraftingResult createItemCraftResult(ItemStack itemStack, CraftingContainer inventoryCrafting, Level worldServer) {
CraftServer server = (CraftServer) Bukkit.getServer();
NonNullList<net.minecraft.world.item.ItemStack> remainingItems = server.getServer().getRecipeManager().getRemainingItemsFor(RecipeType.CRAFTING, inventoryCrafting, worldServer);
CraftingResult craftItemResult = new CraftingResult(itemStack, new ItemStack[9], new ArrayList<>());
// Create resulting matrix and overflow items
for (int i = 0; i < remainingItems.size(); ++i) {
net.minecraft.world.item.ItemStack itemstack1 = inventoryCrafting.getItem(i);
net.minecraft.world.item.ItemStack itemstack2 = (net.minecraft.world.item.ItemStack) remainingItems.get(i);
if (!itemstack1.isEmpty()) {
inventoryCrafting.removeItem(i, 1);
itemstack1 = inventoryCrafting.getItem(i);
}
if (!itemstack2.isEmpty()) {
if (itemstack1.isEmpty()) {
inventoryCrafting.setItem(i, itemstack2);
} else if (net.minecraft.world.item.ItemStack.tagMatches(itemstack1, itemstack2) && net.minecraft.world.item.ItemStack.matches(itemstack1, itemstack2)) {
itemstack2.grow(itemstack1.getCount());
inventoryCrafting.setItem(i, itemstack2);
} else {
craftItemResult.overflowItems().add(CraftItemStack.asBukkitCopy(itemstack2));
}
}
}
for (int i = 0; i < inventoryCrafting.getContents().size(); i++) {
craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i)));
}
return craftItemResult;
}
}

View File

@ -1,49 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_19_R2;
import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.EntityEventListener;
import com.jamesdpeters.minecraft.chests.MaterialChecker;
import com.jamesdpeters.minecraft.chests.NMSProvider;
import com.jamesdpeters.minecraft.chests.v1_17_R1.EntityEventListener_1_17;
import com.jamesdpeters.minecraft.chests.v1_17_R1.MaterialChecker_1_17_R1;
import org.bukkit.block.Lidded;
import org.bukkit.entity.ItemFrame;
public class NMSProviderImpl implements NMSProvider {
@Override
public ChestOpener getChestOpener() {
return (inventory, container, tileEntityOpener) -> {
if(container instanceof Lidded){
if(inventory.getViewers().size() > 0){
((Lidded) container).open();
} else {
((Lidded) container).close();
}
}
return null;
};
}
@Override
public MaterialChecker getMaterialChecker() {
return new MaterialChecker_1_17_R1();
}
@Override
public CraftingProvider getCraftingProvider() {
return new Crafting();
}
@Override
public EntityEventListener getEntityEventListener() {
return new EntityEventListener_1_17();
}
@Override
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
itemFrame.setVisible(visible);
}
}

View File

@ -1,104 +0,0 @@
<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.19.4</minecraft.version>
</properties>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>ChestsPlusPlus_1_19_R3</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_17_R1</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.3</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>

View File

@ -1,103 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_19_R3;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.CraftingResult;
import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_19_R3.CraftServer;
import org.bukkit.craftbukkit.v1_19_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_19_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.ArrayList;
public class Crafting implements CraftingProvider {
@Override
public CraftingResult craft(World world, ItemStack[] items) {
CraftWorld craftWorld = (CraftWorld) world;
// Setup crafting inventories.
CraftingContainer inventoryCrafting = new CraftingContainer(new AbstractContainerMenu(null, -1) {
@Override
public InventoryView getBukkitView() {
return null;
}
@Override
public net.minecraft.world.item.ItemStack quickMoveStack(net.minecraft.world.entity.player.Player player, int i) {
return null;
}
@Override
public boolean stillValid(net.minecraft.world.entity.player.Player player) {
return false;
}
}, 3, 3);
for (int i = 0; i < items.length; i++) {
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
}
var recipe = ((CraftServer) Bukkit.getServer()).getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, inventoryCrafting, craftWorld.getHandle());
// Generate the resulting ItemStack from the Crafting Matrix
net.minecraft.world.item.ItemStack itemStack = net.minecraft.world.item.ItemStack.EMPTY;
if (recipe.isPresent()) {
itemStack = recipe.get().assemble(inventoryCrafting, RegistryAccess.EMPTY);
}
return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
}
@Override
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
return Bukkit.getCraftingRecipe(items, world);
}
private CraftingResult createItemCraftResult(ItemStack itemStack, CraftingContainer inventoryCrafting, Level worldServer) {
CraftServer server = (CraftServer) Bukkit.getServer();
NonNullList<net.minecraft.world.item.ItemStack> remainingItems = server.getServer().getRecipeManager().getRemainingItemsFor(RecipeType.CRAFTING, inventoryCrafting, worldServer);
CraftingResult craftItemResult = new CraftingResult(itemStack, new ItemStack[9], new ArrayList<>());
// Create resulting matrix and overflow items
for (int i = 0; i < remainingItems.size(); ++i) {
net.minecraft.world.item.ItemStack itemstack1 = inventoryCrafting.getItem(i);
net.minecraft.world.item.ItemStack itemstack2 = (net.minecraft.world.item.ItemStack) remainingItems.get(i);
if (!itemstack1.isEmpty()) {
inventoryCrafting.removeItem(i, 1);
itemstack1 = inventoryCrafting.getItem(i);
}
if (!itemstack2.isEmpty()) {
if (itemstack1.isEmpty()) {
inventoryCrafting.setItem(i, itemstack2);
} else if (net.minecraft.world.item.ItemStack.tagMatches(itemstack1, itemstack2) && net.minecraft.world.item.ItemStack.matches(itemstack1, itemstack2)) {
itemstack2.grow(itemstack1.getCount());
inventoryCrafting.setItem(i, itemstack2);
} else {
craftItemResult.overflowItems().add(CraftItemStack.asBukkitCopy(itemstack2));
}
}
}
for (int i = 0; i < inventoryCrafting.getContents().size(); i++) {
craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i)));
}
return craftItemResult;
}
}

View File

@ -1,49 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_19_R3;
import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.EntityEventListener;
import com.jamesdpeters.minecraft.chests.MaterialChecker;
import com.jamesdpeters.minecraft.chests.NMSProvider;
import com.jamesdpeters.minecraft.chests.v1_17_R1.EntityEventListener_1_17;
import com.jamesdpeters.minecraft.chests.v1_17_R1.MaterialChecker_1_17_R1;
import org.bukkit.block.Lidded;
import org.bukkit.entity.ItemFrame;
public class NMSProviderImpl implements NMSProvider {
@Override
public ChestOpener getChestOpener() {
return (inventory, container, tileEntityOpener) -> {
if(container instanceof Lidded){
if(inventory.getViewers().size() > 0){
((Lidded) container).open();
} else {
((Lidded) container).close();
}
}
return null;
};
}
@Override
public MaterialChecker getMaterialChecker() {
return new MaterialChecker_1_17_R1();
}
@Override
public CraftingProvider getCraftingProvider() {
return new Crafting();
}
@Override
public EntityEventListener getEntityEventListener() {
return new EntityEventListener_1_17();
}
@Override
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
itemFrame.setVisible(visible);
}
}

View File

@ -1,104 +0,0 @@
<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.20</minecraft.version>
</properties>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>ChestsPlusPlus_1_20_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_17_R1</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.3</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>

View File

@ -1,104 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_20_R1;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.CraftingResult;
import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.inventory.TransientCraftingContainer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R1.CraftServer;
import org.bukkit.craftbukkit.v1_20_R1.CraftWorld;
import org.bukkit.craftbukkit.v1_20_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.ArrayList;
public class Crafting implements CraftingProvider {
@Override
public CraftingResult craft(World world, ItemStack[] items) {
CraftWorld craftWorld = (CraftWorld) world;
// Setup crafting inventories.
CraftingContainer inventoryCrafting = new TransientCraftingContainer(new AbstractContainerMenu(null, -1) {
@Override
public InventoryView getBukkitView() {
return null;
}
@Override
public net.minecraft.world.item.ItemStack quickMoveStack(net.minecraft.world.entity.player.Player player, int i) {
return null;
}
@Override
public boolean stillValid(net.minecraft.world.entity.player.Player player) {
return false;
}
}, 3, 3);
for (int i = 0; i < items.length; i++) {
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
}
var recipe = ((CraftServer) Bukkit.getServer()).getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, inventoryCrafting, craftWorld.getHandle());
// Generate the resulting ItemStack from the Crafting Matrix
net.minecraft.world.item.ItemStack itemStack = net.minecraft.world.item.ItemStack.EMPTY;
if (recipe.isPresent()) {
itemStack = recipe.get().assemble(inventoryCrafting, RegistryAccess.EMPTY);
}
return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
}
@Override
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
return Bukkit.getCraftingRecipe(items, world);
}
private CraftingResult createItemCraftResult(ItemStack itemStack, CraftingContainer inventoryCrafting, Level worldServer) {
CraftServer server = (CraftServer) Bukkit.getServer();
NonNullList<net.minecraft.world.item.ItemStack> remainingItems = server.getServer().getRecipeManager().getRemainingItemsFor(RecipeType.CRAFTING, inventoryCrafting, worldServer);
CraftingResult craftItemResult = new CraftingResult(itemStack, new ItemStack[9], new ArrayList<>());
// Create resulting matrix and overflow items
for (int i = 0; i < remainingItems.size(); ++i) {
net.minecraft.world.item.ItemStack itemstack1 = inventoryCrafting.getItem(i);
net.minecraft.world.item.ItemStack itemstack2 = (net.minecraft.world.item.ItemStack) remainingItems.get(i);
if (!itemstack1.isEmpty()) {
inventoryCrafting.removeItem(i, 1);
itemstack1 = inventoryCrafting.getItem(i);
}
if (!itemstack2.isEmpty()) {
if (itemstack1.isEmpty()) {
inventoryCrafting.setItem(i, itemstack2);
} else if (net.minecraft.world.item.ItemStack.matches(itemstack1, itemstack2)) {
itemstack2.grow(itemstack1.getCount());
inventoryCrafting.setItem(i, itemstack2);
} else {
craftItemResult.overflowItems().add(CraftItemStack.asBukkitCopy(itemstack2));
}
}
}
for (int i = 0; i < inventoryCrafting.getContents().size(); i++) {
craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i)));
}
return craftItemResult;
}
}

View File

@ -1,49 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_20_R1;
import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.EntityEventListener;
import com.jamesdpeters.minecraft.chests.MaterialChecker;
import com.jamesdpeters.minecraft.chests.NMSProvider;
import com.jamesdpeters.minecraft.chests.v1_17_R1.EntityEventListener_1_17;
import com.jamesdpeters.minecraft.chests.v1_17_R1.MaterialChecker_1_17_R1;
import org.bukkit.block.Lidded;
import org.bukkit.entity.ItemFrame;
public class NMSProviderImpl implements NMSProvider {
@Override
public ChestOpener getChestOpener() {
return (inventory, container, tileEntityOpener) -> {
if(container instanceof Lidded){
if(inventory.getViewers().size() > 0){
((Lidded) container).open();
} else {
((Lidded) container).close();
}
}
return null;
};
}
@Override
public MaterialChecker getMaterialChecker() {
return new MaterialChecker_1_17_R1();
}
@Override
public CraftingProvider getCraftingProvider() {
return new Crafting();
}
@Override
public EntityEventListener getEntityEventListener() {
return new EntityEventListener_1_17();
}
@Override
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
itemFrame.setVisible(visible);
}
}

View File

@ -1,104 +0,0 @@
<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.20.2</minecraft.version>
</properties>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>ChestsPlusPlus_1_20_R2</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_17_R1</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.3</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>

View File

@ -1,104 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_20_R2;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.CraftingResult;
import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.inventory.TransientCraftingContainer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R2.CraftServer;
import org.bukkit.craftbukkit.v1_20_R2.CraftWorld;
import org.bukkit.craftbukkit.v1_20_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.ArrayList;
public class Crafting implements CraftingProvider {
@Override
public CraftingResult craft(World world, ItemStack[] items) {
CraftWorld craftWorld = (CraftWorld) world;
// Setup crafting inventories.
CraftingContainer inventoryCrafting = new TransientCraftingContainer(new AbstractContainerMenu(null, -1) {
@Override
public InventoryView getBukkitView() {
return null;
}
@Override
public net.minecraft.world.item.ItemStack quickMoveStack(net.minecraft.world.entity.player.Player player, int i) {
return null;
}
@Override
public boolean stillValid(net.minecraft.world.entity.player.Player player) {
return false;
}
}, 3, 3);
for (int i = 0; i < items.length; i++) {
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
}
var recipe = ((CraftServer) Bukkit.getServer()).getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, inventoryCrafting, craftWorld.getHandle());
// Generate the resulting ItemStack from the Crafting Matrix
net.minecraft.world.item.ItemStack itemStack = net.minecraft.world.item.ItemStack.EMPTY;
if (recipe.isPresent()) {
itemStack = recipe.get().value().assemble(inventoryCrafting, RegistryAccess.EMPTY);
}
return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
}
@Override
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
return Bukkit.getCraftingRecipe(items, world);
}
private CraftingResult createItemCraftResult(ItemStack itemStack, CraftingContainer inventoryCrafting, Level worldServer) {
CraftServer server = (CraftServer) Bukkit.getServer();
NonNullList<net.minecraft.world.item.ItemStack> remainingItems = server.getServer().getRecipeManager().getRemainingItemsFor(RecipeType.CRAFTING, inventoryCrafting, worldServer);
CraftingResult craftItemResult = new CraftingResult(itemStack, new ItemStack[9], new ArrayList<>());
// Create resulting matrix and overflow items
for (int i = 0; i < remainingItems.size(); ++i) {
net.minecraft.world.item.ItemStack itemstack1 = inventoryCrafting.getItem(i);
net.minecraft.world.item.ItemStack itemstack2 = (net.minecraft.world.item.ItemStack) remainingItems.get(i);
if (!itemstack1.isEmpty()) {
inventoryCrafting.removeItem(i, 1);
itemstack1 = inventoryCrafting.getItem(i);
}
if (!itemstack2.isEmpty()) {
if (itemstack1.isEmpty()) {
inventoryCrafting.setItem(i, itemstack2);
} else if (net.minecraft.world.item.ItemStack.matches(itemstack1, itemstack2)) {
itemstack2.grow(itemstack1.getCount());
inventoryCrafting.setItem(i, itemstack2);
} else {
craftItemResult.overflowItems().add(CraftItemStack.asBukkitCopy(itemstack2));
}
}
}
for (int i = 0; i < inventoryCrafting.getContents().size(); i++) {
craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i)));
}
return craftItemResult;
}
}

View File

@ -1,49 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_20_R2;
import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.EntityEventListener;
import com.jamesdpeters.minecraft.chests.MaterialChecker;
import com.jamesdpeters.minecraft.chests.NMSProvider;
import com.jamesdpeters.minecraft.chests.v1_17_R1.EntityEventListener_1_17;
import com.jamesdpeters.minecraft.chests.v1_17_R1.MaterialChecker_1_17_R1;
import org.bukkit.block.Lidded;
import org.bukkit.entity.ItemFrame;
public class NMSProviderImpl implements NMSProvider {
@Override
public ChestOpener getChestOpener() {
return (inventory, container, tileEntityOpener) -> {
if(container instanceof Lidded){
if(inventory.getViewers().size() > 0){
((Lidded) container).open();
} else {
((Lidded) container).close();
}
}
return null;
};
}
@Override
public MaterialChecker getMaterialChecker() {
return new MaterialChecker_1_17_R1();
}
@Override
public CraftingProvider getCraftingProvider() {
return new Crafting();
}
@Override
public EntityEventListener getEntityEventListener() {
return new EntityEventListener_1_17();
}
@Override
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
itemFrame.setVisible(visible);
}
}

View File

@ -1,104 +0,0 @@
<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.20.4</minecraft.version>
</properties>
<modelVersion>4.0.0</modelVersion>
<packaging>jar</packaging>
<artifactId>ChestsPlusPlus_1_20_R3</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_17_R1</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.3</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>

View File

@ -1,104 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_20_R3;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.CraftingResult;
import net.minecraft.core.NonNullList;
import net.minecraft.core.RegistryAccess;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.CraftingContainer;
import net.minecraft.world.inventory.TransientCraftingContainer;
import net.minecraft.world.item.crafting.RecipeType;
import net.minecraft.world.level.Level;
import org.bukkit.Bukkit;
import org.bukkit.World;
import org.bukkit.craftbukkit.v1_20_R3.CraftServer;
import org.bukkit.craftbukkit.v1_20_R3.CraftWorld;
import org.bukkit.craftbukkit.v1_20_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.ArrayList;
public class Crafting implements CraftingProvider {
@Override
public CraftingResult craft(World world, ItemStack[] items) {
CraftWorld craftWorld = (CraftWorld) world;
// Setup crafting inventories.
CraftingContainer inventoryCrafting = new TransientCraftingContainer(new AbstractContainerMenu(null, -1) {
@Override
public InventoryView getBukkitView() {
return null;
}
@Override
public net.minecraft.world.item.ItemStack quickMoveStack(net.minecraft.world.entity.player.Player player, int i) {
return null;
}
@Override
public boolean stillValid(net.minecraft.world.entity.player.Player player) {
return false;
}
}, 3, 3);
for (int i = 0; i < items.length; i++) {
inventoryCrafting.setItem(i, CraftItemStack.asNMSCopy(items[i]));
}
var recipe = ((CraftServer) Bukkit.getServer()).getServer().getRecipeManager().getRecipeFor(RecipeType.CRAFTING, inventoryCrafting, craftWorld.getHandle());
// Generate the resulting ItemStack from the Crafting Matrix
net.minecraft.world.item.ItemStack itemStack = net.minecraft.world.item.ItemStack.EMPTY;
if (recipe.isPresent()) {
itemStack = recipe.get().value().assemble(inventoryCrafting, RegistryAccess.EMPTY);
}
return createItemCraftResult(CraftItemStack.asBukkitCopy(itemStack), inventoryCrafting, craftWorld.getHandle());
}
@Override
public Recipe getRecipe(Player player, World world, ItemStack[] items) {
return Bukkit.getCraftingRecipe(items, world);
}
private CraftingResult createItemCraftResult(ItemStack itemStack, CraftingContainer inventoryCrafting, Level worldServer) {
CraftServer server = (CraftServer) Bukkit.getServer();
NonNullList<net.minecraft.world.item.ItemStack> remainingItems = server.getServer().getRecipeManager().getRemainingItemsFor(RecipeType.CRAFTING, inventoryCrafting, worldServer);
CraftingResult craftItemResult = new CraftingResult(itemStack, new ItemStack[9], new ArrayList<>());
// Create resulting matrix and overflow items
for (int i = 0; i < remainingItems.size(); ++i) {
net.minecraft.world.item.ItemStack itemstack1 = inventoryCrafting.getItem(i);
net.minecraft.world.item.ItemStack itemstack2 = (net.minecraft.world.item.ItemStack) remainingItems.get(i);
if (!itemstack1.isEmpty()) {
inventoryCrafting.removeItem(i, 1);
itemstack1 = inventoryCrafting.getItem(i);
}
if (!itemstack2.isEmpty()) {
if (itemstack1.isEmpty()) {
inventoryCrafting.setItem(i, itemstack2);
} else if (net.minecraft.world.item.ItemStack.matches(itemstack1, itemstack2)) {
itemstack2.grow(itemstack1.getCount());
inventoryCrafting.setItem(i, itemstack2);
} else {
craftItemResult.overflowItems().add(CraftItemStack.asBukkitCopy(itemstack2));
}
}
}
for (int i = 0; i < inventoryCrafting.getContents().size(); i++) {
craftItemResult.setResultMatrix(i, CraftItemStack.asBukkitCopy(inventoryCrafting.getItem(i)));
}
return craftItemResult;
}
}

View File

@ -1,49 +0,0 @@
package com.jamesdpeters.minecraft.chests.v1_20_R3;
import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.EntityEventListener;
import com.jamesdpeters.minecraft.chests.MaterialChecker;
import com.jamesdpeters.minecraft.chests.NMSProvider;
import com.jamesdpeters.minecraft.chests.v1_17_R1.EntityEventListener_1_17;
import com.jamesdpeters.minecraft.chests.v1_17_R1.MaterialChecker_1_17_R1;
import org.bukkit.block.Lidded;
import org.bukkit.entity.ItemFrame;
public class NMSProviderImpl implements NMSProvider {
@Override
public ChestOpener getChestOpener() {
return (inventory, container, tileEntityOpener) -> {
if(container instanceof Lidded){
if(inventory.getViewers().size() > 0){
((Lidded) container).open();
} else {
((Lidded) container).close();
}
}
return null;
};
}
@Override
public MaterialChecker getMaterialChecker() {
return new MaterialChecker_1_17_R1();
}
@Override
public CraftingProvider getCraftingProvider() {
return new Crafting();
}
@Override
public EntityEventListener getEntityEventListener() {
return new EntityEventListener_1_17();
}
@Override
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
itemFrame.setVisible(visible);
}
}

View File

@ -1,4 +1,4 @@
package com.jamesdpeters.minecraft.chests.v1_17_R1;
package com.jamesdpeters.minecraft.chests.v1_21_R1;
import com.jamesdpeters.minecraft.chests.BaseMaterialChecker;
import com.jamesdpeters.minecraft.chests.MaterialChecker;
@ -7,14 +7,11 @@ import org.bukkit.inventory.ItemStack;
import java.util.List;
/**
* Material Checker for items available in 1.17+
*/
public class MaterialChecker_1_17_R1 extends MaterialChecker {
public class MaterialChecker_1_21_R1 extends MaterialChecker {
private final BaseMaterialChecker baseMaterialChecker;
public MaterialChecker_1_17_R1(){
public MaterialChecker_1_21_R1(){
baseMaterialChecker = new BaseMaterialChecker();
}

View File

@ -1,34 +1,13 @@
package com.jamesdpeters.minecraft.chests.v1_21_R1;
import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.CraftingProvider;
import com.jamesdpeters.minecraft.chests.EntityEventListener;
import com.jamesdpeters.minecraft.chests.MaterialChecker;
import com.jamesdpeters.minecraft.chests.NMSProvider;
import com.jamesdpeters.minecraft.chests.v1_17_R1.EntityEventListener_1_17;
import com.jamesdpeters.minecraft.chests.v1_17_R1.MaterialChecker_1_17_R1;
import org.bukkit.block.Lidded;
import org.bukkit.entity.ItemFrame;
public class NMSProviderImpl implements NMSProvider {
@Override
public ChestOpener getChestOpener() {
return (inventory, container, tileEntityOpener) -> {
if(container instanceof Lidded){
if(!inventory.getViewers().isEmpty()){
((Lidded) container).open();
} else {
((Lidded) container).close();
}
}
return null;
};
}
@Override
public MaterialChecker getMaterialChecker() {
return new MaterialChecker_1_17_R1();
return new MaterialChecker_1_21_R1();
}
@Override
@ -36,14 +15,4 @@ public class NMSProviderImpl implements NMSProvider {
return new Crafting();
}
@Override
public EntityEventListener getEntityEventListener() {
return new EntityEventListener_1_17();
}
@Override
public void setItemFrameVisible(ItemFrame itemFrame, boolean visible) {
itemFrame.setVisible(visible);
}
}

View File

@ -36,7 +36,7 @@
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.17.1-R0.1-SNAPSHOT</version>
<version>1.21-R0.1-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
@ -79,76 +79,6 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_20_R3</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_20_R2</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_20_R1</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_19_R3</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_19_R2</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_19_R1</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_18_R2</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_18_R1</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus_1_17_R1</artifactId>
<version>1.0-SNAPSHOT</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.jamesdpeters.minecraft.chests</groupId>
<artifactId>ChestsPlusPlus-API</artifactId>

View File

@ -7,6 +7,7 @@ import com.jamesdpeters.minecraft.chests.commands.ChestsPlusPlusCommand;
import com.jamesdpeters.minecraft.chests.crafting.Crafting;
import com.jamesdpeters.minecraft.chests.lang.LangFileProperties;
import com.jamesdpeters.minecraft.chests.listeners.AutoCrafterListener;
import com.jamesdpeters.minecraft.chests.listeners.EntityEventListener;
import com.jamesdpeters.minecraft.chests.listeners.HopperFilterListener;
import com.jamesdpeters.minecraft.chests.listeners.InventoryListener;
import com.jamesdpeters.minecraft.chests.listeners.LinkedChestHopperListener;
@ -169,8 +170,8 @@ public class ChestsPlusPlus extends JavaPlugin {
}
});
getServer().getPluginManager().registerEvents(ApiSpecific.getNmsProvider().getEntityEventListener(), this);
Bukkit.getWorlds().forEach(world -> ApiSpecific.getNmsProvider().getEntityEventListener().fixEntities(world));
getServer().getPluginManager().registerEvents(new EntityEventListener(), this);
Bukkit.getWorlds().forEach(EntityEventListener::fixEntities);
getLogger().info("Chests++ enabled!");
}, 1);
}

View File

@ -1,7 +1,6 @@
package com.jamesdpeters.minecraft.chests.api;
import com.jamesdpeters.minecraft.chests.Api;
import com.jamesdpeters.minecraft.chests.ChestOpener;
import com.jamesdpeters.minecraft.chests.MaterialChecker;
import com.jamesdpeters.minecraft.chests.NMSProvider;
import lombok.Getter;
@ -12,17 +11,14 @@ public class ApiSpecific {
@Getter
private static MaterialChecker materialChecker;
@Getter
private static ChestOpener chestOpener;
@Getter
private static NMSProvider nmsProvider;
public static boolean init(Plugin plugin) {
nmsProvider = Api.init(plugin);
if (nmsProvider != null) {
materialChecker = nmsProvider.getMaterialChecker();
chestOpener = nmsProvider.getChestOpener();
}
return (nmsProvider != null && materialChecker != null && chestOpener != null);
return (nmsProvider != null && materialChecker != null);
}
}

View File

@ -58,7 +58,7 @@ public class ItemTypeUtil {
tags.add(Tag.ITEMS_BANNERS);
tags.add(Tag.ITEMS_BOATS);
tags.add(Tag.ITEMS_FISHES);
tags.add(Tag.ITEMS_MUSIC_DISCS);
tags.add(Tag.ITEMS_CREEPER_DROP_MUSIC_DISCS);
tags.add(Tag.ITEMS_COALS);
tags.add(Tag.ITEMS_ARROWS);
}

View File

@ -1,49 +0,0 @@
package com.jamesdpeters.minecraft.chests.interfaces;
import org.bukkit.entity.HumanEntity;
import org.bukkit.event.inventory.InventoryType;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryView;
import org.jetbrains.annotations.NotNull;
public class InventoryViewImpl extends InventoryView {
Inventory top, bottom;
HumanEntity humanEntity;
public InventoryViewImpl(Inventory top, Inventory bottom, HumanEntity humanEntity){
this.top = top;
this.bottom = bottom;
this.humanEntity = humanEntity;
}
@NotNull
@Override
public Inventory getTopInventory() {
return top;
}
@NotNull
@Override
public Inventory getBottomInventory() {
return bottom;
}
@NotNull
@Override
public HumanEntity getPlayer() {
return humanEntity;
}
@NotNull
@Override
public InventoryType getType() {
return InventoryType.WORKBENCH;
}
@NotNull
@Override
public String getTitle() {
return "ChestsPlusPlusInventoryView";
}
}

View File

@ -1,57 +1,67 @@
package com.jamesdpeters.minecraft.chests;
package com.jamesdpeters.minecraft.chests.listeners;
import com.jamesdpeters.minecraft.chests.PluginConfig;
import com.jamesdpeters.minecraft.chests.Values;
import org.bukkit.Chunk;
import org.bukkit.World;
import org.bukkit.block.Hopper;
import org.bukkit.entity.Entity;
import org.bukkit.entity.ItemFrame;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.world.EntitiesLoadEvent;
import org.bukkit.persistence.PersistentDataType;
import java.util.Arrays;
import java.util.stream.Stream;
public abstract class EntityEventListener implements Listener {
public class EntityEventListener implements Listener {
protected void fixEntities(Chunk chunk) {
@EventHandler
void onEntityLoad(EntitiesLoadEvent event) {
event.getEntities().forEach(EntityEventListener::removeEntity);
}
protected static void fixEntities(Chunk chunk) {
removeEntities(chunk);
setItemFrames(chunk);
}
public void fixEntities(World world) {
public static void fixEntities(World world) {
removeEntities(world);
setItemFrames(world);
}
private void removeEntities(World world) {
world.getEntities().forEach(this::removeEntity);
private static void removeEntities(World world) {
world.getEntities().forEach(EntityEventListener::removeEntity);
}
private void removeEntities(Chunk chunk) {
private static void removeEntities(Chunk chunk) {
for (Entity entity : chunk.getEntities()) {
removeEntity(entity);
}
}
protected void removeEntity(Entity entity) {
protected static void removeEntity(Entity entity) {
Integer val = entity.getPersistentDataContainer().get(Values.Instance().PluginKey, PersistentDataType.INTEGER);
if (val != null && val == 1)
entity.remove();
}
private void setItemFrames(World world) {
private static void setItemFrames(World world) {
setItemFrames(world.getEntities().stream());
}
private void setItemFrames(Chunk chunk) {
private static void setItemFrames(Chunk chunk) {
setItemFrames(Arrays.stream(chunk.getEntities()));
}
private void setItemFrames(Stream<Entity> entityStream) {
private static void setItemFrames(Stream<Entity> entityStream) {
entityStream
// Filter Item frames that are connected to Hoppers.
.filter(entity -> (entity instanceof ItemFrame
&& entity.getLocation().getBlock().getRelative(((ItemFrame) entity).getAttachedFace()).getState() instanceof Hopper))
.forEach(entity -> ((ItemFrame) entity).setVisible(!PluginConfig.INVISIBLE_FILTER_ITEM_FRAMES.get()));
}
}

View File

@ -1,13 +1,12 @@
package com.jamesdpeters.minecraft.chests.listeners;
import com.jamesdpeters.minecraft.chests.ChestsPlusPlus;
import com.jamesdpeters.minecraft.chests.api.ApiSpecific;
import com.jamesdpeters.minecraft.chests.PluginConfig;
import com.jamesdpeters.minecraft.chests.filters.HopperFilter;
import com.jamesdpeters.minecraft.chests.lang.Message;
import com.jamesdpeters.minecraft.chests.misc.ServerType;
import com.jamesdpeters.minecraft.chests.misc.Utils;
import com.jamesdpeters.minecraft.chests.serialize.Config;
import com.jamesdpeters.minecraft.chests.PluginConfig;
import com.jamesdpeters.minecraft.chests.serialize.SpigotConfig;
import com.jamesdpeters.minecraft.chests.storage.chestlink.ChestLinkStorage;
import com.jamesdpeters.minecraft.chests.storage.chestlink.ChestLinkStorageType;
@ -119,7 +118,7 @@ public class HopperFilterListener implements Listener {
Rotation rotation = itemFrame.getRotation();
//Set ItemFrame invisible based on config.
ApiSpecific.getNmsProvider().setItemFrameVisible(itemFrame, !PluginConfig.INVISIBLE_FILTER_ITEM_FRAMES.get());
itemFrame.setVisible(!PluginConfig.INVISIBLE_FILTER_ITEM_FRAMES.get());
//ItemFrame event acts weird, it returns the values of the itemframe *before* the event. So we have to calculate what the next state will be.
if (!itemFrame.getItem().getType().equals(Material.AIR)) rotation = rotation.rotateClockwise();

View File

@ -1,12 +1,11 @@
package com.jamesdpeters.minecraft.chests.misc;
import com.jamesdpeters.minecraft.chests.ChestsPlusPlus;
import com.jamesdpeters.minecraft.chests.api.ApiSpecific;
import com.jamesdpeters.minecraft.chests.PluginConfig;
import com.jamesdpeters.minecraft.chests.filters.Filter;
import com.jamesdpeters.minecraft.chests.filters.HopperFilter;
import com.jamesdpeters.minecraft.chests.interfaces.VirtualInventoryHolder;
import com.jamesdpeters.minecraft.chests.serialize.LocationInfo;
import com.jamesdpeters.minecraft.chests.PluginConfig;
import com.jamesdpeters.minecraft.chests.storage.chestlink.ChestLinkStorage;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
@ -18,7 +17,7 @@ import org.bukkit.Sound;
import org.bukkit.World;
import org.bukkit.block.Block;
import org.bukkit.block.BlockFace;
import org.bukkit.block.Container;
import org.bukkit.block.Lidded;
import org.bukkit.entity.Entity;
import org.bukkit.entity.Player;
import org.bukkit.event.inventory.InventoryType;
@ -30,7 +29,6 @@ import org.bukkit.util.Vector;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Enumeration;
import java.util.HashMap;
@ -59,18 +57,26 @@ public class Utils {
private static void containerAnimation(Inventory inventory, LocationInfo location, boolean open) {
if (location != null && Utils.isLocationChunkLoaded(location.getLocation())) {
Block block = location.getLocation().getBlock();
if (block.getState() instanceof Container chest) {
if (block.getState() instanceof Lidded chest) {
if (open) {
location.setTileEntityOpener(ApiSpecific.getChestOpener().updateState(inventory, chest, location.getTileEntityOpener()));
checkChestState(chest, inventory);
} else {
Bukkit.getScheduler().scheduleSyncDelayedTask(ChestsPlusPlus.PLUGIN, () -> {
location.setTileEntityOpener(ApiSpecific.getChestOpener().updateState(inventory, chest, location.getTileEntityOpener()));
checkChestState(chest, inventory);
}, 1);
}
}
}
}
private static void checkChestState(Lidded lidded, Inventory inventory) {
if (!inventory.getViewers().isEmpty()) {
lidded.open();
} else {
lidded.close();
}
}
public static void closeStorageInventory(ChestLinkStorage storage) {
storage.getLocations().forEach(locationInfo -> {
Location location = locationInfo.getLocation();

View File

@ -1,6 +1,5 @@
package com.jamesdpeters.minecraft.chests.serialize;
import com.jamesdpeters.minecraft.chests.TileEntityOpener;
import org.bukkit.Location;
import org.bukkit.block.Sign;
import org.bukkit.configuration.serialization.ConfigurationSerializable;
@ -20,7 +19,6 @@ public class LocationInfo implements ConfigurationSerializable {
private final Location location;
private Location signLocation;
private ArmorStand itemStand, blockStand, toolItemStand;
private TileEntityOpener tileEntityOpener;
@Override
public Map<String, Object> serialize() {
@ -80,14 +78,6 @@ public class LocationInfo implements ConfigurationSerializable {
this.signLocation = signLocation;
}
public void setTileEntityOpener(TileEntityOpener tileEntityOpener) {
this.tileEntityOpener = tileEntityOpener;
}
public TileEntityOpener getTileEntityOpener() {
return tileEntityOpener;
}
public static List<LocationInfo> convert(List<Location> locationList) {
List<LocationInfo> locationInfos = new ArrayList<>();
for (Location location : locationList) {

View File

@ -1,4 +1,4 @@
# Chests++ Language File (Version 2.12-Release)
# Chests++ Language File (Version 2.13-Release)
# NOTE: This file gets replaced when the plugin launches! If you want to make modifications create a copy first!
# To create a new language file simply create a copy of this file and rename it to your desired choice for example 'en_US.properties'
# It should be located in the 'lang' folder

View File

@ -17,15 +17,6 @@
<modules>
<module>ChestsPlusPlusAPI</module>
<module>ChestsPlusPlus_1_21_R1</module>
<module>ChestsPlusPlus_1_20_R3</module>
<module>ChestsPlusPlus_1_20_R2</module>
<module>ChestsPlusPlus_1_20_R1</module>
<module>ChestsPlusPlus_1_19_R3</module>
<module>ChestsPlusPlus_1_19_R2</module>
<module>ChestsPlusPlus_1_19_R1</module>
<module>ChestsPlusPlus_1_18_R2</module>
<module>ChestsPlusPlus_1_18_R1</module>
<module>ChestsPlusPlus_1_17_R1</module>
<module>ChestsPlusPlus_Main</module>
</modules>