ApplyOnJoin class

Пакет: com.hypixel.hytale.server.core.universe.hardcore

Файл: com/hypixel/hytale/server/core/universe/hardcore/HardcoreGameOver.java

extends: RefSystem<EntityStore>

Поля (5)

МодификаторыТипИмя
World var5
String var6
String var7
PlayerLives var8
Player var9

Методы (3)

МодификаторыВозвратСигнатура
public Query<EntityStore> getQuerypublic Query<EntityStore> getQuery()
public void onEntityAddedpublic void onEntityAdded(@Nonnull Ref<EntityStore> var1, @Nonnull AddReason var2, @Nonnull Store<EntityStore> var3, @Nonnull CommandBuffer<EntityStore> var4)
public void onEntityRemovepublic void onEntityRemove(@Nonnull Ref<EntityStore> var1, @Nonnull RemoveReason var2, @Nonnull Store<EntityStore> var3, @Nonnull CommandBuffer<EntityStore> var4)

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.server.core.universe.hardcore;

class="kw">import com.hypixel.hytale.component.AddReason;
class="kw">import com.hypixel.hytale.component.CommandBuffer;
class="kw">import com.hypixel.hytale.component.ComponentAccessor;
class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.RemoveReason;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.component.query.Query;
class="kw">import com.hypixel.hytale.component.system.RefSystem;
class="kw">import com.hypixel.hytale.logger.HytaleLogger;
class="kw">import com.hypixel.hytale.logger.sentry.SkipSentryException;
class="kw">import com.hypixel.hytale.protocol.GameMode;
class="kw">import com.hypixel.hytale.server.core.HytaleServer;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.entity.entities.Player;
class="kw">import com.hypixel.hytale.server.core.entity.entities.player.pages.RespawnPage;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.PlayerLives;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.Spectating;
class="kw">import com.hypixel.hytale.server.core.modules.entity.damage.Damage;
class="kw">import com.hypixel.hytale.server.core.modules.entity.damage.DamageCause;
class="kw">import com.hypixel.hytale.server.core.modules.entity.damage.DeathComponent;
class="kw">import com.hypixel.hytale.server.core.modules.entity.damage.DeathItemLoss;
class="kw">import com.hypixel.hytale.server.core.modules.entity.gamemode.GameModeTypes;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
class="kw">import com.hypixel.hytale.server.core.universe.Universe;
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 com.hypixel.hytale.server.core.util.EventTitleUtil;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;

class="kw">public class="kw">final class HardcoreGameOver {
   class="kw">private class="kw">static class="kw">final HytaleLogger LOGGER = HytaleLogger.forEnclosingClass();
   class="kw">private class="kw">static class="kw">final Message DEATH_MESSAGE = Message.translation("server.misc.hardcore.global.gameOver.deathMessage");
   @Nonnull
   class="kw">public class="kw">static class="kw">final String DEATH_SCREEN_MESSAGE_KEY = "server.misc.hardcore.global.gameOver.deathScreenMessage";
   class="kw">private class="kw">static class="kw">final Message DEATH_SCREEN_MESSAGE = Message.translation("server.misc.hardcore.global.gameOver.deathScreenMessage");
   @Nonnull
   class="kw">public class="kw">static class="kw">final Damage.Source DAMAGE_SOURCE = new Damage.Source() {
      @Nonnull
      @Override
      class="kw">public Message getDeathMessage(@Nonnull Damage var1, @Nonnull Ref<EntityStore> var2, @Nonnull ComponentAccessor<EntityStore> var3) {
         class="kw">return HardcoreGameOver.DEATH_MESSAGE;
      }
   };

   class="kw">private HardcoreGameOver() {
   }

   class="kw">public class="kw">static boolean isActive() {
      HardcoreMode var0 = HytaleServer.get().getConfig().getDefaults().getHardcoreMode();
      class="kw">return var0 != HardcoreMode.Global ? false : Universe.get().getResource(HardcoreState.getResourceType()).isGameOver();
   }

   class="kw">public class="kw">static void trigger() {
      Universe var0 = Universe.get();
      HardcoreState var1 = var0.getResource(HardcoreState.getResourceType());
      if (var1.markGameOver()) {
         var0.flushResource(HardcoreState.getResourceType()).exceptionally(var0x -> {
            ((HytaleLogger.Api)LOGGER.at(Level.SEVERE).withCause(var0x)).log("Failed to flush the hardcore game-over flag");
            class="kw">return null;
         });
         LOGGER.at(Level.INFO).log("The hardcore pool of lives is spent, ending the run for the universe");
         EventTitleUtil.showEventTitleToUniverse(
            Message.translation("server.misc.hardcore.global.gameOver.title"),
            Message.translation("server.misc.hardcore.global.gameOver.subtitle"),
            true,
            null,
            4.0F,
            1.5F,
            1.5F
         );

         for (PlayerRef var3 : var0.getPlayers()) {
            convertOnlinePlayer(var3);
         }
      }
   }

   class="kw">private class="kw">static void convertOnlinePlayer(@Nonnull PlayerRef var0) {
      Ref var1 = var0.getReference();
      if (var1 != null) {
         Store var2 = var1.getStore();
         World var3 = var2.getExternalData().getWorld();

         try {
            var3.execute(() -> {
               if (var1.isValid()) {
                  Player var3 = var2.getComponent(var1, Player.getComponentType());
                  if (var3 != null && isAdventure(var3, var3)) {
                     if (var2.getArchetype(var1).contains(DeathComponent.getComponentType())) {
                        convertDeadPlayer(var1, var2, var3);
                     } else if (!Spectating.isSpectating(var1, var2)) {
                        DeathComponent.tryAddComponent(var2, var1, new Damage(DAMAGE_SOURCE, DamageCause.COMMAND, 2.1474836E9F));
                     }
                  }
               }
            });
         } catch (SkipSentryException var5) {
         }
      }
   }

   class="kw">private class="kw">static void convertDeadPlayer(@Nonnull Ref<EntityStore> var0, @Nonnull Store<EntityStore> var1, @Nonnull Player var2) {
      String var3 = var1.getExternalData().getWorld().getGameModeTypeOnDeath();
      if (GameModeTypes.isValidType(var3)) {
         DeathComponent var4 = var1.getComponent(var0, DeathComponent.getComponentType());
         PlayerRef var5 = var1.getComponent(var0, PlayerRef.getComponentType());
         boolean var6 = var4 != null && var5 != null && var4.isShowDeathMenu();
         Message var7 = var6 ? var4.getDeathMessage() : null;
         boolean var8 = var6 && var4.displayDataOnDeathScreen();
         DeathItemLoss var9 = var6 ? var4.getDeathItemLoss() : null;
         if (GameModeTypes.enterOnDeath(var0, var1, var3)) {
            PlayerLives.markExhausted(var0, var1);
            var2.markNeedsSave();
            if (var6) {
               var2.getPageManager().openCustomPage(var0, var1, RespawnPage.forPermadeath(var5, var7, var8, var9, DEATH_SCREEN_MESSAGE));
            }
         }
      }
   }

   class="kw">private class="kw">static boolean isAdventure(@Nonnull Player var0, @Nonnull World var1) {
      GameMode var2 = var0.getGameMode();
      GameMode var3 = var2 != null ? var2 : var1.getWorldConfig().getGameMode();
      class="kw">return var3 == GameMode.Adventure;
   }

   class="kw">public class="kw">static class ApplyOnJoin class="kw">extends RefSystem<EntityStore> {
      class="kw">public ApplyOnJoin() {
      }

      @Override
      class="kw">public void onEntityAdded(
         @Nonnull Ref<EntityStore> var1, @Nonnull AddReason var2, @Nonnull Store<EntityStore> var3, @Nonnull CommandBuffer<EntityStore> var4
      ) {
         if (HardcoreGameOver.isActive()) {
            World var5 = var4.getExternalData().getWorld();
            String var6 = var5.getGameModeTypeOnDeath();
            String var7 = GameModeTypes.getCurrentTypeId(var1, var4);
            if (var6 == null || !var6.equals(var7)) {
               PlayerLives var8 = var4.getComponent(var1, PlayerLives.getComponentType());
               if (var8 == null || var8.getRemaining() <= 0) {
                  Player var9 = var4.getComponent(var1, Player.getComponentType());
                  if (var9 != null && HardcoreGameOver.isAdventure(var9, var5)) {
                     if (var4.getArchetype(var1).contains(DeathComponent.getComponentType())) {
                        var4.run(var2x -> {
                           if (var1.isValid()) {
                              HardcoreGameOver.convertDeadPlayer(var1, var2x, var9);
                           }
                        });
                     } else if (GameModeTypes.isValidType(var6)) {
                        if (var7 == null || GameModeTypes.exit(var1, var4)) {
                           if (GameModeTypes.enter(var1, var4, var6)) {
                              PlayerLives.markExhausted(var1, var4);
                              var9.markNeedsSave();
                           }
                        }
                     }
                  }
               }
            }
         }
      }

      @Override
      class="kw">public void onEntityRemove(
         @Nonnull Ref<EntityStore> var1, @Nonnull RemoveReason var2, @Nonnull Store<EntityStore> var3, @Nonnull CommandBuffer<EntityStore> var4
      ) {
      }

      @Nonnull
      @Override
      class="kw">public Query<EntityStore> getQuery() {
         class="kw">return Player.getComponentType();
      }
   }
}