package net.minecraft.server.bossevents;

import net.minecraft.server.level.ServerPlayer;
import java.util.Iterator;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.CompoundTag;
import java.util.Collection;
import net.minecraft.network.chat.Component;
import javax.annotation.Nullable;
import com.google.common.collect.Maps;
import net.minecraft.resources.ResourceLocation;
import java.util.Map;
import net.minecraft.server.MinecraftServer;

public class CustomBossEvents {
    private final MinecraftServer server;
    private final Map<ResourceLocation, CustomBossEvent> events;
    
    public CustomBossEvents(final MinecraftServer minecraftServer) {
        this.events = Maps.newHashMap();
        this.server = minecraftServer;
    }
    
    @Nullable
    public CustomBossEvent get(final ResourceLocation sm) {
        return this.events.get(sm);
    }
    
    public CustomBossEvent create(final ResourceLocation sm, final Component lf) {
        final CustomBossEvent tc4 = new CustomBossEvent(sm, lf);
        this.events.put(sm, tc4);
        return tc4;
    }
    
    public void remove(final CustomBossEvent tc) {
        this.events.remove(tc.getTextId());
    }
    
    public Collection<ResourceLocation> getIds() {
        return this.events.keySet();
    }
    
    public Collection<CustomBossEvent> getEvents() {
        return this.events.values();
    }
    
    public CompoundTag save() {
        final CompoundTag jt2 = new CompoundTag();
        for (final CustomBossEvent tc4 : this.events.values()) {
            jt2.put(tc4.getTextId().toString(), tc4.save());
        }
        return jt2;
    }
    
    public void load(final CompoundTag jt) {
        for (final String string4 : jt.getAllKeys()) {
            final ResourceLocation sm5 = new ResourceLocation(string4);
            this.events.put(sm5, CustomBossEvent.load(jt.getCompound(string4), sm5));
        }
    }
    
    public void onPlayerConnect(final ServerPlayer xe) {
        for (final CustomBossEvent tc4 : this.events.values()) {
            tc4.onPlayerConnect(xe);
        }
    }
    
    public void onPlayerDisconnect(final ServerPlayer xe) {
        for (final CustomBossEvent tc4 : this.events.values()) {
            tc4.onPlayerDisconnect(xe);
        }
    }
}
