package net.minecraft.world.level.timers;

import net.minecraft.nbt.CompoundTag;
import net.minecraft.commands.CommandFunction;
import net.minecraft.server.ServerFunctionManager;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;

public class FunctionCallback implements TimerCallback<MinecraftServer> {
    private final ResourceLocation functionId;
    
    public FunctionCallback(final ResourceLocation sm) {
        this.functionId = sm;
    }
    
    @Override
    public void handle(final MinecraftServer minecraftServer, final TimerQueue<MinecraftServer> cvc, final long long3) {
        final ServerFunctionManager sy6 = minecraftServer.getFunctions();
        final ServerFunctionManager serverFunctionManager;
        sy6.get(this.functionId).ifPresent(cn -> serverFunctionManager.execute(cn, serverFunctionManager.getGameLoopSender()));
    }
    
    public static class Serializer extends TimerCallback.Serializer<MinecraftServer, FunctionCallback> {
        public Serializer() {
            super(new ResourceLocation("function"), FunctionCallback.class);
        }
        
        @Override
        public void serialize(final CompoundTag jt, final FunctionCallback cuy) {
            jt.putString("Name", cuy.functionId.toString());
        }
        
        @Override
        public FunctionCallback deserialize(final CompoundTag jt) {
            final ResourceLocation sm3 = new ResourceLocation(jt.getString("Name"));
            return new FunctionCallback(sm3);
        }
    }
}
