MYSQL For Loops

Discussion in 'Spigot Plugin Development' started by Daeshan, May 24, 2016.

  1. Say I have a table that has locations saved, so it has the x y z and world. What I want to do is play particle effects at all the saved locations that have the string TelePad in category inside table, how can I iterate through all them and get them all as own locations. Not asking for code but more of a explanation
     
  2. I believe that jbdc MySQL returns a result set which can be iterated over. For each one, create a world with the x,y,z and world and then play the particle. I think that there is a World.playParticle(Location); method.
     
  3. I am using the particle library to make the particle direction easier
     
  4. So which part are you having trouble with?
     
  5. I could get a for to work but then I realized I need a while for the result set and it working thanks!
     
  6. In the tables, how exactly are you storing the information? Is it like x,y,z,world as a single string, or are they all in separate columns?

    If it's the second option, you'll have to query the database and convert each element into integers for the coordinates, and the world as a string.

    Basically, you need to query the database for every KEY you have set.
    After that, and query the database grabbing the elements associated with the KEY you just obtained.

    Make a new location by inputting those values:
    Code (Text):
    Location loc = new Location(world, x, y, z);
    Note: You will have to convert that world string into the actual world, I won't explain that here but you should be able to know how to do that.

    Store that location in a List<> and you're ready to loop through that list!