String replaceall not working with string "[TEST]"

Discussion in 'Plugin Development' started by SoThatsIt, Aug 4, 2013.

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

    SoThatsIt

    i am making a chat plugin that adds different channels. to set how you want the message formatted you use things in strings like [NAME] or [FACTION] although when i try to replace it i get this error.

    Code:
    [SEVERE] Could not pass event AsyncPlayerChatEvent to LGChat v0.1
    org.bukkit.event.EventException
    >      at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:427)
    >      at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62)
    >      at org.bukkit.plugin.TimedRegisteredListener.callEvent(TimedRegisteredListener.java:30)
    >      at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:478)
    >      at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:460)
    >      at net.minecraft.server.v1_6_R1.PlayerConnection.chat(PlayerConnection.java:916)
    >      at net.minecraft.server.v1_6_R1.PlayerConnection.a(PlayerConnection.java:858)
    >      at net.minecraft.server.v1_6_R1.Packet3Chat.handle(SourceFile:49)
    >      at org.spigotmc.netty.NettyNetworkManager$2.run(NettyNetworkManager.java:134)
    >      at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:471)
    >      at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:334)
    >      at java.util.concurrent.FutureTask.run(FutureTask.java:166)
    >      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    >      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    >      at java.lang.Thread.run(Thread.java:722)
    Caused by: java.lang.NullPointerException
    >      at java.util.regex.Matcher.appendReplacement(Matcher.java:758)
    >      at java.util.regex.Matcher.replaceAll(Matcher.java:906)
    >      at java.lang.String.replaceAll(String.java:2162)
    >      at me.sothatsit.lgchat.config.Channel.sendMessage(Channel.java:67)
    >      at me.sothatsit.lgchat.config.Channel.sendMessage(Channel.java:61)
    >      at me.sothatsit.lgchat.LGChat.onPlayerChat(LGChat.java:131)
    >      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    >      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    >      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    >      at java.lang.reflect.Method.invoke(Method.java:601)
    >      at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:425)
    the error occurs at this line:
    Code:
    message = message.replaceAll("[MESSAGE]", rawmessage);
     
  2. Offline

    thecrystalflame

    well it looks as if rawmessage is possibly null?
     
  3. Offline

    SoThatsIt

    if this is true "e.getMessage()" is returning null where e is the AsyncPlayerChatEvent method
     
  4. Offline

    thecrystalflame

    try doing a printline of e.getMessage() to check
     
  5. Offline

    SoThatsIt

    nope, its not null
     
  6. Offline

    Hoolean

  7. Offline

    SoThatsIt

    i tested both message and rawmessage and neither are null.
     
  8. Offline

    tommycake50

    [ and ] are metacharacters in regular expressions, try
    Code:
    this message = message.replaceAll("\[MESSAGE\]", rawmessage);[/code
    EDIT: although im not sure how that would cause an NPE
     
  9. Offline

    SoThatsIt

    when i do this it gives me an error in eclipse. i have tried \\ the brackets, did not work still got error, i tried putting ^ as the first character in the brackets, i tried \\ all the characters didnt work.
     
  10. Offline

    the_ceed

    Can you explain why you even need to replace these?
     
  11. Offline

    tommycake50

    why not just use % signs like every other plugin?
     
  12. Offline

    nisovin

    You should probably use .replace() rather than .replaceAll(), since you don't need regular expressions.
     
Thread Status:
Not open for further replies.

Share This Page