Solved Font width null exception

Discussion in 'Plugin Development' started by Limeth, Jun 26, 2013.

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

    Limeth

    I'm editing my motd in ServerListPingEvent like so:

    motd
    Code:text
    1. \u00A75\u00BB\u00A7d\u00A7lBreakpoint\u00A75\u00AB \u00A78[\u00A7c%RED%\u00A78\:\u00A79%BLUE%\u00A78] [\u00A7e%TIME%\u00A78]\u00A7e

    without colors, readable by the human kind:
    Code:text
    1. »Breakpoint« [%RED%:%BLUE%] [%TIME%]


    source
    Code:java
    1. @EventHandler
    2. public void onServerPing(ServerListPingEvent event) {
    3.  
    4. String motd = event.getMotd();
    5. String curMap = "randomMapName";
    6. int[] teams = new int[] {3, 2};
    7. String time = "09:13";
    8.  
    9. motd = motd.replace("%TIME%", time);
    10. motd = motd.replace("%RED%", Integer.toString(teams[0]));
    11. motd = motd.replace("%BLUE%", Integer.toString(teams[1]));
    12.  
    13. int motdWidth = 241 - MinecraftFont.Font.getWidth(motd);
    14. int spaceAmount = (int) (34 - (((double) motdWidth) / ((double) spaceWidth)));
    15. String spaces = "";
    16.  
    17. for(int i = 0; i < spaceAmount; i++)
    18. spaces += " ";
    19.  
    20. event.setMotd(motd + spaces + curMap);
    21.  
    22. }


    And I'm getting this error:

    error
    Code:text
    1. 21:10:35 [SEVERE] Could not pass event ServerListPingEvent to Breakpoint v1.2.0.3
    2. org.bukkit.event.EventException
    3. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    4. at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    5. at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30)
    6. at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:478)
    7. at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:463)
    8. at org.bukkit.craftbukkit.v1_5_R3.event.CraftEventFactory.callServerListPingEvent(CraftEventFactory.java:362)
    9. at net.minecraft.server.v1_5_R3.PendingConnection.a(PendingConnection.java:152)
    10. at net.minecraft.server.v1_5_R3.Packet254GetInfo.handle(SourceFile:23)
    11. at org.spigotmc.netty.NettyNetworkManager.b(NettyNetworkManager.java:218)
    12. at net.minecraft.server.v1_5_R3.PendingConnection.c(PendingConnection.java:55)
    13. at org.spigotmc.MultiplexingServerConnection.b(MultiplexingServerConnection.java:77)
    14. at net.minecraft.server.v1_5_R3.MinecraftServer.r(MinecraftServer.java:583)
    15. at net.minecraft.server.v1_5_R3.DedicatedServer.r(DedicatedServer.java:227)
    16. at net.minecraft.server.v1_5_R3.MinecraftServer.q(MinecraftServer.java:472)
    17. at net.minecraft.server.v1_5_R3.MinecraftServer.run(MinecraftServer.java:404)
    18. at net.minecraft.server.v1_5_R3.ThreadServerApplication.run(SourceFile:573)
    19. Caused by: java.lang.NullPointerException
    20. at org.bukkit.map.MapFont.getWidth(MapFont.java:55)
    21. at cz.projectsurvive.me.limeth.listeners.PlayerConnectionListener.onServerPing(PlayerConnectionListener.java:124)
    22. at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    23. at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    24. at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    25. at java.lang.reflect.Method.invoke(Method.java:601)
    26. at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    27. ... 15 more


    Thank you for any help. :)
    Also, if this helps... http://jd.bukkit.org/rb/doxygen/d2/d97/MapFont_8java_source.html

    After long testing, I've found out, that it doesn't like colors...
    Fixed:
    Code:text
    1. int motdWidth = 241 - MinecraftFont.Font.getWidth(ChatColor.stripColor(motd));


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

Share This Page