Problem parsing string (regex), and need further suggestions :)

Discussion in 'Plugin Development' started by JesusGreen, Jan 20, 2011.

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

    JesusGreen

    Alright so I used to code in Java a while back (at a basic) pretty but I stopped for several years and pretty much forgot about it.

    Recently my friend purchased a server and one thing we did was set up a Minecraft server, onto which we installed hMod. But after the latest update we heard hMod is being discontinued, decided to use bukkit - but due to the lack of the plugins we need, we decided we'd write our own.

    First thing's first I decided to make a simple plugin that would allow you to store notes on players, something that would be easy to make to get me back into Java, but would also have an actual use.

    Okay so at one point I use this line:
    Code:
    String choseName = split[1].replaceAll("[!#$%&'()*+,./:;<=>?@\\\\^_`{|}~-]", "");
    I found the above regex on wiki for additional characters that I'd want to remove, albeit with only one \ backslash, I remember in Java you need to use \\\\ to treat it as \ and not escape characters, but for some reason there is an error every time it tries to create the notes file now, so I think my attempt at replacing the backslash is failing. How would I go about fixing this? I suppose I could use regex to check if it's alphanumeric and throw out an error if it's not, but is there a simpler way?

    Plugin download: <Edit by Moderator: Redacted mediafire url>
    (This contains the source and the .jar, to use it you may need to create a folder named "notes" inside your server folder)

    To use it:
    Code:
    /notes Player
    - Returns notes on Player if Player.txt exists in the notes folder
    Code:
    /setnotes Player Notes go here
    - Sets Player.txt in /notes/ to whatever you specify, and creates Player.txt if it does not already exist

    Also I could use some ideas to further extend the plugin, as it's fairly simple at the moment and doesn't have much of a real use. I'm thinking of possibly turning it into a Player Info plugin and showing the player's group, server join date, iConomy info etc later on, but for now I just want some really simple stuff I could add in to make it more functional.

    Thanks :)
     
    Last edited by a moderator: Dec 15, 2016
  2. Offline

    Afforess

    It's only "\\" to be interpreted as "\", not "\\\\" for "\". 2

    The first backslash is the escape character, the second one is the printed character in this case.
     
  3. Offline

    JesusGreen

    Ah right, my mistake, though I seem to remember I tried \\ at some point and while it did not error it did not remove the \'s from my string. I'll give it another go in case I was mistaken but is there anything else that looks wrong?

    Here's my source prior to that edit I just made (to save having to download it), be warned my code is very messy though and there's stuff that doesn't need to be in there, but I was just trying to get it working completely before worrying about that.
    PlayerNotes.java: http://pastebin.com/X5g9FBLS
    PNPlayerListener.java: http://pastebin.com/4RHshLB6

    Edit: Yeah still having problems. If for example I type: /setnotes Jesus.Green test or /setnotes Jesus/Green test it'll remove the . or / and setnotes for JesusGreen, but if I type /setnotes Jesus\Green test it just errors.
     
Thread Status:
Not open for further replies.

Share This Page