TownyAdvanced / MapTowny

A Towny add-on Bukkit plugin that enables towns to show up on a web-map.
MIT License
16 stars 17 forks source link

Prevent ruined towns from being rendered. #9

Closed AAigars closed 3 years ago

AAigars commented 3 years ago

Ruined towns would cause an NPE on the registerReplacements method due to the town not having a mayor, this PR fixes the issue by just ignoring any towns which are ruined.

Stacktrace of the error:

[05:12:09] [Server thread/WARN]: [Pl3xMap-Towny] Task #109 for Pl3xMap-Towny v1.0.0-ALPHA-2 generated an exception
java.lang.NullPointerException: null
    at me.silverwolfg11.pl3xmaptowny.managers.TownInfoManager.lambda$registerReplacements$0(TownInfoManager.java:104) ~[?:?]
    at me.silverwolfg11.pl3xmaptowny.managers.TownInfoManager.getWindowHTML(TownInfoManager.java:241) ~[?:?]
    at me.silverwolfg11.pl3xmaptowny.managers.TownInfoManager.getClickTooltip(TownInfoManager.java:228) ~[?:?]
    at me.silverwolfg11.pl3xmaptowny.managers.TownyLayerManager.buildTownEntry(TownyLayerManager.java:135) ~[?:?]
    at me.silverwolfg11.pl3xmaptowny.tasks.RenderTownsTask.run(RenderTownsTask.java:53) ~[?:?]
    at org.bukkit.craftbukkit.v1_16_R3.scheduler.CraftTask.run(CraftTask.java:100) ~[patched_1.16.5.jar:git-Airplane-"813df1a"]
    at org.bukkit.craftbukkit.v1_16_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:468) ~[patched_1.16.5.jar:git-Airplane-"813df1a"]
    at net.minecraft.server.v1_16_R3.MinecraftServer.w(MinecraftServer.java:1079) ~[patched_1.16.5.jar:git-Airplane-"813df1a"]
    at net.minecraft.server.v1_16_R3.MinecraftServer.lambda$a$0(MinecraftServer.java:291) ~[patched_1.16.5.jar:git-Airplane-"813df1a"]
    at java.lang.Thread.run(Thread.java:834) [?:?]
silverwolfg11 commented 3 years ago

Huzzah! I didn't realize ruined towns intentionally had no mayor, good catch! I think the PR is a good enough solution for right now. Maybe in the near future, I'll add ruin checks to the replacements themselves and also a config option to render ruined towns.

Thank you for your contribution! Before I can merge it though, I just need any confirmation that you're fine with releasing the code you're contributing under the MIT license (I'll make a PR template in the future that has this confirmation in it).

AAigars commented 3 years ago

No problem :) I am fine for the code to be released under the MIT license.