Solved Browse strings list

Discussion in 'Spigot Plugin Development' started by Nico12, Jan 29, 2020.

  1. Hi, I need to go through something like a list:
    Code (Text):

    Spawns:
            'one':
              x: 1145.5380380955376
              y: 8.0
              z: 1651.5045746714875
              yaw: 176,929
              pitch: -1.3741952
              world: world
            'two':
              x: 1222.5174302243174
              y: 8.0
              z: 1578.9711959713577
              yaw: 180.4488
              pitch: -0.6232814
              world: world
            '3':
              x: 1203.512538417417
              y: 8.0
              z: 1638.360937511011
              yaw: 180.40186
              pitch: 5.2430305
              world: world
            '4':
              x: 1145.4109809384747
              y: 8.0
              z: 1651.5027463931658
              yaw: 181.10577
              pitch: 8.57511
              world: world
            '5':
              x: 1083.54660077186
              y: 10.0
              z: 1622.3223202409447
              yaw: -177.25739
              pitch: 5.900059
              world: world
            '6':
              x: 1166.699999988079
              y: 8.0
              z: 1644.699999988079
              yaw: -177.53902
              pitch: 0.328526
              world: world
     
    I need to RANDOMY get any of those spawn so that the player reappears
    Could you help me?
    Thanks in advance!
    Example:
    Code (Text):

    * A player dies *
    // A spawn should be chosen randomly to respawnear, but taking into account that there may be up to 100 respawn points in the list
     
     
    #1 Nico12, Jan 29, 2020
    Last edited: Jan 29, 2020
  2. Do you already have the list as Object? Once you have that, you can simply do this:
    Code (Text):
    List<?> list = ...

    final Random random = new Random();
    ? randomElement = list.get(random.nextInt(list.size()));
     
  3. Thanks! Working!