Solved Solved

Discussion in 'Spigot Plugin Development' started by MisterQuatsch, Jun 30, 2016.

  1. //EDIT Solved
     
    #1 MisterQuatsch, Jun 30, 2016
    Last edited: Jun 30, 2016
  2. This is giving you the error:
    Code (Java):
    spawns.get(r)
    What is your spawns object. When you are getting the location from your spawns object it is returning null.
     
  3. Code (Text):
      public static ArrayList<Location> spawns = new ArrayList<>();
       public static Location loc1 = new Location(Bukkit.getServer().getWorld("world"), 1000, 256, 100);
       public static Location loc2 = new Location(Bukkit.getServer().getWorld("world"), 200, 256, 1000);
       public static Location loc3 = new Location(Bukkit.getServer().getWorld("world"), 3500, 256, 100);
       public static Location loc4 = new Location(Bukkit.getServer().getWorld("world"), 100, 256, 2800);
       public static Location loc5 = new Location(Bukkit.getServer().getWorld("world"), 10, 256, 100);
       public static Location loc6 = new Location(Bukkit.getServer().getWorld("world"), 1240, 256, 3210);
       public static Location loc7 = new Location(Bukkit.getServer().getWorld("world"), -4500, 256, 700);
       public static Location loc8 = new Location(Bukkit.getServer().getWorld("world"), 100, 256, -3500);
       public static Location loc9 = new Location(Bukkit.getServer().getWorld("world"), -1340, 256, 670);
       public static Location loc10 = new Location(Bukkit.getServer().getWorld("world"), 2300, 256, 4300);
       public static Location loc11 = new Location(Bukkit.getServer().getWorld("world"), -213, 256, 3672);
       public static Location loc12 = new Location(Bukkit.getServer().getWorld("world"), 545, 256, 3454);
       public static Location loc13 = new Location(Bukkit.getServer().getWorld("world"), 3030, 256, -1234);
       public static Location loc14 = new Location(Bukkit.getServer().getWorld("world"), 2040, 256, 1400);
       public static Location loc15 = new Location(Bukkit.getServer().getWorld("world"), 3829, 256, 832);
       public static Location loc16 = new Location(Bukkit.getServer().getWorld("world"), 678, 256, -1234);
       public static Location loc17 = new Location(Bukkit.getServer().getWorld("world"), -4653, 256, -3435);
       public static Location loc18 = new Location(Bukkit.getServer().getWorld("world"), -2431, 256, -634);
       public static Location loc19 = new Location(Bukkit.getServer().getWorld("world"), 4633, 256, -52);
       public static Location loc20 = new Location(Bukkit.getServer().getWorld("world"), -312, 256, 4345);
       public static Location loc21 = new Location(Bukkit.getServer().getWorld("world"), -2314, 256, -4123);
       public static Location loc22 = new Location(Bukkit.getServer().getWorld("world"), -673, 256, -4122);
       public static Location loc23 = new Location(Bukkit.getServer().getWorld("world"), -4512, 256, -4143);
       public static Location loc24 = new Location(Bukkit.getServer().getWorld("world"), -1243, 256, 4231);
       public static Location loc25 = new Location(Bukkit.getServer().getWorld("world"), -3245, 256, 4131);
       public static Location loc26 = new Location(Bukkit.getServer().getWorld("world"), -1233, 256, 2133);
       public static Location loc27 = new Location(Bukkit.getServer().getWorld("world"), 4132, 256, -4523);
       public static Location loc28 = new Location(Bukkit.getServer().getWorld("world"), 1232, 256, -1231);
       public static Location loc29 = new Location(Bukkit.getServer().getWorld("world"), -502, 256, -2214);
       public static Location loc30 = new Location(Bukkit.getServer().getWorld("world"), 234, 256, -3231);

         spawns.add(loc1);
         spawns.add(loc2);
         spawns.add(loc3);
         spawns.add(loc4);
         spawns.add(loc5);
         spawns.add(loc6);
         spawns.add(loc7);
         spawns.add(loc8);
         spawns.add(loc9);
         spawns.add(loc10);
         spawns.add(loc11);
         spawns.add(loc12);
         spawns.add(loc13);
         spawns.add(loc14);
         spawns.add(loc15);
         spawns.add(loc16);
         spawns.add(loc17);
         spawns.add(loc18);
         spawns.add(loc19);
         spawns.add(loc20);
         spawns.add(loc21);
         spawns.add(loc22);
         spawns.add(loc23);
         spawns.add(loc24);
         spawns.add(loc25);
         spawns.add(loc26);
         spawns.add(loc27);
         spawns.add(loc28);
         spawns.add(loc29);
         spawns.add(loc30);
     
  4. Could you show that entire spawns class?
     
  5. Jeez, learn to use static probably and to clean that code up... Looking at it would give anyone a headache...
     
  6. Thats every thing that has somthing to do with the "spawns"
     
  7. I dont need any comments like this... If you cant help and just want to say something pls just dont do it. Thanks..
    //Edit: now i see what you mean with the static. hehe i was just copy and pasting this from a other plugin that i made like 5 months ago. ty ^^
     
  8. And arrays
     
  9. Is all that stored in a method, or how are you adding the locations to the ArrayList. You can't just have them out in the open with no method. By the looks of it, I don't think static is necessary here, just make an object called CustomLocations or something and add all the locations with the contructor, then add some get/set methods.

    Static should only be used for global utility methods or constant variables in specific cases.
     
  10. I add them in onEnable
     
  11. arraylist get start from 0
     
  12. Could you rerun your code, recreate the error, post the StackTrace, the class the error is coming from, and the line the error is on. You don't need to mark/separate your code and like this:
    Code (Java):
    pl.teleport /* < this gives me the Error */
                                (spawns.get(r));
    Just post the line normally. Getting something from an ArrayList shouldn't return null. It should give an IndexOutOfBounds exception.

    Perhaps if your Location objects are null. That's the only thing that comes to mind right now.
     
  13. loc is null
     
  14. Is it though? pl is coming from his for loop:
    Code (Java):
    for (Player pl : Bukkit.getServer().getOnlinePlayers())
    EDIT: You changed pl to loc. And I think I'd have to agree with you. The only thing I can see that would be null are the location objects he is giving it.
     
    #14 Hunky524, Jun 30, 2016
    Last edited: Jun 30, 2016
  15. loc, my bad :p
     
  16. Ok i found out what the error was. I debugged it and the world was null.
    Code (Text):
    Location{world=null,x=2040.0,y=256.0,z=1400.0,pitch=0.0,yaw=0.0}
    @Klaus and @Hunky524
    Thanks for the help :)
     
  17. also, you spawn setup is so bad, i mean, why not list.add(new Location()) than making variable and add after
     
    • Agree Agree x 1
  18. Yep like i say i had created this code 5 moths ago i will change it now :D
     
  19. You're creating the Location objects statically upon plugin initialization, which means the World will be null. While the random int you use to retrieve a spawn value is off by one, when it errors it would be an IndexOutOfBoundsException (diff issue). Your NPE is because the worlds weren't loaded when you made your locations.
     
    • Agree Agree x 1
    • Winner Winner x 1
  20. Yea i found it out like 1 min ago but thank you :D