SpawnSetCommand class

Пакет: com.hypixel.hytale.builtin.teleport.commands.teleport

Файл: com/hypixel/hytale/builtin/teleport/commands/teleport/SpawnSetCommand.java

extends: AbstractWorldCommand

Поля (15)

МодификаторыТипИмя
Ref var10
Transform var11
WorldConfig var12
Vector3d var4
var4
var4
RelativeDoublePosition var5
TransformComponent var6
HeadRotation var7
Ref var8
Rotation3fc var9
var9
var9
var9
var9

Методы (2)

МодификаторыВозвратСигнатура
abstract throw new GeneralCommandExceptionthrow new GeneralCommandException(MESSAGE_COMMANDS_ERROR_PROVIDE_POSITION)
abstract super super("set", "server.commands.spawn.set.desc")

Исходный код

Показать/скрыть
class="kw">package com.hypixel.hytale.builtin.teleport.commands.teleport;

class="kw">import com.hypixel.hytale.component.Ref;
class="kw">import com.hypixel.hytale.component.Store;
class="kw">import com.hypixel.hytale.math.vector.Rotation3f;
class="kw">import com.hypixel.hytale.math.vector.Rotation3fc;
class="kw">import com.hypixel.hytale.math.vector.Transform;
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.DefaultArg;
class="kw">import com.hypixel.hytale.server.core.command.system.arguments.system.OptionalArg;
class="kw">import com.hypixel.hytale.server.core.command.system.arguments.types.ArgTypes;
class="kw">import com.hypixel.hytale.server.core.command.system.arguments.types.RelativeDoublePosition;
class="kw">import com.hypixel.hytale.server.core.command.system.basecommands.AbstractWorldCommand;
class="kw">import com.hypixel.hytale.server.core.command.system.exceptions.GeneralCommandException;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.HeadRotation;
class="kw">import com.hypixel.hytale.server.core.modules.entity.component.TransformComponent;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.WorldConfig;
class="kw">import com.hypixel.hytale.server.core.universe.world.spawn.GlobalSpawnProvider;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import java.text.DecimalFormat;
class="kw">import java.util.logging.Level;
class="kw">import javax.annotation.Nonnull;
class="kw">import org.joml.Vector3d;

class="kw">public class SpawnSetCommand class="kw">extends AbstractWorldCommand {
   @Nonnull
   class="kw">private class="kw">static class="kw">final DecimalFormat DECIMAL = new DecimalFormat("#.###");
   @Nonnull
   class="kw">private class="kw">static class="kw">final Message MESSAGE_COMMANDS_ERROR_PROVIDE_POSITION = Message.translation("server.commands.errors.providePosition");
   @Nonnull
   class="kw">private class="kw">final OptionalArg<RelativeDoublePosition> positionArg = this.withOptionalArg(
      "position", "server.commands.spawn.set.position.desc", ArgTypes.RELATIVE_POSITION
   );
   @Nonnull
   class="kw">private class="kw">final DefaultArg<Rotation3fc> rotationArg = this.withDefaultArg(
      "rotation", "server.commands.spawn.set.rotation.desc", ArgTypes.ROTATION, Rotation3f.IDENTITY, "server.commands.spawn.set.rotation.class="kw">default.desc"
   );

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

   @Override
   class="kw">protected void execute(@Nonnull CommandContext var1, @Nonnull World var2, @Nonnull Store<EntityStore> var3) {
      Vector3d var4;
      if (this.positionArg.provided(var1)) {
         RelativeDoublePosition var5 = this.positionArg.get(var1);
         var4 = var5.getRelativePosition(var1, var2, var3);
      } else {
         if (!var1.isPlayer()) {
            throw new GeneralCommandException(MESSAGE_COMMANDS_ERROR_PROVIDE_POSITION);
         }

         Ref var8 = var1.senderAsPlayerRef();
         if (var8 == null || !var8.isValid()) {
            throw new GeneralCommandException(MESSAGE_COMMANDS_ERROR_PROVIDE_POSITION);
         }

         TransformComponent var6 = var3.getComponent(var8, TransformComponent.getComponentType());
         assert var6 != null;
         var4 = new Vector3d(var6.getPosition());
      }

      Rotation3fc var9;
      if (this.rotationArg.provided(var1)) {
         var9 = this.rotationArg.get(var1);
      } else if (var1.isPlayer()) {
         Ref var10 = var1.senderAsPlayerRef();
         if (var10 != null && var10.isValid()) {
            HeadRotation var7 = var3.getComponent(var10, HeadRotation.getComponentType());
            assert var7 != null;
            var9 = var7.getRotation();
         } else {
            var9 = this.rotationArg.get(var1);
         }
      } else {
         var9 = this.rotationArg.get(var1);
      }

      Transform var11 = new Transform(new Vector3d(var4), new Rotation3f(var9));
      WorldConfig var12 = var2.getWorldConfig();
      var12.setSpawnProvider(new GlobalSpawnProvider(var11));
      var12.markChanged();
      var2.getLogger().at(Level.INFO).log("Set spawn provider to: %s", var12.getSpawnProvider());
      var1.sendMessage(
         Message.translation("server.universe.setspawn.info")
            .param("posX", DECIMAL.format(var4.x()))
            .param("posY", DECIMAL.format(var4.y()))
            .param("posZ", DECIMAL.format(var4.z()))
            .param("rotX", DECIMAL.format(var9.x()))
            .param("rotY", DECIMAL.format(var9.y()))
            .param("rotZ", DECIMAL.format(var9.z()))
      );
   }
}