mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-18 18:23:06 +00:00
67 lines
1.1 KiB
Java
67 lines
1.1 KiB
Java
package com.volmit.iris;
|
|
|
|
import java.io.File;
|
|
|
|
import org.bukkit.Bukkit;
|
|
|
|
import com.volmit.iris.util.ChronoLatch;
|
|
import com.volmit.iris.util.FileWatcher;
|
|
import com.volmit.iris.util.KSet;
|
|
|
|
public class IrisHotloadManager
|
|
{
|
|
private ChronoLatch latch;
|
|
private KSet<FileWatcher> watchers;
|
|
|
|
public IrisHotloadManager()
|
|
{
|
|
watchers = new KSet<>();
|
|
latch = new ChronoLatch(3000);
|
|
}
|
|
|
|
public void check(IrisContext ch)
|
|
{
|
|
if(!latch.flip())
|
|
{
|
|
return;
|
|
}
|
|
|
|
Bukkit.getScheduler().scheduleSyncDelayedTask(Iris.instance, () ->
|
|
{
|
|
boolean modified = false;
|
|
int c = 0;
|
|
|
|
try
|
|
{
|
|
for(FileWatcher i : watchers)
|
|
{
|
|
if(i.checkModified())
|
|
{
|
|
c++;
|
|
Iris.info("File Modified: " + i.getFile().getPath());
|
|
modified = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
catch(Throwable e)
|
|
{
|
|
|
|
}
|
|
|
|
if(modified)
|
|
{
|
|
watchers.clear();
|
|
Iris.success("Hotloading Iris (" + c + " File" + (c == 1 ? "" : "s") + " changed)");
|
|
Iris.globaldata.hotloaded();
|
|
ch.onHotloaded();
|
|
}
|
|
});
|
|
}
|
|
|
|
public void track(File file)
|
|
{
|
|
watchers.add(new FileWatcher(file));
|
|
}
|
|
}
|