mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-12-24 01:29:16 +00:00
Reorganize
This commit is contained in:
58
src/main/java/com/volmit/iris/IrisHotloadManager.java
Normal file
58
src/main/java/com/volmit/iris/IrisHotloadManager.java
Normal file
@@ -0,0 +1,58 @@
|
||||
package ninja.bytecode.iris;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import ninja.bytecode.iris.util.ChronoLatch;
|
||||
import ninja.bytecode.iris.util.FileWatcher;
|
||||
import ninja.bytecode.shuriken.collections.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;
|
||||
|
||||
for(FileWatcher i : watchers)
|
||||
{
|
||||
if(i.checkModified())
|
||||
{
|
||||
c++;
|
||||
Iris.info("File Modified: " + i.getFile().getPath());
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if(modified)
|
||||
{
|
||||
watchers.clear();
|
||||
Iris.success("Hotloading Iris (" + c + " File" + (c == 1 ? "" : "s") + " changed)");
|
||||
Iris.data.hotloaded();
|
||||
ch.onHotloaded();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void track(File file)
|
||||
{
|
||||
watchers.add(new FileWatcher(file));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user