extensions trigger for resource reload. Apps will reload upon reload
This commit is contained in:
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 onServerClosed(MinecraftServer server) {}
|
||||||
|
|
||||||
|
default void onReload(MinecraftServer server) {}
|
||||||
|
|
||||||
default String version() {return null;}
|
default String version() {return null;}
|
||||||
|
|
||||||
default void registerLoggers() {}
|
default void registerLoggers() {}
|
||||||
|
|||||||
@@ -146,5 +146,11 @@ public class CarpetServer // static for now - easier to handle all around the co
|
|||||||
TickSpeed.reset();
|
TickSpeed.reset();
|
||||||
settingsManager.detachServer();
|
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 carpet.CarpetServer;
|
||||||
import net.minecraft.network.ClientConnection;
|
import net.minecraft.network.ClientConnection;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.PlayerManager;
|
import net.minecraft.server.PlayerManager;
|
||||||
import net.minecraft.server.network.ServerPlayerEntity;
|
import net.minecraft.server.network.ServerPlayerEntity;
|
||||||
|
import org.spongepowered.asm.mixin.Final;
|
||||||
import org.spongepowered.asm.mixin.Mixin;
|
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.At;
|
||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
@@ -14,10 +17,18 @@ import static carpet.script.CarpetEventServer.Event.PLAYER_CONNECTS;
|
|||||||
@Mixin(PlayerManager.class)
|
@Mixin(PlayerManager.class)
|
||||||
public class PlayerManager_coreMixin
|
public class PlayerManager_coreMixin
|
||||||
{
|
{
|
||||||
|
@Shadow @Final private MinecraftServer server;
|
||||||
|
|
||||||
@Inject(method = "onPlayerConnect", at = @At("RETURN"))
|
@Inject(method = "onPlayerConnect", at = @At("RETURN"))
|
||||||
private void onPlayerConnected(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci)
|
private void onPlayerConnected(ClientConnection connection, ServerPlayerEntity player, CallbackInfo ci)
|
||||||
{
|
{
|
||||||
CarpetServer.onPlayerLoggedIn(player);
|
CarpetServer.onPlayerLoggedIn(player);
|
||||||
PLAYER_CONNECTS.onPlayerEvent(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));
|
callList.removeIf((c)-> c.host != null && c.host.equals(hostName));
|
||||||
}
|
}
|
||||||
|
public void clearEverything()
|
||||||
|
{
|
||||||
|
callList.clear();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum Event
|
public enum Event
|
||||||
@@ -736,6 +740,11 @@ public class CarpetEventServer
|
|||||||
Event.byName.values().forEach((e) -> e.handler.removeAllCalls(hostName));
|
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)
|
private Pair<String,String> decodeCallback(String funName)
|
||||||
{
|
{
|
||||||
Pattern find = Pattern.compile("(\\w+)\\(from (\\w+)\\)");
|
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.arguments.StringArgumentType;
|
||||||
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
import com.mojang.brigadier.builder.LiteralArgumentBuilder;
|
||||||
import com.mojang.brigadier.tree.CommandNode;
|
import com.mojang.brigadier.tree.CommandNode;
|
||||||
|
import net.minecraft.server.MinecraftServer;
|
||||||
import net.minecraft.server.command.ServerCommandSource;
|
import net.minecraft.server.command.ServerCommandSource;
|
||||||
import net.minecraft.util.WorldSavePath;
|
import net.minecraft.util.WorldSavePath;
|
||||||
import net.minecraft.util.math.BlockPos;
|
import net.minecraft.util.math.BlockPos;
|
||||||
@@ -35,12 +36,12 @@ import static net.minecraft.server.command.CommandManager.literal;
|
|||||||
public class CarpetScriptServer
|
public class CarpetScriptServer
|
||||||
{
|
{
|
||||||
//make static for now, but will change that later:
|
//make static for now, but will change that later:
|
||||||
public final CarpetScriptHost globalHost;
|
public CarpetScriptHost globalHost;
|
||||||
public final Map<String, CarpetScriptHost> modules;
|
public Map<String, CarpetScriptHost> modules;
|
||||||
public long tickStart;
|
public long tickStart;
|
||||||
public boolean stopAll;
|
public boolean stopAll;
|
||||||
private final Set<String> holyMoly;
|
private Set<String> holyMoly;
|
||||||
public final CarpetEventServer events;
|
public CarpetEventServer events;
|
||||||
|
|
||||||
private static final List<Module> bundledModuleData = new ArrayList<Module>(){{
|
private static final List<Module> bundledModuleData = new ArrayList<Module>(){{
|
||||||
add(new BundledModule("camera", false));
|
add(new BundledModule("camera", false));
|
||||||
@@ -51,6 +52,11 @@ public class CarpetScriptServer
|
|||||||
}};
|
}};
|
||||||
|
|
||||||
public CarpetScriptServer()
|
public CarpetScriptServer()
|
||||||
|
{
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init()
|
||||||
{
|
{
|
||||||
ScriptHost.systemGlobals.clear();
|
ScriptHost.systemGlobals.clear();
|
||||||
events = new CarpetEventServer();
|
events = new CarpetEventServer();
|
||||||
@@ -281,4 +287,14 @@ public class CarpetScriptServer
|
|||||||
}
|
}
|
||||||
ThreadValue.shutdown();
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user