Advertisement
broken-arrow

Untitled

May 27th, 2021
794
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.66 KB | None | 0 0
  1. import org.bukkit.Location;
  2. import org.bukkit.block.Hopper;
  3. import org.bukkit.inventory.Inventory;
  4. import org.bukkit.scheduler.BukkitRunnable;
  5. import org.bukkit.scheduler.BukkitTask;
  6. import org.mineacademy.sharedinventory.listener.PlayerListener;
  7.  
  8. import java.util.ArrayList;
  9.  
  10. public class HopperMoveTask extends BukkitRunnable {
  11.  
  12.  
  13.     //private final InventoryRegistry registry;
  14.  
  15.     BukkitTask task;
  16.  
  17.     public void start() {
  18.         task = runTaskTimer(SharedInventoryPlugin.getInstance(), 1, 8);
  19.     }
  20.  
  21.     public void stop() {
  22.         task.cancel();
  23.     }
  24.  
  25.     @Override
  26.     public void run() {
  27.         InventoryRegistry registry = InventoryRegistry.getInstance();
  28.         //Location location = registry.getChestlocations();
  29.         ArrayList<Location> locationList = registry.getChestlocations();
  30.         //System.out.println("test if it run" + location);
  31.         if (locationList != null)
  32.             for (Location location : locationList) {
  33.                 if (location != null) {
  34.                     //if (location.getLocation() != null) {
  35.                     //if (!PluginConfig.SHOULD_RUN_HOPPERS_UNLOADED_CHUNKS.get() && !Utils.isLocationChunkLoaded(location.getLocation()))
  36.                     //  continue;
  37.                     Location below = location.clone().subtract(0, 1, 0);
  38.                     if (below.getBlock().getState() instanceof Hopper) {
  39.                         Hopper hopper = (Hopper) below.getBlock().getState();
  40.                         if (below.getBlock().isBlockIndirectlyPowered() || below.getBlock().isBlockPowered()) {
  41.                             continue;
  42.                         }
  43.                         //ArrayList<Inventory> inventors = registry.findAndLoadInventory(location);
  44.                         InventoryHolder holder = InventoryHolder.getInstance();
  45.                         ArrayList<Inventory> invento = holder.getInventory(location);
  46.                         if (invento == null)
  47.                             holder.getPage(0, location);
  48.  
  49.  
  50.                         Inventory inventory = invento.get(0);
  51.                         //System.out.println(inventory);
  52.                         //registry.findAndLoadInventoryHopper(location);
  53.                         //Inventory inventory = inventors.get(0);
  54.                         /*System.out.println("location in db " + location);
  55.                         System.out.println("hopper.getLocation()" + hopper.getLocation());*/
  56.                 /*System.out.println("inventory" + inventory);
  57.                 System.out.println("hopper.getLocation()" + hopper.getLocation());
  58.                 System.out.println("hopper.getInventory()" + hopper.getInventory());*/
  59.  
  60.                         if (move(hopper.getLocation(), inventory, hopper.getInventory())) {
  61.                             //registry.updateDisplayItem();
  62.                             System.out.println("test");
  63.                         }
  64.                         //if (registry.getInventory().getViewers().size() > 0) registry.sort();
  65.                     }
  66.                     //}
  67.                 }
  68.             }
  69.     }
  70.  
  71.  
  72.     public static boolean move(Location targetLocation, Inventory source, Inventory target) {
  73.         int hopperAmount = 1;
  74.         return PlayerListener.hopperMoveItemFromToChest(source, hopperAmount, target);
  75.     }
  76. }
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement