1.16.5 Bukkit.broadcastMessage() causes NullPointerException

Discussion in 'Spigot Plugin Development' started by GermanLetsPanda, Sep 14, 2021.

Thread Status:
Not open for further replies.
  1. I don't know why, but I'm getting a NullPointerException: null whenever I run
    Code (Text):
    I'm currently downgrading one of my Plugins, which worked perfectly for 1.17!
    By the way I'm using Purpur 1.16.5 (idk if I can even ask for help in a spigot forum) but I used Purpur 1.17.1 before which, like I already said, worked just fine.

    And for those who might ask, what's in line 88 of ChatListener:
    Code (Text):
    Bukkit.broadcastMessage(PermissionCore.getDisplayName(p) + p.getName() + " §7> §f" + finalMessage);
    But the Error also occures when I run a broadcast in onEnable

    Code (Text):



    java.lang.NullPointerException: null
    at org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer.sendMessage(CraftPlayer.java:2143) ~[patched_1.16.5.jar:git-Purpur-1171]
    at net.kyori.adventure.audience.Audience.sendMessage(Audience.java:215) ~[patched_1.16.5.jar:git-Purpur-1171]
    at net.kyori.adventure.audience.Audience.sendMessage(Audience.java:189) ~[patched_1.16.5.jar:git-Purpur-1171]
    at org.bukkit.craftbukkit.v1_16_R3.CraftServer.broadcast(CraftServer.java:1597) ~[patched_1.16.5.jar:git-Purpur-1171]
    at org.bukkit.craftbukkit.v1_16_R3.CraftServer.broadcast(CraftServer.java:1569) ~[patched_1.16.5.jar:git-Purpur-1171]
    at org.bukkit.craftbukkit.v1_16_R3.CraftServer.broadcastMessage(CraftServer.java:600) ~[patched_1.16.5.jar:git-Purpur-1171]
    at org.bukkit.Bukkit.broadcastMessage(Bukkit.java:308) ~[patched_1.16.5.jar:git-Purpur-1171]
    at de.pandadoxo.server_permissions.listener.ChatListener.lambda$onChat$2(ChatListener.java:88) ~[?:?]
    at org.bukkit.craftbukkit.v1_16_R3.scheduler.CraftTask.run(CraftTask.java:100) ~[patched_1.16.5.jar:git-Purpur-1171]
    at org.bukkit.craftbukkit.v1_16_R3.scheduler.CraftAsyncTask.run(CraftAsyncTask.java:58) ~[patched_1.16.5.jar:git-Purpur-1171]
    at com.destroystokyo.paper.ServerSchedulerReportingWrapper.run(ServerSchedulerReportingWrapper.java:22) ~[patched_1.16.5.jar:git-Purpur-1171]
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) [?:1.8.0_292]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) [?:1.8.0_292]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_292]
  2. can you give a ss of the whole error please?
  3. That is liturally the whole error o.o

  4. Are you sure the problem is the broadcastMessage and not the permission system?
  5. It must be the permission plugin but I can explain myself why it doesn't work ¯\_(ツ)_/¯. I'm sure it will work with other plugins.
  6. Other topic: I've never seen net.kyori.adventure before. Is this a normal package or did I import smth weird?
    Also, if nobody knows any solution I will just "recode" the plugin, it isn't that large actually - I'll let this thread open till ~10pm
  7. Check the API of the permission system, maybe something is different in the new version. 1.17 -> 1.16
  8. Well actually the permission system is the plugin I'm working on. Or do you mean smth. else?
  9. You didn't post the whole class so we can't know if you really used it.
    • Friendly Friendly x 1
  10. You're right, my bad, here you go:
    Code (Java):
    // -----------------------
    // Coded by Pandadoxo
    // on 30.04.2021 at 17:18
    // -----------------------

    package de.pandadoxo.server_permissions.listener;

    import de.pandadoxo.server_permissions.Main;
    import de.pandadoxo.server_permissions.PermissionCore;
    import org.bukkit.Bukkit;
    import org.bukkit.entity.Player;
    import org.bukkit.event.EventHandler;
    import org.bukkit.event.Listener;
    import org.bukkit.event.player.AsyncPlayerChatEvent;

    import java.util.ArrayList;
    import java.util.HashMap;
    import java.util.List;
    import java.util.UUID;

    public class ChatListener implements Listener {

        private static final HashMap<UUID, String> lastMessage = new HashMap<UUID, String>();
        private static final List<UUID> cooldown = new ArrayList<>();

        public void onChat(AsyncPlayerChatEvent event) {
            //Chat Mute
            if(event.isCancelled()) {

            String message = event.getMessage();
            Player p = event.getPlayer();

            //Caps Protection
            if (!p.hasPermission("501essentials.chat.ignorecaps")) {
                double caps = 0d;
                for (Character ch : message.toCharArray()) {
                    if (Character.isUpperCase(ch)) caps += 1;
                if ((caps / message.length()) * 100 > 51) {
                    message = message.toLowerCase();

            if (Main.isChatRepeat() && !p.hasPermission("501essentials.chat.ignorerepeat")) {
                if (lastMessage.containsKey(p.getUniqueId())) {
                    String lastMsg = lastMessage.get(p.getUniqueId());
                    if (lastMsg.equalsIgnoreCase(message)) {
                        p.sendMessage("§c§oDu wiederholst dich");

            if (Main.isChatCooldown() && !p.hasPermission("501essentials.chat.ignorecooldown")) {
                if (cooldown.contains(p.getUniqueId())) {
                    p.sendMessage("§c§oDu schreibst zu schnell");

            //Repeat Core
            if (Main.isChatRepeat()) {
                lastMessage.put(p.getUniqueId(), event.getMessage());
                Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> lastMessage.remove(p.getUniqueId(), event.getMessage()), 10 * 20);

            //Cooldown Core
            if (Main.isChatCooldown()) {
                Bukkit.getScheduler().runTaskLater(Main.getInstance(), () -> cooldown.remove(p.getUniqueId()), 10);

            if (Main.isChatFormat()) {
                String finalMessage = message;
                Bukkit.getScheduler().runTaskAsynchronously(Main.getInstance(), () -> {
                    Bukkit.broadcastMessage(PermissionCore.getDisplayName(p) + p.getName() + " §7> §f" + finalMessage);


  11. ... I just "recoded" aka. copy - pasted all classes to a new project and still receive the same error code. So forget about what I said, I'll not close this thread until we/I find a solution ^^

    And to the weird package: I belive it's just something from purpur.

    Btw: thanks for the fast replies <3
  12. you use maven or gradle to build right?
    if so, please send a ss of all your dependencies list
    since you mentioned that u've never seen the package"net.kyori.adventure"
    • Friendly Friendly x 1
  13. Sure, but like I said, this package is from purpur which runs on the server but is not a dependency!

  14. i see, so you're using purpur

    unfortunately we can't help you since you are using a non official spigot fork which will cause confliction, this is listed in the rules, no one will help you with purpur or any other non-official spigot fork.
    • Useful Useful x 1
  15. i noticed that from the error messages but was lazy to point it lol, now you can see why you aren't getting a clear answer
    • Funny Funny x 1
  16. Choco


    This is Spigot. You are using a far derivative of Spigot which has changed the implementation of all chat-related functionality. The exception is internal. Consider seeking support from Purpur instead. It's an issue with the server software

    Thread locked.
    • Agree Agree x 1
Thread Status:
Not open for further replies.