Skip to content

Commit

Permalink
Replaceable tag event micro-efficiency
Browse files Browse the repository at this point in the history
Avoid splitting where possible
  • Loading branch information
mcmonkey4eva committed Sep 24, 2014
1 parent a362f9f commit e0eb8d9
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ else if (c == '|' && bracks == 0 && bracks2 == 0) {

// Matches method (checks first attribute (name) of the tag)

// TODO: Remove in 1.0!
public boolean matches(String tagName) {
String[] tagNames = StringUtils.split(tagName, ',');
String name = getName();
Expand All @@ -159,6 +160,13 @@ public boolean matches(String tagName) {
return false;
}

public boolean matches(String... tagNames) {
String name = getName();
for (String string: tagNames)
if (name.equalsIgnoreCase(string.trim())) return true;
return false;
}


private String StripContext(String input) {
if (input == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ContextTags(Denizen denizen) {
// Get scriptqueue context!
@EventHandler
public void contextTags(ReplaceableTagEvent event) {
if (!event.matches("context, c") || event.getScriptEntry() == null) return;
if (!event.matches("context", "c") || event.getScriptEntry() == null) return;

String object = event.getType();

Expand Down Expand Up @@ -62,7 +62,7 @@ public void contextTags(ReplaceableTagEvent event) {
// Get a saved script entry!
@EventHandler
public void savedEntryTags(ReplaceableTagEvent event) {
if (!event.matches("entry, e")
if (!event.matches("entry", "e")
|| event.getScriptEntry() == null
|| !event.hasNameContext()) return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public DefinitionTags(Denizen denizen) {
@EventHandler
public void definitionTag(ReplaceableTagEvent event) {

if (!event.matches("definition, def, d")) return;
if (!event.matches("definition", "def", "d")) return;

if (!event.hasNameContext()) {
dB.echoError("Invalid definition tag, no context specified!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public LocationTags(Denizen denizen) {
@EventHandler
public void locationTags(ReplaceableTagEvent event) {

if (!event.matches("location, l") || event.replaced()) return;
if (!event.matches("location", "l") || event.replaced()) return;

// Stage the location
dLocation loc = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public void run() {
@EventHandler
public void playerTags(ReplaceableTagEvent event) {

if (!event.matches("player, pl") || event.replaced()) return;
if (!event.matches("player", "pl") || event.replaced()) return;

// Build a new attribute out of the raw_tag supplied in the script to be fulfilled
Attribute attribute = new Attribute(event.raw_tag, event.getScriptEntry());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public void procedureTag(ReplaceableTagEvent event) {
// Returns the 'determine' result of a procedure script.
// See <@link example Using Procedure Scripts>.
// -->
if (!event.matches("proc, pr")) return;
if (!event.matches("proc", "pr")) return;

Attribute attr = event.getAttributes();
int attribs = 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public QueueTags(Denizen denizen) {
@EventHandler
public void queueTag(ReplaceableTagEvent event) {

if (!event.matches("queue, q")) return;
if (!event.matches("queue", "q")) return;

Attribute attribute = new Attribute(event.raw_tag, event.getScriptEntry()).fulfill(1);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public ScriptTags(Denizen denizen) {
@EventHandler
public void scriptTags(ReplaceableTagEvent event) {

if (!event.matches("script, s") || event.replaced()) return;
if (!event.matches("script", "s") || event.replaced()) return;

// Stage the location
dScript script = null;
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/net/aufdemrand/denizen/tags/core/UtilTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public UtilTags(Denizen denizen) {
// -->
@EventHandler
public void mathTag(ReplaceableTagEvent event) {
if (!event.matches("math, m")) return;
if (!event.matches("math", "m")) return;
try {
Double evaluation = new DoubleEvaluator().evaluate(event.getValue());
event.setReplaced(new Element(String.valueOf(evaluation)).getAttribute(event.getAttributes().fulfill(1)));
Expand All @@ -78,7 +78,7 @@ public void mathTag(ReplaceableTagEvent event) {
// -->
@EventHandler
public void ternaryTag(ReplaceableTagEvent event) {
if (!event.matches("ternary, tern, t")) return;
if (!event.matches("ternary", "tern", "t")) return;

// Fallback if nothing to evaluate
if (!event.hasNameContext()) return;
Expand All @@ -94,7 +94,7 @@ public void ternaryTag(ReplaceableTagEvent event) {

@EventHandler
public void serverTag(ReplaceableTagEvent event) {
if (!event.matches("server, svr, global") || event.replaced()) return;
if (!event.matches("server", "svr", "global") || event.replaced()) return;
Attribute attribute =
new Attribute(event.raw_tag, event.getScriptEntry()).fulfill(1);

Expand Down Expand Up @@ -681,7 +681,7 @@ else if (player.getName().toLowerCase().contains(matchInput) && matchPlayer == n

@EventHandler
public void utilTag(ReplaceableTagEvent event) {
if (!event.matches("util, u")) return;
if (!event.matches("util", "u")) return;

String type = event.getType() != null ? event.getType() : "";
String typeContext = event.getTypeContext() != null ? event.getTypeContext() : "";
Expand Down

0 comments on commit e0eb8d9

Please sign in to comment.