SleepNotificationSystem class

Пакет: com.hypixel.hytale.builtin.beds.sleep.systems.player

Файл: com/hypixel/hytale/builtin/beds/sleep/systems/player/SleepNotificationSystem.java

extends: DelayedSystem<EntityStore>

Поля (29)

МодификаторыТипИмя
INSTANCE
final int SMALL_SERVER_PLAYER_COUNT
Store var1
Store var1
Ref var12
Message var13
String var14
World var2
WorldSleep var2
int var2
DisplayNameComponent var2
SleepSoundsConfig var3
List var3
Message var3
World var4
SleepNotificationSystem.NotificationState var4
int var4
PlayerRef var4
SleepSoundsConfig var5
long var5
int var5
PlayerSomnolence var5
double var6
boolean var6
WorldSomnolence var7
int var8
boolean var8
Collection var9
boolean var9

Методы (20)

МодификаторыВозвратСигнатура
NotReady NotReady()
static int countReadyToSleepint countReadyToSleep(Collection<Ref<EntityStore>> var0, ComponentAccessor<EntityStore> var1)
for for(PlayerRef var11 : var9)
for for(Ref var4 : var0)
static SleepNotificationSystem.NotificationState getNotificationStateSleepNotificationSystem.NotificationState getNotificationState(World var0)
static Message getSleeperNameMessage getSleeperName(@Nullable Ref<EntityStore> var0)
if if(var4 != SleepNotificationSystem.NotReady.INSTANCE)
if if(var4 instanceof SleepNotificationSystem.SmallServer)
if if(var2 instanceof WorldSlumber)
if if(var4 <= 4)
if if(var5 != null)
if if(var6)
if if(var3 != null)
static void maybeDoNotificationvoid maybeDoNotification(Store<EntityStore> var0, boolean var1)
abstract maybeDoNotification maybeDoNotification(var3, true)
public int playerCountpublic int playerCount()
abstract int playerCountint playerCount()
public int readyToSleeppublic int readyToSleep()
abstract int readyToSleepint readyToSleep()
abstract super super(1.0F)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.beds.sleep.systems.player;

class="kw">import com.hypixel.hytale.builtin.beds.sleep.components.PlayerSomnolence;
class="kw">import com.hypixel.hytale.builtin.beds.sleep.resources.WorldSleep;
class="kw">import com.hypixel.hytale.builtin.beds.sleep.resources.WorldSlumber;
class="kw">import com.hypixel.hytale.builtin.beds.sleep.resources.WorldSomnolence;
class="kw">import com.hypixel.hytale.builtin.beds.sleep.systems.world.CanSleepInWorld;
class="kw">import com.hypixel.hytale.builtin.beds.sleep.systems.world.StartSlumberSystem;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.component.system.DelayedSystem;
class="kw">import com.hypixel.hytale.protocol.SoundCategory;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.asset.type.gameplay.sleep.SleepSoundsConfig;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.DisplayNameComponent;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
class="kw">import com.hypixel.hytale.server.core.universe.world.SoundUtil;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import java.util.Collection;
class="kw">import java.util.List;
class="kw">import java.util.Objects;
class="kw">import javax.annotation.Nullable;
class="kw">import org.checkerframework.checker.nullness.compatqual.NonNullDecl;

class="kw">public class SleepNotificationSystem class="kw">extends DelayedSystem<EntityStore> {
   class="kw">public class="kw">static class="kw">final int SMALL_SERVER_PLAYER_COUNT = 4;
   class="kw">public class="kw">static class="kw">final double BIG_SERVER_SLEEPERS_RATIO = 0.5;
   class="kw">public class="kw">static class="kw">final String COLOR = "#5AB5B5";

   class="kw">public SleepNotificationSystem() {
      super(1.0F);
   }

   @Override
   class="kw">public void delayedTick(float var1, int var2, @NonNullDecl Store<EntityStore> var3) {
      World var4 = var3.getExternalData().getWorld();
      SleepSoundsConfig var5 = var4.getGameplayConfig().getWorldConfig().getSleepConfig().getSounds();
      if (var5.isNotificationLoopEnabled()) {
         maybeDoNotification(var3, true);
      }
   }

   class="kw">public class="kw">static void maybeDoNotification(Store<EntityStore> var0, boolean var1) {
      World var2 = var0.getExternalData().getWorld();
      SleepSoundsConfig var3 = var2.getGameplayConfig().getWorldConfig().getSleepConfig().getSounds();
      SleepNotificationSystem.NotificationState var4 = getNotificationState(var2);
      if (var4 != SleepNotificationSystem.NotReady.INSTANCE) {
         long var5 = System.currentTimeMillis();
         WorldSomnolence var7 = var0.getResource(WorldSomnolence.getResourceType());
         if (var7.useSleepNotificationCooldown(var5, var3.getNotificationLoopCooldownMs())) {
            int var8 = var1 ? var3.getNotificationLoopIndex() : var3.getNotificationIndex();
            Collection var9 = var2.getPlayerRefs();

            for (PlayerRef var11 : var9) {
               Ref var12 = var11.getReference();
               if (var12 != null && !StartSlumberSystem.canNotifyOthersAboutTryingToSleep(var0, var12)) {
                  SoundUtil.playSoundEvent2dToPlayer(var11, var8, SoundCategory.UI);
                  if (var4 class="kw">instanceof SleepNotificationSystem.SmallServer) {
                     if (var4.readyToSleep() == 1) {
                        Message var13 = var9.stream()
                           .map(PlayerRef::getReference)
                           .filter(var1x -> StartSlumberSystem.canNotifyOthersAboutTryingToSleep(var0, (Ref<EntityStore>)var1x))
                           .map(SleepNotificationSystem::getSleeperName)
                           .findFirst()
                           .orElseGet(() -> Message.raw("???"));
                        String var14 = var1 ? "server.interactions.sleep.notificationSingle" : "server.interactions.sleep.notificationSingleEnter";
                        var11.sendMessage(Message.translation(var14).color("#5AB5B5").param("player", var13));
                     } else {
                        var11.sendMessage(
                           Message.translation("server.interactions.sleep.notificationSmall").color("#5AB5B5").param("sleepers", var4.readyToSleep())
                        );
                     }
                  } else if (var4 class="kw">instanceof SleepNotificationSystem.BigServer) {
                     var11.sendMessage(
                        Message.translation("server.interactions.sleep.notificationBig")
                           .color("#5AB5B5")
                           .param("sleepers", var4.readyToSleep())
                           .param("total", var4.playerCount())
                     );
                  }
               }
            }
         }
      }
   }

   class="kw">private class="kw">static SleepNotificationSystem.NotificationState getNotificationState(World var0) {
      if (CanSleepInWorld.check(var0).isNegative()) {
         class="kw">return SleepNotificationSystem.NotReady.INSTANCE;
      } else {
         Store var1 = var0.getEntityStore().getStore();
         WorldSleep var2 = var1.getResource(WorldSomnolence.getResourceType()).getState();
         if (var2 class="kw">instanceof WorldSlumber) {
            class="kw">return SleepNotificationSystem.NotReady.INSTANCE;
         } else {
            List var3 = var0.getPlayerRefs().stream().map(PlayerRef::getReference).filter(Objects::nonNull).toList();
            int var4 = var3.size();
            int var5 = countReadyToSleep(var3, var1);
            if (var4 <= 4) {
               boolean var9 = var5 > 0;
               class="kw">return var9 ? new SleepNotificationSystem.SmallServer(var5, var4) : SleepNotificationSystem.NotReady.INSTANCE;
            } else {
               double var6 = (double)var5 / var4;
               boolean var8 = var6 >= 0.5;
               class="kw">return var8 ? new SleepNotificationSystem.BigServer(var6, var5, var4) : SleepNotificationSystem.NotReady.INSTANCE;
            }
         }
      }
   }

   class="kw">private class="kw">static int countReadyToSleep(Collection<Ref<EntityStore>> var0, ComponentAccessor<EntityStore> var1) {
      int var2 = 0;

      for (Ref var4 : var0) {
         PlayerSomnolence var5 = var1.getComponent(var4, PlayerSomnolence.getComponentType());
         if (var5 != null) {
            boolean var6 = StartSlumberSystem.canNotifyOthersAboutTryingToSleep(var1, var4);
            if (var6) {
               var2++;
            }
         }
      }

      class="kw">return var2;
   }

   class="kw">public class="kw">static Message getSleeperName(@Nullable Ref<EntityStore> var0) {
      if (var0 != null && var0.isValid()) {
         Store var1 = var0.getStore();
         DisplayNameComponent var2 = var1.getComponent(var0, DisplayNameComponent.getComponentType());
         Message var3 = var2 == null ? null : var2.getDisplayName();
         if (var3 != null) {
            class="kw">return var3;
         }

         PlayerRef var4 = var1.getComponent(var0, PlayerRef.getComponentType());
         class="kw">return Message.raw(var4 == null ? "???" : var4.getUsername());
      } else {
         class="kw">return Message.raw("???");
      }
   }

   class="kw">private record BigServer(double ratio, int readyToSleep, int playerCount) class="kw">implements SleepNotificationSystem.NotificationState {
      class="kw">private BigServer {
      }
   }

   class="kw">private enum NotReady class="kw">implements SleepNotificationSystem.NotificationState {
      INSTANCE;

      NotReady() {
      }

      @Override
      class="kw">public int readyToSleep() {
         class="kw">return 0;
      }

      @Override
      class="kw">public int playerCount() {
         class="kw">return 0;
      }
   }

   class="kw">private sealed class="kw">interface NotificationState permits SleepNotificationSystem.NotReady, SleepNotificationSystem.SmallServer, SleepNotificationSystem.BigServer {
      int readyToSleep();

      int playerCount();
   }

   class="kw">private record SmallServer(int readyToSleep, int playerCount) class="kw">implements SleepNotificationSystem.NotificationState {
      class="kw">private SmallServer {
      }
   }
}