mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2025-07-19 02:36:59 +00:00
Config hotloading
This commit is contained in:
parent
6d08faa30f
commit
802bc50102
@ -1,6 +1,5 @@
|
|||||||
package com.volmit.iris;
|
package com.volmit.iris;
|
||||||
|
|
||||||
import com.volmit.iris.nms.INMS;
|
|
||||||
import com.volmit.iris.manager.*;
|
import com.volmit.iris.manager.*;
|
||||||
import com.volmit.iris.manager.command.CommandIris;
|
import com.volmit.iris.manager.command.CommandIris;
|
||||||
import com.volmit.iris.manager.command.PermissionIris;
|
import com.volmit.iris.manager.command.PermissionIris;
|
||||||
@ -8,6 +7,7 @@ import com.volmit.iris.manager.link.BKLink;
|
|||||||
import com.volmit.iris.manager.link.CitizensLink;
|
import com.volmit.iris.manager.link.CitizensLink;
|
||||||
import com.volmit.iris.manager.link.MultiverseCoreLink;
|
import com.volmit.iris.manager.link.MultiverseCoreLink;
|
||||||
import com.volmit.iris.manager.link.MythicMobsLink;
|
import com.volmit.iris.manager.link.MythicMobsLink;
|
||||||
|
import com.volmit.iris.nms.INMS;
|
||||||
import com.volmit.iris.object.IrisCompat;
|
import com.volmit.iris.object.IrisCompat;
|
||||||
import com.volmit.iris.scaffold.IrisWorldCreator;
|
import com.volmit.iris.scaffold.IrisWorldCreator;
|
||||||
import com.volmit.iris.scaffold.IrisWorlds;
|
import com.volmit.iris.scaffold.IrisWorlds;
|
||||||
@ -47,6 +47,7 @@ public class Iris extends VolmitPlugin
|
|||||||
public static boolean biome3d = doesSupport3DBiomes();
|
public static boolean biome3d = doesSupport3DBiomes();
|
||||||
public static boolean lowMemoryMode = false;
|
public static boolean lowMemoryMode = false;
|
||||||
public static IrisCompat compat;
|
public static IrisCompat compat;
|
||||||
|
public static FileWatcher configWatcher;
|
||||||
|
|
||||||
@Permission
|
@Permission
|
||||||
public static PermissionIris perm;
|
public static PermissionIris perm;
|
||||||
@ -158,14 +159,26 @@ public class Iris extends VolmitPlugin
|
|||||||
linkBK = new BKLink();
|
linkBK = new BKLink();
|
||||||
linkMythicMobs = new MythicMobsLink();
|
linkMythicMobs = new MythicMobsLink();
|
||||||
edit = new EditManager();
|
edit = new EditManager();
|
||||||
|
configWatcher = new FileWatcher(getDataFile("settings.json"));
|
||||||
J.a(() -> IO.delete(getTemp()));
|
J.a(() -> IO.delete(getTemp()));
|
||||||
J.a(this::bstats);
|
J.a(this::bstats);
|
||||||
J.s(this::splash, 20);
|
J.s(this::splash, 20);
|
||||||
J.sr(this::tickQueue, 0);
|
J.sr(this::tickQueue, 0);
|
||||||
|
J.ar(this::checkConfigHotload, 50);
|
||||||
PaperLib.suggestPaper(this);
|
PaperLib.suggestPaper(this);
|
||||||
super.onEnable();
|
super.onEnable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkConfigHotload() {
|
||||||
|
if(configWatcher.checkModified())
|
||||||
|
{
|
||||||
|
IrisSettings.invalidate();
|
||||||
|
IrisSettings.get();
|
||||||
|
configWatcher.checkModified();
|
||||||
|
Iris.info("Hotloaded settings.json");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void onDisable()
|
public void onDisable()
|
||||||
{
|
{
|
||||||
if(IrisSettings.get().isStudio())
|
if(IrisSettings.get().isStudio())
|
||||||
|
@ -109,49 +109,73 @@ public class IrisSettings
|
|||||||
|
|
||||||
J.a(() ->
|
J.a(() ->
|
||||||
{
|
{
|
||||||
JSONObject j = new JSONObject(ss);
|
try
|
||||||
boolean u = false;
|
|
||||||
for(String i : def.keySet())
|
|
||||||
{
|
{
|
||||||
if(!j.has(i))
|
JSONObject j = new JSONObject(ss);
|
||||||
|
boolean u = false;
|
||||||
|
for(String i : def.keySet())
|
||||||
{
|
{
|
||||||
u = true;
|
if(!j.has(i))
|
||||||
j.put(i, def.get(i));
|
{
|
||||||
Iris.warn("Adding new config key: " + i);
|
u = true;
|
||||||
|
j.put(i, def.get(i));
|
||||||
|
Iris.warn("Adding new config key: " + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for(String i : new KSet<>(j.keySet()))
|
||||||
|
{
|
||||||
|
if(!def.has(i))
|
||||||
|
{
|
||||||
|
u = true;
|
||||||
|
j.remove(i);
|
||||||
|
Iris.warn("Removing unused config key: " + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(u)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
IO.writeAll(s, j.toString(4));
|
||||||
|
Iris.info("Updated Configuration Files");
|
||||||
|
}
|
||||||
|
|
||||||
|
catch(Throwable e)
|
||||||
|
{
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(String i : j.keySet())
|
catch(Throwable ee)
|
||||||
{
|
{
|
||||||
if(!def.has(i))
|
Iris.error("Configuration Error in settings.json! " + ee.getClass().getSimpleName() + ": " + ee.getMessage());
|
||||||
{
|
Iris.warn("Attempting to fix configuration while retaining valid in-memory settings...");
|
||||||
u = true;
|
|
||||||
j.remove(i);
|
|
||||||
Iris.warn("Removing unused config key: " + i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(u)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
IO.writeAll(s, j.toString(4));
|
|
||||||
Iris.info("Updated Configuration Files");
|
|
||||||
}
|
|
||||||
|
|
||||||
catch(Throwable ignored)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4));
|
||||||
|
Iris.info("Configuration Fixed!");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Iris.error("ERROR! CONFIGURATION IMPOSSIBLE TO READ! Using an unmodifiable configuration from memory. Please delete the settings.json at some point to try to restore configurability!");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
catch(JSONException | IOException e)
|
catch(Throwable ee)
|
||||||
{
|
{
|
||||||
e.printStackTrace();
|
Iris.error("Configuration Error in settings.json! " + ee.getClass().getSimpleName() + ": " + ee.getMessage());
|
||||||
// noinspection ResultOfMethodCallIgnored
|
Iris.warn("Attempting to fix configuration while retaining valid in-memory settings...");
|
||||||
s.delete();
|
|
||||||
|
try {
|
||||||
|
IO.writeAll(s, new JSONObject(new Gson().toJson(settings)).toString(4));
|
||||||
|
Iris.info("Configuration Fixed!");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
Iris.error("ERROR! CONFIGURATION IMPOSSIBLE TO READ! Using an unmodifiable configuration from memory. Please delete the settings.json at some point to try to restore configurability!");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user