Advertisement
broken-arrow

Untitled

Sep 2nd, 2021
726
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.11 KB | None | 0 0
  1. import org.broken.cheststorage.ChestStorage;
  2. import org.broken.cheststorage.cache.ContainerRegistry;
  3. import org.broken.cheststorage.util.YamlSettingsContainers;
  4. import org.bukkit.Bukkit;
  5. import org.bukkit.Location;
  6. import org.bukkit.scheduler.BukkitRunnable;
  7. import org.bukkit.scheduler.BukkitTask;
  8.  
  9. import java.util.HashMap;
  10. import java.util.Map;
  11. import java.util.Objects;
  12.  
  13. public class TeleportLinkItemsTask extends BukkitRunnable {
  14.  
  15.     private final ChestStorage plugin = ChestStorage.getInstance();
  16.     private BukkitTask task;
  17.    
  18.     private static final Map<Location, TeleportItems> hopersuctionTeleportmap = new HashMap<>();
  19.  
  20.     public void start() {
  21.         if (task != null && (Bukkit.getScheduler().isCurrentlyRunning(task.getTaskId()) || Bukkit.getScheduler().isQueued(task.getTaskId())))
  22.             Bukkit.getScheduler().cancelTask(task.getTaskId());
  23.         task = runTaskTimer(ChestStorage.getInstance(), 0L, 1L);
  24.     }
  25.  
  26.     public void tick() {
  27.  
  28.     }
  29.  
  30.     public void stop() {
  31.         task.cancel();
  32.     }
  33.  
  34.     private final ContainerRegistry registry = ContainerRegistry.getInstance();
  35.  
  36.     @Override
  37.     public void run() {
  38.         //System.out.println("test ");
  39.         task();
  40.  
  41.     }
  42.    
  43.     private void task() {
  44.         if (registry.getContainerlocations() != null)
  45.             for (Location locations : registry.getContainerlocations()) {
  46.                 if (!locations.getWorld().isChunkLoaded(locations.getBlockX() >> 4, locations.getBlockZ() >> 4))
  47.                     continue;
  48.                 ContainerRegistry.TypeOfContainer typeOfContainer = registry.getTypeofContainer(locations);
  49.                 if (locations != null && Objects.equals(typeOfContainer, ContainerRegistry.TypeOfContainer.LINKEDCONTAINER))
  50.                     if (!hopersuctionTeleportmap.containsKey(locations)) {
  51.                         int secondsForPickupTeleport = YamlSettingsContainers.getSecondsForPickupTeleport(registry.getContainerFileName(locations), registry.getCurrentUpdate(locations));
  52.                         hopersuctionTeleportmap.put(locations, new TeleportItems(secondsForPickupTeleport * 20, locations));
  53.                     }
  54.             }
  55.         if (!hopersuctionTeleportmap.isEmpty())
  56.             //System.out.println(hopersuctionTeleportmap);
  57.             hopersuctionTeleportmap.values().forEach(TeleportItems::run);
  58.     }
  59.    
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement