Skip to content

Commit

Permalink
Change current queue context system to be dedicated to the definition…
Browse files Browse the repository at this point in the history
…s system.
  • Loading branch information
aufdemrand committed Aug 27, 2013
1 parent 7e08d9e commit d6498aa
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 37 deletions.
Expand Up @@ -38,9 +38,9 @@ public boolean execute(ScriptEntry scriptEntry) {
Matcher m = definition_pattern.matcher(scriptEntry.getCommandName());
StringBuffer sb = new StringBuffer();
while (m.find()) {
if (scriptEntry.getResidingQueue().hasContext(m.group(1).toLowerCase()))
if (scriptEntry.getResidingQueue().hasDefinition(m.group(1).toLowerCase()))
m.appendReplacement(sb,
scriptEntry.getResidingQueue().getContext(m.group(1).toLowerCase()));
scriptEntry.getResidingQueue().getDefinition(m.group(1).toLowerCase()));

else m.appendReplacement(sb, "null");
}
Expand Down Expand Up @@ -105,10 +105,10 @@ public boolean execute(ScriptEntry scriptEntry) {
m = definition_pattern.matcher(arg.raw_value);
sb = new StringBuffer();
while (m.find()) {
if (scriptEntry.getResidingQueue().hasContext(m.group(1).toLowerCase()))
if (scriptEntry.getResidingQueue().hasDefinition(m.group(1).toLowerCase()))
m.appendReplacement(sb,
scriptEntry.getResidingQueue()
.getContext(m.group(1).toLowerCase()));
.getDefinition(m.group(1).toLowerCase()));

else m.appendReplacement(sb, "null");
}
Expand Down
Expand Up @@ -63,7 +63,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
+ aH.debugObj("definition", scriptEntry.getObject("definition").toString())
+ aH.debugObj("value", scriptEntry.getObject("value").toString()));

scriptEntry.getResidingQueue().addContext(
scriptEntry.getResidingQueue().addDefinition(
(String) scriptEntry.getObject("definition"),
(String) scriptEntry.getObject("value"));
}
Expand Down
Expand Up @@ -62,8 +62,8 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
}
}
ScriptQueue queue = new InstantQueue(UUID.randomUUID().toString());
scriptEntry.getResidingQueue().addContext("value", value);
queue.addContext("value", value);
scriptEntry.getResidingQueue().addDefinition("value", value);
queue.addDefinition("value", value);
queue.addEntries(newEntries);
queue.start();
}
Expand Down
Expand Up @@ -60,8 +60,8 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
}
}
ScriptQueue queue = new InstantQueue(UUID.randomUUID().toString());
scriptEntry.getResidingQueue().addContext("value", String.valueOf(incr + 1));
queue.addContext("value", String.valueOf(incr + 1));
scriptEntry.getResidingQueue().addDefinition("value", String.valueOf(incr + 1));
queue.addDefinition("value", String.valueOf(incr + 1));
queue.addEntries(newEntries);
queue.start();
}
Expand Down
Expand Up @@ -142,7 +142,7 @@ public void execute(ScriptEntry scriptEntry) throws CommandExecutionException {
try { definition_names = script.getContainer().getString("definitions").split("\\|"); }
catch (Exception e) { }
for (String definition : definitions) {
queue.addContext(definition_names != null && definition_names.length >= x ?
queue.addDefinition(definition_names != null && definition_names.length >= x ?
definition_names[x - 1].trim() : String.valueOf(x), definition);
x++;
}
Expand Down
Expand Up @@ -105,9 +105,8 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept
entity.target(target.getLivingEntity());
}
}

// Add the dList to the queue's context

scriptEntry.getResidingQueue().addContext("entities", entityList.toString());

This comment has been minimized.

Copy link
@davidcernat

davidcernat Sep 4, 2013

Contributor

Why remove this? It was useful, and you wanted something similar in Shoot anyway. :p

This comment has been minimized.

Copy link
@aufdemrand

aufdemrand Sep 4, 2013

Author Contributor

I think it was removed because it was using the system. To follow suit, this should use scriptentry context. I'll add it back in as that.

This comment has been minimized.

Copy link
@davidcernat

davidcernat Sep 4, 2013

Contributor

No more need now.

This comment has been minimized.

Copy link
@aufdemrand

aufdemrand via email Sep 4, 2013

Author Contributor



}
}
@@ -1,13 +1,11 @@
package net.aufdemrand.denizen.scripts.queues;

import net.aufdemrand.denizen.objects.Duration;
import net.aufdemrand.denizen.objects.dObject;
import net.aufdemrand.denizen.scripts.ScriptEntry;
import net.aufdemrand.denizen.utilities.DenizenAPI;
import net.aufdemrand.denizen.utilities.debugging.dB;
import org.bukkit.Bukkit;

import java.lang.reflect.InvocationTargetException;
import java.util.*;
import java.util.concurrent.ConcurrentHashMap;

Expand Down Expand Up @@ -134,11 +132,11 @@ public static boolean _queueExists(String id) {
private long delay_time = 0;


// ScriptQueues can have a bit of context,
// ScriptQueues can have a bit of definitions,
// keyed by a String Id. Denizen's
// 'Definitions' system uses this context.
// 'Definitions' system uses this definitions.
private Map<String, String>
context = new ConcurrentHashMap<String, String>(8, 0.9f, 1);
definitions = new ConcurrentHashMap<String, String>(8, 0.9f, 1);


/**
Expand All @@ -163,53 +161,63 @@ protected ScriptQueue(String id) {
// Public instance setters and getters
/////////////////////

/**
* Gets a held script entry. Held script entries might
* contains some script entry context that might need
* to be fetched!
*
*/
public ScriptEntry getHeldScriptEntry(String id) {
return null;
}


/**
* Gets a piece of context from the queue. Denizen's
* Gets a definition from the queue. Denizen's
* CommandExecuter will fetch this information
* by using the %definition_name% format, similar
* to 'replaceable tags'
*
* @param definition The name of the context
* @return The value of the context, or null
* @param definition The name of the definitions
* @return The value of the definitions, or null
*/
public String getContext(String definition) {
return context.get(definition.toLowerCase());
public String getDefinition(String definition) {
return definitions.get(definition.toLowerCase());
}


/**
* Checks for a piece of context.
* Checks for a piece of definitions.
*
* @param definition The name of the context
* @param definition The name of the definitions
* @return true if the definition exists.
*/
public boolean hasContext(String definition) {
return context.containsKey(definition.toLowerCase());
public boolean hasDefinition(String definition) {
return definitions.containsKey(definition.toLowerCase());
}


/**
* Adds a new piece of context to the queue. This
* Adds a new piece of definitions to the queue. This
* can be done with dScript as well by using the
* 'define' command.
*
* @param definition the name of the context
* @param definition the name of the definitions
* @param value the value of the definition
*/
public void addContext(String definition, String value) {
context.put(definition.toLowerCase(), value);
public void addDefinition(String definition, String value) {
definitions.put(definition.toLowerCase(), value);
}


/**
* Returns a Map of all the current context
* Returns a Map of all the current definitions
* stored in the queue, keyed by 'definition id'
*
* @return all current context, empty if none.
* @return all current definitions, empty if none.
*/
public Map<String, String> getAllContext() {
return context;
public Map<String, String> getAllDefinitions() {
return definitions;
}


Expand Down
Expand Up @@ -88,7 +88,7 @@ public void queueTags(ReplaceableTagEvent event) {
// Returns all definitions that were passed to the current queue.
// -->
if (attribute.startsWith("definitions"))
event.setReplaced(new Element(event.getScriptEntry().getResidingQueue().getAllContext().toString())
event.setReplaced(new Element(event.getScriptEntry().getResidingQueue().getAllDefinitions().toString())
.getAttribute(attribute.fulfill(1)));

}
Expand Down

0 comments on commit d6498aa

Please sign in to comment.