Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TickTask extends BukkitRunnable {
- BukkitTask task;
- BukkitTask id;
- private int number = 0;
- private int saveData = 0;
- private int updateHolo = 0;
- private int updatestorageunit = 0;
- private int effectsOnChest = 0;
- private boolean turnOF = false;
- PreferenceSettingsRegistery preferenceRegistery = PreferenceSettingsRegistery.getInstance();
- private final MainSettings mainSettings = MainSettings.getInstance();
- private final CustomContainersMainClass plugin = CustomContainersMainClass.getInstance();
- public void start() {
- if (task != null && (Bukkit.getScheduler().isCurrentlyRunning(task.getTaskId()) || Bukkit.getScheduler().isQueued(task.getTaskId())))
- Bukkit.getScheduler().cancelTask(task.getTaskId());
- task = runTaskTimer(CustomContainersMainClass.getInstance(), 0L, 1L);
- }
- public void stop() {
- task.cancel();
- }
- @Override
- public void run() {
- //LagCatcher.start("STORAGEUNIT");
- ContainerRegistryAPI registry = ContainerRegistryAPI.getInstance();
- if (number >= 8) {
- List<Location> loc = new ArrayList<>(registry.getContainerlocations());
- for (ListIterator<Location> locations = loc.listIterator(); loc.listIterator().hasNext(); ) {
- if (!locations.hasNext())
- break;
- Location location = locations.next();
- //for (Location location : registry.getContainerlocations()) {
- //todo fix so you can change update time the chest
- plugin.getCraftingSellTask().craftingSelltask(location, registry);
- HopperMoveTask.getInstance().moveItemsToHopperTask(location, registry);
- number = 0;
- }
- }
- if (updatestorageunit >= 0) {
- List<Location> loc = new ArrayList<>(registry.getContainerlocations());
- for (ListIterator<Location> locations = loc.listIterator(); loc.listIterator().hasNext(); ) {
- if (!locations.hasNext())
- break;
- Location location = locations.next();
- //for (Location location : registry.getContainerlocations()) {
- if (Objects.equals(registry.getTypeofContainer(location), ContainerRegistry.TypeOfContainer.STORAGEUNIT)) {
- AddItemsToStorageUnit.getInstance().getItemsFromStorageUnit(location, registry);
- }
- }
- updatestorageunit = 0;
- }
- plugin.getTeleportLinkItemsTask().task();
- if (updateHolo >= 20 * MainSettings.getInstance().getSettingsData().getHologramsUpdateinterval()) {
- if (MainSettings.getInstance().getSettingsData().isTurnOffhologramsOnOff())
- for (Location location : registry.getContainerlocations()) {
- if (!location.getWorld().isChunkLoaded(location.getBlockX() >> 4, location.getBlockZ() >> 4))
- continue;
- /*if (!location.getWorld().isChunkForceLoaded(location.getBlockX() >> 4, location.getBlockZ() >> 4))
- continue;*/
- HologramsTask.hologramsrun(location, registry);
- }
- updateHolo = 0;
- }
- if (!(DatabaseSettings.getInstance().getSavingTime() == 0) && saveData >= 20 * 60 * DatabaseSettings.getInstance().getSavingTime()) {
- if (id != null && (Bukkit.getScheduler().isCurrentlyRunning(id.getTaskId()) || Bukkit.getScheduler().isQueued(id.getTaskId())))
- Bukkit.getScheduler().cancelTask(id.getTaskId());
- id = Bukkit.getScheduler().runTaskAsynchronously(CustomContainersMainClass.getInstance(), SaveFromCacheToDB::SaveDataFromCache);
- System.out.println("Save to SQlittle" + id.getTaskId());
- saveData = 0;
- }
- if (effectsOnChest >= 20 * 7) {
- Set<Location> locations = new LinkedHashSet<>(registry.getContainerlocations());
- if (mainSettings.getSettingsData().isTurnOffEffectsOnContainers())
- if (!plugin.getHeavyTasks().isContainsMaxAmountInQueue("effectsOnChest", 2)) {
- SpawnContainerEffects task = new SpawnContainerEffects(new LinkedHashSet<>(), locations, new ArrayList<>(), null);
- Bukkit.getScheduler().runTaskAsynchronously(plugin, () -> plugin.getHeavyTasks().addLoad(task));
- plugin.getHeavyTasks().setMaxAmountEachEntityCanQueue("effectsOnChest", System.currentTimeMillis() + 250, task);
- }
- effectsOnChest = 0;
- }
- number++;
- saveData++;
- updateHolo++;
- updatestorageunit++;
- effectsOnChest++;
- }
- }
Add Comment
Please, Sign In to add comment