Bukkit Color error

Status
This thread has been locked.

Annie

nebulanode.com
Supreme
Feedback score
20
Posts
690
Reactions
401
Resources
9
I use this code I got from a tutorial but he seems to be pulling from a bungee chat color so I transferred it to bukkit but it's throwing errors.


Code:
23.11 23:37:06 [Server] WARN Task #42 for AlonBroadcaster v1.0 generated an exception 
23.11 23:37:06 [Server] INFO java.lang.NullPointerException 
23.11 23:37:06 [Server] INFO at org.bukkit.ChatColor.translateAlternateColorCodes(ChatColor.java:324) ~[spigot-1.8.8-21fe707-e1ebe52.jar:git-Spigot-21fe707-e1ebe52] 
23.11 23:37:06 [Server] INFO at me.alontrle.firstplugin.plugin$1.run(plugin.java:28) ~[?:?] 
23.11 23:37:06 [Server] INFO at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftTask.run(CraftTask.java:71) ~[spigot-1.8.8-21fe707-e1ebe52.jar:git-Spigot-21fe707-e1ebe52] 
23.11 23:37:06 [Server] INFO at org.bukkit.craftbukkit.v1_8_R3.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [spigot-1.8.8-21fe707-e1ebe52.jar:git-Spigot-21fe707-e1ebe52] 
23.11 23:37:06 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.B(MinecraftServer.java:723) [spigot-1.8.8-21fe707-e1ebe52.jar:git-Spigot-21fe707-e1ebe52] 
23.11 23:37:06 [Server] INFO at net.minecraft.server.v1_8_R3.DedicatedServer.B(DedicatedServer.java:374) [spigot-1.8.8-21fe707-e1ebe52.jar:git-Spigot-21fe707-e1ebe52] 
23.11 23:37:06 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.A(MinecraftServer.java:654) [spigot-1.8.8-21fe707-e1ebe52.jar:git-Spigot-21fe707-e1ebe52] 
23.11 23:37:06 [Server] INFO at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:557) [spigot-1.8.8-21fe707-e1ebe52.jar:git-Spigot-21fe707-e1ebe52] 
23.11 23:37:06 [Server] INFO at java.lang.Thread.run(Thread.java:745) [?:1.8.0_111]

Code:
package me.alontrle.firstplugin;

import org.bukkit.ChatColor;

import org.bukkit.Bukkit;
import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.java.JavaPlugin;

/**
* Created by Alont on 11/23/2016.
*/
public class plugin extends JavaPlugin {

    public int broadcastnumber = 0;

    public static me.alontrle.firstplugin.plugin plugin;

    public void Broadcasts() {
        final int time = getConfig().getInt("Time");
        Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this.plugin, new Runnable() {
            public void run () {

                if (broadcastnumber == 0) {
                    int broadcasts = getConfig().getStringList("Broadcasts").size();
                    broadcastnumber = broadcasts;
                }

                String header = ChatColor.translateAlternateColorCodes('&', getConfig().getString("Header"));
                Bukkit.getServer().broadcastMessage(header);

                String message = ChatColor.translateAlternateColorCodes('&', getConfig().getStringList("Broadcasts").get(broadcastnumber - 1));
                Bukkit.getServer().broadcastMessage(message);

                String footer = ChatColor.translateAlternateColorCodes('&', getConfig().getString("Footer"));
                Bukkit.getServer().broadcastMessage(footer);



            }
        },0, 20 * time);
    }

    public void onEnable() {
        plugin = this;
        saveDefaultConfig();
        Broadcasts();
    }
}
 
Last edited:

FormallyMyles

Premium
Feedback score
0
Posts
5
Reactions
1
Resources
0
The NullPointerException would indicate that you're missing the values in your config. I'd check that you make these (or have a default config.yml for it to copy).
 

Pazzword

Plugin & Web Developer
Supreme
Feedback score
5
Posts
188
Reactions
131
Resources
0
Make sure you always check for the case that a value is null :)

Code:
String s = getConfig().getString("server");

if(s != null) {

}
 
Status
This thread has been locked.
Top