Solved Changing & to color, what's wrong here?

Discussion in 'Plugin Development' started by Urag, Aug 5, 2015.

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

    Urag

    Message does not appear.

    It's my code:

    Code:
        FileConfiguration config;
        File cfile;
    
        public void onEnable(){
            config = getConfig();
            config.options().copyDefaults(false);
            saveConfig();
            cfile = new File(getDataFolder(), "config.yml");
            Bukkit.getServer().getScheduler().scheduleSyncRepeatingTask(this, new Runnable() {
    
                public void run(){
                    String msg = config.getString("announcement");
                    msg=ChatColor.translateAlternateColorCodes('&', msg);
                    Bukkit.getServer().broadcastMessage(msg);
                }
             
            }, 20, 100);
        }
    It's my config.yml
    Code:
    announcement: &6&lThis is a test!
    It's a warm when broadcasting message:
    Code:
    [14:28:35] [Server thread/WARN]: [Announcer] Task #16 for Announcer v1.0 generated an exception
    java.lang.NullPointerException
        at org.bukkit.ChatColor.translateAlternateColorCodes(ChatColor.java:206) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at me.urag.announcer.Main$1.run(Main.java:27) ~[?:?]
        at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftTask.run(CraftTask.java:71) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.craftbukkit.v1_7_R4.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:350) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at net.minecraft.server.v1_7_R4.MinecraftServer.v(MinecraftServer.java:641) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:289) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    It's an error when /reload:
    Code:
    [14:34:38] [Server thread/ERROR]: Cannot load plugins\Announcer\config.yml
    org.bukkit.configuration.InvalidConfigurationException: while scanning an anchor
    in 'string', line 1, column 15:
        announcement: &6&lThis is a test!
                      ^
    expected alphabetic or numeric character, but found &(38)
    in 'string', line 1, column 17:
        announcement: &6&lThis is a test!
                        ^
    
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:57) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:226) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.configuration.file.FileConfiguration.load(FileConfiguration.java:169) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.configuration.file.YamlConfiguration.loadConfiguration(YamlConfiguration.java:180) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.plugin.java.JavaPlugin.reloadConfig(JavaPlugin.java:183) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.plugin.java.JavaPlugin.getConfig(JavaPlugin.java:157) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at me.urag.announcer.Main.onEnable(Main.java:19) [Announcer.jar:?]
        at org.bukkit.plugin.java.JavaPlugin.setEnabled(JavaPlugin.java:316) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.plugin.java.JavaPluginLoader.enablePlugin(JavaPluginLoader.java:332) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.plugin.SimplePluginManager.enablePlugin(SimplePluginManager.java:412) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.loadPlugin(CraftServer.java:476) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.enablePlugins(CraftServer.java:394) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.reload(CraftServer.java:866) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.Bukkit.reload(Bukkit.java:301) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.command.defaults.ReloadCommand.execute(ReloadCommand.java:23) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.command.SimpleCommandMap.dispatch(SimpleCommandMap.java:181) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchCommand(CraftServer.java:767) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.craftbukkit.v1_7_R4.CraftServer.dispatchServerCommand(CraftServer.java:753) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at net.minecraft.server.v1_7_R4.DedicatedServer.aB(DedicatedServer.java:326) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at net.minecraft.server.v1_7_R4.DedicatedServer.v(DedicatedServer.java:290) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at net.minecraft.server.v1_7_R4.MinecraftServer.u(MinecraftServer.java:584) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at net.minecraft.server.v1_7_R4.MinecraftServer.run(MinecraftServer.java:490) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at net.minecraft.server.v1_7_R4.ThreadServerApplication.run(SourceFile:628) [craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
    Caused by: org.yaml.snakeyaml.scanner.ScannerException: while scanning an anchor; expected alphabetic or numeric character, but found &(38);  in 'string', line 1, column 17:
        announcement: &6&lThis is a test!
                        ^
        at org.yaml.snakeyaml.scanner.ScannerImpl.scanAnchor(ScannerImpl.java:1446) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.yaml.snakeyaml.scanner.ScannerImpl.fetchAnchor(ScannerImpl.java:939) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.yaml.snakeyaml.scanner.ScannerImpl.fetchMoreTokens(ScannerImpl.java:370) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.yaml.snakeyaml.scanner.ScannerImpl.checkToken(ScannerImpl.java:226) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.yaml.snakeyaml.parser.ParserImpl$ParseBlockMappingValue.produce(ParserImpl.java:586) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.yaml.snakeyaml.parser.ParserImpl.peekEvent(ParserImpl.java:158) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.yaml.snakeyaml.parser.ParserImpl.checkEvent(ParserImpl.java:143) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:132) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.yaml.snakeyaml.composer.Composer.composeMappingNode(Composer.java:237) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.yaml.snakeyaml.composer.Composer.composeNode(Composer.java:159) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.yaml.snakeyaml.composer.Composer.composeDocument(Composer.java:122) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.yaml.snakeyaml.composer.Composer.getSingleNode(Composer.java:105) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.yaml.snakeyaml.constructor.BaseConstructor.getSingleData(BaseConstructor.java:120) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.yaml.snakeyaml.Yaml.loadFromReader(Yaml.java:481) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.yaml.snakeyaml.Yaml.load(Yaml.java:400) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString(YamlConfiguration.java:55) ~[craftbukkit.jar:git-Spigot-1.7.9-R0.2-207-g03373bb]
        ... 22 more
     
  2. Offline

    bwfcwalshy Retired Staff

    @Urag First of all, remove the File config.
    Secondly, put the strings from the config in ''
     
    Urag likes this.
  3. Offline

    Urag

Thread Status:
Not open for further replies.

Share This Page