broken-arrow

Untitled

Oct 25th, 2021 (edited)
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.06 KB | None | 0 0
  1. public class TickTask extends BukkitRunnable {
  2.  
  3.     BukkitTask task;
  4.     BukkitTask id;
  5.     private int number = 0;
  6.     private int saveData = 0;
  7.     private int updateHolo = 0;
  8.     private int updatestorageunit = 0;
  9.     private int effectsOnChest = 0;
  10.  
  11.     private boolean turnOF = false;
  12.  
  13.     PreferenceSettingsRegistery preferenceRegistery = PreferenceSettingsRegistery.getInstance();
  14.     private final MainSettings mainSettings = MainSettings.getInstance();
  15.     private final CustomContainersMainClass plugin = CustomContainersMainClass.getInstance();
  16.  
  17.     public void start() {
  18.         if (task != null && (Bukkit.getScheduler().isCurrentlyRunning(task.getTaskId()) || Bukkit.getScheduler().isQueued(task.getTaskId())))
  19.             Bukkit.getScheduler().cancelTask(task.getTaskId());
  20.         task = runTaskTimer(CustomContainersMainClass.getInstance(), 0L, 1L);
  21.     }
  22.  
  23.  
  24.     public void stop() {
  25.         task.cancel();
  26.     }
  27.  
  28.     @Override
  29.     public void run() {
  30.         //LagCatcher.start("STORAGEUNIT");
  31.         ContainerRegistryAPI registry = ContainerRegistryAPI.getInstance();
  32.         if (number >= 8) {
  33.             List<Location> loc = new ArrayList<>(registry.getContainerlocations());
  34.             for (ListIterator<Location> locations = loc.listIterator(); loc.listIterator().hasNext(); ) {
  35.  
  36.                 if (!locations.hasNext())
  37.                     break;
  38.  
  39.                 Location location = locations.next();
  40.                 //for (Location location : registry.getContainerlocations()) {
  41.                 //todo fix so you can change update time the chest
  42.                 plugin.getCraftingSellTask().craftingSelltask(location, registry);
  43.                 HopperMoveTask.getInstance().moveItemsToHopperTask(location, registry);
  44.                 number = 0;
  45.             }
  46.         }
  47.         if (updatestorageunit >= 0) {
  48.             List<Location> loc = new ArrayList<>(registry.getContainerlocations());
  49.             for (ListIterator<Location> locations = loc.listIterator(); loc.listIterator().hasNext(); ) {
  50.  
  51.                 if (!locations.hasNext())
  52.                     break;
  53.  
  54.                 Location location = locations.next();
  55.  
  56.                 //for (Location location : registry.getContainerlocations()) {
  57.  
  58.                 if (Objects.equals(registry.getTypeofContainer(location), ContainerRegistry.TypeOfContainer.STORAGEUNIT)) {
  59.                     AddItemsToStorageUnit.getInstance().getItemsFromStorageUnit(location, registry);
  60.                 }
  61.             }
  62.             updatestorageunit = 0;
  63.         }
  64.         plugin.getTeleportLinkItemsTask().task();
  65.  
  66.         if (updateHolo >= 20 * MainSettings.getInstance().getSettingsData().getHologramsUpdateinterval()) {
  67.             if (MainSettings.getInstance().getSettingsData().isTurnOffhologramsOnOff())
  68.                 for (Location location : registry.getContainerlocations()) {
  69.  
  70.                     if (!location.getWorld().isChunkLoaded(location.getBlockX() >> 4, location.getBlockZ() >> 4))
  71.                         continue;
  72.                     /*if (!location.getWorld().isChunkForceLoaded(location.getBlockX() >> 4, location.getBlockZ() >> 4))
  73.                         continue;*/
  74.  
  75.                     HologramsTask.hologramsrun(location, registry);
  76.  
  77.                 }
  78.             updateHolo = 0;
  79.         }
  80.         if (!(DatabaseSettings.getInstance().getSavingTime() == 0) && saveData >= 20 * 60 * DatabaseSettings.getInstance().getSavingTime()) {
  81.             if (id != null && (Bukkit.getScheduler().isCurrentlyRunning(id.getTaskId()) || Bukkit.getScheduler().isQueued(id.getTaskId())))
  82.                 Bukkit.getScheduler().cancelTask(id.getTaskId());
  83.             id = Bukkit.getScheduler().runTaskAsynchronously(CustomContainersMainClass.getInstance(), SaveFromCacheToDB::SaveDataFromCache);
  84.  
  85.             System.out.println("Save to SQlittle" + id.getTaskId());
  86.             saveData = 0;
  87.         }
  88.         if (effectsOnChest >= 20 * 7) {
  89.             Set<Location> locations = new LinkedHashSet<>(registry.getContainerlocations());
  90.             if (mainSettings.getSettingsData().isTurnOffEffectsOnContainers())
  91.                 if (!plugin.getHeavyTasks().isContainsMaxAmountInQueue("effectsOnChest", 2)) {
  92.                     SpawnContainerEffects task = new SpawnContainerEffects(new LinkedHashSet<>(), locations, new ArrayList<>(), null);
  93.                     Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> plugin.getHeavyTasks().addLoad(task));
  94.                     plugin.getHeavyTasks().setMaxAmountEachEntityCanQueue("effectsOnChest", System.currentTimeMillis() + 250, task);
  95.                 }
  96.  
  97.             effectsOnChest = 0;
  98.         }
  99.         number++;
  100.         saveData++;
  101.         updateHolo++;
  102.         updatestorageunit++;
  103.         effectsOnChest++;
  104.     }
  105. }
Add Comment
Please, Sign In to add comment