SpawnCommand class

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

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

extends: AbstractPlayerCommand

Поля (29)

МодификаторыТипИмя
private static final Message MESSAGE_COMMANDS_ERRORS_PLAYER_NOT_IN_WORLD
private final RequiredArg<PlayerRef> playerArg
private final OptionalArg<Integer> spawnIndexArg
Rotation3f var10
HeadRotation var10
TeleportHistory var11
Vector3d var11
Teleport var12
Rotation3f var12
Vector3d var13
TeleportHistory var13
Teleport var14
Vector3d var15
PlayerRef var2
Ref var3
ISpawnProvider var4
Store var4
int var5
World var5
Transform var6
Transform[] var6
Player var6
TransformComponent var7
int var7
PlayerRef var7
HeadRotation var8
Transform var8
Vector3d var9
TransformComponent var9

Методы (7)

МодификаторыВозвратСигнатура
SpawnOtherCommand SpawnOtherCommand()
protected void executeSyncprotected void executeSync(@Nonnull CommandContext var1)
if if(var5 >= 0 && var5 < var6.length)
if if(var6 == null)
static Transform resolveSpawnTransform resolveSpawn(@Nonnull CommandContext var0, @Nonnull World var1, @Nonnull PlayerRef var2, @Nonnull OptionalArg<Integer> var3)
abstract super super("spawn", "server.commands.spawn.desc")
abstract super super("server.commands.spawn.other.desc")

Исходный код

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

class="kw">import com.hypixel.hytale.builtin.teleport.components.TeleportHistory;
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.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.OptionalArg;
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.AbstractPlayerCommand;
class="kw">import com.hypixel.hytale.server.core.command.system.basecommands.CommandBase;
class="kw">import com.hypixel.hytale.server.core.command.system.exceptions.GeneralCommandException;
class="kw">import com.hypixel.hytale.server.core.entity.entities.Player;
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.modules.entity.teleport.Teleport;
class="kw">import com.hypixel.hytale.server.core.permissions.HytalePermissions;
class="kw">import com.hypixel.hytale.server.core.universe.PlayerRef;
class="kw">import com.hypixel.hytale.server.core.universe.world.World;
class="kw">import com.hypixel.hytale.server.core.universe.world.spawn.ISpawnProvider;
class="kw">import com.hypixel.hytale.server.core.universe.world.storage.EntityStore;
class="kw">import javax.annotation.Nonnull;
class="kw">import org.joml.Vector3d;

class="kw">public class SpawnCommand class="kw">extends AbstractPlayerCommand {
   @Nonnull
   class="kw">private class="kw">final OptionalArg<Integer> spawnIndexArg = this.withOptionalArg("spawnIndex", "server.commands.spawn.index.desc", ArgTypes.INTEGER);

   class="kw">public SpawnCommand() {
      super("spawn", "server.commands.spawn.desc");
      this.requirePermission(HytalePermissions.fromCommand("spawn.self"));
      this.setPermissionGroups("hytale:Builder");
      this.addUsageVariant(new SpawnCommand.SpawnOtherCommand());
      this.addSubCommand(new SpawnSetCommand());
      this.addSubCommand(new SpawnSetDefaultCommand());
   }

   @Override
   class="kw">protected void execute(
      @Nonnull CommandContext var1, @Nonnull Store<EntityStore> var2, @Nonnull Ref<EntityStore> var3, @Nonnull PlayerRef var4, @Nonnull World var5
   ) {
      Transform var6 = resolveSpawn(var1, var5, var4, this.spawnIndexArg);
      TransformComponent var7 = var2.getComponent(var3, TransformComponent.getComponentType());
      assert var7 != null;
      HeadRotation var8 = var2.getComponent(var3, HeadRotation.getComponentType());
      assert var8 != null;
      Vector3d var9 = new Vector3d(var7.getPosition());
      Rotation3f var10 = new Rotation3f(var8.getRotation());
      TeleportHistory var11 = var2.ensureAndGetComponent(var3, TeleportHistory.getComponentType());
      var11.append(var5, var9, var10, "World " + var5.getName() + "'s spawn");
      Teleport var12 = Teleport.createForPlayer(var5, var6);
      var2.addComponent(var3, Teleport.getComponentType(), var12);
      Vector3d var13 = var6.getPosition();
      var1.sendMessage(Message.translation("server.commands.spawn.teleported").param("x", var13.x()).param("y", var13.y()).param("z", var13.z()));
   }

   class="kw">private class="kw">static Transform resolveSpawn(@Nonnull CommandContext var0, @Nonnull World var1, @Nonnull PlayerRef var2, @Nonnull OptionalArg<Integer> var3) {
      ISpawnProvider var4 = var1.getWorldConfig().getSpawnProvider();
      if (var3.provided(var0)) {
         int var5 = var3.get(var0);
         Transform[] var6 = var4.getSpawnPoints();
         if (var5 >= 0 && var5 < var6.length) {
            class="kw">return var6[var5];
         }

         int var7 = var6.length - 1;
         var0.sendMessage(Message.translation("server.commands.spawn.indexNotFound").param("maxIndex", var7));
         throw new GeneralCommandException(Message.translation("server.commands.errors.spawnIndexOutOfRange").param("index", var5).param("maxIndex", var7));
      } else {
         class="kw">return var4.getSpawnPoint(var1, var2.getUuid());
      }
   }

   class="kw">private class="kw">static class SpawnOtherCommand class="kw">extends CommandBase {
      class="kw">private class="kw">static class="kw">final Message MESSAGE_COMMANDS_ERRORS_PLAYER_NOT_IN_WORLD = Message.translation("server.commands.errors.playerNotInWorld");
      @Nonnull
      class="kw">private class="kw">final RequiredArg<PlayerRef> playerArg = this.withRequiredArg("player", "server.commands.argtype.player.desc", ArgTypes.PLAYER_REF);
      @Nonnull
      class="kw">private class="kw">final OptionalArg<Integer> spawnIndexArg = this.withOptionalArg("spawnIndex", "server.commands.spawn.index.desc", ArgTypes.INTEGER);

      SpawnOtherCommand() {
         super("server.commands.spawn.other.desc");
         this.requirePermission(HytalePermissions.fromCommand("spawn.other"));
      }

      @Override
      class="kw">protected void executeSync(@Nonnull CommandContext var1) {
         PlayerRef var2 = this.playerArg.get(var1);
         Ref var3 = var2.getReference();
         if (var3 != null && var3.isValid()) {
            Store var4 = var3.getStore();
            World var5 = var4.getExternalData().getWorld();
            var5.execute(
               () -> {
                  Player var6 = var4.getComponent(var3, Player.getComponentType());
                  if (var6 == null) {
                     var1.sendMessage(MESSAGE_COMMANDS_ERRORS_PLAYER_NOT_IN_WORLD);
                  } else {
                     PlayerRef var7 = var4.getComponent(var3, PlayerRef.getComponentType());
                     assert var7 != null;
                     Transform var8 = SpawnCommand.resolveSpawn(var1, var5, var2, this.spawnIndexArg);
                     TransformComponent var9 = var4.getComponent(var3, TransformComponent.getComponentType());
                     assert var9 != null;
                     HeadRotation var10 = var4.getComponent(var3, HeadRotation.getComponentType());
                     assert var10 != null;
                     Vector3d var11 = new Vector3d(var9.getPosition());
                     Rotation3f var12 = new Rotation3f(var10.getRotation());
                     TeleportHistory var13 = var4.ensureAndGetComponent(var3, TeleportHistory.getComponentType());
                     var13.append(var5, var11, var12, "World " + var5.getName() + "'s spawn");
                     Teleport var14 = Teleport.createForPlayer(var5, var8);
                     var4.addComponent(var3, Teleport.getComponentType(), var14);
                     Vector3d var15 = var8.getPosition();
                     var1.sendMessage(
                        Message.translation("server.commands.spawn.teleportedOther")
                           .param("username", var2.getUsername())
                           .param("x", var15.x())
                           .param("y", var15.y())
                           .param("z", var15.z())
                     );
                  }
               }
            );
         } else {
            var1.sendMessage(MESSAGE_COMMANDS_ERRORS_PLAYER_NOT_IN_WORLD);
         }
      }
   }
}