Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import org.broken.cheststorage.ChestStorage;
- import org.broken.cheststorage.Crafting.FilterItems;
- import org.broken.cheststorage.cache.ContainerRegistry;
- import org.broken.cheststorage.containerholders.InventoryHolder;
- import org.broken.cheststorage.containerholders.InventoryHolderDefultchest;
- import org.broken.cheststorage.containerholders.InventoryHolderStorageUnit;
- import org.broken.cheststorage.util.MathCalations;
- import org.broken.cheststorage.util.YamlSettingsContainers;
- import org.bukkit.*;
- import org.bukkit.block.Barrel;
- import org.bukkit.block.Block;
- import org.bukkit.block.Chest;
- import org.bukkit.block.Hopper;
- import org.bukkit.entity.Entity;
- import org.bukkit.entity.Item;
- import org.bukkit.inventory.Inventory;
- import org.bukkit.inventory.ItemStack;
- import org.bukkit.scheduler.BukkitRunnable;
- import org.bukkit.scheduler.BukkitTask;
- import java.util.*;
- import java.util.concurrent.ConcurrentLinkedDeque;
- public class TeleportLinkItemsTask extends BukkitRunnable {
- private final ChestStorage plugin = ChestStorage.getInstance();
- private BukkitTask task;
- private World world;
- private Inventory hopperInventory;
- private Inventory containerInventory;
- private List<Location> locations = new ArrayList<>();
- private static final Queue<Location> workloadDeque = new ConcurrentLinkedDeque<>();
- private static final Map<Integer, List<Location>> workloadmap = new HashMap<>();
- private static final Map<Location, TeleportItems> hopersuctionTeleportmap = new HashMap<>();
- private int conter = 0;
- int delayItemPicupTeleport = 0;
- public void start() {
- if (task != null && (Bukkit.getScheduler().isCurrentlyRunning(task.getTaskId()) || Bukkit.getScheduler().isQueued(task.getTaskId())))
- Bukkit.getScheduler().cancelTask(task.getTaskId());
- task = runTaskTimer(ChestStorage.getInstance(), 0L, 1L);
- }
- public void tick() {
- }
- public void stop() {
- task.cancel();
- }
- private final ContainerRegistry registry = ContainerRegistry.getInstance();
- @Override
- public void run() {
- //System.out.println("test ");
- task();
- }
- private void addvaluesMap() {
- for (Location locations : registry.getContainerlocations()) {
- List<Location> locationsList = new ArrayList<>();
- if (!locations.getWorld().isChunkLoaded(locations.getBlockX() >> 4, locations.getBlockZ() >> 4))
- continue;
- ContainerRegistry.TypeOfContainer typeOfContainer = registry.getTypeofContainer(locations);
- if (locations != null && Objects.equals(typeOfContainer, ContainerRegistry.TypeOfContainer.LINKEDCONTAINER)) {
- int secondsForPickupTeleport = YamlSettingsContainers.getSecondsForPickupTeleport(registry.getContainerFileName(locations), registry.getCurrentUpdate(locations));
- if (workloadmap.containsKey(secondsForPickupTeleport * 20) && !workloadmap.get(secondsForPickupTeleport * 20).contains(locations)) {
- locationsList.addAll(workloadmap.get(secondsForPickupTeleport * 20));
- }
- locationsList.add(locations);
- workloadmap.put(secondsForPickupTeleport * 20, locationsList);
- }
- }
- }
- private void task() {
- delayItemPicupTeleport++;
- addvaluesMap();
- if (!workloadmap.isEmpty()) {
- for (Map.Entry<Integer, List<Location>> entitys : workloadmap.entrySet())
- for (Location location : entitys.getValue())
- if (!hopersuctionTeleportmap.containsKey(location))
- hopersuctionTeleportmap.put(location, new TeleportItems(entitys.getKey(), location));
- }
- if (!hopersuctionTeleportmap.isEmpty())
- //System.out.println(hopersuctionTeleportmap);
- hopersuctionTeleportmap.values().forEach(TeleportItems::run);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement