& symbol erroring, any way to stop it?

Discussion in 'Plugin Development' started by TopTobster5, Feb 25, 2014.

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

    TopTobster5

    Hi. I have finally bothered to add colour code support to my plugins, but they do not allow users to use the code as the first thing they put in. Is there any way to fix this.

    This is the error, if anyone want to see it:
    Code:
    [21:41:45] [Server thread/ERROR]: Cannot load configuration from stream
    org.bukkit.configuration.InvalidConfigurationException: while scanning an anchor
    in "<string>", line 5, column 9:
        prefix: &4[KB]
                ^
    expected alphabetic or numeric character, but found [(91)
    in "<string>", line 5, column 11:
        prefix: &4[KB]
                  ^
     
        at org.bukkit.configuration.file.YamlConfiguration.loadFromString
     
  2. Offline

    LCastr0

    The plugin code?

    Oh, nevermind. It is in the config file. Sorround the string with the &4[KB] with ', so it would look like '&4[KB]'

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  3. Offline

    TopTobster5

    The code referenced is from the config:
    Code:
    #KillstreakBroadcast
    #By TopTobster5
     
    #Prefix to appear before messages
    prefix: &4[KB]
     
    #Message to be broadcasted when player reaches a certain killstreak. -player- and -killstreak- will be replaced by the player name and the killstreak they reached. You may use colour codes (& symbol) here.
    messagenewkillstreak: &1-player- has reached a killstreak of -killstreak-
     
    #Message to be broadcasted if a player's killstreak is broken. -playerbroken-, -playerbreaker- and -killstreak- will be replaced by the player name of those that have dies, the name of the player who killed them and the killstreak they reached. You may use colour codes (& symbol) here.
    messagekillstreakbroken: &1-playerbreaker- has broken -playerbroken-'s killstreak of -killstreak-!
     
    #Killstreaks to be broadcasted on. Leave empty if you do not want it to broadcast.
    killstreaks:
      - 2
      - 3
      - 4
      - 5
     
    #Use XP bar/level to show how many kills the player currently has in their killstreak
    usexpbar: true

    This is the code which gets the prefix which I believe is what is causing the error, but It never actually mentioned the line number which errored.

    Code:java
    1. String prefix = getConfig().getString("prefix");
    2. prefix = ChatColor.translateAlternateColorCodes('&', prefix);
     
  4. Offline

    Garris0n

    Surround all your strings in single quote marks (') as LCastr0 said.
     
  5. Offline

    xize

    TopTobster5

    put the prefix: &4[KB] as prefix: '&4[KB]'

    edit
    I'm ninjad:p
     
  6. Offline

    TopTobster5

    It works better than it did, the command actually ran, but the massive error is still in the console.

    If it helps, the error only seems to appear once, if I run the command again, the error does not appear.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 6, 2016
  7. Offline

    LCastr0

    Could you please post the plugin's source?
     
  8. Offline

    NathanWolf

    Well that error is presumably from config loading time, so not anything to do with the command at all.

    Can you re-post the error you're seeing? Because if it looks identical than methinks you didn't add the quotes as suggested :)

    By that I mean it prints the thing it's having trouble with in the log message- does that print now show single quotes?
     
  9. Offline

    TopTobster5

    NathanWolf The error does not show the quotes, but they are in the config, I promise.:
    Code:
    #KillstreakBroadcast
    #By TopTobster5
     
    #Prefix to appear before messages
    prefix: '&4[KB]'
     
    #Message to be broadcasted when player reaches a certain killstreak. -player- and -killstreak- will be replaced by the player name and the killstreak they reached. You may use colour codes (& symbol) here.
    messagenewkillstreak: &1-player- has reached a killstreak of -killstreak-
     
    #Message to be broadcasted if a player's killstreak is broken. -playerbroken-, -playerbreaker- and -killstreak- will be replaced by the player name of those that have dies, the name of the player who killed them and the killstreak they reached. You may use colour codes (& symbol) here.
    messagekillstreakbroken: &1-playerbreaker- has broken -playerbroken-'s killstreak of -killstreak-!
     
    #Killstreaks to be broadcasted on. Leave empty if you do not want it to broadcast.
    killstreaks:
      - 2
      - 3
      - 4
      - 5
     
    #Use XP bar/level to show how many kills the player currently has in their killstreak
    usexpbar: true
    Here the error: http://pastebin.com/a7qq8jcY

    LCastr0 Here the link: http://pastebin.com/1ZaiFj7f
     
  10. Offline

    LCastr0

    TopTobster5 I'd tell you to do this:
    First, on your onEnable(), put:
    getConfig().options().copyDefaults(true);
    before your this.saveDefaultConfig();
    And then, change the prefix to something like this:
    String prefix = (gets your prefix here)
    prefix = prefix.replaceAll("&", "§");
    This will make the same as the translate chat colors, but with less code, and for me, less bugged.
     
  11. Offline

    Traks

    LCastr0 That would also replace ampersands that aren't in front of a character that would form a colour. Regex is here to save the day though:
    Code:java
    1. prefix.replaceAll("&(?=[0-9a-fklmnor])", "§");
     
  12. Offline

    L33m4n123

    TopTobster5 can you pastebin your config? Because you left at least some strings out that are not surrounded by ' ' and start with an & .. so if you just go ahaed and pastebin your config file we can look at it and do not need to "pull" it out of your nose part by part
     
  13. Offline

    TopTobster5

    @L33m4n123 I didnt bother because they weren't what was causing the error.​
    Traks LCastr0 I'll try it out tomorrow and let you know, a bit busy right now.
     
Thread Status:
Not open for further replies.

Share This Page