Solved Chat Mention Help!

Discussion in 'Spigot Plugin Development' started by SneakyBruh, Sep 14, 2017.

Thread Status:
Not open for further replies.
  1. I am making a plugin with a feature of a ping sound when your name is written in chat. I also wanted this to be turned on and off via console but i keep getting this error in console!

    Code (Text):
    at me.Sneaky.BroadCast.Chat.onMention( ~[?:?]
    Chat Code:
    Code (Text):

    package me.Sneaky.BroadCast;

    import org.bukkit.Bukkit;
    import org.bukkit.ChatColor;
    import org.bukkit.Instrument;
    import org.bukkit.Note;
    import org.bukkit.Note.Tone;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;

    public class Chat implements Listener {
        private Main main;
        public Chat(Main main) {
        this.main = main;
        public void onMention(AsyncPlayerChatEvent event) {
            Boolean isEnabled = main.getConfig().getBoolean("Sound-On-Mention");
          for (Player player : event.getPlayer().getWorld().getPlayers()) {
              if(player == event.getPlayer())continue;
            event.setMessage(event.getMessage().replaceAll(player.getName(), ChatColor.GREEN+"@"+player.getName()+ChatColor.RESET + ""));
            player.playNote(player.getLocation(), Instrument.PIANO, Note.natural(1, Tone.A));
              else {
                  String message = event.getMessage();
  2. you used a tutorial dintya,
    Code (Text):
    best if statement
    Code (Text):
    just..... why are you broadcasting a chat message (you should be getting 2 messages because of this unless you cancel the event)? also ur code is messy.
  3. Just dont worry about the other code :(. i just need this to work please
  4. If you're getting an error you paste the whole error not a single line, also use the primitive type of boolean ot the wrapper class, also this won't work if the player isn't on the same world hope you know that, you could instead simply use the method provided by the own event to get all the players that are going to see the message 'AsyncPlayerChatEvent#getRecipients()'. Also broadcasting the message for every player doesn't make any sense, you're not cancelling the event neither removing any recipient so the players still would see the message, also don't use the method 'String#replaceAll(String, String)' if you're not using regex, use instead 'String#replace(String, String)'. Also you're changing the format each time, so if the message contains the name of 2 players the format will only work for the last player.
  5. Code (Text):

    Could not pass event AsyncPlayerChatEvent


    at$1.execute( ~[spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.plugin.RegisteredListener.callEvent( ~[spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.plugin.SimplePluginManager.fireEvent( [spigot.jar:git-Spigot-db6de12-18fbb24]

    at org.bukkit.plugin.SimplePluginManager.callEvent( [spigot.jar:git-Spigot-db6de12-18fbb24]

    at [spigot.jar:git-Spigot-db6de12-18fbb24]

    at net.minecraft.server.v1_8_R3.PlayerConnection.a( [spigot.jar:git-Spigot-db6de12-18fbb24]

    at net.minecraft.server.v1_8_R3.PacketPlayInChat$ [spigot.jar:git-Spigot-db6de12-18fbb24]

    at java.util.concurrent.Executors$ [?:1.8.0_141]

    at [?:1.8.0_141]

    at java.util.concurrent.ThreadPoolExecutor.runWorker( [?:1.8.0_141]

    at java.util.concurrent.ThreadPoolExecutor$ [?:1.8.0_141]

    at [?:1.8.0_141]

    Caused by: java.lang.NullPointerException

    at me.Sneaky.BroadCast.Chat.onMention( ~[?:?]

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_141]

    at sun.reflect.NativeMethodAccessorImpl.invoke( ~[?:1.8.0_141]

    at sun.reflect.DelegatingMethodAccessorImpl.invoke( ~[?:1.8.0_141]

    at java.lang.reflect.Method.invoke( ~[?:1.8.0_141]

    at$1.execute( ~[spigot.jar:git-Spigot-db6de12-18fbb24]

    ... 11 more
    Im fixing the other shit.... its just im kinda new to this. You are probably cringing at it
  6. Does your config actually contain Sound-On-Mention? (Based on copy&pasting to Notepad++, line 24 is):
    Code (Text):
    Boolean isEnabled = main.getConfig().getBoolean("Sound-On-Mention");
    So, either you don't have that in the config, or you don't have a config at all. Also, the if statement below it needs to be fixed.
    • Agree Agree x 1
  7. Everything in the config works except the boolean. and yes i fixed the if statement :p
    Code (Text):

    # Prefix used in the broadcast message.
     Prefix: '&8[&cAlert&8]'

    # Prefix used for staff chat.
     Staff-Prefix: '&8[&c&lStaff Alert&8]'

    # Message a player receives when attempting a command with incorrect permissions.
     No-Permission: '&c&lAlert > &7Sorry! You do not have the correct permissions!'

    # Message a player recieves when using the incorrect syntax.
     Usage: '&c&lAlert > &7Please use the correct syntax! /command [message]'

    # Message sent to notify player if the config reloaded properly.
     Reload: '&c&lAlert > &7Successfully reloaded config!'

     # Sound when name written in chat
     Sound-On-Mention: true
  8. But is the value actually in the config ? I mean is the config being properly generated ? Also print out the config keys/value to see if it's properly loaded.
  9. dw i got it working :)
Thread Status:
Not open for further replies.

Share This Page