HeadsUpDisplay

Discussion in 'Plugin Development' started by UltraFireFX, Oct 12, 2013.

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

    UltraFireFX

    Hello Bukkiters,


    I am still working on HeadsUpDisplay and I think that I am almost done, just have a few more bugs to flatten out :D

    So I have been getting the same error for a while now and Google showed up nothing (That I understood) so I decided to ask here, Bukkit.org, I have uploaded the server.txt file

    HeadsUpDisplay.java(Main)
    Code:Java
    1. package me.ultrafirefx.headsupdisplay;
    2.  
    3. import java.io.IOException;
    4. import java.util.List;
    5. import java.util.logging.Logger;
    6.  
    7. import org.bukkit.Bukkit;
    8. import org.bukkit.command.Command;
    9. import org.bukkit.command.CommandSender;
    10. import org.bukkit.entity.Player;
    11. import org.bukkit.event.Listener;
    12. import org.bukkit.plugin.PluginDescriptionFile;
    13. import org.bukkit.plugin.java.JavaPlugin;
    14.  
    15. public final class HeadsUpDisplay extends JavaPlugin implements Listener {
    16. public static HeadsUpDisplay plugin;
    17. public final Logger log = Logger.getLogger("Minecraft");
    18. // The class ChatListener
    19. ChatListener cl = new ChatListener();
    20. // The class PrintScheduler
    21. Broadcast b = new Broadcast();
    22.  
    23. // The string entered into the config to be replaced with normal chat
    24. String cv = "$chat$";
    25. // The default server name
    26. String defaultServerName = "A Bukkit Server";
    27. // Whether or not the plugin will display the hud
    28. boolean enabled = true;
    29. // Name of the plugin, for simplicity's sake
    30. String pluginName = "HeadsUpDisplay";
    31. // Version of the plugin
    32. String pluginVersion;
    33. // Build of the plugin
    34. String pluginBuild;
    35. // Authors of the plugin
    36. List<String> pluginAuthors;
    37. // Player sender variable for chat
    38. Player p;
    39. // List of player messages, used for $chat$
    40. String[] pmsg;
    41. // Length of pmsg
    42. int l;
    43. // Chat messages to be displayed in place of cv
    44. String[] cmsg;
    45. // PluginDescriptionFile to get settings from plugin.yml
    46. PluginDescriptionFile pdf;
    47.  
    48. // Called when the plugin is disabled
    49. @Override
    50. public void onDisable() {
    51. enabled = false;
    52. this.saveDefaultConfig();
    53. // Prints to the console that the plugin is disabled
    54. pdf = this.getDescription();
    55. this.log.info(pdf.getName() + " is now disabled!");
    56. }
    57.  
    58. // Called when the plugin is enabled
    59. @Override
    60. public void onEnable() {
    61. enabled = getConfig().getBoolean("settings.enabled");
    62. this.getCommand("hud").setExecutor(this);
    63. getServer().getPluginManager().registerEvents(new ChatListener(), this);
    64. getConfig().options().copyDefaults(true);
    65. saveConfig();
    66.  
    67. // Starts the frontend Metrics
    68.  
    69. try {
    70. Metrics metrics = new Metrics(this);
    71. metrics.start();
    72. } catch (IOException e) { // Failed to submit the stats :-(
    73. log.severe("Error Submitting stats!");
    74. }
    75. }
    76.  
    77. public void migrate() {
    78. // Imports p and pmsg from ChatListener.java
    79. p = cl.p;
    80. pmsg = cl.pmsg;
    81. // The the length of pmsg
    82. l = pmsg.length;
    83. // The amount of times the while command has been called
    84. int call = 0;
    85. // While call is lesser or equal to l...
    86. while (call <= l && pmsg[call] != null) {
    87. // Builds the pmsg from the config settings, p and pmsg[call]
    88. pmsg[call] = getConfig().getString("settings.prefix") + " " + p
    89. + ": " + pmsg[call] + " "
    90. + getConfig().getString("settings.suffix");
    91. // Adds 1 to call to do the next index in the pmsg array
    92. call++;
    93. }
    94. // Calls format() once the building has been completed
    95. format();
    96. }
    97.  
    98. public void format() {
    99. // The the length of cmsg, should be 20 (0-19)
    100. l = cmsg.length;
    101. // Used for the while statements to format all of the array
    102. int call = 0;
    103. // Used for the while statements
    104. int varNum = 1;
    105. // While call is lesser or equal to l...
    106. while (call <= l && cmsg[call] != null) {
    107.  
    108. // While varNum is lesser or equal to 5...
    109. while (varNum <= 5 && cmsg[call] != null) {
    110. /*
    111.   * Replaces $custom_variable_varNum (1, 2, 3, 4 or 5) with the
    112.   * custom_variable_varNum from the config
    113.   */
    114. cmsg[call].replaceAll(
    115. "$custom_variable_" + varNum + "$",
    116. getConfig().getString(
    117. "settings.custom_variable_" + varNum++));
    118. }
    119. // Resets varNum to 1
    120. varNum = 1;
    121. // Adds 1 to call
    122. call++;
    123. }
    124. // calls print(), once the formating has been completed
    125. print();
    126. }
    127.  
    128. public void print() {
    129. // The the length of cmsg
    130. l = cmsg.length;
    131. int call = 0;
    132. while (call <= l && cmsg[call] != null)
    133. Bukkit.broadcastMessage(cmsg[call++]);
    134. }
    135.  
    136. // onCommand method called when a player types a command
    137. @Override
    138. public boolean onCommand(CommandSender sender, Command cmd,
    139. String commandLabel, String[] args) {
    140. // Turns the sender object into the player object as a Player instance
    141. // Player player = (Player) sender;
    142. // Start of if and else if branch
    143. if (commandLabel.equalsIgnoreCase("hud")) {
    144. log.info(cmd.getLabel());
    145. if (args[0].equalsIgnoreCase("start")) {
    146. enabled = true;
    147. Bukkit.getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    148. public void run() {
    149.  
    150. }
    151. }, 20, 20);
    152. log.info("Hud broadcasting enabled!");
    153. return true;
    154. // If args[0] equalsIngnoreCase, "stop"
    155. } else if (args[0].equalsIgnoreCase("stop")) {
    156. enabled = false;
    157. log.info("Hud broadcasting disabled!");
    158. return true;
    159. // If args[0] equalsIngnoreCase, "reload"
    160. } else if (args[0].equalsIgnoreCase("reload")) {
    161. // call onDisable() then onEnable()
    162. onDisable();
    163. onEnable();
    164. log.info(pdf.getName() + " is now enabled!");
    165. log.info(pdf.getName() + " was reloaded successfully!");
    166. return true;
    167. } else {
    168. /*
    169.   * sends the player the message "Incorrect command!" and returns
    170.   * false
    171.   */
    172. log.info("Incorrect command!");
    173. return false;
    174. }
    175. }
    176. return false;
    177. }
    178. }
    179.  


    ChatListener.java(Listener)
    Code:Java
    1. package me.ultrafirefx.headsupdisplay;
    2.  
    3. import java.util.logging.Logger;
    4.  
    5. import org.bukkit.entity.Player;
    6. import org.bukkit.event.EventHandler;
    7. import org.bukkit.event.Listener;
    8. import org.bukkit.event.player.AsyncPlayerChatEvent;
    9. import org.bukkit.plugin.java.JavaPlugin;
    10.  
    11. public class ChatListener extends JavaPlugin implements Listener {
    12. public static HeadsUpDisplay plugin;
    13. public final Logger log = Logger.getLogger("Minecraft");
    14. public HeadsUpDisplay hud = new HeadsUpDisplay();
    15. public Broadcast b = new Broadcast();
    16.  
    17. public Player p;
    18. public String[] pmsg;
    19. public int l;
    20.  
    21. public void HeadsUpDisplay(HeadsUpDisplay plugin) {
    22. ChatListener.plugin = plugin;
    23. plugin.getServer().getPluginManager().registerEvents(this, plugin);
    24. }
    25.  
    26. // Listens for the PlayerChatEvent...
    27. @EventHandler
    28. public void onPlayerChat(AsyncPlayerChatEvent chat) {
    29. p = chat.getPlayer();
    30. int l = pmsg.length;
    31. // Used for the while statements to format all of the array
    32. int call = 0;
    33. // While call is lesser than l...
    34. while (call < l && pmsg[call] != null) {
    35. /*
    36.   * set pmsg[call] as pmsg[call + 1] in doing so pushes all chat up 1
    37.   * to make room for new chat
    38.   */
    39. pmsg[call++] = pmsg[call];
    40. }
    41. // Sets pmsg[19] as the message just sent by a player
    42. pmsg[19] = chat.getMessage();
    43. // Calls the method migrate in the class HeadsUpDisplay
    44. hud.migrate();
    45. }
    46. }
    47.  


    Broadcaster.java(Broadcasts cmsg[0] to cmsg[19])
    Code:Java
    1. package me.ultrafirefx.headsupdisplay;
    2.  
    3. import org.bukkit.Bukkit;
    4. import org.bukkit.scheduler.BukkitRunnable;
    5.  
    6. public class Broadcast extends BukkitRunnable {
    7. HeadsUpDisplay hud = new HeadsUpDisplay();
    8. ChatListener cl = new ChatListener();
    9.  
    10. String[] pmsg = hud.pmsg;
    11. String[] cmsg = hud.cmsg;
    12.  
    13. public void run() {
    14. // The the length of cmsg
    15. int l = cmsg.length;
    16. int call = 0;
    17. int printedChat = 0;
    18. while (call <= l && cmsg[call] != null && pmsg[call] != null) {
    19. // if cmsg contains "$chat$", cmsg equals pmsg
    20. if (cmsg[call].contains("$chat$")) {
    21. cmsg[call] = pmsg[printedChat++];
    22. }
    23. // Broadcasts cmsg
    24. Bukkit.broadcastMessage(cmsg[call++]);
    25. }
    26. }
    27.  
    28. }
    29.  

    I might as well post my config.yml and plugin.yml so I will
    Config.yaml(Config)
    Code:YAML
    1. ## Default configuration for HeadsUpDisplay!
    2. ## Type '$chat$' to insert a player's chat message!
    3. ## Type $<variable name>$ to send the variable's value!
    4. ## Colour codes will NOT work yet, keep an eye out at
    5. ## [url]http://dev.bukkit.org/bukkit-plugins/headsupdisplay/[/url]
    6. ## to see when colour codes come out!
    7. ## Please do not change the version or the plugin may break when updated!
    8. ## By UltraFireFX!
    9. version:
    10. bukkit_version: '1.6.4'
    11. plugin_version: '0.5.0'
    12. plugin_build: 'db'
    13. settings:
    14. ## Plugin settings
    15. enabled: true
    16. server_name: 'a Bukkit server'
    17. custom_variable_1: '&eMojangster!'
    18. custom_variable_2: '&ePretty impressive!'
    19. custom_variable_3: '&eInfinitum!'
    20. custom_variable_4: '&eRun Steve, run!'
    21. custom_variable_5: '&2C&ar&4e&ae&2p&4e&2r&as &egonna creep!'
    22. ## Chat settings
    23. chatPrefix: '[HUD] '
    24. chatSuffix: ''
    25. playerPrefix: '[
    26. playerSuffix: ']:'
    27. ## Below is how chat is put together
    28. ## <chatPrefix> <playerPrefix>[Displayname]<playerSuffix> [playerMessage] <chatSuffix>
    29. ## <> Can be changed, [] cannot be changed
    30. ## (apart from the colour if no colour is specified e.g. No nickname)
    31. ## WARNING!! Until further notice, putting anthing
    32. ## other than $chat$ will NOT be displayed!
    33. hudList:
    34. line_1: '$custom_variable_4$'
    35. line_2: '$chat$'
    36. line_3: '$chat$'
    37. line_3: '$chat$'
    38. line_4: '$chat$'
    39. line_5: '$chat$'
    40. line_6: '$chat$'
    41. line_7: '$chat$'
    42. line_8: '$chat$'
    43. line_9: '$chat$'
    44. ## Above here is only seen if a player opens their chat log!
    45. line_10: '+------------------------------------------'
    46. line_11: '| &Welcome to $server_name$!'
    47. line_12: '| $custom_variable_5$
    48. line_13: '| Make sure you read the rules!'
    49. line_14: '| Checkout our website at $website$!'
    50. line_15: '+------------------------------------------'
    51. line_16: '$chat$'
    52. line_17: '$chat$'
    53. line_18: '$chat$'
    54. line_19: '$chat$'
    55. line_20: '$custom_variable_3$'
    56.  

    Plugin.yaml(Plugin information)
    Code:YAML
    1. name: HeadsUpDisplay
    2. main: me.ultrafirefx.headsupdisplay.HeadsUpDisplay
    3. version: 0.5.0
    4. author: UltraFireFX
    5. website: [url]http://dev.bukkit.org/bukkit-plugins/headsupdisplay/[/url]
    6. description: A HeadsUpDisplay for players on your server!
    7. database: false
    8. softdepend: [Vault]
    9.  
    10. commands:
    11. hud:
    12. description: 'Did you mean /help headsupdisplay?'
    13. children:
    14. start:
    15. description: Start displaying the HeadsUpDisplay!
    16. aliases: s
    17. permission: headsupdisplay.start
    18. permission-message: You do not have the permission "<permission>"!
    19. usage: Syntax error! Perhaps you meant /<command>?
    20. stop:
    21. description: Stop displaying the HeadsUpDisplay!
    22. aliases: st
    23. permission: headsupdisplay.stop
    24. permission-message: You do not have the permission "<permission>"!
    25. usage: Syntax error! Perhaps you meant /<command>?
    26. reload:
    27. description: Reloads the config!
    28. aliases: r
    29. permission: headsupdisplay.reload
    30. permission-message: You do not have the permission "<permission>"!
    31. usage: Syntax error! Perhaps you meant /<command>?
    32.  
    33. permissions:
    34. headsupdisplay.*:
    35. description: Gives access to all HeadsUpDisplay commands
    36. default: op
    37. children:
    38. headsupdisplay.start: true
    39. headsupdisplay.stop: true
    40. headsupdisplay.reload: true
    41. headsupdisplay.start:
    42. description: Allows you to start the hud
    43. default: op
    44. headsupdisplay.stop:
    45. description: Allows you to stop the hud
    46. default: op
    47. headsupdisplay.reload:
    48. description: Allows you to reload the config
    49. default: op
    50.  


    I probably have some really dumb error and I should kick myself for it but thats life :/

    Thanks in advance
    ~UltraFireFX
     
  2. Offline

    UltraFireFX

    BorisTheTerrible
    How do I get the stack trace, has that got to do with stackOverflows?
     
  3. Offline

    Cirno

    StackOverflowException happens when you recursivly call a method within the method or something along those lines of execution. Usually, it'll spam out which method is causing it,
    something like:
    at object.thing()
    at object.thing()
    at object.thing()
    at object.thing()
    at object.thing()
    at object.thing()
     
  4. Offline

    UltraFireFX

  5. Offline

    Cirno

    It should print in your console.
     
  6. Offline

    UltraFireFX

    @BorrisTheTerrible Cirno
    xD Forgot to post that file xD
    **Caution, lots o' spam!

    Server.txt
    Code:Text
    1. 2013-10-13 14:00:57 [INFO] Starting minecraft server version 1.6.4
    2. 2013-10-13 14:00:57 [INFO] Loading properties
    3. 2013-10-13 14:00:57 [INFO] Default game type: SURVIVAL
    4. 2013-10-13 14:00:57 [INFO] Generating keypair
    5. 2013-10-13 14:00:58 [INFO] Starting Minecraft server on *:25565
    6. 2013-10-13 14:00:58 [INFO] This server is running CraftBukkit version git-Bukkit-1.6.2-R1.0-6-g7d680d3 (MC: 1.6.4) (Implementing API version 1.6.4-R0.1-SNAPSHOT)
    7. 2013-10-13 14:00:59 [SEVERE] Could not load 'plugins\HeadsUpDisplay 1.6.4.jar' in folder 'plugins'
    8. org.bukkit.plugin.InvalidPluginException: java.lang.StackOverflowError
    9. at org.bukkit.plugin.java.JavaPluginLoader.loadPlugin(JavaPluginLoader.java:182)
    10. at org.bukkit.plugin.SimplePluginManager.loadPlugin(SimplePluginManager.java:305)
    11. at org.bukkit.plugin.SimplePluginManager.loadPlugins(SimplePluginManager.java:230)
    12. at org.bukkit.craftbukkit.v1_6_R3.CraftServer.loadPlugins(CraftServer.java:239)
    13. at org.bukkit.craftbukkit.v1_6_R3.CraftServer.<init>(CraftServer.java:217)
    14. at net.minecraft.server.v1_6_R3.PlayerList.<init>(PlayerList.java:56)
    15. at net.minecraft.server.v1_6_R3.DedicatedPlayerList.<init>(SourceFile:11)
    16. at net.minecraft.server.v1_6_R3.DedicatedServer.init(DedicatedServer.java:107)
    17. at net.minecraft.server.v1_6_R3.MinecraftServer.run(MinecraftServer.java:393)
    18. at net.minecraft.server.v1_6_R3.ThreadServerApplication.run(SourceFile:583)
    19. Caused by: java.lang.StackOverflowError
    20. at java.util.Hashtable.hash(Unknown Source)
    21. at java.util.Hashtable.get(Unknown Source)
    22. at java.util.logging.LogManager$LoggerContext.findLogger(Unknown Source)
    23. at java.util.logging.LogManager.getLogger(Unknown Source)
    24. at java.util.logging.LogManager.demandLogger(Unknown Source)
    25. at java.util.logging.Logger.demandLogger(Unknown Source)
    26. at java.util.logging.Logger.getLogger(Unknown Source)
    27. at me.ultrafirefx.headsupdisplay.HeadsUpDisplay.<init>(HeadsUpDisplay.java:17)
    28. at me.ultrafirefx.headsupdisplay.ChatListener.<init>(ChatListener.java:14)
    29. at me.ultrafirefx.headsupdisplay.HeadsUpDisplay.<init>(HeadsUpDisplay.java:19)
    30. at me.ultrafirefx.headsupdisplay.ChatListener.<init>(ChatListener.java:14)
    31. at me.ultrafirefx.headsupdisplay.HeadsUpDisplay.<init>(HeadsUpDisplay.java:19)
    32. at me.ultrafirefx.headsupdisplay.ChatListener.<init>(ChatListener.java:14)
    33.  
    34.  
    35. at me.ultrafirefx.headsupdisplay.ChatListener.<init>(ChatListener.java:14)
    36. at me.ultrafirefx.headsupdisplay.HeadsUpDisplay.<init>(HeadsUpDisplay.java:19)
    37. at me.ultrafirefx.headsupdisplay.ChatListener.<init>(ChatListener.java:14)
    38. at me.ultrafirefx.headsupdisplay.HeadsUpDisplay.<init>(HeadsUpDisplay.java:19)
    39. at me.ultrafirefx.headsupdisplay.ChatListener.<init>(ChatListener.java:14)
    40. at me.ultrafirefx.headsupdisplay.HeadsUpDisplay.<init>(HeadsUpDisplay.java:19)
    41. 2013-10-13 14:01:01 [INFO] Preparing level "world"
    42. 2013-10-13 14:01:02 [INFO] Preparing start region for level 0 (Seed: 4643229562016714079)
    43. 2013-10-13 14:01:03 [INFO] Preparing spawn area: 2%
    44. 2013-10-13 14:01:04 [INFO] Preparing spawn area: 12%
    45. 2013-10-13 14:01:05 [INFO] Preparing spawn area: 31%
    46. 2013-10-13 14:01:06 [INFO] Preparing spawn area: 46%
    47. 2013-10-13 14:01:07 [INFO] Preparing spawn area: 78%
    48. 2013-10-13 14:01:07 [INFO] Preparing start region for level 1 (Seed: 6454989566668296095)
    49. 2013-10-13 14:01:08 [INFO] Server permissions file permissions.yml is empty, ignoring it
    50. 2013-10-13 14:01:08 [INFO] Done (6.700s)! For help, type "help" or "?"
    51. 2013-10-13 14:46:25 [WARNING] Can't keep up! Did the system time change, or is the server overloaded?
    52. 2013-10-13 15:01:39 [WARNING] Can't keep up! Did the system time change, or is the server overloaded?
    53. 2013-10-13 15:12:09 [INFO] CONSOLE: Stopping the server..[m
    54. 2013-10-13 15:12:09 [INFO] Stopping server
    55. 2013-10-13 15:12:09 [INFO] Saving players
    56. 2013-10-13 15:12:09 [INFO] Saving worlds
    57. 2013-10-13 15:12:09 [INFO] Saving chunks for level 'world'/Overworld
    58. 2013-10-13 15:12:09 [WARNING] DSCT: socket closed
    59. 2013-10-13 15:12:09 [INFO] Closing listening thread
    60. 2013-10-13 15:12:16 [INFO] Saving chunks for level 'world_the_end'/The End
    61. 2013-10-13 15:12:17 [INFO] Stopping server
    62. 2013-10-13 15:12:17 [INFO] Saving players
    63. 2013-10-13 15:12:17 [INFO] Saving worlds
    64. 2013-10-13 15:12:17 [INFO] Saving chunks for level 'world'/Overworld
    65. 2013-10-13 15:12:17 [INFO] Saving chunks for level 'world_the_end'/The End
    66.  


    I cut out a few lines because it said "You cannot post a reply with more than 30000 characters" .-.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 4, 2016
  7. Offline

    Cirno

    I'll be honest; your variables are a mess.
    You're supposed to pass these variables into a constructor, not make a new one every time.What you're doing is this:
    Code:java
    1.  
    2. public SomeObject obj = new SomeObject();
    3. public ThisIsAConstructor(){}
    4.  

    when you should be doing:
    Code:java
    1.  
    2. public SomeObject obj;
    3. public ThisIsAConstructor(SomeObject obj){
    4. this.obj = obj;
    5. }
    6.  
     
  8. Offline

    cMan_

    You are correct. However, to be more specific, ultrafire you shouldn't be creating a new instance of your HeadsUpDisplay class. You should be preserving the instance through a constructor as cirno stated.
     
Thread Status:
Not open for further replies.

Share This Page