PwnFilter

PwnFilter

57.1k Downloads

Recommendation: "then announce"

Hedgehogs4Me opened this issue ยท 0 comments

commented

I would love to be able to code a chatbot using regex. That is the dream, and I'm sure a bunch of other people would also want to do either that or something similar (not only that, it fits right in with the code you already have!). I was going to make a pull request with that in it, but no matter what I did, I just couldn't make it work. Sorry. That's probably just because I'm terrible with Java, though.

So, anyway, here's what it would do*:

  1. Check for "then announce" using the same code as, say, "then command" but with an extra letter in the substring. Here's what I had in the version I tried to make:
if (line.startsWith("then announce ")) {
    announcetxt = line.substring(14);
    announce = true;
    valid = true;
}
  1. Send a message to everyone, not just the player like "warn" does. I'm not even going to show you what I had, but instead make a new one on the spot by copying "warn". That's how bad it was when I tried. Note that this is probably wrong, but you can get the gist of what I think would be a nice feature.
if (announce) {
    announcetxt = announcetxt.replaceAll("&([0-9a-fk-or])", "\u00A7$1");
    // These would be extremely helpful for making specific chat responses
    announcetxt = announcetxt.replaceAll("&player", player.getName());
    announcetxt = announcetxt.replaceAll("&string", message);  
    announcetxt = announcetxt.replaceAll("&rawstring", rawmessage);
    final Player fplayer = player;
    final String fannounce = announcetxt;
    Bukkit.getScheduler().runTask(this, new Runnable() {
        public void run() {
            if (!fannounce.matches("")) {
                fplayer.sendMessage(fannounce);
            }
        )
    });
}

That's it! Doing the same for commands is optional, as it'd be nice for "/me" but would be terrible for "/msg". Use your judgement, since you seem to have made the rest of this plugin completely perfectly. :)

Simple example of how it might be used:

# Our chatbot likes hugs.
match ChatBot.+want.+hug
then announce &1[ChatBot] &f: I would love a hug, &player.

* Note: I skipped declaring variables and such because it's not really necessary for an issue submission, right?