#539 PR requested changes
This commit is contained in:
parent
3820bba66c
commit
a59c3c786d
4
pom.xml
4
pom.xml
|
@ -374,8 +374,8 @@
|
|||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>17</source>
|
||||
<target>17</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
<plugin>
|
||||
|
|
|
@ -1,15 +1,11 @@
|
|||
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 org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.ItemStack;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author Acrobot
|
||||
*/
|
||||
|
@ -41,6 +37,10 @@ public class InventoryUtil {
|
|||
return 0;
|
||||
}
|
||||
|
||||
if (inventory.getType() == null) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
HashMap<Integer, ? extends ItemStack> items = inventory.all(item.getType());
|
||||
int itemAmount = 0;
|
||||
|
||||
|
|
|
@ -1,19 +1,14 @@
|
|||
package com.Acrobot.ChestShop.Listeners.Item;
|
||||
|
||||
import com.Acrobot.ChestShop.Configuration.Properties;
|
||||
import com.Acrobot.ChestShop.Listeners.Modules.StockCounterModule;
|
||||
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.Hopper;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.event.EventHandler;
|
||||
import org.bukkit.event.EventPriority;
|
||||
import org.bukkit.event.Listener;
|
||||
import org.bukkit.event.inventory.InventoryMoveItemEvent;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
||||
import static com.Acrobot.Breeze.Utils.ImplementationAdapter.getHolder;
|
||||
|
@ -30,18 +25,8 @@ public class ItemMoveListener implements Listener {
|
|||
|
||||
if (!(destinationHolder instanceof BlockState) && ChestShopSign.isShopBlock(sourceHolder)) {
|
||||
event.setCancelled(true);
|
||||
} else if (ChestShopSign.isShopBlock(destinationHolder) && sourceHolder instanceof Hopper) {
|
||||
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(event.getItem().clone());
|
||||
|
||||
StockCounterModule.updateCounterOnQuantityLine(connectedSign, tempInv);
|
||||
|
||||
tempInv.clear();
|
||||
tempInv.close();
|
||||
} else if (Properties.USE_STOCK_COUNTER && ChestShopSign.isShopBlock(destinationHolder) && sourceHolder instanceof Hopper) {
|
||||
StockCounterModule.updateCounterOnItemMoveEvent(event.getItem(), destinationHolder);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,8 +8,10 @@ import com.Acrobot.ChestShop.Events.ItemParseEvent;
|
|||
import com.Acrobot.ChestShop.Events.PreShopCreationEvent;
|
||||
import com.Acrobot.ChestShop.Events.TransactionEvent;
|
||||
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.Container;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.event.EventHandler;
|
||||
|
@ -143,6 +145,20 @@ public class StockCounterModule implements Listener {
|
|||
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) {
|
||||
int quantity;
|
||||
try {
|
||||
|
|
|
@ -11,11 +11,7 @@ import com.Acrobot.ChestShop.Permission;
|
|||
import com.Acrobot.ChestShop.UUIDs.NameManager;
|
||||
import com.Acrobot.ChestShop.Utils.uBlock;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.block.Block;
|
||||
import org.bukkit.block.BlockState;
|
||||
import org.bukkit.block.Chest;
|
||||
import org.bukkit.block.DoubleChest;
|
||||
import org.bukkit.block.Sign;
|
||||
import org.bukkit.block.*;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.inventory.Inventory;
|
||||
import org.bukkit.inventory.InventoryHolder;
|
||||
|
@ -110,31 +106,31 @@ public class ChestShopSign {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (holder instanceof DoubleChest dChest) {
|
||||
return isShopChest(dChest.getLocation().getBlock());
|
||||
} else if (holder instanceof Chest chest) {
|
||||
return isShopChest(chest.getBlock());
|
||||
if (holder instanceof DoubleChest) {
|
||||
return isShopChest(((DoubleChest) holder).getLocation().getBlock());
|
||||
} else if (holder instanceof Chest) {
|
||||
return isShopChest(((Chest) holder).getBlock());
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isShopBlock(InventoryHolder holder) {
|
||||
if (holder instanceof DoubleChest dChest) {
|
||||
return isShopBlock(dChest.getLeftSide())
|
||||
|| isShopBlock(dChest.getRightSide());
|
||||
} else if (holder instanceof BlockState blockState) {
|
||||
return isShopBlock(blockState.getBlock());
|
||||
if (holder instanceof DoubleChest) {
|
||||
return isShopBlock(((DoubleChest) holder).getLeftSide())
|
||||
|| isShopBlock(((DoubleChest) holder).getRightSide());
|
||||
} else if (holder instanceof BlockState) {
|
||||
return isShopBlock(((BlockState) holder).getBlock());
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static Block getShopBlock(InventoryHolder holder) {
|
||||
if (holder instanceof DoubleChest dChest) {
|
||||
return Optional.ofNullable(getShopBlock(dChest.getLeftSide()))
|
||||
.orElse(getShopBlock(dChest.getRightSide()));
|
||||
} else if (holder instanceof BlockState state) {
|
||||
return state.getBlock();
|
||||
if (holder instanceof DoubleChest) {
|
||||
return Optional.ofNullable(getShopBlock(((DoubleChest) holder).getLeftSide()))
|
||||
.orElse(getShopBlock(((DoubleChest) holder).getRightSide()));
|
||||
} else if (holder instanceof BlockState) {
|
||||
return ((BlockState) holder).getBlock();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue