Skip to content

Commit

Permalink
Save entities spawned with Spawn in context, so they can be fetched w…
Browse files Browse the repository at this point in the history
…ith %entities%
  • Loading branch information
davidcernat committed Jul 29, 2013
1 parent 31158ff commit eb0439a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 9 deletions.
3 changes: 2 additions & 1 deletion src/main/java/net/aufdemrand/denizen/flags/FlagManager.java
Expand Up @@ -274,7 +274,8 @@ public int split(Object obj) {

if (split.length > 0) {
for (String val : split)
value.values.add(val);
if (val.length() > 0)
value.values.add(val);

save();
rebuild();
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/net/aufdemrand/denizen/objects/dItem.java
Expand Up @@ -15,7 +15,9 @@
import org.bukkit.entity.Item;
import org.bukkit.inventory.ItemStack;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -478,7 +480,7 @@ public String identify() {

// If not a saved item, but is a custom item, return the script id
else if (containsLore("§0id:")) {
return "i@" + getLore("§0id: ");
return "i@" + getLore("§0id:");
}
}

Expand Down Expand Up @@ -586,9 +588,19 @@ public String getAttribute(Attribute attribute) {

}

// Return all lore except for lore that holds item script ID
if (attribute.startsWith("lore")) {
if (getItemStack().hasItemMeta() && getItemStack().getItemMeta().hasLore())
return new dList(getItemStack().getItemMeta().getLore()).getAttribute(attribute.fulfill(1));
if (getItemStack().hasItemMeta() && getItemStack().getItemMeta().hasLore()) {

List<String> loreList = new ArrayList<String>();

for (String itemLore : getItemStack().getItemMeta().getLore()) {
if (!itemLore.startsWith("§0id:")) {
loreList.add(itemLore);
}
}
return new dList(loreList).getAttribute(attribute.fulfill(1));
}
else return new dList("").getAttribute(attribute.fulfill(1));
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/net/aufdemrand/denizen/objects/dLocation.java
Expand Up @@ -356,10 +356,11 @@ public String getAttribute(Attribute attribute) {
String[] ints = attribute.getContext(1).split(",", 3);
if ((aH.matchesDouble(ints[0]) || aH.matchesInteger(ints[0]))
&& (aH.matchesDouble(ints[1]) || aH.matchesInteger(ints[1]))
&& (aH.matchesDouble(ints[2]) || aH.matchesInteger(ints[2])))
&& (aH.matchesDouble(ints[2]) || aH.matchesInteger(ints[2]))) {
return new dLocation(this.clone().add(Double.valueOf(ints[0]),
Double.valueOf(ints[1]),
Double.valueOf(ints[2]))).getAttribute(attribute.fulfill(1));
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/main/java/net/aufdemrand/denizen/objects/dPlayer.java
Expand Up @@ -717,8 +717,7 @@ else if (attribute.getAttribute(2).startsWith("world"))

// <--
// <player.allowed_flight> -> Element(boolean)
// returns a dItem that the player's cursor is on, if any. This includes
// chest interfaces, inventories, and hotbars, etc.
// returns true if the player is allowed to fly, and false otherwise
// -->
if (attribute.startsWith("allowed_flight"))
return new Element(String.valueOf(getPlayerEntity().getAllowFlight()))
Expand Down
Expand Up @@ -76,20 +76,36 @@ public void execute(final ScriptEntry scriptEntry) throws CommandExecutionExcept
aH.debugObj("location", location) +
(target != null ? aH.debugObj("target", target) : ""));

// Keep a dList of entities that can be called using %entities%
// later in the script queue

dList entityList = new dList("");

// Go through all the entities and spawn them or teleport them,
// then set their targets if applicable

for (dEntity entity : entities) {

if (entity.isSpawned() == false) {
entity.spawnAt(location);
}
else {
entity.teleport(location);
}

// Only add to entityList after the entities have been
// spawned, otherwise you'll get something like "e@skeleton"
// instead of "e@57" on it

entityList.add(entity.toString());

if (target != null && target.isLivingEntity()) {
entity.target(target.getLivingEntity());
}
}
}

// Add the dList to the queue's context

scriptEntry.getResidingQueue().addContext("entities", entityList.toString());
}
}
Expand Up @@ -46,7 +46,7 @@ public dItem getItemFrom(dPlayer player, dNPC npc) {
List<String> lore = new ArrayList<String>();

// Set Id of the first, invisible lore
lore.add("§0id: " + getName());
lore.add("§0id:" + getName());

// Set Display Name
if (contains("DISPLAY NAME")){
Expand Down

0 comments on commit eb0439a

Please sign in to comment.