added startup and shutdown events. fixes #586
This commit is contained in:
1 parent
e8a6b8936f
commit
522d971688
4 files changed
+35
-3
No files matched your search
@@ -309,6 +309,30 @@ public class CarpetEventServer
|
||||
return events;
|
||||
}
|
||||
|
||||
public static final Event START = new Event("server_starts", 0, true)
|
||||
{
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
handler.call(Collections::emptyList, () ->
|
||||
CarpetServer.minecraft_server.getCommandSource().
|
||||
withWorld(CarpetServer.minecraft_server.getWorld(World.OVERWORLD))
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
public static final Event SHUTDOWN = new Event("server_shuts_down", 0, true)
|
||||
{
|
||||
@Override
|
||||
public void onTick()
|
||||
{
|
||||
handler.call(Collections::emptyList, () ->
|
||||
CarpetServer.minecraft_server.getCommandSource().
|
||||
withWorld(CarpetServer.minecraft_server.getWorld(World.OVERWORLD))
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
public static final Event TICK = new Event("tick", 0, true)
|
||||
{
|
||||
@Override
|
||||
|
||||
@@ -127,7 +127,7 @@ public class CarpetScriptServer
|
||||
addScriptHost(server.getCommandSource(), moduleName, null, true, true, false);
|
||||
}
|
||||
}
|
||||
|
||||
CarpetEventServer.Event.START.onTick();
|
||||
}
|
||||
|
||||
public Module getModule(String name, boolean allowLibraries)
|
||||
@@ -489,6 +489,7 @@ public class CarpetScriptServer
|
||||
|
||||
public void onClose()
|
||||
{
|
||||
CarpetEventServer.Event.SHUTDOWN.onTick();
|
||||
for (ScriptHost host : modules.values())
|
||||
{
|
||||
host.onClose();
|
||||
|
||||
Reference in new issue
Block a user