SetTimePeriodCommand class

Пакет: com.hypixel.hytale.server.core.modules.time.commands

Файл: com/hypixel/hytale/server/core/modules/time/commands/TimeCommand.java

extends: AbstractWorldCommand

Поля (4)

МодификаторыТипИмя
private final TimeCommand.TimeOfDay timeOfDay
float var4
float var5
WorldTimeResource var6

Методы (1)

МодификаторыВозвратСигнатура
protected void executeprotected void execute(@Nonnull CommandContext var1, @Nonnull World var2, @Nonnull Store<EntityStore> var3)

Исходный код

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

class="kw">import com.hypixel.hytale.codec.validation.Validators;
class="kw">import com.hypixel.hytale.common.util.FormatUtil;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.server.core.Message;
class="kw">import com.hypixel.hytale.server.core.command.system.CommandContext;
class="kw">import com.hypixel.hytale.server.core.command.system.arguments.system.RequiredArg;
class="kw">import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
class="kw">import com.hypixel.hytale.server.core.command.system.basecommands.AbstractCommandCollection;
class="kw">import com.hypixel.hytale.server.core.command.system.basecommands.AbstractWorldCommand;
class="kw">import com.hypixel.hytale.server.core.modules.time.WorldTimeResource;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.commands.worldconfig.WorldConfigPauseTimeCommand;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
class="kw">import java.time.LocalDateTime;
class="kw">import java.time.temporal.ChronoField;
class="kw">import java.util.Locale;
class="kw">import javax.annotation.Nonnull;

class="kw">public class TimeCommand class="kw">extends AbstractWorldCommand {
   class="kw">public TimeCommand() {
      super("time", "server.commands.time.get.desc");
      this.setPermissionGroups("hytale:WorldEditor");
      this.addAliases("daytime");
      this.addUsageVariant(new TimeCommand.SetTimeHourCommand());

      for (TimeCommand.TimeOfDay var4 : TimeCommand.TimeOfDay.values()) {
         this.addSubCommand(new TimeCommand.SetTimePeriodCommand(var4));
      }

      this.addSubCommand(new TimeCommand.TimeSetSubCommand());
      this.addSubCommand(new TimeCommand.TimePauseCommand());
      this.addSubCommand(new TimeCommand.TimeDilationCommand());
   }

   @Override
   class="kw">public void execute(@Nonnull CommandContext var1, @Nonnull World var2, @Nonnull Store<EntityStore> var3) {
      WorldTimeResource var4 = var3.getResource(WorldTimeResource.getResourceType());
      LocalDateTime var5 = var4.getGameDateTime();
      String var6 = var2.getWorldConfig().isGameTimePaused() ? "server.commands.time.info" : "server.commands.time.infoUnpaused";
      Message var7 = Message.translation(var6).param("worldName", var2.getName());
      var1.sendMessage(
         var7.param("time", var4.getGameTime().toString())
            .param("dayOfWeek", FormatUtil.addNumberSuffix(var5.get(ChronoField.DAY_OF_WEEK)))
            .param("weekOfMonth", FormatUtil.addNumberSuffix(var5.get(ChronoField.ALIGNED_WEEK_OF_MONTH)))
            .param("weekOfYear", FormatUtil.addNumberSuffix(var5.get(ChronoField.ALIGNED_WEEK_OF_YEAR)))
            .param("dayOfYear", FormatUtil.addNumberSuffix(var5.getDayOfYear()))
            .param("moonPhase", FormatUtil.addNumberSuffix(var4.getMoonPhase() + 1))
      );
   }

   class="kw">private class="kw">static class SetTimeHourCommand class="kw">extends AbstractWorldCommand {
      @Nonnull
      class="kw">private class="kw">final RequiredArg<Float> timeArg = this.withRequiredArg("time", "server.commands.time.set.timeArg.desc", ArgTypes.FLOAT)
         .addValidator(Validators.range(0.0F, (float)WorldTimeResource.HOURS_PER_DAY));

      class="kw">public SetTimeHourCommand() {
         super("server.commands.time.set.desc");
         this.setPermissionGroups("hytale:WorldEditor");
      }

      @Override
      class="kw">protected void execute(@Nonnull CommandContext var1, @Nonnull World var2, @Nonnull Store<EntityStore> var3) {
         float var4 = this.timeArg.get(var1);
         WorldTimeResource var5 = var3.getResource(WorldTimeResource.getResourceType());
         var5.setDayTime(var4 / WorldTimeResource.HOURS_PER_DAY, var2, var3);
         var1.sendMessage(Message.translation("server.commands.time.set").param("worldName", var2.getName()).param("time", var5.getGameTime().toString()));
      }
   }

   class="kw">private class="kw">static class SetTimePeriodCommand class="kw">extends AbstractWorldCommand {
      @Nonnull
      class="kw">private class="kw">final TimeCommand.TimeOfDay timeOfDay;

      class="kw">public SetTimePeriodCommand(@Nonnull TimeCommand.TimeOfDay var1) {
         super(var1.name(), "server.commands.time.period." + var1.name().toLowerCase(Locale.ROOT) + ".desc");
         this.setPermissionGroups("hytale:WorldEditor");
         this.timeOfDay = var1;
         this.addAliases(var1.aliases);
      }

      @Override
      class="kw">protected void execute(@Nonnull CommandContext var1, @Nonnull World var2, @Nonnull Store<EntityStore> var3) {
         float var4 = WorldTimeResource.HOURS_PER_DAY * 0.6F;
         float var5 = Math.max(0.0F, (Float)this.timeOfDay.periodFunc.apply(var4));
         WorldTimeResource var6 = var3.getResource(WorldTimeResource.getResourceType());
         var6.setDayTime(var5 / WorldTimeResource.HOURS_PER_DAY, var2, var3);
         var1.sendMessage(
            Message.translation("server.commands.time.setPeriod." + this.timeOfDay.name().toLowerCase(Locale.ROOT))
               .param("worldName", var2.getName())
               .param("time", var6.getGameTime().toString())
         );
      }
   }

   class="kw">private class="kw">static class TimeDilationCommand class="kw">extends AbstractWorldCommand {
      class="kw">private class="kw">static class="kw">final float TIME_DILATION_MIN = 0.01F;
      class="kw">private class="kw">static class="kw">final float TIME_DILATION_MAX = 4.0F;
      @Nonnull
      class="kw">private class="kw">final RequiredArg<Float> timeDilationArg = this.withRequiredArg("timeDilation", "server.commands.time.dilation.timeDilation.desc", ArgTypes.FLOAT)
         .addValidator(Validators.greaterThan(0.01F))
         .addValidator(Validators.max(4.0F));

      class="kw">public TimeDilationCommand() {
         super("dilation", "server.commands.time.dilation.desc");
         this.setPermissionGroups("hytale:Admin");
      }

      @Override
      class="kw">protected void execute(@Nonnull CommandContext var1, @Nonnull World var2, @Nonnull Store<EntityStore> var3) {
         float var4 = this.timeDilationArg.get(var1);
         World.setTimeDilation(var4, var3);
         var1.sendMessage(Message.translation("server.commands.time.dilation.set.success").param("timeDilation", var4));
      }
   }

   class="kw">public enum TimeOfDay {
      Dawn(var0 -> (WorldTimeResource.HOURS_PER_DAY - var0) / 2.0F, "day", "morning"),
      Midday(var0 -> WorldTimeResource.HOURS_PER_DAY / 2.0F, "noon"),
      Dusk(var0 -> (WorldTimeResource.HOURS_PER_DAY - var0) / 2.0F + var0, "night"),
      Midnight(var0 -> 0.0F);

      @Nonnull
      class="kw">private class="kw">final Float2FloatFunction periodFunc;
      class="kw">private class="kw">final String[] aliases;

      TimeOfDay(@Nonnull class="kw">final Float2FloatFunction nullxx, String... nullxxx) {
         this.periodFunc = nullxx;
         this.aliases = nullxxx;
      }
   }

   class="kw">private class="kw">static class TimePauseCommand class="kw">extends AbstractWorldCommand {
      class="kw">public TimePauseCommand() {
         super("pause", "server.commands.pausetime.desc");
         this.setPermissionGroups("hytale:WorldEditor");
         this.addAliases("stop");
      }

      @Override
      class="kw">protected void execute(@Nonnull CommandContext var1, @Nonnull World var2, @Nonnull Store<EntityStore> var3) {
         WorldConfigPauseTimeCommand.pauseTime(var1.sender(), var2, var3);
      }
   }

   class="kw">private class="kw">static class TimeSetSubCommand class="kw">extends AbstractCommandCollection {
      class="kw">public TimeSetSubCommand() {
         super("set", "server.commands.time.set.desc");
         this.setPermissionGroups("hytale:WorldEditor");
         this.addUsageVariant(new TimeCommand.SetTimeHourCommand());

         for (TimeCommand.TimeOfDay var4 : TimeCommand.TimeOfDay.values()) {
            this.addSubCommand(new TimeCommand.SetTimePeriodCommand(var4));
         }
      }
   }
}