package net.minecraft.world.level.timers;

import net.minecraft.nbt.CompoundTag;
import java.util.Iterator;
import net.minecraft.tags.Tag;
import net.minecraft.server.ServerFunctionManager;
import net.minecraft.commands.CommandFunction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.MinecraftServer;

public class FunctionTagCallback implements TimerCallback<MinecraftServer> {
    private final ResourceLocation tagId;
    
    public FunctionTagCallback(final ResourceLocation sm) {
        this.tagId = sm;
    }
    
    @Override
    public void handle(final MinecraftServer minecraftServer, final TimerQueue<MinecraftServer> cvc, final long long3) {
        final ServerFunctionManager sy6 = minecraftServer.getFunctions();
        final Tag<CommandFunction> aaz7 = sy6.getTags().getTagOrEmpty(this.tagId);
        for (final CommandFunction cn9 : aaz7.getValues()) {
            sy6.execute(cn9, sy6.getGameLoopSender());
        }
    }
    
    public static class Serializer extends TimerCallback.Serializer<MinecraftServer, FunctionTagCallback> {
        public Serializer() {
            super(new ResourceLocation("function_tag"), FunctionTagCallback.class);
        }
        
        @Override
        public void serialize(final CompoundTag jt, final FunctionTagCallback cuz) {
            jt.putString("Name", cuz.tagId.toString());
        }
        
        @Override
        public FunctionTagCallback deserialize(final CompoundTag jt) {
            final ResourceLocation sm3 = new ResourceLocation(jt.getString("Name"));
            return new FunctionTagCallback(sm3);
        }
    }
}
