Advertisement
broken-arrow

Untitled

Oct 10th, 2021
978
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.34 KB | None | 0 0
  1. public class HopperMoveTask {
  2.  
  3.     @Getter
  4.     private static final HopperMoveTask instance = new HopperMoveTask();
  5.  
  6.  
  7.     private Map<Location, Hopper> cachedHoppers = new HashMap<>();
  8.     private static final ChestStorage plugin = ChestStorage.getInstance();
  9.     boolean testing = true;
  10.  
  11.     public void moveItemsToHopperTask(Location location, ContainerRegistryAPI registry) {
  12.  
  13.         if (!location.getWorld().isChunkLoaded(location.getBlockX() >> 4, location.getBlockZ() >> 4)) return;
  14.         //System.out.println((location.getBlockX() >> 4) + " " + (location.getBlockZ() >> 4));
  15.         //if (!PluginConfig.SHOULD_RUN_HOPPERS_UNLOADED_CHUNKS.get() && !Utils.isLocationChunkLoaded(location.getLocation()))
  16.         //  continue;
  17.         Hopper hopper;
  18.  
  19.         Location below = location.clone().subtract(0, 1, 0);
  20.         if (!isCachedHoppers(location)) {
  21.             System.out.println("test bbbb " + below.getBlock().getState().getBlock().getType());
  22.             //System.out.println("test ");
  23.             if (below.getBlock().getState() instanceof Hopper) {
  24.                 System.out.println("test ");
  25.                 hopper = (Hopper) below.getBlock().getState();
  26.                 cachedHoppers.put(location, hopper);
  27.             }
  28.         }
  29.         if (cachedHoppers.containsKey(location)) {
  30.             if (below.getBlock().isBlockIndirectlyPowered() || below.getBlock().isBlockPowered()) {
  31.                 return;
  32.             }
  33.             hopper = cachedHoppers.get(location);
  34.             if (registry.getTypeofContainer(location) != null) {
  35.                 InventoryHolders holder = plugin.getClassinstans().createObjektInventoryHolder(location, null);
  36.                 switch (registry.getTypeofContainer(location)) {
  37.                     case PAGEDCONTAINER:
  38.                     case CRAFTINGCONTAINER:
  39.                         //System.out.println("test move items hopper move items " );
  40.                         Inventory inventory = holder.getEmptyPages(registry);
  41.                         if (move(hopper.getLocation(), inventory, hopper.getInventory(), location)) {
  42.                             if (MainSettings.getInstance().getSettingsData().isHologramsUpdatewhenHopperMoveitems())
  43.                                 HologramsTask.hologramsrun(location, registry);
  44.                             System.out.println("test move items hopper move items ");
  45.                         }
  46.                         break;
  47.                     case STORAGEUNIT:
  48.                         if (HopperMoveItems.addItemsToHopperFromStorageUnit(registry, location, hopper.getInventory())) {
  49.                             Common.runLaterAsync(3, () -> holder.updateInventoryTitle(registry.getAmontOfItems(location), null));
  50.                             if (MainSettings.getInstance().getSettingsData().isHologramsUpdatewhenHopperMoveitems())
  51.                                 HologramsTask.hologramsrun(location, registry);
  52.                             break;
  53.                         }
  54.                         break;
  55.                     default:
  56.                         break;
  57.                 }
  58.             }
  59.  
  60.         }
  61.         //if (registry.getInventory().getViewers().size() > 0) registry.sort();
  62.  
  63.     }
  64.  
  65.  
  66.     public static boolean move(Location targetLocation, Inventory source, Inventory target, Location location) {
  67.         int hopperAmount = plugin.getHopperItemMoveAmountDefult().getDefultAmountMovedFromAndToHopper();
  68.         return HopperMoveItems.hopperMoveItemFromChest(source, hopperAmount, target, location, targetLocation);
  69.  
  70.     }
  71.  
  72.     public boolean isTesting() {
  73.         return testing;
  74.     }
  75.  
  76.     public boolean isCachedHoppers(Location location) {
  77.         boolean containsLoc = false;
  78.         for (Location locations : cachedHoppers.keySet()) {
  79.             containsLoc = locations.equals(location);
  80.         }
  81.         return containsLoc;
  82.     }
  83.  
  84.     public void removeCachedHoppers(Location containerLocation) {
  85.         cachedHoppers.remove(containerLocation);
  86.     }
  87.  
  88.     public void setTesting(boolean testing) {
  89.         this.testing = testing;
  90.     }
  91. }
  92.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement