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;

public class CustomBossEvents {
    private final Map<ResourceLocation, CustomBossEvent> events;
    
    public CustomBossEvents() {
        this.events = Maps.newHashMap();
    }
    
    @Nullable
    public CustomBossEvent get(final ResourceLocation uh) {
        return this.events.get(uh);
    }
    
    public CustomBossEvent create(final ResourceLocation uh, final Component mr) {
        final CustomBossEvent uz4 = new CustomBossEvent(uh, mr);
        this.events.put(uh, uz4);
        return uz4;
    }
    
    public void remove(final CustomBossEvent uz) {
        this.events.remove(uz.getTextId());
    }
    
    public Collection<ResourceLocation> getIds() {
        return this.events.keySet();
    }
    
    public Collection<CustomBossEvent> getEvents() {
        return this.events.values();
    }
    
    public CompoundTag save() {
        final CompoundTag le2 = new CompoundTag();
        for (final CustomBossEvent uz4 : this.events.values()) {
            le2.put(uz4.getTextId().toString(), uz4.save());
        }
        return le2;
    }
    
    public void load(final CompoundTag le) {
        for (final String string4 : le.getAllKeys()) {
            final ResourceLocation uh5 = new ResourceLocation(string4);
            this.events.put(uh5, CustomBossEvent.load(le.getCompound(string4), uh5));
        }
    }
    
    public void onPlayerConnect(final ServerPlayer ze) {
        for (final CustomBossEvent uz4 : this.events.values()) {
            uz4.onPlayerConnect(ze);
        }
    }
    
    public void onPlayerDisconnect(final ServerPlayer ze) {
        for (final CustomBossEvent uz4 : this.events.values()) {
            uz4.onPlayerDisconnect(ze);
        }
    }
}
