wyvern.lib.classes.filters
Class SpeechFilter

java.lang.Object
  extended bywyvern.lib.classes.filters.SpeechFilter
All Implemented Interfaces:
AddRemoveNotify, HookCallback, MutableProperty
Direct Known Subclasses:
NagaFilter, PigLatin

public abstract class SpeechFilter
extends java.lang.Object
implements HookCallback, AddRemoveNotify, MutableProperty

A generic mechanism for filtering things people say. Subclasses decide exactly how to filter the text.

Version:
1.0, Sep 17, 2000
Author:
Steve Yegge

Nested Class Summary
 class SpeechFilter.Replacement
          Keeps track of a pattern and its replacement.
 
Field Summary
protected  java.util.HashSet agents_
          The set of players this filter is currently acting on.
 
Constructor Summary
SpeechFilter()
          Constructs a new SpeechFilter
SpeechFilter(Commandable agent)
          Constructs a new SpeechFilter to filter the specified agent.
 
Method Summary
 void addGlobalPattern(java.lang.String regex, java.lang.String replacement)
          Adds a regex to replace globally.
 void addSinglePattern(java.lang.String regex, java.lang.String replacement)
          Adds a regex to replace one time.
 java.lang.String applyFilter(java.lang.String text)
          Subclasses should use this method to change the message.
 void detachFromAgent(Commandable agent)
          Stops filtering the specified agent.
 void filterAgent(Commandable agent)
          Attaches the filter to the specified agent.
 boolean filterSay()
          Determines whether the filter filters "say" messages.
 boolean filterShout()
          Determines whether the filter filters "shout" messages.
 boolean filterTell()
          Determines whether the filter filters "tell" messages.
 boolean filterWhisper()
          Determines whether the filter filters "whisper" messages.
 java.util.List getGlobalPatterns()
          Returns a list of the replace-all patterns for this filter, if any.
 java.util.List getSinglePatterns()
          Returns a list of the replace-one-time patterns for this filter, if any.
 void hookEvent(java.lang.String hookName, CommandEvent ev)
          Called when the player's trying to say something.
 void notifyAdd(PropertyList obj)
          Notifies the property that it's being added.
 void notifyRemove(PropertyList obj)
          Notifies the property that it's being removed.
 void shutdown()
          Turns the filter off and removes it.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface wyvern.lib.properties.MutableProperty
createClone
 

Field Detail

agents_

protected java.util.HashSet agents_
The set of players this filter is currently acting on.

Constructor Detail

SpeechFilter

public SpeechFilter()
Constructs a new SpeechFilter


SpeechFilter

public SpeechFilter(Commandable agent)
Constructs a new SpeechFilter to filter the specified agent.

Method Detail

notifyAdd

public void notifyAdd(PropertyList obj)
Notifies the property that it's being added.

Specified by:
notifyAdd in interface AddRemoveNotify
Parameters:
obj - the GameObject whose property list we're being added to

notifyRemove

public void notifyRemove(PropertyList obj)
Notifies the property that it's being removed.

Specified by:
notifyRemove in interface AddRemoveNotify
Parameters:
obj - the GameObject whose property list we're being removed from

filterAgent

public void filterAgent(Commandable agent)
Attaches the filter to the specified agent. If you override this method, make sure it's synchronized.


shutdown

public void shutdown()
Turns the filter off and removes it. If you override this method, make sure it's synchronized.


detachFromAgent

public void detachFromAgent(Commandable agent)
Stops filtering the specified agent.


hookEvent

public void hookEvent(java.lang.String hookName,
                      CommandEvent ev)
Called when the player's trying to say something.

Specified by:
hookEvent in interface HookCallback
Parameters:
hookName - the hook, e.g. "sayPreHook"
ev - the CommandEvent encapsulating the event parameters

applyFilter

public java.lang.String applyFilter(java.lang.String text)
Subclasses should use this method to change the message. The default implementation in SpeechFilter is to replace any single patterns once, and perform a replaceAll on any global patterns, in the order they were added.

Parameters:
text - the initial text of the say/shout/tell
Returns:
the modified text

filterSay

public boolean filterSay()
Determines whether the filter filters "say" messages.

Returns:
true if "say " is filtered. Default: true.

filterTell

public boolean filterTell()
Determines whether the filter filters "tell" messages.

Returns:
true if "tell " is filtered. Default: true.

filterShout

public boolean filterShout()
Determines whether the filter filters "shout" messages.

Returns:
true if "shout " is filtered. Default: true.

filterWhisper

public boolean filterWhisper()
Determines whether the filter filters "whisper" messages.

Returns:
true if "whisper " is filtered. Default: true.

addGlobalPattern

public void addGlobalPattern(java.lang.String regex,
                             java.lang.String replacement)
Adds a regex to replace globally.

Parameters:
regex - a Perl5 regular expression

addSinglePattern

public void addSinglePattern(java.lang.String regex,
                             java.lang.String replacement)
Adds a regex to replace one time.

Parameters:
regex - a Perl5 regular expression

getSinglePatterns

public java.util.List getSinglePatterns()
Returns a list of the replace-one-time patterns for this filter, if any.

Returns:
a List of SpeechFilter.Replacement objects, or null if we don't have any single patterns to replace

getGlobalPatterns

public java.util.List getGlobalPatterns()
Returns a list of the replace-all patterns for this filter, if any.

Returns:
a List of SpeechFilter.Replacement objects, or null if we don't have any global patterns to replace