Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HopperMoveTask {
- @Getter
- private static final HopperMoveTask instance = new HopperMoveTask();
- private Map<Location, Hopper> cachedHoppers = new HashMap<>();
- private static final ChestStorage plugin = ChestStorage.getInstance();
- boolean testing = true;
- public void moveItemsToHopperTask(Location location, ContainerRegistryAPI registry) {
- if (!location.getWorld().isChunkLoaded(location.getBlockX() >> 4, location.getBlockZ() >> 4)) return;
- //System.out.println((location.getBlockX() >> 4) + " " + (location.getBlockZ() >> 4));
- //if (!PluginConfig.SHOULD_RUN_HOPPERS_UNLOADED_CHUNKS.get() && !Utils.isLocationChunkLoaded(location.getLocation()))
- // continue;
- Hopper hopper;
- Location below = location.clone().subtract(0, 1, 0);
- if (!isCachedHoppers(location)) {
- System.out.println("test bbbb " + below.getBlock().getState().getBlock().getType());
- //System.out.println("test ");
- if (below.getBlock().getState() instanceof Hopper) {
- System.out.println("test ");
- hopper = (Hopper) below.getBlock().getState();
- cachedHoppers.put(location, hopper);
- }
- }
- if (cachedHoppers.containsKey(location)) {
- if (below.getBlock().isBlockIndirectlyPowered() || below.getBlock().isBlockPowered()) {
- return;
- }
- hopper = cachedHoppers.get(location);
- if (registry.getTypeofContainer(location) != null) {
- InventoryHolders holder = plugin.getClassinstans().createObjektInventoryHolder(location, null);
- switch (registry.getTypeofContainer(location)) {
- case PAGEDCONTAINER:
- case CRAFTINGCONTAINER:
- //System.out.println("test move items hopper move items " );
- Inventory inventory = holder.getEmptyPages(registry);
- if (move(hopper.getLocation(), inventory, hopper.getInventory(), location)) {
- if (MainSettings.getInstance().getSettingsData().isHologramsUpdatewhenHopperMoveitems())
- HologramsTask.hologramsrun(location, registry);
- System.out.println("test move items hopper move items ");
- }
- break;
- case STORAGEUNIT:
- if (HopperMoveItems.addItemsToHopperFromStorageUnit(registry, location, hopper.getInventory())) {
- Common.runLaterAsync(3, () -> holder.updateInventoryTitle(registry.getAmontOfItems(location), null));
- if (MainSettings.getInstance().getSettingsData().isHologramsUpdatewhenHopperMoveitems())
- HologramsTask.hologramsrun(location, registry);
- break;
- }
- break;
- default:
- break;
- }
- }
- }
- //if (registry.getInventory().getViewers().size() > 0) registry.sort();
- }
- public static boolean move(Location targetLocation, Inventory source, Inventory target, Location location) {
- int hopperAmount = plugin.getHopperItemMoveAmountDefult().getDefultAmountMovedFromAndToHopper();
- return HopperMoveItems.hopperMoveItemFromChest(source, hopperAmount, target, location, targetLocation);
- }
- public boolean isTesting() {
- return testing;
- }
- public boolean isCachedHoppers(Location location) {
- boolean containsLoc = false;
- for (Location locations : cachedHoppers.keySet()) {
- containsLoc = locations.equals(location);
- }
- return containsLoc;
- }
- public void removeCachedHoppers(Location containerLocation) {
- cachedHoppers.remove(containerLocation);
- }
- public void setTesting(boolean testing) {
- this.testing = testing;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement