extensions trigger for resource reload. Apps will reload upon reload

This commit is contained in:
gnembon committed 2020-06-05 23:23:47 -03:00
1 parent a8a22e1403
commit c5841408a6
5 files changed
+48 -4

No files matched your search

@@ -50,6 +50,8 @@ public interface CarpetExtension
default void onServerClosed(MinecraftServer server) {}
default void onReload(MinecraftServer server) {}
default String version() {return null;}
default void registerLoggers() {}
+6
View File
@@ -146,5 +146,11 @@ public class CarpetServer // static for now - easier to handle all around the co
TickSpeed.reset();
settingsManager.detachServer();
}
public static void onReload(MinecraftServer server)
{
scriptServer.reload(server);
extensions.forEach(e -> e.onReload(server));
}
}
@@ -2,9 +2,12 @@ package carpet.mixins;
import carpet.CarpetServer;
import net.minecraft.network.ClientConnection;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.PlayerManager;
import net.minecraft.server.network.ServerPlayerEntity;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@@ -14,10 +17,18 @@ import static carpet.script.CarpetEventServer.Event.PLAYER_CONNECTS;
@Mixin(PlayerManager.class)
public class PlayerManager_coreMixin
{
@Shadow @Final private MinecraftServer server;
@Inject(method = "onPlayerConnect", at = @At("RETURN"))
private void onPlayerConnected(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci)
{
CarpetServer.onPlayerLoggedIn(player);
PLAYER_CONNECTS.onPlayerEvent(player);
}
@Inject(method = "onDataPacksReloaded", at = @At("HEAD"))
private void onResourcesRefreshedReloadCommand(CallbackInfo ci)
{
CarpetServer.onReload(server);
}
}
@@ -187,6 +187,10 @@ public class CarpetEventServer
{
callList.removeIf((c)-> c.host != null && c.host.equals(hostName));
}
public void clearEverything()
{
callList.clear();
}
}
public enum Event
@@ -736,6 +740,11 @@ public class CarpetEventServer
Event.byName.values().forEach((e) -> e.handler.removeAllCalls(hostName));
}
public void clearAll()
{
Event.byName.values().forEach(e -> e.handler.clearEverything());
}
private Pair<String,String> decodeCallback(String funName)
{
Pattern find = Pattern.compile("(\\w+)\\(from (\\w+)\\)");
@@ -15,6 +15,7 @@ import carpet.utils.Messenger;
import com.mojang.brigadier.arguments.StringArgumentType;
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
import com.mojang.brigadier.tree.CommandNode;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.util.WorldSavePath;
import net.minecraft.util.math.BlockPos;
@@ -35,12 +36,12 @@ import static net.minecraft.server.command.CommandManager.literal;
public class CarpetScriptServer
{
//make static for now, but will change that later:
public final CarpetScriptHost globalHost;
public final Map<String, CarpetScriptHost> modules;
public CarpetScriptHost globalHost;
public Map<String, CarpetScriptHost> modules;
public long tickStart;
public boolean stopAll;
private final Set<String> holyMoly;
public final CarpetEventServer events;
private Set<String> holyMoly;
public CarpetEventServer events;
private static final List<Module> bundledModuleData = new ArrayList<Module>(){{
add(new BundledModule("camera", false));
@@ -51,6 +52,11 @@ public class CarpetScriptServer
}};
public CarpetScriptServer()
{
init();
}
private void init()
{
ScriptHost.systemGlobals.clear();
events = new CarpetEventServer();
@@ -281,4 +287,14 @@ public class CarpetScriptServer
}
ThreadValue.shutdown();
}
public void reload(MinecraftServer server)
{
Map<String, Boolean> apps = new HashMap<>();
modules.forEach((s, h) -> apps.put(s, h.perUser));
apps.keySet().forEach(s -> removeScriptHost(server.getCommandSource(), s));
events.clearAll();
init();
apps.forEach((s, pp) -> addScriptHost(server.getCommandSource(), s, pp, false));
}
}