/**
   * Creates VisibleObject instance and spawns it using given {@link SpawnTemplate} instance.
   *
   * @param spawn
   * @return created and spawned VisibleObject
   */
  public static VisibleObject spawnObject(SpawnTemplate spawn, int instanceIndex) {
    final VisibleObject visObj = getSpawnedObject(spawn, instanceIndex);
    if (spawn.isEventSpawn()) spawn.getEventTemplate().addSpawnedObject(visObj);

    spawn.setVisibleObject(visObj);
    return visObj;
  }
 static void bringIntoWorld(VisibleObject visibleObject, SpawnTemplate spawn, int instanceIndex) {
   bringIntoWorld(
       visibleObject,
       spawn.getWorldId(),
       instanceIndex,
       spawn.getX(),
       spawn.getY(),
       spawn.getZ(),
       spawn.getHeading());
 }
 public static SpawnTemplate addNewSingleTimeSpawn(
     int worldId,
     int npcId,
     float x,
     float y,
     float z,
     byte heading,
     int creatorId,
     String masterName) {
   SpawnTemplate template = addNewSpawn(worldId, npcId, x, y, z, heading, 0);
   template.setCreatorId(creatorId);
   template.setMasterName(masterName);
   return template;
 }
 static SpawnTemplate createSpawnTemplate(
     int worldId,
     int npcId,
     float x,
     float y,
     float z,
     byte heading,
     int creatorId,
     String masterName) {
   SpawnTemplate template = createSpawnTemplate(worldId, npcId, x, y, z, heading);
   template.setCreatorId(creatorId);
   template.setMasterName(masterName);
   return template;
 }
  private static VisibleObject getSpawnedObject(SpawnTemplate spawn, int instanceIndex) {
    int objectId = spawn.getNpcId();

    if (objectId > 400000 && objectId < 499999) {
      return VisibleObjectSpawner.spawnGatherable(spawn, instanceIndex);
    } else if (spawn instanceof RiftSpawnTemplate) {
      return VisibleObjectSpawner.spawnRiftNpc((RiftSpawnTemplate) spawn, instanceIndex);
    } else if (spawn instanceof BaseSpawnTemplate) {
      return VisibleObjectSpawner.spawnBaseNpc((BaseSpawnTemplate) spawn, instanceIndex);
    } else if (spawn instanceof SiegeSpawnTemplate) {
      return VisibleObjectSpawner.spawnSiegeNpc((SiegeSpawnTemplate) spawn, instanceIndex);
    } else if (spawn instanceof VortexSpawnTemplate) {
      return VisibleObjectSpawner.spawnInvasionNpc((VortexSpawnTemplate) spawn, instanceIndex);
    } else {
      return VisibleObjectSpawner.spawnNpc(spawn, instanceIndex);
    }
  }
 /**
  * Should be used when need to define whether spawn will be deleted after death Using this method
  * spawns will not be saved with //save_spawn command
  *
  * @param worldId
  * @param npcId
  * @param x
  * @param y
  * @param z
  * @param heading
  * @param respawnTime
  * @param permanent
  * @return SpawnTemplate
  */
 public static SpawnTemplate addNewSpawn(
     int worldId, int npcId, float x, float y, float z, byte heading, int respawnTime) {
   SpawnTemplate spawnTemplate = createSpawnTemplate(worldId, npcId, x, y, z, heading);
   spawnTemplate.setRespawnTime(respawnTime);
   return spawnTemplate;
 }