package ru.beykerykt.lightsource.items.flags.basic;

import ru.beykerykt.lightapi.LightAPI;
import ru.beykerykt.lightapi.chunks.ChunkInfo;
import ru.beykerykt.lightsource.items.flags.TickableFlagExecutor;
import ru.beykerykt.lightsource.sources.Source;

public class UpdateExecutor implements TickableFlagExecutor {

	@Override
	public void onTick(Source source, String[] args) {
		if (args.length > 0) {
			boolean flag = Boolean.parseBoolean(args[0]);
			LightAPI.deleteLight(source.getOldLocation().getWorld(), source.getOldLocation().getBlockX(), source.getOldLocation().getBlockY(), source.getOldLocation().getBlockZ(), flag);
			LightAPI.createLight(source.getLocation().getWorld(), source.getLocation().getBlockX(), source.getLocation().getBlockY(), source.getLocation().getBlockZ(), source.getItem().getLevelLight(), flag);
			for (ChunkInfo info : LightAPI.collectChunks(source.getLocation().getWorld(), source.getLocation().getBlockX(), source.getLocation().getBlockY(), source.getLocation().getBlockZ())) {
				LightAPI.updateChunk(info);
			}
		} else {
			LightAPI.deleteLight(source.getOldLocation().getWorld(), source.getOldLocation().getBlockX(), source.getOldLocation().getBlockY(), source.getOldLocation().getBlockZ(), false);
			LightAPI.createLight(source.getLocation().getWorld(), source.getLocation().getBlockX(), source.getLocation().getBlockY(), source.getLocation().getBlockZ(), source.getItem().getLevelLight(), false);
			for (ChunkInfo info : LightAPI.collectChunks(source.getLocation().getWorld(), source.getLocation().getBlockX(), source.getLocation().getBlockY(), source.getLocation().getBlockZ())) {
				LightAPI.updateChunk(info);
			}
		}
	}
}

@@ -395,11 +395,12 @@
 gth 
-%3E 0
+== 1
 ) %7B%0A
@@ -1044,21 +1044,1665 @@
 (info);%0A
-
 %09%09%09%7D%0A
+%09%09%09return;%0A%09%09%7D else if (args.length %3E= 2) %7B%0A%09%09%09boolean flag = Boolean.parseBoolean(args%5B0%5D);%0A%09%09%09boolean saveMove = Boolean.parseBoolean(args%5B1%5D);%0A%09%09%09if (saveMove) %7B%0A%09%09%09%09if (source.getOldLocation().getBlockX() != source.getLocation().getBlockX() && source.getOldLocation().getBlockY() != source.getLocation().getBlockY() && source.getOldLocation().getBlockZ() != source.getLocation().getBlockZ()) %7B%0A%09%09%09%09%09LightAPI.deleteLight(source.getOldLocation().getWorld(), source.getOldLocation().getBlockX(), source.getOldLocation().getBlockY(), source.getOldLocation().getBlockZ(), flag);%0A%09%09%09%09%09LightAPI.createLight(source.getLocation().getWorld(), source.getLocation().getBlockX(), source.getLocation().getBlockY(), source.getLocation().getBlockZ(), source.getItem().getLevelLight(), flag);%0A%09%09%09%09%09for (ChunkInfo info : LightAPI.collectChunks(source.getLocation().getWorld(), source.getLocation().getBlockX(), source.getLocation().getBlockY(), source.getLocation().getBlockZ())) %7B%0A%09%09%09%09%09%09LightAPI.updateChunk(info);%0A%09%09%09%09%09%7D%0A%09%09%09%09%7D%0A%09%09%09%09return;%0A%09%09%09%7D%0A%09%09%09LightAPI.deleteLight(source.getOldLocation().getWorld(), source.getOldLocation().getBlockX(), source.getOldLocation().getBlockY(), source.getOldLocation().getBlockZ(), flag);%0A%09%09%09LightAPI.createLight(source.getLocation().getWorld(), source.getLocation().getBlockX(), source.getLocation().getBlockY(), source.getLocation().getBlockZ(), source.getItem().getLevelLight(), flag);%0A%09%09%09for (ChunkInfo info : LightAPI.collectChunks(source.getLocation().getWorld(), source.getLocation().getBlockX(), source.getLocation().getBlockY(), source.getLocation().getBlockZ())) %7B%0A%09%09%09%09LightAPI.updateChunk(info);%0A%09%09%09%7D%0A%09%09%09return;%0A
 %09%09%7D else

implement save mode for update flag