Compare commits
3 Commits
e33f812b3c
...
9533c96385
Author | SHA1 | Date |
---|---|---|
mcm | 9533c96385 | |
James Peters | cd73798499 | |
mcm | da65805fc2 |
|
@ -8,7 +8,7 @@ MAVEN_DIR="$HOME/.m2"
|
|||
SPIGOT="${MAVEN_DIR}/repository/org/spigotmc/spigot"
|
||||
|
||||
#Versions
|
||||
array=("1.18.1" "1.18.2" "1.19" "1.19.3" "1.19.4" "1.20")
|
||||
array=("1.18.1" "1.18.2" "1.19" "1.19.3" "1.19.4" "1.20" "1.20.4")
|
||||
|
||||
#Download BuildTools jar
|
||||
curl -s -o BuildTools.jar https://hub.spigotmc.org/jenkins/job/BuildTools/lastSuccessfulBuild/artifact/target/BuildTools.jar
|
||||
|
|
|
@ -0,0 +1,104 @@
|
|||
<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>
|
|
@ -0,0 +1,104 @@
|
|||
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_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;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,49 @@
|
|||
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);
|
||||
}
|
||||
|
||||
}
|
|
@ -63,7 +63,7 @@
|
|||
<dependency>
|
||||
<groupId>net.wesjd</groupId>
|
||||
<artifactId>anvilgui</artifactId>
|
||||
<version>1.9.0-SNAPSHOT</version>
|
||||
<version>1.9.2-SNAPSHOT</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
|
|
|
@ -38,6 +38,10 @@ public class HopperFilter {
|
|||
return filters;
|
||||
}
|
||||
|
||||
public static boolean hasFilters(Block block) {
|
||||
return getHopperFilters(block).size() > 0;
|
||||
}
|
||||
|
||||
public static boolean isInFilter(Block block, ItemStack itemStack) {
|
||||
return isInFilter(getHopperFilters(block), itemStack);
|
||||
}
|
||||
|
|
|
@ -36,6 +36,8 @@ public class HopperFilterListener implements Listener {
|
|||
public void onHopperMoveEvent(InventoryMoveItemEvent event) {
|
||||
//TO HOPPER
|
||||
if(event.getDestination().getHolder() instanceof Hopper){
|
||||
if(!HopperFilter.hasFilters(event.getDestination().getLocation().getBlock())) return;
|
||||
|
||||
if(event.getDestination().getLocation() != null){
|
||||
// If the event is cancelled by other plugin
|
||||
if(event.isCancelled()) return;
|
||||
|
@ -49,7 +51,8 @@ public class HopperFilterListener implements Listener {
|
|||
|
||||
// Item shouldn't be allowed
|
||||
if (event.isCancelled() && ServerType.getType() == ServerType.Type.PAPER) {
|
||||
int index = event.getSource().first(event.getItem());
|
||||
int index = event.getSource().first(event.getItem().getType());
|
||||
|
||||
int hopperAmount = SpigotConfig.getWorldSettings(event.getSource().getLocation()).getHopperAmount();
|
||||
|
||||
// Loop over the inventory until next item is found, if no item found return.
|
||||
|
@ -76,7 +79,7 @@ public class HopperFilterListener implements Listener {
|
|||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void fromHopper(InventoryMoveItemEvent event){
|
||||
//FROM HOPPER
|
||||
if (event.getInitiator().getHolder() instanceof Hopper) {
|
||||
if (event.getSource().getHolder() instanceof Hopper) {
|
||||
Location location = event.getDestination().getLocation();
|
||||
ChestLinkStorageType storageType = Config.getChestLink();
|
||||
if (storageType == null) return;
|
||||
|
|
|
@ -19,7 +19,7 @@ public class LinkedChestHopperListener implements Listener {
|
|||
@EventHandler(priority = EventPriority.HIGH)
|
||||
public void fromHopper(InventoryMoveItemEvent event) {
|
||||
//FROM HOPPER
|
||||
if (event.getInitiator().getHolder() instanceof Hopper) {
|
||||
if (event.getSource().getHolder() instanceof Hopper) {
|
||||
Location location = event.getDestination().getLocation();
|
||||
if (location == null) return;
|
||||
if (!Utils.isLocationChunkLoaded(location)) return;
|
||||
|
|
|
@ -21,6 +21,7 @@ import org.bukkit.block.BlockFace;
|
|||
import org.bukkit.block.Container;
|
||||
import org.bukkit.entity.Entity;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
||||
import org.bukkit.event.inventory.InventoryType;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
@ -95,42 +96,36 @@ public class Utils {
|
|||
//player.closeInventory();
|
||||
}
|
||||
|
||||
public static ItemStack removeStackFromInventory(Inventory inventory, int amount, List<Filter> filters) {
|
||||
ItemStack toRemove;
|
||||
for (int i = 0; i < inventory.getContents().length; i++) {
|
||||
ItemStack stack = inventory.getItem(i);
|
||||
if ((stack != null) && (HopperFilter.isInFilter(filters, stack))) {
|
||||
toRemove = stack.clone();
|
||||
toRemove.setAmount(Math.min(stack.getAmount(), amount));
|
||||
stack.setAmount(stack.getAmount() - toRemove.getAmount());
|
||||
return toRemove;
|
||||
public static boolean hopperMove(Inventory from, int amount, Inventory to) {
|
||||
// Search for an item stack to remove
|
||||
for (int i = 0; i < from.getContents().length; i++) {
|
||||
ItemStack stack = from.getItem(i);
|
||||
if (stack != null) {
|
||||
// if (hopperMove(from, stack, amount, to)) return true;
|
||||
hopperMove(from, stack, amount, to);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static boolean hopperMove(Inventory from, int amount, Inventory to, List<Filter> filters) {
|
||||
ItemStack removed = removeStackFromInventory(from, amount, filters);
|
||||
if (removed != null) {
|
||||
HashMap<Integer, ItemStack> leftOvers = to.addItem(removed);
|
||||
for (ItemStack leftOver : leftOvers.values()) {
|
||||
from.addItem(leftOver);
|
||||
if (removed.equals(leftOver)) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean hopperMove(Inventory from, int amount, Inventory to) {
|
||||
return hopperMove(from, amount, to, null);
|
||||
public static boolean hopperMove(Inventory from, ItemStack stack, int amount, Inventory to) {
|
||||
return hopperMove(from, stack, amount, to, true);
|
||||
}
|
||||
|
||||
public static boolean hopperMove(Inventory from, ItemStack stack, int amount, Inventory to) {
|
||||
public static boolean hopperMove(Inventory from, ItemStack stack, int amount, Inventory to, boolean triggerEvent) {
|
||||
if (stack != null) {
|
||||
ItemStack toRemove = stack.clone();
|
||||
toRemove.setAmount(Math.min(stack.getAmount(), amount));
|
||||
stack.setAmount(stack.getAmount() - toRemove.getAmount());
|
||||
if(triggerEvent) {
|
||||
InventoryMoveItemEvent event = new InventoryMoveItemEvent(from, toRemove.clone(), to, false);
|
||||
Bukkit.getPluginManager().callEvent(event);
|
||||
if(event.isCancelled()) {
|
||||
stack.setAmount(stack.getAmount() + toRemove.getAmount());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
HashMap<Integer, ItemStack> leftOvers = to.addItem(toRemove);
|
||||
for (ItemStack leftOver : leftOvers.values()) {
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.jamesdpeters.minecraft.chests.runnables;
|
||||
|
||||
import com.jamesdpeters.minecraft.chests.ChestsPlusPlus;
|
||||
import com.jamesdpeters.minecraft.chests.filters.HopperFilter;
|
||||
import com.jamesdpeters.minecraft.chests.misc.Utils;
|
||||
import com.jamesdpeters.minecraft.chests.serialize.LocationInfo;
|
||||
import com.jamesdpeters.minecraft.chests.serialize.SpigotConfig;
|
||||
|
@ -36,6 +35,8 @@ public class VirtualChestToHopper extends BukkitRunnable {
|
|||
if (location.getLocation() != null) {
|
||||
if (!Utils.isLocationChunkLoaded(location.getLocation()) || !location.getLocation().getChunk().isEntitiesLoaded())
|
||||
continue;
|
||||
if(storage.getInventory().isEmpty()) continue;
|
||||
|
||||
Location below = location.getLocation().clone().subtract(0, 1, 0);
|
||||
if (below.getBlock().getState() instanceof Hopper hopper) {
|
||||
if (below.getBlock().isBlockIndirectlyPowered() || below.getBlock().isBlockPowered()) {
|
||||
|
@ -53,6 +54,6 @@ public class VirtualChestToHopper extends BukkitRunnable {
|
|||
|
||||
public static boolean move(Location targetLocation, Inventory source, Inventory target) {
|
||||
int hopperAmount = SpigotConfig.getWorldSettings(targetLocation.getWorld()).getHopperAmount();
|
||||
return Utils.hopperMove(source, hopperAmount, target, HopperFilter.getHopperFilters(targetLocation.getBlock()));
|
||||
return Utils.hopperMove(source, hopperAmount, target);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue