File size: 2,285 Bytes
d46f4a3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package net.minecraft.server.bossevents;

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

public class CustomBossEvents {
    private final Map<ResourceLocation, CustomBossEvent> events = Maps.newHashMap();

    @Nullable
    public CustomBossEvent get(ResourceLocation p_136298_) {
        return this.events.get(p_136298_);
    }

    public CustomBossEvent create(ResourceLocation p_136300_, Component p_136301_) {
        CustomBossEvent custombossevent = new CustomBossEvent(p_136300_, p_136301_);
        this.events.put(p_136300_, custombossevent);
        return custombossevent;
    }

    public void remove(CustomBossEvent p_136303_) {
        this.events.remove(p_136303_.getTextId());
    }

    public Collection<ResourceLocation> getIds() {
        return this.events.keySet();
    }

    public Collection<CustomBossEvent> getEvents() {
        return this.events.values();
    }

    public CompoundTag save(HolderLookup.Provider p_328754_) {
        CompoundTag compoundtag = new CompoundTag();

        for (CustomBossEvent custombossevent : this.events.values()) {
            compoundtag.put(custombossevent.getTextId().toString(), custombossevent.save(p_328754_));
        }

        return compoundtag;
    }

    public void load(CompoundTag p_136296_, HolderLookup.Provider p_329843_) {
        for (String s : p_136296_.getAllKeys()) {
            ResourceLocation resourcelocation = ResourceLocation.parse(s);
            this.events.put(resourcelocation, CustomBossEvent.load(p_136296_.getCompound(s), resourcelocation, p_329843_));
        }
    }

    public void onPlayerConnect(ServerPlayer p_136294_) {
        for (CustomBossEvent custombossevent : this.events.values()) {
            custombossevent.onPlayerConnect(p_136294_);
        }
    }

    public void onPlayerDisconnect(ServerPlayer p_136306_) {
        for (CustomBossEvent custombossevent : this.events.values()) {
            custombossevent.onPlayerDisconnect(p_136306_);
        }
    }
}