2025-11-24 22:52:51 +03:00

79 lines
2.8 KiB
Java

/*
* Decompiled with CFR 0.152.
*
* Could not load the following classes:
* com.google.common.collect.Maps
* com.mojang.logging.LogUtils
* com.mojang.serialization.Codec
* org.jspecify.annotations.Nullable
* org.slf4j.Logger
*/
package net.minecraft.server.bossevents;
import com.google.common.collect.Maps;
import com.mojang.logging.LogUtils;
import com.mojang.serialization.Codec;
import java.util.Collection;
import java.util.Map;
import net.minecraft.core.HolderLookup;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.NbtOps;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.Identifier;
import net.minecraft.server.bossevents.CustomBossEvent;
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Util;
import org.jspecify.annotations.Nullable;
import org.slf4j.Logger;
public class CustomBossEvents {
private static final Logger LOGGER = LogUtils.getLogger();
private static final Codec<Map<Identifier, CustomBossEvent.Packed>> EVENTS_CODEC = Codec.unboundedMap(Identifier.CODEC, CustomBossEvent.Packed.CODEC);
private final Map<Identifier, CustomBossEvent> events = Maps.newHashMap();
public @Nullable CustomBossEvent get(Identifier id) {
return this.events.get(id);
}
public CustomBossEvent create(Identifier id, Component name) {
CustomBossEvent result = new CustomBossEvent(id, name);
this.events.put(id, result);
return result;
}
public void remove(CustomBossEvent event) {
this.events.remove(event.getTextId());
}
public Collection<Identifier> getIds() {
return this.events.keySet();
}
public Collection<CustomBossEvent> getEvents() {
return this.events.values();
}
public CompoundTag save(HolderLookup.Provider registries) {
Map<Identifier, CustomBossEvent.Packed> packedEvents = Util.mapValues(this.events, CustomBossEvent::pack);
return (CompoundTag)EVENTS_CODEC.encodeStart(registries.createSerializationContext(NbtOps.INSTANCE), packedEvents).getOrThrow();
}
public void load(CompoundTag tag, HolderLookup.Provider registries) {
Map<Identifier, CustomBossEvent.Packed> events = EVENTS_CODEC.parse(registries.createSerializationContext(NbtOps.INSTANCE), (Object)tag).resultOrPartial(error -> LOGGER.error("Failed to parse boss bar events: {}", error)).orElse(Map.of());
events.forEach((id, packed) -> this.events.put((Identifier)id, CustomBossEvent.load(id, packed)));
}
public void onPlayerConnect(ServerPlayer player) {
for (CustomBossEvent event : this.events.values()) {
event.onPlayerConnect(player);
}
}
public void onPlayerDisconnect(ServerPlayer player) {
for (CustomBossEvent event : this.events.values()) {
event.onPlayerDisconnect(player);
}
}
}