Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.bukkit.Location;
- import org.bukkit.block.Hopper;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.scheduler.BukkitTask;
- import org.mineacademy.sharedinventory.listener.PlayerListener;
- import java.util.ArrayList;
- public class HopperMoveTask extends BukkitRunnable {
- //private final InventoryRegistry registry;
- BukkitTask task;
- public void start() {
- task = runTaskTimer(SharedInventoryPlugin.getInstance(), 1, 8);
- }
- public void stop() {
- task.cancel();
- }
- @Override
- public void run() {
- InventoryRegistry registry = InventoryRegistry.getInstance();
- //Location location = registry.getChestlocations();
- ArrayList<Location> locationList = registry.getChestlocations();
- //System.out.println("test if it run" + location);
- if (locationList != null)
- for (Location location : locationList) {
- if (location != null) {
- //if (location.getLocation() != null) {
- //if (!PluginConfig.SHOULD_RUN_HOPPERS_UNLOADED_CHUNKS.get() && !Utils.isLocationChunkLoaded(location.getLocation()))
- // continue;
- Location below = location.clone().subtract(0, 1, 0);
- if (below.getBlock().getState() instanceof Hopper) {
- Hopper hopper = (Hopper) below.getBlock().getState();
- if (below.getBlock().isBlockIndirectlyPowered() || below.getBlock().isBlockPowered()) {
- continue;
- }
- //ArrayList<Inventory> inventors = registry.findAndLoadInventory(location);
- InventoryHolder holder = InventoryHolder.getInstance();
- ArrayList<Inventory> invento = holder.getInventory(location);
- if (invento == null)
- holder.getPage(0, location);
- Inventory inventory = invento.get(0);
- //System.out.println(inventory);
- //registry.findAndLoadInventoryHopper(location);
- //Inventory inventory = inventors.get(0);
- /*System.out.println("location in db " + location);
- System.out.println("hopper.getLocation()" + hopper.getLocation());*/
- /*System.out.println("inventory" + inventory);
- System.out.println("hopper.getLocation()" + hopper.getLocation());
- System.out.println("hopper.getInventory()" + hopper.getInventory());*/
- if (move(hopper.getLocation(), inventory, hopper.getInventory())) {
- //registry.updateDisplayItem();
- System.out.println("test");
- }
- //if (registry.getInventory().getViewers().size() > 0) registry.sort();
- }
- //}
- }
- }
- }
- public static boolean move(Location targetLocation, Inventory source, Inventory target) {
- int hopperAmount = 1;
- return PlayerListener.hopperMoveItemFromToChest(source, hopperAmount, target);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement