#539 PR requested changes

This commit is contained in:
Johanmans10 2024-05-02 22:57:52 +02:00
parent 3820bba66c
commit a59c3c786d
5 changed files with 42 additions and 45 deletions

View File

@ -374,8 +374,8 @@
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version> <version>3.8.1</version>
<configuration> <configuration>
<source>17</source> <source>1.8</source>
<target>17</target> <target>1.8</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>

View File

@ -1,15 +1,11 @@
package com.Acrobot.Breeze.Utils; package com.Acrobot.Breeze.Utils;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import com.Acrobot.ChestShop.Configuration.Properties; import com.Acrobot.ChestShop.Configuration.Properties;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.ItemStack; import org.bukkit.inventory.ItemStack;
import java.util.*;
/** /**
* @author Acrobot * @author Acrobot
*/ */
@ -41,6 +37,10 @@ public class InventoryUtil {
return 0; return 0;
} }
if (inventory.getType() == null) {
return Integer.MAX_VALUE;
}
HashMap<Integer, ? extends ItemStack> items = inventory.all(item.getType()); HashMap<Integer, ? extends ItemStack> items = inventory.all(item.getType());
int itemAmount = 0; int itemAmount = 0;

View File

@ -1,19 +1,14 @@
package com.Acrobot.ChestShop.Listeners.Item; package com.Acrobot.ChestShop.Listeners.Item;
import com.Acrobot.ChestShop.Configuration.Properties;
import com.Acrobot.ChestShop.Listeners.Modules.StockCounterModule; import com.Acrobot.ChestShop.Listeners.Modules.StockCounterModule;
import com.Acrobot.ChestShop.Signs.ChestShopSign; import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.Utils.ItemUtil;
import com.Acrobot.ChestShop.Utils.uBlock;
import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.block.BlockState; import org.bukkit.block.BlockState;
import org.bukkit.block.Hopper; import org.bukkit.block.Hopper;
import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
import org.bukkit.event.EventPriority; import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import org.bukkit.event.inventory.InventoryMoveItemEvent; import org.bukkit.event.inventory.InventoryMoveItemEvent;
import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
import static com.Acrobot.Breeze.Utils.ImplementationAdapter.getHolder; import static com.Acrobot.Breeze.Utils.ImplementationAdapter.getHolder;
@ -30,18 +25,8 @@ public class ItemMoveListener implements Listener {
if (!(destinationHolder instanceof BlockState) && ChestShopSign.isShopBlock(sourceHolder)) { if (!(destinationHolder instanceof BlockState) && ChestShopSign.isShopBlock(sourceHolder)) {
event.setCancelled(true); event.setCancelled(true);
} else if (ChestShopSign.isShopBlock(destinationHolder) && sourceHolder instanceof Hopper) { } else if (Properties.USE_STOCK_COUNTER && ChestShopSign.isShopBlock(destinationHolder) && sourceHolder instanceof Hopper) {
Block shopBlock = ChestShopSign.getShopBlock(destinationHolder); StockCounterModule.updateCounterOnItemMoveEvent(event.getItem(), destinationHolder);
Sign connectedSign = uBlock.getConnectedSign(shopBlock);
Inventory tempInv = Bukkit.createInventory(null, destinationHolder.getInventory().getSize() + 9);
tempInv.setContents(ItemUtil.deepClone(destinationHolder.getInventory().getContents()));
tempInv.addItem(event.getItem().clone());
StockCounterModule.updateCounterOnQuantityLine(connectedSign, tempInv);
tempInv.clear();
tempInv.close();
} }
} }

View File

@ -8,8 +8,10 @@ import com.Acrobot.ChestShop.Events.ItemParseEvent;
import com.Acrobot.ChestShop.Events.PreShopCreationEvent; import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
import com.Acrobot.ChestShop.Events.TransactionEvent; import com.Acrobot.ChestShop.Events.TransactionEvent;
import com.Acrobot.ChestShop.Signs.ChestShopSign; import com.Acrobot.ChestShop.Signs.ChestShopSign;
import com.Acrobot.ChestShop.Utils.ItemUtil;
import com.Acrobot.ChestShop.Utils.uBlock; import com.Acrobot.ChestShop.Utils.uBlock;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.block.Block;
import org.bukkit.block.Container; import org.bukkit.block.Container;
import org.bukkit.block.Sign; import org.bukkit.block.Sign;
import org.bukkit.event.EventHandler; import org.bukkit.event.EventHandler;
@ -143,6 +145,20 @@ public class StockCounterModule implements Listener {
sign.update(true); sign.update(true);
} }
public static void updateCounterOnItemMoveEvent(ItemStack toAdd, InventoryHolder destinationHolder) {
Block shopBlock = ChestShopSign.getShopBlock(destinationHolder);
Sign connectedSign = uBlock.getConnectedSign(shopBlock);
Inventory tempInv = Bukkit.createInventory(null, destinationHolder.getInventory().getSize() + 9);
tempInv.setContents(ItemUtil.deepClone(destinationHolder.getInventory().getContents()));
tempInv.addItem(toAdd.clone());
updateCounterOnQuantityLine(connectedSign, tempInv);
tempInv.clear();
tempInv.close();
}
public static void removeCounterFromQuantityLine(Sign sign) { public static void removeCounterFromQuantityLine(Sign sign) {
int quantity; int quantity;
try { try {

View File

@ -11,11 +11,7 @@ import com.Acrobot.ChestShop.Permission;
import com.Acrobot.ChestShop.UUIDs.NameManager; import com.Acrobot.ChestShop.UUIDs.NameManager;
import com.Acrobot.ChestShop.Utils.uBlock; import com.Acrobot.ChestShop.Utils.uBlock;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.block.Block; import org.bukkit.block.*;
import org.bukkit.block.BlockState;
import org.bukkit.block.Chest;
import org.bukkit.block.DoubleChest;
import org.bukkit.block.Sign;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.bukkit.inventory.Inventory; import org.bukkit.inventory.Inventory;
import org.bukkit.inventory.InventoryHolder; import org.bukkit.inventory.InventoryHolder;
@ -110,31 +106,31 @@ public class ChestShopSign {
return false; return false;
} }
if (holder instanceof DoubleChest dChest) { if (holder instanceof DoubleChest) {
return isShopChest(dChest.getLocation().getBlock()); return isShopChest(((DoubleChest) holder).getLocation().getBlock());
} else if (holder instanceof Chest chest) { } else if (holder instanceof Chest) {
return isShopChest(chest.getBlock()); return isShopChest(((Chest) holder).getBlock());
} else { } else {
return false; return false;
} }
} }
public static boolean isShopBlock(InventoryHolder holder) { public static boolean isShopBlock(InventoryHolder holder) {
if (holder instanceof DoubleChest dChest) { if (holder instanceof DoubleChest) {
return isShopBlock(dChest.getLeftSide()) return isShopBlock(((DoubleChest) holder).getLeftSide())
|| isShopBlock(dChest.getRightSide()); || isShopBlock(((DoubleChest) holder).getRightSide());
} else if (holder instanceof BlockState blockState) { } else if (holder instanceof BlockState) {
return isShopBlock(blockState.getBlock()); return isShopBlock(((BlockState) holder).getBlock());
} }
return false; return false;
} }
public static Block getShopBlock(InventoryHolder holder) { public static Block getShopBlock(InventoryHolder holder) {
if (holder instanceof DoubleChest dChest) { if (holder instanceof DoubleChest) {
return Optional.ofNullable(getShopBlock(dChest.getLeftSide())) return Optional.ofNullable(getShopBlock(((DoubleChest) holder).getLeftSide()))
.orElse(getShopBlock(dChest.getRightSide())); .orElse(getShopBlock(((DoubleChest) holder).getRightSide()));
} else if (holder instanceof BlockState state) { } else if (holder instanceof BlockState) {
return state.getBlock(); return ((BlockState) holder).getBlock();
} }
return null; return null;
} }