Solved Holographic Displays.... got an error, out of ideas

Discussion in 'Plugin Development' started by Dealyise, Nov 15, 2014.

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

    Dealyise

    So, basically it worked few days ago. I did not made any changes to it (at least I can't remember). Now, it throws me an error while enabling my plugin. Even when I call my function when player is joining, it does not show up the holos. I am really out of ideas, tried quite everything.

    My class, where the function is:
    Show Spoiler
    Code:java
    1. public static de.crimezone.main.CZ plugin;
    2.  
    3. public static void reloadHolos(World world){
    4. try{
    5. for (Hologram hologram : HolographicDisplaysAPI.getHolograms(plugin)) {
    6. hologram.delete();
    7. }
    8. }catch(Exception ex){
    9. ex.printStackTrace();
    10. }
    11. Location loc3 = new Location(world, 2565.398237784228,83,1486.0395828304186);
    12. HolographicDisplaysAPI.createHologram(plugin, loc3, "§f[§6Bank§f]", "Drücke SHIFT, um die Bank zu betreten");
    13. File folder = new File("plugins/System/Locations/");
    14. File[] listOfFiles = folder.listFiles();
    15. for(File file : listOfFiles){
    16. FileConfiguration cfg = YamlConfiguration.loadConfiguration(file);
    17. Location loc = new Location(world,cfg.getInt("Location.x"),cfg.getInt("Location.y") + 2,cfg.getInt("Location.z"));
    18. System.out.println("Ergebnis von Plugin: " + plugin + " und die Loc lautet: " + loc + ".");
    19. Location loc2 = new Location(world,cfg.getInt("Location.x2"),cfg.getInt("Location.y2") + 2,cfg.getInt("Location.z2"));
    20. System.out.println("Ergebnis von Plugin2: " + plugin + " und die Loc2 lautet: " + loc2 + ".");
    21.  
    22. String type = cfg.getString("Location.type");
    23. System.out.println(type);
    24. switch(type){
    25. case "waffenladen":
    26. HolographicDisplaysAPI.createHologram(plugin, loc, "§f[§cWaffenladen§f]", "Drücke SHIFT, um den Laden zu betreten");
    27. HolographicDisplaysAPI.createHologram(plugin, loc2, "Drücke SHIFT, um den Laden zu verlassen");
    28. break;
    29. case "tankstelle":
    30. HolographicDisplaysAPI.createHologram(plugin, loc, "§f[§aTankstelle§f]", "Drücke SHIFT, um den Laden zu betreten");
    31. HolographicDisplaysAPI.createHologram(plugin, loc2, "Drücke SHIFT, um den Laden zu verlassen");
    32. break;
    33. case "laden":
    34. HolographicDisplaysAPI.createHologram(plugin, loc, "§f[§eZoneShop§f]", "Drücke SHIFT, um den Laden zu betreten");
    35. HolographicDisplaysAPI.createHologram(plugin, loc2, "Drücke SHIFT, um den Laden zu verlassen");
    36. break;
    37. case "burgerlord":
    38. HolographicDisplaysAPI.createHologram(plugin, loc, "§f[§bBurger Lord§f]", "Drücke SHIFT, um den Laden zu betreten");
    39. HolographicDisplaysAPI.createHologram(plugin, loc2, "Drücke SHIFT, um den Laden zu verlassen");
    40. break;
    41. }
    42. }
    43. }


    Class, where I use it:
    Show Spoiler
    Code:java
    1. private static Plugin SYS;
    2.  
    3. public BankClass(Plugin plugin){
    4. SYS = plugin;
    5.  
    6. injectEvents();
    7. injectHolos();
    8. @SuppressWarnings("unused")
    9. BankStatus bs = new BankStatus();
    10. @SuppressWarnings("unused")
    11. BankData bd = new BankData(SYS);
    12. }
    13.  
    14. static void injectEvents(){
    15. SYS.getServer().getPluginManager().registerEvents(new BankEvent(), SYS);
    16. }
    17.  
    18. static void injectHolos(){
    19. Team.reloadHolos(User.plugin.getServer().getWorld("czwelt"));
    20. }
    21.  
    22. static void injectThread(){
    23.  
    24. }
    25.  
    26. static void injectAsync(){
    27.  
    28. }
    29.  
    30. public static Plugin getSystem(){
    31. return SYS;
    32. }


    And last but not least, the main class where I am calling the function:
    Show Spoiler
    Code:java
    1. Team.plugin = this;
    2.  
    3. @SuppressWarnings("unused")
    4. BankClass bc = new BankClass(this);


    The following error says that this line:
    Code:java
    1. HolographicDisplaysAPI.createHologram(plugin, loc, "§f[§cWaffenladen§f]", "Drücke SHIFT, um den Laden zu betreten");

    causes a NPE, but I still don't know why.

    Complete error:
    Show Spoiler
    Code:
    [18:18:54] [Server thread/INFO]: @@@[System] Loading Locations...
    [18:18:54] [Server thread/ERROR]: Error occurred while enabling CrimeZoneSystem v0.2.1 (Is it up to date?)
    java.lang.NullPointerException
        at com.gmail.filoghost.holograms.object.pieces.HologramLine.spawn(HologramLine.java:32) ~[?:?]
        at com.gmail.filoghost.holograms.object.APICraftHologram.forceUpdate(APICraftHologram.java:73) ~[?:?]
        at com.gmail.filoghost.holograms.object.CraftHologram.update(CraftHologram.java:113) ~[?:?]
        at com.gmail.filoghost.holograms.api.HolographicDisplaysAPI.createHologram(HolographicDisplaysAPI.java:47) ~[?:?]
        at de.crimezone.main.functions.Team.reloadHolos(Team.java:77) ~[?:?]
        at de.crimezone.main.bank.BankClass.injectHolos(BankClass.java:27) ~[?:?]
        at de.crimezone.main.bank.BankClass.<init>(BankClass.java:15) ~[?:?]
        at de.crimezone.main.CZ.onEnable(CZ.java:150) ~[?:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) ~[srv.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:324) [srv.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:404) [srv.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.loadPlugin(CraftServer.java:446) [srv.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at org.bukkit.craftbukkit.v1_7_R3.CraftServer.enablePlugins(CraftServer.java:380) [srv.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.n(MinecraftServer.java:352) [srv.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.g(MinecraftServer.java:326) [srv.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.a(MinecraftServer.java:282) [srv.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.DedicatedServer.init(DedicatedServer.java:182) [srv.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.MinecraftServer.run(MinecraftServer.java:436) [srv.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]
        at net.minecraft.server.v1_7_R3.ThreadServerApplication.run(SourceFile:628) [srv.jar:git-Bukkit-1.7.9-R0.1-10-g8688bd4-b3092jnks]


    Please guys, help me out, I'm stuck at this one.

    greetz.
     
  2. Offline

    Skionz

    Post your entire class.
     
  3. Offline

    Dealyise

  4. Offline

    Skionz

  5. Offline

    Dealyise

    Skionz
    Code:java
    1. package de.crimezone.main;
    2.  
    3. import java.io.File;
    4. import java.io.IOException;
    5. import java.util.logging.Logger;
    6.  
    7. import org.bukkit.Location;
    8. import org.bukkit.WorldCreator;
    9. import org.bukkit.configuration.file.FileConfiguration;
    10. import org.bukkit.configuration.file.YamlConfiguration;
    11. import org.bukkit.entity.Player;
    12. import org.bukkit.plugin.java.JavaPlugin;
    13.  
    14.  
    15.  
    16.  
    17.  
    18.  
    19.  
    20.  
    21. import de.crimezone.main.bank.BankClass;
    22. import de.crimezone.main.commands.AcceptTicketCommand;
    23. import de.crimezone.main.commands.AddLocalPrefixCommand;
    24. import de.crimezone.main.commands.AdminSpawnCommand;
    25. import de.crimezone.main.commands.AllCommand;
    26. import de.crimezone.main.commands.ArrestCommand;
    27. import de.crimezone.main.commands.BanCommand;
    28. import de.crimezone.main.commands.BanSystemCommand;
    29. import de.crimezone.main.commands.ChatGang;
    30. import de.crimezone.main.commands.ChatTeam;
    31. import de.crimezone.main.commands.CloseTicketCommand;
    32. import de.crimezone.main.commands.CreateLocationCommand;
    33. import de.crimezone.main.commands.CreateWorldCommand;
    34. import de.crimezone.main.commands.DeclineTicketCommand;
    35. import de.crimezone.main.commands.GangCommand;
    36. import de.crimezone.main.commands.GangMoneyCommand;
    37. import de.crimezone.main.commands.GangPay;
    38. import de.crimezone.main.commands.GangTake;
    39. import de.crimezone.main.commands.GiveUpCommand;
    40. import de.crimezone.main.commands.HelpCommand;
    41. import de.crimezone.main.commands.InfoCommand;
    42. import de.crimezone.main.commands.KickPlayerCommand;
    43. import de.crimezone.main.commands.LoginCommand;
    44. import de.crimezone.main.commands.MakeAdminCommand;
    45. import de.crimezone.main.commands.MoneyCommand;
    46. import de.crimezone.main.commands.MuteCommand;
    47. import de.crimezone.main.commands.PNCommand;
    48. import de.crimezone.main.commands.PayCommand;
    49. import de.crimezone.main.commands.PaydayCommand;
    50. import de.crimezone.main.commands.RadioChat;
    51. import de.crimezone.main.commands.ReclassCommand;
    52. import de.crimezone.main.commands.RegisterCommand;
    53. import de.crimezone.main.commands.RemoveEntitiesCommand;
    54. import de.crimezone.main.commands.ReplyCommand;
    55. import de.crimezone.main.commands.RobCommand;
    56. import de.crimezone.main.commands.SaveExitCommand;
    57. import de.crimezone.main.commands.StatsCommand;
    58. import de.crimezone.main.commands.SupportCommand;
    59. import de.crimezone.main.commands.SwitchWorldCommand;
    60. import de.crimezone.main.commands.TPSCommand;
    61. import de.crimezone.main.commands.TempBanCommand;
    62. import de.crimezone.main.commands.TicketCommand;
    63. import de.crimezone.main.commands.ToggleCommand;
    64. import de.crimezone.main.commands.TpCommand;
    65. import de.crimezone.main.commands.TphereCommand;
    66. import de.crimezone.main.commands.UnmuteCommand;
    67. import de.crimezone.main.commands.WartungCommand;
    68. import de.crimezone.main.config.DataModifier;
    69. import de.crimezone.main.events.EXPListener;
    70. import de.crimezone.main.events.PlayerJoin;
    71. import de.crimezone.main.events.PlayerEvents;
    72. import de.crimezone.main.events.SignHandle;
    73. import de.crimezone.main.events.WepListener;
    74. import de.crimezone.main.functions.API;
    75. import de.crimezone.main.functions.AutoRespawn;
    76. import de.crimezone.main.functions.Status;
    77. import de.crimezone.main.functions.Team;
    78. import de.crimezone.main.functions.User;
    79. import de.crimezone.main.functions.Weapon;
    80. import de.crimezone.main.maintenance.Wartung;
    81. import de.crimezone.main.support.Support;
    82. import de.crimezone.main.tasks.paydayFunc;
    83. import de.crimezone.main.tasks.scoreboardTimer;
    84. import de.crimezone.main.tasks.timeRunner;
    85.  
    86. import org.json.JSONObject;
    87.  
    88. import com.gmail.filoghost.holograms.api.Hologram;
    89. import com.gmail.filoghost.holograms.api.HolographicDisplaysAPI;
    90.  
    91.  
    92. public class CZ extends JavaPlugin {
    93.  
    94. /* CrimeZone - Der deutsche #1 Cops and Robbers Server
    95.   *
    96.   * Coded by Temphis (Dennis Fichte) | All Rights reserved (C) 2014
    97.   *
    98.   */
    99. public static Logger log = Logger.getLogger("Minecraft");
    100. public Boolean protocolLib = false;
    101. public Object protocolManager = null;
    102.  
    103. public String plVersion = this.getDescription().getVersion();
    104.  
    105. //Spawn Zivilisten: x = 2497.60897 | y = 72.000 | z = 1671.46615 | f = -0.061125055
    106. //Zeilen insgesamt: 2897 | Stand: 19.05.2014 22:09
    107. //Zeilen seit 03.06.2014: 4152 | Stand: 15:43
    108. //Zeilen seit 13.07.2014: 6615 | Stand: 11:20
    109. @Override
    110. public void onEnable() {
    111.  
    112.  
    113. //Registriere die Klassen
    114. new AutoRespawn(this);
    115. java.lang.System.out.println("@@@[System] Init Classes...");
    116.  
    117. //lade Welten
    118.  
    119. getServer().createWorld(new WorldCreator("bauwelt"));
    120. getServer().createWorld(new WorldCreator("stadt"));
    121. java.lang.System.out.println("@@@[System] Loading Worlds...");
    122.  
    123. // Sage Klassen das System die MainPlugin ist
    124.  
    125. User.plugin = this;
    126. Weapon.plugin = this;
    127. WepListener.plugin = this;
    128. scoreboardTimer.plugin = this;
    129. RegisterCommand.plugin = this;
    130. LoginCommand.plugin = this;
    131. PlayerJoin.plugin = this;
    132. EXPListener.plugin = this;
    133. timeRunner.plugin = this;
    134. paydayFunc.plugin = this;
    135. Team.plugin = this;
    136. Support.plugin = this;
    137.  
    138. java.lang.System.out.println("@@@[System] Init Subclasses...");
    139.  
    140. //Reset der Settings
    141. java.lang.System.out.println("@@@[System] Reset Settings...");
    142. DataModifier.resetToggle();
    143.  
    144. //Laden der L§den (Locations)
    145. DataModifier.getLocations();
    146. java.lang.System.out.println("@@@[System] Loading Locations...");
    147.  
    148. //Injektion der Bank
    149. @SuppressWarnings("unused")
    150. BankClass bc = new BankClass(this);
    151.  
    152.  
    153. //Starte Tasks
    154. timeRunner.startTask();
    155. scoreboardTimer.startTask();
    156. paydayFunc.startTask();
    157. java.lang.System.out.println("@@@[System] Init Tasks...");
    158.  
    159. // Alle Listener registrieren
    160. java.lang.System.out.println("@@@[System] Init Listeners...");
    161. User.register(new PlayerJoin(), this);
    162. User.register(new PlayerEvents(), this);
    163. User.register(new SignHandle(), this);
    164. User.register(new EXPListener(), this);
    165. User.register(new WepListener(), this);
    166.  
    167.  
    168. // Alle Befehle registrieren
    169. java.lang.System.out.println("@@@[System] Register Commands...");
    170. User.command(new LoginCommand(), "login");
    171. User.command(new RegisterCommand(), "register");
    172. User.command(new HelpCommand(), "help");
    173. User.command(new ReclassCommand(), "reclass");
    174. User.command(new GangCommand(), "gang");
    175. User.command(new ChatGang(), "g");
    176. User.command(new GangPay(), "gpay");
    177. User.command(new GangTake(), "gtake");
    178. User.command(new MoneyCommand(), "money");
    179. User.command(new GangMoneyCommand(), "gmoney");
    180. User.command(new RobCommand(), "rob");
    181. User.command(new PNCommand(), "pn");
    182. User.command(new ReplyCommand(), "r");
    183. User.command(new AllCommand(), "all");
    184. User.command(new StatsCommand(), "stats");
    185. User.command(new RadioChat(), "d");
    186. User.command(new PayCommand(), "pay");
    187. User.command(new TpCommand(), "tp");
    188. User.command(new TphereCommand(), "tphere");
    189. User.command(new TicketCommand(), "ticket");
    190. User.command(new GiveUpCommand(), "giveup");
    191. User.command(new ArrestCommand(), "arrest");
    192. User.command(new TPSCommand(), "tps");
    193. User.command(new PaydayCommand(), "payday");
    194. User.command(new MakeAdminCommand(), "makeadmin");
    195. User.command(new ChatTeam(), "t");
    196. User.command(new BanCommand(), "ban");
    197. User.command(new BanSystemCommand(), "bansystem");
    198. User.command(new TempBanCommand(), "tempban");
    199. User.command(new KickPlayerCommand(), "kick");
    200. User.command(new MuteCommand(), "mute");
    201. User.command(new UnmuteCommand(), "unmute");
    202. User.command(new ToggleCommand(), "toggle");
    203. User.command(new SwitchWorldCommand(), "tpworld");
    204. User.command(new CreateWorldCommand(), "createworld");
    205. User.command(new RemoveEntitiesCommand(), "clear");
    206. User.command(new CreateLocationCommand(), "createloc");
    207. User.command(new SaveExitCommand(), "saveexit");
    208. User.command(new WartungCommand(), "wartung");
    209. User.command(new InfoCommand(), "shout");
    210. User.command(new SupportCommand(), "sup");
    211. User.command(new AcceptTicketCommand(), "accepttc");
    212. User.command(new DeclineTicketCommand(), "declinetc");
    213. User.command(new AdminSpawnCommand(), "aspawn");
    214. User.command(new CloseTicketCommand(), "closetc");
    215. User.command(new AddLocalPrefixCommand(), "makelocal");
    216. User.command(new TestCommand(), "rcontest");
    217.  
    218. //Server Status Abfrage
    219. switch(Status.getStatus()){
    220. case 0:
    221. //Ist offline, muss online gesetzt werden
    222. Wartung.setOnline();
    223. break;
    224. case 2:
    225. //Wartung komplett aktivieren
    226. Wartung.isMaintenance = true;
    227. break;
    228. }
    229. java.lang.System.out.println("@@@[System] Updating Server Status...");
    230.  
    231.  
    232. //ende
    233. log.info("@@@[CrimeZoneSystem] v" + plVersion + " erfolgreich geladen!");
    234.  
    235. }
    236.  
    237. @Override
    238. public void onDisable(){
    239. //Logge alle Spieler aus
    240.  
    241. try {
    242. JSONObject r = API.logoutAll();
    243. String count_datensatz = (String) r.get("return");
    244. log.info("@@@[CrimeZoneSystem] v" + plVersion + " Info: " + count_datensatz);
    245. } catch (IOException e) {
    246. e.printStackTrace();
    247. }
    248. log.info("@@@[CrimeZoneSystem] v" + plVersion + " alle Spieler ausgeloggt");
    249. //Speichere alle Spielerkonten
    250. for(Player p : getServer().getOnlinePlayers()){
    251. DataModifier.updatePlayerData(p);
    252. }
    253. log.info("@@@[CrimeZoneSystem] v" + plVersion + " alle Spieler geupdated");
    254. //L§sche den PalyerData Cache
    255. for(Player p : getServer().getOnlinePlayers()){
    256. DataModifier.deleteFile(p);
    257. }
    258. log.info("@@@[CrimeZoneSystem] v" + plVersion + " Spieler Cache geleert");
    259. //L§sche den Locations Cache
    260. DataModifier.deleteLocations();
    261. //Schalte Schedular aus
    262. try{
    263. PlayerJoin.endTask();
    264. timeRunner.endTask();
    265. scoreboardTimer.endTask();
    266. paydayFunc.endTask();
    267. }catch(Exception ex){
    268.  
    269. }
    270.  
    271. //Server Status Abfrage
    272. switch(Status.getStatus()){
    273. case 1:
    274. //Ist online, muss offline gesetzt werden
    275. Wartung.setOffline();
    276. break;
    277. }
    278. java.lang.System.out.println("@@@[System] Updating Server Status...");
    279.  
    280.  
    281.  
    282. }
    283.  
    284.  
    285. }


    Alright, I fixed it.
    The error was simple:
    The world got a bit bigger, so, Bukkit needed longer to load it. While loading the map, my Plugin wanted to spawn the holos. But he couldn't , because Bukkit returns null when a map is not loaded. I removed the function from onEnable and added it somewhere else and voila, it works. Simple as that.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 13, 2016
Thread Status:
Not open for further replies.

Share This Page