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 uh) {
        this.functionId = uh;
    }
    
    @Override
    public void handle(final MinecraftServer minecraftServer, final TimerQueue<MinecraftServer> ded, final long long3) {
        final ServerFunctionManager uu6 = minecraftServer.getFunctions();
        final ServerFunctionManager serverFunctionManager;
        uu6.get(this.functionId).ifPresent(cw -> serverFunctionManager.execute(cw, 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 le, final FunctionCallback ddz) {
            le.putString("Name", ddz.functionId.toString());
        }
        
        @Override
        public FunctionCallback deserialize(final CompoundTag le) {
            final ResourceLocation uh3 = new ResourceLocation(le.getString("Name"));
            return new FunctionCallback(uh3);
        }
    }
}
