Solved ERROR org.bukkit.plugin.InvalidPluginException: java.lang.StackOverflowError

Discussion in 'Plugin Development' started by Tomasko, Jan 3, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    Tomasko

    Hello, please, if you can help my with fixing this error, thanks :)

    Error:
    at teleport.Teleport.<init>(TeleportPlayer.java:35) ~[?:?]
    at teleport.TeleportPlayer.<init>(TeleportPlayer.java:35) ~[?:?] more than 60 times
    [​IMG]



    Teleport
    Code:java
    1. /*
    2. * To change this license header, choose License Headers in Project Properties.
    3. * To change this template file, choose Tools | Templates
    4. * and open the template in the editor.
    5. */
    6.  
    7. package teleport;
    8.  
    9. import java.io.File;
    10. import java.util.logging.Logger;
    11. import org.bukkit.command.Command;
    12. import org.bukkit.command.CommandSender;
    13. import org.bukkit.configuration.file.FileConfiguration;
    14. import org.bukkit.configuration.file.YamlConfiguration;
    15. import org.bukkit.entity.Player;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.plugin.java.JavaPlugin;
    18.  
    19. /**
    20. *
    21. * @author Tomas
    22. */
    23. public class Teleport extends JavaPlugin {
    24.  
    25. static final Logger log = Logger.getLogger("Minecraft");
    26. public File confFile;
    27. public File confFile2;
    28. public FileConfiguration conf;
    29. public FileConfiguration conf2;
    30. TeleportPlayer tp = new TeleportPlayer();
    31.  
    32.  
    33.  
    34.  
    35.  
    36. @Override
    37. public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args) {
    38. if (cmd.getName().equalsIgnoreCase("stargate") && sender instanceof Player) {
    39. //todo
    40. }
    41. return false;
    42. }
    43.  
    44. @Override
    45. public void onEnable() {
    46. log.info("[STARGATE]Plugin enabled");
    47. getServer().getPluginManager().registerEvents((Listener) new CustomListener(), this);
    48.  
    49. confFile = new File(this.getDataFolder(), "config.yml");
    50. confFile2 = new File(this.getDataFolder(), "gates.yml");
    51. conf = YamlConfiguration.loadConfiguration(confFile);
    52. conf2 = YamlConfiguration.loadConfiguration(confFile2);
    53. if (conf.getInt("AUT") != 5) tp.setfile();
    54. else
    55. tp.loadfile();
    56. }
    57.  
    58. @Override
    59. public void onDisable() {
    60. log.info("[STARGATE]Plugin disabled");
    61. }
    62.  
    63. public static void main(String[] args) {
    64. // TODO code application logic here
    65. }
    66.  
    67. }
    68.  



    Listener
    Code:java
    1. /*
    2.  
    3.  
    4. package teleport;
    5.  
    6. import java.util.logging.Logger;
    7. import org.bukkit.ChatColor;
    8.  
    9. import org.bukkit.Material;
    10. import org.bukkit.World;
    11. import org.bukkit.block.Block;
    12.  
    13. import org.bukkit.entity.Player;
    14. import org.bukkit.event.EventHandler;
    15. import org.bukkit.event.EventPriority;
    16. import org.bukkit.event.Listener;
    17. import org.bukkit.event.block.Action;
    18. import org.bukkit.event.player.PlayerInteractEvent;
    19.  
    20.  
    21. public class CustomListener implements Listener {
    22.  
    23.   private static Logger log = Logger.getLogger("Minecraft");
    24.   TeleportPlayer tp = new TeleportPlayer();
    25.   int x;
    26.   int y;
    27.   int z;
    28.   World w;
    29.  
    30.  
    31.   @EventHandler(priority=EventPriority.HIGHEST)
    32.   public void onPlayerUse(PlayerInteractEvent event){
    33.   Player p = event.getPlayer();
    34.   Action a = event.getAction();
    35.  
    36.   Block test = event.getClickedBlock();
    37.   if (test.getType() == Material.ENDER_PORTAL_FRAME) {
    38.   x = event.getClickedBlock().getX();
    39.   y = event.getClickedBlock().getY();
    40.   z = event.getClickedBlock().getZ();
    41.   w = event.getClickedBlock().getWorld();
    42.   if (tp.gatetest(x, y, z, w) == true) {
    43.   p.sendMessage(ChatColor.RED + "Gate is ok");
    44.   if (tp.gatecheck(x, y, z) == 0) tp.registergate(x, y, z);
    45.   }
    46.   else
    47.   p.sendMessage(ChatColor.RED + "Gate is destroyed");
    48.  
    49.   }
    50.  
    51.   }
    52. }
    53.  


    PlayerTeleport
    Code:java
    1. /*
    2. * To change this license header, choose License Headers in Project Properties.
    3. * To change this template file, choose Tools | Templates
    4. * and open the template in the editor.
    5. */
    6.  
    7. package teleport;
    8.  
    9. import java.io.IOException;
    10. import java.util.logging.Level;
    11. import java.util.logging.Logger;
    12. import org.bukkit.Bukkit;
    13. import org.bukkit.Location;
    14. import org.bukkit.World;
    15. import org.bukkit.Material;
    16.  
    17.  
    18.  
    19.  
    20.  
    21. /**
    22. *
    23. * @author Tomas
    24. */
    25. public class TeleportPlayer {
    26. int tmp = 0;
    27. int tmp2 = 0;
    28. public double x[];
    29. public double y[];
    30. public double z[];
    31. public int id[];
    32. public String code[];
    33. public int gates;
    34. public int temp = 0;
    35. Teleport t = new Teleport();
    36. int xsur = 0;
    37. int ysur = 0;
    38. int zsur = 0;
    39. int tmp3 = 0;
    40.  
    41. public boolean gatetest(int x, int y, int z, World w) {
    42. Location pos1 = new Location(Bukkit.getServer().getWorld("world"), x, y, z);
    43. Location pos2 = new Location(Bukkit.getServer().getWorld("world"), x, y, z + 1);
    44. Location pos3 = new Location(Bukkit.getServer().getWorld("world"), x, y + 1, z + 1);
    45. Location pos4 = new Location(Bukkit.getServer().getWorld("world"), x, y + 2, z + 1);
    46. Location pos5 = new Location(Bukkit.getServer().getWorld("world"), x, y + 3, z + 1);
    47. Location pos6 = new Location(Bukkit.getServer().getWorld("world"), x - 1, y, z + 1);
    48. Location pos7 = new Location(Bukkit.getServer().getWorld("world"), x - 2, y, z + 1);
    49. Location pos8 = new Location(Bukkit.getServer().getWorld("world"), x - 3, y, z + 1);
    50. Location pos9 = new Location(Bukkit.getServer().getWorld("world"), x - 3, y + 1, z + 1);
    51. Location pos10 = new Location(Bukkit.getServer().getWorld("world"), x - 3, y + 2, z + 1);
    52. Location pos11 = new Location(Bukkit.getServer().getWorld("world"), x - 3, y + 3, z + 1);
    53. Location pos12 = new Location(Bukkit.getServer().getWorld("world"), x - 1, y + 3, z + 1);
    54. Location pos13 = new Location(Bukkit.getServer().getWorld("world"), x - 2,y + 3, z + 1);
    55.  
    56.  
    57.  
    58. if (pos1.getBlock().getType() == Material.ENDER_PORTAL_FRAME) {
    59. tmp++;
    60. }
    61.  
    62. if (pos2.getBlock().getType() == Material.OBSIDIAN) {
    63. tmp++;
    64. }
    65.  
    66. if (pos3.getBlock().getType() == Material.OBSIDIAN) {
    67. tmp++;
    68. }
    69.  
    70. if (pos4.getBlock().getType() == Material.OBSIDIAN) {
    71. tmp++;
    72. }
    73.  
    74. if (pos5.getBlock().getType() == Material.OBSIDIAN) {
    75. tmp++;
    76. }
    77.  
    78. if (pos6.getBlock().getType() == Material.OBSIDIAN) {
    79. tmp++;
    80. }
    81.  
    82. if (pos7.getBlock().getType() == Material.OBSIDIAN) {
    83. tmp++;
    84. }
    85.  
    86. if (pos8.getBlock().getType() == Material.OBSIDIAN) {
    87. tmp++;
    88. }
    89.  
    90. if (pos9.getBlock().getType() == Material.OBSIDIAN) {
    91. tmp++;
    92. }
    93.  
    94. if (pos10.getBlock().getType() == Material.OBSIDIAN) {
    95. tmp++;
    96. }
    97.  
    98. if (pos11.getBlock().getType() == Material.OBSIDIAN) {
    99. tmp++;
    100. }
    101.  
    102. if (pos12.getBlock().getType() == Material.OBSIDIAN) {
    103. tmp++;
    104. }
    105.  
    106. if (pos13.getBlock().getType() == Material.OBSIDIAN) {
    107. tmp++;
    108. }
    109.  
    110. if (tmp == 13) {tmp = 0; return true;}
    111.  
    112.  
    113.  
    114. tmp = 0;
    115. return false;
    116.  
    117. }
    118.  
    119. public int gatecheck(int xsur, int ysur, int zsur) {
    120. tmp2 = 0;
    121.  
    122. while(tmp2 != gates) {
    123. if (x[tmp2] == xsur) tmp3++;
    124. if (y[tmp2] == ysur) tmp3++;
    125. if (z[tmp2] == zsur) tmp3++;
    126. if (tmp3 == 3) {temp = tmp2; return 1;}
    127. tmp2++;
    128. }
    129. return 0;
    130. }
    131.  
    132. public void setfile() {
    133. t.conf2.set("Gates", 0);
    134. t.conf.set("AUT", 5);
    135. try {
    136. t.conf2.save(t.confFile2);
    137. } catch (IOException ex) {
    138. Logger.getLogger(TeleportPlayer.class.getName()).log(Level.SEVERE, null, ex);
    139. }
    140.  
    141. try {
    142. t.conf.save(t.confFile);
    143. } catch (IOException ex) {
    144. Logger.getLogger(TeleportPlayer.class.getName()).log(Level.SEVERE, null, ex);
    145. }
    146. }
    147.  
    148. public void loadfile() {
    149. tmp2 = t.conf2.getInt("Gates");
    150. if (tmp2 == 0) {gates = 0;}
    151. else {
    152. gates = tmp2;
    153. tmp2 = 0;
    154. while(tmp2 != gates) {
    155. x[tmp2] = t.conf2.getDouble(tmp2 + ".X");
    156. y[tmp2] = t.conf2.getDouble(tmp2 + ".Y");
    157. z[tmp2] = t.conf2.getDouble(tmp2 + ".Z");
    158. id[tmp2] = tmp2;
    159. code[tmp] = t.conf2.getString(tmp2 + ".CODE");
    160. tmp2++;
    161. }
    162. tmp2 = 0;
    163. }
    164. }
    165.  
    166. public void registergate(int xsur, int ysur, int zsur) {
    167. tmp2 = 0;
    168. tmp3 = 0;
    169. tmp2 = t.conf2.getInt("Gates") + 1;
    170.  
    171. t.conf2.set(tmp2 + ".X", xsur);
    172. t.conf2.set(tmp2 + ".Y", ysur);
    173. t.conf2.set(tmp2 + ".Z", zsur);
    174. t.conf2.set(tmp2 + ".CODE", "somecodehere");
    175. try {
    176. t.conf2.save(t.confFile2);
    177. } catch (IOException ex) {
    178. Logger.getLogger(TeleportPlayer.class.getName()).log(Level.SEVERE, null, ex);
    179. }
    180. }
    181.  
    182.  
    183.  
    184.  
    185.  
    186.  
    187.  
    188.  
    189.  
    190.  
    191.  
    192.  
    193. }
    194.  

    And plugin.yml
    name: Teleport
    main: teleport.Teleport
    version: 0.1

    Thanks for your time and answers

    Full error code: http://pastebin.com/jXRN8aif
     
  2. Offline

    16davidjm6

    Tomasko

    your plugin opens the main, Teleport class, which contains this line of code creating a new TeleportPlayer:

    TeleportPlayer tp = new TeleportPlayer();

    Which then takes us to this line of code in the TeleportPlayer class, creating a new Teleport:

    Teleport t = new Teleport();

    Which then takes us back to the Teleport class, which runs this line creating a new TeleportPlayer:

    TeleportPlayer tp = new TeleportPlayer();

    Which ONCE AGAIN runs this line in the TeleportPlayer class, creating a new Teleport:

    Teleport t = new Teleport();


    See where this is going? You have created an infinite loop creating objects, which causes java to use more and more and more and more memory trying to keep track of all these objects, and it eventually gives up. (You try meeting 20 million new people at once and see if you can remember each one of their names, height, eye color, gender, etc lol)

    If you would like to post what you were TRYING to do, maybe I or someone else could help you.


    Remember to add 16davidjm6 to your post so I see it
     
    Assist likes this.
  3. Offline

    xTrollxDudex

    Tomasko
    They're called in code: recursive.

    You shouldn't be repeatedly initializing one class which initializes the class that intializes the seconds class, this casuses the code to make hundreds of instances of TeleportPlayer.

    Luckily, this exception was caught and exited the server from executing anymore code, else, your computer might crash in a few hours.
     
  4. Offline

    Tomasko

    Thanks :)
     
Thread Status:
Not open for further replies.

Share This Page